Skip to content
Permalink
Browse files
Make the Port object have a Host
https://bugs.webkit.org/show_bug.cgi?id=71961

Reviewed by Adam Barth.

This has been a long time coming.
Now that Port has a Host object, it's very easy
to write unittests which use a properly mocked Port.
Soon we will remove the executive, filesystem and user
members of Port and get everything through the Host.

Note how in many callsites we're actually removing
explicit mocks, since we're now always going to get the
correct Executive/User/FileSystem from the
Host and callsites don't need to be careful to pass each one.

This is prep-work for adding a new Environment member to
Host and needing to be able to access the Environment
member from Port functions w/o needing to pass an Environment
object (or appropriate Mock) every place we create a Port object.
Now that we have a single Host object to reach out through, its
simple to add additional functionality (like Environment) while
keeping our unittests properly mocked.

* Scripts/webkitpy/common/host.py:
* Scripts/webkitpy/common/net/credentials_unittest.py:
* Scripts/webkitpy/layout_tests/controllers/manager_unittest.py:
* Scripts/webkitpy/layout_tests/controllers/manager_worker_broker.py:
* Scripts/webkitpy/layout_tests/port/apple.py:
* 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_gpu.py:
* Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_linux.py:
* Scripts/webkitpy/layout_tests/port/chromium_linux_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_mac.py:
* Scripts/webkitpy/layout_tests/port/chromium_mac_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_win.py:
* Scripts/webkitpy/layout_tests/port/chromium_win_unittest.py:
* Scripts/webkitpy/layout_tests/port/dryrun.py:
* Scripts/webkitpy/layout_tests/port/efl.py:
* Scripts/webkitpy/layout_tests/port/factory.py:
* Scripts/webkitpy/layout_tests/port/google_chrome.py:
* Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py:
* Scripts/webkitpy/layout_tests/port/gtk.py:
* Scripts/webkitpy/layout_tests/port/mac.py:
* Scripts/webkitpy/layout_tests/port/mac_unittest.py:
* Scripts/webkitpy/layout_tests/port/mock_drt.py:
* Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py:
* Scripts/webkitpy/layout_tests/port/port_testcase.py:
* Scripts/webkitpy/layout_tests/port/qt.py:
* Scripts/webkitpy/layout_tests/port/qt_unittest.py:
* Scripts/webkitpy/layout_tests/port/test.py:
* Scripts/webkitpy/layout_tests/port/webkit.py:
* Scripts/webkitpy/layout_tests/port/webkit_unittest.py:
* Scripts/webkitpy/layout_tests/port/win.py:
* Scripts/webkitpy/layout_tests/port/win_unittest.py:
* Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
* Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py:
* Scripts/webkitpy/tool/servers/rebaselineserver.py:
* Scripts/webkitpy/tool/servers/rebaselineserver_unittest.py:

