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 src="resources/bluetooth-helpers.js"></script> | 4 <script src="resources/bluetooth-helpers.js"></script> |
5 <script> | 5 <script> |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | 8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, |
9 'window.testRunner is required for the following tests.'); | 9 'window.testRunner is required for the following tests.'); |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 return requestDeviceWithKeyDown({filters: [{services: [testSpec.uuid]}]}) | 110 return requestDeviceWithKeyDown({filters: [{services: [testSpec.uuid]}]}) |
111 .then(device => { | 111 .then(device => { |
112 assert_promise_rejects_with_message( | 112 assert_promise_rejects_with_message( |
113 device.connectGATT(), | 113 device.connectGATT(), |
114 testSpec.error, | 114 testSpec.error, |
115 'Adapter failed to connect to device.'); | 115 'Adapter failed to connect to device.'); |
116 }); | 116 }); |
117 }, testSpec.testName); | 117 }, testSpec.testName); |
118 }); | 118 }); |
119 | 119 |
120 // TODO(ortuno): Allow connections when the tab is in the background. | |
121 // This is a short term solution instead of implementing a tab indicator | |
122 // for bluetooth connections. | |
123 // https://crbug.com/579746 | |
124 promise_test(() => { | |
125 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | |
126 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | |
127 .then(device => { | |
128 testRunner.setPageVisibility('hidden'); | |
129 return assert_promise_rejects_with_message( | |
130 device.connectGATT(), | |
131 new DOMException('Connection is only allowed while the page is visible. ' + | |
132 'This is a temporary measure until we are able to ' + | |
133 'effectively communicate to the user that a page is ' + | |
134 'connected to a device.', | |
135 'SecurityError')); | |
136 }).then(() => testRunner.setPageVisibility('visible')); | |
Jeffrey Yasskin
2016/01/21 23:44:33
Do we also need to run this if the promise rejects
ortuno
2016/01/22 21:34:12
Added catch.
| |
137 }, 'Device should not be able to connect in background.'); | |
138 | |
120 promise_test(() => { | 139 promise_test(() => { |
121 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 140 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
122 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 141 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
123 .then(device => device.connectGATT()) | 142 .then(device => device.connectGATT()) |
124 .then(gattServer => assert_true(gattServer.connected)); | 143 .then(gattServer => assert_true(gattServer.connected)); |
125 }, 'Device will connect'); | 144 }, 'Device will connect'); |
126 | 145 |
127 promise_test(() => { | 146 promise_test(() => { |
128 testRunner.setBluetoothMockDataSet(''); | 147 testRunner.setBluetoothMockDataSet(''); |
129 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 148 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
130 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 149 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) |
131 .then(device => { | 150 .then(device => { |
132 return Promise.all([device.connectGATT(), device.connectGATT()]) | 151 return Promise.all([device.connectGATT(), device.connectGATT()]) |
133 }).then(gattServers => { | 152 }).then(gattServers => { |
134 // connectGATT should return the same object if it was created earlier. | 153 // connectGATT should return the same object if it was created earlier. |
135 // TODO(ortuno): change to assert_equals. | 154 // TODO(ortuno): change to assert_equals. |
136 assert_not_equals(gattServers[0], gattServers[1]); | 155 assert_not_equals(gattServers[0], gattServers[1]); |
137 }); | 156 }); |
138 }); | 157 }); |
139 </script> | 158 </script> |
OLD | NEW |