<!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>[206237] trunk</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/206237">206237</a></dd>
<dt>Author</dt> <dd>mattbaker@apple.com</dd>
<dt>Date</dt> <dd>2016-09-21 14:40:22 -0700 (Wed, 21 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Improve output of TestHarness.expect* failures
https://bugs.webkit.org/show_bug.cgi?id=162177
&lt;rdar://problem/28367186&gt;

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

This patch adds specific expectation functions to TestHarness, to better
express intent when writing tests, and to allow more details to be logged
in the event of a failure.

For functions taking both `actual` and `expected` parameters, the `actual`
parameter comes first. This convention simplifies the implementation of
TestHarness, improves the readability of tests involving inequalities,
and is consistent with XCTest assertions.

* UserInterface/Test/TestHarness.js:
(TestHarness):
(TestHarness.prototype.expectThat):
(TestHarness.prototype.expectFalse):
(TestHarness.prototype.expectNull):
(TestHarness.prototype.expectNotNull):
(TestHarness.prototype.expectEqual):
(TestHarness.prototype.expectNotEqual):
(TestHarness.prototype.expectShallowEqual):
(TestHarness.prototype.expectNotShallowEqual):
(TestHarness.prototype.expectEqualWithAccuracy):
(TestHarness.prototype.expectLessThan):
(TestHarness.prototype.expectLessThanOrEqual):
(TestHarness.prototype.expectGreaterThan):
(TestHarness.prototype.expectGreaterThanOrEqual):
New expectation functions, all of which call _expect under the hood.

(TestHarness.prototype._expect):
Helper method which calls pass or fail. Creates a message when no user
message is provided, and logs expected and actual values in the event
of a failure.

(TestHarness.prototype._expectationValueAsString):
(TestHarness.prototype._expectationMessageFormat):
Get a message format string for the expectation type. Used to create
pass/fail message when no user message is provided.

(TestHarness.prototype._expectedValueFormat):
Get a format string for displaying the expected value. Used to create
the &quot;Expected: &quot; failure message line.

LayoutTests:

Extend coverage to more TestHarness messages by omitting the optional
`message` parameter when calling expect* functions.

Other improvements:
- expectEqual/expectNotEqual should test WebInspector object instances,
  to cover more TestHarness message formatting cases.
- expectEqual/expectNotEqual should test shallow equal arrays, since the
  test is for strict equality.

* inspector/indexeddb/requestData-expected.txt:
* inspector/unit-tests/number-utilities-expected.txt:
Updated expectations for new TestHarness output.

* inspector/unit-tests/test-harness-expect-functions-expected.txt:
* inspector/unit-tests/test-harness-expect-functions.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectorindexeddbrequestDataexpectedtxt">trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorunittestsnumberutilitiesexpectedtxt">trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorunitteststestharnessexpectfunctionsexpectedtxt">trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorunitteststestharnessexpectfunctionshtml">trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceTestTestHarnessjs">trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/ChangeLog        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-09-21  Matt Baker  &lt;mattbaker@apple.com&gt;
+
+        Web Inspector: Improve output of TestHarness.expect* failures
+        https://bugs.webkit.org/show_bug.cgi?id=162177
+        &lt;rdar://problem/28367186&gt;
+
+        Reviewed by Joseph Pecoraro.
+
+        Extend coverage to more TestHarness messages by omitting the optional
+        `message` parameter when calling expect* functions.
+
+        Other improvements:
+        - expectEqual/expectNotEqual should test WebInspector object instances,
+          to cover more TestHarness message formatting cases.
+        - expectEqual/expectNotEqual should test shallow equal arrays, since the
+          test is for strict equality.
+
+        * inspector/indexeddb/requestData-expected.txt:
+        * inspector/unit-tests/number-utilities-expected.txt:
+        Updated expectations for new TestHarness output.
+
+        * inspector/unit-tests/test-harness-expect-functions-expected.txt:
+        * inspector/unit-tests/test-harness-expect-functions.html:
+
</ins><span class="cx"> 2016-09-21  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Marking inspector/css/manager-preferredInspectorStyleSheetForFrame.html as flaky on mac.
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorindexeddbrequestDataexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -41,9 +41,13 @@
</span><span class="cx"> PASS: Key should be ordered by email: 'beaver@webkit.org'
</span><span class="cx"> PASS: Value should be a remote object for: 'Monstrous Beaver'
</span><span class="cx"> FAIL: Primary key should be ordered by email: 2
</span><ins>+    Expected: truthy
+    Actual: false
</ins><span class="cx"> PASS: Key should be ordered by email: 'hampster@webkit.org'
</span><span class="cx"> PASS: Value should be a remote object for: 'Thirsty Hampster'
</span><span class="cx"> FAIL: Primary key should be ordered by email: 1
</span><ins>+    Expected: truthy
+    Actual: false
</ins><span class="cx"> PASS: Key should be ordered by email: 'peacock@webkit.org'
</span><span class="cx"> PASS: Value should be a remote object for: 'Jamming Peacock'
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunittestsnumberutilitiesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -12,6 +12,8 @@
</span><span class="cx"> PASS: constrain of a value above max becomes max
</span><span class="cx"> PASS: constrain of a value above max becomes max
</span><span class="cx"> FAIL: constrain of NaN becomes min
</span><ins>+    Expected: truthy
+    Actual: false
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: Number.secondsToString
</span><span class="cx"> PASS: normal resolution of 0ms should be ms with no decimals
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunitteststestharnessexpectfunctionsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -11,11 +11,23 @@
</span><span class="cx"> PASS: expectThat([])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectThat(false)
</span><ins>+    Expected: truthy
+    Actual: false
</ins><span class="cx"> FAIL: expectThat(0)
</span><ins>+    Expected: truthy
+    Actual: 0
</ins><span class="cx"> FAIL: expectThat(&quot;&quot;)
</span><ins>+    Expected: truthy
+    Actual: &quot;&quot;
</ins><span class="cx"> FAIL: expectThat(null)
</span><ins>+    Expected: truthy
+    Actual: null
</ins><span class="cx"> FAIL: expectThat(undefined)
</span><ins>+    Expected: truthy
+    Actual: undefined
</ins><span class="cx"> FAIL: expectThat(NaN)
</span><ins>+    Expected: truthy
+    Actual: NaN
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectFalse
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -27,10 +39,20 @@
</span><span class="cx"> PASS: expectFalse(NaN)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectFalse(true)
</span><ins>+    Expected: falsey
+    Actual: true
</ins><span class="cx"> FAIL: expectFalse(1)
</span><ins>+    Expected: falsey
+    Actual: 1
</ins><span class="cx"> FAIL: expectFalse(&quot;abc&quot;)
</span><ins>+    Expected: falsey
+    Actual: &quot;abc&quot;
</ins><span class="cx"> FAIL: expectFalse({})
</span><ins>+    Expected: falsey
+    Actual: {}
</ins><span class="cx"> FAIL: expectFalse([])
</span><ins>+    Expected: falsey
+    Actual: []
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectNull
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -37,12 +59,26 @@
</span><span class="cx"> PASS: expectNull(null)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNull(true)
</span><ins>+    Expected: null
+    Actual: true
</ins><span class="cx"> FAIL: expectNull(false)
</span><ins>+    Expected: null
+    Actual: false
</ins><span class="cx"> FAIL: expectNull(1)
</span><ins>+    Expected: null
+    Actual: 1
</ins><span class="cx"> FAIL: expectNull(&quot;&quot;)
</span><ins>+    Expected: null
+    Actual: &quot;&quot;
</ins><span class="cx"> FAIL: expectNull(undefined)
</span><ins>+    Expected: null
+    Actual: undefined
</ins><span class="cx"> FAIL: expectNull({})
</span><ins>+    Expected: null
+    Actual: {}
</ins><span class="cx"> FAIL: expectNull([])
</span><ins>+    Expected: null
+    Actual: []
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectNotNull
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -55,11 +91,14 @@
</span><span class="cx"> PASS: expectNotNull([])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNotNull(null)
</span><ins>+    Expected: not null
+    Actual: null
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectEqual
</span><span class="cx"> Expected to PASS
</span><span class="cx"> PASS: expectEqual(true, true)
</span><span class="cx"> PASS: expectEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;a&quot;:1,&quot;b&quot;:2})
</span><ins>+PASS: expectEqual(CSSStyleDeclaration instance #1, CSSStyleDeclaration instance #1)
</ins><span class="cx"> PASS: expectEqual(1.23, 1.23)
</span><span class="cx"> PASS: expectEqual(&quot;abc&quot;, &quot;abc&quot;)
</span><span class="cx"> PASS: expectEqual(null, null)
</span><span class="lines">@@ -66,18 +105,38 @@
</span><span class="cx"> PASS: expectEqual(undefined, undefined)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectEqual(true, false)
</span><del>-FAIL: expectEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;c&quot;:3,&quot;d&quot;:4})
</del><ins>+    Expected: false
+    Actual: true
+FAIL: expectEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;a&quot;:1,&quot;b&quot;:2})
+    Expected: {&quot;a&quot;:1,&quot;b&quot;:2}
+    Actual: {&quot;a&quot;:1,&quot;b&quot;:2}
+FAIL: expectEqual(CSSStyleDeclaration instance #1, CSSRule instance #2)
+    Expected: CSSRule instance #2
+    Actual: CSSStyleDeclaration instance #1
</ins><span class="cx"> FAIL: expectEqual(1.23, 4.56)
</span><ins>+    Expected: 4.56
+    Actual: 1.23
</ins><span class="cx"> FAIL: expectEqual(&quot;abc&quot;, &quot;def&quot;)
</span><ins>+    Expected: &quot;def&quot;
+    Actual: &quot;abc&quot;
</ins><span class="cx"> FAIL: expectEqual(null, undefined)
</span><ins>+    Expected: undefined
+    Actual: null
</ins><span class="cx"> FAIL: expectEqual(NaN, NaN)
</span><ins>+    Expected: NaN
+    Actual: NaN
</ins><span class="cx"> FAIL: expectEqual({}, {})
</span><ins>+    Expected: {}
+    Actual: {}
</ins><span class="cx"> FAIL: expectEqual([], [])
</span><ins>+    Expected: []
+    Actual: []
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectNotEqual
</span><span class="cx"> Expected to PASS
</span><span class="cx"> PASS: expectNotEqual(true, false)
</span><del>-PASS: expectNotEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;c&quot;:3,&quot;d&quot;:4})
</del><ins>+PASS: expectNotEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;a&quot;:1,&quot;b&quot;:2})
+PASS: expectNotEqual(CSSStyleDeclaration instance #1, CSSRule instance #2)
</ins><span class="cx"> PASS: expectNotEqual(1.23, 4.56)
</span><span class="cx"> PASS: expectNotEqual(&quot;abc&quot;, &quot;def&quot;)
</span><span class="cx"> PASS: expectNotEqual(null, undefined)
</span><span class="lines">@@ -86,11 +145,26 @@
</span><span class="cx"> PASS: expectNotEqual([], [])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNotEqual(true, true)
</span><ins>+    Expected: not true
+    Actual: true
</ins><span class="cx"> FAIL: expectNotEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;a&quot;:1,&quot;b&quot;:2})
</span><ins>+    Expected: not {&quot;a&quot;:1,&quot;b&quot;:2}
+    Actual: {&quot;a&quot;:1,&quot;b&quot;:2}
+FAIL: expectNotEqual(CSSStyleDeclaration instance #1, CSSStyleDeclaration instance #1)
+    Expected: not CSSStyleDeclaration instance #1
+    Actual: CSSStyleDeclaration instance #1
</ins><span class="cx"> FAIL: expectNotEqual(1.23, 1.23)
</span><ins>+    Expected: not 1.23
+    Actual: 1.23
</ins><span class="cx"> FAIL: expectNotEqual(&quot;abc&quot;, &quot;abc&quot;)
</span><ins>+    Expected: not &quot;abc&quot;
+    Actual: &quot;abc&quot;
</ins><span class="cx"> FAIL: expectNotEqual(null, null)
</span><ins>+    Expected: not null
+    Actual: null
</ins><span class="cx"> FAIL: expectNotEqual(undefined, undefined)
</span><ins>+    Expected: not undefined
+    Actual: undefined
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectShallowEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -99,7 +173,11 @@
</span><span class="cx"> PASS: expectShallowEqual([], [])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectShallowEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;a&quot;:3,&quot;b&quot;:4})
</span><ins>+    Expected: {&quot;a&quot;:3,&quot;b&quot;:4}
+    Actual: {&quot;a&quot;:1,&quot;b&quot;:2}
</ins><span class="cx"> FAIL: expectShallowEqual({}, [])
</span><ins>+    Expected: []
+    Actual: {}
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectNotShallowEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -107,8 +185,14 @@
</span><span class="cx"> PASS: expectNotShallowEqual({}, [])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNotShallowEqual({&quot;a&quot;:1,&quot;b&quot;:2}, {&quot;a&quot;:1,&quot;b&quot;:2})
</span><ins>+    Expected: not {&quot;a&quot;:1,&quot;b&quot;:2}
+    Actual: {&quot;a&quot;:1,&quot;b&quot;:2}
</ins><span class="cx"> FAIL: expectNotShallowEqual({}, {})
</span><ins>+    Expected: not {}
+    Actual: {}
</ins><span class="cx"> FAIL: expectNotShallowEqual([], [])
</span><ins>+    Expected: not []
+    Actual: []
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectEqualWithAccuracy
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -118,7 +202,11 @@
</span><span class="cx"> PASS: expectEqualWithAccuracy(1, 0, 1)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectEqualWithAccuracy(0, 2, 1)
</span><ins>+    Expected: 2 +/- 1
+    Actual: 0
</ins><span class="cx"> FAIL: expectEqualWithAccuracy(2, 0, 1)
</span><ins>+    Expected: 0 +/- 1
+    Actual: 2
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectLessThan
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -126,9 +214,17 @@
</span><span class="cx"> PASS: expectLessThan(&quot;abc&quot;, &quot;def&quot;)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectLessThan(0, 0)
</span><ins>+    Expected: less than 0
+    Actual: 0
</ins><span class="cx"> FAIL: expectLessThan(1, 0)
</span><ins>+    Expected: less than 0
+    Actual: 1
</ins><span class="cx"> FAIL: expectLessThan(&quot;abc&quot;, &quot;abc&quot;)
</span><ins>+    Expected: less than &quot;abc&quot;
+    Actual: &quot;abc&quot;
</ins><span class="cx"> FAIL: expectLessThan(&quot;def&quot;, &quot;abc&quot;)
</span><ins>+    Expected: less than &quot;abc&quot;
+    Actual: &quot;def&quot;
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectLessThanOrEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -138,7 +234,11 @@
</span><span class="cx"> PASS: expectLessThanOrEqual(&quot;abc&quot;, &quot;abc&quot;)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectLessThanOrEqual(1, 0)
</span><ins>+    Expected: less than or equal to 0
+    Actual: 1
</ins><span class="cx"> FAIL: expectLessThanOrEqual(&quot;def&quot;, &quot;abc&quot;)
</span><ins>+    Expected: less than or equal to &quot;abc&quot;
+    Actual: &quot;def&quot;
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectGreaterThan
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -146,9 +246,17 @@
</span><span class="cx"> PASS: expectGreaterThan(&quot;def&quot;, &quot;abc&quot;)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectGreaterThan(0, 0)
</span><ins>+    Expected: greater than 0
+    Actual: 0
</ins><span class="cx"> FAIL: expectGreaterThan(0, 1)
</span><ins>+    Expected: greater than 1
+    Actual: 0
</ins><span class="cx"> FAIL: expectGreaterThan(&quot;abc&quot;, &quot;abc&quot;)
</span><ins>+    Expected: greater than &quot;abc&quot;
+    Actual: &quot;abc&quot;
</ins><span class="cx"> FAIL: expectGreaterThan(&quot;abc&quot;, &quot;def&quot;)
</span><ins>+    Expected: greater than &quot;def&quot;
+    Actual: &quot;abc&quot;
</ins><span class="cx"> 
</span><span class="cx"> -- Running test case: InspectorTest.expectGreaterThanOrEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -158,5 +266,9 @@
</span><span class="cx"> PASS: expectGreaterThanOrEqual(&quot;abc&quot;, &quot;abc&quot;)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectGreaterThanOrEqual(0, 1)
</span><ins>+    Expected: greater than or equal to 1
+    Actual: 0
</ins><span class="cx"> FAIL: expectGreaterThanOrEqual(&quot;abc&quot;, &quot;def&quot;)
</span><ins>+    Expected: greater than or equal to &quot;def&quot;
+    Actual: &quot;abc&quot;
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunitteststestharnessexpectfunctionshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -5,8 +5,6 @@
</span><span class="cx"> &lt;script&gt;
</span><span class="cx"> function test()
</span><span class="cx"> {
</span><del>-    console.assert(false, &quot;FAIL ASSERTION!!!!!!!&quot;);
-
</del><span class="cx">     let suite = InspectorTest.createSyncSuite(&quot;InspectorTestExpectFunctions&quot;);
</span><span class="cx"> 
</span><span class="cx">     function toArray(a) {
</span><span class="lines">@@ -13,15 +11,6 @@
</span><span class="cx">         return a instanceof Array &amp;&amp; a.length ? a : [a];
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    function stringifyArguments(args) {
-        return args.map((a) =&gt; {
-            if (typeof a === &quot;number&quot;)
-                return a;
-            // Append empty string so `undefined` is displayed correctly.
-            return JSON.stringify(a) + &quot;&quot;;
-        }).join(&quot;, &quot;);
-    }
-
</del><span class="cx">     function addTestCase({functionName, passingInputs, failingInputs}) {
</span><span class="cx">         let functionUnderTest = InspectorTest[functionName];
</span><span class="cx">         InspectorTest.assert(typeof functionUnderTest === &quot;function&quot;, &quot;Unknown InspectorTest function: &quot; + functionName);
</span><span class="lines">@@ -36,10 +25,8 @@
</span><span class="cx">                     }
</span><span class="cx"> 
</span><span class="cx">                     InspectorTest.log(&quot;Expected to &quot; + (shouldPass ? &quot;PASS&quot; : &quot;FAIL&quot;));
</span><del>-                    for (let input of inputs.map(toArray)) {
-                        let argumentsString = stringifyArguments(input);
-                        functionUnderTest.call(InspectorTest, ...input, `${functionName}(${argumentsString})`);
-                    }
</del><ins>+                    for (let input of inputs.map(toArray))
+                        functionUnderTest.call(InspectorTest, ...input);
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 exerciseFunction(passingInputs, true);
</span><span class="lines">@@ -70,12 +57,15 @@
</span><span class="cx">     addInverseTestCase(&quot;expectNotNull&quot;, expectNullTestCase);
</span><span class="cx"> 
</span><span class="cx">     let object1 = {a: 1, b: 2};
</span><del>-    let object2 = {c: 3, d: 4};
</del><ins>+    let object2 = {a: 1, b: 2};
+    let customObject1 = new WebInspector.CSSStyleDeclaration;
+    let customObject2 = new WebInspector.CSSRule;
</ins><span class="cx">     let expectEqualTestCase = {
</span><span class="cx">         functionName: &quot;expectEqual&quot;,
</span><span class="cx">         passingInputs: [
</span><span class="cx">             [true, true],
</span><span class="cx">             [object1, object1],
</span><ins>+            [customObject1, customObject1],
</ins><span class="cx">             [1.23, 1.23],
</span><span class="cx">             [&quot;abc&quot;, &quot;abc&quot;],
</span><span class="cx">             [null, null],
</span><span class="lines">@@ -84,6 +74,7 @@
</span><span class="cx">         failingInputs: [
</span><span class="cx">             [true, false],
</span><span class="cx">             [object1, object2],
</span><ins>+            [customObject1, customObject2],
</ins><span class="cx">             [1.23, 4.56],
</span><span class="cx">             [&quot;abc&quot;, &quot;def&quot;],
</span><span class="cx">             [null, undefined],
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/Source/WebInspectorUI/ChangeLog        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2016-09-21  Matt Baker  &lt;mattbaker@apple.com&gt;
+
+        Web Inspector: Improve output of TestHarness.expect* failures
+        https://bugs.webkit.org/show_bug.cgi?id=162177
+        &lt;rdar://problem/28367186&gt;
+
+        Reviewed by Joseph Pecoraro.
+
+        This patch adds specific expectation functions to TestHarness, to better
+        express intent when writing tests, and to allow more details to be logged
+        in the event of a failure.
+
+        For functions taking both `actual` and `expected` parameters, the `actual`
+        parameter comes first. This convention simplifies the implementation of
+        TestHarness, improves the readability of tests involving inequalities,
+        and is consistent with XCTest assertions.
+
+        * UserInterface/Test/TestHarness.js:
+        (TestHarness):
+        (TestHarness.prototype.expectThat):
+        (TestHarness.prototype.expectFalse):
+        (TestHarness.prototype.expectNull):
+        (TestHarness.prototype.expectNotNull):
+        (TestHarness.prototype.expectEqual):
+        (TestHarness.prototype.expectNotEqual):
+        (TestHarness.prototype.expectShallowEqual):
+        (TestHarness.prototype.expectNotShallowEqual):
+        (TestHarness.prototype.expectEqualWithAccuracy):
+        (TestHarness.prototype.expectLessThan):
+        (TestHarness.prototype.expectLessThanOrEqual):
+        (TestHarness.prototype.expectGreaterThan):
+        (TestHarness.prototype.expectGreaterThanOrEqual):
+        New expectation functions, all of which call _expect under the hood.
+
+        (TestHarness.prototype._expect):
+        Helper method which calls pass or fail. Creates a message when no user
+        message is provided, and logs expected and actual values in the event
+        of a failure.
+
+        (TestHarness.prototype._expectationValueAsString):
+        (TestHarness.prototype._expectationMessageFormat):
+        Get a message format string for the expectation type. Used to create
+        pass/fail message when no user message is provided.
+
+        (TestHarness.prototype._expectedValueFormat):
+        Get a format string for displaying the expected value. Used to create
+        the &quot;Expected: &quot; failure message line.
+
</ins><span class="cx"> 2016-09-20  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Reload unexpectedly switches to Storage Tab
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceTestTestHarnessjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -30,6 +30,8 @@
</span><span class="cx">         super();
</span><span class="cx"> 
</span><span class="cx">         this._logCount = 0;
</span><ins>+        this._failureObjects = new Map;
+        this._failureObjectIdentifier = 1;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     completeTest()
</span><span class="lines">@@ -91,74 +93,72 @@
</span><span class="cx">         this.log(&quot;ASSERT: &quot; + stringifiedMessage);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectThat(condition, message)
</del><ins>+    expectThat(actual, message)
</ins><span class="cx">     {
</span><del>-        if (condition)
-            this.pass(message);
-        else
-            this.fail(message);
</del><ins>+        this._expect(TestHarness.ExpectationType.True, !!actual, message, actual);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectFalse(expression, message)
</del><ins>+    expectFalse(actual, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(!expression, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.False, !actual, message, actual);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectNull(expression, message)
</del><ins>+    expectNull(actual, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression === null, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.Null, actual === null, message, actual, null);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectNotNull(expression, message)
</del><ins>+    expectNotNull(actual, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression !== null, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.NotNull, actual !== null, message, actual);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectEqual(expression1, expression2, message)
</del><ins>+    expectEqual(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression1 === expression2, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.Equal, expected === actual, message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectNotEqual(expression1, expression2, message)
</del><ins>+    expectNotEqual(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression1 !== expression2, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.NotEqual, expected !== actual, message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectShallowEqual(expression1, expression2, message)
</del><ins>+    expectShallowEqual(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(Object.shallowEqual(expression1, expression2), message);
</del><ins>+        this._expect(TestHarness.ExpectationType.ShallowEqual, Object.shallowEqual(actual, expected), message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectNotShallowEqual(expression1, expression2, message)
</del><ins>+    expectNotShallowEqual(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(!Object.shallowEqual(expression1, expression2), message);
</del><ins>+        this._expect(TestHarness.ExpectationType.NotShallowEqual, !Object.shallowEqual(actual, expected), message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectEqualWithAccuracy(expression1, expression2, accuracy, message)
</del><ins>+    expectEqualWithAccuracy(actual, expected, accuracy, message)
</ins><span class="cx">     {
</span><del>-        console.assert(typeof expression1 === &quot;number&quot;);
-        console.assert(typeof expression2 === &quot;number&quot;);
-        this.expectThat(Math.abs(expression1 - expression2) &lt;= accuracy, message);
</del><ins>+        console.assert(typeof expected === &quot;number&quot;);
+        console.assert(typeof actual === &quot;number&quot;);
+
+        this._expect(TestHarness.ExpectationType.EqualWithAccuracy, Math.abs(expected - actual) &lt;= accuracy, message, actual, expected, accuracy);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectLessThan(expression1, expression2, message)
</del><ins>+    expectLessThan(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression1 &lt; expression2, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.LessThan, actual &lt; expected, message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectLessThanOrEqual(expression1, expression2, message)
</del><ins>+    expectLessThanOrEqual(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression1 &lt;= expression2, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.LessThanOrEqual, actual &lt;= expected, message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectGreaterThan(expression1, expression2, message)
</del><ins>+    expectGreaterThan(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression1 &gt; expression2, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.GreaterThan, actual &gt; expected, message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    expectGreaterThanOrEqual(expression1, expression2, message)
</del><ins>+    expectGreaterThanOrEqual(actual, expected, message)
</ins><span class="cx">     {
</span><del>-        this.expectThat(expression1 &gt;= expression2, message);
</del><ins>+        this._expect(TestHarness.ExpectationType.GreaterThanOrEqual, actual &gt;= expected, message, actual, expected);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     pass(message)
</span><span class="lines">@@ -182,4 +182,138 @@
</span><span class="cx"> 
</span><span class="cx">         return (typeof message !== &quot;string&quot;) ? JSON.stringify(message) : message;
</span><span class="cx">     }
</span><ins>+
+    // Private
+
+    _expect(type, condition, message, ...values)
+    {
+        console.assert(values.length &gt; 0, &quot;Should have an 'actual' value.&quot;);
+
+        if (!message || !condition) {
+            values = values.map(this._expectationValueAsString.bind(this));
+            message = message || this._expectationMessageFormat(type).format(...values);
+        }
+
+        if (condition) {
+            this.pass(message);
+            return;
+        }
+
+        message += &quot;\n    Expected: &quot; + this._expectedValueFormat(type).format(...values.slice(1));
+        message += &quot;\n    Actual: &quot; + values[0];
+
+        this.fail(message);
+    }
+
+    _expectationValueAsString(value)
+    {
+        let instanceIdentifier = (object) =&gt; {
+            let id = this._failureObjects.get(object);
+            if (!id) {
+                id = this._failureObjectIdentifier++;
+                this._failureObjects.set(object, id);
+            }
+            return &quot;#&quot; + id;
+        };
+
+        const maximumValueStringLength = 200;
+        const defaultValueString = String(new Object); // [object Object]
+
+        // Special case for numbers, since JSON.stringify converts Infinity and NaN to null.
+        if (typeof value === &quot;number&quot;)
+            return value;
+
+        try {
+            let valueString = JSON.stringify(value);
+            if (valueString.length &lt;= maximumValueStringLength)
+                return valueString;
+        } catch (e) {}
+
+        try {
+            let valueString = String(value);
+            if (valueString === defaultValueString &amp;&amp; value.constructor &amp;&amp; value.constructor.name !== &quot;Object&quot;)
+                return value.constructor.name + &quot; instance &quot; + instanceIdentifier(value);
+            return valueString;
+        } catch (e) {
+            return defaultValueString;
+        }
+    }
+
+    _expectationMessageFormat(type)
+    {
+        switch (type) {
+        case TestHarness.ExpectationType.True:
+            return &quot;expectThat(%s)&quot;;
+        case TestHarness.ExpectationType.False:
+            return &quot;expectFalse(%s)&quot;;
+        case TestHarness.ExpectationType.Null:
+            return &quot;expectNull(%s)&quot;;
+        case TestHarness.ExpectationType.NotNull:
+            return &quot;expectNotNull(%s)&quot;;
+        case TestHarness.ExpectationType.Equal:
+            return &quot;expectEqual(%s, %s)&quot;;
+        case TestHarness.ExpectationType.NotEqual:
+            return &quot;expectNotEqual(%s, %s)&quot;;
+        case TestHarness.ExpectationType.ShallowEqual:
+            return &quot;expectShallowEqual(%s, %s)&quot;;
+        case TestHarness.ExpectationType.NotShallowEqual:
+            return &quot;expectNotShallowEqual(%s, %s)&quot;;
+        case TestHarness.ExpectationType.EqualWithAccuracy:
+            return &quot;expectEqualWithAccuracy(%s, %s, %s)&quot;;
+        case TestHarness.ExpectationType.LessThan:
+            return &quot;expectLessThan(%s, %s)&quot;;
+        case TestHarness.ExpectationType.LessThanOrEqual:
+            return &quot;expectLessThanOrEqual(%s, %s)&quot;;
+        case TestHarness.ExpectationType.GreaterThan:
+            return &quot;expectGreaterThan(%s, %s)&quot;;
+        case TestHarness.ExpectationType.GreaterThanOrEqual:
+            return &quot;expectGreaterThanOrEqual(%s, %s)&quot;;
+        default:
+            console.error(&quot;Unknown TestHarness.ExpectationType type: &quot; + type);
+            return null;
+        }
+    }
+
+    _expectedValueFormat(type)
+    {
+        switch (type) {
+        case TestHarness.ExpectationType.True:
+            return &quot;truthy&quot;;
+        case TestHarness.ExpectationType.False:
+            return &quot;falsey&quot;;
+        case TestHarness.ExpectationType.NotNull:
+            return &quot;not null&quot;;
+        case TestHarness.ExpectationType.NotEqual:
+        case TestHarness.ExpectationType.NotShallowEqual:
+            return &quot;not %s&quot;;
+        case TestHarness.ExpectationType.EqualWithAccuracy:
+            return &quot;%s +/- %s&quot;;
+        case TestHarness.ExpectationType.LessThan:
+            return &quot;less than %s&quot;;
+        case TestHarness.ExpectationType.LessThanOrEqual:
+            return &quot;less than or equal to %s&quot;;
+        case TestHarness.ExpectationType.GreaterThan:
+            return &quot;greater than %s&quot;;
+        case TestHarness.ExpectationType.GreaterThanOrEqual:
+            return &quot;greater than or equal to %s&quot;;
+        default:
+            return &quot;%s&quot;;
+        }
+    }
</ins><span class="cx"> };
</span><ins>+
+TestHarness.ExpectationType = {
+    True: Symbol(&quot;expect-true&quot;),
+    False: Symbol(&quot;expect-false&quot;),
+    Null: Symbol(&quot;expect-null&quot;),
+    NotNull: Symbol(&quot;expect-not-null&quot;),
+    Equal: Symbol(&quot;expect-equal&quot;),
+    NotEqual: Symbol(&quot;expect-not-equal&quot;),
+    ShallowEqual: Symbol(&quot;expect-shallow-equal&quot;),
+    NotShallowEqual: Symbol(&quot;expect-not-shallow-equal&quot;),
+    EqualWithAccuracy: Symbol(&quot;expect-equal-with-accuracy&quot;),
+    LessThan: Symbol(&quot;expect-less-than&quot;),
+    LessThanOrEqual: Symbol(&quot;expect-less-than-or-equal&quot;),
+    GreaterThan: Symbol(&quot;expect-greater-than&quot;),
+    GreaterThanOrEqual: Symbol(&quot;expect-greater-than-or-equal&quot;),
+};
</ins></span></pre>
</div>
</div>

</body>
</html>