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 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 Loading... | |
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_ = [ | |
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 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 :)
| |
180 resolve(managedUsers); | |
181 }); | |
182 options.ManagedUserListData.getInstance().promise_ = promise; | |
177 // Also add the name 'Test' to |profileNames_| to simulate that the profile | 183 // Also add the name 'Test' to |profileNames_| to simulate that the profile |
178 // exists on the device. | 184 // exists on the device. |
179 ManageProfileOverlay.getInstance().profileNames_.Test = true; | 185 ManageProfileOverlay.getInstance().profileNames_.Test = true; |
180 | 186 |
181 // Initially, the ok button should be enabled and the import link should not | 187 // Initially, the ok button should be enabled and the import link should not |
182 // exist. | 188 // exist. |
183 assertFalse($('create-profile-ok').disabled); | 189 assertFalse($('create-profile-ok').disabled); |
184 assertTrue($('supervised-user-import') == null); | 190 assertTrue($('supervised-user-import') == null); |
185 | 191 |
186 // Now try to create profiles with the names of existing supervised users. | 192 // Now try to create profiles with the names of existing supervised users. |
187 $('create-profile-managed').checked = true; | 193 $('create-profile-managed').checked = true; |
188 var nameField = $('create-profile-name'); | 194 var nameField = $('create-profile-name'); |
189 // A profile which already has an avatar. | 195 // A profile which already has an avatar. |
190 nameField.value = 'Rosalie'; | 196 nameField.value = 'Rosalie'; |
191 ManageProfileOverlay.getInstance().onNameChanged_('create'); | 197 ManageProfileOverlay.getInstance().onNameChanged_('create'); |
192 assertTrue($('create-profile-ok').disabled); | 198 // Need to wait until the promise resolves. |
193 assertFalse($('supervised-user-import') == null); | 199 promise.then(function() { |
194 // A profile which doesn't have an avatar yet. | 200 assertTrue($('create-profile-ok').disabled); |
195 nameField.value = 'Fritz'; | 201 assertFalse($('supervised-user-import') == null); |
196 ManageProfileOverlay.getInstance().onNameChanged_('create'); | 202 }).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.
| |
197 assertTrue($('create-profile-ok').disabled); | 203 // A profile which doesn't have an avatar yet. |
198 assertFalse($('supervised-user-import') == null); | 204 nameField.value = 'Fritz'; |
199 // A profile which already exists on the device. | 205 ManageProfileOverlay.getInstance().onNameChanged_('create'); |
200 nameField.value = 'Test'; | 206 }).then(function() { |
201 ManageProfileOverlay.getInstance().onNameChanged_('create'); | 207 assertTrue($('create-profile-ok').disabled); |
202 assertTrue($('create-profile-ok').disabled); | 208 assertFalse($('supervised-user-import') == null); |
203 assertTrue($('supervised-user-import') == null); | 209 }).then(function() { |
204 | 210 // A profile which already exists on the device. |
205 // A profile which does not exist yet. | 211 nameField.value = 'Test'; |
206 nameField.value = 'NewProfileName'; | 212 ManageProfileOverlay.getInstance().onNameChanged_('create'); |
207 ManageProfileOverlay.getInstance().onNameChanged_('create'); | 213 }).then(function() { |
208 assertFalse($('create-profile-ok').disabled); | 214 assertTrue($('create-profile-ok').disabled); |
209 assertTrue($('supervised-user-import') == null); | 215 assertTrue($('supervised-user-import') == null); |
216 }).then(function() { | |
217 // A profile which does not exist yet. | |
218 nameField.value = 'NewProfileName'; | |
219 ManageProfileOverlay.getInstance().onNameChanged_('create'); | |
220 }).then(function() { | |
221 assertFalse($('create-profile-ok').disabled); | |
222 assertTrue($('supervised-user-import') == null); | |
223 }); | |
210 }); | 224 }); |
211 | 225 |
212 // Managed users should not be able to edit their profile names, and the initial | 226 // Managed users should not be able to edit their profile names, and the initial |
213 // focus should be adjusted accordingly. | 227 // focus should be adjusted accordingly. |
214 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() { | 228 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() { |
215 var nameField = $('manage-profile-name'); | 229 var nameField = $('manage-profile-name'); |
216 | 230 |
217 this.setProfileManaged_(false, 'manage'); | 231 this.setProfileManaged_(false, 'manage'); |
218 ManageProfileOverlay.showManageDialog(); | 232 ManageProfileOverlay.showManageDialog(); |
219 expectFalse(nameField.disabled); | 233 expectFalse(nameField.disabled); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 332 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); |
319 | 333 |
320 checkDialog('OneWord'); | 334 checkDialog('OneWord'); |
321 checkDialog('Multiple Words'); | 335 checkDialog('Multiple Words'); |
322 checkDialog('It\'s "<HTML> injection" & more!', | 336 checkDialog('It\'s "<HTML> injection" & more!', |
323 'It\'s "<HTML> injection" & more!', | 337 'It\'s "<HTML> injection" & more!', |
324 // The innerHTML getter doesn't escape quotation marks, | 338 // The innerHTML getter doesn't escape quotation marks, |
325 // independent of whether they were escaped in the setter. | 339 // independent of whether they were escaped in the setter. |
326 'It\'s "<HTML> injection" & more!'); | 340 'It\'s "<HTML> injection" & more!'); |
327 | 341 |
328 // Test elision. MAX_LENGTH = 50, minus 3 for the ellipsis. | 342 // Test elision. MAX_LENGTH = 50, minus 1 for the ellipsis. |
329 var name47Characters = '01234567890123456789012345678901234567890123456'; | 343 var name49Characters = '0123456789012345678901234567890123456789012345678'; |
330 var name60Characters = name47Characters + '0123456789012'; | 344 var name50Characters = name49Characters + '9'; |
331 checkDialog(name60Characters, name47Characters + '...'); | 345 var name51Characters = name50Characters + '0'; |
346 var name60Characters = name51Characters + '123456789'; | |
347 checkDialog(name49Characters, name49Characters); | |
348 checkDialog(name50Characters, name50Characters); | |
349 checkDialog(name51Characters, name49Characters + '\u2026'); | |
350 checkDialog(name60Characters, name49Characters + '\u2026'); | |
332 | 351 |
333 // Test both elision and HTML escaping. The allowed string length is the | 352 // Test both elision and HTML escaping. The allowed string length is the |
334 // visible length, not the length including the entity names. | 353 // visible length, not the length including the entity names. |
335 name47Characters = name47Characters.replace('0', '&').replace('1', '>'); | 354 name49Characters = name49Characters.replace('0', '&').replace('1', '>'); |
336 name60Characters = name60Characters.replace('0', '&').replace('1', '>'); | 355 name60Characters = name60Characters.replace('0', '&').replace('1', '>'); |
337 var escaped = name47Characters.replace('&', '&').replace('>', '>'); | 356 var escaped = name49Characters.replace('&', '&').replace('>', '>'); |
338 checkDialog(name60Characters, name47Characters + '...', escaped + '...'); | 357 checkDialog( |
358 name60Characters, name49Characters + '\u2026', escaped + '\u2026'); | |
339 }); | 359 }); |
340 | 360 |
341 // An additional warning should be shown when deleting a managed user. | 361 // An additional warning should be shown when deleting a managed user. |
342 TEST_F('ManageProfileUITest', 'DeleteManagedUserWarning', function() { | 362 TEST_F('ManageProfileUITest', 'DeleteManagedUserWarning', function() { |
343 var addendum = $('delete-managed-profile-addendum'); | 363 var addendum = $('delete-managed-profile-addendum'); |
344 | 364 |
345 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(true)); | 365 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(true)); |
346 assertFalse(addendum.hidden); | 366 assertFalse(addendum.hidden); |
347 | 367 |
348 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 368 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 chromeSendMessages.push(message); | 482 chromeSendMessages.push(message); |
463 }; | 483 }; |
464 $('delete-profile-ok').onclick(); | 484 $('delete-profile-ok').onclick(); |
465 // Restore the original function so the test framework can use it. | 485 // Restore the original function so the test framework can use it. |
466 chrome.send = originalChromeSend; | 486 chrome.send = originalChromeSend; |
467 return chromeSendMessages; | 487 return chromeSendMessages; |
468 } | 488 } |
469 | 489 |
470 this.setProfileManaged_(false, 'manage'); | 490 this.setProfileManaged_(false, 'manage'); |
471 var messages = clickAndListen(); | 491 var messages = clickAndListen(); |
472 assertEquals(2, messages.length); | 492 assertEquals(1, messages.length); |
473 assertEquals('deleteProfile', messages[0]); | 493 assertEquals('deleteProfile', messages[0]); |
474 assertEquals('requestManagedUserImportUpdate', messages[1]); | |
475 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 494 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
476 | 495 |
477 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 496 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
478 this.setProfileManaged_(true, 'manage'); | 497 this.setProfileManaged_(true, 'manage'); |
479 messages = clickAndListen(); | 498 messages = clickAndListen(); |
480 assertEquals(0, messages.length); | 499 assertEquals(0, messages.length); |
481 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 500 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
482 }); | 501 }); |
483 | 502 |
484 GEN('#endif // OS_CHROMEOS'); | 503 GEN('#endif // OS_CHROMEOS'); |
OLD | NEW |