Title: [201505] trunk/Tools
Revision
201505
Author
carlo...@webkit.org
Date
2016-05-31 00:22:40 -0700 (Tue, 31 May 2016)

Log Message

[GTK] Test /webkit2/WebKitWebView/geolocation-permission-requests is failing since r201423
https://bugs.webkit.org/show_bug.cgi?id=158200

Reviewed by Philippe Normand.

This is because geolocation is no longer allowed for non secure sites, like HTTP. In that case
POSITION_UNAVAILABLE is returned without asking the API layer.

* TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
(testWebViewGeolocationPermissionRequests): Keep the HTTP case to check that it indeed returns
POSITION_UNAVAILABLE and use HTTPS URLs to check permission requests are allowed or denied. Also stop using the
document title, and use user script messages that are more reliable instead.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (201504 => 201505)


--- trunk/Tools/ChangeLog	2016-05-31 03:35:44 UTC (rev 201504)
+++ trunk/Tools/ChangeLog	2016-05-31 07:22:40 UTC (rev 201505)
@@ -1,3 +1,18 @@
+2016-05-31  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Test /webkit2/WebKitWebView/geolocation-permission-requests is failing since r201423
+        https://bugs.webkit.org/show_bug.cgi?id=158200
+
+        Reviewed by Philippe Normand.
+
+        This is because geolocation is no longer allowed for non secure sites, like HTTP. In that case
+        POSITION_UNAVAILABLE is returned without asking the API layer.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
+        (testWebViewGeolocationPermissionRequests): Keep the HTTP case to check that it indeed returns
+        POSITION_UNAVAILABLE and use HTTPS URLs to check permission requests are allowed or denied. Also stop using the
+        document title, and use user script messages that are more reliable instead.
+
 2016-05-28  Aakash Jain  <aakash_j...@apple.com>
 
         tests fail if display sleeps while run-webkit-tests is running

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp (201504 => 201505)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp	2016-05-31 03:35:44 UTC (rev 201504)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp	2016-05-31 07:22:40 UTC (rev 201505)
@@ -225,8 +225,15 @@
         return TRUE;
     }
 
+    static void permissionResultMessageReceivedCallback(WebKitUserContentManager* userContentManager, WebKitJavascriptResult* _javascript_Result, UIClientTest* test)
+    {
+        test->m_permissionResult.reset(WebViewTest::_javascript_ResultToCString(_javascript_Result));
+        g_main_loop_quit(test->m_mainLoop);
+    }
+
     UIClientTest()
-        : m_scriptDialogType(WEBKIT_SCRIPT_DIALOG_ALERT)
+        : WebViewTest(webkit_user_content_manager_new())
+        , m_scriptDialogType(WEBKIT_SCRIPT_DIALOG_ALERT)
         , m_scriptDialogConfirmed(true)
         , m_allowPermissionRequests(false)
         , m_verifyMediaTypes(false)
@@ -239,11 +246,17 @@
         g_signal_connect(m_webView, "script-dialog", G_CALLBACK(scriptDialog), this);
         g_signal_connect(m_webView, "mouse-target-changed", G_CALLBACK(mouseTargetChanged), this);
         g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequested), this);
+        WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView);
+        webkit_user_content_manager_register_script_message_handler(manager, "permission");
+        g_signal_connect(manager, "script-message-received::permission", G_CALLBACK(permissionResultMessageReceivedCallback), this);
     }
 
     ~UIClientTest()
     {
         g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
+        WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView);
+        g_signal_handlers_disconnect_matched(manager, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
+        webkit_user_content_manager_unregister_script_message_handler(manager, "permission");
     }
 
     static void tryWebViewCloseCallback(UIClientTest* test)
@@ -269,6 +282,13 @@
         g_main_loop_run(m_mainLoop);
     }
 
+    const char* waitUntilPermissionResultMessageReceived()
+    {
+        m_permissionResult = nullptr;
+        g_main_loop_run(m_mainLoop);
+        return m_permissionResult.get();
+    }
+
     void setExpectedWindowProperties(const WindowProperties& windowProperties)
     {
         m_windowProperties = windowProperties;
@@ -336,6 +356,7 @@
     HashSet<WTF::String> m_windowPropertiesChanged;
     GRefPtr<WebKitHitTestResult> m_mouseTargetHitTestResult;
     unsigned m_mouseTargetModifiers;
+    GUniquePtr<char> m_permissionResult;
 };
 
 static void testWebViewCreateReadyClose(UIClientTest* test, gconstpointer)
@@ -722,31 +743,33 @@
         "  <script>"
         "  function runTest()"
         "  {"
-        "    navigator.geolocation.getCurrentPosition(function(p) { document.title = \"OK\" },"
-        "                                             function(e) { document.title = e.code });"
+        "    navigator.geolocation.getCurrentPosition(function(p) { window.webkit.messageHandlers.permission.postMessage('OK'); },"
+        "                                             function(e) { window.webkit.messageHandlers.permission.postMessage(e.code.toString()); });"
         "  }"
         "  </script>"
         "  <body _onload_='runTest();'></body>"
         "</html>";
 
-    // Test denying a permission request.
+    // Geolocation is not allowed from insecure connections like HTTP,
+    // POSITION_UNAVAILABLE ('2') is returned in that case without even
+    // asking the API layer.
     test->m_allowPermissionRequests = false;
     test->loadHtml(geolocationRequestHTML, "http://foo.com/bar");
-    test->waitUntilTitleChanged();
+    const gchar* result = test->waitUntilPermissionResultMessageReceived();
+    g_assert_cmpstr(result, ==, "2");
 
-    // According to the Geolocation API specification, '1' is the
-    // error code returned for the PERMISSION_DENIED error.
-    // http://dev.w3.org/geo/api/spec-source.html#position_error_interface
-    const gchar* result = webkit_web_view_get_title(test->m_webView);
+    // Test denying a permission request. PERMISSION_DENIED ('1') is
+    // returned in this case.
+    test->m_allowPermissionRequests = false;
+    test->loadHtml(geolocationRequestHTML, "https://foo.com/bar");
+    result = test->waitUntilPermissionResultMessageReceived();
     g_assert_cmpstr(result, ==, "1");
 
-    // Test allowing a permission request.
+    // Test allowing a permission request. Result should be different
+    // to PERMISSION_DENIED ('1').
     test->m_allowPermissionRequests = true;
-    test->loadHtml(geolocationRequestHTML, 0);
-    test->waitUntilTitleChanged();
-
-    // Check that we did not get the PERMISSION_DENIED error now.
-    result = webkit_web_view_get_title(test->m_webView);
+    test->loadHtml(geolocationRequestHTML, "https://foo.com/bar");
+    result = test->waitUntilPermissionResultMessageReceived();
     g_assert_cmpstr(result, !=, "1");
     test->addLogFatalFlag(G_LOG_LEVEL_WARNING);
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to