Changeset 104340 in webkit


Ignore:
Timestamp:
Jan 6, 2012 2:27:18 PM (12 years ago)
Author:
dpranke@chromium.org
Message:

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):

Location:
trunk/Tools
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r104331 r104340  
     12012-01-05  Dirk Pranke  <dpranke@chromium.org>
     2
     3        webkitpy: clean up test/uri conversion routines
     4        https://bugs.webkit.org/show_bug.cgi?id=75648
     5
     6        Reviewed by Eric Seidel.
     7
     8        This change moves test_to_uri and uri_to_test from the Port
     9        class to the Driver class (the routines were only being
     10        called by the drivers), and removes a bunch of stale and/or
     11        busted logic.
     12
     13        * Scripts/webkitpy/layout_tests/port/base.py:
     14        * Scripts/webkitpy/layout_tests/port/base_unittest.py:
     15        * Scripts/webkitpy/layout_tests/port/chromium.py:
     16        * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
     17        * Scripts/webkitpy/layout_tests/port/driver.py:
     18        (is_http_test):
     19        (test_to_uri):
     20        (uri_to_test):
     21        * Scripts/webkitpy/layout_tests/port/mock_drt.py:
     22        (run_one_test):
     23        * Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py:
     24        (MockDRTTest.input_line):
     25        (input_line):
     26        (expected_output):
     27        * Scripts/webkitpy/layout_tests/port/test.py:
     28        * Scripts/webkitpy/layout_tests/port/webkit.py:
     29        (_command_from_driver_input):
     30
    1312012-01-06  Simon Fraser  <simon.fraser@apple.com>
    232
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/base.py

    r104206 r104340  
    4040
    4141from webkitpy.common.memoized import memoized
     42from webkitpy.common.system import path
    4243
    4344
     
    5051from webkitpy.common import find_files
    5152from webkitpy.common.system import logutils
    52 from webkitpy.common.system import path
    5353from webkitpy.common.system.executive import ScriptError
    5454from webkitpy.common.system.systemhost import SystemHost
     
    462462        return filename in reftest_list
    463463
    464     def test_to_uri(self, test_name):
    465         """Convert a test name to a URI."""
    466         LAYOUTTEST_HTTP_DIR = "http/tests/"
    467         LAYOUTTEST_WEBSOCKET_DIR = "http/tests/websocket/tests/"
    468 
    469         port = None
    470 
    471         relative_path = test_name
    472         if (relative_path.startswith(LAYOUTTEST_WEBSOCKET_DIR)
    473             or relative_path.startswith(LAYOUTTEST_HTTP_DIR)):
    474             relative_path = relative_path[len(LAYOUTTEST_HTTP_DIR):]
    475             port = 8000
    476 
    477         # Make http/tests/local run as local files. This is to mimic the
    478         # logic in run-webkit-tests.
    479         #
    480         # TODO(dpranke): remove the SSL reference?
    481         if (port and not relative_path.startswith("local/")):
    482             if relative_path.startswith("ssl/"):
    483                 port += 443
    484                 protocol = "https"
    485             else:
    486                 protocol = "http"
    487             return "%s://127.0.0.1:%u/%s" % (protocol, port, relative_path)
    488 
    489         return path.abspath_to_uri(self.abspath_for_test(test_name))
    490 
    491464    def tests(self, paths):
    492465        """Return the list of tests found."""
     
    567540        """
    568541        self._filesystem.write_binary_file(baseline_path, data)
    569 
    570     def uri_to_test_name(self, uri):
    571         """Return the base layout test name for a given URI.
    572 
    573         This returns the test name for a given URI, e.g., if you passed in
    574         "file:///src/LayoutTests/fast/html/keygen.html" it would return
    575         "fast/html/keygen.html".
    576 
    577         """
    578         test = uri
    579         if uri.startswith("file:///"):
    580             prefix = path.abspath_to_uri(self.layout_tests_dir()) + "/"
    581             return test[len(prefix):]
    582 
    583         if uri.startswith("http://127.0.0.1:8880/"):
    584             # websocket tests
    585             return test.replace('http://127.0.0.1:8880/', '')
    586 
    587         if uri.startswith("http://"):
    588             # regular HTTP test
    589             return test.replace('http://127.0.0.1:8000/', 'http/tests/')
    590 
    591         if uri.startswith("https://"):
    592             return test.replace('https://127.0.0.1:8443/', 'http/tests/')
    593 
    594         raise NotImplementedError('unknown url type: %s' % uri)
    595542
    596543    def layout_tests_dir(self):
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/base_unittest.py

    r103952 r104340  
    227227        self.assertTrue('css2.1' in dirs)
    228228
    229     def test_test_to_uri(self):
    230         port = self.make_port()
    231         layout_test_dir = port.layout_tests_dir()
    232         test = 'foo/bar.html'
    233         path = port._filesystem.join(layout_test_dir, test)
    234         if sys.platform == 'win32':
    235             path = path.replace("\\", "/")
    236 
    237         self.assertEqual(port.test_to_uri(test), abspath_to_uri(path))
    238 
    239229    def test_get_option__set(self):
    240230        options, args = optparse.OptionParser().parse_args([])
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/chromium.py

    r102400 r104340  
    525525        has_base64 = False
    526526
    527         uri = self._port.test_to_uri(driver_input.test_name)
     527        uri = self.test_to_uri(driver_input.test_name)
    528528        cmd = self._test_shell_command(uri, driver_input.timeout, driver_input.image_hash)
    529529        line, crash = self._write_command_and_read_line(input=cmd)
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/chromium_unittest.py

    r100674 r104340  
    9999        self.driver._proc.stdout.readline = mock_readline
    100100
    101         self.driver._port.test_to_uri = lambda test: 'mocktesturi'
     101        self.driver.test_to_uri = lambda test: 'mocktesturi'
    102102        driver_output = self.driver.run_test(DriverInput(test_name='some/test.html', timeout=1, image_hash=None, is_reftest=False))
    103103        self.assertEqual(self.driver._port.driver_name(), driver_output.crashed_process_name)
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/driver.py

    r100326 r104340  
    2828
    2929import shlex
     30
     31from webkitpy.common.system import path
    3032
    3133
     
    9294        return shlex.split(wrapper_option) if wrapper_option else []
    9395
     96    HTTP_DIR = "http/tests/"
     97    HTTP_LOCAL_DIR = "http/tests/local/"
     98
     99    def is_http_test(self, test_name):
     100        return test_name.startswith(self.HTTP_DIR) and not test_name.startswith(self.HTTP_LOCAL_DIR)
     101
     102    def test_to_uri(self, test_name):
     103        """Convert a test name to a URI."""
     104        if not self.is_http_test(test_name):
     105            return path.abspath_to_uri(self._port.abspath_for_test(test_name))
     106
     107        relative_path = test_name[len(self.HTTP_DIR):]
     108
     109        # TODO(dpranke): remove the SSL reference?
     110        if relative_path.startswith("ssl/"):
     111            return "https://127.0.0.1:8443/" + relative_path
     112        return "http://127.0.0.1:8000/" + relative_path
     113
     114    def uri_to_test(self, uri):
     115        """Return the base layout test name for a given URI.
     116
     117        This returns the test name for a given URI, e.g., if you passed in
     118        "file:///src/LayoutTests/fast/html/keygen.html" it would return
     119        "fast/html/keygen.html".
     120
     121        """
     122        if uri.startswith("file:///"):
     123            return uri[len(path.abspath_to_uri(self._port.layout_tests_dir()) + "/"):]
     124        if uri.startswith("http://"):
     125            return uri.replace('http://127.0.0.1:8000/', self.HTTP_DIR)
     126        if uri.startswith("https://"):
     127            return uri.replace('https://127.0.0.1:8443/', self.HTTP_DIR)
     128        raise NotImplementedError('unknown url type: %s' % uri)
     129
    94130    def has_crashed(self):
    95131        return False
     
    114150            self._reftest_driver = driver_instance_constructor(port, worker_number, pixel_tests=True)
    115151
     152    def is_http_test(self, test_name):
     153        return self._driver.is_http_test(test_name)
     154
     155    def test_to_uri(self, test_name):
     156        return self._driver.test_to_uri(test_name)
     157
     158    def uri_to_test(self, uri):
     159        return self._driver.uri_to_test(uri)
     160
    116161    def run_test(self, driver_input):
    117162        if driver_input.is_reftest:
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py

    r103012 r104340  
    187187            port_name = options.platform
    188188        self._port = PortFactory(host).get(port_name=port_name, options=options)
     189        self._driver = self._port.create_driver(0)
    189190
    190191    def run(self):
     
    201202    def run_one_test(self, test_input):
    202203        port = self._port
    203         if test_input.uri.startswith('http'):
    204             test_name = port.uri_to_test_name(test_input.uri)
     204        if test_input.uri.startswith('http://') or test_input.uri.startswith('https://'):
     205            test_name = self._driver.uri_to_test(test_input.uri)
    205206        else:
    206207            test_name = port.relative_test_filename(test_input.uri)
     
    257258    def run_one_test(self, test_input):
    258259        port = self._port
    259         test_name = self._port.uri_to_test_name(test_input.uri)
     260        test_name = self._driver.uri_to_test(test_input.uri)
    260261
    261262        actual_text = port.expected_text(test_name)
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py

    r103253 r104340  
    9090class MockDRTTest(unittest.TestCase):
    9191    def input_line(self, port, test_name, checksum=None):
    92         url = port.test_to_uri(test_name)
     92        url = port.create_driver(0).test_to_uri(test_name)
    9393        # FIXME: we shouldn't have to work around platform-specific issues
    9494        # here.
     
    216216
    217217    def input_line(self, port, test_name, checksum=None):
    218         url = port.test_to_uri(test_name)
     218        url = port.create_driver(0).test_to_uri(test_name)
    219219        if checksum:
    220220            return url + ' 6000 ' + checksum + '\n'
     
    222222
    223223    def expected_output(self, port, test_name, pixel_tests, text_output, expected_checksum):
    224         url = port.test_to_uri(test_name)
     224        url = port.create_driver(0).test_to_uri(test_name)
    225225        if pixel_tests and expected_checksum:
    226226            return ['#URL:%s\n' % url,
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/test.py

    r103952 r104340  
    451451        return self.ALL_BASELINE_VARIANTS
    452452
    453     # FIXME: These next two routines are copied from base.py with
    454     # the calls to path.abspath_to_uri() removed. We shouldn't have
    455     # to do this.
    456     def test_to_uri(self, test_name):
    457         """Convert a test file (which is an absolute path) to a URI."""
    458         LAYOUTTEST_HTTP_DIR = "http/tests/"
    459         LAYOUTTEST_WEBSOCKET_DIR = "http/tests/websocket/tests/"
    460 
    461         port = None
    462         use_ssl = False
    463 
    464         relative_path = test_name
    465         if (relative_path.startswith(LAYOUTTEST_WEBSOCKET_DIR)
    466             or relative_path.startswith(LAYOUTTEST_HTTP_DIR)):
    467             relative_path = relative_path[len(LAYOUTTEST_HTTP_DIR):]
    468             port = 8000
    469 
    470         # Make http/tests/local run as local files. This is to mimic the
    471         # logic in run-webkit-tests.
    472         #
    473         # TODO(dpranke): remove the media reference and the SSL reference?
    474         if (port and not relative_path.startswith("local/") and
    475             not relative_path.startswith("media/")):
    476             if relative_path.startswith("ssl/"):
    477                 port += 443
    478                 protocol = "https"
    479             else:
    480                 protocol = "http"
    481             return "%s://127.0.0.1:%u/%s" % (protocol, port, relative_path)
    482 
    483         return "file://" + self.abspath_for_test(test_name)
    484 
    485     def abspath_for_test(self, test_name):
    486         return self.layout_tests_dir() + self.TEST_PATH_SEPARATOR + test_name
    487 
    488     def uri_to_test_name(self, uri):
    489         """Return the base layout test name for a given URI.
    490 
    491         This returns the test name for a given URI, e.g., if you passed in
    492         "file:///src/LayoutTests/fast/html/keygen.html" it would return
    493         "fast/html/keygen.html".
    494 
    495         """
    496         test = uri
    497         if uri.startswith("file:///"):
    498             prefix = "file://" + self.layout_tests_dir() + "/"
    499             return test[len(prefix):]
    500 
    501         if uri.startswith("http://127.0.0.1:8880/"):
    502             # websocket tests
    503             return test.replace('http://127.0.0.1:8880/', '')
    504 
    505         if uri.startswith("http://"):
    506             # regular HTTP test
    507             return test.replace('http://127.0.0.1:8000/', 'http/tests/')
    508 
    509         if uri.startswith("https://"):
    510             return test.replace('https://127.0.0.1:8443/', 'http/tests/')
    511 
    512         raise NotImplementedError('unknown url type: %s' % uri)
    513 
    514453
    515454class TestDriver(Driver):
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py

    r104273 r104340  
    522522
    523523    def _command_from_driver_input(self, driver_input):
    524         uri = self._port.test_to_uri(driver_input.test_name)
    525         command = uri[7:] if uri.startswith("file:///") else uri
     524        if self.is_http_test(driver_input.test_name):
     525            command = self.test_to_uri(driver_input.test_name)
     526        else:
     527            command = self._port.abspath_for_test(driver_input.test_name)
    526528
    527529        if driver_input.image_hash:
Note: See TracChangeset for help on using the changeset viewer.