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

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

Issue 253543002: web_dev_style: check webui browser tests as well. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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('#include "chrome/browser/ui/webui/options/options_browsertest.h"'); 5 GEN('#include "chrome/browser/ui/webui/options/options_browsertest.h"');
6 6
7 /** @const */ var MANAGED_USERS_PREF = 'profile.managed_users'; 7 /** @const */ var MANAGED_USERS_PREF = 'profile.managed_users';
8 8
9 /** 9 /**
10 * Wait for the method specified by |methodName|, on the |object| object, to be 10 * Wait for the method specified by |methodName|, on the |object| object, to be
11 * called, then execute |afterFunction|. 11 * called, then execute |afterFunction|.
12 * @param {*} object Object with callable property named |methodName|.
13 * @param {string} methodName The name of the property on |object| to use as a
14 * callback.
15 * @param {!Function} afterFunction A function to call after object.methodName()
16 * is called.
12 */ 17 */
13 function waitForResponse(object, methodName, afterFunction) { 18 function waitForResponse(object, methodName, afterFunction) {
14 var originalCallback = object[methodName]; 19 var originalCallback = object[methodName];
15 20
16 // Install a wrapper that temporarily replaces the original function. 21 // Install a wrapper that temporarily replaces the original function.
17 object[methodName] = function() { 22 object[methodName] = function() {
18 object[methodName] = originalCallback; 23 object[methodName] = originalCallback;
19 originalCallback.apply(this, arguments); 24 originalCallback.apply(this, arguments);
20 afterFunction(); 25 afterFunction();
21 }; 26 };
22 } 27 }
23 28
24 /** 29 /**
25 * Wait for the global window.onpopstate callback to be called (after a tab 30 * Wait for the global window.onpopstate callback to be called (after a tab
26 * history navigation), then execute |afterFunction|. 31 * history navigation), then execute |afterFunction|.
32 * @param {!Function} afterFunction A function to call after pop state events.
27 */ 33 */
28 function waitForPopstate(afterFunction) { 34 function waitForPopstate(afterFunction) {
29 waitForResponse(window, 'onpopstate', afterFunction); 35 waitForResponse(window, 'onpopstate', afterFunction);
30 } 36 }
31 37
32 /** 38 /**
33 * TestFixture for OptionsPage WebUI testing. 39 * TestFixture for OptionsPage WebUI testing.
34 * @extends {testing.Test} 40 * @extends {testing.Test}
35 * @constructor 41 * @constructor
36 */ 42 */
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 assertNotEquals(defaultZoomFactor, null); 142 assertNotEquals(defaultZoomFactor, null);
137 143
138 // Verify that the zoom factor element has a reasonable number of choices. 144 // Verify that the zoom factor element has a reasonable number of choices.
139 expectGE(defaultZoomFactor.options.length, defaultZoomFactorMinimumLength); 145 expectGE(defaultZoomFactor.options.length, defaultZoomFactorMinimumLength);
140 146
141 // Simulate a change event, selecting the highest zoom value. Verify that 147 // Simulate a change event, selecting the highest zoom value. Verify that
142 // the javascript handler was invoked once. 148 // the javascript handler was invoked once.
143 this.mockHandler.expects(once()).defaultZoomFactorAction(NOT_NULL). 149 this.mockHandler.expects(once()).defaultZoomFactorAction(NOT_NULL).
144 will(callFunction(function() { })); 150 will(callFunction(function() { }));
145 defaultZoomFactor.selectedIndex = defaultZoomFactor.options.length - 1; 151 defaultZoomFactor.selectedIndex = defaultZoomFactor.options.length - 1;
146 var event = { target: defaultZoomFactor }; 152 var event = {target: defaultZoomFactor};
147 if (defaultZoomFactor.onchange) defaultZoomFactor.onchange(event); 153 if (defaultZoomFactor.onchange) defaultZoomFactor.onchange(event);
148 testDone(); 154 testDone();
149 }); 155 });
150 156
151 // If |confirmInterstitial| is true, the OK button of the Do Not Track 157 /**
152 // interstitial is pressed, otherwise the abort button is pressed. 158 * If |confirmInterstitial| is true, the OK button of the Do Not Track
159 * interstitial is pressed, otherwise the abort button is pressed.
160 * @param {boolean} confirmInterstitial Whether to confirm the Do Not Track
161 * interstitial.
162 */
153 OptionsWebUITest.prototype.testDoNotTrackInterstitial = 163 OptionsWebUITest.prototype.testDoNotTrackInterstitial =
154 function(confirmInterstitial) { 164 function(confirmInterstitial) {
155 Preferences.prefsFetchedCallback({'enable_do_not_track': {'value': false } }); 165 Preferences.prefsFetchedCallback({'enable_do_not_track': {'value': false}});
156 var buttonToClick = confirmInterstitial ? $('do-not-track-confirm-ok') 166 var buttonToClick = confirmInterstitial ? $('do-not-track-confirm-ok') :
157 : $('do-not-track-confirm-cancel'); 167 $('do-not-track-confirm-cancel');
158 var dntCheckbox = $('do-not-track-enabled'); 168 var dntCheckbox = $('do-not-track-enabled');
159 var dntOverlay = OptionsPage.registeredOverlayPages['donottrackconfirm']; 169 var dntOverlay = OptionsPage.registeredOverlayPages['donottrackconfirm'];
160 assertFalse(dntCheckbox.checked); 170 assertFalse(dntCheckbox.checked);
161 171
162 var visibleChangeCounter = 0; 172 var visibleChangeCounter = 0;
163 var visibleChangeHandler = function() { 173 var visibleChangeHandler = function() {
164 ++visibleChangeCounter; 174 ++visibleChangeCounter;
165 switch (visibleChangeCounter) { 175 switch (visibleChangeCounter) {
166 case 1: 176 case 1:
167 window.setTimeout(function() { 177 window.setTimeout(function() {
168 assertTrue(dntOverlay.visible); 178 assertTrue(dntOverlay.visible);
169 buttonToClick.click(); 179 buttonToClick.click();
170 }, 0); 180 }, 0);
171 break; 181 break;
172 case 2: 182 case 2:
173 window.setTimeout(function() { 183 window.setTimeout(function() {
174 assertFalse(dntOverlay.visible); 184 assertFalse(dntOverlay.visible);
175 assertEquals(confirmInterstitial, dntCheckbox.checked); 185 assertEquals(confirmInterstitial, dntCheckbox.checked);
176 dntOverlay.removeEventListener(visibleChangeHandler); 186 dntOverlay.removeEventListener(visibleChangeHandler);
177 testDone(); 187 testDone();
178 }, 0); 188 }, 0);
179 break; 189 break;
180 default: 190 default:
181 assertTrue(false); 191 assertTrue(false);
182 } 192 }
183 } 193 };
184 dntOverlay.addEventListener('visibleChange', visibleChangeHandler); 194 dntOverlay.addEventListener('visibleChange', visibleChangeHandler);
185 195
186 if (confirmInterstitial) { 196 if (confirmInterstitial) {
187 this.mockHandler.expects(once()).setBooleanPref( 197 this.mockHandler.expects(once()).setBooleanPref(
188 ['enable_do_not_track', true, 'Options_DoNotTrackCheckbox']); 198 ['enable_do_not_track', true, 'Options_DoNotTrackCheckbox']);
189 } else { 199 } else {
190 // The mock handler complains if setBooleanPref is called even though 200 // The mock handler complains if setBooleanPref is called even though
191 // it should not be. 201 // it should not be.
192 } 202 }
193 203
194 dntCheckbox.click(); 204 dntCheckbox.click();
195 } 205 };
196 206
197 TEST_F('OptionsWebUITest', 'EnableDoNotTrackAndConfirmInterstitial', 207 TEST_F('OptionsWebUITest', 'EnableDoNotTrackAndConfirmInterstitial',
198 function() { 208 function() {
199 this.testDoNotTrackInterstitial(true); 209 this.testDoNotTrackInterstitial(true);
200 }); 210 });
201 211
202 TEST_F('OptionsWebUITest', 'EnableDoNotTrackAndCancelInterstitial', 212 TEST_F('OptionsWebUITest', 'EnableDoNotTrackAndCancelInterstitial',
203 function() { 213 function() {
204 this.testDoNotTrackInterstitial(false); 214 this.testDoNotTrackInterstitial(false);
205 }); 215 });
206 216
207 // Check that the "Do not Track" preference can be correctly disabled. 217 // Check that the "Do not Track" preference can be correctly disabled.
208 // In order to do that, we need to enable it first. 218 // In order to do that, we need to enable it first.
209 TEST_F('OptionsWebUITest', 'EnableAndDisableDoNotTrack', function() { 219 TEST_F('OptionsWebUITest', 'EnableAndDisableDoNotTrack', function() {
210 Preferences.prefsFetchedCallback({'enable_do_not_track': {'value': false } }); 220 Preferences.prefsFetchedCallback({'enable_do_not_track': {'value': false}});
211 var dntCheckbox = $('do-not-track-enabled'); 221 var dntCheckbox = $('do-not-track-enabled');
212 var dntOverlay = OptionsPage.registeredOverlayPages['donottrackconfirm']; 222 var dntOverlay = OptionsPage.registeredOverlayPages.donottrackconfirm;
213 assertFalse(dntCheckbox.checked); 223 assertFalse(dntCheckbox.checked);
214 224
215 var visibleChangeCounter = 0; 225 var visibleChangeCounter = 0;
216 var visibleChangeHandler = function() { 226 var visibleChangeHandler = function() {
217 ++visibleChangeCounter; 227 ++visibleChangeCounter;
218 switch (visibleChangeCounter) { 228 switch (visibleChangeCounter) {
219 case 1: 229 case 1:
220 window.setTimeout(function() { 230 window.setTimeout(function() {
221 assertTrue(dntOverlay.visible); 231 assertTrue(dntOverlay.visible);
222 $('do-not-track-confirm-ok').click(); 232 $('do-not-track-confirm-ok').click();
223 }, 0); 233 }, 0);
224 break; 234 break;
225 case 2: 235 case 2:
226 window.setTimeout(function() { 236 window.setTimeout(function() {
227 assertFalse(dntOverlay.visible); 237 assertFalse(dntOverlay.visible);
228 assertTrue(dntCheckbox.checked); 238 assertTrue(dntCheckbox.checked);
229 dntOverlay.removeEventListener(visibleChangeHandler); 239 dntOverlay.removeEventListener(visibleChangeHandler);
230 dntCheckbox.click(); 240 dntCheckbox.click();
231 }, 0); 241 }, 0);
232 break; 242 break;
233 default: 243 default:
234 assertNotReached(); 244 assertNotReached();
235 } 245 }
236 } 246 }
237 dntOverlay.addEventListener('visibleChange', visibleChangeHandler); 247 dntOverlay.addEventListener('visibleChange', visibleChangeHandler);
238 248
239 this.mockHandler.expects(once()).setBooleanPref( 249 this.mockHandler.expects(once()).setBooleanPref(
240 eq(["enable_do_not_track", true, 'Options_DoNotTrackCheckbox'])); 250 eq(['enable_do_not_track', true, 'Options_DoNotTrackCheckbox']));
241 251
242 var verifyCorrectEndState = function() { 252 var verifyCorrectEndState = function() {
243 window.setTimeout(function() { 253 window.setTimeout(function() {
244 assertFalse(dntOverlay.visible); 254 assertFalse(dntOverlay.visible);
245 assertFalse(dntCheckbox.checked); 255 assertFalse(dntCheckbox.checked);
246 testDone(); 256 testDone();
247 }, 0) 257 }, 0);
248 } 258 }
249 this.mockHandler.expects(once()).setBooleanPref( 259 this.mockHandler.expects(once()).setBooleanPref(
250 eq(["enable_do_not_track", false, 'Options_DoNotTrackCheckbox'])).will( 260 eq(['enable_do_not_track', false, 'Options_DoNotTrackCheckbox'])).will(
251 callFunction(verifyCorrectEndState)); 261 callFunction(verifyCorrectEndState));
252 262
253 dntCheckbox.click(); 263 dntCheckbox.click();
254 }); 264 });
255 265
256 // Verify that preventDefault() is called on 'Enter' keydown events that trigger 266 // Verify that preventDefault() is called on 'Enter' keydown events that trigger
257 // the default button. If this doesn't happen, other elements that may get 267 // the default button. If this doesn't happen, other elements that may get
258 // focus (by the overlay closing for instance), will execute in addition to the 268 // focus (by the overlay closing for instance), will execute in addition to the
259 // default button. See crbug.com/268336. 269 // default button. See crbug.com/268336.
260 TEST_F('OptionsWebUITest', 'EnterPreventsDefault', function() { 270 TEST_F('OptionsWebUITest', 'EnterPreventsDefault', function() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 335
326 testGenPreamble: function() { 336 testGenPreamble: function() {
327 // Start with no supervised users managed by this profile. 337 // Start with no supervised users managed by this profile.
328 GEN(' ClearPref("' + MANAGED_USERS_PREF + '");'); 338 GEN(' ClearPref("' + MANAGED_USERS_PREF + '");');
329 }, 339 },
330 340
331 /** @override */ 341 /** @override */
332 isAsync: true, 342 isAsync: true,
333 343
334 /** @override */ 344 /** @override */
335 setUp: function () { 345 setUp: function() {
336 // user-image-stream is a streaming video element used for capturing a 346 // user-image-stream is a streaming video element used for capturing a
337 // user image during OOBE. 347 // user image during OOBE.
338 this.accessibilityAuditConfig.ignoreSelectors('videoWithoutCaptions', 348 this.accessibilityAuditConfig.ignoreSelectors('videoWithoutCaptions',
339 '.user-image-stream'); 349 '.user-image-stream');
340 }, 350 },
341 351
342 /** 352 /**
343 * Asserts that two non-nested arrays are equal. The arrays must contain only 353 * Asserts that two non-nested arrays are equal. The arrays must contain only
344 * plain data types, no nested arrays or other objects. 354 * plain data types, no nested arrays or other objects.
345 * @param {Array} expected An array of expected values. 355 * @param {Array} expected An array of expected values.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 prohibitChangesToOverlay_: function(overlay) { 458 prohibitChangesToOverlay_: function(overlay) {
449 overlay.initializePage = 459 overlay.initializePage =
450 overlay.didShowPage = 460 overlay.didShowPage =
451 overlay.didClosePage = function() { 461 overlay.didClosePage = function() {
452 assertTrue(false, 462 assertTrue(false,
453 'Overlay was affected when changes were prohibited.'); 463 'Overlay was affected when changes were prohibited.');
454 }; 464 };
455 }, 465 },
456 }; 466 };
457 467
458 /* 468 /**
459 * Set by verifyHistory_ to incorporate a followup callback, then called by the 469 * Set by verifyHistory_ to incorporate a followup callback, then called by the
460 * C++ fixture with the navigation history to be verified. 470 * C++ fixture with the navigation history to be verified.
461 * @type {Function} 471 * @type {Function}
462 */ 472 */
463 OptionsWebUIExtendedTest.verifyHistoryCallback = null; 473 OptionsWebUIExtendedTest.verifyHistoryCallback = null;
464 474
465 // Show the search page with no query string, to fall back to the settings page. 475 // Show the search page with no query string, to fall back to the settings page.
466 // Test disabled because it's flaky. crbug.com/303841 476 // Test disabled because it's flaky. crbug.com/303841
467 TEST_F('OptionsWebUIExtendedTest', 'DISABLED_ShowSearchPageNoQuery', 477 TEST_F('OptionsWebUIExtendedTest', 'DISABLED_ShowSearchPageNoQuery',
468 function() { 478 function() {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 chrome.send('optionsTestSetPref', [MANAGED_USERS_PREF, {key: 'value'}]); 759 chrome.send('optionsTestSetPref', [MANAGED_USERS_PREF, {key: 'value'}]);
750 waitForResponse(BrowserOptions, 'updateManagesSupervisedUsers', function() { 760 waitForResponse(BrowserOptions, 'updateManagesSupervisedUsers', function() {
751 assertFalse($('profiles-supervised-dashboard-tip').hidden); 761 assertFalse($('profiles-supervised-dashboard-tip').hidden);
752 chrome.send('optionsTestSetPref', [MANAGED_USERS_PREF, {}]); 762 chrome.send('optionsTestSetPref', [MANAGED_USERS_PREF, {}]);
753 waitForResponse(BrowserOptions, 'updateManagesSupervisedUsers', function() { 763 waitForResponse(BrowserOptions, 'updateManagesSupervisedUsers', function() {
754 assertTrue($('profiles-supervised-dashboard-tip').hidden); 764 assertTrue($('profiles-supervised-dashboard-tip').hidden);
755 testDone(); 765 testDone();
756 }); 766 });
757 }); 767 });
758 }); 768 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698