| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // extension_apitest.js | 5 // extension_apitest.js |
| 6 // mini-framework for ExtensionApiTest browser tests | 6 // mini-framework for ExtensionApiTest browser tests |
| 7 | 7 |
| 8 var chrome = chrome || {}; | 8 var chrome = chrome || {}; |
| 9 (function() { | 9 (function() { |
| 10 chrome.test = chrome.test || {}; | 10 chrome.test = chrome.test || {}; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (message) { | 115 if (message) { |
| 116 message = test + "\n" + message; | 116 message = test + "\n" + message; |
| 117 } else { | 117 } else { |
| 118 message = test; | 118 message = test; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 chrome.test.fail(message); | 121 chrome.test.fail(message); |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 function checkDeepEq(expected, actual) { |
| 126 for (var p in expected) { |
| 127 var eq = true; |
| 128 switch (typeof(expected[p])) { |
| 129 case 'object': |
| 130 eq = checkDeepEq(expected[p], actual[p]); |
| 131 break; |
| 132 case 'function': |
| 133 eq = (typeof(actual[p]) != 'undefined' && |
| 134 expected[p].toString() == actual[p].toString()); |
| 135 break; |
| 136 default: |
| 137 eq = (expected[p] == actual[p] && |
| 138 typeof(expected[p]) == typeof(actual[p])); |
| 139 break; |
| 140 } |
| 141 if (!eq) |
| 142 return false; |
| 143 } |
| 144 for (var p in actual) { |
| 145 if (typeof(expected[p]) == 'undefined') |
| 146 return false; |
| 147 } |
| 148 return true; |
| 149 } |
| 150 |
| 125 chrome.test.assertEq = function(expected, actual) { | 151 chrome.test.assertEq = function(expected, actual) { |
| 152 if (typeof(expected) == 'object') { |
| 153 if (!checkDeepEq(expected, actual)) { |
| 154 chrome.test.fail("API Test Error in " + testName(currentTest) + |
| 155 "\nActual: " + JSON.stringify(actual) + |
| 156 "\nExpected: " + JSON.stringify(expected)); |
| 157 } |
| 158 return; |
| 159 } |
| 126 if (expected != actual) { | 160 if (expected != actual) { |
| 127 chrome.test.fail("API Test Error in " + testName(currentTest) + | 161 chrome.test.fail("API Test Error in " + testName(currentTest) + |
| 128 "\nActual: " + actual + "\nExpected: " + expected); | 162 "\nActual: " + actual + "\nExpected: " + expected); |
| 129 } | 163 } |
| 130 if (typeof(expected) != typeof(actual)) { | 164 if (typeof(expected) != typeof(actual)) { |
| 131 chrome.test.fail("API Test Error in " + testName(currentTest) + | 165 chrome.test.fail("API Test Error in " + testName(currentTest) + |
| 132 " (type mismatch)\nActual Type: " + typeof(actual) + | 166 " (type mismatch)\nActual Type: " + typeof(actual) + |
| 133 "\nExpected Type:" + typeof(expected)); | 167 "\nExpected Type:" + typeof(expected)); |
| 134 } | 168 } |
| 135 }; | 169 }; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 252 |
| 219 chrome.test.callbackFail = function(expectedError, func) { | 253 chrome.test.callbackFail = function(expectedError, func) { |
| 220 return chrome.test.callback(func, expectedError); | 254 return chrome.test.callback(func, expectedError); |
| 221 }; | 255 }; |
| 222 | 256 |
| 223 chrome.test.runTests = function(tests) { | 257 chrome.test.runTests = function(tests) { |
| 224 chrome.test.tests = tests; | 258 chrome.test.tests = tests; |
| 225 chrome.test.runNextTest(); | 259 chrome.test.runNextTest(); |
| 226 }; | 260 }; |
| 227 })(); | 261 })(); |
| OLD | NEW |