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

Side by Side 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: Fix tests. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 GEN('#include "base/command_line.h"'); 8 GEN('#include "base/command_line.h"');
9 GEN('#include "chrome/common/chrome_switches.h"'); 9 GEN('#include "chrome/common/chrome_switches.h"');
10 10
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // same name as an existing managed user profile. 144 // same name as an existing managed user profile.
145 TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() { 145 TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() {
146 ManageProfileOverlay.getInstance().initializePage(); 146 ManageProfileOverlay.getInstance().initializePage();
147 var custodianEmail = 'chrome.playpen.test@gmail.com'; 147 var custodianEmail = 'chrome.playpen.test@gmail.com';
148 CreateProfileOverlay.updateSignedInStatus(custodianEmail); 148 CreateProfileOverlay.updateSignedInStatus(custodianEmail);
149 assertEquals(custodianEmail, 149 assertEquals(custodianEmail,
150 CreateProfileOverlay.getInstance().signedInEmail_); 150 CreateProfileOverlay.getInstance().signedInEmail_);
151 this.setProfileManaged_(false, 'create'); 151 this.setProfileManaged_(false, 'create');
152 152
153 // Initialize the list of existing managed users. 153 // Initialize the list of existing managed users.
154 var managedUserListData = options.ManagedUserListData.getInstance(); 154 var managedUsers = [
155 managedUserListData.managedUsers_ = [
Bernhard Bauer 2014/01/10 13:52:08 Would this work if you inject a fulfilled promise
Adrian Kuegel 2014/01/10 16:52:01 Yes, it does. Thanks for the suggestion.
156 { 155 {
157 id: 'managedUser1', 156 id: 'managedUser1',
158 name: 'Rosalie', 157 name: 'Rosalie',
159 iconURL: 'chrome://path/to/icon/image', 158 iconURL: 'chrome://path/to/icon/image',
160 onCurrentDevice: false, 159 onCurrentDevice: false,
160 nameConflict: false,
161 needAvatar: false 161 needAvatar: false
162 }, 162 },
163 { 163 {
164 id: 'managedUser2', 164 id: 'managedUser2',
165 name: 'Fritz', 165 name: 'Fritz',
166 iconURL: 'chrome://path/to/icon/image', 166 iconURL: 'chrome://path/to/icon/image',
167 onCurrentDevice: false, 167 onCurrentDevice: false,
168 nameConflict: false,
168 needAvatar: true 169 needAvatar: true
169 }, 170 },
170 { 171 {
171 id: 'managedUser3', 172 id: 'managedUser3',
172 name: 'Test', 173 name: 'Test',
173 iconURL: 'chrome://path/to/icon/image', 174 iconURL: 'chrome://path/to/icon/image',
174 onCurrentDevice: true, 175 onCurrentDevice: true,
176 nameConflict: true,
175 needAvatar: false 177 needAvatar: false
176 }]; 178 }];
179 options.ManagedUserListData.receiveExistingManagedUsers(managedUsers);
177 // Also add the name 'Test' to |profileNames_| to simulate that the profile 180 // Also add the name 'Test' to |profileNames_| to simulate that the profile
178 // exists on the device. 181 // exists on the device.
179 ManageProfileOverlay.getInstance().profileNames_.Test = true; 182 ManageProfileOverlay.getInstance().profileNames_.Test = true;
180 183
181 // Initially, the ok button should be enabled and the import link should not 184 // Initially, the ok button should be enabled and the import link should not
182 // exist. 185 // exist.
183 assertFalse($('create-profile-ok').disabled); 186 assertFalse($('create-profile-ok').disabled);
184 assertTrue($('supervised-user-import') == null); 187 assertTrue($('supervised-user-import') == null);
185 188
186 // Now try to create profiles with the names of existing supervised users. 189 // Now try to create profiles with the names of existing supervised users.
187 $('create-profile-managed').checked = true; 190 $('create-profile-managed').checked = true;
188 var nameField = $('create-profile-name'); 191 var nameField = $('create-profile-name');
189 // A profile which already has an avatar. 192 // A profile which already has an avatar.
190 nameField.value = 'Rosalie'; 193 nameField.value = 'Rosalie';
191 ManageProfileOverlay.getInstance().onNameChanged_('create'); 194 ManageProfileOverlay.getInstance().onNameChanged_('create');
192 assertTrue($('create-profile-ok').disabled); 195 // Need to wait until the promise resolves for the first time. The first time
193 assertFalse($('supervised-user-import') == null); 196 // resolves asynchronously even if the resolve method was already called. Bug?
194 // A profile which doesn't have an avatar yet. 197 options.ManagedUserListData.getInstance().promise_.then(function() {
195 nameField.value = 'Fritz'; 198 assertTrue($('create-profile-ok').disabled);
196 ManageProfileOverlay.getInstance().onNameChanged_('create'); 199 assertFalse($('supervised-user-import') == null);
197 assertTrue($('create-profile-ok').disabled); 200 // A profile which doesn't have an avatar yet.
198 assertFalse($('supervised-user-import') == null); 201 nameField.value = 'Fritz';
199 // A profile which already exists on the device. 202 ManageProfileOverlay.getInstance().onNameChanged_('create');
200 nameField.value = 'Test'; 203 assertTrue($('create-profile-ok').disabled);
201 ManageProfileOverlay.getInstance().onNameChanged_('create'); 204 assertFalse($('supervised-user-import') == null);
202 assertTrue($('create-profile-ok').disabled); 205 // A profile which already exists on the device.
203 assertTrue($('supervised-user-import') == null); 206 nameField.value = 'Test';
207 ManageProfileOverlay.getInstance().onNameChanged_('create');
208 assertTrue($('create-profile-ok').disabled);
209 assertTrue($('supervised-user-import') == null);
204 210
205 // A profile which does not exist yet. 211 // A profile which does not exist yet.
206 nameField.value = 'NewProfileName'; 212 nameField.value = 'NewProfileName';
207 ManageProfileOverlay.getInstance().onNameChanged_('create'); 213 ManageProfileOverlay.getInstance().onNameChanged_('create');
208 assertFalse($('create-profile-ok').disabled); 214 assertFalse($('create-profile-ok').disabled);
209 assertTrue($('supervised-user-import') == null); 215 assertTrue($('supervised-user-import') == null);
216 });
210 }); 217 });
211 218
212 // Managed users should not be able to edit their profile names, and the initial 219 // Managed users should not be able to edit their profile names, and the initial
213 // focus should be adjusted accordingly. 220 // focus should be adjusted accordingly.
214 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() { 221 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() {
215 var nameField = $('manage-profile-name'); 222 var nameField = $('manage-profile-name');
216 223
217 this.setProfileManaged_(false, 'manage'); 224 this.setProfileManaged_(false, 'manage');
218 ManageProfileOverlay.showManageDialog(); 225 ManageProfileOverlay.showManageDialog();
219 expectFalse(nameField.disabled); 226 expectFalse(nameField.disabled);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 checkDialog('Multiple Words'); 328 checkDialog('Multiple Words');
322 checkDialog('It\'s "<HTML> injection" & more!', 329 checkDialog('It\'s "<HTML> injection" & more!',
323 'It\'s "<HTML> injection" & more!', 330 'It\'s "<HTML> injection" & more!',
324 // The innerHTML getter doesn't escape quotation marks, 331 // The innerHTML getter doesn't escape quotation marks,
325 // independent of whether they were escaped in the setter. 332 // independent of whether they were escaped in the setter.
326 'It\'s "&lt;HTML&gt; injection" &amp; more!'); 333 'It\'s "&lt;HTML&gt; injection" &amp; more!');
327 334
328 // Test elision. MAX_LENGTH = 50, minus 3 for the ellipsis. 335 // Test elision. MAX_LENGTH = 50, minus 3 for the ellipsis.
329 var name47Characters = '01234567890123456789012345678901234567890123456'; 336 var name47Characters = '01234567890123456789012345678901234567890123456';
330 var name60Characters = name47Characters + '0123456789012'; 337 var name60Characters = name47Characters + '0123456789012';
331 checkDialog(name60Characters, name47Characters + '...'); 338 checkDialog(name60Characters, name47Characters + '\u2026');
332 339
333 // Test both elision and HTML escaping. The allowed string length is the 340 // Test both elision and HTML escaping. The allowed string length is the
334 // visible length, not the length including the entity names. 341 // visible length, not the length including the entity names.
335 name47Characters = name47Characters.replace('0', '&').replace('1', '>'); 342 name47Characters = name47Characters.replace('0', '&').replace('1', '>');
336 name60Characters = name60Characters.replace('0', '&').replace('1', '>'); 343 name60Characters = name60Characters.replace('0', '&').replace('1', '>');
337 var escaped = name47Characters.replace('&', '&amp;').replace('>', '&gt;'); 344 var escaped = name47Characters.replace('&', '&amp;').replace('>', '&gt;');
338 checkDialog(name60Characters, name47Characters + '...', escaped + '...'); 345 checkDialog(
346 name60Characters, name47Characters + '\u2026', escaped + '\u2026');
339 }); 347 });
340 348
341 // An additional warning should be shown when deleting a managed user. 349 // An additional warning should be shown when deleting a managed user.
342 TEST_F('ManageProfileUITest', 'DeleteManagedUserWarning', function() { 350 TEST_F('ManageProfileUITest', 'DeleteManagedUserWarning', function() {
343 var addendum = $('delete-managed-profile-addendum'); 351 var addendum = $('delete-managed-profile-addendum');
344 352
345 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(true)); 353 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(true));
346 assertFalse(addendum.hidden); 354 assertFalse(addendum.hidden);
347 355
348 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); 356 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 chromeSendMessages.push(message); 470 chromeSendMessages.push(message);
463 }; 471 };
464 $('delete-profile-ok').onclick(); 472 $('delete-profile-ok').onclick();
465 // Restore the original function so the test framework can use it. 473 // Restore the original function so the test framework can use it.
466 chrome.send = originalChromeSend; 474 chrome.send = originalChromeSend;
467 return chromeSendMessages; 475 return chromeSendMessages;
468 } 476 }
469 477
470 this.setProfileManaged_(false, 'manage'); 478 this.setProfileManaged_(false, 'manage');
471 var messages = clickAndListen(); 479 var messages = clickAndListen();
472 assertEquals(2, messages.length); 480 assertEquals(1, messages.length);
473 assertEquals('deleteProfile', messages[0]); 481 assertEquals('deleteProfile', messages[0]);
474 assertEquals('requestManagedUserImportUpdate', messages[1]);
475 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 482 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
476 483
477 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); 484 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false));
478 this.setProfileManaged_(true, 'manage'); 485 this.setProfileManaged_(true, 'manage');
479 messages = clickAndListen(); 486 messages = clickAndListen();
480 assertEquals(0, messages.length); 487 assertEquals(0, messages.length);
481 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); 488 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name);
482 }); 489 });
483 490
484 GEN('#endif // OS_CHROMEOS'); 491 GEN('#endif // OS_CHROMEOS');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698