Skip to content

Commit

Permalink
Fix file-url based tests not working with runInCrossOriginIFrame
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265985
rdar://119300316

Reviewed by Alex Christensen.

runInCrossOriginIFrame doesn't work with file:/// based tests as they
can't be loaded in an i-frame. This change instead runs those tests
via http whenever this option is enabled by using a new alias to the
root of the LayoutTests directory.

* Tools/Scripts/webkitpy/layout_tests/servers/aliases.json:
* Tools/Scripts/webkitpy/port/driver.py:
(Driver.is_http_test):
(Driver.test_to_uri):
(Driver.uri_to_test):
(Driver._command_from_driver_input):
(DriverProxy.is_http_test):
(DriverProxy.test_to_uri):

Canonical link: https://commits.webkit.org/272281@main
  • Loading branch information
Pascoe committed Dec 19, 2023
1 parent b77e480 commit 3a9c4b7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Tools/Scripts/webkitpy/layout_tests/servers/aliases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
["/modern-media-controls", "../Source/WebCore/Modules/modern-media-controls"],
["/resources/testharness.css", "resources/testharness.css"],
["/resources/testharness.js", "resources/testharness.js"],
["/resources/testharnessreport.js", "resources/testharnessreport.js"]
["/resources/testharnessreport.js", "resources/testharnessreport.js"],
["/root", "."]
]
31 changes: 19 additions & 12 deletions Tools/Scripts/webkitpy/port/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ def _command_wrapper(self):
WEBKIT_SPECIFIC_WEB_PLATFORM_TEST_SUBDIR = "http/wpt/"
WEBKIT_WEB_PLATFORM_TEST_SERVER_ROUTE = "WebKit/"

def is_http_test(self, test_name):
return test_name.startswith(self.HTTP_DIR) and not test_name.startswith(self.HTTP_LOCAL_DIR)
def is_http_test(self, driver_input):
if driver_input.self_comparison_header and "runInCrossOriginIFrame=true" in driver_input.self_comparison_header:
return True
return driver_input.test_name.startswith(self.HTTP_DIR) and not driver_input.test_name.startswith(self.HTTP_LOCAL_DIR)

def is_webkit_specific_web_platform_test(self, test_name):
return test_name.startswith(self.WEBKIT_SPECIFIC_WEB_PLATFORM_TEST_SUBDIR)
Expand Down Expand Up @@ -385,17 +387,19 @@ def is_secure_path(self, path):
def http_base_url(self, secure=None):
return "%s://127.0.0.1:%d/" % (('https', 8443) if secure else ('http', 8000))

def test_to_uri(self, test_name):
def test_to_uri(self, driver_input):
"""Convert a test name to a URI."""
test_name = driver_input.test_name
if self.is_web_platform_test(test_name):
return self.wpt_test_path_to_uri(test_name[len(self.web_platform_test_server_doc_root):])
if self.is_webkit_specific_web_platform_test(test_name):
return self.wpt_webkit_test_path_to_uri(self.WEBKIT_WEB_PLATFORM_TEST_SERVER_ROUTE + test_name[len(self.WEBKIT_SPECIFIC_WEB_PLATFORM_TEST_SUBDIR):])

if not self.is_http_test(test_name):
if not self.is_http_test(driver_input):
return path.abspath_to_uri(self._port.host.platform, self._port.abspath_for_test(test_name))

return self.http_test_path_to_uri(test_name[len(self.HTTP_DIR):])
if self.HTTP_DIR in test_name:
return self.http_test_path_to_uri(test_name[len(self.HTTP_DIR):])
return self.http_test_path_to_uri("root/" + test_name)

