1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
|
// Copyright 2013 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.
// None of these tests is relevant for Chrome OS.
GEN('#if !defined(OS_CHROMEOS)');
/**
* TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing.
* @extends {testing.Test}
* @constructor
*/
function ManageProfileUITest() {}
ManageProfileUITest.prototype = {
__proto__: testing.Test.prototype,
/** @override */
browsePreload: 'chrome://settings-frame/manageProfile',
/**
* No need to run these for every OptionsPage test, since they'll cover the
* whole consolidated page each time.
* @override
*/
runAccessibilityChecks: false,
/**
* Some default profile infos.
*/
defaultIconURLs: [],
defaultNames: [],
/**
* Returns a test profile-info object with configurable "supervised" status.
* @param {boolean} supervised If true, the test profile will be marked as
* supervised.
* @return {Object} A test profile-info object.
*/
testProfileInfo_: function(supervised) {
return {
name: 'Test Profile',
iconURL: 'chrome://path/to/icon/image',
filePath: '/path/to/profile/data/on/disk',
isCurrentProfile: true,
isSupervised: supervised
};
},
/**
* Overrides WebUI methods that provide profile info, making them return a
* test profile-info object.
* @param {boolean} supervised Whether the test profile should be marked
* as supervised.
* @param {string} mode The mode of the overlay (either 'manage' or 'create').
*/
setProfileSupervised_: function(supervised, mode) {
// Override the BrowserOptions method to return the fake info.
BrowserOptions.getCurrentProfile = function() {
return this.testProfileInfo_(supervised);
}.bind(this);
// Set the profile info in the overlay.
ManageProfileOverlay.setProfileInfo(this.testProfileInfo_(supervised),
mode);
},
/**
* Set some default profile infos (icon URLs and names).
* @param {boolean} supervised Whether the test profile should be marked as
* supervised.
* @param {string} mode The mode of the overlay (either 'manage' or 'create').
*/
initDefaultProfiles_: function(mode) {
PageManager.showPageByName(mode + 'Profile');
var defaultProfile = {
name: 'Default Name',
iconURL: '/default/path',
};
this.defaultIconURLs = ['/some/path',
defaultProfile.iconURL,
'/another/path',
'/one/more/path'];
this.defaultNames = ['Some Name', defaultProfile.name, '', 'Another Name'];
ManageProfileOverlay.receiveDefaultProfileIconsAndNames(
mode, this.defaultIconURLs, this.defaultNames);
ManageProfileOverlay.receiveNewProfileDefaults(defaultProfile);
// Make sure the correct item in the icon grid was selected.
var gridEl = $(mode + '-profile-icon-grid');
expectEquals(defaultProfile.iconURL, gridEl.selectedItem);
},
};
// Receiving the new profile defaults in the manage-user overlay shouldn't mess
// up the focus in a visible higher-level overlay.
TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() {
var self = this;
function checkFocus(pageName, expectedFocus, initialFocus) {
PageManager.showPageByName(pageName);
initialFocus.focus();
expectEquals(initialFocus, document.activeElement, pageName);
ManageProfileOverlay.receiveNewProfileDefaults(
self.testProfileInfo_(false));
expectEquals(expectedFocus, document.activeElement, pageName);
PageManager.closeOverlay();
}
// Receiving new profile defaults sets focus to the name field if the create
// overlay is open, and should not change focus at all otherwise.
checkFocus('manageProfile',
$('manage-profile-cancel'),
$('manage-profile-cancel'));
checkFocus('createProfile',
$('create-profile-name'),
$('create-profile-cancel'));
checkFocus('supervisedUserLearnMore',
$('supervised-user-learn-more-done'),
$('supervised-user-learn-more-done'));
checkFocus('supervisedUserLearnMore',
document.querySelector('#supervised-user-learn-more-text a'),
document.querySelector('#supervised-user-learn-more-text a'));
});
// The default options should be reset each time the creation overlay is shown.
TEST_F('ManageProfileUITest', 'DefaultCreateOptions', function() {
PageManager.showPageByName('createProfile');
var shortcutsAllowed = loadTimeData.getBoolean('profileShortcutsEnabled');
var createShortcut = $('create-shortcut');
var createSupervised = $('create-profile-supervised');
assertEquals(shortcutsAllowed, createShortcut.checked);
assertFalse(createSupervised.checked);
createShortcut.checked = !shortcutsAllowed;
createSupervised.checked = true;
PageManager.closeOverlay();
PageManager.showPageByName('createProfile');
assertEquals(shortcutsAllowed, createShortcut.checked);
assertFalse(createSupervised.checked);
});
// The checkbox label should change depending on whether the user is signed in.
TEST_F('ManageProfileUITest', 'CreateSupervisedUserText', function() {
var signedInText = $('create-profile-supervised-signed-in');
var notSignedInText = $('create-profile-supervised-not-signed-in');
ManageProfileOverlay.getInstance().initializePage();
var custodianEmail = 'chrome.playpen.test@gmail.com';
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
assertEquals(custodianEmail,
CreateProfileOverlay.getInstance().signedInEmail_);
assertFalse(signedInText.hidden);
assertTrue(notSignedInText.hidden);
// Make sure the email is in the string somewhere, without depending on the
// exact details of the message.
assertNotEquals(-1, signedInText.textContent.indexOf(custodianEmail));
CreateProfileOverlay.updateSignedInStatus('');
assertEquals('', CreateProfileOverlay.getInstance().signedInEmail_);
assertTrue(signedInText.hidden);
assertFalse(notSignedInText.hidden);
assertFalse($('create-profile-supervised').checked);
assertTrue($('create-profile-supervised').disabled);
});
function ManageProfileUITestAsync() {}
ManageProfileUITestAsync.prototype = {
__proto__: ManageProfileUITest.prototype,
isAsync: true,
};
// The import link should show up if the user tries to create a profile with the
// same name as an existing supervised user profile.
TEST_F('ManageProfileUITestAsync', 'CreateExistingSupervisedUser', function() {
// Initialize the list of existing supervised users.
var supervisedUsers = [
{
id: 'supervisedUser1',
name: 'Rosalie',
iconURL: 'chrome://path/to/icon/image',
onCurrentDevice: false,
needAvatar: false
},
{
id: 'supervisedUser2',
name: 'Fritz',
iconURL: 'chrome://path/to/icon/image',
onCurrentDevice: false,
needAvatar: true
},
{
id: 'supervisedUser3',
name: 'Test',
iconURL: 'chrome://path/to/icon/image',
onCurrentDevice: true,
needAvatar: false
},
{
id: 'supervisedUser4',
name: 'SameName',
iconURL: 'chrome://path/to/icon/image',
onCurrentDevice: false,
needAvatar: false
}];
var promise = Promise.resolve(supervisedUsers);
options.SupervisedUserListData.getInstance().promise_ = promise;
// Initialize the ManageProfileOverlay.
ManageProfileOverlay.getInstance().initializePage();
var custodianEmail = 'chrome.playpen.test@gmail.com';
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
assertEquals(custodianEmail,
CreateProfileOverlay.getInstance().signedInEmail_);
this.setProfileSupervised_(false, 'create');
// Also add the names 'Test' and 'SameName' to |existingProfileNames_| to
// simulate that profiles with those names exist on the device.
ManageProfileOverlay.getInstance().existingProfileNames_.Test = true;
ManageProfileOverlay.getInstance().existingProfileNames_.SameName = true;
// Initially, the ok button should be enabled and the import link should not
// exist.
assertFalse($('create-profile-ok').disabled);
assertTrue($('supervised-user-import-existing') == null);
// Now try to create profiles with the names of existing supervised users.
$('create-profile-supervised').checked = true;
var nameField = $('create-profile-name');
// A profile which already has an avatar.
nameField.value = 'Rosalie';
ManageProfileOverlay.getInstance().onNameChanged_('create');
// Need to wait until the promise resolves.
promise.then(function() {
assertTrue($('create-profile-ok').disabled);
assertFalse($('supervised-user-import-existing') == null);
// A profile which doesn't have an avatar yet.
nameField.value = 'Fritz';
ManageProfileOverlay.getInstance().onNameChanged_('create');
return options.SupervisedUserListData.getInstance().promise_;
}).then(function() {
assertTrue($('create-profile-ok').disabled);
assertFalse($('supervised-user-import-existing') == null);
// A profile which already exists on the device.
nameField.value = 'Test';
ManageProfileOverlay.getInstance().onNameChanged_('create');
return options.SupervisedUserListData.getInstance().promise_;
}).then(function() {
assertFalse($('create-profile-ok').disabled);
assertTrue($('supervised-user-import-existing') == null);
// A profile which does not exist on the device, but there is a profile with
// the same name already on the device.
nameField.value = 'SameName';
ManageProfileOverlay.getInstance().onNameChanged_('create');
return options.SupervisedUserListData.getInstance().promise_;
}).then(function() {
assertTrue($('create-profile-ok').disabled);
assertFalse($('supervised-user-import-existing') == null);
// A profile which does not exist yet.
nameField.value = 'NewProfileName';
ManageProfileOverlay.getInstance().onNameChanged_('create');
return options.SupervisedUserListData.getInstance().promise_;
}).then(function() {
assertFalse($('create-profile-ok').disabled);
assertTrue($('supervised-user-import-existing') == null);
testDone();
});
});
// Supervised users should not be able to edit their profile names, and the
// initial focus should be adjusted accordingly.
TEST_F('ManageProfileUITest', 'EditSupervisedUserNameAllowed', function() {
var nameField = $('manage-profile-name');
this.setProfileSupervised_(false, 'manage');
ManageProfileOverlay.showManageDialog();
expectFalse(nameField.disabled);
expectEquals(nameField, document.activeElement);
PageManager.closeOverlay();
this.setProfileSupervised_(true, 'manage');
ManageProfileOverlay.showManageDialog();
expectTrue(nameField.disabled);
expectEquals($('manage-profile-ok'), document.activeElement);
});
// Setting profile information should allow the confirmation to be shown.
TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() {
var testProfile = this.testProfileInfo_(true);
testProfile.custodianEmail = 'foo@bar.example.com';
SupervisedUserCreateConfirmOverlay.setProfileInfo(testProfile);
assertTrue(SupervisedUserCreateConfirmOverlay.getInstance().canShowPage());
PageManager.showPageByName('supervisedUserCreateConfirm', false);
assertEquals('supervisedUserCreateConfirm',
PageManager.getTopmostVisiblePage().name);
});
// Trying to show a confirmation dialog with no profile information should fall
// back to the default (main) settings page.
TEST_F('ManageProfileUITest', 'NoEmptyConfirmation', function() {
assertEquals('manageProfile', PageManager.getTopmostVisiblePage().name);
assertFalse(SupervisedUserCreateConfirmOverlay.getInstance().canShowPage());
PageManager.showPageByName('supervisedUserCreateConfirm', true);
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
});
// A confirmation dialog should be shown after creating a new supervised user.
TEST_F('ManageProfileUITest', 'ShowCreateConfirmationOnSuccess', function() {
PageManager.showPageByName('createProfile');
assertEquals('createProfile', PageManager.getTopmostVisiblePage().name);
CreateProfileOverlay.onSuccess(this.testProfileInfo_(false));
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
PageManager.showPageByName('createProfile');
assertEquals('createProfile', PageManager.getTopmostVisiblePage().name);
CreateProfileOverlay.onSuccess(this.testProfileInfo_(true));
assertEquals('supervisedUserCreateConfirm',
PageManager.getTopmostVisiblePage().name);
expectEquals($('supervised-user-created-switch'), document.activeElement);
});
// An error should be shown if creating a new supervised user fails.
TEST_F('ManageProfileUITest', 'NoCreateConfirmationOnError', function() {
PageManager.showPageByName('createProfile');
assertEquals('createProfile', PageManager.getTopmostVisiblePage().name);
var errorBubble = $('create-profile-error-bubble');
assertTrue(errorBubble.hidden);
CreateProfileOverlay.onError('An Error Message!');
assertEquals('createProfile', PageManager.getTopmostVisiblePage().name);
assertFalse(errorBubble.hidden);
});
// The name and email should be inserted into the confirmation dialog.
TEST_F('ManageProfileUITest', 'CreateConfirmationText', function() {
var self = this;
var custodianEmail = 'foo@example.com';
// Checks the strings in the confirmation dialog. If |expectedNameText| is
// given, it should be present in the dialog's textContent; otherwise the name
// is expected. If |expectedNameHtml| is given, it should be present in the
// dialog's innerHTML; otherwise the expected text is expected in the HTML
// too.
function checkDialog(name, expectedNameText, expectedNameHtml) {
var expectedText = expectedNameText || name;
var expectedHtml = expectedNameHtml || expectedText;
// Configure the test profile and show the confirmation dialog.
var testProfile = self.testProfileInfo_(true);
testProfile.name = name;
CreateProfileOverlay.onSuccess(testProfile);
assertEquals('supervisedUserCreateConfirm',
PageManager.getTopmostVisiblePage().name);
// Check for the presence of the name and email in the UI, without depending
// on the details of the messages.
assertNotEquals(-1,
$('supervised-user-created-title').textContent.indexOf(expectedText));
assertNotEquals(-1,
$('supervised-user-created-switch').textContent.indexOf(expectedText));
var message = $('supervised-user-created-text');
assertNotEquals(-1, message.textContent.indexOf(expectedText));
assertNotEquals(-1, message.textContent.indexOf(custodianEmail));
// The name should be properly HTML-escaped.
assertNotEquals(-1, message.innerHTML.indexOf(expectedHtml));
PageManager.closeOverlay();
assertEquals('settings', PageManager.getTopmostVisiblePage().name, name);
}
// Show and configure the create-profile dialog.
PageManager.showPageByName('createProfile');
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
assertEquals('createProfile', PageManager.getTopmostVisiblePage().name);
checkDialog('OneWord');
checkDialog('Multiple Words');
checkDialog('It\'s "<HTML> injection" & more!',
'It\'s "<HTML> injection" & more!',
// The innerHTML getter doesn't escape quotation marks,
// independent of whether they were escaped in the setter.
'It\'s "<HTML> injection" & more!');
// Test elision. MAX_LENGTH = 50, minus 1 for the ellipsis.
var name49Characters = '0123456789012345678901234567890123456789012345678';
var name50Characters = name49Characters + '9';
var name51Characters = name50Characters + '0';
var name60Characters = name51Characters + '123456789';
checkDialog(name49Characters, name49Characters);
checkDialog(name50Characters, name50Characters);
checkDialog(name51Characters, name49Characters + '\u2026');
checkDialog(name60Characters, name49Characters + '\u2026');
// Test both elision and HTML escaping. The allowed string length is the
// visible length, not the length including the entity names.
name49Characters = name49Characters.replace('0', '&').replace('1', '>');
name60Characters = name60Characters.replace('0', '&').replace('1', '>');
var escaped = name49Characters.replace('&', '&').replace('>', '>');
checkDialog(
name60Characters, name49Characters + '\u2026', escaped + '\u2026');
});
// An additional warning should be shown when deleting a supervised user.
TEST_F('ManageProfileUITest', 'DeleteSupervisedUserWarning', function() {
var addendum = $('delete-supervised-profile-addendum');
ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(true));
assertFalse(addendum.hidden);
ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
assertTrue(addendum.hidden);
});
// The policy prohibiting supervised users should update the UI dynamically.
TEST_F('ManageProfileUITest', 'PolicyDynamicRefresh', function() {
ManageProfileOverlay.getInstance().initializePage();
var custodianEmail = 'chrome.playpen.test@gmail.com';
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
CreateProfileOverlay.updateSupervisedUsersAllowed(true);
var checkbox = $('create-profile-supervised');
var signInPromo = $('create-profile-supervised-not-signed-in');
var signInLink = $('create-profile-supervised-sign-in-link');
var indicator = $('create-profile-supervised-indicator');
assertFalse(checkbox.disabled, 'allowed and signed in');
assertTrue(signInPromo.hidden, 'allowed and signed in');
assertEquals('none', window.getComputedStyle(indicator, null).display,
'allowed and signed in');
CreateProfileOverlay.updateSignedInStatus('');
CreateProfileOverlay.updateSupervisedUsersAllowed(true);
assertTrue(checkbox.disabled, 'allowed, not signed in');
assertFalse(signInPromo.hidden, 'allowed, not signed in');
assertTrue(signInLink.enabled, 'allowed, not signed in');
assertEquals('none', window.getComputedStyle(indicator, null).display,
'allowed, not signed in');
CreateProfileOverlay.updateSignedInStatus('');
CreateProfileOverlay.updateSupervisedUsersAllowed(false);
assertTrue(checkbox.disabled, 'disallowed, not signed in');
assertFalse(signInPromo.hidden, 'disallowed, not signed in');
assertFalse(signInLink.enabled, 'disallowed, not signed in');
assertEquals('inline-block', window.getComputedStyle(indicator, null).display,
'disallowed, not signed in');
assertEquals('policy', indicator.getAttribute('controlled-by'));
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
CreateProfileOverlay.updateSupervisedUsersAllowed(false);
assertTrue(checkbox.disabled, 'disallowed, signed in');
assertTrue(signInPromo.hidden, 'disallowed, signed in');
assertEquals('inline-block', window.getComputedStyle(indicator, null).display,
'disallowed, signed in');
assertEquals('policy', indicator.getAttribute('controlled-by'));
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
CreateProfileOverlay.updateSupervisedUsersAllowed(true);
assertFalse(checkbox.disabled, 're-allowed and signed in');
assertTrue(signInPromo.hidden, 're-allowed and signed in');
assertEquals('none', window.getComputedStyle(indicator, null).display,
're-allowed and signed in');
});
// The supervised user checkbox should correctly update its state during profile
// creation and afterwards.
TEST_F('ManageProfileUITest', 'CreateInProgress', function() {
ManageProfileOverlay.getInstance().initializePage();
var custodianEmail = 'chrome.playpen.test@gmail.com';
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
CreateProfileOverlay.updateSupervisedUsersAllowed(true);
var checkbox = $('create-profile-supervised');
var signInPromo = $('create-profile-supervised-not-signed-in');
var indicator = $('create-profile-supervised-indicator');
assertFalse(checkbox.disabled, 'allowed and signed in');
assertTrue(signInPromo.hidden, 'allowed and signed in');
assertEquals('none', window.getComputedStyle(indicator, null).display,
'allowed and signed in');
assertFalse(indicator.hasAttribute('controlled-by'));
CreateProfileOverlay.updateCreateInProgress(true);
assertTrue(checkbox.disabled, 'creation in progress');
// A no-op update to the sign-in status should not change the UI.
CreateProfileOverlay.updateSignedInStatus(custodianEmail);
CreateProfileOverlay.updateSupervisedUsersAllowed(true);
assertTrue(checkbox.disabled, 'creation in progress');
CreateProfileOverlay.updateCreateInProgress(false);
assertFalse(checkbox.disabled, 'creation finished');
});
// Supervised users shouldn't be able to open the delete or create dialogs.
TEST_F('ManageProfileUITest', 'SupervisedShowDeleteAndCreate', function() {
this.setProfileSupervised_(false, 'create');
ManageProfileOverlay.showCreateDialog();
assertEquals('createProfile', PageManager.getTopmostVisiblePage().name);
PageManager.closeOverlay();
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
assertEquals('manageProfile', PageManager.getTopmostVisiblePage().name);
assertFalse($('manage-profile-overlay-delete').hidden);
PageManager.closeOverlay();
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
this.setProfileSupervised_(true, 'create');
ManageProfileOverlay.showCreateDialog();
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
});
// Only non-supervised users should be able to delete profiles.
TEST_F('ManageProfileUITest', 'SupervisedDelete', function() {
ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
assertEquals('manageProfile', PageManager.getTopmostVisiblePage().name);
assertFalse($('manage-profile-overlay-delete').hidden);
// Clicks the "Delete" button, after overriding chrome.send to record what
// messages were sent.
function clickAndListen() {
var originalChromeSend = chrome.send;
var chromeSendMessages = [];
chrome.send = function(message) {
chromeSendMessages.push(message);
};
$('delete-profile-ok').onclick();
// Restore the original function so the test framework can use it.
chrome.send = originalChromeSend;
return chromeSendMessages;
}
this.setProfileSupervised_(false, 'manage');
var messages = clickAndListen();
assertEquals(1, messages.length);
assertEquals('deleteProfile', messages[0]);
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
this.setProfileSupervised_(true, 'manage');
messages = clickAndListen();
assertEquals(0, messages.length);
assertEquals('settings', PageManager.getTopmostVisiblePage().name);
});
// Selecting a different avatar image should update the suggested profile name.
TEST_F('ManageProfileUITest', 'Create_NameUpdateOnAvatarSelected', function() {
var mode = 'create';
this.initDefaultProfiles_(mode);
var gridEl = $(mode + '-profile-icon-grid');
var nameEl = $(mode + '-profile-name');
// Select another icon and check that the profile name was updated.
assertNotEquals(gridEl.selectedItem, this.defaultIconURLs[0]);
gridEl.selectedItem = this.defaultIconURLs[0];
expectEquals(this.defaultNames[0], nameEl.value);
// Select icon without an associated name; the profile name shouldn't change.
var oldName = nameEl.value;
assertEquals('', this.defaultNames[2]);
gridEl.selectedItem = this.defaultIconURLs[2];
expectEquals(oldName, nameEl.value);
// Select another icon with a name and check that the name is updated again.
assertNotEquals('', this.defaultNames[1]);
gridEl.selectedItem = this.defaultIconURLs[1];
expectEquals(this.defaultNames[1], nameEl.value);
PageManager.closeOverlay();
});
// After the user edited the profile name, selecting a different avatar image
// should not update the suggested name anymore.
TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterEdit',
function() {
var mode = 'create';
this.initDefaultProfiles_(mode);
var gridEl = $(mode + '-profile-icon-grid');
var nameEl = $(mode + '-profile-name');
// After the user manually entered a name, it should not be changed anymore
// (even if the entered name is another default name).
nameEl.value = this.defaultNames[3];
nameEl.oninput();
gridEl.selectedItem = this.defaultIconURLs[0];
expectEquals(this.defaultNames[3], nameEl.value);
PageManager.closeOverlay();
});
// After the user edited the profile name, selecting a different avatar image
// should not update the suggested name anymore even if the original suggestion
// is entered again.
TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterRevert',
function() {
var mode = 'create';
this.initDefaultProfiles_(mode);
var gridEl = $(mode + '-profile-icon-grid');
var nameEl = $(mode + '-profile-name');
// After the user manually entered a name, it should not be changed anymore,
// even if the user then reverts to the original suggestion.
var oldName = nameEl.value;
nameEl.value = 'Custom Name';
nameEl.oninput();
nameEl.value = oldName;
nameEl.oninput();
// Now select another avatar and check that the name remained the same.
assertNotEquals(gridEl.selectedItem, this.defaultIconURLs[0]);
gridEl.selectedItem = this.defaultIconURLs[0];
expectEquals(oldName, nameEl.value);
PageManager.closeOverlay();
});
// In the manage dialog, the name should never be updated on avatar selection.
TEST_F('ManageProfileUITest', 'Manage_NoNameUpdateOnAvatarSelected',
function() {
var mode = 'manage';
this.setProfileSupervised_(false, mode);
PageManager.showPageByName(mode + 'Profile');
var testProfile = this.testProfileInfo_(false);
var iconURLs = [testProfile.iconURL, '/some/path', '/another/path'];
var names = [testProfile.name, 'Some Name', ''];
ManageProfileOverlay.receiveDefaultProfileIconsAndNames(
mode, iconURLs, names);
var gridEl = $(mode + '-profile-icon-grid');
var nameEl = $(mode + '-profile-name');
// Select another icon and check if the profile name was updated.
var oldName = nameEl.value;
gridEl.selectedItem = iconURLs[1];
expectEquals(oldName, nameEl.value);
PageManager.closeOverlay();
});
GEN('#endif // OS_CHROMEOS');
|