Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome/test/data/webui/settings/bluetooth_page_browsertest_chromeos.js

Issue 1466433002: Add Settings bluetooth page test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make Chrome OS only Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /** @fileoverview Suite of tests for settings-bluetooth-page. */
6
7 GEN_INCLUDE(['settings_page_browsertest.js']);
8
9 var bluetoothPage = bluetoothPage || {};
10
11 /**
12 * @constructor
13 * @extends {SettingsPageBrowserTest}
14 */
15 function SettingsBluetoothPageBrowserTest() {
16 }
17
18 SettingsBluetoothPageBrowserTest.prototype = {
19 __proto__: SettingsPageBrowserTest.prototype,
20
21 /** @override */
22 browsePreload: 'chrome://md-settings/advanced',
23
24 /** @override */
25 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
26 '../fake_chrome_event.js',
27 'fake_bluetooth.js',
28 'fake_bluetooth_private.js'
29 ]),
30
31 /** @type {Bluetooth} */
32 bluetoothApi_: undefined,
33
34 /** @type {BluetoothPrivate} */
35 bluetoothPrivateApi_: undefined,
36
37 /** @override */
38 preLoad: function() {
39 SettingsPageBrowserTest.prototype.preLoad.call(this);
40 settingsHidePagesByDefaultForTest = true;
41 this.bluetoothApi_ = new settings.FakeBluetooth();
42 this.bluetoothPrivateApi_ =
43 new settings.FakeBluetoothPrivate(this.bluetoothApi_);
44 // Set globals to override Settings Bluetooth Page apis.
45 bluetoothPage.bluetoothApiForTest = this.bluetoothApi_;
46 bluetoothPage.bluetoothPrivateApiForTest = this.bluetoothPrivateApi_;
47 }
48 };
49
50 // Times out on debug builders and may time out on memory bots because
51 // the Settings page can take several seconds to load in a Release build
52 // and several times that in a Debug build. See https://crbug.com/558434.
53 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)');
54 GEN('#define MAYBE_Bluetooth DISABLED_Bluetooth');
55 GEN('#else');
56 GEN('#define MAYBE_Bluetooth Bluetooth');
57 GEN('#endif');
58
59 // Runs bluetooth tests.
60 TEST_F('SettingsBluetoothPageBrowserTest', 'MAYBE_Bluetooth', function() {
61 // Differentiate |this| in the Test from |this| in suite() and test(), see
62 // comment at the top of mocha_adapter.js.
63 var self = this;
64
65 var advanced = self.getPage('advanced');
66 assertTrue(!!advanced);
67 advanced.set('pageVisibility.bluetooth', true);
68 Polymer.dom.flush();
69
70 /** @type {!Array<!chrome.bluetooth.Device>} */ var fakeDevices_ = [
71 {
72 address: '10:00:00:00:00:01',
73 name: 'FakePairedDevice1',
74 paired: true,
75 },
76 {
77 address: '10:00:00:00:00:02',
78 name: 'FakePairedDevice2',
79 paired: true,
80 },
81 {
82 address: '00:00:00:00:00:01',
83 name: 'FakeUnPairedDevice1',
84 paired: false,
85 },
86 ];
87
88 suite('SettingsBluetoothPage', function() {
89 test('enable', function() {
90 assertFalse(self.bluetoothApi_.enabled);
Dan Beam 2015/12/28 20:01:39 yeah, this just a case of |this| changing when int
michaelpg 2015/12/28 20:39:36 these functions are .call()d with a particular con
stevenjb 2015/12/28 20:49:16 Acknowledged.
91 var bluetoothSection = self.getSection(advanced, 'bluetooth');
92 assertTrue(!!bluetoothSection);
93 var bluetooth =
94 bluetoothSection.querySelector('settings-bluetooth-page');
95 assertTrue(!!bluetooth);
96 expectFalse(bluetooth.bluetoothEnabled);
97 var enable = bluetooth.$.enableBluetooth;
98 assertTrue(!!enable);
99 expectFalse(enable.checked);
100 // Test that tapping the enable checkbox changes its value and calls
101 // bluetooth.setAdapterState with powered = false.
102 MockInteractions.tap(enable);
103 expectTrue(enable.checked);
104 expectTrue(self.bluetoothApi_.enabled);
105 // Confirm that 'bluetoothEnabled' remains set to true.
106 Polymer.dom.flush();
107 expectTrue(bluetooth.bluetoothEnabled);
108 // Set 'bluetoothEnabled' directly and confirm that the checkbox
109 // toggles.
110 bluetooth.bluetoothEnabled = false;
111 Polymer.dom.flush();
112 expectFalse(enable.checked);
113 });
114
115 test('device list', function() {
Dan Beam 2015/12/28 20:01:39 I think we still might be better off doing the min
stevenjb 2015/12/28 20:49:16 Understood, but I am also worried about per-test o
stevenjb 2015/12/28 20:49:16 Understood, but I am also worried about per-test o
116 var bluetoothSection = self.getSection(advanced, 'bluetooth');
117 var bluetooth =
118 bluetoothSection.querySelector('settings-bluetooth-page');
119 assertTrue(!!bluetooth);
120 var deviceList = bluetooth.$.deviceList;
121 assertTrue(!!deviceList);
122 // Set enabled, with default (empty) device list.
123 self.bluetoothApi_.enabled = true;
124 bluetooth.bluetoothEnabled = true;
125 Polymer.dom.flush();
126 // Ensure that initially the 'device list empty' span is visible.
127 expectFalse(deviceList.hidden);
128 var noDevices = deviceList.querySelector('span');
129 assertTrue(!!noDevices);
130 expectFalse(noDevices.hidden);
131 // Set some devices (triggers onDeviceAdded events). 'empty' span should
132 // be hidden.
133 self.bluetoothApi_.setDevicesForTest(fakeDevices_);
134 Polymer.dom.flush();
135 expectTrue(noDevices.hidden);
136 // Confirm that there are three devices in the list.
137 var devices = deviceList.querySelectorAll('iron-selector div');
138 assertEquals(3, devices.length);
139 // Only paired devices should be visible.
140 expectFalse(devices[0].hidden);
141 expectFalse(devices[1].hidden);
142 expectTrue(devices[2].hidden);
143 });
144 });
145
146 // Run all registered tests.
147 mocha.run();
148 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698