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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/settings/bluetooth_page_browsertest.js
diff --git a/chrome/test/data/webui/settings/bluetooth_page_browsertest.js b/chrome/test/data/webui/settings/bluetooth_page_browsertest.js
new file mode 100644
index 0000000000000000000000000000000000000000..bbc09afe4b3e0bc318d4c7eb29d723628ee23a15
--- /dev/null
+++ b/chrome/test/data/webui/settings/bluetooth_page_browsertest.js
@@ -0,0 +1,145 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/** @fileoverview Suite of tests for settings-bluetooth-page. */
+
+GEN_INCLUDE(['settings_page_browsertest.js']);
+
+/**
+ * @constructor
+ * @extends {SettingsPageBrowserTest}
+*/
+function SettingsBluetoothPageBrowserTest() {
+}
+
+SettingsBluetoothPageBrowserTest.prototype = {
+ __proto__: SettingsPageBrowserTest.prototype,
+
+ /** @override */
+ browsePreload: 'chrome://md-settings/advanced',
+
+ /** @override */
+ extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
+ '../fake_chrome_event.js',
+ 'fake_bluetooth.js',
+ 'fake_bluetooth_private.js'
+ ]),
+
+ /** @type {Bluetooth} */
+ bluetoothApi_: undefined,
+
+ /** @type {BluetoothPrivate} */
+ bluetoothPrivateApi_: undefined,
+
+ /** @override */
+ preLoad: function() {
+ SettingsPageBrowserTest.prototype.preLoad.call(this);
+ settingsHidePagesByDefaultForTest = true;
+ this.bluetoothApi_ = new settings.FakeBluetooth();
+ 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
+ this.bluetoothPrivateApi_ =
+ new settings.FakeBluetoothPrivate(this.bluetoothApi_);
+ bluetoothPrivateApiForTest = this.bluetoothPrivateApi_;
+ }
+};
+
+// Times out on debug builders and may time out on memory bots because
+// the Settings page can take several seconds to load in a Release build
+// and several times that in a Debug build. See https://crbug.com/558434.
+GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)');
+GEN('#define MAYBE_Bluetooth DISABLED_Bluetooth');
+GEN('#else');
+GEN('#define MAYBE_Bluetooth Bluetooth');
+GEN('#endif');
+
+// Runs bluetooth tests.
+TEST_F('SettingsBluetoothPageBrowserTest', 'MAYBE_Bluetooth', function() {
+ // Assign |self| to |this| instead of binding since 'this' in suite()
+ // 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
+ var self = this;
+
+ var advanced = self.getPage('advanced');
+ assertTrue(!!advanced);
+ advanced.set('pageVisibility.bluetooth', true);
+ Polymer.dom.flush();
+
+ var fakeDevices_ = [
+ {
+ address: '10:00:00:00:00:01',
+ name: 'FakePairedDevice1',
+ paired: true,
+ },
+ {
+ address: '10:00:00:00:00:02',
+ name: 'FakePairedDevice2',
+ paired: true,
+ },
+ {
+ address: '00:00:00:00:00:01',
+ name: 'FakeUnPairedDevice1',
+ paired: false,
+ },
+ ];
+
+ suite('SettingsBluetoothPage', function() {
+ test('enable', function() {
+ assertFalse(self.bluetoothApi_.enabled);
+ var bluetoothSection = self.getSection(advanced, 'bluetooth');
+ assertTrue(!!bluetoothSection);
+ var bluetooth =
+ 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
+ assertTrue(!!bluetooth);
+ expectFalse(bluetooth.bluetoothEnabled);
+ var enable = bluetooth.$.enableBluetooth;
+ assertTrue(!!enable);
+ expectFalse(enable.checked);
+ // Test that tapping the enable checkbox changes its value and calls
+ // 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.
+ MockInteractions.tap(enable);
+ expectTrue(enable.checked);
+ expectTrue(self.bluetoothApi_.enabled);
+ // Confirm that 'bluetoothEnabled' remains set to true.
+ Polymer.dom.flush();
+ expectTrue(bluetooth.bluetoothEnabled);
+ // Set 'bluetoothEnabled' directly and confirm that the checkbox
+ // toggles.
+ bluetooth.bluetoothEnabled = false;
+ Polymer.dom.flush();
+ expectFalse(enable.checked);
+ });
+
+ test('device list', function() {
+ var bluetoothSection = self.getSection(advanced, 'bluetooth');
+ var bluetooth =
+ bluetoothSection.querySelector('settings-bluetooth-page');
+ assertTrue(!!bluetooth);
+ var deviceList = bluetooth.$.deviceList;
+ assertTrue(!!deviceList);
+ // Set enabled, with default (empty) device list.
+ self.bluetoothApi_.enabled = true;
+ bluetooth.bluetoothEnabled = true;
+ Polymer.dom.flush();
+ // Ensure that initially the 'device list empty' span is visible.
+ expectFalse(deviceList.hidden);
+ var noDevices = deviceList.querySelector('span');
+ assertTrue(!!noDevices);
+ expectFalse(noDevices.hidden);
+ // Set some devices (triggers onDeviceAdded events). 'empty' span should
+ // be hidden.
+ self.bluetoothApi_.setDevicesForTest(fakeDevices_);
+ Polymer.dom.flush();
+ expectTrue(noDevices.hidden);
+ // Confirm that there are three devices in the list.
+ var devices = deviceList.querySelectorAll('iron-selector div');
+ assertEquals(3, devices.length);
+ // Only paired devices should be visible.
+ expectFalse(devices[0].hidden);
+ expectFalse(devices[1].hidden);
+ expectTrue(devices[2].hidden);
+ });
+ });
+
+ // Run all registered tests.
+ mocha.run();
+});

Powered by Google App Engine
This is Rietveld 408576698