Canonical link: https://commits.webkit.org/88338@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@99773 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
eseidel committed Nov 9, 2011
1 parent 4a8d371 commit 2ef8b5f5a297c5a9684512beecf0a611990c137d
Showing with 288 additions and 266 deletions.
  1. +66 −0 Tools/ChangeLog
  2. +1 −0 Tools/Scripts/webkitpy/common/host.py
  3. +0 −1 Tools/Scripts/webkitpy/common/net/credentials_unittest.py
  4. +1 −2 Tools/Scripts/webkitpy/layout_tests/controllers/manager_unittest.py
  5. +5 −3 Tools/Scripts/webkitpy/layout_tests/controllers/manager_worker_broker.py
  6. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/apple.py
  7. +10 −8 Tools/Scripts/webkitpy/layout_tests/port/base.py
  8. +3 −6 Tools/Scripts/webkitpy/layout_tests/port/base_unittest.py
  9. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/chromium.py
  10. +13 −13 Tools/Scripts/webkitpy/layout_tests/port/chromium_gpu.py
  11. +5 −3 Tools/Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py
  12. +2 −5 Tools/Scripts/webkitpy/layout_tests/port/chromium_linux.py
  13. +14 −23 Tools/Scripts/webkitpy/layout_tests/port/chromium_linux_unittest.py
  14. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/chromium_mac.py
  15. +11 −10 Tools/Scripts/webkitpy/layout_tests/port/chromium_mac_unittest.py
  16. +5 −8 Tools/Scripts/webkitpy/layout_tests/port/chromium_unittest.py
  17. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/chromium_win.py
  18. +13 −12 Tools/Scripts/webkitpy/layout_tests/port/chromium_win_unittest.py
  19. +2 −3 Tools/Scripts/webkitpy/layout_tests/port/dryrun.py
  20. +5 −5 Tools/Scripts/webkitpy/layout_tests/port/efl.py
  21. +4 −12 Tools/Scripts/webkitpy/layout_tests/port/factory.py
  22. +18 −29 Tools/Scripts/webkitpy/layout_tests/port/google_chrome.py
  23. +7 −9 Tools/Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py
  24. +14 −11 Tools/Scripts/webkitpy/layout_tests/port/gtk.py
  25. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/mac.py
  26. +9 −9 Tools/Scripts/webkitpy/layout_tests/port/mac_unittest.py
  27. +17 −22 Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py
  28. +14 −13 Tools/Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py
  29. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/port_testcase.py
  30. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/qt.py
  31. +2 −3 Tools/Scripts/webkitpy/layout_tests/port/qt_unittest.py
  32. +4 −6 Tools/Scripts/webkitpy/layout_tests/port/test.py
  33. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/webkit.py
  34. +9 −15 Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py
  35. +2 −2 Tools/Scripts/webkitpy/layout_tests/port/win.py
  36. +3 −5 Tools/Scripts/webkitpy/layout_tests/port/win_unittest.py
  37. +4 −5 Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py
  38. +0 −1 Tools/Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py
  39. +3 −1 Tools/Scripts/webkitpy/tool/servers/rebaselineserver.py
  40. +6 −5 Tools/Scripts/webkitpy/tool/servers/rebaselineserver_unittest.py
@@ -1,3 +1,69 @@
2011-11-09 Eric Seidel <eric@webkit.org>

Make the Port object have a Host
https://bugs.webkit.org/show_bug.cgi?id=71961

Reviewed by Adam Barth.

This has been a long time coming.
Now that Port has a Host object, it's very easy
to write unittests which use a properly mocked Port.
Soon we will remove the executive, filesystem and user
members of Port and get everything through the Host.

Note how in many callsites we're actually removing
explicit mocks, since we're now always going to get the
correct Executive/User/FileSystem from the
Host and callsites don't need to be careful to pass each one.

This is prep-work for adding a new Environment member to
Host and needing to be able to access the Environment
member from Port functions w/o needing to pass an Environment
object (or appropriate Mock) every place we create a Port object.
Now that we have a single Host object to reach out through, its
simple to add additional functionality (like Environment) while
keeping our unittests properly mocked.

* Scripts/webkitpy/common/host.py:
* Scripts/webkitpy/common/net/credentials_unittest.py:
* Scripts/webkitpy/layout_tests/controllers/manager_unittest.py:
* Scripts/webkitpy/layout_tests/controllers/manager_worker_broker.py:
* Scripts/webkitpy/layout_tests/port/apple.py:
* 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_gpu.py:
* Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_linux.py:
* Scripts/webkitpy/layout_tests/port/chromium_linux_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_mac.py:
* Scripts/webkitpy/layout_tests/port/chromium_mac_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
* Scripts/webkitpy/layout_tests/port/chromium_win.py:
* Scripts/webkitpy/layout_tests/port/chromium_win_unittest.py:
* Scripts/webkitpy/layout_tests/port/dryrun.py:
* Scripts/webkitpy/layout_tests/port/efl.py:
* Scripts/webkitpy/layout_tests/port/factory.py:
* Scripts/webkitpy/layout_tests/port/google_chrome.py:
* Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py:
* Scripts/webkitpy/layout_tests/port/gtk.py:
* Scripts/webkitpy/layout_tests/port/mac.py:
* Scripts/webkitpy/layout_tests/port/mac_unittest.py:
* Scripts/webkitpy/layout_tests/port/mock_drt.py:
* Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py:
* Scripts/webkitpy/layout_tests/port/port_testcase.py:
* Scripts/webkitpy/layout_tests/port/qt.py:
* Scripts/webkitpy/layout_tests/port/qt_unittest.py:
* Scripts/webkitpy/layout_tests/port/test.py:
* Scripts/webkitpy/layout_tests/port/webkit.py:
* Scripts/webkitpy/layout_tests/port/webkit_unittest.py:
* Scripts/webkitpy/layout_tests/port/win.py:
* Scripts/webkitpy/layout_tests/port/win_unittest.py:
* Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
* Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py:
* Scripts/webkitpy/tool/servers/rebaselineserver.py:
* Scripts/webkitpy/tool/servers/rebaselineserver_unittest.py:

