- Revision
- 135496
- Author
- [email protected]
- Date
- 2012-11-22 01:44:45 -0800 (Thu, 22 Nov 2012)
Log Message
[Qt][WTR] TestController::platformRunUntil should not do busy waiting
https://bugs.webkit.org/show_bug.cgi?id=101327
Reviewed by Simon Hausmann.
Avoid busy waiting for events in platformRunUntil while making
sure we don't change the behavior of modal event loops.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::~TestController):
* WebKitTestRunner/TestController.h:
(TestController):
* WebKitTestRunner/efl/TestControllerEfl.cpp:
(WTR::TestController::platformDestroy):
(WTR):
* WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::TestController::platformDestroy):
(WTR):
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::TestController::platformDestroy):
(WTR):
* WebKitTestRunner/qt/TestControllerQt.cpp:
(TestController::RunLoop): Helper class to handle
the event loop logic
(WTR):
(WTR::TestController::RunLoop::RunLoop):
(WTR::TestController::RunLoop::runUntil): Use QEventLoop to implement
the run loop. This is the appropriate API to push the WaitForMoreEvents
flag to QCoreApplication::processEvents and also being able to exit the
loop if we have timed out.
(WTR::TestController::RunLoop::notifyDone):
(WTR::TestController::RunLoop::timerFired):
(WTR::TestController::RunLoop::runModal):
(WTR::TestController::notifyDone):
(WTR::TestController::platformInitialize):
(WTR::TestController::platformDestroy):
(WTR::TestController::platformRunUntil):
(WTR::TestController::runModal):
* WebKitTestRunner/win/TestControllerWin.cpp:
(WTR::TestController::platformDestroy):
(WTR):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (135495 => 135496)
--- trunk/Tools/ChangeLog 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/ChangeLog 2012-11-22 09:44:45 UTC (rev 135496)
@@ -1,3 +1,47 @@
+2012-11-22 Balazs Kelemen <[email protected]>
+
+ [Qt][WTR] TestController::platformRunUntil should not do busy waiting
+ https://bugs.webkit.org/show_bug.cgi?id=101327
+
+ Reviewed by Simon Hausmann.
+
+ Avoid busy waiting for events in platformRunUntil while making
+ sure we don't change the behavior of modal event loops.
+
+ * WebKitTestRunner/TestController.cpp:
+ (WTR::TestController::~TestController):
+ * WebKitTestRunner/TestController.h:
+ (TestController):
+ * WebKitTestRunner/efl/TestControllerEfl.cpp:
+ (WTR::TestController::platformDestroy):
+ (WTR):
+ * WebKitTestRunner/gtk/TestControllerGtk.cpp:
+ (WTR::TestController::platformDestroy):
+ (WTR):
+ * WebKitTestRunner/mac/TestControllerMac.mm:
+ (WTR::TestController::platformDestroy):
+ (WTR):
+ * WebKitTestRunner/qt/TestControllerQt.cpp:
+ (TestController::RunLoop): Helper class to handle
+ the event loop logic
+ (WTR):
+ (WTR::TestController::RunLoop::RunLoop):
+ (WTR::TestController::RunLoop::runUntil): Use QEventLoop to implement
+ the run loop. This is the appropriate API to push the WaitForMoreEvents
+ flag to QCoreApplication::processEvents and also being able to exit the
+ loop if we have timed out.
+ (WTR::TestController::RunLoop::notifyDone):
+ (WTR::TestController::RunLoop::timerFired):
+ (WTR::TestController::RunLoop::runModal):
+ (WTR::TestController::notifyDone):
+ (WTR::TestController::platformInitialize):
+ (WTR::TestController::platformDestroy):
+ (WTR::TestController::platformRunUntil):
+ (WTR::TestController::runModal):
+ * WebKitTestRunner/win/TestControllerWin.cpp:
+ (WTR::TestController::platformDestroy):
+ (WTR):
+
2012-11-22 Sudarsana Nagineni <[email protected]>
[EFL][WK2] Enable WKPreferences and AboutBlankLoad API tests
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (135495 => 135496)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2012-11-22 09:44:45 UTC (rev 135496)
@@ -109,6 +109,7 @@
TestController::~TestController()
{
+ platformDestroy();
}
static WKRect getWindowFrame(WKPageRef page, const void* clientInfo)
Modified: trunk/Tools/WebKitTestRunner/TestController.h (135495 => 135496)
--- trunk/Tools/WebKitTestRunner/TestController.h 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/WebKitTestRunner/TestController.h 2012-11-22 09:44:45 UTC (rev 135496)
@@ -92,6 +92,7 @@
bool runTest(const char* pathOrURL);
void platformInitialize();
+ void platformDestroy();
void platformInitializeContext();
void platformRunUntil(bool& done, double timeout);
void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
@@ -182,6 +183,11 @@
OwnPtr<EventSenderProxy> m_eventSenderProxy;
#endif
+#if PLATFORM(QT)
+ class RunLoop;
+ RunLoop* m_runLoop;
+#endif
+
WorkQueueManager m_workQueueManager;
};
Modified: trunk/Tools/WebKitTestRunner/efl/TestControllerEfl.cpp (135495 => 135496)
--- trunk/Tools/WebKitTestRunner/efl/TestControllerEfl.cpp 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/WebKitTestRunner/efl/TestControllerEfl.cpp 2012-11-22 09:44:45 UTC (rev 135496)
@@ -57,6 +57,10 @@
}
}
+void TestController::platformDestroy()
+{
+}
+
void TestController::platformRunUntil(bool& condition, double timeout)
{
if (timeout == m_noTimeout) {
Modified: trunk/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp (135495 => 135496)
--- trunk/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp 2012-11-22 09:44:45 UTC (rev 135496)
@@ -54,6 +54,10 @@
{
}
+void TestController::platformDestroy()
+{
+}
+
static gboolean timeoutCallback(gpointer)
{
fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
Modified: trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm (135495 => 135496)
--- trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm 2012-11-22 09:44:45 UTC (rev 135496)
@@ -40,6 +40,10 @@
{
}
+void TestController::platformDestroy()
+{
+}
+
void TestController::initializeInjectedBundlePath()
{
NSString *nsBundlePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"WebKitTestRunnerInjectedBundle.bundle"];
Modified: trunk/Tools/WebKitTestRunner/qt/TestControllerQt.cpp (135495 => 135496)
--- trunk/Tools/WebKitTestRunner/qt/TestControllerQt.cpp 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/WebKitTestRunner/qt/TestControllerQt.cpp 2012-11-22 09:44:45 UTC (rev 135496)
@@ -32,46 +32,108 @@
#include <cstdlib>
#include <QCoreApplication>
-#include <QElapsedTimer>
#include <QEventLoop>
#include <QFileInfo>
#include <QLibrary>
#include <QObject>
+#include <QTimer>
+#include <QtGlobal>
#include <qquickwebview_p.h>
-#include <QtGlobal>
#include <wtf/Platform.h>
#include <wtf/text/WTFString.h>
namespace WTR {
-void TestController::notifyDone()
+class TestController::RunLoop : public QObject {
+ Q_OBJECT
+public:
+ RunLoop();
+
+ void runUntil(double timeout);
+ void notifyDone();
+ void runModal(PlatformWebView*);
+public Q_SLOTS:
+ void timerFired();
+private:
+ QEventLoop m_runUntilLoop;
+ QEventLoop m_modalLoop;
+ QTimer m_runUntilLoopTimer;
+ bool m_runUntilLoopClosePending;
+};
+
+TestController::RunLoop::RunLoop()
+ : m_runUntilLoopClosePending(false)
{
+ m_runUntilLoopTimer.setSingleShot(true);
+ QObject::connect(&m_runUntilLoopTimer, SIGNAL(timeout()), this, SLOT(timerFired()));
}
-void TestController::platformInitialize()
+void TestController::RunLoop::runUntil(double timeout)
{
- QQuickWebView::platformInitialize();
+ ASSERT(!m_runUntilLoop.isRunning());
+ if (timeout) {
+ const int timeoutInMilliSecs = timeout * 1000;
+ m_runUntilLoopTimer.start(timeoutInMilliSecs);
+ }
+ m_runUntilLoop.exec(QEventLoop::ExcludeUserInputEvents);
}
-void TestController::platformRunUntil(bool& condition, double timeout)
+void TestController::RunLoop::notifyDone()
{
- if (qgetenv("QT_WEBKIT2_DEBUG") == "1" || timeout == m_noTimeout) {
- // Never timeout if we are debugging or not meant to timeout.
- while (!condition)
- QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 50);
+ if (m_modalLoop.isRunning()) {
+ // Wait for the modal loop first. We only kill it if we timeout.
+ m_runUntilLoopClosePending = true;
return;
}
- int timeoutInMSecs = timeout * 1000;
- QElapsedTimer timer;
- timer.start();
- while (!condition) {
- if (timer.elapsed() > timeoutInMSecs)
- return;
- QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents, timeoutInMSecs - timer.elapsed());
+ m_runUntilLoopTimer.stop();
+ m_runUntilLoop.exit();
+}
+
+void TestController::RunLoop::timerFired()
+{
+ if (m_modalLoop.isRunning()) {
+ m_runUntilLoopClosePending = true;
+ m_modalLoop.exit();
+ return;
}
+
+ m_runUntilLoop.exit();
}
+void TestController::RunLoop::runModal(PlatformWebView* view)
+{
+ ASSERT(!m_modalLoop.isRunning());
+ view->setModalEventLoop(&m_modalLoop);
+ m_modalLoop.exec(QEventLoop::ExcludeUserInputEvents);
+
+ if (m_runUntilLoopClosePending)
+ m_runUntilLoop.exit();
+}
+
+void TestController::notifyDone()
+{
+ m_runLoop->notifyDone();
+}
+
+void TestController::platformInitialize()
+{
+ m_runLoop = new RunLoop;
+ QQuickWebView::platformInitialize();
+}
+
+void TestController::platformDestroy()
+{
+ delete m_runLoop;
+}
+
+void TestController::platformRunUntil(bool& condition, double timeout)
+{
+ UNUSED_PARAM(condition);
+ const bool shouldTimeout = !(qgetenv("QT_WEBKIT2_DEBUG") == "1" || timeout == m_noTimeout);
+ m_runLoop->runUntil(shouldTimeout ? timeout : 0);
+}
+
static bool isExistingLibrary(const QString& path)
{
#if OS(WINDOWS)
@@ -113,9 +175,7 @@
void TestController::runModal(PlatformWebView* view)
{
- QEventLoop eventLoop;
- view->setModalEventLoop(&eventLoop);
- eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
+ shared().m_runLoop->runModal(view);
}
const char* TestController::platformLibraryPathForTesting()
@@ -124,3 +184,5 @@
}
} // namespace WTR
+
+#include "TestControllerQt.moc"
Modified: trunk/Tools/WebKitTestRunner/win/TestControllerWin.cpp (135495 => 135496)
--- trunk/Tools/WebKitTestRunner/win/TestControllerWin.cpp 2012-11-22 09:37:06 UTC (rev 135495)
+++ trunk/Tools/WebKitTestRunner/win/TestControllerWin.cpp 2012-11-22 09:44:45 UTC (rev 135496)
@@ -121,6 +121,10 @@
webProcessCrashingEvent = ::CreateEventA(0, FALSE, FALSE, webProcessCrashingEventName);
}
+void TestController::platformDestroy()
+{
+}
+
void TestController::initializeInjectedBundlePath()
{
CFStringRef exeContainerPath = CFURLCopyFileSystemPath(CFURLCreateCopyDeletingLastPathComponent(0, CFBundleCopyExecutableURL(CFBundleGetMainBundle())), kCFURLWindowsPathStyle);