Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script> | 4 <script> |
| 5 var lock = false; | |
| 6 var testQueue = []; | |
| 7 | |
| 8 var getLock = function(test) { | |
|
esprehn
2015/04/08 00:10:29
function getLock, no need for the var.
| |
| 9 if (lock) { | |
| 10 testQueue.push(test); | |
| 11 } else { | |
| 12 lock = true; | |
| 13 test(); | |
| 14 } | |
| 15 }; | |
| 16 | |
| 17 var releaseLock = function() { | |
|
esprehn
2015/04/08 00:10:29
function releaseLock()
| |
| 18 var nextTest = testQueue.shift(); | |
| 19 if (nextTest) { | |
| 20 nextTest(); | |
|
Jeffrey Yasskin
2015/04/07 23:46:38
Probably use `Promise.resolve().then(nextTest)` or
| |
| 21 } else { | |
| 22 lock = false; | |
| 23 } | |
| 24 }; | |
| 5 | 25 |
| 6 test(function(t) { assert_exists(window, "testRunner"); t.done(); }, | 26 test(function(t) { assert_exists(window, "testRunner"); t.done(); }, |
| 7 "window.testRunner is required for the following tests."); | 27 "window.testRunner is required for the following tests."); |
| 8 | 28 |
| 9 async_test(function(t) { | 29 getLock(function(t) { |
|
Jeffrey Yasskin
2015/04/07 23:46:38
I'm not sure the test will wait for all of the tes
| |
| 10 testRunner.setBluetoothMockDataSet('RejectRequestDevice_NotFoundError'); | 30 async_test(function(t) { |
| 11 navigator.bluetooth.requestDevice() | 31 testRunner.setBluetoothMockDataSet('RejectRequestDevice_NotFoundError'); |
|
Jeffrey Yasskin
2015/04/07 23:46:38
If this throws, it'll hang the test. It'd be bette
| |
| 12 .then( | 32 navigator.bluetooth.requestDevice() |
| 13 t.step_func(function() { assert_unreached('Mock was set to reject.'); }), | 33 .then( |
| 14 t.step_func(function(e) { | 34 » t.step_func(function() { |
| 15 assert_equals(e.name, 'NotFoundError'); | 35 releaseLock(); |
| 16 t.done(); | 36 assert_unreached('Mock was set to reject.'); }), |
| 17 })); | 37 » t.step_func(function(e) { |
| 18 }, 'Reject with NotFoundError.'); | 38 releaseLock(); |
| 39 assert_equals(e.name, 'NotFoundError'); | |
| 40 t.done(); | |
| 41 » })); | |
| 42 }, 'Reject with NotFoundError.')}); | |
| 19 | 43 |
| 20 async_test(function(t) { | 44 getLock(function(t) { |
| 21 testRunner.setBluetoothMockDataSet('RejectRequestDevice_SecurityError'); | 45 async_test(function(t) { |
| 22 navigator.bluetooth.requestDevice() | 46 testRunner.setBluetoothMockDataSet('RejectRequestDevice_SecurityError'); |
| 23 .then( | 47 navigator.bluetooth.requestDevice() |
| 24 t.step_func(function() { assert_unreached('Mock was set to reject.'); }), | 48 .then( |
| 25 t.step_func(function(e) { | 49 » t.step_func(function() { |
| 26 assert_equals(e.name, 'SecurityError'); | 50 releaseLock(); |
| 27 t.done(); | 51 » assert_unreached('Mock was set to reject.'); |
| 28 })); | 52 » }), |
| 29 }, 'Reject with SecurityError.'); | 53 » t.step_func(function(e) { |
| 54 releaseLock(); | |
| 55 assert_equals(e.name, 'SecurityError'); | |
| 56 t.done(); | |
| 57 » })); | |
| 58 }, 'Reject with SecurityError.')}); | |
| 30 | 59 |
| 31 async_test(function(t) { | 60 getLock(function(t) { |
| 32 testRunner.setBluetoothMockDataSet('Single Empty Device'); | 61 async_test(function(t) { |
| 33 navigator.bluetooth.requestDevice() | 62 testRunner.setBluetoothMockDataSet('Single Empty Device'); |
| 34 .then( | 63 navigator.bluetooth.requestDevice() |
| 35 t.step_func(function(device) { | 64 .then( |
| 36 assert_equals(device.constructor.name, "BluetoothDevice"); | 65 » t.step_func(function(device) { |
| 37 t.done(); | 66 releaseLock(); |
| 38 }), | 67 assert_equals(device.constructor.name, "BluetoothDevice"); |
| 39 t.step_func(function() { assert_unreached('Mock was set to resolve.'); })) ; | 68 t.done(); |
| 40 }, 'Mock will resolve.'); | 69 » }), |
| 41 | 70 » t.step_func(function() { |
| 71 releaseLock(); | |
| 72 » assert_unreached('Mock was set to resolve.'); | |
| 73 » })); | |
| 74 }, 'Mock will resolve.')}); | |
| 42 </script> | 75 </script> |
| OLD | NEW |