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..fea0682f284ed866227618d2d5a7fc0408434da0 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,82 @@ 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 not be disabled and the import link should |
Pam (message me for reviews)
2014/01/08 11:21:35
This would be clearer as "should be enabled"
Adrian Kuegel
2014/01/08 12:51:47
Done.
|
+ // 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); |
+ // 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); |
+}); |
Pam (message me for reviews)
2014/01/08 11:21:35
Also test creating a name that doesn't exist.
Adrian Kuegel
2014/01/08 12:51:47
Done.
|
+ |
// 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 +422,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 +434,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 +461,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); |