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
3 // found in the LICENSE file.
5 // None of these tests is relevant for Chrome OS.
6 GEN('#if !defined(OS_CHROMEOS)');
9 * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing.
10 * @extends {testing.Test}
13 function ManageProfileUITest() {}
15 ManageProfileUITest
.prototype = {
16 __proto__
: testing
.Test
.prototype,
19 browsePreload
: 'chrome://settings-frame/manageProfile',
22 * No need to run these for every OptionsPage test, since they'll cover the
23 * whole consolidated page each time.
26 runAccessibilityChecks
: false,
29 * Some default profile infos.
35 * Returns a test profile-info object with configurable "supervised" status.
36 * @param {boolean} supervised If true, the test profile will be marked as
38 * @return {Object} A test profile-info object.
40 testProfileInfo_: function(supervised
) {
43 iconURL
: 'chrome://path/to/icon/image',
44 filePath
: '/path/to/profile/data/on/disk',
45 isCurrentProfile
: true,
46 isSupervised
: supervised
51 * Overrides WebUI methods that provide profile info, making them return a
52 * test profile-info object.
53 * @param {boolean} supervised Whether the test profile should be marked
55 * @param {string} mode The mode of the overlay (either 'manage' or 'create').
57 setProfileSupervised_: function(supervised
, mode
) {
58 // Override the BrowserOptions method to return the fake info.
59 BrowserOptions
.getCurrentProfile = function() {
60 return this.testProfileInfo_(supervised
);
62 // Set the profile info in the overlay.
63 ManageProfileOverlay
.setProfileInfo(this.testProfileInfo_(supervised
),
68 * Set some default profile infos (icon URLs and names).
69 * @param {boolean} supervised Whether the test profile should be marked as
71 * @param {string} mode The mode of the overlay (either 'manage' or 'create').
73 initDefaultProfiles_: function(mode
) {
74 PageManager
.showPageByName(mode
+ 'Profile');
76 var defaultProfile
= {
78 iconURL
: '/default/path',
80 this.defaultIconURLs
= ['/some/path',
81 defaultProfile
.iconURL
,
84 this.defaultNames
= ['Some Name', defaultProfile
.name
, '', 'Another Name'];
85 ManageProfileOverlay
.receiveDefaultProfileIconsAndNames(
86 mode
, this.defaultIconURLs
, this.defaultNames
);
87 ManageProfileOverlay
.receiveNewProfileDefaults(defaultProfile
);
89 // Make sure the correct item in the icon grid was selected.
90 var gridEl
= $(mode
+ '-profile-icon-grid');
91 expectEquals(defaultProfile
.iconURL
, gridEl
.selectedItem
);
95 // Receiving the new profile defaults in the manage-user overlay shouldn't mess
96 // up the focus in a visible higher-level overlay.
97 TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() {
100 function checkFocus(pageName
, expectedFocus
, initialFocus
) {
101 PageManager
.showPageByName(pageName
);
102 initialFocus
.focus();
103 expectEquals(initialFocus
, document
.activeElement
, pageName
);
105 ManageProfileOverlay
.receiveNewProfileDefaults(
106 self
.testProfileInfo_(false));
107 expectEquals(expectedFocus
, document
.activeElement
, pageName
);
108 PageManager
.closeOverlay();
111 // Receiving new profile defaults sets focus to the name field if the create
112 // overlay is open, and should not change focus at all otherwise.
113 checkFocus('manageProfile',
114 $('manage-profile-cancel'),
115 $('manage-profile-cancel'));
116 checkFocus('createProfile',
117 $('create-profile-name'),
118 $('create-profile-cancel'));
119 checkFocus('supervisedUserLearnMore',
120 $('supervised-user-learn-more-done'),
121 $('supervised-user-learn-more-done'));
122 checkFocus('supervisedUserLearnMore',
123 document
.querySelector('#supervised-user-learn-more-text a'),
124 document
.querySelector('#supervised-user-learn-more-text a'));
127 // The default options should be reset each time the creation overlay is shown.
128 TEST_F('ManageProfileUITest', 'DefaultCreateOptions', function() {
129 PageManager
.showPageByName('createProfile');
130 var shortcutsAllowed
= loadTimeData
.getBoolean('profileShortcutsEnabled');
131 var createShortcut
= $('create-shortcut');
132 var createSupervised
= $('create-profile-supervised');
133 assertEquals(shortcutsAllowed
, createShortcut
.checked
);
134 assertFalse(createSupervised
.checked
);
136 createShortcut
.checked
= !shortcutsAllowed
;
137 createSupervised
.checked
= true;
138 PageManager
.closeOverlay();
139 PageManager
.showPageByName('createProfile');
140 assertEquals(shortcutsAllowed
, createShortcut
.checked
);
141 assertFalse(createSupervised
.checked
);
144 // The checkbox label should change depending on whether the user is signed in.
145 TEST_F('ManageProfileUITest', 'CreateSupervisedUserText', function() {
146 var signedInText
= $('create-profile-supervised-signed-in');
147 var notSignedInText
= $('create-profile-supervised-not-signed-in');
149 ManageProfileOverlay
.getInstance().initializePage();
151 var custodianEmail
= 'chrome.playpen.test@gmail.com';
152 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
153 assertEquals(custodianEmail
,
154 CreateProfileOverlay
.getInstance().signedInEmail_
);
155 assertFalse(signedInText
.hidden
);
156 assertTrue(notSignedInText
.hidden
);
157 // Make sure the email is in the string somewhere, without depending on the
158 // exact details of the message.
159 assertNotEquals(-1, signedInText
.textContent
.indexOf(custodianEmail
));
161 CreateProfileOverlay
.updateSignedInStatus('');
162 assertEquals('', CreateProfileOverlay
.getInstance().signedInEmail_
);
163 assertTrue(signedInText
.hidden
);
164 assertFalse(notSignedInText
.hidden
);
165 assertFalse($('create-profile-supervised').checked
);
166 assertTrue($('create-profile-supervised').disabled
);
169 function ManageProfileUITestAsync() {}
171 ManageProfileUITestAsync
.prototype = {
172 __proto__
: ManageProfileUITest
.prototype,
177 // The import link should show up if the user tries to create a profile with the
178 // same name as an existing supervised user profile.
179 TEST_F('ManageProfileUITestAsync', 'CreateExistingSupervisedUser', function() {
180 // Initialize the list of existing supervised users.
181 var supervisedUsers
= [
183 id
: 'supervisedUser1',
185 iconURL
: 'chrome://path/to/icon/image',
186 onCurrentDevice
: false,
190 id
: 'supervisedUser2',
192 iconURL
: 'chrome://path/to/icon/image',
193 onCurrentDevice
: false,
197 id
: 'supervisedUser3',
199 iconURL
: 'chrome://path/to/icon/image',
200 onCurrentDevice
: true,
204 id
: 'supervisedUser4',
206 iconURL
: 'chrome://path/to/icon/image',
207 onCurrentDevice
: false,
210 var promise
= Promise
.resolve(supervisedUsers
);
211 options
.SupervisedUserListData
.getInstance().promise_
= promise
;
213 // Initialize the ManageProfileOverlay.
214 ManageProfileOverlay
.getInstance().initializePage();
215 var custodianEmail
= 'chrome.playpen.test@gmail.com';
216 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
217 assertEquals(custodianEmail
,
218 CreateProfileOverlay
.getInstance().signedInEmail_
);
219 this.setProfileSupervised_(false, 'create');
221 // Also add the names 'Test' and 'SameName' to |existingProfileNames_| to
222 // simulate that profiles with those names exist on the device.
223 ManageProfileOverlay
.getInstance().existingProfileNames_
.Test
= true;
224 ManageProfileOverlay
.getInstance().existingProfileNames_
.SameName
= true;
226 // Initially, the ok button should be enabled and the import link should not
228 assertFalse($('create-profile-ok').disabled
);
229 assertTrue($('supervised-user-import-existing') == null);
231 // Now try to create profiles with the names of existing supervised users.
232 $('create-profile-supervised').checked
= true;
233 var nameField
= $('create-profile-name');
234 // A profile which already has an avatar.
235 nameField
.value
= 'Rosalie';
236 ManageProfileOverlay
.getInstance().onNameChanged_('create');
237 // Need to wait until the promise resolves.
238 promise
.then(function() {
239 assertTrue($('create-profile-ok').disabled
);
240 assertFalse($('supervised-user-import-existing') == null);
242 // A profile which doesn't have an avatar yet.
243 nameField
.value
= 'Fritz';
244 ManageProfileOverlay
.getInstance().onNameChanged_('create');
245 return options
.SupervisedUserListData
.getInstance().promise_
;
247 assertTrue($('create-profile-ok').disabled
);
248 assertFalse($('supervised-user-import-existing') == null);
250 // A profile which already exists on the device.
251 nameField
.value
= 'Test';
252 ManageProfileOverlay
.getInstance().onNameChanged_('create');
253 return options
.SupervisedUserListData
.getInstance().promise_
;
255 assertFalse($('create-profile-ok').disabled
);
256 assertTrue($('supervised-user-import-existing') == null);
258 // A profile which does not exist on the device, but there is a profile with
259 // the same name already on the device.
260 nameField
.value
= 'SameName';
261 ManageProfileOverlay
.getInstance().onNameChanged_('create');
262 return options
.SupervisedUserListData
.getInstance().promise_
;
264 assertTrue($('create-profile-ok').disabled
);
265 assertFalse($('supervised-user-import-existing') == null);
267 // A profile which does not exist yet.
268 nameField
.value
= 'NewProfileName';
269 ManageProfileOverlay
.getInstance().onNameChanged_('create');
270 return options
.SupervisedUserListData
.getInstance().promise_
;
272 assertFalse($('create-profile-ok').disabled
);
273 assertTrue($('supervised-user-import-existing') == null);
278 // Supervised users should not be able to edit their profile names, and the
279 // initial focus should be adjusted accordingly.
280 TEST_F('ManageProfileUITest', 'EditSupervisedUserNameAllowed', function() {
281 var nameField
= $('manage-profile-name');
283 this.setProfileSupervised_(false, 'manage');
284 ManageProfileOverlay
.showManageDialog();
285 expectFalse(nameField
.disabled
);
286 expectEquals(nameField
, document
.activeElement
);
288 PageManager
.closeOverlay();
290 this.setProfileSupervised_(true, 'manage');
291 ManageProfileOverlay
.showManageDialog();
292 expectTrue(nameField
.disabled
);
293 expectEquals($('manage-profile-ok'), document
.activeElement
);
296 // Setting profile information should allow the confirmation to be shown.
297 TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() {
298 var testProfile
= this.testProfileInfo_(true);
299 testProfile
.custodianEmail
= 'foo@bar.example.com';
300 SupervisedUserCreateConfirmOverlay
.setProfileInfo(testProfile
);
301 assertTrue(SupervisedUserCreateConfirmOverlay
.getInstance().canShowPage());
302 PageManager
.showPageByName('supervisedUserCreateConfirm', false);
303 assertEquals('supervisedUserCreateConfirm',
304 PageManager
.getTopmostVisiblePage().name
);
307 // Trying to show a confirmation dialog with no profile information should fall
308 // back to the default (main) settings page.
309 TEST_F('ManageProfileUITest', 'NoEmptyConfirmation', function() {
310 assertEquals('manageProfile', PageManager
.getTopmostVisiblePage().name
);
311 assertFalse(SupervisedUserCreateConfirmOverlay
.getInstance().canShowPage());
312 PageManager
.showPageByName('supervisedUserCreateConfirm', true);
313 assertEquals('settings', PageManager
.getTopmostVisiblePage().name
);
316 // A confirmation dialog should be shown after creating a new supervised user.
317 TEST_F('ManageProfileUITest', 'ShowCreateConfirmationOnSuccess', function() {
318 PageManager
.showPageByName('createProfile');
319 assertEquals('createProfile', PageManager
.getTopmostVisiblePage().name
);
320 CreateProfileOverlay
.onSuccess(this.testProfileInfo_(false));
321 assertEquals('settings', PageManager
.getTopmostVisiblePage().name
);
323 PageManager
.showPageByName('createProfile');
324 assertEquals('createProfile', PageManager
.getTopmostVisiblePage().name
);
325 CreateProfileOverlay
.onSuccess(this.testProfileInfo_(true));
326 assertEquals('supervisedUserCreateConfirm',
327 PageManager
.getTopmostVisiblePage().name
);
328 expectEquals($('supervised-user-created-switch'), document
.activeElement
);
331 // An error should be shown if creating a new supervised user fails.
332 TEST_F('ManageProfileUITest', 'NoCreateConfirmationOnError', function() {
333 PageManager
.showPageByName('createProfile');
334 assertEquals('createProfile', PageManager
.getTopmostVisiblePage().name
);
335 var errorBubble
= $('create-profile-error-bubble');
336 assertTrue(errorBubble
.hidden
);
338 CreateProfileOverlay
.onError('An Error Message!');
339 assertEquals('createProfile', PageManager
.getTopmostVisiblePage().name
);
340 assertFalse(errorBubble
.hidden
);
343 // The name and email should be inserted into the confirmation dialog.
344 TEST_F('ManageProfileUITest', 'CreateConfirmationText', function() {
346 var custodianEmail
= 'foo@example.com';
348 // Checks the strings in the confirmation dialog. If |expectedNameText| is
349 // given, it should be present in the dialog's textContent; otherwise the name
350 // is expected. If |expectedNameHtml| is given, it should be present in the
351 // dialog's innerHTML; otherwise the expected text is expected in the HTML
353 function checkDialog(name
, expectedNameText
, expectedNameHtml
) {
354 var expectedText
= expectedNameText
|| name
;
355 var expectedHtml
= expectedNameHtml
|| expectedText
;
357 // Configure the test profile and show the confirmation dialog.
358 var testProfile
= self
.testProfileInfo_(true);
359 testProfile
.name
= name
;
360 CreateProfileOverlay
.onSuccess(testProfile
);
361 assertEquals('supervisedUserCreateConfirm',
362 PageManager
.getTopmostVisiblePage().name
);
364 // Check for the presence of the name and email in the UI, without depending
365 // on the details of the messages.
367 $('supervised-user-created-title').textContent
.indexOf(expectedText
));
369 $('supervised-user-created-switch').textContent
.indexOf(expectedText
));
370 var message
= $('supervised-user-created-text');
371 assertNotEquals(-1, message
.textContent
.indexOf(expectedText
));
372 assertNotEquals(-1, message
.textContent
.indexOf(custodianEmail
));
374 // The name should be properly HTML-escaped.
375 assertNotEquals(-1, message
.innerHTML
.indexOf(expectedHtml
));
377 PageManager
.closeOverlay();
378 assertEquals('settings', PageManager
.getTopmostVisiblePage().name
, name
);
381 // Show and configure the create-profile dialog.
382 PageManager
.showPageByName('createProfile');
383 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
384 assertEquals('createProfile', PageManager
.getTopmostVisiblePage().name
);
386 checkDialog('OneWord');
387 checkDialog('Multiple Words');
388 checkDialog('It\'s "<HTML> injection" & more!',
389 'It\'s "<HTML> injection" & more!',
390 // The innerHTML getter doesn't escape quotation marks,
391 // independent of whether they were escaped in the setter.
392 'It\'s "<HTML> injection" & more!');
394 // Test elision. MAX_LENGTH = 50, minus 1 for the ellipsis.
395 var name49Characters
= '0123456789012345678901234567890123456789012345678';
396 var name50Characters
= name49Characters
+ '9';
397 var name51Characters
= name50Characters
+ '0';
398 var name60Characters
= name51Characters
+ '123456789';
399 checkDialog(name49Characters
, name49Characters
);
400 checkDialog(name50Characters
, name50Characters
);
401 checkDialog(name51Characters
, name49Characters
+ '\u2026');
402 checkDialog(name60Characters
, name49Characters
+ '\u2026');
404 // Test both elision and HTML escaping. The allowed string length is the
405 // visible length, not the length including the entity names.
406 name49Characters
= name49Characters
.replace('0', '&').replace('1', '>');
407 name60Characters
= name60Characters
.replace('0', '&').replace('1', '>');
408 var escaped
= name49Characters
.replace('&', '&').replace('>', '>');
410 name60Characters
, name49Characters
+ '\u2026', escaped
+ '\u2026');
413 // The confirmation dialog should close if the new supervised user is deleted.
414 TEST_F('ManageProfileUITest', 'CloseConfirmationOnDelete', function() {
415 // Configure the test profile and show the confirmation dialog.
416 var testProfile
= this.testProfileInfo_(true);
417 CreateProfileOverlay
.onSuccess(testProfile
);
418 assertEquals('supervisedUserCreateConfirm',
419 PageManager
.getTopmostVisiblePage().name
);
421 SupervisedUserCreateConfirmOverlay
.onDeletedProfile(testProfile
.filePath
);
422 assertEquals('settings', PageManager
.getTopmostVisiblePage().name
, name
);
425 // The confirmation dialog should update if the new supervised user's name is
427 TEST_F('ManageProfileUITest', 'UpdateConfirmationOnRename', function() {
428 // Configure the test profile and show the confirmation dialog.
429 var testProfile
= this.testProfileInfo_(true);
430 CreateProfileOverlay
.onSuccess(testProfile
);
431 assertEquals('supervisedUserCreateConfirm',
432 PageManager
.getTopmostVisiblePage().name
);
434 var oldName
= testProfile
.name
;
435 var newName
= 'New Name';
436 SupervisedUserCreateConfirmOverlay
.onUpdatedProfileName(testProfile
.filePath
,
438 assertEquals('supervisedUserCreateConfirm',
439 PageManager
.getTopmostVisiblePage().name
);
441 var titleElement
= $('supervised-user-created-title');
442 var switchElement
= $('supervised-user-created-switch');
443 var messageElement
= $('supervised-user-created-text');
445 assertEquals(-1, titleElement
.textContent
.indexOf(oldName
));
446 assertEquals(-1, switchElement
.textContent
.indexOf(oldName
));
447 assertEquals(-1, messageElement
.textContent
.indexOf(oldName
));
449 assertNotEquals(-1, titleElement
.textContent
.indexOf(newName
));
450 assertNotEquals(-1, switchElement
.textContent
.indexOf(newName
));
451 assertNotEquals(-1, messageElement
.textContent
.indexOf(newName
));
454 // An additional warning should be shown when deleting a supervised user.
455 TEST_F('ManageProfileUITest', 'DeleteSupervisedUserWarning', function() {
456 var addendum
= $('delete-supervised-profile-addendum');
458 ManageProfileOverlay
.showDeleteDialog(this.testProfileInfo_(true));
459 assertFalse(addendum
.hidden
);
461 ManageProfileOverlay
.showDeleteDialog(this.testProfileInfo_(false));
462 assertTrue(addendum
.hidden
);
465 // The policy prohibiting supervised users should update the UI dynamically.
466 TEST_F('ManageProfileUITest', 'PolicyDynamicRefresh', function() {
467 ManageProfileOverlay
.getInstance().initializePage();
469 var custodianEmail
= 'chrome.playpen.test@gmail.com';
470 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
471 CreateProfileOverlay
.updateSupervisedUsersAllowed(true);
472 var checkbox
= $('create-profile-supervised');
473 var signInPromo
= $('create-profile-supervised-not-signed-in');
474 var signInLink
= $('create-profile-supervised-sign-in-link');
475 var indicator
= $('create-profile-supervised-indicator');
477 assertFalse(checkbox
.disabled
, 'allowed and signed in');
478 assertTrue(signInPromo
.hidden
, 'allowed and signed in');
479 assertEquals('none', window
.getComputedStyle(indicator
, null).display
,
480 'allowed and signed in');
482 CreateProfileOverlay
.updateSignedInStatus('');
483 CreateProfileOverlay
.updateSupervisedUsersAllowed(true);
484 assertTrue(checkbox
.disabled
, 'allowed, not signed in');
485 assertFalse(signInPromo
.hidden
, 'allowed, not signed in');
486 assertTrue(signInLink
.enabled
, 'allowed, not signed in');
487 assertEquals('none', window
.getComputedStyle(indicator
, null).display
,
488 'allowed, not signed in');
490 CreateProfileOverlay
.updateSignedInStatus('');
491 CreateProfileOverlay
.updateSupervisedUsersAllowed(false);
492 assertTrue(checkbox
.disabled
, 'disallowed, not signed in');
493 assertFalse(signInPromo
.hidden
, 'disallowed, not signed in');
494 assertFalse(signInLink
.enabled
, 'disallowed, not signed in');
495 assertEquals('inline-block', window
.getComputedStyle(indicator
, null).display
,
496 'disallowed, not signed in');
497 assertEquals('policy', indicator
.getAttribute('controlled-by'));
499 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
500 CreateProfileOverlay
.updateSupervisedUsersAllowed(false);
501 assertTrue(checkbox
.disabled
, 'disallowed, signed in');
502 assertTrue(signInPromo
.hidden
, 'disallowed, signed in');
503 assertEquals('inline-block', window
.getComputedStyle(indicator
, null).display
,
504 'disallowed, signed in');
505 assertEquals('policy', indicator
.getAttribute('controlled-by'));
507 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
508 CreateProfileOverlay
.updateSupervisedUsersAllowed(true);
509 assertFalse(checkbox
.disabled
, 're-allowed and signed in');
510 assertTrue(signInPromo
.hidden
, 're-allowed and signed in');
511 assertEquals('none', window
.getComputedStyle(indicator
, null).display
,
512 're-allowed and signed in');
515 // The supervised user checkbox should correctly update its state during profile
516 // creation and afterwards.
517 TEST_F('ManageProfileUITest', 'CreateInProgress', function() {
518 ManageProfileOverlay
.getInstance().initializePage();
520 var custodianEmail
= 'chrome.playpen.test@gmail.com';
521 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
522 CreateProfileOverlay
.updateSupervisedUsersAllowed(true);
523 var checkbox
= $('create-profile-supervised');
524 var signInPromo
= $('create-profile-supervised-not-signed-in');
525 var indicator
= $('create-profile-supervised-indicator');
527 assertFalse(checkbox
.disabled
, 'allowed and signed in');
528 assertTrue(signInPromo
.hidden
, 'allowed and signed in');
529 assertEquals('none', window
.getComputedStyle(indicator
, null).display
,
530 'allowed and signed in');
531 assertFalse(indicator
.hasAttribute('controlled-by'));
533 CreateProfileOverlay
.updateCreateInProgress(true);
534 assertTrue(checkbox
.disabled
, 'creation in progress');
536 // A no-op update to the sign-in status should not change the UI.
537 CreateProfileOverlay
.updateSignedInStatus(custodianEmail
);
538 CreateProfileOverlay
.updateSupervisedUsersAllowed(true);
539 assertTrue(checkbox
.disabled
, 'creation in progress');
541 CreateProfileOverlay
.updateCreateInProgress(false);
542 assertFalse(checkbox
.disabled
, 'creation finished');
545 // Supervised users should be able to open the delete dialog, but not the
547 TEST_F('ManageProfileUITest', 'SupervisedShowCreate', function() {
548 this.setProfileSupervised_(false, 'create');
550 ManageProfileOverlay
.showCreateDialog();
551 assertEquals('createProfile', PageManager
.getTopmostVisiblePage().name
);
552 PageManager
.closeOverlay();
553 assertEquals('settings', PageManager
.getTopmostVisiblePage().name
);
554 ManageProfileOverlay
.showDeleteDialog(this.testProfileInfo_(false));
555 assertEquals('manageProfile', PageManager
.getTopmostVisiblePage().name
);
556 assertFalse($('manage-profile-overlay-delete').hidden
);
557 PageManager
.closeOverlay();
558 assertEquals('settings', PageManager
.getTopmostVisiblePage().name
);
560 this.setProfileSupervised_(true, 'create');
561 ManageProfileOverlay
.showCreateDialog();
562 assertEquals('settings', PageManager
.getTopmostVisiblePage().name
);
563 ManageProfileOverlay
.showDeleteDialog(this.testProfileInfo_(false));
564 assertEquals('manageProfile', PageManager
.getTopmostVisiblePage().name
);
567 // Selecting a different avatar image should update the suggested profile name.
568 TEST_F('ManageProfileUITest', 'Create_NameUpdateOnAvatarSelected', function() {
570 this.initDefaultProfiles_(mode
);
572 var gridEl
= $(mode
+ '-profile-icon-grid');
573 var nameEl
= $(mode
+ '-profile-name');
575 // Select another icon and check that the profile name was updated.
576 assertNotEquals(gridEl
.selectedItem
, this.defaultIconURLs
[0]);
577 gridEl
.selectedItem
= this.defaultIconURLs
[0];
578 expectEquals(this.defaultNames
[0], nameEl
.value
);
580 // Select icon without an associated name; the profile name shouldn't change.
581 var oldName
= nameEl
.value
;
582 assertEquals('', this.defaultNames
[2]);
583 gridEl
.selectedItem
= this.defaultIconURLs
[2];
584 expectEquals(oldName
, nameEl
.value
);
586 // Select another icon with a name and check that the name is updated again.
587 assertNotEquals('', this.defaultNames
[1]);
588 gridEl
.selectedItem
= this.defaultIconURLs
[1];
589 expectEquals(this.defaultNames
[1], nameEl
.value
);
591 PageManager
.closeOverlay();
594 // After the user edited the profile name, selecting a different avatar image
595 // should not update the suggested name anymore.
596 TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterEdit',
599 this.initDefaultProfiles_(mode
);
601 var gridEl
= $(mode
+ '-profile-icon-grid');
602 var nameEl
= $(mode
+ '-profile-name');
604 // After the user manually entered a name, it should not be changed anymore
605 // (even if the entered name is another default name).
606 nameEl
.value
= this.defaultNames
[3];
608 gridEl
.selectedItem
= this.defaultIconURLs
[0];
609 expectEquals(this.defaultNames
[3], nameEl
.value
);
611 PageManager
.closeOverlay();
614 // After the user edited the profile name, selecting a different avatar image
615 // should not update the suggested name anymore even if the original suggestion
617 TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterRevert',
620 this.initDefaultProfiles_(mode
);
622 var gridEl
= $(mode
+ '-profile-icon-grid');
623 var nameEl
= $(mode
+ '-profile-name');
625 // After the user manually entered a name, it should not be changed anymore,
626 // even if the user then reverts to the original suggestion.
627 var oldName
= nameEl
.value
;
628 nameEl
.value
= 'Custom Name';
630 nameEl
.value
= oldName
;
632 // Now select another avatar and check that the name remained the same.
633 assertNotEquals(gridEl
.selectedItem
, this.defaultIconURLs
[0]);
634 gridEl
.selectedItem
= this.defaultIconURLs
[0];
635 expectEquals(oldName
, nameEl
.value
);
637 PageManager
.closeOverlay();
640 // In the manage dialog, the name should never be updated on avatar selection.
641 TEST_F('ManageProfileUITest', 'Manage_NoNameUpdateOnAvatarSelected',
644 this.setProfileSupervised_(false, mode
);
645 PageManager
.showPageByName(mode
+ 'Profile');
647 var testProfile
= this.testProfileInfo_(false);
648 var iconURLs
= [testProfile
.iconURL
, '/some/path', '/another/path'];
649 var names
= [testProfile
.name
, 'Some Name', ''];
650 ManageProfileOverlay
.receiveDefaultProfileIconsAndNames(
651 mode
, iconURLs
, names
);
653 var gridEl
= $(mode
+ '-profile-icon-grid');
654 var nameEl
= $(mode
+ '-profile-name');
656 // Select another icon and check if the profile name was updated.
657 var oldName
= nameEl
.value
;
658 gridEl
.selectedItem
= iconURLs
[1];
659 expectEquals(oldName
, nameEl
.value
);
661 PageManager
.closeOverlay();
664 GEN('#endif // OS_CHROMEOS');