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"'); | |
9 GEN('#include "chrome/common/chrome_switches.h"'); | |
10 | |
8 /** | 11 /** |
9 * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing. | 12 * TestFixture for ManageProfileOverlay and CreateProfileOverlay WebUI testing. |
10 * @extends {testing.Test} | 13 * @extends {testing.Test} |
11 * @constructor | 14 * @constructor |
12 */ | 15 */ |
13 function ManageProfileUITest() {} | 16 function ManageProfileUITest() {} |
14 | 17 |
15 ManageProfileUITest.prototype = { | 18 ManageProfileUITest.prototype = { |
16 __proto__: testing.Test.prototype, | 19 __proto__: testing.Test.prototype, |
17 | 20 |
18 /** @override */ | 21 /** @override */ |
19 browsePreload: 'chrome://settings-frame/manageProfile', | 22 browsePreload: 'chrome://settings-frame/manageProfile', |
20 | 23 |
21 /** | 24 /** |
22 * No need to run these for every OptionsPage test, since they'll cover the | 25 * No need to run these for every OptionsPage test, since they'll cover the |
23 * whole consolidated page each time. | 26 * whole consolidated page each time. |
24 * @override | 27 * @override |
25 */ | 28 */ |
26 runAccessibilityChecks: false, | 29 runAccessibilityChecks: false, |
27 | 30 |
31 /** @override */ | |
32 testGenPreamble: function() { | |
33 GEN('CommandLine::ForCurrentProcess()->' + | |
34 'AppendSwitch(switches::kAllowCreateExistingManagedUsers);'); | |
35 }, | |
36 | |
28 /** | 37 /** |
29 * Returns a test profile-info object with configurable "managed" status. | 38 * Returns a test profile-info object with configurable "managed" status. |
30 * @param {boolean} managed If true, the test profile will be marked as | 39 * @param {boolean} managed If true, the test profile will be marked as |
31 * managed. | 40 * managed. |
32 * @return {Object} A test profile-info object. | 41 * @return {Object} A test profile-info object. |
33 */ | 42 */ |
34 testProfileInfo_: function(managed) { | 43 testProfileInfo_: function(managed) { |
35 return { | 44 return { |
36 name: 'Test Profile', | 45 name: 'Test Profile', |
37 iconURL: 'chrome://path/to/icon/image', | 46 iconURL: 'chrome://path/to/icon/image', |
38 filePath: '/path/to/profile/data/on/disk', | 47 filePath: '/path/to/profile/data/on/disk', |
39 isCurrentProfile: true, | 48 isCurrentProfile: true, |
40 isManaged: managed | 49 isManaged: managed |
41 }; | 50 }; |
42 }, | 51 }, |
43 | 52 |
44 /** | 53 /** |
45 * Overrides WebUI methods that provide profile info, making them return a | 54 * Overrides WebUI methods that provide profile info, making them return a |
46 * test profile-info object. | 55 * test profile-info object. |
47 * @param {boolean} managed Whether the test profile should be marked managed. | 56 * @param {boolean} managed Whether the test profile should be marked managed. |
57 * @param {string} mode The mode of the overlay (either 'manage' or 'create'). | |
48 */ | 58 */ |
49 setProfileManaged_: function(managed) { | 59 setProfileManaged_: function(managed, mode) { |
50 // Override the BrowserOptions method to return the fake info. | 60 // Override the BrowserOptions method to return the fake info. |
51 BrowserOptions.getCurrentProfile = function() { | 61 BrowserOptions.getCurrentProfile = function() { |
52 return this.testProfileInfo_(managed); | 62 return this.testProfileInfo_(managed); |
53 }.bind(this); | 63 }.bind(this); |
54 // Set the profile info in the overlay. | 64 // Set the profile info in the overlay. |
55 ManageProfileOverlay.setProfileInfo(this.testProfileInfo_(managed), | 65 ManageProfileOverlay.setProfileInfo(this.testProfileInfo_(managed), mode); |
56 'manage'); | |
57 }, | 66 }, |
58 }; | 67 }; |
59 | 68 |
60 // Receiving the new profile defaults in the manage-user overlay shouldn't mess | 69 // Receiving the new profile defaults in the manage-user overlay shouldn't mess |
61 // up the focus in a visible higher-level overlay. | 70 // up the focus in a visible higher-level overlay. |
62 TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() { | 71 TEST_F('ManageProfileUITest', 'NewProfileDefaultsFocus', function() { |
63 var self = this; | 72 var self = this; |
64 | 73 |
65 function checkFocus(pageName, expectedFocus, initialFocus) { | 74 function checkFocus(pageName, expectedFocus, initialFocus) { |
66 OptionsPage.showPageByName(pageName); | 75 OptionsPage.showPageByName(pageName); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 assertNotEquals(-1, signedInText.textContent.indexOf(custodianEmail)); | 133 assertNotEquals(-1, signedInText.textContent.indexOf(custodianEmail)); |
125 | 134 |
126 CreateProfileOverlay.updateSignedInStatus(''); | 135 CreateProfileOverlay.updateSignedInStatus(''); |
127 assertEquals('', CreateProfileOverlay.getInstance().signedInEmail_); | 136 assertEquals('', CreateProfileOverlay.getInstance().signedInEmail_); |
128 assertTrue(signedInText.hidden); | 137 assertTrue(signedInText.hidden); |
129 assertFalse(notSignedInText.hidden); | 138 assertFalse(notSignedInText.hidden); |
130 assertFalse($('create-profile-managed').checked); | 139 assertFalse($('create-profile-managed').checked); |
131 assertTrue($('create-profile-managed').disabled); | 140 assertTrue($('create-profile-managed').disabled); |
132 }); | 141 }); |
133 | 142 |
143 // The import link should show up if the user tries to create a profile with the | |
144 // same name as an existing managed user profile. | |
145 TEST_F('ManageProfileUITest', 'CreateExistingManagedUser', function() { | |
146 ManageProfileOverlay.getInstance().initializePage(); | |
147 var custodianEmail = 'chrome.playpen.test@gmail.com'; | |
148 CreateProfileOverlay.updateSignedInStatus(custodianEmail); | |
149 assertEquals(custodianEmail, | |
150 CreateProfileOverlay.getInstance().signedInEmail_); | |
151 this.setProfileManaged_(false, 'create'); | |
152 | |
153 // Initialize the list of existing managed users. | |
154 var managedUserList = options.ManagedUserList.getInstance(); | |
155 managedUserList.managedUsers = [ | |
156 { | |
157 id: 'managedUser1', | |
158 name: 'Rosalie', | |
159 iconURL: 'chrome://path/to/icon/image', | |
160 onCurrentDevice: false, | |
161 needAvatar: false | |
162 }, | |
163 { | |
164 id: 'managedUser2', | |
165 name: 'Fritz', | |
166 iconURL: 'chrome://path/to/icon/image', | |
167 onCurrentDevice: false, | |
168 needAvatar: true | |
169 }, | |
170 { | |
171 id: 'managedUser3', | |
172 name: 'Test', | |
173 iconURL: 'chrome://path/to/icon/image', | |
174 onCurrentDevice: true, | |
175 needAvatar: false | |
176 }]; | |
177 // Also add the name 'Test' to |profileNames_| to simulate that the profile | |
178 // exists on the device. | |
179 ManageProfileOverlay.getInstance().profileNames_.Test = true; | |
180 | |
181 // 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.
| |
182 // not exist. | |
183 assertFalse($('create-profile-ok').disabled); | |
184 assertTrue($('supervised-user-import') == null); | |
185 | |
186 // Now try to create profiles with the names of existing supervised users. | |
187 $('create-profile-managed').checked = true; | |
188 var nameField = $('create-profile-name'); | |
189 // A profile which already has an avatar. | |
190 nameField.value = 'Rosalie'; | |
191 ManageProfileOverlay.getInstance().onNameChanged_('create'); | |
192 assertTrue($('create-profile-ok').disabled); | |
193 assertTrue($('supervised-user-import') != null); | |
194 // A profile which doesn't have an avatar yet. | |
195 nameField.value = 'Fritz'; | |
196 ManageProfileOverlay.getInstance().onNameChanged_('create'); | |
197 assertTrue($('create-profile-ok').disabled); | |
198 assertTrue($('supervised-user-import') != null); | |
199 // A profile which already exists on the device. | |
200 nameField.value = 'Test'; | |
201 ManageProfileOverlay.getInstance().onNameChanged_('create'); | |
202 assertTrue($('create-profile-ok').disabled); | |
203 assertTrue($('supervised-user-import') == null); | |
204 }); | |
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.
| |
205 | |
134 // Managed users should not be able to edit their profile names, and the initial | 206 // Managed users should not be able to edit their profile names, and the initial |
135 // focus should be adjusted accordingly. | 207 // focus should be adjusted accordingly. |
136 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() { | 208 TEST_F('ManageProfileUITest', 'EditManagedUserNameAllowed', function() { |
137 var nameField = $('manage-profile-name'); | 209 var nameField = $('manage-profile-name'); |
138 | 210 |
139 this.setProfileManaged_(false); | 211 this.setProfileManaged_(false, 'manage'); |
140 ManageProfileOverlay.showManageDialog(); | 212 ManageProfileOverlay.showManageDialog(); |
141 expectFalse(nameField.disabled); | 213 expectFalse(nameField.disabled); |
142 expectEquals(nameField, document.activeElement); | 214 expectEquals(nameField, document.activeElement); |
143 | 215 |
144 OptionsPage.closeOverlay(); | 216 OptionsPage.closeOverlay(); |
145 | 217 |
146 this.setProfileManaged_(true); | 218 this.setProfileManaged_(true, 'manage'); |
147 ManageProfileOverlay.showManageDialog(); | 219 ManageProfileOverlay.showManageDialog(); |
148 expectTrue(nameField.disabled); | 220 expectTrue(nameField.disabled); |
149 expectEquals($('manage-profile-ok'), document.activeElement); | 221 expectEquals($('manage-profile-ok'), document.activeElement); |
150 }); | 222 }); |
151 | 223 |
152 // Setting profile information should allow the confirmation to be shown. | 224 // Setting profile information should allow the confirmation to be shown. |
153 TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() { | 225 TEST_F('ManageProfileUITest', 'ShowCreateConfirmation', function() { |
154 var testProfile = this.testProfileInfo_(true); | 226 var testProfile = this.testProfileInfo_(true); |
155 testProfile.custodianEmail = 'foo@bar.example.com'; | 227 testProfile.custodianEmail = 'foo@bar.example.com'; |
156 ManagedUserCreateConfirmOverlay.setProfileInfo(testProfile); | 228 ManagedUserCreateConfirmOverlay.setProfileInfo(testProfile); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 CreateProfileOverlay.updateSignedInStatus(custodianEmail); | 415 CreateProfileOverlay.updateSignedInStatus(custodianEmail); |
344 CreateProfileOverlay.updateManagedUsersAllowed(true); | 416 CreateProfileOverlay.updateManagedUsersAllowed(true); |
345 assertTrue(checkbox.disabled, 'creation in progress'); | 417 assertTrue(checkbox.disabled, 'creation in progress'); |
346 | 418 |
347 CreateProfileOverlay.updateCreateInProgress(false); | 419 CreateProfileOverlay.updateCreateInProgress(false); |
348 assertFalse(checkbox.disabled, 'creation finished'); | 420 assertFalse(checkbox.disabled, 'creation finished'); |
349 }); | 421 }); |
350 | 422 |
351 // Managed users shouldn't be able to open the delete or create dialogs. | 423 // Managed users shouldn't be able to open the delete or create dialogs. |
352 TEST_F('ManageProfileUITest', 'ManagedShowDeleteAndCreate', function() { | 424 TEST_F('ManageProfileUITest', 'ManagedShowDeleteAndCreate', function() { |
353 this.setProfileManaged_(false); | 425 this.setProfileManaged_(false, 'create'); |
354 | 426 |
355 ManageProfileOverlay.showCreateDialog(); | 427 ManageProfileOverlay.showCreateDialog(); |
356 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); | 428 assertEquals('createProfile', OptionsPage.getTopmostVisiblePage().name); |
357 OptionsPage.closeOverlay(); | 429 OptionsPage.closeOverlay(); |
358 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 430 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
359 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 431 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
360 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); | 432 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); |
361 assertFalse($('manage-profile-overlay-delete').hidden); | 433 assertFalse($('manage-profile-overlay-delete').hidden); |
362 OptionsPage.closeOverlay(); | 434 OptionsPage.closeOverlay(); |
363 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 435 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
364 | 436 |
365 this.setProfileManaged_(true); | 437 this.setProfileManaged_(true, 'create'); |
366 ManageProfileOverlay.showCreateDialog(); | 438 ManageProfileOverlay.showCreateDialog(); |
367 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 439 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
368 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 440 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
369 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 441 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
370 }); | 442 }); |
371 | 443 |
372 // Only non-managed users should be able to delete profiles. | 444 // Only non-managed users should be able to delete profiles. |
373 TEST_F('ManageProfileUITest', 'ManagedDelete', function() { | 445 TEST_F('ManageProfileUITest', 'ManagedDelete', function() { |
374 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 446 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
375 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); | 447 assertEquals('manageProfile', OptionsPage.getTopmostVisiblePage().name); |
376 assertFalse($('manage-profile-overlay-delete').hidden); | 448 assertFalse($('manage-profile-overlay-delete').hidden); |
377 | 449 |
378 // Clicks the "Delete" button, after overriding chrome.send to record what | 450 // Clicks the "Delete" button, after overriding chrome.send to record what |
379 // messages were sent. | 451 // messages were sent. |
380 function clickAndListen() { | 452 function clickAndListen() { |
381 var originalChromeSend = chrome.send; | 453 var originalChromeSend = chrome.send; |
382 var chromeSendMessages = []; | 454 var chromeSendMessages = []; |
383 chrome.send = function(message) { | 455 chrome.send = function(message) { |
384 chromeSendMessages.push(message); | 456 chromeSendMessages.push(message); |
385 }; | 457 }; |
386 $('delete-profile-ok').onclick(); | 458 $('delete-profile-ok').onclick(); |
387 // Restore the original function so the test framework can use it. | 459 // Restore the original function so the test framework can use it. |
388 chrome.send = originalChromeSend; | 460 chrome.send = originalChromeSend; |
389 return chromeSendMessages; | 461 return chromeSendMessages; |
390 } | 462 } |
391 | 463 |
392 this.setProfileManaged_(false); | 464 this.setProfileManaged_(false, 'manage'); |
393 var messages = clickAndListen(); | 465 var messages = clickAndListen(); |
394 assertEquals(1, messages.length); | 466 assertEquals(1, messages.length); |
395 assertEquals('deleteProfile', messages[0]); | 467 assertEquals('deleteProfile', messages[0]); |
396 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 468 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
397 | 469 |
398 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); | 470 ManageProfileOverlay.showDeleteDialog(this.testProfileInfo_(false)); |
399 this.setProfileManaged_(true); | 471 this.setProfileManaged_(true, 'manage'); |
400 messages = clickAndListen(); | 472 messages = clickAndListen(); |
401 assertEquals(0, messages.length); | 473 assertEquals(0, messages.length); |
402 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); | 474 assertEquals('settings', OptionsPage.getTopmostVisiblePage().name); |
403 }); | 475 }); |
404 | 476 |
405 GEN('#endif // OS_CHROMEOS'); | 477 GEN('#endif // OS_CHROMEOS'); |
OLD | NEW |