| 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 var nativesPromise = requireAsync('testNatives'); | |
| 6 | |
| 7 function registerHooks(api) { | 5 function registerHooks(api) { |
| 8 var chromeTest = api.compiledApi; | |
| 9 var apiFunctions = api.apiFunctions; | 6 var apiFunctions = api.apiFunctions; |
| 10 | 7 |
| 11 apiFunctions.setHandleRequest('notifyPass', function() { | 8 apiFunctions.setHandleRequest('notifyPass', function() { |
| 12 nativesPromise.then(function(natives) { | 9 requireAsync('testNatives').then(function(natives) { |
| 13 natives.NotifyPass(); | 10 natives.NotifyPass(); |
| 14 }); | 11 }); |
| 15 }); | 12 }); |
| 16 | 13 |
| 17 apiFunctions.setHandleRequest('notifyFail', function(message) { | 14 apiFunctions.setHandleRequest('notifyFail', function(message) { |
| 18 nativesPromise.then(function(natives) { | 15 requireAsync('testNatives').then(function(natives) { |
| 19 natives.NotifyFail(message); | 16 natives.NotifyFail(message); |
| 20 }); | 17 }); |
| 21 }); | 18 }); |
| 22 | 19 |
| 23 apiFunctions.setHandleRequest('log', function() { | 20 apiFunctions.setHandleRequest('log', function() { |
| 24 nativesPromise.then(function(natives) { | 21 requireAsync('testNatives').then(function(natives) { |
| 25 natives.Log($Array.join(arguments, ' ')); | 22 natives.Log($Array.join(arguments, ' ')); |
| 26 }); | 23 }); |
| 27 }); | 24 }); |
| 28 | 25 |
| 29 } | 26 } |
| 30 | 27 |
| 31 function testDone(runNextTest) { | 28 function testDone(runNextTest) { |
| 32 // Use a promise here to allow previous test contexts to be eligible for | 29 // Use a promise here to allow previous test contexts to be eligible for |
| 33 // garbage collection. | 30 // garbage collection. |
| 34 Promise.resolve().then(function() { | 31 Promise.resolve().then(function() { |
| 35 runNextTest(); | 32 runNextTest(); |
| 36 }); | 33 }); |
| 37 } | 34 } |
| 38 | 35 |
| 39 function exportTests(tests, runTests, exports) { | 36 function exportTests(tests, runTests, exports) { |
| 40 $Array.forEach(tests, function(test) { | 37 $Array.forEach(tests, function(test) { |
| 41 exports[test.name] = function() { | 38 exports[test.name] = function() { |
| 42 runTests([test]); | 39 runTests([test]); |
| 43 return true; | 40 return true; |
| 44 } | 41 } |
| 45 }); | 42 }); |
| 46 } | 43 } |
| 47 | 44 |
| 48 exports.registerHooks = registerHooks; | 45 exports.registerHooks = registerHooks; |
| 49 exports.testDone = testDone; | 46 exports.testDone = testDone; |
| 50 exports.exportTests = exportTests; | 47 exports.exportTests = exportTests; |
| OLD | NEW |