OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // test_custom_bindings.js | 5 // test_unittest_custom_bindings.js |
6 // mini-framework for ExtensionApiTest browser tests | 6 // An implementation of chrome.test for ApiTestBase unit tests. |
7 // This is a fork of src/extensions/renderer/resources/test_custom_bindings.js. | |
not at google - send to devlin
2014/07/18 15:09:14
I'm not sure about this. It seems like you could a
Sam McNally
2014/07/21 03:56:28
Done.
| |
7 | 8 |
8 var binding = require('binding').Binding.create('test'); | 9 var binding = require('binding').Binding.create('test'); |
9 | 10 |
10 var chrome = requireNative('chrome').GetChrome(); | 11 var nativesPromise = requireAsync('testNatives'); |
11 var GetExtensionAPIDefinitionsForTest = | |
12 requireNative('apiDefinitions').GetExtensionAPIDefinitionsForTest; | |
13 var GetAvailability = requireNative('v8_context').GetAvailability; | |
14 var GetAPIFeatures = requireNative('test_features').GetAPIFeatures; | |
15 var uncaughtExceptionHandler = require('uncaught_exception_handler'); | 12 var uncaughtExceptionHandler = require('uncaught_exception_handler'); |
16 var userGestures = requireNative('user_gestures'); | |
17 | |
18 var RunWithNativesEnabledModuleSystem = | |
19 requireNative('v8_context').RunWithNativesEnabledModuleSystem; | |
20 | 13 |
21 binding.registerCustomHook(function(api) { | 14 binding.registerCustomHook(function(api) { |
22 var chromeTest = api.compiledApi; | 15 var chromeTest = api.compiledApi; |
23 var apiFunctions = api.apiFunctions; | 16 var apiFunctions = api.apiFunctions; |
24 | 17 |
25 chromeTest.tests = chromeTest.tests || []; | 18 chromeTest.tests = chromeTest.tests || []; |
26 | 19 |
27 var currentTest = null; | 20 var currentTest = null; |
28 var lastTest = null; | 21 var lastTest = null; |
29 var testsFailed = 0; | 22 var testsFailed = 0; |
30 var testCount = 1; | 23 var testCount = 1; |
31 var failureException = 'chrome.test.failure'; | 24 var failureException = 'chrome.test.failure'; |
32 | 25 |
33 // Helper function to get around the fact that function names in javascript | 26 // Helper function to get around the fact that function names in javascript |
34 // are read-only, and you can't assign one to anonymous functions. | 27 // are read-only, and you can't assign one to anonymous functions. |
35 function testName(test) { | 28 function testName(test) { |
36 return test ? (test.name || test.generatedName) : "(no test)"; | 29 return test ? (test.name || test.generatedName) : "(no test)"; |
37 } | 30 } |
38 | 31 |
32 apiFunctions.setHandleRequest('notifyPass', function() { | |
33 nativesPromise.then(function(natives) { | |
34 natives.NotifyPass(); | |
35 }); | |
36 }); | |
37 | |
38 apiFunctions.setHandleRequest('notifyFail', function(message) { | |
39 nativesPromise.then(function(natives) { | |
40 natives.NotifyFail(message); | |
41 }); | |
42 }); | |
43 | |
44 apiFunctions.setHandleRequest('log', function() { | |
45 nativesPromise.then(function(natives) { | |
46 natives.Log($Array.join(arguments, ' ')); | |
47 }); | |
48 }); | |
49 | |
39 function testDone() { | 50 function testDone() { |
40 // Use setTimeout here to allow previous test contexts to be | 51 // Use a promise here to allow previous test contexts to be eligible for |
41 // eligible for garbage collection. | 52 // garbage collection. |
42 setTimeout(chromeTest.runNextTest, 0); | 53 Promise.resolve().then(function() { |
54 chromeTest.runNextTest(); | |
55 }); | |
43 } | 56 } |
44 | 57 |
45 function allTestsDone() { | 58 function allTestsDone() { |
46 if (testsFailed == 0) { | 59 if (testsFailed == 0) { |
47 chromeTest.notifyPass(); | 60 chromeTest.notifyPass(); |
48 } else { | 61 } else { |
49 chromeTest.notifyFail('Failed ' + testsFailed + ' of ' + | 62 chromeTest.notifyFail('Failed ' + testsFailed + ' of ' + |
50 testCount + ' tests'); | 63 testCount + ' tests'); |
51 } | 64 } |
52 } | 65 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 throw failureException; | 132 throw failureException; |
120 }); | 133 }); |
121 | 134 |
122 apiFunctions.setHandleRequest('succeed', function() { | 135 apiFunctions.setHandleRequest('succeed', function() { |
123 console.log("[SUCCESS] " + testName(currentTest)); | 136 console.log("[SUCCESS] " + testName(currentTest)); |
124 chromeTest.log("( SUCCESS )"); | 137 chromeTest.log("( SUCCESS )"); |
125 testDone(); | 138 testDone(); |
126 }); | 139 }); |
127 | 140 |
128 apiFunctions.setHandleRequest('runWithModuleSystem', function(callback) { | 141 apiFunctions.setHandleRequest('runWithModuleSystem', function(callback) { |
129 RunWithNativesEnabledModuleSystem(callback); | 142 throw new Error('Not implemented'); |
130 }); | 143 }); |
131 | 144 |
132 apiFunctions.setHandleRequest('assertTrue', function(test, message) { | 145 apiFunctions.setHandleRequest('assertTrue', function(test, message) { |
133 chromeTest.assertBool(test, true, message); | 146 chromeTest.assertBool(test, true, message); |
134 }); | 147 }); |
135 | 148 |
136 apiFunctions.setHandleRequest('assertFalse', function(test, message) { | 149 apiFunctions.setHandleRequest('assertFalse', function(test, message) { |
137 chromeTest.assertBool(test, false, message); | 150 chromeTest.assertBool(test, false, message); |
138 }); | 151 }); |
139 | 152 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 | 330 |
318 apiFunctions.setHandleRequest('callbackPass', function(func) { | 331 apiFunctions.setHandleRequest('callbackPass', function(func) { |
319 return chromeTest.callback(func); | 332 return chromeTest.callback(func); |
320 }); | 333 }); |
321 | 334 |
322 apiFunctions.setHandleRequest('callbackFail', function(expectedError, func) { | 335 apiFunctions.setHandleRequest('callbackFail', function(expectedError, func) { |
323 return chromeTest.callback(func, expectedError); | 336 return chromeTest.callback(func, expectedError); |
324 }); | 337 }); |
325 | 338 |
326 apiFunctions.setHandleRequest('runTests', function(tests) { | 339 apiFunctions.setHandleRequest('runTests', function(tests) { |
327 chromeTest.tests = tests; | 340 var testWrappers = {}; |
328 testCount = chromeTest.tests.length; | 341 $Array.forEach(tests, function(testCase) { |
329 chromeTest.runNextTest(); | 342 testWrappers[testName(testCase)] = function() { |
343 chromeTest.tests = [testCase]; | |
344 testCount = 1; | |
345 chromeTest.runNextTest(); | |
346 return true; | |
347 } | |
348 }); | |
349 return testWrappers; | |
330 }); | 350 }); |
331 | 351 |
332 apiFunctions.setHandleRequest('getApiDefinitions', function() { | 352 apiFunctions.setHandleRequest('getApiDefinitions', function() { |
333 return GetExtensionAPIDefinitionsForTest(); | 353 throw new Error('Not implemented'); |
334 }); | 354 }); |
335 | 355 |
336 apiFunctions.setHandleRequest('getApiFeatures', function() { | 356 apiFunctions.setHandleRequest('getApiFeatures', function() { |
337 return GetAPIFeatures(); | 357 throw new Error('Not implemented'); |
338 }); | 358 }); |
339 | 359 |
340 apiFunctions.setHandleRequest('isProcessingUserGesture', function() { | 360 apiFunctions.setHandleRequest('isProcessingUserGesture', function() { |
341 return userGestures.IsProcessingUserGesture(); | 361 throw new Error('Not implemented'); |
342 }); | 362 }); |
343 | 363 |
344 apiFunctions.setHandleRequest('runWithUserGesture', function(callback) { | 364 apiFunctions.setHandleRequest('runWithUserGesture', function(callback) { |
345 chromeTest.assertEq(typeof(callback), 'function'); | 365 throw new Error('Not implemented'); |
346 return userGestures.RunWithUserGesture(callback); | |
347 }); | 366 }); |
348 | 367 |
349 apiFunctions.setHandleRequest('runWithoutUserGesture', function(callback) { | 368 apiFunctions.setHandleRequest('runWithoutUserGesture', function(callback) { |
350 chromeTest.assertEq(typeof(callback), 'function'); | 369 throw new Error('Not implemented'); |
351 return userGestures.RunWithoutUserGesture(callback); | |
352 }); | 370 }); |
353 | 371 |
354 apiFunctions.setHandleRequest('setExceptionHandler', function(callback) { | 372 apiFunctions.setHandleRequest('setExceptionHandler', function(callback) { |
355 chromeTest.assertEq(typeof(callback), 'function'); | 373 chromeTest.assertEq(typeof(callback), 'function'); |
356 uncaughtExceptionHandler.setHandler(callback); | 374 uncaughtExceptionHandler.setHandler(callback); |
357 }); | 375 }); |
358 }); | 376 }); |
359 | 377 |
360 exports.binding = binding.generate(); | 378 exports.binding = binding.generate(); |
379 | |
not at google - send to devlin
2014/07/18 15:09:14
not this
Sam McNally
2014/07/21 03:56:28
Done.
| |
OLD | NEW |