| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 debug = function debug(msg) | |
| 6 { | |
| 7 console.log(msg); | |
| 8 }; | |
| 9 | |
| 10 description = function description(msg, quiet) | |
| 11 { | |
| 12 console.log(msg); | |
| 13 }; | |
| 14 | |
| 15 finishJSTest = function finishJSTest() { | |
| 16 console.log("TEST FINISHED"); | |
| 17 }; | |
| 18 | |
| 19 function handleTestFinished() { | |
| 20 if (!window.jsTestIsAsync) | |
| 21 finishJSTest(); | |
| 22 } | |
| 23 | |
| 24 function testFailed(msg) { | |
| 25 debug('FAIL: ' + msg); | |
| 26 } | |
| 27 | |
| 28 function testPassed(msg) | |
| 29 { | |
| 30 debug('PASS: ' + msg); | |
| 31 } | |
| 32 | |
| 33 function isWorker() | |
| 34 { | |
| 35 // It's conceivable that someone would stub out 'document' in a worker so | |
| 36 // also check for childNodes, an arbitrary DOM-related object that is | |
| 37 // meaningless in a WorkerContext. | |
| 38 return (typeof document === 'undefined' || | |
| 39 typeof document.childNodes === 'undefined') && !!self.importScripts; | |
| 40 } | |
| 41 | |
| 42 if (!isWorker()) { | |
| 43 window.addEventListener('DOMContentLoaded', handleTestFinished, false); | |
| 44 } | |
| 45 | |
| 46 | |
| 47 // Functions in common with js-test.js in blink, | |
| 48 // see third_party/WebKit/LayoutTests/resources/js-test.js | |
| 49 | |
| 50 function areArraysEqual(a, b) | |
| 51 { | |
| 52 try { | |
| 53 if (a.length !== b.length) | |
| 54 return false; | |
| 55 for (var i = 0; i < a.length; i++) | |
| 56 if (a[i] !== b[i]) | |
| 57 return false; | |
| 58 } catch (ex) { | |
| 59 return false; | |
| 60 } | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 // Returns a sorted array of property names of object. This function returns | |
| 65 // not only own properties but also properties on prototype chains. | |
| 66 function getAllPropertyNames(object) { | |
| 67 var properties = []; | |
| 68 for (var property in object) { | |
| 69 properties.push(property); | |
| 70 } | |
| 71 return properties.sort(); | |
| 72 } | |
| 73 | |
| 74 function isNewSVGTearOffType(v) | |
| 75 { | |
| 76 return ['[object SVGLength]', '[object SVGLengthList]', | |
| 77 '[object SVGPoint]', '[object SVGPointList]', | |
| 78 '[object SVGNumber]', '[object SVGTransform]', | |
| 79 '[object SVGTransformList]'].indexOf(""+v) != -1; | |
| 80 } | |
| 81 | |
| 82 function stringify(v) | |
| 83 { | |
| 84 if (isNewSVGTearOffType(v)) | |
| 85 return v.valueAsString; | |
| 86 if (v === 0 && 1/v < 0) | |
| 87 return "-0"; | |
| 88 else return "" + v; | |
| 89 } | |
| 90 | |
| 91 function isResultCorrect(actual, expected) | |
| 92 { | |
| 93 if (expected === 0) | |
| 94 return actual === expected && (1/actual) === (1/expected); | |
| 95 if (actual === expected) | |
| 96 return true; | |
| 97 // http://crbug.com/308818 : The new implementation of SVGListProperties | |
| 98 // do not necessary return the same wrapper object, so === operator would | |
| 99 // not work. We compare for their string representation instead. | |
| 100 if (isNewSVGTearOffType(expected) && typeof(expected) == typeof(actual) | |
| 101 && actual.valueAsString == expected.valueAsString) | |
| 102 return true; | |
| 103 if (typeof(expected) == "number" && isNaN(expected)) | |
| 104 return typeof(actual) == "number" && isNaN(actual); | |
| 105 if (expected && (Object.prototype.toString.call(expected) | |
| 106 == Object.prototype.toString.call([]))) | |
| 107 return areArraysEqual(actual, expected); | |
| 108 return false; | |
| 109 } | |
| 110 | |
| 111 function shouldBe(_a, _b, quiet, opt_tolerance) | |
| 112 { | |
| 113 if (typeof _a != "string" || typeof _b != "string") | |
| 114 debug("WARN: shouldBe() expects string arguments"); | |
| 115 var _exception; | |
| 116 var _av; | |
| 117 try { | |
| 118 _av = eval(_a); | |
| 119 } catch (e) { | |
| 120 _exception = e; | |
| 121 } | |
| 122 var _bv = eval(_b); | |
| 123 | |
| 124 if (_exception) | |
| 125 testFailed(_a + " should be " + _bv + ". Threw exception " | |
| 126 + _exception); | |
| 127 else if (isResultCorrect(_av, _bv) | |
| 128 || (typeof opt_tolerance == 'number' && typeof _av == 'number' | |
| 129 && Math.abs(_av - _bv) <= opt_tolerance)) { | |
| 130 if (!quiet) { | |
| 131 testPassed(_a + " is " + _b); | |
| 132 } | |
| 133 } else if (typeof(_av) == typeof(_bv)) { | |
| 134 testFailed(_a + " should be " + _bv + ". Was " + stringify(_av) + "."); | |
| 135 } else { | |
| 136 testFailed(_a + " should be " + _bv + " (of type " + typeof _bv | |
| 137 + "). Was " + _av + " (of type " + typeof _av + ")."); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 function shouldBeEqualToString(a, b) | |
| 142 { | |
| 143 if (typeof a !== "string" || typeof b !== "string") | |
| 144 debug("WARN: shouldBeEqualToString() expects string arguments"); | |
| 145 var unevaledString = JSON.stringify(b); | |
| 146 shouldBe(a, unevaledString); | |
| 147 } | |
| 148 | |
| 149 function shouldBeTrue(a, quiet) { shouldBe(a, "true", quiet); } | |
| 150 function shouldBeFalse(a, quiet) { shouldBe(a, "false", quiet); } | |
| OLD | NEW |