2011-11-09 Dominic Mazzoni <dmazzoni@google.com>

[Chromium] Implement AccessibilityUIElement::insertionPointLineNumberGetterCallback
@@ -60,6 +60,7 @@ def __init__(self):
# FIXME: Unfortunately Port objects are currently the central-dispatch objects of the NRWT world.
# In order to instantiate a port correctly, we have to pass it at least an executive, user, scm, and filesystem
# so for now we just pass along the whole Host object.
# FIXME: PortFactory doesn't belong on this Host object if Port is going to have a Host (circular dependency).
self.port_factory = PortFactory(self)

def _initialize_scm(self, patch_directories=None):
@@ -37,7 +37,6 @@
from webkitpy.thirdparty.mock import Mock
from webkitpy.tool.mocktool import MockOptions
from webkitpy.common.system.executive_mock import MockExecutive
from webkitpy.common.system.user_mock import MockUser


# FIXME: Other unit tests probably want this class.
@@ -47,7 +47,6 @@
from webkitpy.layout_tests.views import printing
from webkitpy.tool.mocktool import MockOptions
from webkitpy.common.system.executive_mock import MockExecutive
from webkitpy.common.system.user_mock import MockUser
from webkitpy.common.host_mock import MockHost


@@ -188,7 +187,7 @@ def handle_finished_list(self, source, list_name, num_tests, elapsed_time):

options, args = run_webkit_tests.parse_args(['--platform=test', '--print=nothing', 'http/tests/passes', 'passes'])
host = MockHost()
port = host.port_factory.get(port_name=options.platform, options=options, user=MockUser(), executive=MockExecutive())
port = host.port_factory.get(port_name=options.platform, options=options)
run_webkit_tests._set_up_derived_options(port, options)
printer = printing.Printer(port, options, StringIO.StringIO(), StringIO.StringIO(), configure_logging=True)
manager = LockCheckingManager(port, options, printer)
@@ -52,7 +52,7 @@
except ImportError:
multiprocessing = None

from webkitpy.layout_tests.port.factory import PortFactory
from webkitpy.common.host import Host # FIXME: This should not be needed!
from webkitpy.layout_tests.controllers import message_broker
from webkitpy.layout_tests.views import printing

@@ -252,8 +252,10 @@ def __init__(self, worker_connection, platform_name, options, client):

def run(self):
options = self._options
# FIXME: This should get the PortFactory from the Host.
port_obj = PortFactory().get(self._platform_name, options)
# FIXME: This should get the Host from the owner of this object
# so this function can be properly mocked!
host = Host()
port_obj = host.port_factory.get(self._platform_name, options)

# The unix multiprocessing implementation clones the
# log handler configuration into the child processes,
@@ -56,9 +56,9 @@ def _strip_port_name_prefix(self, port_name):
# instead of the individual port constructors.
return port_name[len(self.port_name + '-'):]

def __init__(self, port_name=None, os_version_string=None, **kwargs):
def __init__(self, host, port_name=None, os_version_string=None, **kwargs):
port_name = port_name or self.port_name
WebKitPort.__init__(self, port_name=port_name, **kwargs)
WebKitPort.__init__(self, host, port_name=port_name, **kwargs)

# FIXME: This sort of parsing belongs in factory.py!
if port_name == '%s-wk2' % self.port_name:
@@ -47,11 +47,9 @@
except ImportError:
multiprocessing = None

