Tools/ChangeLog

 12021-08-01 Lauro Moura <lmoura@igalia.com>
 2
 3 [GLIB] Make CORS allowlist test wait for promise resolution
 4 https://bugs.webkit.org/show_bug.cgi?id=228695
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 r278456 introduced a CORS allow list test that tries to fetch a
 9 resource using the fetch() function, which returns a promise. This is
 10 working on GTK but in WPE the test fails as the promise is not yet
 11 resolved by the time the test variable is checked.
 12
 13 This commit changes the test to actually report the promise failure
 14 through catch() and wait for its resolution before checking the values.
 15
 16 * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
 17 (testWebViewCORSAllowlist):
 18
1192021-07-30 Jonathan Bedard <jbedard@apple.com>
220
321 [git-webkit] Forward errors from log and blame

Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp

@@static void testWebViewCORSAllowlist(WebViewTest* test, gconstpointer)
16181618 webkit_uri_scheme_request_finish(request, inputStream.get(), strlen(data), "text/html");
16191619 }, nullptr, nullptr);
16201620
1621  char html[] = "<html><script>let foo = 0; fetch('foo://bar/baz').then(response => { if (response.status === 200) foo = 42});</script></html>";
1622  webkit_web_view_load_html(test->m_webView, html, "http://example.com");
1623  test->waitUntilLoadFinished();
 1621 char html[] = "<html><script>let foo = 0; fetch('foo://bar/baz').then(response => { foo = response.status; }).catch(err => { foo = -1; });</script></html>";
 1622
 1623 auto waitForFooChanged = [&test]() {
 1624 GUniqueOutPtr<GError> error;
 1625 WebKitJavascriptResult* result;
 1626 JSCValue* jscvalue;
 1627 int value;
 1628 do {
 1629 result = test->runJavaScriptAndWaitUntilFinished("foo;", &error.outPtr());
 1630 g_assert_no_error(error.get());
 1631 jscvalue = webkit_javascript_result_get_js_value(result);
 1632 value = jsc_value_to_int32(jscvalue);
 1633 webkit_javascript_result_unref(result);
 1634 } while (!value);
 1635 return value;
 1636 };
16241637
16251638 // Request is not allowed, foo should be 0.
1626  GUniqueOutPtr<GError> error;
1627  WebKitJavascriptResult* result = test->runJavaScriptAndWaitUntilFinished("foo;", &error.outPtr());
1628  g_assert_no_error(error.get());
1629  JSCValue* value = webkit_javascript_result_get_js_value(result);
1630  g_assert_cmpint(jsc_value_to_int32(value), ==, 0);
1631  webkit_javascript_result_unref(result);
 1639 webkit_web_view_load_html(test->m_webView, html, "http://example.com");
 1640 test->waitUntilLoadFinished();
 1641 g_assert_cmpint(waitForFooChanged(), ==, -1);
16321642
16331643 // Allowlisting host alone does not work. Path is also required. foo should remain 0.
16341644 GUniquePtr<char*> allowlist(g_new(char*, 2));

@@static void testWebViewCORSAllowlist(WebViewTest* test, gconstpointer)
16381648
16391649 webkit_web_view_load_html(test->m_webView, html, "http://example.com");
16401650 test->waitUntilLoadFinished();
1641  result = test->runJavaScriptAndWaitUntilFinished("foo;", &error.outPtr());
1642  g_assert_no_error(error.get());
1643  value = webkit_javascript_result_get_js_value(result);
1644  g_assert_cmpint(jsc_value_to_int32(value), ==, 0);
1645  webkit_javascript_result_unref(result);
 1651 g_assert_cmpint(waitForFooChanged(), ==, -1);
16461652
16471653 // Finally let's properly allow our scheme. foo should now change to 42 when the request succeeds.
16481654 allowlist.reset(g_new(char*, 2));

@@static void testWebViewCORSAllowlist(WebViewTest* test, gconstpointer)
16521658
16531659 webkit_web_view_load_html(test->m_webView, html, "http://example.com");
16541660 test->waitUntilLoadFinished();
1655  result = test->runJavaScriptAndWaitUntilFinished("foo;", &error.outPtr());
1656  g_assert_no_error(error.get());
1657  value = webkit_javascript_result_get_js_value(result);
1658  g_assert_cmpint(jsc_value_to_int32(value), ==, 42);
1659  webkit_javascript_result_unref(result);
 1661 g_assert_cmpint(waitForFooChanged(), ==, 200);
16601662}
16611663
16621664#if USE(SOUP2)