| OLD | NEW |
| 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 /** | 8 /** |
| 9 * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing. | 9 * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing. |
| 10 * @extends {testing.Test} | 10 * @extends {testing.Test} |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 mode); | 64 mode); |
| 65 }, | 65 }, |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Set some default profile infos (icon URLs and names). | 68 * Set some default profile infos (icon URLs and names). |
| 69 * @param {boolean} supervised Whether the test profile should be marked as | 69 * @param {boolean} supervised Whether the test profile should be marked as |
| 70 * supervised. | 70 * supervised. |
| 71 * @param {string} mode The mode of the overlay (either 'manage' or 'create'). | 71 * @param {string} mode The mode of the overlay (either 'manage' or 'create'). |
| 72 */ | 72 */ |
| 73 initDefaultProfiles_: function(mode) { | 73 initDefaultProfiles_: function(mode) { |
| 74 OptionsPage.showPageByName(mode + 'Profile'); | 74 PageManager.showPageByName(mode + 'Profile'); |
| 75 | 75 |
| 76 var defaultProfile = { | 76 var defaultProfile = { |
| 77 name: 'Default Name', | 77 name: 'Default Name', |
| 78 iconURL: '/default/path', | 78 iconURL: '/default/path', |
| 79 }; | 79 }; |
| 80 this.defaultIconURLs = ['/some/path', | 80 this.defaultIconURLs = ['/some/path', |
| 81 defaultProfile.iconURL, | 81 defaultProfile.iconURL, |
| 82 '/another/path', | 82 '/another/path', |
| 83 '/one/more/path']; | 83 '/one/more/path']; |
| 84 this.defaultNames = ['Some Name', defaultProfile.name, '', 'Another Name']; | 84 this.defaultNames = ['Some Name', defaultProfile.name, '', 'Another Name']; |
| 85 ManageProfileOverlay.receiveDefaultProfileIconsAndNames( | 85 ManageProfileOverlay.receiveDefaultProfileIconsAndNames( |
| 86 mode, this.defaultIconURLs, this.defaultNames); | 86 mode, this.defaultIconURLs, this.defaultNames); |
| 87 ManageProfileOverlay.receiveNewProfileDefaults(defaultProfile); | 87 ManageProfileOverlay.receiveNewProfileDefaults(defaultProfile); |
| 88 | 88 |
| 89 // Make sure the correct item in the icon grid was selected. | 89 // Make sure the correct item in the icon grid was selected. |
| 90 var gridEl = $(mode + '-profile-icon-grid'); | 90 var gridEl = $(mode + '-profile-icon-grid'); |
| 91 expectEquals(defaultProfile.iconURL, gridEl.selectedItem); | 91 expectEquals(defaultProfile.iconURL, gridEl.selectedItem); |
| 92 }, | 92 }, |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 // Receiving the new profile defaults in the manage-user overlay shouldn't mess | 95 // Receiving the new profile defaults in the manage-user overlay shouldn't mess |
| 96 // up the focus in a visible higher-level overlay. | 96 // up the focus in a visible higher-level overlay. |
| 97 TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() { | 97 TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() { |
| 98 var self = this; | 98 var self = this; |
| 99 | 99 |
| 100 function checkFocus(pageName, expectedFocus, initialFocus) { | 100 function checkFocus(pageName, expectedFocus, initialFocus) { |
| 101 OptionsPage.showPageByName(pageName); | 101 PageManager.showPageByName(pageName); |
| 102 initialFocus.focus(); | 102 initialFocus.focus(); |
| 103 expectEquals(initialFocus, document.activeElement, pageName); | 103 expectEquals(initialFocus, document.activeElement, pageName); |
| 104 | 104 |
| 105 ManageProfileOverlay.receiveNewProfileDefaults( | 105 ManageProfileOverlay.receiveNewProfileDefaults( |
| 106 self.testProfileInfo_(false)); | 106 self.testProfileInfo_(false)); |
| 107 expectEquals(expectedFocus, document.activeElement, pageName); | 107 expectEquals(expectedFocus, document.activeElement, pageName); |
| 108 OptionsPage.closeOverlay(); | 108 PageManager.closeOverlay(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Receiving new profile defaults sets focus to the name field if the create | 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. | 112 // overlay is open, and should not change focus at all otherwise. |
| 113 checkFocus('manageProfile', | 113 checkFocus('manageProfile', |
| 114 $('manage-profile-cancel'), | 114 $('manage-profile-cancel'), |
| 115 $('manage-profile-cancel')); | 115 $('manage-profile-cancel')); |
| 116 checkFocus('createProfile', | 116 checkFocus('createProfile', |
| 117 $('create-profile-name'), | 117 $('create-profile-name'), |
| 118 $('create-profile-cancel')); | 118 $('create-profile-cancel')); |
| 119 checkFocus('supervisedUserLearnMore', | 119 checkFocus('supervisedUserLearnMore', |
| 120 $('supervised-user-learn-more-done'), | 120 $('supervised-user-learn-more-done'), |
| 121 $('supervised-user-learn-more-done')); | 121 $('supervised-user-learn-more-done')); |
| 122 checkFocus('supervisedUserLearnMore', | 122 checkFocus('supervisedUserLearnMore', |
| 123 document.querySelector('#supervised-user-learn-more-text a'), | 123 document.querySelector('#supervised-user-learn-more-text a'), |
| 124 document.querySelector('#supervised-user-learn-more-text a')); | 124 document.querySelector('#supervised-user-learn-more-text a')); |
| 125 }); | 125 }); |
| 126 | 126 |
| 127 // The default options should be reset each time the creation overlay is shown. | 127 // The default options should be reset each time the creation overlay is shown. |
| 128 TEST_F('ManageProfileUITest', 'DefaultCreateOptions', function() { | 128 TEST_F('ManageProfileUITest', 'DefaultCreateOptions', function() { |
| 129 OptionsPage.showPageByName('createProfile'); | 129 PageManager.showPageByName('createProfile'); |
| 130 var shortcutsAllowed = loadTimeData.getBoolean('profileShortcutsEnabled'); | 130 var shortcutsAllowed = loadTimeData.getBoolean('profileShortcutsEnabled'); |
| 131 var createShortcut = $('create-shortcut'); | 131 var createShortcut = $('create-shortcut'); |
| 132 var createSupervised = $('create-profile-supervised'); | 132 var createSupervised = $('create-profile-supervised'); |
| 133 assertEquals(shortcutsAllowed, createShortcut.checked); | 133 assertEquals(shortcutsAllowed, createShortcut.checked); |
| 134 assertFalse(createSupervised.checked); | 134 assertFalse(createSupervised.checked); |
| 135 | 135 |
| 136 createShortcut.checked = !shortcutsAllowed; | 136 createShortcut.checked = !shortcutsAllowed; |
| 137 createSupervised.checked = true; | 137 createSupervised.checked = true; |
| 138 OptionsPage.closeOverlay(); | 138 PageManager.closeOverlay(); |
| 139 OptionsPage.showPageByName('createProfile'); | 139 PageManager.showPageByName('createProfile'); |
| 140 assertEquals(shortcutsAllowed, createShortcut.checked); | 140 assertEquals(shortcutsAllowed, createShortcut.checked); |
| 141 assertFalse(createSupervised.checked); | 141 assertFalse(createSupervised.checked); |
| 142 }); | 142 }); |
| 143 | 143 |
| 144 // The checkbox label should change depending on whether the user is signed in. | 144 // The checkbox label should change depending on whether the user is signed in. |
| 145 TEST_F('ManageProfileUITest', 'CreateSupervisedUserText', function() { | 145 TEST_F('ManageProfileUITest', 'CreateSupervisedUserText', function() { |
| 146 var signedInText = $('create-profile-supervised-signed-in'); | 146 var signedInText = $('create-profile-supervised-signed-in'); |
| 147 var notSignedInText = $('create-profile-supervised-not-signed-in'); | 147 var notSignedInText = $('create-profile-supervised-not-signed-in'); |
| 148 | 148 |
| 149 ManageProfileOverlay.getInstance().initializePage(); | 149 ManageProfileOverlay.getInstance().initializePage(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // Supervised users should not be able to edit their profile names, and the | 278 // Supervised users should not be able to edit their profile names, and the |
| 279 // initial focus should be adjusted accordingly. | 279 // initial focus should be adjusted accordingly. |
| 280 TEST_F('ManageProfileUITest', 'EditSupervisedUserNameAllowed', function() { | 280 TEST_F('ManageProfileUITest', 'EditSupervisedUserNameAllowed', function() { |
| 281 var nameField = $('manage-profile-name'); | 281 var nameField = $('manage-profile-name'); |
| 282 | 282 |
| 283 this.setProfileSupervised_(false, 'manage'); | 283 this.setProfileSupervised_(false, 'manage'); |
| 284 ManageProfileOverlay.showManageDialog(); | 284 ManageProfileOverlay.showManageDialog(); |
| 285 expectFalse(nameField.disabled); | 285 expectFalse(nameField.disabled); |
| 286 expectEquals(nameField, document.activeElement); | 286 expectEquals(nameField, document.activeElement); |
| 287 | 287 |
| 288 OptionsPage.closeOverlay(); | 288 PageManager.closeOverlay(); |
| 289 | 289 |
| 290 this.setProfileSupervised_(true, 'manage'); | 290 this.setProfileSupervised_(true, 'manage'); |
| 291 ManageProfileOverlay.showManageDialog(); | 291 ManageProfileOverlay.showManageDialog(); |
| 292 expectTrue(nameField.disabled); | 292 expectTrue(nameField.disabled); |
| 293 expectEquals($('manage-profile-ok'), document.activeElement); | 293 expectEquals($('manage-profile-ok'), document.activeElement); |
| 294 }); | 294 }); |
| 295 | 295 |
| 296 // Setting profile information should allow the confirmation to be shown. | 296 // Setting profile information should allow the confirmation to be shown. |
| 297 TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() { | 297 TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() { |
| 298 var testProfile = this.testProfileInfo_(true); | 298 var testProfile = this.testProfileInfo_(true); |
| 299 testProfile.custodianEmail = 'foo@bar.example.com'; | 299 testProfile.custodianEmail = 'foo@bar.example.com'; |
| 300 SupervisedUserCreateConfirmOverlay.setProfileInfo(testProfile); | 300 SupervisedUserCreateConfirmOverlay.setProfileInfo(testProfile); |
| 301 assertTrue(SupervisedUserCreateConfirmOverlay.getInstance().canShowPage()); | 301 assertTrue(SupervisedUserCreateConfirmOverlay.getInstance().canShowPage()); |
| 302 OptionsPage.showPageByName('supervisedUserCreateConfirm', false); | 302 PageManager.showPageByName('supervisedUserCreateConfirm', false); |
| 303 assertEquals('supervisedUserCreateConfirm', | 303 assertEquals('supervisedUserCreateConfirm', |
| 304 OptionsPage.getTopmostVisiblePage().name); | 304 PageManager.getTopmostVisiblePage().name); |
| 305 }); | 305 }); |
| 306 | 306 |
| 307 // Trying to show a confirmation dialog with no profile information should fall | 307 // Trying to show a confirmation dialog with no profile information should fall |
| 308 // back to the default (main) settings page. | 308 // back to the default (main) settings page. |
| 309 TEST_F('ManageProfileUITest', 'NoEmptyConfirmation', function() { | 309 TEST_F('ManageProfileUITest', 'NoEmptyConfirmation', function() { |
| 310 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); | 310 assertEquals('manageProfile', PageManager.getTopmostVisiblePage().name); |
| 311 assertFalse(SupervisedUserCreateConfirmOverlay.getInstance().canShowPage()); | 311 assertFalse(SupervisedUserCreateConfirmOverlay.getInstance().canShowPage()); |
| 312 OptionsPage.showPageByName('supervisedUserCreateConfirm', true); | 312 PageManager.showPageByName('supervisedUserCreateConfirm', true); |
| 313 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 313 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 314 }); | 314 }); |
| 315 | 315 |
| 316 // A confirmation dialog should be shown after creating a new supervised user. | 316 // A confirmation dialog should be shown after creating a new supervised user. |
| 317 TEST_F('ManageProfileUITest', 'ShowCreateConfirmationOnSuccess', function() { | 317 TEST_F('ManageProfileUITest', 'ShowCreateConfirmationOnSuccess', function() { |
| 318 OptionsPage.showPageByName('createProfile'); | 318 PageManager.showPageByName('createProfile'); |
| 319 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 319 assertEquals('createProfile', PageManager.getTopmostVisiblePage().name); |
| 320 CreateProfileOverlay.onSuccess(this.testProfileInfo_(false)); | 320 CreateProfileOverlay.onSuccess(this.testProfileInfo_(false)); |
| 321 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 321 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 322 | 322 |
| 323 OptionsPage.showPageByName('createProfile'); | 323 PageManager.showPageByName('createProfile'); |
| 324 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 324 assertEquals('createProfile', PageManager.getTopmostVisiblePage().name); |
| 325 CreateProfileOverlay.onSuccess(this.testProfileInfo_(true)); | 325 CreateProfileOverlay.onSuccess(this.testProfileInfo_(true)); |
| 326 assertEquals('supervisedUserCreateConfirm', | 326 assertEquals('supervisedUserCreateConfirm', |
| 327 OptionsPage.getTopmostVisiblePage().name); | 327 PageManager.getTopmostVisiblePage().name); |
| 328 expectEquals($('supervised-user-created-switch'), document.activeElement); | 328 expectEquals($('supervised-user-created-switch'), document.activeElement); |
| 329 }); | 329 }); |
| 330 | 330 |
| 331 // An error should be shown if creating a new supervised user fails. | 331 // An error should be shown if creating a new supervised user fails. |
| 332 TEST_F('ManageProfileUITest', 'NoCreateConfirmationOnError', function() { | 332 TEST_F('ManageProfileUITest', 'NoCreateConfirmationOnError', function() { |
| 333 OptionsPage.showPageByName('createProfile'); | 333 PageManager.showPageByName('createProfile'); |
| 334 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 334 assertEquals('createProfile', PageManager.getTopmostVisiblePage().name); |
| 335 var errorBubble = $('create-profile-error-bubble'); | 335 var errorBubble = $('create-profile-error-bubble'); |
| 336 assertTrue(errorBubble.hidden); | 336 assertTrue(errorBubble.hidden); |
| 337 | 337 |
| 338 CreateProfileOverlay.onError('An Error Message!'); | 338 CreateProfileOverlay.onError('An Error Message!'); |
| 339 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 339 assertEquals('createProfile', PageManager.getTopmostVisiblePage().name); |
| 340 assertFalse(errorBubble.hidden); | 340 assertFalse(errorBubble.hidden); |
| 341 }); | 341 }); |
| 342 | 342 |
| 343 // The name and email should be inserted into the confirmation dialog. | 343 // The name and email should be inserted into the confirmation dialog. |
| 344 TEST_F('ManageProfileUITest', 'CreateConfirmationText', function() { | 344 TEST_F('ManageProfileUITest', 'CreateConfirmationText', function() { |
| 345 var self = this; | 345 var self = this; |
| 346 var custodianEmail = 'foo@example.com'; | 346 var custodianEmail = 'foo@example.com'; |
| 347 | 347 |
| 348 // Checks the strings in the confirmation dialog. If |expectedNameText| is | 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 | 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 | 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 | 351 // dialog's innerHTML; otherwise the expected text is expected in the HTML |
| 352 // too. | 352 // too. |
| 353 function checkDialog(name, expectedNameText, expectedNameHtml) { | 353 function checkDialog(name, expectedNameText, expectedNameHtml) { |
| 354 var expectedText = expectedNameText || name; | 354 var expectedText = expectedNameText || name; |
| 355 var expectedHtml = expectedNameHtml || expectedText; | 355 var expectedHtml = expectedNameHtml || expectedText; |
| 356 | 356 |
| 357 // Configure the test profile and show the confirmation dialog. | 357 // Configure the test profile and show the confirmation dialog. |
| 358 var testProfile = self.testProfileInfo_(true); | 358 var testProfile = self.testProfileInfo_(true); |
| 359 testProfile.name = name; | 359 testProfile.name = name; |
| 360 CreateProfileOverlay.onSuccess(testProfile); | 360 CreateProfileOverlay.onSuccess(testProfile); |
| 361 assertEquals('supervisedUserCreateConfirm', | 361 assertEquals('supervisedUserCreateConfirm', |
| 362 OptionsPage.getTopmostVisiblePage().name); | 362 PageManager.getTopmostVisiblePage().name); |
| 363 | 363 |
| 364 // Check for the presence of the name and email in the UI, without depending | 364 // Check for the presence of the name and email in the UI, without depending |
| 365 // on the details of the messages. | 365 // on the details of the messages. |
| 366 assertNotEquals(-1, | 366 assertNotEquals(-1, |
| 367 $('supervised-user-created-title').textContent.indexOf(expectedText)); | 367 $('supervised-user-created-title').textContent.indexOf(expectedText)); |
| 368 assertNotEquals(-1, | 368 assertNotEquals(-1, |
| 369 $('supervised-user-created-switch').textContent.indexOf(expectedText)); | 369 $('supervised-user-created-switch').textContent.indexOf(expectedText)); |
| 370 var message = $('supervised-user-created-text'); | 370 var message = $('supervised-user-created-text'); |
| 371 assertNotEquals(-1, message.textContent.indexOf(expectedText)); | 371 assertNotEquals(-1, message.textContent.indexOf(expectedText)); |
| 372 assertNotEquals(-1, message.textContent.indexOf(custodianEmail)); | 372 assertNotEquals(-1, message.textContent.indexOf(custodianEmail)); |
| 373 | 373 |
| 374 // The name should be properly HTML-escaped. | 374 // The name should be properly HTML-escaped. |
| 375 assertNotEquals(-1, message.innerHTML.indexOf(expectedHtml)); | 375 assertNotEquals(-1, message.innerHTML.indexOf(expectedHtml)); |
| 376 | 376 |
| 377 OptionsPage.closeOverlay(); | 377 PageManager.closeOverlay(); |
| 378 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name, name); | 378 assertEquals('settings', PageManager.getTopmostVisiblePage().name, name); |
| 379 } | 379 } |
| 380 | 380 |
| 381 // Show and configure the create-profile dialog. | 381 // Show and configure the create-profile dialog. |
| 382 OptionsPage.showPageByName('createProfile'); | 382 PageManager.showPageByName('createProfile'); |
| 383 CreateProfileOverlay.updateSignedInStatus(custodianEmail); | 383 CreateProfileOverlay.updateSignedInStatus(custodianEmail); |
| 384 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 384 assertEquals('createProfile', PageManager.getTopmostVisiblePage().name); |
| 385 | 385 |
| 386 checkDialog('OneWord'); | 386 checkDialog('OneWord'); |
| 387 checkDialog('Multiple Words'); | 387 checkDialog('Multiple Words'); |
| 388 checkDialog('It\'s "<HTML> injection" & more!', | 388 checkDialog('It\'s "<HTML> injection" & more!', |
| 389 'It\'s "<HTML> injection" & more!', | 389 'It\'s "<HTML> injection" & more!', |
| 390 // The innerHTML getter doesn't escape quotation marks, | 390 // The innerHTML getter doesn't escape quotation marks, |
| 391 // independent of whether they were escaped in the setter. | 391 // independent of whether they were escaped in the setter. |
| 392 'It\'s "<HTML> injection" & more!'); | 392 'It\'s "<HTML> injection" & more!'); |
| 393 | 393 |
| 394 // Test elision. MAX_LENGTH = 50, minus 1 for the ellipsis. | 394 // Test elision. MAX_LENGTH = 50, minus 1 for the ellipsis. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 496 |
| 497 CreateProfileOverlay.updateCreateInProgress(false); | 497 CreateProfileOverlay.updateCreateInProgress(false); |
| 498 assertFalse(checkbox.disabled, 'creation finished'); | 498 assertFalse(checkbox.disabled, 'creation finished'); |
| 499 }); | 499 }); |
| 500 | 500 |
| 501 // Supervised users shouldn't be able to open the delete or create dialogs. | 501 // Supervised users shouldn't be able to open the delete or create dialogs. |
| 502 TEST_F('ManageProfileUITest', 'SupervisedShowDeleteAndCreate', function() { | 502 TEST_F('ManageProfileUITest', 'SupervisedShowDeleteAndCreate', function() { |
| 503 this.setProfileSupervised_(false, 'create'); | 503 this.setProfileSupervised_(false, 'create'); |
| 504 | 504 |
| 505 ManageProfileOverlay.showCreateDialog(); | 505 ManageProfileOverlay.showCreateDialog(); |
| 506 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 506 assertEquals('createProfile', PageManager.getTopmostVisiblePage().name); |
| 507 OptionsPage.closeOverlay(); | 507 PageManager.closeOverlay(); |
| 508 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 508 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 509 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 509 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
| 510 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); | 510 assertEquals('manageProfile', PageManager.getTopmostVisiblePage().name); |
| 511 assertFalse($('manage-profile-overlay-delete').hidden); | 511 assertFalse($('manage-profile-overlay-delete').hidden); |
| 512 OptionsPage.closeOverlay(); | 512 PageManager.closeOverlay(); |
| 513 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 513 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 514 | 514 |
| 515 this.setProfileSupervised_(true, 'create'); | 515 this.setProfileSupervised_(true, 'create'); |
| 516 ManageProfileOverlay.showCreateDialog(); | 516 ManageProfileOverlay.showCreateDialog(); |
| 517 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 517 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 518 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 518 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
| 519 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 519 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 520 }); | 520 }); |
| 521 | 521 |
| 522 // Only non-supervised users should be able to delete profiles. | 522 // Only non-supervised users should be able to delete profiles. |
| 523 TEST_F('ManageProfileUITest', 'SupervisedDelete', function() { | 523 TEST_F('ManageProfileUITest', 'SupervisedDelete', function() { |
| 524 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 524 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
| 525 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); | 525 assertEquals('manageProfile', PageManager.getTopmostVisiblePage().name); |
| 526 assertFalse($('manage-profile-overlay-delete').hidden); | 526 assertFalse($('manage-profile-overlay-delete').hidden); |
| 527 | 527 |
| 528 // Clicks the "Delete" button, after overriding chrome.send to record what | 528 // Clicks the "Delete" button, after overriding chrome.send to record what |
| 529 // messages were sent. | 529 // messages were sent. |
| 530 function clickAndListen() { | 530 function clickAndListen() { |
| 531 var originalChromeSend = chrome.send; | 531 var originalChromeSend = chrome.send; |
| 532 var chromeSendMessages = []; | 532 var chromeSendMessages = []; |
| 533 chrome.send = function(message) { | 533 chrome.send = function(message) { |
| 534 chromeSendMessages.push(message); | 534 chromeSendMessages.push(message); |
| 535 }; | 535 }; |
| 536 $('delete-profile-ok').onclick(); | 536 $('delete-profile-ok').onclick(); |
| 537 // Restore the original function so the test framework can use it. | 537 // Restore the original function so the test framework can use it. |
| 538 chrome.send = originalChromeSend; | 538 chrome.send = originalChromeSend; |
| 539 return chromeSendMessages; | 539 return chromeSendMessages; |
| 540 } | 540 } |
| 541 | 541 |
| 542 this.setProfileSupervised_(false, 'manage'); | 542 this.setProfileSupervised_(false, 'manage'); |
| 543 var messages = clickAndListen(); | 543 var messages = clickAndListen(); |
| 544 assertEquals(1, messages.length); | 544 assertEquals(1, messages.length); |
| 545 assertEquals('deleteProfile', messages[0]); | 545 assertEquals('deleteProfile', messages[0]); |
| 546 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 546 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 547 | 547 |
| 548 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 548 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
| 549 this.setProfileSupervised_(true, 'manage'); | 549 this.setProfileSupervised_(true, 'manage'); |
| 550 messages = clickAndListen(); | 550 messages = clickAndListen(); |
| 551 assertEquals(0, messages.length); | 551 assertEquals(0, messages.length); |
| 552 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 552 assertEquals('settings', PageManager.getTopmostVisiblePage().name); |
| 553 }); | 553 }); |
| 554 | 554 |
| 555 // Selecting a different avatar image should update the suggested profile name. | 555 // Selecting a different avatar image should update the suggested profile name. |
| 556 TEST_F('ManageProfileUITest', 'Create_NameUpdateOnAvatarSelected', function() { | 556 TEST_F('ManageProfileUITest', 'Create_NameUpdateOnAvatarSelected', function() { |
| 557 var mode = 'create'; | 557 var mode = 'create'; |
| 558 this.initDefaultProfiles_(mode); | 558 this.initDefaultProfiles_(mode); |
| 559 | 559 |
| 560 var gridEl = $(mode + '-profile-icon-grid'); | 560 var gridEl = $(mode + '-profile-icon-grid'); |
| 561 var nameEl = $(mode + '-profile-name'); | 561 var nameEl = $(mode + '-profile-name'); |
| 562 | 562 |
| 563 // Select another icon and check that the profile name was updated. | 563 // Select another icon and check that the profile name was updated. |
| 564 assertNotEquals(gridEl.selectedItem, this.defaultIconURLs[0]); | 564 assertNotEquals(gridEl.selectedItem, this.defaultIconURLs[0]); |
| 565 gridEl.selectedItem = this.defaultIconURLs[0]; | 565 gridEl.selectedItem = this.defaultIconURLs[0]; |
| 566 expectEquals(this.defaultNames[0], nameEl.value); | 566 expectEquals(this.defaultNames[0], nameEl.value); |
| 567 | 567 |
| 568 // Select icon without an associated name; the profile name shouldn't change. | 568 // Select icon without an associated name; the profile name shouldn't change. |
| 569 var oldName = nameEl.value; | 569 var oldName = nameEl.value; |
| 570 assertEquals('', this.defaultNames[2]); | 570 assertEquals('', this.defaultNames[2]); |
| 571 gridEl.selectedItem = this.defaultIconURLs[2]; | 571 gridEl.selectedItem = this.defaultIconURLs[2]; |
| 572 expectEquals(oldName, nameEl.value); | 572 expectEquals(oldName, nameEl.value); |
| 573 | 573 |
| 574 // Select another icon with a name and check that the name is updated again. | 574 // Select another icon with a name and check that the name is updated again. |
| 575 assertNotEquals('', this.defaultNames[1]); | 575 assertNotEquals('', this.defaultNames[1]); |
| 576 gridEl.selectedItem = this.defaultIconURLs[1]; | 576 gridEl.selectedItem = this.defaultIconURLs[1]; |
| 577 expectEquals(this.defaultNames[1], nameEl.value); | 577 expectEquals(this.defaultNames[1], nameEl.value); |
| 578 | 578 |
| 579 OptionsPage.closeOverlay(); | 579 PageManager.closeOverlay(); |
| 580 }); | 580 }); |
| 581 | 581 |
| 582 // After the user edited the profile name, selecting a different avatar image | 582 // After the user edited the profile name, selecting a different avatar image |
| 583 // should not update the suggested name anymore. | 583 // should not update the suggested name anymore. |
| 584 TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterEdit', | 584 TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterEdit', |
| 585 function() { | 585 function() { |
| 586 var mode = 'create'; | 586 var mode = 'create'; |
| 587 this.initDefaultProfiles_(mode); | 587 this.initDefaultProfiles_(mode); |
| 588 | 588 |
| 589 var gridEl = $(mode + '-profile-icon-grid'); | 589 var gridEl = $(mode + '-profile-icon-grid'); |
| 590 var nameEl = $(mode + '-profile-name'); | 590 var nameEl = $(mode + '-profile-name'); |
| 591 | 591 |
| 592 // After the user manually entered a name, it should not be changed anymore | 592 // After the user manually entered a name, it should not be changed anymore |
| 593 // (even if the entered name is another default name). | 593 // (even if the entered name is another default name). |
| 594 nameEl.value = this.defaultNames[3]; | 594 nameEl.value = this.defaultNames[3]; |
| 595 nameEl.oninput(); | 595 nameEl.oninput(); |
| 596 gridEl.selectedItem = this.defaultIconURLs[0]; | 596 gridEl.selectedItem = this.defaultIconURLs[0]; |
| 597 expectEquals(this.defaultNames[3], nameEl.value); | 597 expectEquals(this.defaultNames[3], nameEl.value); |
| 598 | 598 |
| 599 OptionsPage.closeOverlay(); | 599 PageManager.closeOverlay(); |
| 600 }); | 600 }); |
| 601 | 601 |
| 602 // After the user edited the profile name, selecting a different avatar image | 602 // After the user edited the profile name, selecting a different avatar image |
| 603 // should not update the suggested name anymore even if the original suggestion | 603 // should not update the suggested name anymore even if the original suggestion |
| 604 // is entered again. | 604 // is entered again. |
| 605 TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterRevert', | 605 TEST_F('ManageProfileUITest', 'Create_NoNameUpdateOnAvatarSelectedAfterRevert', |
| 606 function() { | 606 function() { |
| 607 var mode = 'create'; | 607 var mode = 'create'; |
| 608 this.initDefaultProfiles_(mode); | 608 this.initDefaultProfiles_(mode); |
| 609 | 609 |
| 610 var gridEl = $(mode + '-profile-icon-grid'); | 610 var gridEl = $(mode + '-profile-icon-grid'); |
| 611 var nameEl = $(mode + '-profile-name'); | 611 var nameEl = $(mode + '-profile-name'); |
| 612 | 612 |
| 613 // After the user manually entered a name, it should not be changed anymore, | 613 // After the user manually entered a name, it should not be changed anymore, |
| 614 // even if the user then reverts to the original suggestion. | 614 // even if the user then reverts to the original suggestion. |
| 615 var oldName = nameEl.value; | 615 var oldName = nameEl.value; |
| 616 nameEl.value = 'Custom Name'; | 616 nameEl.value = 'Custom Name'; |
| 617 nameEl.oninput(); | 617 nameEl.oninput(); |
| 618 nameEl.value = oldName; | 618 nameEl.value = oldName; |
| 619 nameEl.oninput(); | 619 nameEl.oninput(); |
| 620 // Now select another avatar and check that the name remained the same. | 620 // Now select another avatar and check that the name remained the same. |
| 621 assertNotEquals(gridEl.selectedItem, this.defaultIconURLs[0]); | 621 assertNotEquals(gridEl.selectedItem, this.defaultIconURLs[0]); |
| 622 gridEl.selectedItem = this.defaultIconURLs[0]; | 622 gridEl.selectedItem = this.defaultIconURLs[0]; |
| 623 expectEquals(oldName, nameEl.value); | 623 expectEquals(oldName, nameEl.value); |
| 624 | 624 |
| 625 OptionsPage.closeOverlay(); | 625 PageManager.closeOverlay(); |
| 626 }); | 626 }); |
| 627 | 627 |
| 628 // In the manage dialog, the name should never be updated on avatar selection. | 628 // In the manage dialog, the name should never be updated on avatar selection. |
| 629 TEST_F('ManageProfileUITest', 'Manage_NoNameUpdateOnAvatarSelected', | 629 TEST_F('ManageProfileUITest', 'Manage_NoNameUpdateOnAvatarSelected', |
| 630 function() { | 630 function() { |
| 631 var mode = 'manage'; | 631 var mode = 'manage'; |
| 632 this.setProfileSupervised_(false, mode); | 632 this.setProfileSupervised_(false, mode); |
| 633 OptionsPage.showPageByName(mode + 'Profile'); | 633 PageManager.showPageByName(mode + 'Profile'); |
| 634 | 634 |
| 635 var testProfile = this.testProfileInfo_(false); | 635 var testProfile = this.testProfileInfo_(false); |
| 636 var iconURLs = [testProfile.iconURL, '/some/path', '/another/path']; | 636 var iconURLs = [testProfile.iconURL, '/some/path', '/another/path']; |
| 637 var names = [testProfile.name, 'Some Name', '']; | 637 var names = [testProfile.name, 'Some Name', '']; |
| 638 ManageProfileOverlay.receiveDefaultProfileIconsAndNames( | 638 ManageProfileOverlay.receiveDefaultProfileIconsAndNames( |
| 639 mode, iconURLs, names); | 639 mode, iconURLs, names); |
| 640 | 640 |
| 641 var gridEl = $(mode + '-profile-icon-grid'); | 641 var gridEl = $(mode + '-profile-icon-grid'); |
| 642 var nameEl = $(mode + '-profile-name'); | 642 var nameEl = $(mode + '-profile-name'); |
| 643 | 643 |
| 644 // Select another icon and check if the profile name was updated. | 644 // Select another icon and check if the profile name was updated. |
| 645 var oldName = nameEl.value; | 645 var oldName = nameEl.value; |
| 646 gridEl.selectedItem = iconURLs[1]; | 646 gridEl.selectedItem = iconURLs[1]; |
| 647 expectEquals(oldName, nameEl.value); | 647 expectEquals(oldName, nameEl.value); |
| 648 | 648 |
| 649 OptionsPage.closeOverlay(); | 649 PageManager.closeOverlay(); |
| 650 }); | 650 }); |
| 651 | 651 |
| 652 GEN('#endif // OS_CHROMEOS'); | 652 GEN('#endif // OS_CHROMEOS'); |
| OLD | NEW |