from webkitpy.common import system
from webkitpy.common.system import logutils
from webkitpy.common.system import path
from webkitpy.common.system.executive import Executive, ScriptError
from webkitpy.common.system.user import User
from webkitpy.common.system.executive import ScriptError
from webkitpy.layout_tests import read_checksum_from_png
from webkitpy.layout_tests.models.test_configuration import TestConfiguration
from webkitpy.layout_tests.port import config as port_config
@@ -67,7 +65,7 @@
class DummyOptions(object):
"""Fake implementation of optparse.Values. Cloned from webkitpy.tool.mocktool.MockOptions."""

def __init__(self, **kwargs):
def __init__(self, *args, **kwargs):
# The caller can set option values using keyword arguments. We don't
# set any values by default because we don't know how this
# object will be used. Generally speaking unit tests should
@@ -88,7 +86,8 @@ class Port(object):

ALL_BUILD_TYPES = ('debug', 'release')

def __init__(self, port_name=None, options=None,
def __init__(self, host,
port_name=None, options=None,
executive=None,
user=None,
filesystem=None,
@@ -107,9 +106,12 @@ def __init__(self, port_name=None, options=None,
# options defined on it.
self.options = options or DummyOptions()

self.executive = executive or Executive()
self.user = user or User()
self.filesystem = filesystem or system.filesystem.FileSystem()
self.host = host

# FIXME: Remove thes accessors once all callers have moved to using self.host.
self.executive = executive or self.host.executive
self.user = user or self.host.user
self.filesystem = filesystem or self.host.filesystem
self.config = config or port_config.Config(self.executive, self.filesystem)

# FIXME: Remove all of the old "protected" versions when we can.
@@ -39,8 +39,7 @@
from webkitpy.thirdparty.mock import Mock
from webkitpy.tool.mocktool import MockOptions
from webkitpy.common.system.executive_mock import MockExecutive
from webkitpy.common.system.user_mock import MockUser

from webkitpy.common.host_mock import MockHost

from webkitpy.layout_tests.port import Port, Driver, DriverOutput

@@ -50,9 +49,7 @@

class PortTest(unittest.TestCase):
def make_port(self, *args, **kwargs):
kwargs.setdefault('filesystem', MockFileSystem())
kwargs.setdefault('user', MockUser())
kwargs.setdefault('executive', MockExecutive())
kwargs.setdefault('host', MockHost())
return Port(*args, **kwargs)

def test_format_wdiff_output_as_html(self):
@@ -284,7 +281,7 @@ def assertVirtual(self, method, *args, **kwargs):
self.assertRaises(NotImplementedError, method, *args, **kwargs)

def test_virtual_methods(self):
port = Port()
port = Port(MockHost())
self.assertVirtual(port.baseline_path)
self.assertVirtual(port.baseline_search_path)
self.assertVirtual(port.check_build, None)
@@ -88,8 +88,8 @@ class ChromiumPort(Port):
'linux': ['lucid'],
}

def __init__(self, **kwargs):
Port.__init__(self, **kwargs)
def __init__(self, host, **kwargs):
Port.__init__(self, host, **kwargs)
# All sub-classes override this, but we need an initial value for testing.
self._version = 'xp'
self._chromium_base_dir = None
@@ -33,7 +33,7 @@
from webkitpy.layout_tests.port import test_files


def get(platform=None, port_name='chromium-gpu', **kwargs):
def get(host, platform=None, port_name='chromium-gpu', **kwargs):
"""Some tests have slightly different results when run while using
hardware acceleration. In those cases, we prepend an additional directory
to the baseline paths."""
@@ -49,13 +49,13 @@ def get(platform=None, port_name='chromium-gpu', **kwargs):
raise NotImplementedError('unsupported platform: %s' % platform)

if port_name.startswith('chromium-gpu-linux'):
return ChromiumGpuLinuxPort(port_name=port_name, **kwargs)
return ChromiumGpuLinuxPort(host, port_name=port_name, **kwargs)
if port_name.startswith('chromium-gpu-cg-mac'):
return ChromiumGpuCgMacPort(port_name=port_name, **kwargs)
return ChromiumGpuCgMacPort(host, port_name=port_name, **kwargs)
if port_name.startswith('chromium-gpu-mac'):
return ChromiumGpuMacPort(port_name=port_name, **kwargs)
return ChromiumGpuMacPort(host, port_name=port_name, **kwargs)
if port_name.startswith('chromium-gpu-win'):
return ChromiumGpuWinPort(port_name=port_name, **kwargs)
return ChromiumGpuWinPort(host, port_name=port_name, **kwargs)
raise NotImplementedError('unsupported port: %s' % port_name)


@@ -90,8 +90,8 @@ def _tests(port, paths):


class ChromiumGpuLinuxPort(chromium_linux.ChromiumLinuxPort):
def __init__(self, port_name='chromium-gpu-linux', **kwargs):
chromium_linux.ChromiumLinuxPort.__init__(self, port_name=port_name, **kwargs)
def __init__(self, host, port_name='chromium-gpu-linux', **kwargs):
chromium_linux.ChromiumLinuxPort.__init__(self, host, port_name=port_name, **kwargs)
_set_gpu_options(self)

def baseline_search_path(self):
@@ -104,8 +104,8 @@ def tests(self, paths):


class ChromiumGpuCgMacPort(chromium_mac.ChromiumMacPort):
def __init__(self, port_name='chromium-gpu-cg-mac', **kwargs):
chromium_mac.ChromiumMacPort.__init__(self, port_name=port_name, **kwargs)
def __init__(self, host, port_name='chromium-gpu-cg-mac', **kwargs):
chromium_mac.ChromiumMacPort.__init__(self, host, port_name=port_name, **kwargs)
_set_gpu_options(self, graphics_type='gpu-cg')

def baseline_search_path(self):
@@ -117,8 +117,8 @@ def tests(self, paths):


class ChromiumGpuMacPort(chromium_mac.ChromiumMacPort):
def __init__(self, port_name='chromium-gpu-mac', **kwargs):
chromium_mac.ChromiumMacPort.__init__(self, port_name=port_name, **kwargs)
def __init__(self, host, port_name='chromium-gpu-mac', **kwargs):
chromium_mac.ChromiumMacPort.__init__(self, host, port_name=port_name, **kwargs)
_set_gpu_options(self)

def baseline_search_path(self):
@@ -130,8 +130,8 @@ def tests(self, paths):


class ChromiumGpuWinPort(chromium_win.ChromiumWinPort):
def __init__(self, port_name='chromium-gpu-win', **kwargs):
chromium_win.ChromiumWinPort.__init__(self, port_name=port_name, **kwargs)
def __init__(self, host, port_name='chromium-gpu-win', **kwargs):
chromium_win.ChromiumWinPort.__init__(self, host, port_name=port_name, **kwargs)
_set_gpu_options(self)

def baseline_search_path(self):
@@ -58,16 +58,18 @@ def integration_test_chromium_gpu_win(self):
self.assert_port_works('chromium-gpu-win', 'chromium-gpu', 'cygwin')

def assert_port_works(self, port_name, input_name=None, platform=None):
host = MockHost()
host.filesystem = FileSystem() # FIXME: This test should not use a real filesystem!

# test that we got the right port
mock_options = MockOptions(accelerated_compositing=None,
accelerated_2d_canvas=None,
builder_name='foo',
child_processes=None)
if input_name and platform:
port = chromium_gpu.get(platform=platform, port_name=input_name,
options=mock_options)
port = chromium_gpu.get(host, platform=platform, port_name=input_name, options=mock_options)
else:
port = chromium_gpu.get(port_name=port_name, options=mock_options)
port = chromium_gpu.get(host, port_name=port_name, options=mock_options)
self.assertTrue(port._options.accelerated_compositing)
self.assertTrue(port._options.accelerated_2d_canvas)
self.assertTrue(port._options.experimental_fully_parallel)
@@ -27,10 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Chromium Linux implementation of the Port interface."""

import logging

import chromium


@@ -58,9 +55,9 @@ class ChromiumLinuxPort(chromium.ChromiumPort):
],
}

def __init__(self, port_name=None, **kwargs):
def __init__(self, host, port_name=None, **kwargs):
port_name = port_name or 'chromium-linux'
chromium.ChromiumPort.__init__(self, port_name=port_name, **kwargs)
chromium.ChromiumPort.__init__(self, host, port_name=port_name, **kwargs)
# We re-set the port name once the base object is fully initialized
# in order to be able to find the DRT binary properly.
if port_name.endswith('-linux'):

0 comments on commit 2ef8b5f

Please sign in to comment.