Commit d96c4bde authored by dpranke@chromium.org's avatar dpranke@chromium.org

webkitpy: clean up test/uri conversion routines

https://bugs.webkit.org/show_bug.cgi?id=75648

Reviewed by Eric Seidel.

This change moves test_to_uri and uri_to_test from the Port
class to the Driver class (the routines were only being
called by the drivers), and removes a bunch of stale and/or
busted logic.

* Scripts/webkitpy/layout_tests/port/base.py:
* Scripts/webkitpy/layout_tests/port/base_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium.py:
* Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
* Scripts/webkitpy/layout_tests/port/driver.py:
(is_http_test):
(test_to_uri):
(uri_to_test):
* Scripts/webkitpy/layout_tests/port/mock_drt.py:
(run_one_test):
* Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py:
(MockDRTTest.input_line):
(input_line):
(expected_output):
* Scripts/webkitpy/layout_tests/port/test.py:
* Scripts/webkitpy/layout_tests/port/webkit.py:
(_command_from_driver_input):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104340 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2c2bf5b4
2012-01-05 Dirk Pranke <dpranke@chromium.org>
webkitpy: clean up test/uri conversion routines
https://bugs.webkit.org/show_bug.cgi?id=75648
Reviewed by Eric Seidel.
This change moves test_to_uri and uri_to_test from the Port
class to the Driver class (the routines were only being
called by the drivers), and removes a bunch of stale and/or
busted logic.
* Scripts/webkitpy/layout_tests/port/base.py:
* Scripts/webkitpy/layout_tests/port/base_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium.py:
* Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
* Scripts/webkitpy/layout_tests/port/driver.py:
(is_http_test):
(test_to_uri):
(uri_to_test):
* Scripts/webkitpy/layout_tests/port/mock_drt.py:
(run_one_test):
* Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py:
(MockDRTTest.input_line):
(input_line):
(expected_output):
* Scripts/webkitpy/layout_tests/port/test.py:
* Scripts/webkitpy/layout_tests/port/webkit.py:
(_command_from_driver_input):
2012-01-06 Simon Fraser <simon.fraser@apple.com> 2012-01-06 Simon Fraser <simon.fraser@apple.com>
Mitigate scrollbar differences when running pixel tests Mitigate scrollbar differences when running pixel tests
...@@ -39,6 +39,7 @@ import os ...@@ -39,6 +39,7 @@ import os
import re import re
from webkitpy.common.memoized import memoized from webkitpy.common.memoized import memoized
from webkitpy.common.system import path
# Handle Python < 2.6 where multiprocessing isn't available. # Handle Python < 2.6 where multiprocessing isn't available.
...@@ -49,7 +50,6 @@ except ImportError: ...@@ -49,7 +50,6 @@ except ImportError:
from webkitpy.common import find_files from webkitpy.common import find_files
from webkitpy.common.system import logutils from webkitpy.common.system import logutils
from webkitpy.common.system import path
from webkitpy.common.system.executive import ScriptError from webkitpy.common.system.executive import ScriptError
from webkitpy.common.system.systemhost import SystemHost from webkitpy.common.system.systemhost import SystemHost
from webkitpy.layout_tests import read_checksum_from_png from webkitpy.layout_tests import read_checksum_from_png
...@@ -461,33 +461,6 @@ class Port(object): ...@@ -461,33 +461,6 @@ class Port(object):
filename = self._filesystem.join(self.layout_tests_dir(), test_name) filename = self._filesystem.join(self.layout_tests_dir(), test_name)
return filename in reftest_list return filename in reftest_list
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 tests(self, paths): def tests(self, paths):
"""Return the list of tests found.""" """Return the list of tests found."""
# When collecting test cases, skip these directories # When collecting test cases, skip these directories
...@@ -567,32 +540,6 @@ class Port(object): ...@@ -567,32 +540,6 @@ class Port(object):
""" """
self._filesystem.write_binary_file(baseline_path, data) self._filesystem.write_binary_file(baseline_path, data)
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 layout_tests_dir(self): def layout_tests_dir(self):
"""Return the absolute path to the top of the LayoutTests directory.""" """Return the absolute path to the top of the LayoutTests directory."""
return self.path_from_webkit_base('LayoutTests') return self.path_from_webkit_base('LayoutTests')
......
...@@ -226,16 +226,6 @@ class PortTest(unittest.TestCase): ...@@ -226,16 +226,6 @@ class PortTest(unittest.TestCase):
self.assertTrue('canvas' in dirs) self.assertTrue('canvas' in dirs)
self.assertTrue('css2.1' in dirs) self.assertTrue('css2.1' in dirs)
def test_test_to_uri(self):
port = self.make_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_get_option__set(self): def test_get_option__set(self):
options, args = optparse.OptionParser().parse_args([]) options, args = optparse.OptionParser().parse_args([])
options.foo = 'bar' options.foo = 'bar'
......
...@@ -524,7 +524,7 @@ class ChromiumDriver(Driver): ...@@ -524,7 +524,7 @@ class ChromiumDriver(Driver):
has_audio = False has_audio = False
has_base64 = False has_base64 = False
uri = self._port.test_to_uri(driver_input.test_name) uri = self.test_to_uri(driver_input.test_name)
cmd = self._test_shell_command(uri, driver_input.timeout, driver_input.image_hash) cmd = self._test_shell_command(uri, driver_input.timeout, driver_input.image_hash)
line, crash = self._write_command_and_read_line(input=cmd) line, crash = self._write_command_and_read_line(input=cmd)
......
...@@ -98,7 +98,7 @@ class ChromiumDriverTest(unittest.TestCase): ...@@ -98,7 +98,7 @@ class ChromiumDriverTest(unittest.TestCase):
raise IOError raise IOError
self.driver._proc.stdout.readline = mock_readline self.driver._proc.stdout.readline = mock_readline
self.driver._port.test_to_uri = lambda test: 'mocktesturi' self.driver.test_to_uri = lambda test: 'mocktesturi'
driver_output = self.driver.run_test(DriverInput(test_name='some/test.html', timeout=1, image_hash=None, is_reftest=False)) driver_output = self.driver.run_test(DriverInput(test_name='some/test.html', timeout=1, image_hash=None, is_reftest=False))
self.assertEqual(self.driver._port.driver_name(), driver_output.crashed_process_name) self.assertEqual(self.driver._port.driver_name(), driver_output.crashed_process_name)
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
import shlex import shlex
from webkitpy.common.system import path
class DriverInput(object): class DriverInput(object):
def __init__(self, test_name, timeout, image_hash, is_reftest): def __init__(self, test_name, timeout, image_hash, is_reftest):
...@@ -91,6 +93,40 @@ class Driver(object): ...@@ -91,6 +93,40 @@ class Driver(object):
# used by e.g. tools/valgrind/valgrind_tests.py. # used by e.g. tools/valgrind/valgrind_tests.py.
return shlex.split(wrapper_option) if wrapper_option else [] return shlex.split(wrapper_option) if wrapper_option else []
HTTP_DIR = "http/tests/"
HTTP_LOCAL_DIR = "http/tests/local/"
def is_http_test(self, test_name):
return test_name.startswith(self.HTTP_DIR) and not test_name.startswith(self.HTTP_LOCAL_DIR)
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.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 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 has_crashed(self): def has_crashed(self):
return False return False
...@@ -113,6 +149,15 @@ class DriverProxy(object): ...@@ -113,6 +149,15 @@ class DriverProxy(object):
else: else:
self._reftest_driver = driver_instance_constructor(port, worker_number, pixel_tests=True) self._reftest_driver = driver_instance_constructor(port, worker_number, pixel_tests=True)
def is_http_test(self, test_name):
return self._driver.is_http_test(test_name)
def test_to_uri(self, test_name):
return self._driver.test_to_uri(test_name)
def uri_to_test(self, uri):
return self._driver.uri_to_test(uri)
def run_test(self, driver_input): def run_test(self, driver_input):
if driver_input.is_reftest: if driver_input.is_reftest:
return self._reftest_driver.run_test(driver_input) return self._reftest_driver.run_test(driver_input)
......
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys
import unittest
from webkitpy.common.system.path import abspath_to_uri
from webkitpy.common.host_mock import MockHost
from webkitpy.layout_tests.port import Port, Driver, DriverOutput
class DriverTest(unittest.TestCase):
def make_port(self):
return Port(MockHost())
def _assert_wrapper(self, wrapper_string, expected_wrapper):
wrapper = Driver(Port(MockHost()), None, pixel_tests=False)._command_wrapper(wrapper_string)
self.assertEqual(wrapper, expected_wrapper)
def test_command_wrapper(self):
self._assert_wrapper(None, [])
self._assert_wrapper("valgrind", ["valgrind"])
# Validate that shlex works as expected.
command_with_spaces = "valgrind --smc-check=\"check with spaces!\" --foo"
expected_parse = ["valgrind", "--smc-check=check with spaces!", "--foo"]
self._assert_wrapper(command_with_spaces, expected_parse)
def test_test_to_uri(self):
port = self.make_port()
driver = Driver(port, None, pixel_tests=False)
if sys.platform in ('cygwin', 'win32'):
self.assertEqual(driver.test_to_uri('foo/bar.html'), 'file:///%s/foo/bar.html' % port.layout_tests_dir())
else:
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')
def test_uri_to_test(self):
port = self.make_port()
driver = Driver(port, None, pixel_tests=False)
if sys.platform in ('cygwin', 'win32'):
self.assertEqual(driver.uri_to_test('file:///%s/foo/bar.html' % port.layout_tests_dir()), 'foo/bar.html')
else:
self.assertEqual(driver.uri_to_test('file://%s/foo/bar.html' % port.layout_tests_dir()), 'foo/bar.html')
self.assertEqual(driver.uri_to_test('http://127.0.0.1:8000/foo.html'), 'http/tests/foo.html')
self.assertEqual(driver.uri_to_test('https://127.0.0.1:8443/ssl/bar.html'), 'http/tests/ssl/bar.html')
if __name__ == '__main__':
unittest.main()
...@@ -186,6 +186,7 @@ class MockDRT(object): ...@@ -186,6 +186,7 @@ class MockDRT(object):
if options.platform: if options.platform:
port_name = options.platform port_name = options.platform
self._port = PortFactory(host).get(port_name=port_name, options=options) self._port = PortFactory(host).get(port_name=port_name, options=options)
self._driver = self._port.create_driver(0)
def run(self): def run(self):
while True: while True:
...@@ -200,8 +201,8 @@ class MockDRT(object): ...@@ -200,8 +201,8 @@ class MockDRT(object):
def run_one_test(self, test_input): def run_one_test(self, test_input):
port = self._port port = self._port
if test_input.uri.startswith('http'): if test_input.uri.startswith('http://') or test_input.uri.startswith('https://'):
test_name = port.uri_to_test_name(test_input.uri) test_name = self._driver.uri_to_test(test_input.uri)
else: else:
test_name = port.relative_test_filename(test_input.uri) test_name = port.relative_test_filename(test_input.uri)
...@@ -256,7 +257,7 @@ class MockChromiumDRT(MockDRT): ...@@ -256,7 +257,7 @@ class MockChromiumDRT(MockDRT):
def run_one_test(self, test_input): def run_one_test(self, test_input):
port = self._port port = self._port
test_name = self._port.uri_to_test_name(test_input.uri) test_name = self._driver.uri_to_test(test_input.uri)
actual_text = port.expected_text(test_name) actual_text = port.expected_text(test_name)
actual_image = '' actual_image = ''
......
...@@ -89,7 +89,7 @@ class MockDRTPortTest(port_testcase.PortTestCase): ...@@ -89,7 +89,7 @@ class MockDRTPortTest(port_testcase.PortTestCase):
class MockDRTTest(unittest.TestCase): class MockDRTTest(unittest.TestCase):
def input_line(self, port, test_name, checksum=None): def input_line(self, port, test_name, checksum=None):
url = port.test_to_uri(test_name) url = port.create_driver(0).test_to_uri(test_name)
# FIXME: we shouldn't have to work around platform-specific issues # FIXME: we shouldn't have to work around platform-specific issues
# here. # here.
if url.startswith('file:////'): if url.startswith('file:////'):
...@@ -215,13 +215,13 @@ class MockChromiumDRTTest(MockDRTTest): ...@@ -215,13 +215,13 @@ class MockChromiumDRTTest(MockDRTTest):
return mock_drt.MockChromiumDRT(options, args, host, stdin, stdout, stderr) return mock_drt.MockChromiumDRT(options, args, host, stdin, stdout, stderr)
def input_line(self, port, test_name, checksum=None): def input_line(self, port, test_name, checksum=None):
url = port.test_to_uri(test_name) url = port.create_driver(0).test_to_uri(test_name)
if checksum: if checksum:
return url + ' 6000 ' + checksum + '\n' return url + ' 6000 ' + checksum + '\n'
return url + ' 6000\n' return url + ' 6000\n'
def expected_output(self, port, test_name, pixel_tests, text_output, expected_checksum): def expected_output(self, port, test_name, pixel_tests, text_output, expected_checksum):
url = port.test_to_uri(test_name) url = port.create_driver(0).test_to_uri(test_name)
if pixel_tests and expected_checksum: if pixel_tests and expected_checksum:
return ['#URL:%s\n' % url, return ['#URL:%s\n' % url,
'#MD5:%s\n' % expected_checksum, '#MD5:%s\n' % expected_checksum,
......
...@@ -450,67 +450,6 @@ class TestPort(Port): ...@@ -450,67 +450,6 @@ class TestPort(Port):
def all_baseline_variants(self): def all_baseline_variants(self):
return self.ALL_BASELINE_VARIANTS return self.ALL_BASELINE_VARIANTS
# FIXME: These next two routines are copied from base.py with
# the calls to path.abspath_to_uri() removed. We shouldn't have
# to do this.
def test_to_uri(self, test_name):
"""Convert a test file (which is an absolute path) to a URI."""
LAYOUTTEST_HTTP_DIR = "http/tests/"
LAYOUTTEST_WEBSOCKET_DIR = "http/tests/websocket/tests/"
port = None
use_ssl = False
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 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 "file://" + self.abspath_for_test(test_name)
def abspath_for_test(self, test_name):
return self.layout_tests_dir() + self.TEST_PATH_SEPARATOR + 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 = "file://" + 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)
class TestDriver(Driver): class TestDriver(Driver):
"""Test/Dummy implementation of the DumpRenderTree interface.""" """Test/Dummy implementation of the DumpRenderTree interface."""
......
...@@ -521,8 +521,10 @@ class WebKitDriver(Driver): ...@@ -521,8 +521,10 @@ class WebKitDriver(Driver):
return self._crashed_subprocess_name or self._server_process.process_name() return self._crashed_subprocess_name or self._server_process.process_name()
def _command_from_driver_input(self, driver_input): def _command_from_driver_input(self, driver_input):
uri = self._port.test_to_uri(driver_input.test_name) if self.is_http_test(driver_input.test_name):
command = uri[7:] if uri.startswith("file:///") else uri command = self.test_to_uri(driver_input.test_name)
else:
command = self._port.abspath_for_test(driver_input.test_name)
if driver_input.image_hash: if driver_input.image_hash:
# FIXME: Why the leading quote? # FIXME: Why the leading quote?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment