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

Side by Side Diff: chrome/test/data/webui/md_user_manager/create_profile_tests.js

Issue 1826903002: updated UI, default profile name, check for existing supervised user before create (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 cr.define('user_manager.create_profile_tests', function() { 5 cr.define('user_manager.create_profile_tests', function() {
6 /** @return {!CreateProfileElement} */ 6 /** @return {!CreateProfileElement} */
7 function createElement() { 7 function createElement() {
8 PolymerTest.clearBody(); 8 PolymerTest.clearBody();
9 var createProfileElement = document.createElement('create-profile'); 9 var createProfileElement = document.createElement('create-profile');
10 document.body.appendChild(createProfileElement); 10 document.body.appendChild(createProfileElement);
11 return createProfileElement; 11 return createProfileElement;
12 } 12 }
13 13
14 function registerTests() { 14 function registerTests() {
15 /** @type {?TestProfileBrowserProxy} */ 15 /** @type {?TestProfileBrowserProxy} */
16 var browserProxy = null; 16 var browserProxy = null;
17 17
18 /** @type {?CreateProfileElement} */ 18 /** @type {?CreateProfileElement} */
19 var createProfileElement = null; 19 var createProfileElement = null;
20 20
21 suite('CreateProfileTests', function() { 21 suite('CreateProfileTests', function() {
22 setup(function() { 22 setup(function() {
23 browserProxy = new TestProfileBrowserProxy(); 23 browserProxy = new TestProfileBrowserProxy();
24 24
25 // Replace real proxy with mock proxy. 25 // Replace real proxy with mock proxy.
26 signin.ProfileBrowserProxyImpl.instance_ = browserProxy; 26 signin.ProfileBrowserProxyImpl.instance_ = browserProxy;
27 browserProxy.setDefaultProfileInfo({name: 'profile name'});
27 browserProxy.setIconUrls(['icon1.png', 'icon2.png']); 28 browserProxy.setIconUrls(['icon1.png', 'icon2.png']);
28 browserProxy.setSignedInUsers([{username: 'username', 29 browserProxy.setSignedInUsers([{username: 'username',
29 profilePath: 'path/to/profile'}]); 30 profilePath: 'path/to/profile'}]);
31 browserProxy.setExistingSupervisedUsers([{name: 'existing name 1',
32 onCurrentDevice: true},
33 {name: 'existing name 2',
34 onCurrentDevice: false}]);
30 35
31 createProfileElement = createElement(); 36 createProfileElement = createElement();
32 37
33 // Make sure DOM is up to date. 38 // Make sure DOM is up to date.
34 Polymer.dom.flush(); 39 Polymer.dom.flush();
35 }); 40 });
36 41
37 teardown(function() { createProfileElement.remove(); }); 42 teardown(function() { createProfileElement.remove(); });
38 43
39 test('Handles available profile icons', function() { 44 test('Handles available profile icons', function() {
40 return browserProxy.whenCalled('getAvailableIcons').then(function() { 45 return browserProxy.whenCalled('getAvailableIcons').then(function() {
41 assertEquals('icon1.png', createProfileElement.profileIconUrl_); 46 assertEquals('icon1.png', createProfileElement.profileIconUrl_);
42 }); 47 });
43 }); 48 });
44 49
45 test('Handles signed in users', function() { 50 test('Handles signed in users', function() {
46 return browserProxy.whenCalled('getSignedInUsers').then(function() { 51 return browserProxy.whenCalled('getSignedInUsers').then(function() {
47 assertEquals(1, createProfileElement.signedInUsers_.length); 52 assertEquals(1, createProfileElement.signedInUsers_.length);
48 assertEquals('username', 53 assertEquals('username',
49 createProfileElement.signedInUsers_[0].username); 54 createProfileElement.signedInUsers_[0].username);
50 assertEquals('path/to/profile', 55 assertEquals('path/to/profile',
51 createProfileElement.signedInUsers_[0].profilePath); 56 createProfileElement.signedInUsers_[0].profilePath);
52 57
53 // The dropdown menu is populated. 58 // The 'learn more' link is visible.
59 assertTrue(!!createProfileElement.$$('#learn-more'));
60
61 // The dropdown menu is visible only when the checkbox is checked.
62 assertFalse(!!createProfileElement.$$('paper-dropdown-menu'));
63
64 // Simulate checking the checkbox.
65 MockInteractions.tap(createProfileElement.$$('paper-checkbox'));
54 Polymer.dom.flush(); 66 Polymer.dom.flush();
55 var users = createProfileElement.querySelectorAll('paper-item');
56 assertEquals(1, users.length);
57 67
58 assertTrue(createProfileElement.$.noSignedInUserContainer.hidden); 68 // The dropdown menu is visible and is populated with the sentinel
69 // item as well as the signed in users.
70 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
71 assertTrue(!!dropdownMenu);
72 var users = dropdownMenu.querySelectorAll('paper-item');
73 assertEquals(2, users.length);
59 }); 74 });
60 }); 75 });
61 76
62 test('Name is empty by default', function() { 77 test('Sentinel item is the initially selected item', function() {
63 assertEquals('', createProfileElement.$.nameInput.value); 78 return browserProxy.whenCalled('getSignedInUsers').then(function() {
79 // Simulate checking the checkbox.
80 MockInteractions.tap(createProfileElement.$$('paper-checkbox'));
81 Polymer.dom.flush();
82
83 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
84 var paperMenu = dropdownMenu.querySelector('paper-menu');
85 assertEquals(createProfileElement.i18n('selectAnAccount'),
86 paperMenu.selectedItem.textContent.trim());
87 });
88 });
89
90 test('Name is non-empty by default', function() {
91 assertEquals('profile name', createProfileElement.$.nameInput.value);
64 }); 92 });
65 93
66 test('Create button is disabled if name is empty or invalid', function() { 94 test('Create button is disabled if name is empty or invalid', function() {
67 assertEquals('', createProfileElement.$.nameInput.value); 95 assertEquals('profile name', createProfileElement.$.nameInput.value);
96 assertFalse(createProfileElement.$.nameInput.invalid);
97 assertFalse(createProfileElement.$.save.disabled);
98
99 createProfileElement.$.nameInput.value = '';
68 assertTrue(createProfileElement.$.save.disabled); 100 assertTrue(createProfileElement.$.save.disabled);
69 101
70 createProfileElement.$.nameInput.value = ' '; 102 createProfileElement.$.nameInput.value = ' ';
71 assertTrue(createProfileElement.$.nameInput.invalid); 103 assertTrue(createProfileElement.$.nameInput.invalid);
72 assertTrue(createProfileElement.$.save.disabled); 104 assertTrue(createProfileElement.$.save.disabled);
73
74 createProfileElement.$.nameInput.value = 'foo';
75 assertFalse(createProfileElement.$.nameInput.invalid);
76 assertFalse(createProfileElement.$.save.disabled);
77 }); 105 });
78 106
79 test('Create a profile', function() { 107 test('Create a profile', function() {
80 // Set the text in the name field. 108 // Simulate clicking 'Create'.
81 createProfileElement.$.nameInput.value = 'foo'; 109 MockInteractions.tap(createProfileElement.$.save);
110
111 return browserProxy.whenCalled('createProfile').then(function(args) {
112 assertEquals('profile name', args.profileName);
113 assertEquals('icon1.png', args.profileIconUrl);
114 assertFalse(args.isSupervised);
115 assertEquals('', args.custodianProfilePath);
116 });
117 });
118
119 test('Has to select a custodian for the supervised profile', function() {
120 // Simulate checking the checkbox.
121 MockInteractions.tap(createProfileElement.$$('paper-checkbox'));
122 Polymer.dom.flush();
123
124 // Simulate clicking 'Create'.
125 MockInteractions.tap(createProfileElement.$.save);
126
127 // Create is not in progress.
128 assertFalse(createProfileElement.createInProgress_);
129 // Message container is visible.
130 assertFalse(createProfileElement.$$('#message-container').hidden);
131 // Error message is set.
132 assertEquals(
133 createProfileElement.i18n('custodianAccountNotSelectedError'),
134 createProfileElement.$.message.innerHTML);
135 });
136
137 test('Supervised profile name is duplicate (on the device)', function() {
138 // Simulate checking the checkbox.
139 MockInteractions.tap(createProfileElement.$$('paper-checkbox'));
140 Polymer.dom.flush();
141
142 // There is an existing supervised user with this name on the device.
143 createProfileElement.$.nameInput.value = 'existing name 1';
144
145 // Select the first signed in user.
146 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
147 var paperMenu = dropdownMenu.querySelector('paper-menu');
148 paperMenu.selected = 0;
149
150 // Simulate clicking 'Create'.
151 MockInteractions.tap(createProfileElement.$.save);
152
153 return browserProxy.whenCalled('getExistingSupervisedUsers').then(
154 function(args) {
155 // Create is not in progress.
156 assertFalse(createProfileElement.createInProgress_);
157 // Message container is visible.
158 assertFalse(createProfileElement.$$('#message-container').hidden);
159 // Error message is set.
160 var message = createProfileElement.i18n(
161 'managedProfilesExistingLocalSupervisedUser');
162 assertEquals(message, createProfileElement.$.message.innerHTML);
163 });
164 });
165
166 test('Supervised profile name is duplicate (remote)', function() {
167 // Simulate checking the checkbox.
168 MockInteractions.tap(createProfileElement.$$('paper-checkbox'));
169 Polymer.dom.flush();
170
171 // There is an existing supervised user with this name on the device.
172 createProfileElement.$.nameInput.value = 'existing name 2';
173
174 // Select the first signed in user.
175 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
176 var paperMenu = dropdownMenu.querySelector('paper-menu');
177 paperMenu.selected = 0;
178
179 // Simulate clicking 'Create'.
180 MockInteractions.tap(createProfileElement.$.save);
181
182 return browserProxy.whenCalled('getExistingSupervisedUsers').then(
183 function(args) {
184 // Create is not in progress.
185 assertFalse(createProfileElement.createInProgress_);
186 // Message container is visible.
187 assertFalse(createProfileElement.$$('#message-container').hidden);
188 // Error message contains a link to import the supervised user.
189 var message = createProfileElement.$.message;
190 assertTrue(
191 !!message.querySelector('#supervised-user-import-existing'));
192 });
193 });
194
195 test('Create supervised profile', function() {
196 // Simulate checking the checkbox.
197 MockInteractions.tap(createProfileElement.$$('paper-checkbox'));
198 Polymer.dom.flush();
199
200 // Select the first signed in user.
201 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
202 var paperMenu = dropdownMenu.querySelector('paper-menu');
203 paperMenu.selected = 0;
82 204
83 // Simulate clicking 'Create'. 205 // Simulate clicking 'Create'.
84 MockInteractions.tap(createProfileElement.$.save); 206 MockInteractions.tap(createProfileElement.$.save);
85 207
86 return browserProxy.whenCalled('createProfile').then(function(args) { 208 return browserProxy.whenCalled('createProfile').then(function(args) {
87 assertEquals('foo', args.profileName); 209 assertEquals('profile name', args.profileName);
88 assertEquals('icon1.png', args.profileIconUrl);
89 assertFalse(args.isSupervised);
90 assertEquals('path/to/profile', args.supervisorProfilePath);
91 });
92 });
93
94 test('Create supervised profile', function() {
95 // Set the text in the name field.
96 createProfileElement.$.nameInput.value = 'foo';
97
98 // Simulate checking the checkbox.
99 MockInteractions.tap(createProfileElement.$$('paper-checkbox'));
100
101 // Simulate clicking 'Create'.
102 MockInteractions.tap(createProfileElement.$.save);
103
104 return browserProxy.whenCalled('createProfile').then(function(args) {
105 assertEquals('foo', args.profileName);
106 assertEquals('icon1.png', args.profileIconUrl); 210 assertEquals('icon1.png', args.profileIconUrl);
107 assertTrue(args.isSupervised); 211 assertTrue(args.isSupervised);
108 assertEquals('path/to/profile', args.supervisorProfilePath); 212 assertEquals('path/to/profile', args.custodianProfilePath);
109 }); 213 });
110 }); 214 });
111 215
112 test('Cancel creating a profile', function() { 216 test('Cancel creating a profile', function() {
113 // Set the text in the name field.
114 createProfileElement.$.nameInput.value = 'foo';
115
116 // Simulate clicking 'Create'. 217 // Simulate clicking 'Create'.
117 MockInteractions.tap(createProfileElement.$.save); 218 MockInteractions.tap(createProfileElement.$.save);
118 219
119 return browserProxy.whenCalled('createProfile').then(function(args) { 220 return browserProxy.whenCalled('createProfile').then(function(args) {
120 // The 'Save' button is disabled when create is in progress. 221 // The 'Save' button is disabled when create is in progress.
121 assertTrue(createProfileElement.createInProgress_); 222 assertTrue(createProfileElement.createInProgress_);
122 assertTrue(createProfileElement.$.save.disabled); 223 assertTrue(createProfileElement.$.save.disabled);
123 224
124 // Simulate clicking 'Cancel'. 225 // Simulate clicking 'Cancel'.
125 MockInteractions.tap(createProfileElement.$.cancel); 226 MockInteractions.tap(createProfileElement.$.cancel);
126 return browserProxy.whenCalled('cancelCreateProfile').then( 227 return browserProxy.whenCalled('cancelCreateProfile').then(
127 function() { 228 function() {
128 // The 'Save' button is enabled when create is not in progress. 229 // The 'Save' button is enabled when create is not in progress.
129 assertFalse(createProfileElement.createInProgress_); 230 assertFalse(createProfileElement.createInProgress_);
130 assertFalse(createProfileElement.$.save.disabled); 231 assertFalse(createProfileElement.$.save.disabled);
131 }); 232 });
132 }); 233 });
133 }); 234 });
134 235
135 test('Leave the page by clicking the Cancel button', function() { 236 test('Leave the page by clicking the Cancel button', function() {
136 return new Promise(function(resolve, reject) { 237 return new Promise(function(resolve, reject) {
137 // Create is not in progress. We expect to leave the page. 238 // Create is not in progress. We expect to leave the page.
138 createProfileElement.addEventListener('change-page', function() { 239 createProfileElement.addEventListener('change-page', function(event) {
139 // This should not be called if create is not in progress. 240 // This should not be called if create is not in progress.
140 if (!browserProxy.cancelCreateProfileCalled) 241 if (!browserProxy.cancelCreateProfileCalled &&
242 event.detail.page == 'user-pods-page') {
141 resolve(); 243 resolve();
244 }
142 }); 245 });
143 246
144 // Simulate clicking 'Cancel'. 247 // Simulate clicking 'Cancel'.
145 MockInteractions.tap(createProfileElement.$.cancel); 248 MockInteractions.tap(createProfileElement.$.cancel);
146 }); 249 });
147 }); 250 });
148 251
149 test('Create profile success', function() { 252 test('Create profile success', function() {
150 return new Promise(function(resolve, reject) { 253 return new Promise(function(resolve, reject) {
151 // Create was successful. We expect to leave the page. 254 // Create was successful. We expect to leave the page.
152 createProfileElement.addEventListener('change-page', resolve); 255 createProfileElement.addEventListener('change-page', resolve);
153 256
154 // Set the text in the name field.
155 createProfileElement.$.nameInput.value = 'foo';
156
157 // Simulate clicking 'Create'. 257 // Simulate clicking 'Create'.
158 MockInteractions.tap(createProfileElement.$.save); 258 MockInteractions.tap(createProfileElement.$.save);
159 259
160 browserProxy.whenCalled('createProfile').then(function(args) { 260 browserProxy.whenCalled('createProfile').then(function(args) {
161 // The paper-spinner is active when create is in progress. 261 // The paper-spinner is active when create is in progress.
162 assertTrue(createProfileElement.createInProgress_); 262 assertTrue(createProfileElement.createInProgress_);
163 assertTrue(createProfileElement.$$('paper-spinner').active); 263 assertTrue(createProfileElement.$$('paper-spinner').active);
164 264
165 cr.webUIListenerCallback('create-profile-success'); 265 cr.webUIListenerCallback('create-profile-success');
166 // The paper-spinner is not active when create is not in progress. 266 // The paper-spinner is not active when create is not in progress.
167 assertFalse(createProfileElement.createInProgress_); 267 assertFalse(createProfileElement.createInProgress_);
168 assertFalse(createProfileElement.$$('paper-spinner').active); 268 assertFalse(createProfileElement.$$('paper-spinner').active);
169 }); 269 });
170 }); 270 });
171 }); 271 });
172 272
173 test('Create profile error', function() { 273 test('Create profile error', function() {
174 // Set the text in the name field.
175 createProfileElement.$.nameInput.value = 'foo';
176
177 // Simulate clicking 'Create'. 274 // Simulate clicking 'Create'.
178 MockInteractions.tap(createProfileElement.$.save); 275 MockInteractions.tap(createProfileElement.$.save);
179 276
180 return browserProxy.whenCalled('createProfile').then(function(args) { 277 return browserProxy.whenCalled('createProfile').then(function(args) {
181 cr.webUIListenerCallback('create-profile-error', 'Error Message'); 278 cr.webUIListenerCallback('create-profile-error', 'Error Message');
182 279
183 // Create is no longer in progress. 280 // Create is no longer in progress.
184 assertFalse(createProfileElement.createInProgress_); 281 assertFalse(createProfileElement.createInProgress_);
185 // Error message is set. 282 // Error message is set.
186 assertEquals('Error Message', 283 assertEquals('Error Message',
187 createProfileElement.$.messageBubble.innerHTML); 284 createProfileElement.$.message.innerHTML);
188 }); 285 });
189 }); 286 });
190 287
191 test('Create profile warning', function() { 288 test('Create profile warning', function() {
192 // Set the text in the name field. 289 // Set the text in the name field.
193 createProfileElement.$.nameInput.value = 'foo'; 290 createProfileElement.$.nameInput.value = 'foo';
194 291
195 // Simulate clicking 'Create'. 292 // Simulate clicking 'Create'.
196 MockInteractions.tap(createProfileElement.$.save); 293 MockInteractions.tap(createProfileElement.$.save);
197 294
198 return browserProxy.whenCalled('createProfile').then(function(args) { 295 return browserProxy.whenCalled('createProfile').then(function(args) {
199 cr.webUIListenerCallback('create-profile-warning', 296 cr.webUIListenerCallback('create-profile-warning',
200 'Warning Message'); 297 'Warning Message');
201 298
202 // Create is no longer in progress. 299 // Create is no longer in progress.
203 assertFalse(createProfileElement.createInProgress_); 300 assertFalse(createProfileElement.createInProgress_);
204 // Warning message is set. 301 // Warning message is set.
205 assertEquals('Warning Message', 302 assertEquals('Warning Message',
206 createProfileElement.$.messageBubble.innerHTML); 303 createProfileElement.$.message.innerHTML);
304 });
305 });
306
307 test('Learn more link takes you to the correct page', function() {
308 return new Promise(function(resolve, reject) {
309 // Create is not in progress. We expect to leave the page.
310 createProfileElement.addEventListener('change-page', function(event) {
311 if (event.detail.page == 'supervised-learn-more-page')
312 resolve();
313 });
314
315 // Simulate clicking 'Learn more'.
316 MockInteractions.tap(createProfileElement.$$('#learn-more'));
207 }); 317 });
208 }); 318 });
209 }); 319 });
210 320
211 suite('CreateProfileTestsNoSignedInUser', function() { 321 suite('CreateProfileTestsNoSignedInUser', function() {
212 setup(function() { 322 setup(function() {
213 browserProxy = new TestProfileBrowserProxy(); 323 browserProxy = new TestProfileBrowserProxy();
214 // Replace real proxy with mock proxy. 324 // Replace real proxy with mock proxy.
215 signin.ProfileBrowserProxyImpl.instance_ = browserProxy; 325 signin.ProfileBrowserProxyImpl.instance_ = browserProxy;
216 326
217 createProfileElement = createElement(); 327 createProfileElement = createElement();
218 328
219 // Make sure DOM is up to date. 329 // Make sure DOM is up to date.
220 Polymer.dom.flush(); 330 Polymer.dom.flush();
221 }); 331 });
222 332
223 teardown(function() { createProfileElement.remove(); }); 333 teardown(function() { createProfileElement.remove(); });
224 334
225 test('Handles no signed in users', function() { 335 test('Handles no signed in users', function() {
226 return browserProxy.whenCalled('getSignedInUsers').then(function() { 336 return browserProxy.whenCalled('getSignedInUsers').then(function() {
227 assertEquals(0, createProfileElement.signedInUsers_.length); 337 assertEquals(0, createProfileElement.signedInUsers_.length);
228 338
229 // The dropdown menu is empty. 339 // '#supervised-user-container' is not present in the DOM.
230 var users = createProfileElement.querySelectorAll('paper-item'); 340 var container = createProfileElement.$$('#supervised-user-container');
231 assertEquals(0, users.length); 341 assertFalse(!!container);
232
233 assertFalse(createProfileElement.$.noSignedInUserContainer.hidden);
234 }); 342 });
235 }); 343 });
236 344
237 test('Create button is disabled', function() { 345 test('Create button is disabled', function() {
238 assertTrue(createProfileElement.$.save.disabled); 346 assertTrue(createProfileElement.$.save.disabled);
239 }); 347 });
240 }); 348 });
241 } 349 }
242 350
243 return { 351 return {
244 registerTests: registerTests, 352 registerTests: registerTests,
245 }; 353 };
246 }); 354 });
OLDNEW
« no previous file with comments | « chrome/chrome_browser_ui.gypi ('k') | chrome/test/data/webui/md_user_manager/test_profile_browser_proxy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698