Added: trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt (0 => 205834)
--- trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt 2016-09-12 22:36:57 UTC (rev 205834)
@@ -0,0 +1,162 @@
+Testing TestHarness.expect* family of functions.
+
+
+== Running test suite: InspectorTestExpectFunctions
+-- Running test case: InspectorTest.expectThat
+Expected to PASS
+PASS: expectThat(true)
+PASS: expectThat(1)
+PASS: expectThat("abc")
+PASS: expectThat({})
+PASS: expectThat([])
+Expected to FAIL
+FAIL: expectThat(false)
+FAIL: expectThat(0)
+FAIL: expectThat("")
+FAIL: expectThat(null)
+FAIL: expectThat(undefined)
+FAIL: expectThat(NaN)
+
+-- Running test case: InspectorTest.expectFalse
+Expected to PASS
+PASS: expectFalse(false)
+PASS: expectFalse(0)
+PASS: expectFalse("")
+PASS: expectFalse(null)
+PASS: expectFalse(undefined)
+PASS: expectFalse(NaN)
+Expected to FAIL
+FAIL: expectFalse(true)
+FAIL: expectFalse(1)
+FAIL: expectFalse("abc")
+FAIL: expectFalse({})
+FAIL: expectFalse([])
+
+-- Running test case: InspectorTest.expectNull
+Expected to PASS
+PASS: expectNull(null)
+Expected to FAIL
+FAIL: expectNull(true)
+FAIL: expectNull(false)
+FAIL: expectNull(1)
+FAIL: expectNull("")
+FAIL: expectNull(undefined)
+FAIL: expectNull({})
+FAIL: expectNull([])
+
+-- Running test case: InspectorTest.expectNotNull
+Expected to PASS
+PASS: expectNotNull(true)
+PASS: expectNotNull(false)
+PASS: expectNotNull(1)
+PASS: expectNotNull("")
+PASS: expectNotNull(undefined)
+PASS: expectNotNull({})
+PASS: expectNotNull([])
+Expected to FAIL
+FAIL: expectNotNull(null)
+
+-- Running test case: InspectorTest.expectEqual
+Expected to PASS
+PASS: expectEqual(true, true)
+PASS: expectEqual({"a":1,"b":2}, {"a":1,"b":2})
+PASS: expectEqual(1.23, 1.23)
+PASS: expectEqual("abc", "abc")
+PASS: expectEqual(null, null)
+PASS: expectEqual(undefined, undefined)
+Expected to FAIL
+FAIL: expectEqual(true, false)
+FAIL: expectEqual({"a":1,"b":2}, {"c":3,"d":4})
+FAIL: expectEqual(1.23, 4.56)
+FAIL: expectEqual("abc", "def")
+FAIL: expectEqual(null, undefined)
+FAIL: expectEqual(NaN, NaN)
+FAIL: expectEqual({}, {})
+FAIL: expectEqual([], [])
+
+-- Running test case: InspectorTest.expectNotEqual
+Expected to PASS
+PASS: expectNotEqual(true, false)
+PASS: expectNotEqual({"a":1,"b":2}, {"c":3,"d":4})
+PASS: expectNotEqual(1.23, 4.56)
+PASS: expectNotEqual("abc", "def")
+PASS: expectNotEqual(null, undefined)
+PASS: expectNotEqual(NaN, NaN)
+PASS: expectNotEqual({}, {})
+PASS: expectNotEqual([], [])
+Expected to FAIL
+FAIL: expectNotEqual(true, true)
+FAIL: expectNotEqual({"a":1,"b":2}, {"a":1,"b":2})
+FAIL: expectNotEqual(1.23, 1.23)
+FAIL: expectNotEqual("abc", "abc")
+FAIL: expectNotEqual(null, null)
+FAIL: expectNotEqual(undefined, undefined)
+
+-- Running test case: InspectorTest.expectShallowEqual
+Expected to PASS
+PASS: expectShallowEqual({"a":1,"b":2}, {"a":1,"b":2})
+PASS: expectShallowEqual({}, {})
+PASS: expectShallowEqual([], [])
+Expected to FAIL
+FAIL: expectShallowEqual({"a":1,"b":2}, {"a":3,"b":4})
+FAIL: expectShallowEqual({}, [])
+
+-- Running test case: InspectorTest.expectNotShallowEqual
+Expected to PASS
+PASS: expectNotShallowEqual({"a":1,"b":2}, {"a":3,"b":4})
+PASS: expectNotShallowEqual({}, [])
+Expected to FAIL
+FAIL: expectNotShallowEqual({"a":1,"b":2}, {"a":1,"b":2})
+FAIL: expectNotShallowEqual({}, {})
+FAIL: expectNotShallowEqual([], [])
+
+-- Running test case: InspectorTest.expectEqualWithAccuracy
+Expected to PASS
+PASS: expectEqualWithAccuracy(0, 0, 0)
+PASS: expectEqualWithAccuracy(0, 0, 1)
+PASS: expectEqualWithAccuracy(0, 1, 1)
+PASS: expectEqualWithAccuracy(1, 0, 1)
+Expected to FAIL
+FAIL: expectEqualWithAccuracy(0, 2, 1)
+FAIL: expectEqualWithAccuracy(2, 0, 1)
+
+-- Running test case: InspectorTest.expectLessThan
+Expected to PASS
+PASS: expectLessThan(0, 1)
+PASS: expectLessThan("abc", "def")
+Expected to FAIL
+FAIL: expectLessThan(0, 0)
+FAIL: expectLessThan(1, 0)
+FAIL: expectLessThan("abc", "abc")
+FAIL: expectLessThan("def", "abc")
+
+-- Running test case: InspectorTest.expectLessThanOrEqual
+Expected to PASS
+PASS: expectLessThanOrEqual(0, 1)
+PASS: expectLessThanOrEqual(0, 0)
+PASS: expectLessThanOrEqual("abc", "def")
+PASS: expectLessThanOrEqual("abc", "abc")
+Expected to FAIL
+FAIL: expectLessThanOrEqual(1, 0)
+FAIL: expectLessThanOrEqual("def", "abc")
+
+-- Running test case: InspectorTest.expectGreaterThan
+Expected to PASS
+PASS: expectGreaterThan(1, 0)
+PASS: expectGreaterThan("def", "abc")
+Expected to FAIL
+FAIL: expectGreaterThan(0, 0)
+FAIL: expectGreaterThan(0, 1)
+FAIL: expectGreaterThan("abc", "abc")
+FAIL: expectGreaterThan("abc", "def")
+
+-- Running test case: InspectorTest.expectGreaterThanOrEqual
+Expected to PASS
+PASS: expectGreaterThanOrEqual(1, 0)
+PASS: expectGreaterThanOrEqual(0, 0)
+PASS: expectGreaterThanOrEqual("def", "abc")
+PASS: expectGreaterThanOrEqual("abc", "abc")
+Expected to FAIL
+FAIL: expectGreaterThanOrEqual(0, 1)
+FAIL: expectGreaterThanOrEqual("abc", "def")
+
Added: trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html (0 => 205834)
--- trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html (rev 0)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html 2016-09-12 22:36:57 UTC (rev 205834)
@@ -0,0 +1,190 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+<script>
+function test()
+{
+ console.assert(false, "FAIL ASSERTION!!!!!!!");
+
+ let suite = InspectorTest.createSyncSuite("InspectorTestExpectFunctions");
+
+ function toArray(a) {
+ return a instanceof Array && a.length ? a : [a];
+ }
+
+ function stringifyArguments(args) {
+ return args.map((a) => {
+ if (typeof a === "number")
+ return a;
+ // Append empty string so `undefined` is displayed correctly.
+ return JSON.stringify(a) + "";
+ }).join(", ");
+ }
+
+ function addTestCase({functionName, passingInputs, failingInputs}) {
+ let functionUnderTest = InspectorTest[functionName];
+ InspectorTest.assert(typeof functionUnderTest === "function", "Unknown InspectorTest function: " + functionName);
+
+ suite.addTestCase({
+ name: `InspectorTest.${functionName}`,
+ test() {
+ function exerciseFunction(inputs, shouldPass) {
+ if (!inputs || !inputs.length) {
+ InspectorTest.fail("exerciseFunction called with no inputs.");
+ return;
+ }
+
+ InspectorTest.log("Expected to " + (shouldPass ? "PASS" : "FAIL"));
+ for (let input of inputs.map(toArray)) {
+ let argumentsString = stringifyArguments(input);
+ functionUnderTest.call(InspectorTest, ...input, `${functionName}(${argumentsString})`);
+ }
+ }
+
+ exerciseFunction(passingInputs, true);
+ exerciseFunction(failingInputs, false);
+ return true;
+ }
+ });
+ }
+
+ function addInverseTestCase(functionName, testCase) {
+ addTestCase({functionName, passingInputs: testCase.failingInputs, failingInputs: testCase.passingInputs})
+ }
+
+ let expectThatTestCase = {
+ functionName: "expectThat",
+ passingInputs: [true, 1, "abc", {}, []],
+ failingInputs: [false, 0, "", null, undefined, NaN],
+ };
+ addTestCase(expectThatTestCase);
+ addInverseTestCase("expectFalse", expectThatTestCase);
+
+ let expectNullTestCase = {
+ functionName: "expectNull",
+ passingInputs: [null],
+ failingInputs: [true, false, 1, "", undefined, {}, []]
+ };
+ addTestCase(expectNullTestCase);
+ addInverseTestCase("expectNotNull", expectNullTestCase);
+
+ let object1 = {a: 1, b: 2};
+ let object2 = {c: 3, d: 4};
+ let expectEqualTestCase = {
+ functionName: "expectEqual",
+ passingInputs: [
+ [true, true],
+ [object1, object1],
+ [1.23, 1.23],
+ ["abc", "abc"],
+ [null, null],
+ [undefined, undefined],
+ ],
+ failingInputs: [
+ [true, false],
+ [object1, object2],
+ [1.23, 4.56],
+ ["abc", "def"],
+ [null, undefined],
+ [NaN, NaN],
+ [{}, {}],
+ [[], []],
+ ]
+ };
+ addTestCase(expectEqualTestCase);
+ addInverseTestCase("expectNotEqual", expectEqualTestCase);
+
+ let expectShallowEqualTestCase = {
+ functionName: "expectShallowEqual",
+ passingInputs: [
+ [{a: 1, b: 2}, {a: 1, b: 2}],
+ [{}, {}],
+ [[], []],
+ ],
+ failingInputs: [
+ [{a: 1, b: 2}, {a: 3, b: 4}],
+ [{}, []],
+ ]
+ };
+ addTestCase(expectShallowEqualTestCase);
+ addInverseTestCase("expectNotShallowEqual", expectShallowEqualTestCase);
+
+ addTestCase({
+ functionName: "expectEqualWithAccuracy",
+ passingInputs: [
+ [0, 0, 0],
+ [0, 0, 1],
+ [0, 1, 1],
+ [1, 0, 1],
+ ],
+ failingInputs: [
+ [0, 2, 1],
+ [2, 0, 1],
+ ]
+ });
+
+ addTestCase({
+ functionName: "expectLessThan",
+ passingInputs: [
+ [0, 1],
+ ["abc", "def"],
+ ],
+ failingInputs: [
+ [0, 0],
+ [1, 0],
+ ["abc", "abc"],
+ ["def", "abc"],
+ ]
+ });
+
+ addTestCase({
+ functionName: "expectLessThanOrEqual",
+ passingInputs: [
+ [0, 1],
+ [0, 0],
+ ["abc", "def"],
+ ["abc", "abc"],
+ ],
+ failingInputs: [
+ [1, 0],
+ ["def", "abc"],
+ ]
+ });
+
+ addTestCase({
+ functionName: "expectGreaterThan",
+ passingInputs: [
+ [1, 0],
+ ["def", "abc"],
+ ],
+ failingInputs: [
+ [0, 0],
+ [0, 1],
+ ["abc", "abc"],
+ ["abc", "def"],
+ ]
+ });
+
+ addTestCase({
+ functionName: "expectGreaterThanOrEqual",
+ passingInputs: [
+ [1, 0],
+ [0, 0],
+ ["def", "abc"],
+ ["abc", "abc"],
+ ],
+ failingInputs: [
+ [0, 1],
+ ["abc", "def"],
+ ]
+ });
+
+ suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+ <p>Testing TestHarness.expect* family of functions.</p>
+</body>
+</html>
Modified: trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js (205833 => 205834)
--- trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js 2016-09-12 22:36:14 UTC (rev 205833)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js 2016-09-12 22:36:57 UTC (rev 205834)
@@ -99,6 +99,68 @@
this.fail(message);
}
+ expectFalse(_expression_, message)
+ {
+ this.expectThat(!_expression_, message);
+ }
+
+ expectNull(_expression_, message)
+ {
+ this.expectThat(_expression_ === null, message);
+ }
+
+ expectNotNull(_expression_, message)
+ {
+ this.expectThat(_expression_ !== null, message);
+ }
+
+ expectEqual(expression1, expression2, message)
+ {
+ this.expectThat(expression1 === expression2, message);
+ }
+
+ expectNotEqual(expression1, expression2, message)
+ {
+ this.expectThat(expression1 !== expression2, message);
+ }
+
+ expectShallowEqual(expression1, expression2, message)
+ {
+ this.expectThat(Object.shallowEqual(expression1, expression2), message);
+ }
+
+ expectNotShallowEqual(expression1, expression2, message)
+ {
+ this.expectThat(!Object.shallowEqual(expression1, expression2), message);
+ }
+
+ expectEqualWithAccuracy(expression1, expression2, accuracy, message)
+ {
+ console.assert(typeof expression1 === "number");
+ console.assert(typeof expression2 === "number");
+ this.expectThat(Math.abs(expression1 - expression2) <= accuracy, message);
+ }
+
+ expectLessThan(expression1, expression2, message)
+ {
+ this.expectThat(expression1 < expression2, message);
+ }
+
+ expectLessThanOrEqual(expression1, expression2, message)
+ {
+ this.expectThat(expression1 <= expression2, message);
+ }
+
+ expectGreaterThan(expression1, expression2, message)
+ {
+ this.expectThat(expression1 > expression2, message);
+ }
+
+ expectGreaterThanOrEqual(expression1, expression2, message)
+ {
+ this.expectThat(expression1 >= expression2, message);
+ }
+
pass(message)
{
let stringifiedMessage = TestHarness.messageAsString(message);