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

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

Issue 1466433002: Add Settings bluetooth page test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + Use FakeBluetooth + add device list tests Created 5 years 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 /**
10 * @constructor
11 * @extends {SettingsPageBrowserTest}
12 */
13 function SettingsBluetoothPageBrowserTest() {
14 }
15
16 SettingsBluetoothPageBrowserTest.prototype = {
17 __proto__: SettingsPageBrowserTest.prototype,
18
19 /** @override */
20 browsePreload: 'chrome://md-settings/advanced',
21
22 /** @override */
23 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
24 '../fake_chrome_event.js',
25 'fake_bluetooth.js',
26 'fake_bluetooth_private.js'
27 ]),
28
29 /** @type {Bluetooth} */
30 bluetoothApi_: undefined,
31
32 /** @type {BluetoothPrivate} */
33 bluetoothPrivateApi_: undefined,
34
35 /** @override */
36 preLoad: function() {
37 SettingsPageBrowserTest.prototype.preLoad.call(this);
38 settingsHidePagesByDefaultForTest = true;
39 this.bluetoothApi_ = new settings.FakeBluetooth();
40 bluetoothApiForTest = this.bluetoothApi_;
dpapad 2015/12/16 22:07:48 Where is bluetoothApiForTest defined, and where is
stevenjb 2015/12/17 00:13:34 It, along with bluetoothPrivateApiForTest are defi
dpapad 2015/12/17 02:06:58 Ok. I am guessing that those two objects are being
stevenjb 2015/12/17 17:28:12 Correct. Once a DOM element is stamped, we have no
41 this.bluetoothPrivateApi_ =
42 new settings.FakeBluetoothPrivate(this.bluetoothApi_);
43 bluetoothPrivateApiForTest = this.bluetoothPrivateApi_;
44 }
45 };
46
47 // Times out on debug builders and may time out on memory bots because
48 // the Settings page can take several seconds to load in a Release build
49 // and several times that in a Debug build. See https://crbug.com/558434.
50 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)');
51 GEN('#define MAYBE_Bluetooth DISABLED_Bluetooth');
52 GEN('#else');
53 GEN('#define MAYBE_Bluetooth Bluetooth');
54 GEN('#endif');
55
56 // Runs bluetooth tests.
57 TEST_F('SettingsBluetoothPageBrowserTest', 'MAYBE_Bluetooth', function() {
58 // Assign |self| to |this| instead of binding since 'this' in suite()
59 // and test() will be a Mocha 'Suite' or 'Test' instance.
dschuyler 2015/12/16 22:15:01 I'm having trouble parsing this comment. I'm wond
stevenjb 2015/12/17 00:13:34 That would be: // Assign |self| to |this| instead
dpapad 2015/12/17 01:12:54 FWIW (I know we talked about this before), I find
stevenjb 2015/12/17 01:28:57 If we ever need to reference the Mocha Suite or Te
dpapad 2015/12/17 02:06:58 It's fine to leave as is and address in a follow u
60 var self = this;
61
62 var advanced = self.getPage('advanced');
63 assertTrue(!!advanced);
64 advanced.set('pageVisibility.bluetooth', true);
65 Polymer.dom.flush();
66
67 var fakeDevices_ = [
68 {
69 address: '10:00:00:00:00:01',
70 name: 'FakePairedDevice1',
71 paired: true,
72 },
73 {
74 address: '10:00:00:00:00:02',
75 name: 'FakePairedDevice2',
76 paired: true,
77 },
78 {
79 address: '00:00:00:00:00:01',
80 name: 'FakeUnPairedDevice1',
81 paired: false,
82 },
83 ];
84
85 suite('SettingsBluetoothPage', function() {
86 test('enable', function() {
87 assertFalse(self.bluetoothApi_.enabled);
88 var bluetoothSection = self.getSection(advanced, 'bluetooth');
89 assertTrue(!!bluetoothSection);
90 var bluetooth =
91 bluetoothSection.querySelector('settings-bluetooth-page');
dpapad 2015/12/16 22:07:48 Nit: use $$() shorthand.
stevenjb 2015/12/17 00:13:34 Not actually the same thing. $$ queries the shadow
92 assertTrue(!!bluetooth);
93 expectFalse(bluetooth.bluetoothEnabled);
94 var enable = bluetooth.$.enableBluetooth;
95 assertTrue(!!enable);
96 expectFalse(enable.checked);
97 // Test that tapping the enable checkbox changes its value and calls
98 // bluetooth.setAdapterState with pwered = false.
dschuyler 2015/12/16 22:15:01 is pwered a mistype of powered?
stevenjb 2015/12/17 00:13:34 Done.
99 MockInteractions.tap(enable);
100 expectTrue(enable.checked);
101 expectTrue(self.bluetoothApi_.enabled);
102 // Confirm that 'bluetoothEnabled' remains set to true.
103 Polymer.dom.flush();
104 expectTrue(bluetooth.bluetoothEnabled);
105 // Set 'bluetoothEnabled' directly and confirm that the checkbox
106 // toggles.
107 bluetooth.bluetoothEnabled = false;
108 Polymer.dom.flush();
109 expectFalse(enable.checked);
110 });
111
112 test('device list', function() {
113 var bluetoothSection = self.getSection(advanced, 'bluetooth');
114 var bluetooth =
115 bluetoothSection.querySelector('settings-bluetooth-page');
116 assertTrue(!!bluetooth);
117 var deviceList = bluetooth.$.deviceList;
118 assertTrue(!!deviceList);
119 // Set enabled, with default (empty) device list.
120 self.bluetoothApi_.enabled = true;
121 bluetooth.bluetoothEnabled = true;
122 Polymer.dom.flush();
123 // Ensure that initially the 'device list empty' span is visible.
124 expectFalse(deviceList.hidden);
125 var noDevices = deviceList.querySelector('span');
126 assertTrue(!!noDevices);
127 expectFalse(noDevices.hidden);
128 // Set some devices (triggers onDeviceAdded events). 'empty' span should
129 // be hidden.
130 self.bluetoothApi_.setDevicesForTest(fakeDevices_);
131 Polymer.dom.flush();
132 expectTrue(noDevices.hidden);
133 // Confirm that there are three devices in the list.
134 var devices = deviceList.querySelectorAll('iron-selector div');
135 assertEquals(3, devices.length);
136 // Only paired devices should be visible.
137 expectFalse(devices[0].hidden);
138 expectFalse(devices[1].hidden);
139 expectTrue(devices[2].hidden);
140 });
141 });
142
143 // Run all registered tests.
144 mocha.run();
145 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698