+2010-09-21 Dirk Pranke <dpranke@chromium.org>
+
+ Reviewed by Adam Barth.
+
+ Modify the Port interface to take only a series of keyword arguments
+ in the constructor, and modify Port/factory.get() to accomodate that,
+ and to accept user=XXX as an argument so we can pass
+ webkitpy.common.system.user.User objects in.
+
+ Then, modify new-run-webkit-tests and rebaseline-chromium-webkit-tests
+ to use the common routine in webkitpy.common.system.user.open_url()
+ to display HTML files.
+
+ There was a routine in the Port interface to do the same thing,
+ but I see no need for a port-specific hook for this, since it is
+ something that will always be executed by the host environment
+ and displaying web pages has nothing to do with running layout tests.
+
+ Note that new-run-webkit-tests used to use test_shell to display
+ the page; this is potentially useful so that you can actually click
+ from a result to the broken page; however, since DumpRenderTree
+ doesn't support this functionality, it will be going away eventually.
+
+ https://bugs.webkit.org/show_bug.cgi?id=46128
+
+ * 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_linux.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_mac.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_win.py:
+ * Scripts/webkitpy/layout_tests/port/dryrun.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/qt.py:
+ * Scripts/webkitpy/layout_tests/port/test.py:
+ * Scripts/webkitpy/layout_tests/port/webkit.py:
+ * Scripts/webkitpy/layout_tests/port/win.py:
+ * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests.py:
+ * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
+ * Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:
+
2010-09-21 Lucas De Marchi <lucas.demarchi@profusion.mobi>
Reviewed by Kenneth Rohde Christiansen.
from webkitpy.common.system import logutils
from webkitpy.common.system.executive import Executive, ScriptError
+from webkitpy.common.system.user import User
_log = logutils.get_logger(__file__)
}
return flags_by_configuration[configuration]
- def __init__(self, port_name=None, options=None, executive=Executive()):
- self._name = port_name
- self._options = options
+ def __init__(self, **kwargs):
+ self._name = kwargs.get('port_name', None)
+ self._options = kwargs.get('options', None)
+ self._executive = kwargs.get('executive', Executive())
+ self._user = kwargs.get('user', User())
self._helper = None
self._http_server = None
self._webkit_base_dir = None
self._websocket_server = None
- self._executive = executive
def default_child_processes(self):
"""Return the number of DumpRenderTree instances to use for this
"""
return os.environ.copy()
- def show_html_results_file(self, results_filename):
+ def show_results_html_file(self, results_filename):
"""This routine should display the HTML file pointed at by
results_filename in a users' browser."""
- raise NotImplementedError('Port.show_html_results_file')
+ return self._user.open_url(results_filename)
def create_driver(self, image_path, options):
"""Return a newly created base.Driver subclass for starting/stopping
self.assertVirtual(port.path_to_test_expectations_file)
self.assertVirtual(port.test_platform_name)
self.assertVirtual(port.results_directory)
- self.assertVirtual(port.show_html_results_file, None)
self.assertVirtual(port.test_expectations)
self.assertVirtual(port.test_base_platform_names)
self.assertVirtual(port.test_platform_name)
class ChromiumPort(base.Port):
"""Abstract base class for Chromium implementations of the Port class."""
- def __init__(self, port_name=None, options=None, **kwargs):
- base.Port.__init__(self, port_name, options, **kwargs)
+ def __init__(self, **kwargs):
+ if 'options' in kwargs:
+ options = kwargs['options']
+ if (options and (not hasattr(options, 'configuration') or
+ options.configuration is None)):
+ options.configuration = 'Release'
+ base.Port.__init__(self, **kwargs)
self._chromium_base_dir = None
def baseline_path(self):
if os.path.exists(cachedir):
shutil.rmtree(cachedir)
- def show_results_html_file(self, results_filename):
- uri = self.get_absolute_path(results_filename)
- if self._options.use_drt:
- # FIXME: This should use User.open_url
- webbrowser.open(uri, new=1)
- else:
- # Note: Not thread safe: http://bugs.python.org/issue2320
- subprocess.Popen([self._path_to_driver(), uri])
-
def create_driver(self, image_path, options):
"""Starts a new Driver and returns a handle to it."""
if options.use_drt and sys.platform == 'darwin':
class ChromiumLinuxPort(chromium.ChromiumPort):
"""Chromium Linux implementation of the Port class."""
- def __init__(self, port_name=None, options=None):
- if port_name is None:
- port_name = 'chromium-linux'
- if options and not hasattr(options, 'configuration'):
- options.configuration = 'Release'
- chromium.ChromiumPort.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ kwargs.setdefault('port_name', 'chromium-linux')
+ chromium.ChromiumPort.__init__(self, **kwargs)
def baseline_search_path(self):
port_names = ["chromium-linux", "chromium-win", "chromium", "win", "mac"]
class ChromiumMacPort(chromium.ChromiumPort):
"""Chromium Mac implementation of the Port class."""
- def __init__(self, port_name=None, options=None):
- if port_name is None:
- port_name = 'chromium-mac'
- if options and not hasattr(options, 'configuration'):
- options.configuration = 'Release'
- chromium.ChromiumPort.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ kwargs.setdefault('port_name', 'chromium-mac')
+ chromium.ChromiumPort.__init__(self, **kwargs)
def baseline_search_path(self):
port_names = ["chromium-mac", "chromium", "mac" + self.version(), "mac"]
def __init__(self):
self.use_drt = True
- port = chromium_linux.ChromiumLinuxPort('test-port', options=MockOptions())
+ port = chromium_linux.ChromiumLinuxPort(port_name='test-port',
+ options=MockOptions())
self.assertTrue(port._path_to_image_diff().endswith(
'/out/Release/ImageDiff'))
- port = chromium_mac.ChromiumMacPort('test-port', options=MockOptions())
+ port = chromium_mac.ChromiumMacPort(port_name='test-port',
+ options=MockOptions())
self.assertTrue(port._path_to_image_diff().endswith(
'/xcodebuild/Release/ImageDiff'))
# FIXME: Figure out how this is going to work on Windows.
def __init__(self):
self.use_drt = True
- port = chromium_linux.ChromiumLinuxPort('test-port', options=MockOptions())
+ port = chromium_linux.ChromiumLinuxPort(port_name='test-port',
+ options=MockOptions())
fake_test = os.path.join(port.layout_tests_dir(), "fast/js/not-good.js")
class ChromiumWinPort(chromium.ChromiumPort):
"""Chromium Win implementation of the Port class."""
- def __init__(self, port_name=None, options=None):
- if port_name is None:
- port_name = "chromium-win" + self.version()
- if options and not hasattr(options, "configuration"):
- options.configuration = "Release"
- chromium.ChromiumPort.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ kwargs.setdefault('port_name', 'chromium-win')
+ chromium.ChromiumPort.__init__(self, **kwargs)
def setup_environ_for_server(self):
env = chromium.ChromiumPort.setup_environ_for_server(self)
class DryRunPort(object):
"""DryRun implementation of the Port interface."""
- def __init__(self, port_name=None, options=None):
+ def __init__(self, **kwargs):
pfx = 'dryrun-'
- if port_name.startswith(pfx):
- port_name = port_name[len(pfx):]
- else:
- port_name = None
- self._options = options
- self.__delegate = factory.get(port_name, options)
+ if 'port_name' in kwargs:
+ if kwargs['port_name'].startswith(pfx):
+ kwargs['port_name'] = kwargs['port_name'][len(pfx):]
+ else:
+ kwargs['port_name'] = None
+ self.__delegate = factory.get(**kwargs)
def __getattr__(self, name):
return getattr(self.__delegate, name)
'google-chrome-mac', 'google-chrome-linux32', 'google-chrome-linux64']
-def get(port_name=None, options=None):
+def get(port_name=None, options=None, **kwargs):
"""Returns an object implementing the Port interface. If
port_name is None, this routine attempts to guess at the most
appropriate port on this platform."""
- port_to_use = port_name
+ # Wrapped for backwards-compatibility
+ if port_name:
+ kwargs['port_name'] = port_name
+ if options:
+ kwargs['options'] = options
+ return _get_kwargs(**kwargs)
+
+
+def _get_kwargs(**kwargs):
+ port_to_use = kwargs.get('port_name', None)
+ options = kwargs.get('options', None)
if port_to_use is None:
if sys.platform == 'win32' or sys.platform == 'cygwin':
if options and hasattr(options, 'chromium') and options.chromium:
if port_to_use == 'test':
import test
- return test.TestPort(port_name, options)
+ cls = test.TestPort
elif port_to_use.startswith('dryrun'):
import dryrun
- return dryrun.DryRunPort(port_name, options)
+ cls = dryrun.DryRunPort
elif port_to_use.startswith('mac'):
import mac
- return mac.MacPort(port_name, options)
+ cls = mac.MacPort
elif port_to_use.startswith('win'):
import win
- return win.WinPort(port_name, options)
+ cls = win.WinPort
elif port_to_use.startswith('gtk'):
import gtk
- return gtk.GtkPort(port_name, options)
+ cls = gtk.GtkPort
elif port_to_use.startswith('qt'):
import qt
- return qt.QtPort(port_name, options)
+ cls = qt.QtPort
elif port_to_use.startswith('chromium-mac'):
import chromium_mac
- return chromium_mac.ChromiumMacPort(port_name, options)
+ cls = chromium_mac.ChromiumMacPort
elif port_to_use.startswith('chromium-linux'):
import chromium_linux
- return chromium_linux.ChromiumLinuxPort(port_name, options)
+ cls = chromium_linux.ChromiumLinuxPort
elif port_to_use.startswith('chromium-win'):
import chromium_win
- return chromium_win.ChromiumWinPort(port_name, options)
+ cls = chromium_win.ChromiumWinPort
elif port_to_use.startswith('google-chrome'):
import google_chrome
- return google_chrome.GetGoogleChromePort(port_name, options)
-
- raise NotImplementedError('unsupported port: %s' % port_to_use)
-
+ cls = google_chrome.GetGoogleChromePort
+ else:
+ raise NotImplementedError('unsupported port: %s' % port_to_use)
+ return cls(**kwargs)
def get_all(options=None):
"""Returns all the objects implementing the Port interface."""
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-def GetGoogleChromePort(port_name, options):
+def GetGoogleChromePort(**kwargs):
"""Some tests have slightly different results when compiled as Google
Chrome vs Chromium. In those cases, we prepend an additional directory to
to the baseline paths."""
+ port_name = kwargs['port_name']
+ del kwargs['port_name']
if port_name == 'google-chrome-linux32':
import chromium_linux
paths.insert(0, self._webkit_baseline_path(
'google-chrome-linux32'))
return paths
- return GoogleChromeLinux32Port(None, options)
+ return GoogleChromeLinux32Port(**kwargs)
elif port_name == 'google-chrome-linux64':
import chromium_linux
paths.insert(0, self._webkit_baseline_path(
'google-chrome-linux64'))
return paths
- return GoogleChromeLinux64Port(None, options)
+ return GoogleChromeLinux64Port(**kwargs)
elif port_name.startswith('google-chrome-mac'):
import chromium_mac
paths.insert(0, self._webkit_baseline_path(
'google-chrome-mac'))
return paths
- return GoogleChromeMacPort(None, options)
+ return GoogleChromeMacPort(**kwargs)
elif port_name.startswith('google-chrome-win'):
import chromium_win
paths.insert(0, self._webkit_baseline_path(
'google-chrome-win'))
return paths
- return GoogleChromeWinPort(None, options)
+ return GoogleChromeWinPort(**kwargs)
raise NotImplementedError('unsupported port: %s' % port_name)
self._verify_baseline_path('google-chrome-win', 'google-chrome-win-vista')
def _verify_baseline_path(self, expected_path, port_name):
- port = google_chrome.GetGoogleChromePort(port_name, None)
+ port = google_chrome.GetGoogleChromePort(port_name=port_name,
+ options=None)
path = port.baseline_search_path()[0]
self.assertEqual(expected_path, os.path.split(path)[1])
class GtkPort(WebKitPort):
"""WebKit Gtk implementation of the Port class."""
- def __init__(self, port_name=None, options=None):
- if port_name is None:
- port_name = 'gtk'
- WebKitPort.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ kwargs.setdefault('port_name', 'gtk')
+ WebKitPort.__init__(self, **kwargs)
def _tests_for_other_platforms(self):
# FIXME: This list could be dynamic based on platform name and
class MacPort(WebKitPort):
"""WebKit Mac implementation of the Port class."""
- def __init__(self, port_name=None, options=None):
- if port_name is None:
- port_name = 'mac' + self.version()
- WebKitPort.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ kwargs.setdefault('port_name', 'mac' + self.version())
+ WebKitPort.__init__(self, **kwargs)
def default_child_processes(self):
# FIXME: new-run-webkit-tests is unstable on Mac running more than
class QtPort(WebKitPort):
"""QtWebKit implementation of the Port class."""
- def __init__(self, port_name=None, options=None):
- if port_name is None:
- port_name = 'qt'
- WebKitPort.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ kwargs.setdefault('port_name', 'qt')
+ WebKitPort.__init__(self, **kwargs)
def _tests_for_other_platforms(self):
# FIXME: This list could be dynamic based on platform name and
class TestPort(base.Port):
"""Test implementation of the Port interface."""
- def __init__(self, port_name=None, options=None):
- base.Port.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ base.Port.__init__(self, **kwargs)
tests = TestList(self)
tests.add('passes/image.html')
tests.add('passes/text.html')
def setup_test_run(self):
pass
- def show_results_html_file(self, filename):
- pass
-
def create_driver(self, image_path, options):
return TestDriver(self, image_path, options, executive=None)
class WebKitPort(base.Port):
"""WebKit implementation of the Port class."""
- def __init__(self, port_name=None, options=None, **kwargs):
- base.Port.__init__(self, port_name, options, **kwargs)
+ def __init__(self, **kwargs):
+ base.Port.__init__(self, **kwargs)
self._cached_build_root = None
self._cached_apache_path = None
# FIXME: disable pixel tests until they are run by default on the
# build machines.
- if options and (not hasattr(options, "pixel_tests") or
- options.pixel_tests is None):
- options.pixel_tests = False
+ if self._options and (not hasattr(self._options, "pixel_tests") or
+ self._options.pixel_tests is None):
+ self._options.pixel_tests = False
def baseline_path(self):
return self._webkit_baseline_path(self._name)
# This port doesn't require any specific configuration.
pass
- def show_results_html_file(self, results_filename):
- # FIXME: We should open results in the version of WebKit we built.
- webbrowser.open(results_filename, new=1)
-
def create_driver(self, image_path, options):
return WebKitDriver(self, image_path, options,
executive=self._executive)
class WinPort(WebKitPort):
"""WebKit Win implementation of the Port class."""
- def __init__(self, port_name=None, options=None):
- if port_name is None:
- port_name = 'win'
- WebKitPort.__init__(self, port_name, options)
+ def __init__(self, **kwargs):
+ kwargs.setdefault('port_name', 'win')
+ WebKitPort.__init__(self, **kwargs)
def baseline_search_path(self):
# Based on code from old-run-webkit-tests expectedDirectoryForTest()
import tempfile
import time
import urllib
-import webbrowser
import zipfile
+from webkitpy.common.system import user
from webkitpy.common.system.executive import run_command, ScriptError
import webkitpy.common.checkout.scm as scm
"""Launch the rebaselining html in brwoser."""
_log.info('Launching html: "%s"', self._html_file)
-
- html_uri = self._target_port.filename_to_uri(self._html_file)
- webbrowser.open(html_uri, 1)
-
+ user.open_url(self._html_file)
_log.info('Html launched.')
def _generate_baseline_links(self, test_basename, suffix, platform):
from test_types import text_diff
from test_types import test_type_base
+from webkitpy.common.system import user
from webkitpy.thirdparty import simplejson
import port
from webkitpy.common import array_stream
from webkitpy.common.system import outputcapture
+from webkitpy.common.system import user
from webkitpy.layout_tests import port
from webkitpy.layout_tests import run_webkit_tests
from webkitpy.layout_tests.layout_package import dump_render_tree_thread
from webkitpy.thirdparty.mock import Mock
+class MockUser():
+ def __init__(self):
+ self.url = None
+
+ def open_url(self, url):
+ self.url = url
+
+
def passing_run(args=[], port_obj=None, record_results=False,
tests_included=False):
new_args = ['--print', 'nothing']
'failures/expected/*'])
options, parsed_args = run_webkit_tests.parse_args(new_args)
if port_obj is None:
- port_obj = port.get(options.platform, options)
+ port_obj = port.get(port_name=options.platform, options=options,
+ user=MockUser())
res = run_webkit_tests.run(port_obj, options, parsed_args)
return res == 0
'websocket/tests',
'failures/expected/*'])
options, parsed_args = run_webkit_tests.parse_args(new_args)
- port_obj = port.get(options.platform, options)
+ user = MockUser()
+ port_obj = port.get(port_name=options.platform, options=options, user=user)
buildbot_output = array_stream.ArrayStream()
regular_output = array_stream.ArrayStream()
res = run_webkit_tests.run(port_obj, options, parsed_args,
buildbot_output=buildbot_output,
regular_output=regular_output)
- return (res, buildbot_output, regular_output)
+ return (res, buildbot_output, regular_output, user)
class MainTest(unittest.TestCase):
self.assertTrue(passing_run(['--batch-size', '2']))
def test_child_process_1(self):
- (res, buildbot_output, regular_output) = logging_run(
+ (res, buildbot_output, regular_output, user) = logging_run(
['--print', 'config', '--child-processes', '1'])
self.assertTrue('Running one DumpRenderTree\n'
in regular_output.get())
def test_child_processes_2(self):
- (res, buildbot_output, regular_output) = logging_run(
+ (res, buildbot_output, regular_output, user) = logging_run(
['--print', 'config', '--child-processes', '2'])
self.assertTrue('Running 2 DumpRenderTrees in parallel\n'
in regular_output.get())
self.assertTrue(passing_run(['--full-results-html']))
def test_help_printing(self):
- res, out, err = logging_run(['--help-printing'])
+ res, out, err, user = logging_run(['--help-printing'])
self.assertEqual(res, 0)
self.assertTrue(out.empty())
self.assertFalse(err.empty())
def test_hung_thread(self):
- res, out, err = logging_run(['--run-singly', '--time-out-ms=50',
- 'failures/expected/hang.html'],
- tests_included=True)
+ res, out, err, user = logging_run(['--run-singly', '--time-out-ms=50',
+ 'failures/expected/hang.html'],
+ tests_included=True)
self.assertEqual(res, 0)
self.assertFalse(out.empty())
self.assertFalse(err.empty())
def test_last_results(self):
passing_run(['--clobber-old-results'], record_results=True)
- (res, buildbot_output, regular_output) = logging_run(
+ (res, buildbot_output, regular_output, user) = logging_run(
['--print-last-failures'])
self.assertEqual(regular_output.get(), ['\n\n'])
self.assertEqual(buildbot_output.get(), [])
def test_lint_test_files(self):
# FIXME: add errors?
- res, out, err = logging_run(['--lint-test-files'], tests_included=True)
+ res, out, err, user = logging_run(['--lint-test-files'],
+ tests_included=True)
self.assertEqual(res, 0)
self.assertTrue(out.empty())
self.assertTrue(any(['lint succeeded' in msg for msg in err.get()]))
def test_no_tests_found(self):
- res, out, err = logging_run(['resources'], tests_included=True)
+ res, out, err, user = logging_run(['resources'], tests_included=True)
self.assertEqual(res, -1)
self.assertTrue(out.empty())
self.assertTrue('No tests to run.\n' in err.get())
def test_no_tests_found_2(self):
- res, out, err = logging_run(['foo'], tests_included=True)
+ res, out, err, user = logging_run(['foo'], tests_included=True)
self.assertEqual(res, -1)
self.assertTrue(out.empty())
self.assertTrue('No tests to run.\n' in err.get())
self.assertTrue(passing_run(['--test-list=%s' % filename],
tests_included=True))
os.remove(filename)
- res, out, err = logging_run(['--test-list=%s' % filename],
- tests_included=True)
+ res, out, err, user = logging_run(['--test-list=%s' % filename],
+ tests_included=True)
self.assertEqual(res, -1)
self.assertFalse(err.empty())
def test_unexpected_failures(self):
# Run tests including the unexpected failures.
- res, out, err = logging_run(tests_included=True)
+ self._url_opened = None
+ res, out, err, user = logging_run(tests_included=True)
self.assertEqual(res, 1)
self.assertFalse(out.empty())
self.assertFalse(err.empty())
+ self.assertEqual(user.url, '/tmp/layout-test-results/results.html')
def _mocked_open(original_open, file_list):
finally:
codecs.open = original_open
+
class TestRunnerTest(unittest.TestCase):
def test_results_html(self):
mock_port = Mock()
'fast/html']))
def test_test(self):
- res, out, err = logging_run(['--platform', 'dryrun-test',
- '--pixel-tests'])
- self.assertEqual(res, 0)
- self.assertFalse(out.empty())
- self.assertFalse(err.empty())
+ self.assertTrue(passing_run(['--platform', 'dryrun-test',
+ '--pixel-tests']))
class TestThread(dump_render_tree_thread.WatchableThread):