Unreviewed. Fix GTK+ test /webkit2/WebKitWebView/javascript-dialogs after r214277.
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Mar 2017 14:55:59 +0000 (14:55 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Mar 2017 14:55:59 +0000 (14:55 +0000)
Since r214277 beforeunload events are not fired unless there's some user interaction, so we need to simulate it
in our unit tests to work.

* TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
(testWebViewJavaScriptDialogs):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@214347 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp

index 97b5591..3f540c9 100644 (file)
@@ -1,5 +1,15 @@
 2017-03-24  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        Unreviewed. Fix GTK+ test /webkit2/WebKitWebView/javascript-dialogs after r214277.
+
+        Since r214277 beforeunload events are not fired unless there's some user interaction, so we need to simulate it
+        in our unit tests to work.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
+        (testWebViewJavaScriptDialogs):
+
+2017-03-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] Add MIMETypeRegistry implementation using xdgmime and remove the GTK+ one
         https://bugs.webkit.org/show_bug.cgi?id=170001
 
index f8fe59c..4bc8956 100644 (file)
@@ -298,6 +298,15 @@ public:
         return m_mouseTargetHitTestResult.get();
     }
 
+    void simulateUserInterqaction()
+    {
+        mouseMoveTo(1, 1);
+        keyStroke(GDK_KEY_Down);
+        keyStroke(GDK_KEY_Up);
+        while (gtk_events_pending())
+            gtk_main_iteration();
+    }
+
     virtual GtkWidget* viewCreate(WebKitWebView* webView, WebKitNavigationAction* navigation)
     {
         g_assert(webView == m_webView);
@@ -519,6 +528,8 @@ static void testWebViewDisallowModalDialogs(ModalDialogsTest* test, gconstpointe
 
 static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer)
 {
+    test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL);
+
     static const char* htmlOnLoadFormat = "<html><body onLoad=\"%s\"></body></html>";
     static const char* jsAlertFormat = "alert('%s')";
     static const char* jsConfirmFormat = "do { confirmed = confirm('%s'); } while (!confirmed); alert('confirmed');";
@@ -557,6 +568,7 @@ static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer)
 
     // Reload should trigger onbeforeunload.
 #if 0
+    test->simulateUserInterqaction();
     // FIXME: reloading HTML data doesn't emit finished load event.
     // See https://bugs.webkit.org/show_bug.cgi?id=139089.
     test->m_scriptDialogConfirmed = false;
@@ -566,6 +578,7 @@ static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer)
 #endif
 
     // Navigation should trigger onbeforeunload.
+    test->simulateUserInterqaction();
     test->m_scriptDialogConfirmed = false;
     test->loadHtml("<html></html>", nullptr);
     test->waitUntilLoadFinished();
@@ -575,6 +588,7 @@ static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer)
     test->m_scriptDialogConfirmed = false;
     test->loadHtml(beforeUnloadDialogHTML.get(), nullptr);
     test->waitUntilLoadFinished();
+    test->simulateUserInterqaction();
     test->tryCloseAndWaitUntilClosed();
     g_assert(test->m_scriptDialogConfirmed);