def test_abspath_to_uri_escaping_cygwin(self): if sys.platform != "cygwin": return self.assertEqual( path.abspath_to_uri(self.platforminfo(), "/cygdrive/c/foo/bar + baz%.html"), "file:///C:/foo/bar%20+%20baz%25.html", )
def filename_to_uri(self, filename): """Convert a test file (which is an absolute path) to a URI.""" LAYOUTTEST_HTTP_DIR = "http/tests/" LAYOUTTEST_WEBSOCKET_DIR = "http/tests/websocket/tests/" relative_path = self.relative_test_filename(filename) port = None use_ssl = False if (relative_path.startswith(LAYOUTTEST_WEBSOCKET_DIR) or relative_path.startswith(LAYOUTTEST_HTTP_DIR)): relative_path = relative_path[len(LAYOUTTEST_HTTP_DIR):] port = 8000 # Make http/tests/local run as local files. This is to mimic the # logic in run-webkit-tests. # # TODO(dpranke): remove the media reference and the SSL reference? if (port and not relative_path.startswith("local/") and not relative_path.startswith("media/")): if relative_path.startswith("ssl/"): port += 443 protocol = "https" else: protocol = "http" return "%s://127.0.0.1:%u/%s" % (protocol, port, relative_path) return abspath_to_uri(os.path.abspath(filename))
def test_to_uri(self, test_name): """Convert a test name to a URI.""" LAYOUTTEST_HTTP_DIR = "http/tests/" LAYOUTTEST_WEBSOCKET_DIR = "http/tests/websocket/tests/" port = None relative_path = test_name if (relative_path.startswith(LAYOUTTEST_WEBSOCKET_DIR) or relative_path.startswith(LAYOUTTEST_HTTP_DIR)): relative_path = relative_path[len(LAYOUTTEST_HTTP_DIR):] port = 8000 # Make http/tests/local run as local files. This is to mimic the # logic in run-webkit-tests. # # TODO(dpranke): remove the SSL reference? if (port and not relative_path.startswith("local/")): if relative_path.startswith("ssl/"): port += 443 protocol = "https" else: protocol = "http" return "%s://127.0.0.1:%u/%s" % (protocol, port, relative_path) return path.abspath_to_uri(self.abspath_for_test(test_name))
def uri_to_test_name(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". """ test = uri if uri.startswith("file:///"): prefix = path.abspath_to_uri(self.layout_tests_dir()) + "/" return test[len(prefix):] if uri.startswith("http://127.0.0.1:8880/"): # websocket tests return test.replace('http://127.0.0.1:8880/', '') if uri.startswith("http://"): # regular HTTP test return test.replace('http://127.0.0.1:8000/', 'http/tests/') if uri.startswith("https://"): return test.replace('https://127.0.0.1:8443/', 'http/tests/') raise NotImplementedError('unknown url type: %s' % uri)
def test_basic(self): options, args = parse_args(tests_included=True) logging_stream = StringIO.StringIO() host = MockHost() port_obj = host.port_factory.get(options.platform, options) details = run_webkit_tests.run(port_obj, options, args, logging_stream) # These numbers will need to be updated whenever we add new tests. self.assertEqual(details.initial_results.total, test.TOTAL_TESTS) self.assertEqual(details.initial_results.expected_skips, test.TOTAL_SKIPS) self.assertEqual(len(details.initial_results.unexpected_results_by_name), test.UNEXPECTED_PASSES + test.UNEXPECTED_FAILURES) self.assertEqual(details.exit_code, test.UNEXPECTED_FAILURES) self.assertEqual(details.retry_results.total, test.TOTAL_RETRIES) one_line_summary = "%d tests ran as expected, %d didn't:\n" % ( details.initial_results.total - details.initial_results.expected_skips - len(details.initial_results.unexpected_results_by_name), len(details.initial_results.unexpected_results_by_name)) self.assertTrue(one_line_summary in logging_stream.buflist) # Ensure the results were summarized properly. self.assertEqual(details.summarized_results['num_regressions'], details.exit_code) # Ensure the image diff percentage is in the results. self.assertEqual(details.summarized_results['tests']['failures']['expected']['image.html']['image_diff_percent'], 1) # Ensure the results were written out and displayed. full_results_text = host.filesystem.read_text_file('/tmp/layout-test-results/full_results.json') json_to_eval = full_results_text.replace("ADD_RESULTS(", "").replace(");", "") self.assertEqual(json.loads(json_to_eval), details.summarized_results) self.assertEqual(host.user.opened_urls, [path.abspath_to_uri(MockHost().platform, '/tmp/layout-test-results/results.html')])
def test_results_directory_default(self): # We run a configuration that should fail, to generate output, then # look for what the output results url was. # This is the default location. _, _, user = logging_run(tests_included=True) self.assertEqual(user.opened_urls, [path.abspath_to_uri(MockHost().platform, '/tmp/layout-test-results/results.html')])
def test_results_directory_absolute(self): # We run a configuration that should fail, to generate output, then # look for what the output results url was. host = MockHost() with host.filesystem.mkdtemp() as tmpdir: _, _, user = logging_run(['--results-directory=' + str(tmpdir)], tests_included=True, host=host) self.assertEqual(user.opened_urls, [path.abspath_to_uri(host.platform, host.filesystem.join(tmpdir, 'results.html'))])
def test_results_directory_relative(self): # We run a configuration that should fail, to generate output, then # look for what the output results url was. host = MockHost() host.filesystem.maybe_make_directory('/tmp/cwd') host.filesystem.chdir('/tmp/cwd') _, _, user = logging_run(['--results-directory=foo'], tests_included=True, host=host) self.assertEqual(user.opened_urls, [path.abspath_to_uri(host.platform, '/tmp/cwd/foo/results.html')])
def test_test_to_uri(self): port = Port() layout_test_dir = port.layout_tests_dir() test = 'foo/bar.html' path = port._filesystem.join(layout_test_dir, test) if sys.platform == 'win32': path = path.replace("\\", "/") self.assertEqual(port.test_to_uri(test), abspath_to_uri(path))
def test_unexpected_failures(self): # Run tests including the unexpected failures. self._url_opened = None res, out, err, user = logging_run(tests_included=True) self.assertEqual(res, unexpected_tests_count) self.assertFalse(out.empty()) self.assertFalse(err.empty()) self.assertEqual(user.opened_urls, [path.abspath_to_uri('/tmp/layout-test-results/results.html')])
def test_unexpected_failures(self): # Run tests including the unexpected failures. self._url_opened = None res, out, err, user = logging_run(tests_included=True) self.assertEqual(res, unexpected_tests_count) self.assertNotEmpty(out) self.assertNotEmpty(err) self.assertEqual(user.opened_urls, [path.abspath_to_uri(MockHost().platform, '/tmp/layout-test-results/results.html')])
def test_to_uri(self, test_name): """Convert a test name to a URI.""" if not self.is_http_test(test_name): return path.abspath_to_uri(self._port.host.platform, self._port.abspath_for_test(test_name)) relative_path = test_name[len(self.HTTP_DIR):] # TODO(dpranke): remove the SSL reference? if relative_path.startswith("ssl/"): return "https://127.0.0.1:8443/" + relative_path return "http://127.0.0.1:8000/" + 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') will be loaded over HTTPS; all other tests over HTTP. """ if not self.is_http_test(test_name): return path.abspath_to_uri(self._port.host.platform, self._port.abspath_for_test(test_name)) if "/https/" in test_name: return "https://127.0.0.1:8443/" + test_name return "http://127.0.0.1:8000/" + test_name
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". """ if uri.startswith("file:///"): return uri[len(path.abspath_to_uri(self._port.layout_tests_dir()) + "/") :] if uri.startswith("http://"): return uri.replace("http://127.0.0.1:8000/", self.HTTP_DIR) if uri.startswith("https://"): return uri.replace("https://127.0.0.1:8443/", self.HTTP_DIR) raise NotImplementedError("unknown url type: %s" % uri)
def test_filename_to_uri(self): port = base.Port() layout_test_dir = port.layout_tests_dir() test_file = port._filesystem.join(layout_test_dir, "foo", "bar.html") # On Windows, absolute paths are of the form "c:\foo.txt". However, # all current browsers (except for Opera) normalize file URLs by # prepending an additional "/" as if the absolute path was # "/c:/foo.txt". This means that all file URLs end up with "file:///" # at the beginning. if sys.platform == "win32": prefix = "file:///" path = test_file.replace("\\", "/") else: prefix = "file://" path = test_file self.assertEqual(port.filename_to_uri(test_file), abspath_to_uri(test_file))
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". """ 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://127.0.0.1:8000/', self.HTTP_DIR) if uri.startswith("https://"): return uri.replace('https://127.0.0.1:8443/', self.HTTP_DIR) 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 (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 show_results_html_file(self, results_filename): self._run_script('run-safari', [abspath_to_uri(SystemHost().platform, results_filename)])
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_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.platforminfo(), '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')
def test_filename_to_uri(self): port = base.Port() layout_test_dir = port.layout_tests_dir() test_file = os.path.join(layout_test_dir, "foo", "bar.html") self.assertEqual(port.filename_to_uri(test_file), abspath_to_uri(test_file, Executive()))
def test_abspath_to_uri_escaping_cygwin(self): if sys.platform != 'cygwin': return self.assertEqual(path.abspath_to_uri(self.platforminfo(), '/cygdrive/c/foo/bar + baz%.html'), 'file:///C:/foo/bar%20+%20baz%25.html')
def abspath_to_uri(self, filename): """Converts an absolute path to a file: URI.""" return path.abspath_to_uri(filename, self._executive)
def show_results_html_file(self, results_filename): self.run_minibrowser( [path.abspath_to_uri(self.host.platform, results_filename)])
def abspath_to_uri(self, filename): """Converts an absolute path to a file: URI.""" return path.abspath_to_uri(filename, self._port._executive)
def show_results_html_file(self, results_filename): self._run_script("run-minibrowser", [path.abspath_to_uri(self.host.platform, results_filename)])
def test_abspath_to_uri_win(self): if not sys.platform.startswith('win'): return self.assertEqual(path.abspath_to_uri(self.platforminfo(), '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')
def test_abspath_to_uri_cygwin(self): if sys.platform != 'cygwin': return self.assertEqual(path.abspath_to_uri(self.platforminfo(), '/cygdrive/c/foo/bar.html'), 'file:///C:/foo/bar.html')
def show_results_html_file(self, results_filename): self._run_script('run-safari', [abspath_to_uri(results_filename)])
def test_abspath_to_uri_cygwin(self): if sys.platform != "cygwin": return self.assertEquals( path.abspath_to_uri(self.platforminfo(), "/cygdrive/c/foo/bar.html"), "file:///C:/foo/bar.html" )
def show_results_html_file(self, results_filename): self._run_script( 'run-safari', [abspath_to_uri(SystemHost().platform, results_filename)])
def test_abspath_to_uri_win(self): if sys.platform != "win32": return self.assertEquals(path.abspath_to_uri(self.platforminfo(), "c:\\foo\\bar.html"), "file:///c:/foo/bar.html")
def test_abspath_to_uri_win(self): if not sys.platform.startswith('win'): return self.assertEqual( path.abspath_to_uri(self.platforminfo(), 'c:\\foo\\bar.html'), 'file:///c:/foo/bar.html')