Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function debug(message) | 5 function debug(message) { |
| 6 { | |
| 7 var span = document.createElement("span"); | 6 var span = document.createElement("span"); |
| 8 span.appendChild(document.createTextNode(message)); | 7 span.appendChild(document.createTextNode(message)); |
| 9 span.appendChild(document.createElement("br")); | 8 span.appendChild(document.createElement("br")); |
| 10 document.getElementById('status').appendChild(span); | 9 document.getElementById('status').appendChild(span); |
| 11 } | 10 } |
| 12 | 11 |
| 13 function done(message) | 12 function done(message) { |
| 14 { | |
| 15 if (document.location.hash == '#fail') | 13 if (document.location.hash == '#fail') |
| 16 return; | 14 return; |
| 17 if (message) | 15 if (message) |
| 18 debug('PASS: ' + message); | 16 debug('PASS: ' + message); |
| 19 else | 17 else |
| 20 debug('PASS'); | 18 debug('PASS'); |
| 21 document.location.hash = '#pass'; | 19 document.location.hash = '#pass'; |
| 22 } | 20 } |
| 23 | 21 |
| 24 function fail(message) | 22 function fail(message) { |
| 25 { | |
| 26 debug('FAILED: ' + message); | 23 debug('FAILED: ' + message); |
| 27 document.location.hash = '#fail'; | 24 document.location.hash = '#fail'; |
| 28 } | 25 } |
| 29 | 26 |
| 30 function getLog() | 27 function getLog() { |
| 31 { | |
| 32 return "" + document.getElementById('status').innerHTML; | 28 return "" + document.getElementById('status').innerHTML; |
| 33 } | 29 } |
| 34 | 30 |
| 35 function unexpectedUpgradeNeededCallback(e) | |
| 36 { | |
| 37 fail('unexpectedUpgradeNeededCallback' + | |
| 38 ' (oldVersion: ' + e.oldVersion + ' newVersion: ' + e.newVersion + ')'); | |
| 39 } | |
| 40 | |
| 41 function unexpectedAbortCallback(e) | |
| 42 { | |
| 43 fail('unexpectedAbortCallback' + | |
| 44 ' (' + e.target.error.name + ': ' + e.target.error.message + ')'); | |
| 45 } | |
| 46 | |
| 47 function unexpectedSuccessCallback() | |
| 48 { | |
| 49 fail('unexpectedSuccessCallback'); | |
| 50 } | |
| 51 | |
| 52 function unexpectedCompleteCallback() | |
| 53 { | |
| 54 fail('unexpectedCompleteCallback'); | |
| 55 } | |
| 56 | |
| 57 function unexpectedErrorCallback(e) | |
| 58 { | |
| 59 fail('unexpectedErrorCallback' + | |
| 60 ' (' + e.target.error.name + ': ' + e.target.error.message + ')'); | |
| 61 } | |
| 62 | |
| 63 function unexpectedBlockedCallback(e) | |
| 64 { | |
| 65 fail('unexpectedBlockedCallback' + | |
| 66 ' (oldVersion: ' + e.oldVersion + ' newVersion: ' + e.newVersion + ')'); | |
| 67 } | |
| 68 | |
| 69 function deleteAllObjectStores(db) | |
| 70 { | |
| 71 objectStoreNames = db.objectStoreNames; | |
| 72 for (var i = 0; i < objectStoreNames.length; ++i) | |
| 73 db.deleteObjectStore(objectStoreNames[i]); | |
| 74 } | |
| 75 | |
| 76 // The following functions are based on | 31 // The following functions are based on |
| 77 // WebKit/LayoutTests/fast/js/resources/js-test-pre.js | 32 // WebKit/LayoutTests/fast/js/resources/js-test-pre.js |
| 78 // so that the tests will look similar to the existing layout tests. | 33 // so that the tests will look similar to the existing layout tests. |
| 79 function stringify(v) | 34 function stringify(v) { |
| 80 { | |
| 81 if (v === 0 && 1/v < 0) | 35 if (v === 0 && 1/v < 0) |
| 82 return "-0"; | 36 return "-0"; |
| 83 else return "" + v; | 37 else return "" + v; |
| 84 } | 38 } |
| 85 | 39 |
| 40 function areArraysEqual(a, b) { | |
| 41 try { | |
| 42 if (a.length !== b.length) | |
| 43 return false; | |
| 44 for (var i = 0; i < a.length; i++) | |
|
pwnall
2016/12/01 01:12:13
I may not remember this correctly, but I think tha
dmurph
2016/12/01 20:40:59
Done.
| |
| 45 if (a[i] !== b[i]) | |
| 46 return false; | |
| 47 } catch (ex) { | |
| 48 return false; | |
| 49 } | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 86 function isResultCorrect(_actual, _expected) | 53 function isResultCorrect(_actual, _expected) |
| 87 { | 54 { |
| 88 if (_expected === 0) | 55 if (_expected === 0) |
| 89 return _actual === _expected && (1/_actual) === (1/_expected); | 56 return _actual === _expected && (1/_actual) === (1/_expected); |
| 90 if (_actual === _expected) | 57 if (_actual === _expected) |
| 91 return true; | 58 return true; |
| 92 if (typeof(_expected) == "number" && isNaN(_expected)) | 59 if (typeof(_expected) == "number" && isNaN(_expected)) |
| 93 return typeof(_actual) == "number" && isNaN(_actual); | 60 return typeof(_actual) == "number" && isNaN(_actual); |
| 94 if (Object.prototype.toString.call(_expected) == | 61 if (Object.prototype.toString.call(_expected) == |
| 95 Object.prototype.toString.call([])) | 62 Object.prototype.toString.call([])) |
| 96 return areArraysEqual(_actual, _expected); | 63 return areArraysEqual(_actual, _expected); |
| 64 | |
| 97 return false; | 65 return false; |
| 98 } | 66 } |
| 99 | 67 |
| 68 function ab2str(buf) { | |
|
pwnall
2016/12/01 01:12:13
arrayBufferToString?
dmurph
2016/12/01 20:40:59
Removed.
| |
| 69 return String.fromCharCode.apply(null, new Uint8Array(buf)); | |
|
pwnall
2016/12/01 01:12:13
ArrayBuffer instances tend to contain binary data,
dmurph
2016/12/01 20:40:59
Done.
| |
| 70 } | |
| 71 | |
| 100 function shouldBe(_a, _b) | 72 function shouldBe(_a, _b) |
| 101 { | 73 { |
| 102 if (typeof _a != "string" || typeof _b != "string") | 74 if (typeof _a != "string" || typeof _b != "string") |
| 103 debug("WARN: shouldBe() expects string arguments"); | 75 debug("WARN: shouldBe() expects string arguments"); |
| 104 var exception; | 76 var exception; |
| 105 var _av; | 77 var _av; |
| 106 try { | 78 try { |
| 107 _av = eval(_a); | 79 _av = eval(_a); |
| 108 } catch (e) { | 80 } catch (e) { |
| 109 exception = e; | 81 exception = e; |
| 110 } | 82 } |
| 111 var _bv = eval(_b); | 83 var _bv = eval(_b); |
| 112 | 84 |
| 113 if (exception) | 85 if (exception) |
| 114 fail(_a + " should be " + _bv + ". Threw exception " + exception); | 86 fail(_a + " should be " + _bv + ". Threw exception " + exception); |
| 115 else if (isResultCorrect(_av, _bv)) | 87 else if (isResultCorrect(_av, _bv)) |
| 116 debug(_a + " is " + _b); | 88 debug(_a + " is " + _b); |
| 117 else if (typeof(_av) == typeof(_bv)) | 89 else if (typeof(_av) == typeof(_bv)) |
| 118 fail(_a + " should be " + _bv + ". Was " + stringify(_av) + "."); | 90 fail(_a + " should be " + _bv + ". Was " + stringify(_av) + "."); |
| 119 else | 91 else |
| 120 fail(_a + " should be " + _bv + " (of type " + typeof _bv + "). " + | 92 fail(_a + " should be " + _bv + " (of type " + typeof _bv + "). " + |
| 121 "Was " + _av + " (of type " + typeof _av + ")."); | 93 "Was " + _av + " (of type " + typeof _av + ")."); |
| 122 } | 94 } |
| 123 | 95 |
| 124 function shouldBeTrue(_a) { shouldBe(_a, "true"); } | 96 function shouldBeTrue(_a) { shouldBe(_a, "true"); } |
| 125 function shouldBeFalse(_a) { shouldBe(_a, "false"); } | 97 function shouldBeFalse(_a) { shouldBe(_a, "false"); } |
| 126 function shouldBeNaN(_a) { shouldBe(_a, "NaN"); } | 98 function shouldBeNaN(_a) { shouldBe(_a, "NaN"); } |
| 127 function shouldBeNull(_a) { shouldBe(_a, "null"); } | 99 function shouldBeNull(_a) { shouldBe(_a, "null"); } |
| 128 function shouldBeEqualToString(a, b) | 100 function shouldBeEqualToString(a, b) { |
| 129 { | |
| 130 var unevaledString = '"' + b.replace(/\\/g, "\\\\").replace(/"/g, "\"") + '"'; | 101 var unevaledString = '"' + b.replace(/\\/g, "\\\\").replace(/"/g, "\"") + '"'; |
| 131 shouldBe(a, unevaledString); | 102 shouldBe(a, unevaledString); |
| 132 } | 103 } |
| 133 | 104 |
| 134 function indexedDBTest(upgradeCallback, optionalOpenCallback) { | |
| 135 dbname = self.location.pathname.substring( | |
| 136 1 + self.location.pathname.lastIndexOf("/")); | |
| 137 var deleteRequest = indexedDB.deleteDatabase(dbname); | |
| 138 deleteRequest.onerror = unexpectedErrorCallback; | |
| 139 deleteRequest.onblocked = unexpectedBlockedCallback; | |
| 140 deleteRequest.onsuccess = function() { | |
| 141 var openRequest = indexedDB.open(dbname); | |
| 142 openRequest.onerror = unexpectedErrorCallback; | |
| 143 openRequest.onupgradeneeded = upgradeCallback; | |
| 144 openRequest.onblocked = unexpectedBlockedCallback; | |
| 145 if (optionalOpenCallback) | |
| 146 openRequest.onsuccess = optionalOpenCallback; | |
| 147 }; | |
| 148 } | |
| 149 | |
| 150 if (typeof String.prototype.startsWith !== 'function') { | 105 if (typeof String.prototype.startsWith !== 'function') { |
| 151 String.prototype.startsWith = function (str) { | 106 String.prototype.startsWith = function (str) { |
| 152 return this.indexOf(str) === 0; | 107 return this.indexOf(str) === 0; |
| 153 }; | 108 }; |
| 154 } | 109 } |
| OLD | NEW |