OLD | NEW |
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); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 test('Handles signed in users', function() { | 50 test('Handles signed in users', function() { |
51 return browserProxy.whenCalled('getSignedInUsers').then(function() { | 51 return browserProxy.whenCalled('getSignedInUsers').then(function() { |
52 assertEquals(1, createProfileElement.signedInUsers_.length); | 52 assertEquals(1, createProfileElement.signedInUsers_.length); |
53 assertEquals('username', | 53 assertEquals('username', |
54 createProfileElement.signedInUsers_[0].username); | 54 createProfileElement.signedInUsers_[0].username); |
55 assertEquals('path/to/profile', | 55 assertEquals('path/to/profile', |
56 createProfileElement.signedInUsers_[0].profilePath); | 56 createProfileElement.signedInUsers_[0].profilePath); |
57 | 57 |
58 // The 'learn more' link is visible. | 58 // The 'learn more' link is visible. |
59 assertTrue(!!createProfileElement.$$('#learn-more')); | 59 assertTrue(!!createProfileElement.$$('#learn-more > a')); |
60 | 60 |
61 // The dropdown menu is visible only when the checkbox is checked. | 61 // The dropdown menu becomes visible when the checkbox is checked. |
62 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); | 62 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); |
63 | 63 |
64 // Simulate checking the checkbox. | 64 // Simulate checking the checkbox. |
65 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 65 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
66 Polymer.dom.flush(); | 66 Polymer.dom.flush(); |
67 | 67 |
68 // The dropdown menu is visible and is populated with the sentinel | 68 // The dropdown menu is visible and is populated with the sentinel |
69 // item as well as the signed in users. | 69 // item as well as the signed in users. |
70 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 70 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
71 assertTrue(!!dropdownMenu); | 71 assertTrue(!!dropdownMenu); |
72 var users = dropdownMenu.querySelectorAll('paper-item'); | 72 var users = dropdownMenu.querySelectorAll('paper-item'); |
73 assertEquals(2, users.length); | 73 assertEquals(2, users.length); |
74 }); | 74 }); |
75 }); | 75 }); |
76 | 76 |
77 test('Sentinel item is the initially selected item', function() { | 77 test('Sentinel item is the initially selected item', function() { |
78 return browserProxy.whenCalled('getSignedInUsers').then(function() { | 78 return browserProxy.whenCalled('getSignedInUsers').then(function() { |
79 // Simulate checking the checkbox. | 79 // Simulate checking the checkbox. |
80 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 80 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
81 Polymer.dom.flush(); | 81 Polymer.dom.flush(); |
82 | 82 |
83 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 83 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
84 var paperMenu = dropdownMenu.querySelector('paper-menu'); | 84 var selector = dropdownMenu.querySelector('paper-listbox'); |
85 assertEquals(loadTimeData.getString('selectAnAccount'), | 85 assertEquals(loadTimeData.getString('selectAnAccount'), |
86 paperMenu.selectedItem.textContent.trim()); | 86 selector.selectedItem.textContent.trim()); |
87 }); | 87 }); |
88 }); | 88 }); |
89 | 89 |
90 test('Name is non-empty by default', function() { | 90 test('Name is non-empty by default', function() { |
91 assertEquals('profile name', createProfileElement.$.nameInput.value); | 91 assertEquals('profile name', createProfileElement.$.nameInput.value); |
92 }); | 92 }); |
93 | 93 |
94 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() { |
95 assertEquals('profile name', createProfileElement.$.nameInput.value); | 95 assertEquals('profile name', createProfileElement.$.nameInput.value); |
96 assertFalse(createProfileElement.$.nameInput.invalid); | 96 assertFalse(createProfileElement.$.nameInput.invalid); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 test('Supervised profile name is duplicate (on the device)', function() { | 138 test('Supervised profile name is duplicate (on the device)', function() { |
139 // Simulate checking the checkbox. | 139 // Simulate checking the checkbox. |
140 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 140 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
141 Polymer.dom.flush(); | 141 Polymer.dom.flush(); |
142 | 142 |
143 // There is an existing supervised user with this name on the device. | 143 // There is an existing supervised user with this name on the device. |
144 createProfileElement.$.nameInput.value = 'existing name 1'; | 144 createProfileElement.$.nameInput.value = 'existing name 1'; |
145 | 145 |
146 // Select the first signed in user. | 146 // Select the first signed in user. |
147 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 147 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
148 var paperMenu = dropdownMenu.querySelector('paper-menu'); | 148 var selector = dropdownMenu.querySelector('paper-listbox'); |
149 paperMenu.selected = 0; | 149 selector.selected = 0; |
150 | 150 |
151 // Simulate clicking 'Create'. | 151 // Simulate clicking 'Create'. |
152 MockInteractions.tap(createProfileElement.$.save); | 152 MockInteractions.tap(createProfileElement.$.save); |
153 | 153 |
154 return browserProxy.whenCalled('getExistingSupervisedUsers').then( | 154 return browserProxy.whenCalled('getExistingSupervisedUsers').then( |
155 function(args) { | 155 function(args) { |
156 // Create is not in progress. | 156 // Create is not in progress. |
157 assertFalse(createProfileElement.createInProgress_); | 157 assertFalse(createProfileElement.createInProgress_); |
158 // Message container is visible. | 158 // Message container is visible. |
159 assertFalse(createProfileElement.$$('#message-container').hidden); | 159 assertFalse(createProfileElement.$$('#message-container').hidden); |
160 // Error message is set. | 160 // Error message is set. |
161 var message = loadTimeData.getString( | 161 var message = loadTimeData.getString( |
162 'managedProfilesExistingLocalSupervisedUser'); | 162 'managedProfilesExistingLocalSupervisedUser'); |
163 assertEquals(message, createProfileElement.$.message.innerHTML); | 163 assertEquals(message, createProfileElement.$.message.innerHTML); |
164 }); | 164 }); |
165 }); | 165 }); |
166 | 166 |
167 test('Supervised profile name is duplicate (remote)', function() { | 167 test('Supervised profile name is duplicate (remote)', function() { |
168 // Simulate checking the checkbox. | 168 // Simulate checking the checkbox. |
169 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 169 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
170 Polymer.dom.flush(); | 170 Polymer.dom.flush(); |
171 | 171 |
172 // There is an existing supervised user with this name on the device. | 172 // There is an existing supervised user with this name on the device. |
173 createProfileElement.$.nameInput.value = 'existing name 2'; | 173 createProfileElement.$.nameInput.value = 'existing name 2'; |
174 | 174 |
175 // Select the first signed in user. | 175 // Select the first signed in user. |
176 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 176 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
177 var paperMenu = dropdownMenu.querySelector('paper-menu'); | 177 var selector = dropdownMenu.querySelector('paper-listbox'); |
178 paperMenu.selected = 0; | 178 selector.selected = 0; |
179 | 179 |
180 // Simulate clicking 'Create'. | 180 // Simulate clicking 'Create'. |
181 MockInteractions.tap(createProfileElement.$.save); | 181 MockInteractions.tap(createProfileElement.$.save); |
182 | 182 |
183 return browserProxy.whenCalled('getExistingSupervisedUsers').then( | 183 return browserProxy.whenCalled('getExistingSupervisedUsers').then( |
184 function(args) { | 184 function(args) { |
185 // Create is not in progress. | 185 // Create is not in progress. |
186 assertFalse(createProfileElement.createInProgress_); | 186 assertFalse(createProfileElement.createInProgress_); |
187 // Message container is visible. | 187 // Message container is visible. |
188 assertFalse(createProfileElement.$$('#message-container').hidden); | 188 assertFalse(createProfileElement.$$('#message-container').hidden); |
189 // Error message contains a link to import the supervised user. | 189 // Error message contains a link to import the supervised user. |
190 var message = createProfileElement.$.message; | 190 var message = createProfileElement.$.message; |
191 assertTrue( | 191 assertTrue( |
192 !!message.querySelector('#supervised-user-import-existing')); | 192 !!message.querySelector('#supervised-user-import-existing')); |
193 }); | 193 }); |
194 }); | 194 }); |
195 | 195 |
196 test('Create supervised profile', function() { | 196 test('Create supervised profile', function() { |
197 // Simulate checking the checkbox. | 197 // Simulate checking the checkbox. |
198 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 198 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
199 Polymer.dom.flush(); | 199 Polymer.dom.flush(); |
200 | 200 |
201 // Select the first signed in user. | 201 // Select the first signed in user. |
202 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 202 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
203 var paperMenu = dropdownMenu.querySelector('paper-menu'); | 203 var selector = dropdownMenu.querySelector('paper-listbox'); |
204 paperMenu.selected = 0; | 204 selector.selected = 0; |
205 | 205 |
206 // Simulate clicking 'Create'. | 206 // Simulate clicking 'Create'. |
207 MockInteractions.tap(createProfileElement.$.save); | 207 MockInteractions.tap(createProfileElement.$.save); |
208 | 208 |
209 return browserProxy.whenCalled('createProfile').then(function(args) { | 209 return browserProxy.whenCalled('createProfile').then(function(args) { |
210 assertEquals('profile name', args.profileName); | 210 assertEquals('profile name', args.profileName); |
211 assertEquals('icon1.png', args.profileIconUrl); | 211 assertEquals('icon1.png', args.profileIconUrl); |
212 assertTrue(args.isSupervised); | 212 assertTrue(args.isSupervised); |
213 assertEquals('', args.supervisedUserId); | 213 assertEquals('', args.supervisedUserId); |
214 assertEquals('path/to/profile', args.custodianProfilePath); | 214 assertEquals('path/to/profile', args.custodianProfilePath); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 348 |
349 test('Learn more link takes you to the correct page', function() { | 349 test('Learn more link takes you to the correct page', function() { |
350 return new Promise(function(resolve, reject) { | 350 return new Promise(function(resolve, reject) { |
351 // Create is not in progress. We expect to leave the page. | 351 // Create is not in progress. We expect to leave the page. |
352 createProfileElement.addEventListener('change-page', function(event) { | 352 createProfileElement.addEventListener('change-page', function(event) { |
353 if (event.detail.page == 'supervised-learn-more-page') | 353 if (event.detail.page == 'supervised-learn-more-page') |
354 resolve(); | 354 resolve(); |
355 }); | 355 }); |
356 | 356 |
357 // Simulate clicking 'Learn more'. | 357 // Simulate clicking 'Learn more'. |
358 MockInteractions.tap(createProfileElement.$$('#learn-more')); | 358 MockInteractions.tap(createProfileElement.$$('#learn-more > a')); |
359 }); | 359 }); |
360 }); | 360 }); |
361 }); | 361 }); |
362 | 362 |
363 suite('CreateProfileTestsNoSignedInUser', function() { | 363 suite('CreateProfileTestsNoSignedInUser', function() { |
364 setup(function() { | 364 setup(function() { |
365 browserProxy = new TestProfileBrowserProxy(); | 365 browserProxy = new TestProfileBrowserProxy(); |
366 // Replace real proxy with mock proxy. | 366 // Replace real proxy with mock proxy. |
367 signin.ProfileBrowserProxyImpl.instance_ = browserProxy; | 367 signin.ProfileBrowserProxyImpl.instance_ = browserProxy; |
368 | 368 |
369 createProfileElement = createElement(); | 369 createProfileElement = createElement(); |
370 | 370 |
371 // Make sure DOM is up to date. | 371 // Make sure DOM is up to date. |
372 Polymer.dom.flush(); | 372 Polymer.dom.flush(); |
373 }); | 373 }); |
374 | 374 |
375 teardown(function() { createProfileElement.remove(); }); | 375 teardown(function() { createProfileElement.remove(); }); |
376 | 376 |
377 test('Handles no signed in users', function() { | 377 test('Handles no signed in users', function() { |
378 return browserProxy.whenCalled('getSignedInUsers').then(function() { | 378 return browserProxy.whenCalled('getSignedInUsers').then(function() { |
379 assertEquals(0, createProfileElement.signedInUsers_.length); | 379 assertEquals(0, createProfileElement.signedInUsers_.length); |
380 | 380 |
381 // '#supervised-user-container' is not present in the DOM. | 381 // Simulate checking the checkbox. |
382 var container = createProfileElement.$$('#supervised-user-container'); | 382 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
383 assertFalse(!!container); | 383 Polymer.dom.flush(); |
| 384 |
| 385 // The dropdown menu is not visible when there are no signed in users. |
| 386 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); |
| 387 |
| 388 // Instead a message containing a link to the Help Center on how |
| 389 // to sign in to Chrome is displaying. |
| 390 assertTrue(!!createProfileElement.$$('#sign-in-to-chrome')); |
384 }); | 391 }); |
385 }); | 392 }); |
386 | 393 |
387 test('Create button is disabled', function() { | 394 test('Create button is disabled', function() { |
388 assertTrue(createProfileElement.$.save.disabled); | 395 assertTrue(createProfileElement.$.save.disabled); |
389 }); | 396 }); |
390 }); | 397 }); |
391 } | 398 } |
392 | 399 |
393 return { | 400 return { |
394 registerTests: registerTests, | 401 registerTests: registerTests, |
395 }; | 402 }; |
396 }); | 403 }); |
OLD | NEW |