def uri_to_test(self, uri):
"""Return the base layout test name for a given URI.
Expand All @@ -419,6 +423,9 @@ def uri_to_test(self, uri):
if uri.startswith(self.web_platform_test_server_base_https_url):
return uri.replace(self.web_platform_test_server_base_https_url, self.web_platform_test_server_doc_root)
if uri.startswith("http://"):
base_url = self.http_base_url(secure=False)
if base_url + "root/" in uri:
return uri.replace(base_url + "root/", "")
return uri.replace(self.http_base_url(secure=False), self.HTTP_DIR)
if uri.startswith("https://"):
return uri.replace(self.http_base_url(secure=True), self.HTTP_DIR)
Expand Down Expand Up @@ -651,8 +658,8 @@ def _command_from_driver_input(self, driver_input):
# FIXME: performance tests pass in full URLs instead of test names.
if driver_input.test_name.startswith('http://') or driver_input.test_name.startswith('https://') or driver_input.test_name == ('about:blank'):
command = driver_input.test_name
elif self.is_web_platform_test(driver_input.test_name) or self.is_webkit_specific_web_platform_test(driver_input.test_name) or self.is_http_test(driver_input.test_name):
command = self.test_to_uri(driver_input.test_name)
elif self.is_web_platform_test(driver_input.test_name) or self.is_webkit_specific_web_platform_test(driver_input.test_name) or self.is_http_test(driver_input):
command = self.test_to_uri(driver_input)
command += "'--absolutePath'"
absPath = self._port.abspath_for_test(driver_input.test_name, self._target_host)
if sys.platform == 'cygwin':
Expand Down Expand Up @@ -850,8 +857,8 @@ def host(self):
return self._driver._target_host

# FIXME: this should be a @classmethod (or implemented on Port instead).
def is_http_test(self, test_name):
return self._driver.is_http_test(test_name)
def is_http_test(self, driver_input):
return self._driver.is_http_test(driver_input)

def is_web_platform_test(self, test_name):
return self._driver.is_web_platform_test(test_name)
Expand All @@ -860,8 +867,8 @@ def is_webkit_specific_web_platform_test(self, test_name):
return self._driver.is_webkit_specific_web_platform_test(test_name)

# FIXME: this should be a @classmethod (or implemented on Port instead).
def test_to_uri(self, test_name):
return self._driver.test_to_uri(test_name)
def test_to_uri(self, driver_input):
return self._driver.test_to_uri(driver_input)

# FIXME: this should be a @classmethod (or implemented on Port instead).
def uri_to_test(self, uri):
Expand Down
19 changes: 11 additions & 8 deletions Tools/Scripts/webkitpy/port/driver_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from webkitpy.common.system.systemhost_mock import MockSystemHost

from webkitpy.port import Port, Driver, DriverOutput
from webkitpy.port import Port, Driver, DriverInput, DriverOutput
from webkitpy.port.server_process_mock import MockServerProcess
from webkitpy.thirdparty.mock import patch

Expand Down Expand Up @@ -115,13 +115,15 @@ def test_profiler_and_wrapper(self):
def test_test_to_uri(self):
port = self.make_port()
driver = Driver(port, None, pixel_tests=False)
self.assertEqual(driver.test_to_uri('foo/bar.html'), 'file://%s/foo/bar.html' % port.layout_tests_dir())
self.assertEqual(driver.test_to_uri('http/tests/foo.html'), 'http://127.0.0.1:8000/foo.html')
self.assertEqual(driver.test_to_uri('http/tests/ssl/bar.html'), 'https://127.0.0.1:8443/ssl/bar.html')
self.assertEqual(driver.test_to_uri('imported/w3c/web-platform-tests/foo/bar.html'), 'http://localhost:8800/foo/bar.html')
self.assertEqual(driver.test_to_uri('imported/w3c/web-platform-tests/foo/bar.https.html'), 'https://localhost:9443/foo/bar.https.html')
self.assertEqual(driver.test_to_uri('http/wpt/bar2.html'), 'http://localhost:8800/WebKit/bar2.html')
self.assertEqual(driver.test_to_uri('http/wpt/bar2.https.html'), 'https://localhost:9443/WebKit/bar2.https.html')

self.assertEqual(driver.test_to_uri(DriverInput('foo/bar.html', 1000, None, None)), 'file://%s/foo/bar.html' % port.layout_tests_dir())
self.assertEqual(driver.test_to_uri(DriverInput('foo/bar.html', 1000, None, None, self_comparison_header='runInCrossOriginIFrame=true')), 'http://127.0.0.1:8000/root/foo/bar.html')
self.assertEqual(driver.test_to_uri(DriverInput('http/tests/foo.html', 1000, None, None)), 'http://127.0.0.1:8000/foo.html')
self.assertEqual(driver.test_to_uri(DriverInput('http/tests/ssl/bar.html', 1000, None, None)), 'https://127.0.0.1:8443/ssl/bar.html')
self.assertEqual(driver.test_to_uri(DriverInput('imported/w3c/web-platform-tests/foo/bar.html', 1000, None, None)), 'http://localhost:8800/foo/bar.html')
self.assertEqual(driver.test_to_uri(DriverInput('imported/w3c/web-platform-tests/foo/bar.https.html', 1000, None, None)), 'https://localhost:9443/foo/bar.https.html')
self.assertEqual(driver.test_to_uri(DriverInput('http/wpt/bar2.html', 1000, None, None)), 'http://localhost:8800/WebKit/bar2.html')
self.assertEqual(driver.test_to_uri(DriverInput('http/wpt/bar2.https.html', 1000, None, None)), 'https://localhost:9443/WebKit/bar2.https.html')

def test_uri_to_test(self):
port = self.make_port()
Expand All @@ -133,6 +135,7 @@ def test_uri_to_test(self):
self.assertEqual(driver.uri_to_test('http://localhost:8800/foo/bar.html'), 'imported/w3c/web-platform-tests/foo/bar.html')
self.assertEqual(driver.uri_to_test('http://localhost:8800/WebKit/bar2.html'), 'http/wpt/bar2.html')
self.assertEqual(driver.uri_to_test('https://localhost:9443/WebKit/bar2.https.html'), 'http/wpt/bar2.https.html')
self.assertEqual(driver.uri_to_test('http://127.0.0.1:8000/root/foo/bar.html'), 'foo/bar.html')

def test_read_block(self):
port = TestWebKitPort()
Expand Down

0 comments on commit 3a9c4b7

Please sign in to comment.