Chromium Code Reviews| Index: chrome/browser/ui/webui/options/manage_profile_browsertest.js |
| diff --git a/chrome/browser/ui/webui/options/manage_profile_browsertest.js b/chrome/browser/ui/webui/options/manage_profile_browsertest.js |
| index 76b7d0a6980dd9551b27942d45a21a0794fd2098..8a68908605bc3fd3b876b23907105b8e23d4a6e1 100644 |
| --- a/chrome/browser/ui/webui/options/manage_profile_browsertest.js |
| +++ b/chrome/browser/ui/webui/options/manage_profile_browsertest.js |
| @@ -5,6 +5,9 @@ |
| // None of these tests is relevant for Chrome OS. |
| GEN('#if !defined(OS_CHROMEOS)'); |
| +GEN('#include "base/command_line.h"'); |
| +GEN('#include "chrome/common/chrome_switches.h"'); |
| + |
| /** |
| * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing. |
| * @extends {testing.Test} |
| @@ -25,6 +28,12 @@ ManageProfileUITest.prototype = { |
| */ |
| runAccessibilityChecks: false, |
| + /** @override */ |
| + testGenPreamble: function() { |
| + GEN('CommandLine::ForCurrentProcess()->' + |
| + 'AppendSwitch(switches::kAllowCreateExistingManagedUsers);'); |
| + }, |
| + |
| /** |
| * Returns a test profile-info object with configurable "managed" status. |
| * @param {boolean} managed If true, the test profile will be marked as |
| @@ -45,15 +54,15 @@ ManageProfileUITest.prototype = { |
| * Overrides WebUI methods that provide profile info, making them return a |
| * test profile-info object. |
| * @param {boolean} managed Whether the test profile should be marked managed. |
| + * @param {string} mode The mode of the overlay (either 'manage' or 'create'). |
| */ |
| - setProfileManaged_: function(managed) { |
| + setProfileManaged_: function(managed, mode) { |
| // Override the BrowserOptions method to return the fake info. |
| BrowserOptions.getCurrentProfile = function() { |
| return this.testProfileInfo_(managed); |
| }.bind(this); |
| // Set the profile info in the overlay. |
| - ManageProfileOverlay.setProfileInfo(this.testProfileInfo_(managed), |
| - 'manage'); |
| + ManageProfileOverlay.setProfileInfo(this.testProfileInfo_(managed), mode); |
| }, |
| }; |
| @@ -131,19 +140,88 @@ TEST_F('ManageProfileUITest', 'CreateManagedUserText', function() { |
| assertTrue($('create-profile-managed').disabled); |
| }); |
| +// The import link should show up if the user tries to create a profile with the |
| +// same name as an existing managed user profile. |
| +TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() { |
| + ManageProfileOverlay.getInstance().initializePage(); |
| + var custodianEmail = 'chrome.playpen.test@gmail.com'; |
| + CreateProfileOverlay.updateSignedInStatus(custodianEmail); |
| + assertEquals(custodianEmail, |
| + CreateProfileOverlay.getInstance().signedInEmail_); |
| + this.setProfileManaged_(false, 'create'); |
| + |
| + // Initialize the list of existing managed users. |
| + var managedUserList = options.ManagedUserList.getInstance(); |
| + managedUserList.managedUsers = [ |
| + { |
| + id: 'managedUser1', |
| + name: 'Rosalie', |
| + iconURL: 'chrome://path/to/icon/image', |
| + onCurrentDevice: false, |
| + needAvatar: false |
| + }, |
| + { |
| + id: 'managedUser2', |
| + name: 'Fritz', |
| + iconURL: 'chrome://path/to/icon/image', |
| + onCurrentDevice: false, |
| + needAvatar: true |
| + }, |
| + { |
| + id: 'managedUser3', |
| + name: 'Test', |
| + iconURL: 'chrome://path/to/icon/image', |
| + onCurrentDevice: true, |
| + needAvatar: false |
| + }]; |
| + // Also add the name 'Test' to |profileNames_| to simulate that the profile |
| + // exists on the device. |
| + ManageProfileOverlay.getInstance().profileNames_.Test = true; |
| + |
| + // Initially, the ok button should be enabled and the import link should not |
| + // exist. |
| + assertFalse($('create-profile-ok').disabled); |
| + assertTrue($('supervised-user-import') == null); |
| + |
| + // Now try to create profiles with the names of existing supervised users. |
| + $('create-profile-managed').checked = true; |
| + var nameField = $('create-profile-name'); |
| + // A profile which already has an avatar. |
| + nameField.value = 'Rosalie'; |
| + ManageProfileOverlay.getInstance().onNameChanged_('create'); |
| + assertTrue($('create-profile-ok').disabled); |
| + assertTrue($('supervised-user-import') != null); |
|
Pam (message me for reviews)
2014/01/08 14:36:46
How about
assertFalse($('supervised-user-import'
Adrian Kuegel
2014/01/08 16:49:09
Done.
|
| + // A profile which doesn't have an avatar yet. |
| + nameField.value = 'Fritz'; |
| + ManageProfileOverlay.getInstance().onNameChanged_('create'); |
| + assertTrue($('create-profile-ok').disabled); |
| + assertTrue($('supervised-user-import') != null); |
| + // A profile which already exists on the device. |
| + nameField.value = 'Test'; |
| + ManageProfileOverlay.getInstance().onNameChanged_('create'); |
| + assertTrue($('create-profile-ok').disabled); |
| + assertTrue($('supervised-user-import') == null); |
| + |
| + // A profile which does not exist yet. |
| + nameField.value = 'NewProfileName'; |
| + ManageProfileOverlay.getInstance().onNameChanged_('create'); |
| + assertFalse($('create-profile-ok').disabled); |
| + assertTrue($('supervised-user-import') == null); |
| +}); |
| + |
| // Managed users should not be able to edit their profile names, and the initial |
| // focus should be adjusted accordingly. |
| TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() { |
| var nameField = $('manage-profile-name'); |
| - this.setProfileManaged_(false); |
| + this.setProfileManaged_(false, 'manage'); |
| ManageProfileOverlay.showManageDialog(); |
| expectFalse(nameField.disabled); |
| expectEquals(nameField, document.activeElement); |
| OptionsPage.closeOverlay(); |
| - this.setProfileManaged_(true); |
| + this.setProfileManaged_(true, 'manage'); |
| ManageProfileOverlay.showManageDialog(); |
| expectTrue(nameField.disabled); |
| expectEquals($('manage-profile-ok'), document.activeElement); |
| @@ -350,7 +428,7 @@ TEST_F('ManageProfileUITest', 'CreateInProgress', function() { |
| // Managed users shouldn't be able to open the delete or create dialogs. |
| TEST_F('ManageProfileUITest', 'ManagedShowDeleteAndCreate', function() { |
| - this.setProfileManaged_(false); |
| + this.setProfileManaged_(false, 'create'); |
| ManageProfileOverlay.showCreateDialog(); |
| assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); |
| @@ -362,7 +440,7 @@ TEST_F('ManageProfileUITest', 'ManagedShowDeleteAndCreate', function() { |
| OptionsPage.closeOverlay(); |
| assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
| - this.setProfileManaged_(true); |
| + this.setProfileManaged_(true, 'create'); |
| ManageProfileOverlay.showCreateDialog(); |
| assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
| ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
| @@ -389,14 +467,14 @@ TEST_F('ManageProfileUITest', 'ManagedDelete', function() { |
| return chromeSendMessages; |
| } |
| - this.setProfileManaged_(false); |
| + this.setProfileManaged_(false, 'manage'); |
| var messages = clickAndListen(); |
| assertEquals(1, messages.length); |
| assertEquals('deleteProfile', messages[0]); |
| assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
| ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
| - this.setProfileManaged_(true); |
| + this.setProfileManaged_(true, 'manage'); |
| messages = clickAndListen(); |
| assertEquals(0, messages.length); |
| assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |