OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 GEN('#if defined(OS_CHROMEOS)'); | 5 GEN('#if defined(OS_CHROMEOS)'); |
6 | 6 |
7 function BluetoothWebUITest() {} | 7 function BluetoothWebUITest() {} |
8 | 8 |
9 BluetoothWebUITest.prototype = { | 9 BluetoothWebUITest.prototype = { |
10 __proto__: testing.Test.prototype, | 10 __proto__: testing.Test.prototype, |
11 | 11 |
12 /** | 12 /** |
13 * Start tests from the main-settings page. | 13 * Start tests from the main-settings page. |
14 */ | 14 */ |
15 browsePreload: 'chrome://settings-frame/settings', | 15 browsePreload: 'chrome://settings-frame/settings', |
16 | 16 |
17 /** | 17 /** |
18 * @inheritDoc | 18 * @override |
19 */ | 19 */ |
20 preLoad: function() { | 20 preLoad: function() { |
21 this.makeAndRegisterMockHandler([ | 21 this.makeAndRegisterMockHandler([ |
22 'bluetoothEnableChange', | 22 'bluetoothEnableChange', |
23 'updateBluetoothDevice', | 23 'updateBluetoothDevice', |
24 'findBluetoothDevices', | 24 'findBluetoothDevices', |
25 'stopBluetoothDeviceDiscovery', | 25 'stopBluetoothDeviceDiscovery', |
26 ]); | 26 ]); |
27 }, | 27 }, |
28 | 28 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 * @param {!Element} element Text input field. | 61 * @param {!Element} element Text input field. |
62 * @param {string} text New value for the input field. | 62 * @param {string} text New value for the input field. |
63 */ | 63 */ |
64 fakeInput: function(element, text) { | 64 fakeInput: function(element, text) { |
65 element.value = text; | 65 element.value = text; |
66 cr.dispatchSimpleEvent(element, 'input'); | 66 cr.dispatchSimpleEvent(element, 'input'); |
67 }, | 67 }, |
68 | 68 |
69 }; | 69 }; |
70 | 70 |
71 TEST_F('BluetoothWebUITest','testEnableBluetooth', function() { | 71 TEST_F('BluetoothWebUITest', 'testEnableBluetooth', function() { |
72 assertEquals(this.browsePreload, document.location.href); | 72 assertEquals(this.browsePreload, document.location.href); |
73 expectFalse($('enable-bluetooth').checked); | 73 expectFalse($('enable-bluetooth').checked); |
74 expectTrue($('bluetooth-paired-devices-list').parentNode.hidden); | 74 expectTrue($('bluetooth-paired-devices-list').parentNode.hidden); |
75 | 75 |
76 this.mockHandler.expects(once()).bluetoothEnableChange([true]).will( | 76 this.mockHandler.expects(once()).bluetoothEnableChange([true]).will( |
77 callFunction(function() { | 77 callFunction(function() { |
78 options.BrowserOptions.setBluetoothState(true); | 78 options.BrowserOptions.setBluetoothState(true); |
79 })); | 79 })); |
80 $('enable-bluetooth').click(); | 80 $('enable-bluetooth').click(); |
81 | 81 |
82 expectFalse($('bluetooth-paired-devices-list').parentNode.hidden); | 82 expectFalse($('bluetooth-paired-devices-list').parentNode.hidden); |
83 }); | 83 }); |
84 | 84 |
85 TEST_F('BluetoothWebUITest','testAddDevices', function() { | 85 TEST_F('BluetoothWebUITest', 'testAddDevices', function() { |
86 assertEquals(this.browsePreload, document.location.href); | 86 assertEquals(this.browsePreload, document.location.href); |
87 | 87 |
88 var pairedDeviceList = $('bluetooth-paired-devices-list'); | 88 var pairedDeviceList = $('bluetooth-paired-devices-list'); |
89 var unpairedDeviceList = $('bluetooth-unpaired-devices-list'); | 89 var unpairedDeviceList = $('bluetooth-unpaired-devices-list'); |
90 | 90 |
91 var fakePairedDevice = { | 91 var fakePairedDevice = { |
92 address: '00:11:22:33:44:55', | 92 address: '00:11:22:33:44:55', |
93 connectable: true, | 93 connectable: true, |
94 connected: false, | 94 connected: false, |
95 name: 'Fake device', | 95 name: 'Fake device', |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // Test selecting an element and clicking on the connect button. | 159 // Test selecting an element and clicking on the connect button. |
160 this.mockHandler.expects(once()).stopBluetoothDeviceDiscovery(); | 160 this.mockHandler.expects(once()).stopBluetoothDeviceDiscovery(); |
161 this.mockHandler.expects(once()).updateBluetoothDevice( | 161 this.mockHandler.expects(once()).updateBluetoothDevice( |
162 [fakeUnpairedDevice2.address, 'connect']); | 162 [fakeUnpairedDevice2.address, 'connect']); |
163 this.selectDevice(unpairedDeviceList, fakeUnpairedDevice2); | 163 this.selectDevice(unpairedDeviceList, fakeUnpairedDevice2); |
164 var connectButton = $('bluetooth-add-device-apply-button'); | 164 var connectButton = $('bluetooth-add-device-apply-button'); |
165 expectFalse(connectButton.disabled); | 165 expectFalse(connectButton.disabled); |
166 connectButton.click(); | 166 connectButton.click(); |
167 }); | 167 }); |
168 | 168 |
169 TEST_F('BluetoothWebUITest','testDevicePairing', function() { | 169 TEST_F('BluetoothWebUITest', 'testDevicePairing', function() { |
170 assertEquals(this.browsePreload, document.location.href); | 170 assertEquals(this.browsePreload, document.location.href); |
171 | 171 |
172 var pairedDeviceList = $('bluetooth-paired-devices-list'); | 172 var pairedDeviceList = $('bluetooth-paired-devices-list'); |
173 var unpairedDeviceList = $('bluetooth-unpaired-devices-list'); | 173 var unpairedDeviceList = $('bluetooth-unpaired-devices-list'); |
174 | 174 |
175 var fakeDevice = { | 175 var fakeDevice = { |
176 address: '00:24:BE:00:00:00', | 176 address: '00:24:BE:00:00:00', |
177 connectable: true, | 177 connectable: true, |
178 connected: false, | 178 connected: false, |
179 name: 'Sony BT-00', | 179 name: 'Sony BT-00', |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 $('bluetooth-pair-device-connect-button').click(); | 217 $('bluetooth-pair-device-connect-button').click(); |
218 | 218 |
219 // Verify that the device is removed from the unparied list and added to the | 219 // Verify that the device is removed from the unparied list and added to the |
220 // paired device list. | 220 // paired device list. |
221 expectTrue(!!this.getElementForDevice(pairedDeviceList, | 221 expectTrue(!!this.getElementForDevice(pairedDeviceList, |
222 fakeDevice.name)); | 222 fakeDevice.name)); |
223 expectFalse(!!this.getElementForDevice(unpairedDeviceList, | 223 expectFalse(!!this.getElementForDevice(unpairedDeviceList, |
224 fakeDevice.name)); | 224 fakeDevice.name)); |
225 }); | 225 }); |
226 | 226 |
227 TEST_F('BluetoothWebUITest','testConnectionState', function() { | 227 TEST_F('BluetoothWebUITest', 'testConnectionState', function() { |
228 assertEquals(this.browsePreload, document.location.href); | 228 assertEquals(this.browsePreload, document.location.href); |
229 | 229 |
230 var pairedDeviceList = $('bluetooth-paired-devices-list'); | 230 var pairedDeviceList = $('bluetooth-paired-devices-list'); |
231 var connectButton = $('bluetooth-reconnect-device'); | 231 var connectButton = $('bluetooth-reconnect-device'); |
232 | 232 |
233 var fakeDevice = { | 233 var fakeDevice = { |
234 address: '00:24:BE:00:00:00', | 234 address: '00:24:BE:00:00:00', |
235 connectable: true, | 235 connectable: true, |
236 connected: false, | 236 connected: false, |
237 name: 'Sony BT-00', | 237 name: 'Sony BT-00', |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 [fakeDevice.address, 'forget']).will( | 288 [fakeDevice.address, 'forget']).will( |
289 callFunction(function() { | 289 callFunction(function() { |
290 options.BrowserOptions.removeBluetoothDevice(fakeDevice.address); | 290 options.BrowserOptions.removeBluetoothDevice(fakeDevice.address); |
291 })); | 291 })); |
292 button.click(); | 292 button.click(); |
293 expectFalse(!!this.getElementForDevice(pairedDeviceList, | 293 expectFalse(!!this.getElementForDevice(pairedDeviceList, |
294 fakeDevice.name)); | 294 fakeDevice.name)); |
295 }); | 295 }); |
296 | 296 |
297 | 297 |
298 TEST_F('BluetoothWebUITest','testMaliciousInput', function() { | 298 TEST_F('BluetoothWebUITest', 'testMaliciousInput', function() { |
299 assertEquals(this.browsePreload, document.location.href); | 299 assertEquals(this.browsePreload, document.location.href); |
300 | 300 |
301 var unpairedDeviceList = $('bluetooth-unpaired-devices-list'); | 301 var unpairedDeviceList = $('bluetooth-unpaired-devices-list'); |
302 var pairDeviceDialog = $('bluetooth-pairing'); | 302 var pairDeviceDialog = $('bluetooth-pairing'); |
303 | 303 |
304 var maliciousStrings = [ | 304 var maliciousStrings = [ |
305 '<SCRIPT>alert(1)</SCRIPT>', | 305 '<SCRIPT>alert(1)</SCRIPT>', |
306 '>\'>\\"><SCRIPT>alert(1)</SCRIPT>', | 306 '>\'>\\"><SCRIPT>alert(1)</SCRIPT>', |
307 '<IMG SRC=\\"javascript:alert(1)\\">', | 307 '<IMG SRC=\\"javascript:alert(1)\\">', |
308 '<A HREF=\\"data:text/html;base64,' + | 308 '<A HREF=\\"data:text/html;base64,' + |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 assertTrue(!!element); | 365 assertTrue(!!element); |
366 var label = element.querySelector('.bluetooth-device-label'); | 366 var label = element.querySelector('.bluetooth-device-label'); |
367 assertTrue(!!label); | 367 assertTrue(!!label); |
368 assertEquals(maliciousStrings[i], label.textContent); | 368 assertEquals(maliciousStrings[i], label.textContent); |
369 assertEquals(pairDeviceDialogSize, nodeCount(pairDeviceDialog)); | 369 assertEquals(pairDeviceDialogSize, nodeCount(pairDeviceDialog)); |
370 } | 370 } |
371 | 371 |
372 }); | 372 }); |
373 | 373 |
374 GEN('#endif'); | 374 GEN('#endif'); |
OLD | NEW |