summaryrefslogtreecommitdiffstats
path: root/WebKitTools/Scripts/webkitpy/layout_tests/port/base.py
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-09-30 15:42:16 +0100
committerSteve Block <steveblock@google.com>2010-10-07 10:59:29 +0100
commitbec39347bb3bb5bf1187ccaf471d26247f28b585 (patch)
tree56bdc4c2978fbfd3d79d0d36d5d6c640ecc09cc8 /WebKitTools/Scripts/webkitpy/layout_tests/port/base.py
parent90b7966e7815b262cd19ac25f03aaad9b21fdc06 (diff)
downloadexternal_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.zip
external_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.tar.gz
external_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.tar.bz2
Merge WebKit at r68651 : Initial merge by git.
Change-Id: I3d6bff59f17eedd6722723354f386fec9be8ad12
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/layout_tests/port/base.py')
-rw-r--r--WebKitTools/Scripts/webkitpy/layout_tests/port/base.py115
1 files changed, 105 insertions, 10 deletions
diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/port/base.py b/WebKitTools/Scripts/webkitpy/layout_tests/port/base.py
index 70beac3..6a5d43b 100644
--- a/WebKitTools/Scripts/webkitpy/layout_tests/port/base.py
+++ b/WebKitTools/Scripts/webkitpy/layout_tests/port/base.py
@@ -42,11 +42,13 @@ import sys
import time
import apache_http_server
+import test_files
import http_server
import websocket_server
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__)
@@ -81,14 +83,15 @@ class Port(object):
}
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
@@ -130,11 +133,11 @@ class Port(object):
interface so that it can be overriden for testing purposes."""
return expected_text != actual_text
- def diff_image(self, expected_filename, actual_filename,
+ def diff_image(self, expected_contents, actual_contents,
diff_filename=None, tolerance=0):
- """Compare two image files and produce a delta image file.
+ """Compare two images and produce a delta image file.
- Return True if the two files are different, False if they are the same.
+ Return True if the two images are different, False if they are the same.
Also produce a delta image of the two images and write that into
|diff_filename| if it is not None.
@@ -252,6 +255,31 @@ class Port(object):
return os.path.join(platform_dir, baseline_filename)
return os.path.join(self.layout_tests_dir(), baseline_filename)
+ def _expected_file_contents(self, test, extension, encoding):
+ path = self.expected_filename(test, extension)
+ if not os.path.exists(path):
+ return None
+ with codecs.open(path, 'r', encoding) as file:
+ return file.read()
+
+ def expected_checksum(self, test):
+ """Returns the checksum of the image we expect the test to produce, or None if it is a text-only test."""
+ return self._expected_file_contents(test, '.checksum', 'ascii')
+
+ def expected_image(self, test):
+ """Returns the image we expect the test to produce."""
+ return self._expected_file_contents(test, '.png', None)
+
+ def expected_text(self, test):
+ """Returns the text output we expect the test to produce."""
+ # NOTE: -expected.txt files are ALWAYS utf-8. However,
+ # we do not decode the output from DRT, so we should not
+ # decode the -expected.txt values either to allow comparisons.
+ text = self._expected_file_contents(test, '.txt', None)
+ if not text:
+ return ''
+ return text.strip("\r\n").replace("\r\n", "\n") + "\n"
+
def filename_to_uri(self, filename):
"""Convert a test file to a URI."""
LAYOUTTEST_HTTP_DIR = "http/tests/"
@@ -287,6 +315,73 @@ class Port(object):
return "file:///" + self.get_absolute_path(filename)
return "file://" + self.get_absolute_path(filename)
+ def tests(self, paths):
+ """Return the list of tests found (relative to layout_tests_dir()."""
+ return test_files.find(self, paths)
+
+ def test_dirs(self):
+ """Returns the list of top-level test directories.
+
+ Used by --clobber-old-results."""
+ layout_tests_dir = self.layout_tests_dir()
+ return filter(lambda x: os.path.isdir(os.path.join(layout_tests_dir, x)),
+ os.listdir(layout_tests_dir))
+
+ def path_isdir(self, path):
+ """Returns whether the path refers to a directory of tests.
+
+ Used by test_expectations.py to apply rules to whole directories."""
+ return os.path.isdir(path)
+
+ def path_exists(self, path):
+ """Returns whether the path refers to an existing test or baseline."""
+ # Used by test_expectations.py to determine if an entry refers to a
+ # valid test and by printing.py to determine if baselines exist."""
+ return os.path.exists(path)
+
+ def update_baseline(self, path, data, encoding):
+ """Updates the baseline for a test.
+
+ Args:
+ path: the actual path to use for baseline, not the path to
+ the test. This function is used to update either generic or
+ platform-specific baselines, but we can't infer which here.
+ data: contents of the baseline.
+ encoding: file encoding to use for the baseline.
+ """
+ with codecs.open(path, "w", encoding=encoding) as file:
+ file.write(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:///"):
+ if sys.platform == 'win32':
+ test = test.replace('file:///', '')
+ test = test.replace('/', '\\')
+ else:
+ test = test.replace('file://', '')
+ return self.relative_test_filename(test)
+
+ 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 get_absolute_path(self, filename):
"""Return the absolute path in unix format for the given filename.
@@ -369,10 +464,10 @@ class Port(object):
"""
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
@@ -588,7 +683,7 @@ class Port(object):
try:
with self._open_configuration_file() as file:
return file.readline().rstrip()
- except IOError, e:
+ except:
return None
# FIXME: This list may be incomplete as Apple has some sekret configs.