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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/power_overlay_browsertest.js

Issue 2919343005: Remove tests for deprecated Options UI (Closed)
Patch Set: and more Created 3 years, 6 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 GEN_INCLUDE(['../options_browsertest_base.js']);
6
7 function PowerOverlayWebUITest() {}
8
9 PowerOverlayWebUITest.prototype = {
10 __proto__: OptionsBrowsertestBase.prototype,
11
12 browsePreload: 'chrome://settings-frame/',
13
14 commandLineSwitches: [{
15 switchName: 'enable-power-overlay',
16 }],
17
18 /** @override */
19 preLoad: function() {
20 this.makeAndRegisterMockHandler([
21 'updatePowerStatus',
22 'setPowerSource',
23 ]);
24 this.mockHandler.expects(atLeastOnce()).updatePowerStatus();
25 },
26
27 /**
28 * Sets power sources using a deep copy of |sources|.
29 * @param {Array<Object>} sources
30 * @param {string} sourceId
31 * @param {bool} isUsbCharger
32 * @param {bool} isCalculating
33 */
34 setPowerSources: function(sources, sourceId, isUsbCharger, isCalculating) {
35 var sourcesCopy = sources.map(function(source) {
36 return Object.assign({}, source);
37 });
38 options.PowerOverlay.setPowerSources(
39 sourcesCopy, sourceId, isUsbCharger, isCalculating);
40 },
41
42 /**
43 * Simulates the user selecting a power source, verifying that the overlay
44 * calls setPowerSource.
45 * @param {string} sourceId
46 */
47 selectPowerSource: function(sourceId) {
48 this.mockHandler.expects(once()).setPowerSource(eq(sourceId));
49 $('power-source-dropdown').value = sourceId;
50 expectTrue(cr.dispatchSimpleEvent($('power-source-dropdown'), 'change'));
51 },
52
53 /**
54 * Checks that the sources dropdown is visible.
55 * @param {string} sourceId The ID of the source that should be selected.
56 */
57 checkSource: function(sourceId) {
58 expectTrue($('power-source-charger').hidden);
59 expectFalse($('power-sources').hidden);
60 expectEquals(sourceId, $('power-source-dropdown').value);
61 },
62
63 checkNoSources: function() {
64 expectTrue($('power-source-charger').hidden);
65 expectTrue($('power-sources').hidden);
66 },
67
68 checkDedicatedCharger: function() {
69 expectFalse($('power-source-charger').hidden);
70 expectTrue($('power-sources').hidden);
71 },
72 };
73
74 TEST_F('PowerOverlayWebUITest', 'testNoPowerSources', function() {
75 assertEquals(this.browsePreload, document.location.href);
76 this.mockHandler.expects(never()).setPowerSource();
77 $('power-settings-link').click();
78
79 // This should be the initial state.
80 this.checkNoSources();
81
82 // Setting an empty sources list shouldn't change the state.
83 this.setPowerSources([], '', false, false);
84 this.checkNoSources();
85 });
86
87 TEST_F('PowerOverlayWebUITest', 'testDedicatedCharger', function() {
88 assertEquals(this.browsePreload, document.location.href);
89 this.mockHandler.expects(never()).setPowerSource();
90 $('power-settings-link').click();
91
92 var fakeSources = [{
93 id: 'source1',
94 description: 'Left port',
95 type: options.PowerStatusDeviceType.DEDICATED_CHARGER,
96 }];
97
98 this.setPowerSources(fakeSources, 'source1', false, false);
99 this.checkDedicatedCharger();
100
101 // Remove the charger.
102 this.setPowerSources([], '');
103 this.checkNoSources();
104
105 // Set a low-powered charger.
106 this.setPowerSources(fakeSources, 'source1', true, false);
107 this.checkDedicatedCharger();
108 });
109
110 TEST_F('PowerOverlayWebUITest', 'testSingleSource', function() {
111 assertEquals(this.browsePreload, document.location.href);
112 $('power-settings-link').click();
113
114 var fakeSources = [{
115 id: 'source1',
116 description: 'Left port',
117 type: options.PowerStatusDeviceType.DUAL_ROLE_USB,
118 }];
119
120 this.setPowerSources(fakeSources, '', false, false);
121 this.checkSource('');
122
123 this.selectPowerSource('source1');
124 this.checkSource('source1');
125
126 // Remove the device.
127 this.setPowerSources([], '', false, false);
128 this.checkNoSources();
129 });
130
131 TEST_F('PowerOverlayWebUITest', 'testMultipleSources', function() {
132 assertEquals(this.browsePreload, document.location.href);
133 $('power-settings-link').click();
134
135 var fakeSources = [{
136 id: 'source1',
137 description: 'Left port',
138 type: options.PowerStatusDeviceType.DUAL_ROLE_USB,
139 }, {
140 id: 'source2',
141 description: 'Right port',
142 type: options.PowerStatusDeviceType.DUAL_ROLE_USB,
143 }, {
144 id: 'source3',
145 description: 'Front port',
146 type: options.PowerStatusDeviceType.DUAL_ROLE_USB,
147 }, {
148 id: 'source4',
149 description: 'Rear port',
150 type: options.PowerStatusDeviceType.DUAL_ROLE_USB,
151 }];
152
153 // Use a dual-role device.
154 this.setPowerSources(fakeSources, 'source2', false, false);
155 this.checkSource('source2');
156
157 // Use a USB charger.
158 this.setPowerSources(fakeSources, 'source3', true, false);
159 this.checkSource('source3');
160
161 // Remove the currently used device.
162 fakeSources.splice(2, 1);
163 this.setPowerSources(fakeSources, 'source4', false, false);
164 this.checkSource('source4');
165
166 // Do not charge (use battery).
167 this.setPowerSources(fakeSources, '', false, false);
168 this.checkSource('');
169
170 // The user selects a device.
171 this.selectPowerSource('source1');
172
173 // The user selects the battery.
174 this.selectPowerSource('');
175 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698