<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[284845] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/284845">284845</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2021-10-25 16:25:03 -0700 (Mon, 25 Oct 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>webkitpy: Add an explicit ImageDiffResult.passed rather than relying on diff_image being non-None
https://bugs.webkit.org/show_bug.cgi?id=232266

Reviewed by Jonathan Bedard.

A ref test was considered failing if it ImageDiffResult.diff_image was not None, allowing
for confusing unit tests that used a value of True for diff_image.

Fix by giving ImageDiffResult an explicit 'passes' field, and testing it rather than
diff_image.

Also used named arguments when creating ImageDiffResults for readability.

* Scripts/webkitpy/layout_tests/controllers/single_test_runner.py:
(SingleTestRunner._compare_image): Use `diff_result.passed` as truth for whether the test passed,
and only store the error_string in failure cases (which allows ImageDiff to spew diagnostic errors
without triggering failures).
(SingleTestRunner._compare_output_with_reference):
* Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py:
(TestResultWriterTest.test_reftest_diff_image.ImageDiffTestPort.diff_image):
(TestResultWriterTest):
* Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
(RunTest.test_tolerance.ImageDiffTestPort.diff_image):
* Scripts/webkitpy/port/base.py:
(Port.diff_image):
* Scripts/webkitpy/port/image_diff.py:
(ImageDiffResult.__init__):
(ImageDiffResult.__eq__):
(ImageDiffResult.__repr__):
(ImageDiffer._read):
* Scripts/webkitpy/port/port_testcase.py:
(PortTestCase.integration_test_image_diff):
(PortTestCase.test_diff_image__missing_both):
(PortTestCase.test_diff_image__missing_actual):
(PortTestCase.test_diff_image__missing_expected):
(PortTestCase.test_diff_image):
(PortTestCase.test_diff_image_passed):
(PortTestCase.test_diff_image_failed):
(PortTestCase.test_diff_image_crashed):
* Scripts/webkitpy/port/test.py:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpylayout_testscontrollerssingle_test_runnerpy">trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py</a></li>
<li><a href="#trunkToolsScriptswebkitpylayout_testscontrollerstest_result_writer_unittestpy">trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py</a></li>
<li><a href="#trunkToolsScriptswebkitpylayout_testsrun_webkit_tests_integrationtestpy">trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportbasepy">trunk/Tools/Scripts/webkitpy/port/base.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportimage_diffpy">trunk/Tools/Scripts/webkitpy/port/image_diff.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportport_testcasepy">trunk/Tools/Scripts/webkitpy/port/port_testcase.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyporttestpy">trunk/Tools/Scripts/webkitpy/port/test.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/ChangeLog       2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+2021-10-25  Simon Fraser  <simon.fraser@apple.com>
+
+        webkitpy: Add an explicit ImageDiffResult.passed rather than relying on diff_image being non-None
+        https://bugs.webkit.org/show_bug.cgi?id=232266
+
+        Reviewed by Jonathan Bedard.
+        
+        A ref test was considered failing if it ImageDiffResult.diff_image was not None, allowing
+        for confusing unit tests that used a value of True for diff_image.
+
+        Fix by giving ImageDiffResult an explicit 'passes' field, and testing it rather than
+        diff_image.
+
+        Also used named arguments when creating ImageDiffResults for readability.
+
+        * Scripts/webkitpy/layout_tests/controllers/single_test_runner.py:
+        (SingleTestRunner._compare_image): Use `diff_result.passed` as truth for whether the test passed,
+        and only store the error_string in failure cases (which allows ImageDiff to spew diagnostic errors
+        without triggering failures).
+        (SingleTestRunner._compare_output_with_reference):
+        * Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py:
+        (TestResultWriterTest.test_reftest_diff_image.ImageDiffTestPort.diff_image):
+        (TestResultWriterTest):
+        * Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
+        (RunTest.test_tolerance.ImageDiffTestPort.diff_image):
+        * Scripts/webkitpy/port/base.py:
+        (Port.diff_image):
+        * Scripts/webkitpy/port/image_diff.py:
+        (ImageDiffResult.__init__):
+        (ImageDiffResult.__eq__):
+        (ImageDiffResult.__repr__):
+        (ImageDiffer._read):
+        * Scripts/webkitpy/port/port_testcase.py:
+        (PortTestCase.integration_test_image_diff):
+        (PortTestCase.test_diff_image__missing_both):
+        (PortTestCase.test_diff_image__missing_actual):
+        (PortTestCase.test_diff_image__missing_expected):
+        (PortTestCase.test_diff_image):
+        (PortTestCase.test_diff_image_passed):
+        (PortTestCase.test_diff_image_failed):
+        (PortTestCase.test_diff_image_crashed):
+        * Scripts/webkitpy/port/test.py:
+
</ins><span class="cx"> 2021-10-25  Alex Christensen  <achristensen@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         WebKit ought to be able to play videos without Content-Length HTTP header fields and without range support
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpylayout_testscontrollerssingle_test_runnerpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py      2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py 2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -294,17 +294,15 @@
</span><span class="cx">             failures.append(test_failures.FailureMissingImageHash())
</span><span class="cx">         elif driver_output.image_hash != expected_driver_output.image_hash:
</span><span class="cx">             diff_result = self._port.diff_image(expected_driver_output.image, driver_output.image)
</span><del>-            if diff_result.error_string:
-                _log.warning('  %s : %s' % (self._test_name, diff_result.error_string))
-                failures.append(test_failures.FailureImageHashMismatch())
-                driver_output.error = (driver_output.error or '') + diff_result.error_string
</del><ins>+            if not diff_result.passed:
+                failures.append(test_failures.FailureImageHashMismatch(diff_result.diff_percent))
+                if diff_result.error_string:
+                    _log.warning('  %s : %s' % (self._test_name, diff_result.error_string))
+                    driver_output.error = (driver_output.error or '') + diff_result.error_string
+                driver_output.image_diff = diff_result.diff_image
</ins><span class="cx">             else:
</span><del>-                driver_output.image_diff = diff_result.diff_image
-                if driver_output.image_diff:
-                    failures.append(test_failures.FailureImageHashMismatch(diff_result.diff_percent))
-                else:
-                    # See https://bugs.webkit.org/show_bug.cgi?id=69444 for why this isn't a full failure.
-                    _log.warning('  %s -> pixel hash failed (but diff passed)' % self._test_name)
</del><ins>+                # See https://bugs.webkit.org/show_bug.cgi?id=69444 for why this isn't a full failure.
+                _log.warning('  %s -> pixel hash failed (but diff passed)' % self._test_name)
</ins><span class="cx">         return failures
</span><span class="cx"> 
</span><span class="cx">     def _run_reftest(self):
</span><span class="lines">@@ -357,11 +355,10 @@
</span><span class="cx">         elif reference_driver_output.image_hash != actual_driver_output.image_hash:
</span><span class="cx">             # ImageDiff has a hard coded color distance threshold even though tolerance=0 is specified.
</span><span class="cx">             diff_result = self._port.diff_image(reference_driver_output.image, actual_driver_output.image, tolerance=0)
</span><del>-            if diff_result.error_string:
-                _log.warning('  %s : %s' % (self._test_name, diff_result.error_string))
</del><ins>+            if not diff_result.passed:
</ins><span class="cx">                 failures.append(test_failures.FailureReftestMismatch(reference_filename))
</span><del>-                actual_driver_output.error = (actual_driver_output.error or '') + diff_result.error_string
-            elif diff_result.diff_image:
-                failures.append(test_failures.FailureReftestMismatch(reference_filename))
</del><ins>+                if diff_result.error_string:
+                    _log.warning('  %s : %s' % (self._test_name, diff_result.error_string))
+                    actual_driver_output.error = (actual_driver_output.error or '') + diff_result.error_string
</ins><span class="cx"> 
</span><span class="cx">         return TestResult(self._test_input, failures, total_test_time, has_stderr, pid=actual_driver_output.pid)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpylayout_testscontrollerstest_result_writer_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py     2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py        2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx">         class ImageDiffTestPort(TestPort):
</span><span class="cx">             def diff_image(self, expected_contents, actual_contents, tolerance=None):
</span><span class="cx">                 used_tolerance_values.append(tolerance)
</span><del>-                return ImageDiffResult(True, 1, None)
</del><ins>+                return ImageDiffResult(passed=False, diff_image=b'', difference=1)
</ins><span class="cx"> 
</span><span class="cx">         host = MockHost()
</span><span class="cx">         port = ImageDiffTestPort(host)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpylayout_testsrun_webkit_tests_integrationtestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py    2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py       2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -752,7 +752,7 @@
</span><span class="cx">         class ImageDiffTestPort(test.TestPort):
</span><span class="cx">             def diff_image(self, expected_contents, actual_contents, tolerance=None):
</span><span class="cx">                 self.tolerance_used_for_diff_image = self._options.tolerance
</span><del>-                return ImageDiffResult(True, 1, None)
</del><ins>+                return ImageDiffResult(passed=False, diff_image=b'', difference=1)
</ins><span class="cx"> 
</span><span class="cx">         def get_port_for_run(args):
</span><span class="cx">             options, parsed_args = run_webkit_tests.parse_args(args)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportbasepy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/base.py (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/base.py        2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/base.py   2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -307,10 +307,10 @@
</span><span class="cx">         If an error occurs (like ImageDiff isn't found, or crashes, we log an error and return True (for a diff).
</span><span class="cx">         """
</span><span class="cx">         if not actual_contents and not expected_contents:
</span><del>-            return ImageDiffResult(None, 0, None)
</del><ins>+            return ImageDiffResult(passed=True, diff_image=None, difference=0)
</ins><span class="cx"> 
</span><span class="cx">         if not actual_contents or not expected_contents:
</span><del>-            return ImageDiffResult(True, 0, None)
</del><ins>+            return ImageDiffResult(passed=False, diff_image=b'', difference=1)
</ins><span class="cx"> 
</span><span class="cx">         if not self._image_differ:
</span><span class="cx">             self._image_differ = image_diff.ImageDiffer(self)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportimage_diffpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/image_diff.py (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/image_diff.py  2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/image_diff.py     2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -40,7 +40,8 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class ImageDiffResult(object):
</span><del>-    def __init__(self, diff_image, difference, error_string):
</del><ins>+    def __init__(self, passed, diff_image, difference, error_string=None):
+        self.passed = passed
</ins><span class="cx">         self.diff_image = diff_image
</span><span class="cx">         self.diff_percent = difference
</span><span class="cx">         self.error_string = error_string
</span><span class="lines">@@ -47,7 +48,8 @@
</span><span class="cx"> 
</span><span class="cx">     def __eq__(self, other):
</span><span class="cx">         if isinstance(other, self.__class__):
</span><del>-            return (self.diff_image == other.diff_image and
</del><ins>+            return (self.passed == other.passed and
+                    self.diff_image == other.diff_image and
</ins><span class="cx">                     self.diff_percent == other.diff_percent and
</span><span class="cx">                     self.error_string == other.error_string)
</span><span class="cx"> 
</span><span class="lines">@@ -57,7 +59,7 @@
</span><span class="cx">         return not self.__eq__(other)
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><del>-        return 'ImageDiffResult({} {} {})'.format(self.diff_image, self.diff_percent, self.error_string)
</del><ins>+        return 'ImageDiffResult(Passed {} {} {} {})'.format(self.passed, self.diff_image, self.diff_percent, self.error_string)
</ins><span class="cx"> 
</span><span class="cx"> class ImageDiffer(object):
</span><span class="cx">     def __init__(self, port):
</span><span class="lines">@@ -128,10 +130,10 @@
</span><span class="cx">         if output and output.startswith(b'diff'):
</span><span class="cx">             m = re.match(b'diff: (.+)% (passed|failed)', output)
</span><span class="cx">             if m.group(2) == b'passed':
</span><del>-                return ImageDiffResult(None, 0, None)
</del><ins>+                return ImageDiffResult(passed=True, diff_image=None, difference=0)
</ins><span class="cx">             diff_percent = float(string_utils.decode(m.group(1), target_type=str))
</span><span class="cx"> 
</span><del>-        return ImageDiffResult(output_image, diff_percent, err_str or None)
</del><ins>+        return ImageDiffResult(passed=False, diff_image=output_image, difference=diff_percent, error_string=err_str or None)
</ins><span class="cx"> 
</span><span class="cx">     def stop(self):
</span><span class="cx">         if self._process:
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportport_testcasepy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/port_testcase.py (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/port_testcase.py       2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/port_testcase.py  2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -249,36 +249,35 @@
</span><span class="cx">         dir = port.layout_tests_dir()
</span><span class="cx">         file1 = port._filesystem.join(dir, 'fast', 'css', 'button_center.png')
</span><span class="cx">         contents1 = port._filesystem.read_binary_file(file1)
</span><del>-        file2 = port._filesystem.join(dir, 'fast', 'css',
-                                      'remove-shorthand-expected.png')
</del><ins>+        file2 = port._filesystem.join(dir, 'fast', 'css', 'remove-shorthand-expected.png')
</ins><span class="cx">         contents2 = port._filesystem.read_binary_file(file2)
</span><span class="cx">         tmpfd, tmpfile = port._filesystem.open_binary_tempfile('')
</span><span class="cx">         tmpfd.close()
</span><span class="cx"> 
</span><del>-        self.assertFalse(port.diff_image(contents1, contents1).diff_image)
-        self.assertTrue(port.diff_image(contents1, contents2).diff_image)
</del><ins>+        self.assertTrue(port.diff_image(contents1, contents1).passed)
+        self.assertFalse(port.diff_image(contents1, contents2).passed)
</ins><span class="cx"> 
</span><del>-        self.assertTrue(port.diff_image(contents1, contents2, tmpfile).diff_image)
</del><ins>+        self.assertFalse(port.diff_image(contents1, contents2, tmpfile).passed)
</ins><span class="cx"> 
</span><span class="cx">         port._filesystem.remove(tmpfile)
</span><span class="cx"> 
</span><span class="cx">     def test_diff_image__missing_both(self):
</span><span class="cx">         port = self.make_port()
</span><del>-        self.assertFalse(port.diff_image(None, None).diff_image)
-        self.assertFalse(port.diff_image(None, b'').diff_image)
-        self.assertFalse(port.diff_image(b'', None).diff_image)
</del><ins>+        self.assertTrue(port.diff_image(None, None).passed)
+        self.assertTrue(port.diff_image(None, b'').passed)
+        self.assertTrue(port.diff_image(b'', None).passed)
</ins><span class="cx"> 
</span><del>-        self.assertFalse(port.diff_image(b'', b'').diff_image)
</del><ins>+        self.assertTrue(port.diff_image(b'', b'').passed)
</ins><span class="cx"> 
</span><span class="cx">     def test_diff_image__missing_actual(self):
</span><span class="cx">         port = self.make_port()
</span><del>-        self.assertTrue(port.diff_image(None, b'foo').diff_image)
-        self.assertTrue(port.diff_image(b'', b'foo').diff_image)
</del><ins>+        self.assertFalse(port.diff_image(None, b'foo').passed)
+        self.assertFalse(port.diff_image(b'', b'foo').passed)
</ins><span class="cx"> 
</span><span class="cx">     def test_diff_image__missing_expected(self):
</span><span class="cx">         port = self.make_port()
</span><del>-        self.assertTrue(port.diff_image(b'foo', None).diff_image)
-        self.assertTrue(port.diff_image(b'foo', b'').diff_image)
</del><ins>+        self.assertFalse(port.diff_image(b'foo', None).passed)
+        self.assertFalse(port.diff_image(b'foo', b'').passed)
</ins><span class="cx"> 
</span><span class="cx">     def test_diff_image(self):
</span><span class="cx">         port = self.make_port()
</span><span class="lines">@@ -298,11 +297,11 @@
</span><span class="cx">         # First test the case of not using the JHBuild wrapper.
</span><span class="cx">         self.assertFalse(port._should_use_jhbuild())
</span><span class="cx"> 
</span><del>-        self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(b'', 100.0, None))
</del><ins>+        self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
</ins><span class="cx">         self.assertEqual(self.proc.cmd, [port._path_to_image_diff(), "--tolerance", "0.1"])
</span><del>-        self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(b'', 100.0, None))
</del><ins>+        self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
</ins><span class="cx">         self.assertEqual(self.proc.cmd, [port._path_to_image_diff(), "--tolerance", "0.1"])
</span><del>-        self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(b'', 100.0, None))
</del><ins>+        self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
</ins><span class="cx">         self.assertEqual(self.proc.cmd, [port._path_to_image_diff(), "--tolerance", "0"])
</span><span class="cx"> 
</span><span class="cx">         # Now test the case of using JHBuild wrapper.
</span><span class="lines">@@ -309,11 +308,11 @@
</span><span class="cx">         port._filesystem.maybe_make_directory(port.path_from_webkit_base('WebKitBuild', 'Dependencies%s' % port.port_name.upper()))
</span><span class="cx">         self.assertTrue(port._should_use_jhbuild())
</span><span class="cx"> 
</span><del>-        self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(b'', 100.0, None))
</del><ins>+        self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
</ins><span class="cx">         self.assertEqual(self.proc.cmd, port._jhbuild_wrapper + [port._path_to_image_diff(), "--tolerance", "0.1"])
</span><del>-        self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(b'', 100.0, None))
</del><ins>+        self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
</ins><span class="cx">         self.assertEqual(self.proc.cmd, port._jhbuild_wrapper + [port._path_to_image_diff(), "--tolerance", "0.1"])
</span><del>-        self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(b'', 100.0, None))
</del><ins>+        self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
</ins><span class="cx">         self.assertEqual(self.proc.cmd, port._jhbuild_wrapper + [port._path_to_image_diff(), "--tolerance", "0"])
</span><span class="cx"> 
</span><span class="cx">         port.clean_up_test_run()
</span><span class="lines">@@ -324,13 +323,13 @@
</span><span class="cx">         port = self.make_port()
</span><span class="cx">         port._server_process_constructor = lambda port, nm, cmd, env, crash_message=None: MockServerProcess(lines=['diff: 0% passed\n'])
</span><span class="cx">         image_differ = ImageDiffer(port)
</span><del>-        self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(None, 0, None))
</del><ins>+        self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(passed=True, diff_image=None, difference=0))
</ins><span class="cx"> 
</span><span class="cx">     def test_diff_image_failed(self):
</span><span class="cx">         port = self.make_port()
</span><span class="cx">         port._server_process_constructor = lambda port, nm, cmd, env, crash_message=None: MockServerProcess(lines=['diff: 100% failed\n'])
</span><span class="cx">         image_differ = ImageDiffer(port)
</span><del>-        self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(b'', 100.0, None))
</del><ins>+        self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
</ins><span class="cx"> 
</span><span class="cx">     def test_diff_image_crashed(self):
</span><span class="cx">         port = self.make_port()
</span><span class="lines">@@ -346,7 +345,7 @@
</span><span class="cx"> 
</span><span class="cx">         port._server_process_constructor = make_proc
</span><span class="cx">         port.setup_test_run()
</span><del>-        self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(b'', 0, 'ImageDiff crashed\n'))
</del><ins>+        self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(passed=False, diff_image=b'', difference=0, error_string='ImageDiff crashed\n'))
</ins><span class="cx">         port.clean_up_test_run()
</span><span class="cx"> 
</span><span class="cx">     @slow
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyporttestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/test.py (284844 => 284845)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/test.py        2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/test.py   2021-10-25 23:25:03 UTC (rev 284845)
</span><span class="lines">@@ -408,20 +408,23 @@
</span><span class="cx">         actual_contents = string_utils.encode(actual_contents)
</span><span class="cx">         diffed = actual_contents != expected_contents
</span><span class="cx">         if not actual_contents and not expected_contents:
</span><del>-            return ImageDiffResult(None, 0, None)
</del><ins>+            return ImageDiffResult(passed=True, diff_image=None, difference=0)
</ins><span class="cx"> 
</span><span class="cx">         if not actual_contents or not expected_contents:
</span><del>-            return ImageDiffResult(True, 0, None)
</del><ins>+            return ImageDiffResult(passed=False, diff_image=b'', difference=0)
</ins><span class="cx"> 
</span><span class="cx">         if b'ref' in expected_contents:
</span><span class="cx">             assert tolerance == 0
</span><span class="cx">         if diffed:
</span><del>-            return ImageDiffResult("< {}\n---\n> {}\n".format(
-                string_utils.decode(expected_contents, target_type=str),
-                string_utils.decode(actual_contents, target_type=str),
-            ), 1, None)
</del><ins>+            return ImageDiffResult(
+                passed=False,
+                diff_image="< {}\n---\n> {}\n".format(
+                    string_utils.decode(expected_contents, target_type=str),
+                    string_utils.decode(actual_contents, target_type=str),
+                ),
+                difference=1)
</ins><span class="cx"> 
</span><del>-        return ImageDiffResult(None, 0, None)
</del><ins>+        return ImageDiffResult(passed=True, diff_image=None, difference=0)
</ins><span class="cx"> 
</span><span class="cx">     def layout_tests_dir(self):
</span><span class="cx">         return LAYOUT_TEST_DIR
</span></span></pre>
</div>
</div>

</body>
</html>