Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3819)

Unified Diff: chrome/browser/ui/webui/options/manage_profile_browsertest.js

Issue 132013002: Replace own callback handling with Promises. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a592709c88f55b984971102cbe078960cbbe54e8..380e8e12deeb739ee0601d818307b01f9f0bd416 100644
--- a/chrome/browser/ui/webui/options/manage_profile_browsertest.js
+++ b/chrome/browser/ui/webui/options/manage_profile_browsertest.js
@@ -151,13 +151,13 @@ TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() {
this.setProfileManaged_(false, 'create');
// Initialize the list of existing managed users.
- var managedUserListData = options.ManagedUserListData.getInstance();
- managedUserListData.managedUsers_ = [
+ var managedUsers = [
{
id: 'managedUser1',
name: 'Rosalie',
iconURL: 'chrome://path/to/icon/image',
onCurrentDevice: false,
+ nameConflict: false,
needAvatar: false
},
{
@@ -165,6 +165,7 @@ TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() {
name: 'Fritz',
iconURL: 'chrome://path/to/icon/image',
onCurrentDevice: false,
+ nameConflict: false,
needAvatar: true
},
{
@@ -172,8 +173,13 @@ TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() {
name: 'Test',
iconURL: 'chrome://path/to/icon/image',
onCurrentDevice: true,
+ nameConflict: true,
needAvatar: false
}];
+ var promise = new Promise(function(resolve, reject) {
Bernhard Bauer 2014/01/13 14:33:50 This is available as Promise.resolve(...).
Adrian Kuegel 2014/01/13 15:43:37 Cool. Thanks for pointing that out :)
+ resolve(managedUsers);
+ });
+ options.ManagedUserListData.getInstance().promise_ = promise;
// Also add the name 'Test' to |profileNames_| to simulate that the profile
// exists on the device.
ManageProfileOverlay.getInstance().profileNames_.Test = true;
@@ -189,24 +195,32 @@ TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() {
// A profile which already has an avatar.
nameField.value = 'Rosalie';
ManageProfileOverlay.getInstance().onNameChanged_('create');
- assertTrue($('create-profile-ok').disabled);
- assertFalse($('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);
- assertFalse($('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);
+ // Need to wait until the promise resolves.
+ promise.then(function() {
+ assertTrue($('create-profile-ok').disabled);
+ assertFalse($('supervised-user-import') == null);
+ }).then(function() {
Bernhard Bauer 2014/01/13 14:33:50 This will be called immediately afterwards, so you
Adrian Kuegel 2014/01/13 15:43:37 Thank you very much for the detailed explanation.
+ // A profile which doesn't have an avatar yet.
+ nameField.value = 'Fritz';
+ ManageProfileOverlay.getInstance().onNameChanged_('create');
+ }).then(function() {
+ assertTrue($('create-profile-ok').disabled);
+ assertFalse($('supervised-user-import') == null);
+ }).then(function() {
+ // A profile which already exists on the device.
+ nameField.value = 'Test';
+ ManageProfileOverlay.getInstance().onNameChanged_('create');
+ }).then(function() {
+ assertTrue($('create-profile-ok').disabled);
+ assertTrue($('supervised-user-import') == null);
+ }).then(function() {
+ // A profile which does not exist yet.
+ nameField.value = 'NewProfileName';
+ ManageProfileOverlay.getInstance().onNameChanged_('create');
+ }).then(function() {
+ assertFalse($('create-profile-ok').disabled);
+ assertTrue($('supervised-user-import') == null);
+ });
});
// Managed users should not be able to edit their profile names, and the initial
@@ -325,17 +339,23 @@ TEST_F('ManageProfileUITest', 'CreateConfirmationText', function () {
// independent of whether they were escaped in the setter.
'It\'s "<HTML> injection" & more!');
- // Test elision. MAX_LENGTH = 50, minus 3 for the ellipsis.
- var name47Characters = '01234567890123456789012345678901234567890123456';
- var name60Characters = name47Characters + '0123456789012';
- checkDialog(name60Characters, name47Characters + '...');
+ // 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.
- name47Characters = name47Characters.replace('0', '&').replace('1', '>');
+ name49Characters = name49Characters.replace('0', '&').replace('1', '>');
name60Characters = name60Characters.replace('0', '&').replace('1', '>');
- var escaped = name47Characters.replace('&', '&').replace('>', '>');
- checkDialog(name60Characters, name47Characters + '...', escaped + '...');
+ var escaped = name49Characters.replace('&', '&').replace('>', '>');
+ checkDialog(
+ name60Characters, name49Characters + '\u2026', escaped + '\u2026');
});
// An additional warning should be shown when deleting a managed user.
@@ -469,9 +489,8 @@ TEST_F('ManageProfileUITest', 'ManagedDelete', function() {
this.setProfileManaged_(false, 'manage');
var messages = clickAndListen();
- assertEquals(2, messages.length);
+ assertEquals(1, messages.length);
assertEquals('deleteProfile', messages[0]);
- assertEquals('requestManagedUserImportUpdate', messages[1]);
assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));

Powered by Google App Engine
This is Rietveld 408576698