def uri_to_test(self, uri): """Return the base web test name for a given URI. This returns the test name for a given URI, e.g., if you passed in "file:///src/web_tests/fast/html/keygen.html" it would return "fast/html/keygen.html". """ if uri.startswith('file:///'): prefix = path.abspath_to_uri(self._port.host.platform, self._port.web_tests_dir()) if not prefix.endswith('/'): prefix += '/' return uri[len(prefix):] for prefix in self._get_uri_prefixes(*self.HTTP_HOST_AND_PORTS): if uri.startswith(prefix): return self.HTTP_DIR + uri[len(prefix):] for prefix in self._get_uri_prefixes(*self.WPT_HOST_AND_PORTS): if uri.startswith(prefix): url_path = '/' + uri[len(prefix):] for wpt_path, url_prefix in self.WPT_DIRS.items(): if url_path.startswith(url_prefix): return wpt_path + '/' + url_path[len(url_prefix):] raise NotImplementedError('unknown url type: %s' % uri)
def uri_to_test(self, uri): """Return the base layout test name for a given URI. This returns the test name for a given URI, e.g., if you passed in "file:///src/LayoutTests/fast/html/keygen.html" it would return "fast/html/keygen.html". """ # This looks like a bit of a hack, since the uri is used instead of test name. hostname, insecure_port, secure_port = self._get_http_host_and_ports_for_test( uri) if uri.startswith('file:///'): prefix = path.abspath_to_uri(self._port.host.platform, self._port.layout_tests_dir()) if not prefix.endswith('/'): prefix += '/' return uri[len(prefix):] if uri.startswith('http://'): return uri.replace('http://%s:%d/' % (hostname, insecure_port), self.HTTP_DIR) if uri.startswith('https://'): return uri.replace('https://%s:%d/' % (hostname, secure_port), self.HTTP_DIR) raise NotImplementedError('unknown url type: %s' % uri)
def test_to_uri(self, test_name): """Convert a test name to a URI. Tests which have an 'https' directory in their paths or '.https.' or '.serviceworker.' in their name will be loaded over HTTPS; all other tests over HTTP. Example paths loaded over HTTPS: http/tests/security/mixedContent/https/test1.html http/tests/security/mixedContent/test1.https.html external/wpt/encoding/idlharness.any.serviceworker.html """ using_wptserve = self._port.should_use_wptserve(test_name) if not self.is_http_test(test_name) and not using_wptserve: return path.abspath_to_uri(self._port.host.platform, self._port.abspath_for_test(test_name)) if using_wptserve: test_dir_prefix = self.WPT_DIR hostname, insecure_port, secure_port = self.WPT_HOST_AND_PORTS else: test_dir_prefix = self.HTTP_DIR hostname, insecure_port, secure_port = self.HTTP_HOST_AND_PORTS relative_path = test_name[len(test_dir_prefix):] if '/https/' in test_name or '.https.' in test_name or '.serviceworker.' in test_name: return 'https://%s:%d/%s' % (hostname, secure_port, relative_path) return 'http://%s:%d/%s' % (hostname, insecure_port, relative_path)
def test_to_uri(self, test_name): """Convert a test name to a URI. Tests which have an 'https' directory in their paths (e.g. '/http/tests/security/mixedContent/https/test1.html') or '.https.' in their name (e.g. 'http/tests/security/mixedContent/test1.https.html') will be loaded over HTTPS; all other tests over HTTP. """ using_wptserve = self._port.should_use_wptserve(test_name) if not self.is_http_test(test_name) and not using_wptserve: return path.abspath_to_uri(self._port.host.platform, self._port.abspath_for_test(test_name)) if using_wptserve: test_dir_prefix = self.WPT_DIR else: test_dir_prefix = self.HTTP_DIR relative_path = test_name[len(test_dir_prefix):] hostname, insecure_port, secure_port = self._get_http_host_and_ports_for_test( test_name) if '/https/' in test_name or '.https.' in test_name: return 'https://%s:%d/%s' % (hostname, secure_port, relative_path) return 'http://%s:%d/%s' % (hostname, insecure_port, relative_path)
def test_to_uri(self, test_name): """Convert a test name to a URI. Tests which have an 'https' directory in their paths or '.https.' or '.serviceworker.' in their name will be loaded over HTTPS; all other tests over HTTP. Example paths loaded over HTTPS: http/tests/security/mixedContent/https/test1.html http/tests/security/mixedContent/test1.https.html external/wpt/encoding/idlharness.any.serviceworker.html """ using_wptserve = self._port.should_use_wptserve(test_name) if not self.is_http_test(test_name) and not using_wptserve: return path.abspath_to_uri(self._port.host.platform, self._port.abspath_for_test(test_name)) if using_wptserve: for wpt_path, url_prefix in self.WPT_DIRS.items(): # The keys of WPT_DIRS do not have trailing slashes. wpt_path += '/' if test_name.startswith(wpt_path): test_dir_prefix = wpt_path test_url_prefix = url_prefix break else: # We really shouldn't reach here, but in case we do, fail gracefully. _log.error('Unrecognized WPT test name: %s', test_name) test_dir_prefix = 'external/wpt/' test_url_prefix = '/' hostname, insecure_port, secure_port = self.WPT_HOST_AND_PORTS if '.www.' in test_name: hostname = "www.%s" % hostname if '.h2.' in test_name: secure_port = self.WPT_H2_PORT else: test_dir_prefix = self.HTTP_DIR test_url_prefix = '/' hostname, insecure_port, secure_port = self.HTTP_HOST_AND_PORTS relative_path = test_name[len(test_dir_prefix):] if ('/https/' in test_name or '.https.' in test_name or '.h2.' in test_name or '.serviceworker.' in test_name or '.serviceworker-module.' in test_name): return 'https://%s:%d%s%s' % (hostname, secure_port, test_url_prefix, relative_path) return 'http://%s:%d%s%s' % (hostname, insecure_port, test_url_prefix, relative_path)
def test_abspath_to_uri_escaping_unixy(self): self.assertEqual( path.abspath_to_uri(MockPlatformInfo(), '/foo/bar + baz%?.html'), 'file:///foo/bar%20+%20baz%25%3F.html')
def test_abspath_to_uri_win(self): if sys.platform != 'win32': return self.assertEqual( path.abspath_to_uri(self.platform_info(), 'c:\\foo\\bar.html'), 'file:///c:/foo/bar.html')
def test_abspath_to_uri_unixy(self): self.assertEqual( path.abspath_to_uri(MockPlatformInfo(), '/foo/bar.html'), 'file:///foo/bar.html')