OLD | NEW |
1 // extension_apitest.js | 1 // extension_apitest.js |
2 // mini-framework for ExtensionApiTest browser tests | 2 // mini-framework for ExtensionApiTest browser tests |
3 | 3 |
4 var chrome = chrome || {}; | 4 var chrome = chrome || {}; |
5 (function() { | 5 (function() { |
6 chrome.test = chrome.test || {}; | 6 chrome.test = chrome.test || {}; |
7 | 7 |
8 chrome.test.tests = chrome.test.tests || []; | 8 chrome.test.tests = chrome.test.tests || []; |
9 | 9 |
10 var completed = false; | 10 var completed = false; |
11 var currentTest = null; | 11 var currentTest = null; |
12 var lastTest = null; | 12 var lastTest = null; |
13 | 13 |
14 function complete() { | 14 function complete() { |
15 completed = true; | 15 completed = true; |
16 | 16 |
17 // Try to get the script to stop running immediately. | 17 // Try to get the script to stop running immediately. |
18 // This isn't an error, just an attempt at saying "done". | 18 // This isn't an error, just an attempt at saying "done". |
19 throw "completed"; | 19 throw "completed"; |
20 } | 20 } |
21 | 21 |
22 // Helper function to get around the fact that function names in javascript | 22 // Helper function to get around the fact that function names in javascript |
23 // are read-only, and you can't assign one to anonymous functions. | 23 // are read-only, and you can't assign one to anonymous functions. |
24 function testName(test) { | 24 function testName(test) { |
25 return test.name || test.generatedName; | 25 return test ? (test.name || test.generatedName) : "(no test)"; |
26 } | 26 } |
27 | 27 |
28 chrome.test.fail = function(message) { | 28 chrome.test.fail = function(message) { |
29 if (completed) throw "completed"; | 29 if (completed) throw "completed"; |
30 chrome.test.log("( FAILED ) " + testName(currentTest)); | 30 chrome.test.log("( FAILED ) " + testName(currentTest)); |
31 | 31 |
32 var stack = "(no stack available)"; | 32 var stack = "(no stack available)"; |
33 try { | 33 try { |
34 crash.me += 0; // An intentional exception to get the stack trace. | 34 crash.me += 0; // An intentional exception to get the stack trace. |
35 } catch (e) { | 35 } catch (e) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 chrome.test.callbackFail = function(expectedError) { | 205 chrome.test.callbackFail = function(expectedError) { |
206 return chrome.test.callback(null, expectedError); | 206 return chrome.test.callback(null, expectedError); |
207 }; | 207 }; |
208 | 208 |
209 chrome.test.runTests = function(tests) { | 209 chrome.test.runTests = function(tests) { |
210 chrome.test.tests = tests; | 210 chrome.test.tests = tests; |
211 chrome.test.runNextTest(); | 211 chrome.test.runNextTest(); |
212 }; | 212 }; |
213 })(); | 213 })(); |
OLD | NEW |