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 | 5 |
6 var promise_tests = Promise.resolve(); | |
7 // Helper function to run promise tests one after the other. | |
8 // TODO(ortuno): Remove once https://github.com/w3c/testharness.js/pull/115/file s | |
9 // gets through. | |
10 function sequential_promise_test(func, name) { | |
11 var test = async_test(name); | |
12 promise_tests = promise_tests.then(function() { | |
13 return Promise.resolve(test.step(func, test, test)) | |
14 .then( | |
15 function() { | |
esprehn
2015/04/11 00:45:02
I think we usually put the function() inline with
| |
16 test.done(); | |
17 }) | |
18 .catch(test.step_func( | |
19 function(value) { | |
20 throw value; | |
21 })); | |
22 }); | |
23 } | |
24 | |
6 test(function(t) { assert_exists(window, "testRunner"); t.done(); }, | 25 test(function(t) { assert_exists(window, "testRunner"); t.done(); }, |
7 "window.testRunner is required for the following tests."); | 26 "window.testRunner is required for the following tests."); |
8 | 27 |
9 async_test(function(t) { | 28 sequential_promise_test(function(t) { |
10 testRunner.setBluetoothMockDataSet('RejectRequestDevice_NotFoundError'); | 29 testRunner.setBluetoothMockDataSet('RejectRequestDevice_NotFoundError'); |
11 navigator.bluetooth.requestDevice() | 30 return navigator.bluetooth.requestDevice() |
12 .then( | 31 .then( |
13 t.step_func(function() { assert_unreached('Mock was set to reject.'); }), | 32 function() { |
14 t.step_func(function(e) { | 33 assert_unreached('Mock was set to reject.'); |
15 assert_equals(e.name, 'NotFoundError'); | 34 }, |
16 t.done(); | 35 function(e) { |
17 })); | 36 assert_equals(e.name, 'NotFoundErrora'); |
37 }); | |
18 }, 'Reject with NotFoundError.'); | 38 }, 'Reject with NotFoundError.'); |
19 | 39 |
20 async_test(function(t) { | 40 sequential_promise_test(function(t) { |
21 testRunner.setBluetoothMockDataSet('RejectRequestDevice_SecurityError'); | 41 testRunner.setBluetoothMockDataSet('RejectRequestDevice_SecurityError'); |
22 navigator.bluetooth.requestDevice() | 42 return navigator.bluetooth.requestDevice() |
23 .then( | 43 .then( |
24 t.step_func(function() { assert_unreached('Mock was set to reject.'); }), | 44 function() { |
25 t.step_func(function(e) { | 45 » assert_unreached('Mock was set to reject.'); |
46 }, | |
47 function(e) { | |
26 assert_equals(e.name, 'SecurityError'); | 48 assert_equals(e.name, 'SecurityError'); |
27 t.done(); | 49 }); |
28 })); | |
29 }, 'Reject with SecurityError.'); | 50 }, 'Reject with SecurityError.'); |
30 | 51 |
31 async_test(function(t) { | 52 sequential_promise_test(function() { |
32 testRunner.setBluetoothMockDataSet('Single Empty Device'); | 53 testRunner.setBluetoothMockDataSet('Single Empty Device'); |
33 navigator.bluetooth.requestDevice() | 54 return navigator.bluetooth.requestDevice() |
34 .then( | 55 .then(function(device) { |
35 t.step_func(function(device) { | 56 assert_equals(device.constructor.name, "BluetoothDevice"); |
36 assert_equals(device.constructor.name, "BluetoothDevice"); | 57 }); |
37 t.done(); | |
38 }), | |
39 t.step_func(function() { assert_unreached('Mock was set to resolve.'); })) ; | |
40 }, 'Mock will resolve.'); | 58 }, 'Mock will resolve.'); |
41 | |
42 </script> | 59 </script> |
OLD | NEW |