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