| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 chrome.test = chrome.test || {}; | 8 chrome.test = chrome.test || {}; |
| 9 | 9 |
| 10 chrome.test.tests = chrome.test.tests || []; | 10 chrome.test.tests = chrome.test.tests || []; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // Try to get the script to stop running immediately. | 38 // Try to get the script to stop running immediately. |
| 39 // This isn't an error, just an attempt at saying "done". | 39 // This isn't an error, just an attempt at saying "done". |
| 40 throw "completed"; | 40 throw "completed"; |
| 41 } | 41 } |
| 42 | 42 |
| 43 var pendingCallbacks = 0; | 43 var pendingCallbacks = 0; |
| 44 | 44 |
| 45 chrome.test.callbackAdded = function() { | 45 chrome.test.callbackAdded = function() { |
| 46 pendingCallbacks++; | 46 pendingCallbacks++; |
| 47 | 47 |
| 48 var called = false; |
| 48 return function() { | 49 return function() { |
| 50 chrome.test.assertFalse(called, 'callback has already been run'); |
| 51 called = true; |
| 52 |
| 49 pendingCallbacks--; | 53 pendingCallbacks--; |
| 50 if (pendingCallbacks == 0) { | 54 if (pendingCallbacks == 0) { |
| 51 chrome.test.succeed(); | 55 chrome.test.succeed(); |
| 52 } | 56 } |
| 53 }; | 57 }; |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 chrome.test.runNextTest = function() { | 60 chrome.test.runNextTest = function() { |
| 57 // There may have been callbacks which were interrupted by failure | 61 // There may have been callbacks which were interrupted by failure |
| 58 // exceptions. | 62 // exceptions. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 265 |
| 262 chrome.test.callbackFail = function(expectedError, func) { | 266 chrome.test.callbackFail = function(expectedError, func) { |
| 263 return chrome.test.callback(func, expectedError); | 267 return chrome.test.callback(func, expectedError); |
| 264 }; | 268 }; |
| 265 | 269 |
| 266 chrome.test.runTests = function(tests) { | 270 chrome.test.runTests = function(tests) { |
| 267 chrome.test.tests = tests; | 271 chrome.test.tests = tests; |
| 268 testCount = chrome.test.tests.length; | 272 testCount = chrome.test.tests.length; |
| 269 chrome.test.runNextTest(); | 273 chrome.test.runNextTest(); |
| 270 }; | 274 }; |
| OLD | NEW |