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

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

Issue 125993002: Add error handling for supervised user import flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move ManagedUserListData to its own file. Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // None of these tests is relevant for Chrome OS. 5 // None of these tests is relevant for Chrome OS.
6 GEN('#if !defined(OS_CHROMEOS)'); 6 GEN('#if !defined(OS_CHROMEOS)');
7 7
8 GEN('#include "base/command_line.h"');
9 GEN('#include "chrome/common/chrome_switches.h"');
10
8 /** 11 /**
9 * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing. 12 * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing.
10 * @extends {testing.Test} 13 * @extends {testing.Test}
11 * @constructor 14 * @constructor
12 */ 15 */
13 function ManageProfileUITest() {} 16 function ManageProfileUITest() {}
14 17
15 ManageProfileUITest.prototype = { 18 ManageProfileUITest.prototype = {
16 __proto__: testing.Test.prototype, 19 __proto__: testing.Test.prototype,
17 20
18 /** @override */ 21 /** @override */
19 browsePreload: 'chrome://settings-frame/manageProfile', 22 browsePreload: 'chrome://settings-frame/manageProfile',
20 23
21 /** 24 /**
22 * No need to run these for every OptionsPage test, since they'll cover the 25 * No need to run these for every OptionsPage test, since they'll cover the
23 * whole consolidated page each time. 26 * whole consolidated page each time.
24 * @override 27 * @override
25 */ 28 */
26 runAccessibilityChecks: false, 29 runAccessibilityChecks: false,
27 30
31 /** @override */
32 testGenPreamble: function() {
33 GEN('CommandLine::ForCurrentProcess()->' +
34 'AppendSwitch(switches::kAllowCreateExistingManagedUsers);');
35 },
36
28 /** 37 /**
29 * Returns a test profile-info object with configurable "managed" status. 38 * Returns a test profile-info object with configurable "managed" status.
30 * @param {boolean} managed If true, the test profile will be marked as 39 * @param {boolean} managed If true, the test profile will be marked as
31 * managed. 40 * managed.
32 * @return {Object} A test profile-info object. 41 * @return {Object} A test profile-info object.
33 */ 42 */
34 testProfileInfo_: function(managed) { 43 testProfileInfo_: function(managed) {
35 return { 44 return {
36 name: 'Test Profile', 45 name: 'Test Profile',
37 iconURL: 'chrome://path/to/icon/image', 46 iconURL: 'chrome://path/to/icon/image',
38 filePath: '/path/to/profile/data/on/disk', 47 filePath: '/path/to/profile/data/on/disk',
39 isCurrentProfile: true, 48 isCurrentProfile: true,
40 isManaged: managed 49 isManaged: managed
41 }; 50 };
42 }, 51 },
43 52
44 /** 53 /**
45 * Overrides WebUI methods that provide profile info, making them return a 54 * Overrides WebUI methods that provide profile info, making them return a
46 * test profile-info object. 55 * test profile-info object.
47 * @param {boolean} managed Whether the test profile should be marked managed. 56 * @param {boolean} managed Whether the test profile should be marked managed.
57 * @param {string} mode The mode of the overlay (either 'manage' or 'create').
48 */ 58 */
49 setProfileManaged_: function(managed) { 59 setProfileManaged_: function(managed, mode) {
50 // Override the BrowserOptions method to return the fake info. 60 // Override the BrowserOptions method to return the fake info.
51 BrowserOptions.getCurrentProfile = function() { 61 BrowserOptions.getCurrentProfile = function() {
52 return this.testProfileInfo_(managed); 62 return this.testProfileInfo_(managed);
53 }.bind(this); 63 }.bind(this);
54 // Set the profile info in the overlay. 64 // Set the profile info in the overlay.
55 ManageProfileOverlay.setProfileInfo(this.testProfileInfo_(managed), 65 ManageProfileOverlay.setProfileInfo(this.testProfileInfo_(managed), mode);
56 'manage');
57 }, 66 },
58 }; 67 };
59 68
60 // Receiving the new profile defaults in the manage-user overlay shouldn't mess 69 // Receiving the new profile defaults in the manage-user overlay shouldn't mess
61 // up the focus in a visible higher-level overlay. 70 // up the focus in a visible higher-level overlay.
62 TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() { 71 TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() {
63 var self = this; 72 var self = this;
64 73
65 function checkFocus(pageName, expectedFocus, initialFocus) { 74 function checkFocus(pageName, expectedFocus, initialFocus) {
66 OptionsPage.showPageByName(pageName); 75 OptionsPage.showPageByName(pageName);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 assertNotEquals(-1, signedInText.textContent.indexOf(custodianEmail)); 133 assertNotEquals(-1, signedInText.textContent.indexOf(custodianEmail));
125 134
126 CreateProfileOverlay.updateSignedInStatus(''); 135 CreateProfileOverlay.updateSignedInStatus('');
127 assertEquals('', CreateProfileOverlay.getInstance().signedInEmail_); 136 assertEquals('', CreateProfileOverlay.getInstance().signedInEmail_);
128 assertTrue(signedInText.hidden); 137 assertTrue(signedInText.hidden);
129 assertFalse(notSignedInText.hidden); 138 assertFalse(notSignedInText.hidden);
130 assertFalse($('create-profile-managed').checked); 139 assertFalse($('create-profile-managed').checked);
131 assertTrue($('create-profile-managed').disabled); 140 assertTrue($('create-profile-managed').disabled);
132 }); 141 });
133 142
143 // The import link should show up if the user tries to create a profile with the
144 // same name as an existing managed user profile.
145 TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() {
146 ManageProfileOverlay.getInstance().initializePage();
147 var custodianEmail = 'chrome.playpen.test@gmail.com';
148 CreateProfileOverlay.updateSignedInStatus(custodianEmail);
149 assertEquals(custodianEmail,
150 CreateProfileOverlay.getInstance().signedInEmail_);
151 this.setProfileManaged_(false, 'create');
152
153 // Initialize the list of existing managed users.
154 var managedUserListData = options.ManagedUserListData.getInstance();
155 managedUserListData.managedUsers_ = [
156 {
157 id: 'managedUser1',
158 name: 'Rosalie',
159 iconURL: 'chrome://path/to/icon/image',
160 onCurrentDevice: false,
161 needAvatar: false
162 },
163 {
164 id: 'managedUser2',
165 name: 'Fritz',
166 iconURL: 'chrome://path/to/icon/image',
167 onCurrentDevice: false,
168 needAvatar: true
169 },
170 {
171 id: 'managedUser3',
172 name: 'Test',
173 iconURL: 'chrome://path/to/icon/image',
174 onCurrentDevice: true,
175 needAvatar: false
176 }];
177 // Also add the name 'Test' to |profileNames_| to simulate that the profile
178 // exists on the device.
179 ManageProfileOverlay.getInstance().profileNames_.Test = true;
180
181 // Initially, the ok button should be enabled and the import link should not
182 // exist.
183 assertFalse($('create-profile-ok').disabled);
184 assertTrue($('supervised-user-import') == null);
185
186 // Now try to create profiles with the names of existing supervised users.
187 $('create-profile-managed').checked = true;
188 var nameField = $('create-profile-name');
189 // A profile which already has an avatar.
190 nameField.value = 'Rosalie';
191 ManageProfileOverlay.getInstance().onNameChanged_('create');
192 assertTrue($('create-profile-ok').disabled);
193 assertFalse($('supervised-user-import') == null);
194 // A profile which doesn't have an avatar yet.
195 nameField.value = 'Fritz';
196 ManageProfileOverlay.getInstance().onNameChanged_('create');
197 assertTrue($('create-profile-ok').disabled);
198 assertFalse($('supervised-user-import') == null);
199 // A profile which already exists on the device.
200 nameField.value = 'Test';
201 ManageProfileOverlay.getInstance().onNameChanged_('create');
202 assertTrue($('create-profile-ok').disabled);
203 assertTrue($('supervised-user-import') == null);
204
205 // A profile which does not exist yet.
206 nameField.value = 'NewProfileName';
207 ManageProfileOverlay.getInstance().onNameChanged_('create');
208 assertFalse($('create-profile-ok').disabled);
209 assertTrue($('supervised-user-import') == null);
210 });
211
134 // Managed users should not be able to edit their profile names, and the initial 212 // Managed users should not be able to edit their profile names, and the initial
135 // focus should be adjusted accordingly. 213 // focus should be adjusted accordingly.
136 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() { 214 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() {
137 var nameField = $('manage-profile-name'); 215 var nameField = $('manage-profile-name');
138 216
139 this.setProfileManaged_(false); 217 this.setProfileManaged_(false, 'manage');
140 ManageProfileOverlay.showManageDialog(); 218 ManageProfileOverlay.showManageDialog();
141 expectFalse(nameField.disabled); 219 expectFalse(nameField.disabled);
142 expectEquals(nameField, document.activeElement); 220 expectEquals(nameField, document.activeElement);
143 221
144 OptionsPage.closeOverlay(); 222 OptionsPage.closeOverlay();
145 223
146 this.setProfileManaged_(true); 224 this.setProfileManaged_(true, 'manage');
147 ManageProfileOverlay.showManageDialog(); 225 ManageProfileOverlay.showManageDialog();
148 expectTrue(nameField.disabled); 226 expectTrue(nameField.disabled);
149 expectEquals($('manage-profile-ok'), document.activeElement); 227 expectEquals($('manage-profile-ok'), document.activeElement);
150 }); 228 });
151 229
152 // Setting profile information should allow the confirmation to be shown. 230 // Setting profile information should allow the confirmation to be shown.
153 TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() { 231 TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() {
154 var testProfile = this.testProfileInfo_(true); 232 var testProfile = this.testProfileInfo_(true);
155 testProfile.custodianEmail = 'foo@bar.example.com'; 233 testProfile.custodianEmail = 'foo@bar.example.com';
156 ManagedUserCreateConfirmOverlay.setProfileInfo(testProfile); 234 ManagedUserCreateConfirmOverlay.setProfileInfo(testProfile);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 CreateProfileOverlay.updateSignedInStatus(custodianEmail); 421 CreateProfileOverlay.updateSignedInStatus(custodianEmail);
344 CreateProfileOverlay.updateManagedUsersAllowed(true); 422 CreateProfileOverlay.updateManagedUsersAllowed(true);
345 assertTrue(checkbox.disabled, 'creation in progress'); 423 assertTrue(checkbox.disabled, 'creation in progress');
346 424
347 CreateProfileOverlay.updateCreateInProgress(false); 425 CreateProfileOverlay.updateCreateInProgress(false);
348 assertFalse(checkbox.disabled, 'creation finished'); 426 assertFalse(checkbox.disabled, 'creation finished');
349 }); 427 });
350 428
351 // Managed users shouldn't be able to open the delete or create dialogs. 429 // Managed users shouldn't be able to open the delete or create dialogs.
352 TEST_F('ManageProfileUITest', 'ManagedShowDeleteAndCreate', function() { 430 TEST_F('ManageProfileUITest', 'ManagedShowDeleteAndCreate', function() {
353 this.setProfileManaged_(false); 431 this.setProfileManaged_(false, 'create');
354 432
355 ManageProfileOverlay.showCreateDialog(); 433 ManageProfileOverlay.showCreateDialog();
356 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); 434 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name);
357 OptionsPage.closeOverlay(); 435 OptionsPage.closeOverlay();
358 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 436 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
359 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); 437 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
360 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); 438 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name);
361 assertFalse($('manage-profile-overlay-delete').hidden); 439 assertFalse($('manage-profile-overlay-delete').hidden);
362 OptionsPage.closeOverlay(); 440 OptionsPage.closeOverlay();
363 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 441 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
364 442
365 this.setProfileManaged_(true); 443 this.setProfileManaged_(true, 'create');
366 ManageProfileOverlay.showCreateDialog(); 444 ManageProfileOverlay.showCreateDialog();
367 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 445 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
368 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); 446 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
369 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 447 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
370 }); 448 });
371 449
372 // Only non-managed users should be able to delete profiles. 450 // Only non-managed users should be able to delete profiles.
373 TEST_F('ManageProfileUITest', 'ManagedDelete', function() { 451 TEST_F('ManageProfileUITest', 'ManagedDelete', function() {
374 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); 452 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
375 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); 453 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name);
376 assertFalse($('manage-profile-overlay-delete').hidden); 454 assertFalse($('manage-profile-overlay-delete').hidden);
377 455
378 // Clicks the "Delete" button, after overriding chrome.send to record what 456 // Clicks the "Delete" button, after overriding chrome.send to record what
379 // messages were sent. 457 // messages were sent.
380 function clickAndListen() { 458 function clickAndListen() {
381 var originalChromeSend = chrome.send; 459 var originalChromeSend = chrome.send;
382 var chromeSendMessages = []; 460 var chromeSendMessages = [];
383 chrome.send = function(message) { 461 chrome.send = function(message) {
384 chromeSendMessages.push(message); 462 chromeSendMessages.push(message);
385 }; 463 };
386 $('delete-profile-ok').onclick(); 464 $('delete-profile-ok').onclick();
387 // Restore the original function so the test framework can use it. 465 // Restore the original function so the test framework can use it.
388 chrome.send = originalChromeSend; 466 chrome.send = originalChromeSend;
389 return chromeSendMessages; 467 return chromeSendMessages;
390 } 468 }
391 469
392 this.setProfileManaged_(false); 470 this.setProfileManaged_(false, 'manage');
393 var messages = clickAndListen(); 471 var messages = clickAndListen();
394 assertEquals(1, messages.length); 472 assertEquals(1, messages.length);
395 assertEquals('deleteProfile', messages[0]); 473 assertEquals('deleteProfile', messages[0]);
396 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 474 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
397 475
398 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); 476 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
399 this.setProfileManaged_(true); 477 this.setProfileManaged_(true, 'manage');
400 messages = clickAndListen(); 478 messages = clickAndListen();
401 assertEquals(0, messages.length); 479 assertEquals(0, messages.length);
402 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 480 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
403 }); 481 });
404 482
405 GEN('#endif // OS_CHROMEOS'); 483 GEN('#endif // OS_CHROMEOS');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698