Title: [207098] releases/WebKitGTK/webkit-2.14/Tools
Revision
207098
Author
[email protected]
Date
2016-10-11 05:01:09 -0700 (Tue, 11 Oct 2016)

Log Message

Merge r206304 - REGRESSION(r204163): [GTK] API test /webkit2/WebKitSecurityManager/file-xhr is failing
https://bugs.webkit.org/show_bug.cgi?id=161607

Reviewed by Michael Catanzaro.

Since r204163, in case of cross origin error when loading the XHR, the load fails and an error message is shown
in the console, but there isn't any js expcetion, which is what we were checking. Now, we check that there
aren't exceptions, and that the error message is sent to the console.

* Scripts/run-gtk-tests:
(TestRunner):
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp:
(consoleMessageReceivedCallback):
(testWebContextSecurityFileXHR):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.14/Tools/ChangeLog (207097 => 207098)


--- releases/WebKitGTK/webkit-2.14/Tools/ChangeLog	2016-10-11 12:00:15 UTC (rev 207097)
+++ releases/WebKitGTK/webkit-2.14/Tools/ChangeLog	2016-10-11 12:01:09 UTC (rev 207098)
@@ -1,5 +1,22 @@
 2016-09-23  Carlos Garcia Campos  <[email protected]>
 
+        REGRESSION(r204163): [GTK] API test /webkit2/WebKitSecurityManager/file-xhr is failing
+        https://bugs.webkit.org/show_bug.cgi?id=161607
+
+        Reviewed by Michael Catanzaro.
+
+        Since r204163, in case of cross origin error when loading the XHR, the load fails and an error message is shown
+        in the console, but there isn't any js expcetion, which is what we were checking. Now, we check that there
+        aren't exceptions, and that the error message is sent to the console.
+
+        * Scripts/run-gtk-tests:
+        (TestRunner):
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp:
+        (consoleMessageReceivedCallback):
+        (testWebContextSecurityFileXHR):
+
+2016-09-23  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Make all WebView tests have a WebKitUserContentManager
         https://bugs.webkit.org/show_bug.cgi?id=162487
 

Modified: releases/WebKitGTK/webkit-2.14/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp (207097 => 207098)


--- releases/WebKitGTK/webkit-2.14/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp	2016-10-11 12:00:15 UTC (rev 207097)
+++ releases/WebKitGTK/webkit-2.14/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp	2016-10-11 12:01:09 UTC (rev 207098)
@@ -627,6 +627,13 @@
         | SecurityPolicyTest::CORSEnabled | SecurityPolicyTest::EmptyDocument);
 }
 
+static void consoleMessageReceivedCallback(WebKitUserContentManager*, WebKitJavascriptResult* message, WebKitJavascriptResult** result)
+{
+    g_assert(result);
+    g_assert(!*result);
+    *result = webkit_javascript_result_ref(message);
+}
+
 static void testWebContextSecurityFileXHR(WebViewTest* test, gconstpointer)
 {
     GUniquePtr<char> fileURL(g_strdup_printf("file://%s/simple.html", Test::getResourcesDir(Test::WebKit2Resources).data()));
@@ -636,11 +643,30 @@
     GUniquePtr<char> jsonURL(g_strdup_printf("file://%s/simple.json", Test::getResourcesDir().data()));
     GUniquePtr<char> xhr(g_strdup_printf("var xhr = new XMLHttpRequest; xhr.open(\"GET\", \"%s\"); xhr.send();", jsonURL.get()));
 
-    // By default file access is not allowed, this will fail with a cross-origin error.
+    WebKitJavascriptResult* consoleMessage = nullptr;
+    webkit_user_content_manager_register_script_message_handler(test->m_userContentManager.get(), "console");
+    g_signal_connect(test->m_userContentManager.get(), "script-message-received::console", G_CALLBACK(consoleMessageReceivedCallback), &consoleMessage);
+
+    // By default file access is not allowed, this will show a console message with a cross-origin error.
     GUniqueOutPtr<GError> error;
     WebKitJavascriptResult* _javascript_Result = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
-    g_assert(!_javascript_Result);
-    g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);
+    g_assert(_javascript_Result);
+    g_assert(!error);
+    g_assert(consoleMessage);
+    GUniquePtr<char> messageString(WebViewTest::_javascript_ResultToCString(consoleMessage));
+    GRefPtr<GVariant> variant = g_variant_parse(G_VARIANT_TYPE("(uusus)"), messageString.get(), nullptr, nullptr, nullptr);
+    g_assert(variant.get());
+    unsigned level;
+    const char* messageText;
+    g_variant_get(variant.get(), "(uu&su&s)", nullptr, &level, &messageText, nullptr, nullptr);
+    g_assert_cmpuint(level, ==, 3); // Console error message.
+    GUniquePtr<char> expectedErrorMessage(g_strdup_printf("XMLHttpRequest cannot load %s. Cross origin requests are only supported for HTTP.", jsonURL.get()));
+    g_assert_cmpstr(messageText, ==, expectedErrorMessage.get());
+    webkit_javascript_result_unref(consoleMessage);
+    consoleMessage = nullptr;
+    level = 0;
+    messageText = nullptr;
+    variant = nullptr;
 
     // Allow file access from file URLs.
     webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), TRUE);
@@ -654,9 +680,19 @@
     test->loadURI(kServer->getURIForPath("/").data());
     test->waitUntilLoadFinished();
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
-    g_assert(!_javascript_Result);
-    g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);
+    g_assert(_javascript_Result);
+    g_assert(!error);
+    g_assert(consoleMessage);
+    variant = g_variant_parse(G_VARIANT_TYPE("(uusus)"), messageString.get(), nullptr, nullptr, nullptr);
+    g_assert(variant.get());
+    g_variant_get(variant.get(), "(uu&su&s)", nullptr, &level, &messageText, nullptr, nullptr);
+    g_assert_cmpuint(level, ==, 3); // Console error message.
+    g_assert_cmpstr(messageText, ==, expectedErrorMessage.get());
+    webkit_javascript_result_unref(consoleMessage);
 
+    g_signal_handlers_disconnect_matched(test->m_userContentManager.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, &consoleMessage);
+    webkit_user_content_manager_unregister_script_message_handler(test->m_userContentManager.get(), "console");
+
     webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), FALSE);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to