diff options
author | Keegan McAllister <kmcallister@mozilla.com> | 2013-10-14 16:38:42 -0700 |
---|---|---|
committer | Keegan McAllister <kmcallister@mozilla.com> | 2013-10-15 13:30:01 -0700 |
commit | 4bb2a70e08143bf9047a8c4bb4e3cc918e541be9 (patch) | |
tree | 76145010a815e872dc08edcfd4d5217a632d6ebe | |
parent | e701ba4d43f976272c98c06704515b162558651c (diff) | |
download | servo-4bb2a70e08143bf9047a8c4bb4e3cc918e541be9.tar.gz servo-4bb2a70e08143bf9047a8c4bb4e3cc918e541be9.zip |
harness: Support more assertion types
-rw-r--r-- | src/test/html/content/harness.js | 28 | ||||
-rw-r--r-- | src/test/html/content/test_childnodes.html | 4 | ||||
-rw-r--r-- | src/test/html/content/test_create_element.html | 6 | ||||
-rw-r--r-- | src/test/html/content/test_document_getElementById.html | 6 | ||||
-rw-r--r-- | src/test/html/content/test_empty_clientrect.html | 4 | ||||
-rw-r--r-- | src/test/html/content/test_navigator.html | 2 | ||||
-rw-r--r-- | src/test/html/content/test_prototypes.html | 14 |
7 files changed, 38 insertions, 26 deletions
diff --git a/src/test/html/content/harness.js b/src/test/html/content/harness.js index 725380838c2..0697376df4f 100644 --- a/src/test/html/content/harness.js +++ b/src/test/html/content/harness.js @@ -12,16 +12,28 @@ function _pass(s, m) { window.alert(_oneline("TEST-PASS | " + s + ": " + m)); } -function is(a, b, c) { - let f = a != b ? _fail : _pass; - let m = !c ? "" : c; - f(a + " == " + b, m); +function _printer(opstr, op) { + return function (a, b, msg) { + let f = op(a,b) ? _pass : _fail; + if (!msg) msg = ""; + f(a + " " + opstr + " " + b, msg); + }; } -function isnot(a, b, c) { - let f = (a != b) ? _pass : _fail; - let m = !c ? "" : c; - f(a + " != " + b, m); +var is = _printer("==", function (a,b) { return a == b; }); +var is_a = _printer("is a", function (a,b) { return a instanceof b; }); +var is_in = _printer("is in", function (a,b) { return a in b; }); +var is_not_in = _printer("is not in", function (a,b) { return !(a in b); }); +var as_str_is = _printer("as string is", function (a,b) { return String(a) == b; }); +var isnot = _printer("!=", function (a,b) { return a != b; }); +var lt = _printer("<", function (a,b) { return a < b; }); +var gt = _printer(">", function (a,b) { return a > b; }); +var leq = _printer("<=", function (a,b) { return a <= b; }); +var geq = _printer(">=", function (a,b) { return a >= b; }); +var starts_with = _printer("starts with", function (a,b) { return a.indexOf(b) == 0; }); + +function is_function(val, name) { + starts_with(String(val), "function " + name + "("); } var _test_complete = false; diff --git a/src/test/html/content/test_childnodes.html b/src/test/html/content/test_childnodes.html index f8a4d9797c6..205a6124959 100644 --- a/src/test/html/content/test_childnodes.html +++ b/src/test/html/content/test_childnodes.html @@ -18,11 +18,11 @@ var child2 = document.createElement("p"); elem.appendChild(child2); - is(1 in children, true); + is_in(1, children); is(children.length, 2); is(children.item(1), child2); - is(!(2 in children), true); + is_not_in(2, children); is(children.item(2), null); finish(); diff --git a/src/test/html/content/test_create_element.html b/src/test/html/content/test_create_element.html index eaa3e11377a..f62c599504d 100644 --- a/src/test/html/content/test_create_element.html +++ b/src/test/html/content/test_create_element.html @@ -8,11 +8,11 @@ var elem = document.createElement("foo"); is(elem.tagName, "FOO"); var elem = document.createElement("p"); - is(elem instanceof HTMLParagraphElement, true); + is_a(elem, HTMLParagraphElement); var elem = document.createElement("sPAn"); - is(elem instanceof HTMLSpanElement, true); + is_a(elem, HTMLSpanElement); var text = document.createTextNode("hello"); - is(text instanceof Text, true); + is_a(text, Text); finish(); </script> </body> diff --git a/src/test/html/content/test_document_getElementById.html b/src/test/html/content/test_document_getElementById.html index 20140274477..370ec77fde0 100644 --- a/src/test/html/content/test_document_getElementById.html +++ b/src/test/html/content/test_document_getElementById.html @@ -13,12 +13,12 @@ let foo = document.getElementById("foo"); isnot(foo, null, "test-1-0, on static page"); is(foo && foo.tagName, "HEAD", "test1-1, on static page"); - is(foo instanceof HTMLHeadElement, true, "test1-2, on static page"); + is_a(foo, HTMLHeadElement, "test1-2, on static page"); let bar = document.getElementById("bar"); isnot(bar, null, "test1-3, on static page"); is(bar && bar.tagName, "DIV", "test1-4, on static page"); - is(bar instanceof HTMLDivElement, true, "test1-5, on static page"); + is_a(bar, HTMLDivElement, "test1-5, on static page"); } // test2: scripted element @@ -32,7 +32,7 @@ let appended = document.getElementById(TEST_ID); isnot(appended, null, "test2-0, appended element"); is(appended && appended.tagName, "DIV", "test2-1, appended element"); - is(appended instanceof HTMLDivElement, true, "test2-2, appended element"); + is_a(appended, HTMLDivElement, "test2-2, appended element"); // test: removed element gBody.removeChild(test); diff --git a/src/test/html/content/test_empty_clientrect.html b/src/test/html/content/test_empty_clientrect.html index 3902886ee99..3671ca5bcc4 100644 --- a/src/test/html/content/test_empty_clientrect.html +++ b/src/test/html/content/test_empty_clientrect.html @@ -4,14 +4,14 @@ <script> var rect = window.document.head.getBoundingClientRect(); var rects = window.document.head.getClientRects(); -is(rect instanceof ClientRect, true); +is_a(rect, ClientRect); is(rect.top, 0); is(rect.bottom, 0); is(rect.left, 0); is(rect.right, 0); is(rect.width, 0); is(rect.height, 0); -is(rects instanceof ClientRectList, true); +is_a(rects, ClientRectList); is(rects.length, 0); finish(); </script> diff --git a/src/test/html/content/test_navigator.html b/src/test/html/content/test_navigator.html index 7d786ea8ec6..c7809f36895 100644 --- a/src/test/html/content/test_navigator.html +++ b/src/test/html/content/test_navigator.html @@ -6,7 +6,7 @@ <body> <script> is(window.navigator, window.navigator); -is(String(window.navigator), '[object Navigator]'); +is_a(window.navigator, Navigator); var nav = window.navigator; is(nav.doNotTrack, "unspecified"); diff --git a/src/test/html/content/test_prototypes.html b/src/test/html/content/test_prototypes.html index 9eb3e878e31..61835bd750e 100644 --- a/src/test/html/content/test_prototypes.html +++ b/src/test/html/content/test_prototypes.html @@ -5,14 +5,14 @@ <body> <foo-á>foo</foo-á> <script> -is(window.document.documentElement instanceof Node, true); -is(window.document.documentElement instanceof Element, true); -is(window.document.documentElement instanceof HTMLElement, true); -is(window.document.documentElement instanceof HTMLHtmlElement, true); -is(window.document instanceof Document, true); -is(window.document instanceof HTMLDocument, true); +is_a(window.document.documentElement, Node); +is_a(window.document.documentElement, Element); +is_a(window.document.documentElement, HTMLElement); +is_a(window.document.documentElement, HTMLHtmlElement); +is_a(window.document, Document); +is_a(window.document, HTMLDocument); is(window.document.documentElement.tagName, "HTML"); -is(window.document.getElementsByTagName('foo-á')[0] instanceof HTMLUnknownElement, true); +is_a(window.document.getElementsByTagName('foo-á')[0], HTMLUnknownElement); is(window.document.getElementsByTagName('foo-á')[0].tagName, "FOO-á"); finish(); </script> |