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

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

Issue 2938933002: WebUI: swap paper-dropdown-menu out for md-select. (Closed)
Patch Set: fix test Created 3 years, 6 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 var createProfileElement = document.createElement('create-profile'); 8 var createProfileElement = document.createElement('create-profile');
9 document.body.appendChild(createProfileElement); 9 document.body.appendChild(createProfileElement);
10 return createProfileElement; 10 return createProfileElement;
11 } 11 }
12 12
13 function registerTests() { 13 function registerTests() {
14 /** @type {?TestProfileBrowserProxy} */ 14 /** @type {?TestProfileBrowserProxy} */
15 var browserProxy = null; 15 var browserProxy = null;
16 16
17 /** @type {?CreateProfileElement} */ 17 /** @type {?CreateProfileElement} */
18 var createProfileElement = null; 18 var createProfileElement = null;
19 19
20 // Helper to select first signed in user from a dropdown menu.
21 var selectFirstSignedInUser = function(dropdownMenu) {
22 var option = dropdownMenu.querySelector('option:not([disabled])');
23 dropdownMenu.value = option.value;
24 dropdownMenu.dispatchEvent(new Event('change'));
25 };
26
20 suite('CreateProfileTests', function() { 27 suite('CreateProfileTests', function() {
21 setup(function() { 28 setup(function() {
22 browserProxy = new TestProfileBrowserProxy(); 29 browserProxy = new TestProfileBrowserProxy();
23 30
24 // Replace real proxy with mock proxy. 31 // Replace real proxy with mock proxy.
25 signin.ProfileBrowserProxyImpl.instance_ = browserProxy; 32 signin.ProfileBrowserProxyImpl.instance_ = browserProxy;
26 browserProxy.setDefaultProfileInfo({name: 'profile name'}); 33 browserProxy.setDefaultProfileInfo({name: 'profile name'});
27 browserProxy.setIcons([{url: 'icon1.png', label: 'icon1'}, 34 browserProxy.setIcons([{url: 'icon1.png', label: 'icon1'},
28 {url: 'icon2.png', label: 'icon2'}]); 35 {url: 'icon2.png', label: 'icon2'}]);
29 browserProxy.setSignedInUsers([{username: 'username', 36 browserProxy.setSignedInUsers([{username: 'username',
(...skipping 26 matching lines...) Expand all
56 assertEquals(1, createProfileElement.signedInUsers_.length); 63 assertEquals(1, createProfileElement.signedInUsers_.length);
57 assertEquals('username', 64 assertEquals('username',
58 createProfileElement.signedInUsers_[0].username); 65 createProfileElement.signedInUsers_[0].username);
59 assertEquals('path/to/profile', 66 assertEquals('path/to/profile',
60 createProfileElement.signedInUsers_[0].profilePath); 67 createProfileElement.signedInUsers_[0].profilePath);
61 68
62 // The 'learn more' link is visible. 69 // The 'learn more' link is visible.
63 assertTrue(!!createProfileElement.$$('#learn-more > a')); 70 assertTrue(!!createProfileElement.$$('#learn-more > a'));
64 71
65 // The dropdown menu becomes visible when the checkbox is checked. 72 // The dropdown menu becomes visible when the checkbox is checked.
66 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); 73 assertFalse(!!createProfileElement.$$('.md-select'));
67 74
68 // Simulate checking the supervised user checkbox. 75 // Simulate checking the supervised user checkbox.
69 MockInteractions.tap( 76 MockInteractions.tap(
70 createProfileElement.$$("#makeSupervisedCheckbox")); 77 createProfileElement.$$("#makeSupervisedCheckbox"));
71 Polymer.dom.flush(); 78 Polymer.dom.flush();
72 79
73 // The dropdown menu is visible and is populated with signed in users. 80 // The dropdown menu is visible and is populated with signed in users.
74 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); 81 var dropdownMenu = createProfileElement.$$('.md-select');
75 assertTrue(!!dropdownMenu); 82 assertTrue(!!dropdownMenu);
76 var users = dropdownMenu.querySelectorAll('paper-item'); 83 var users = dropdownMenu.querySelectorAll('option:not([disabled])');
77 assertEquals(1, users.length); 84 assertEquals(1, users.length);
78 }); 85 });
79 }); 86 });
80 87
81 test('Name is non-empty by default', function() { 88 test('Name is non-empty by default', function() {
82 assertEquals('profile name', createProfileElement.$.nameInput.value); 89 assertEquals('profile name', createProfileElement.$.nameInput.value);
83 }); 90 });
84 91
85 test('Create button is disabled if name is empty or invalid', function() { 92 test('Create button is disabled if name is empty or invalid', function() {
86 assertEquals('profile name', createProfileElement.$.nameInput.value); 93 assertEquals('profile name', createProfileElement.$.nameInput.value);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 }); 143 });
137 144
138 test('Supervised profile name is duplicate (on the device)', function() { 145 test('Supervised profile name is duplicate (on the device)', function() {
139 // Simulate checking the supervised user checkbox. 146 // Simulate checking the supervised user checkbox.
140 MockInteractions.tap( 147 MockInteractions.tap(
141 createProfileElement.$$("#makeSupervisedCheckbox")); 148 createProfileElement.$$("#makeSupervisedCheckbox"));
142 Polymer.dom.flush(); 149 Polymer.dom.flush();
143 150
144 // There is an existing supervised user with this name on the device. 151 // There is an existing supervised user with this name on the device.
145 createProfileElement.$.nameInput.value = 'existing name 1'; 152 createProfileElement.$.nameInput.value = 'existing name 1';
146 153 selectFirstSignedInUser(createProfileElement.$$('.md-select'));
147 // Select the first signed in user.
148 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
149 var selector = dropdownMenu.querySelector('paper-listbox');
150 selector.selected = 0;
151 154
152 // Simulate clicking 'Create'. 155 // Simulate clicking 'Create'.
153 MockInteractions.tap(createProfileElement.$.save); 156 MockInteractions.tap(createProfileElement.$.save);
154 157
155 return browserProxy.whenCalled('getExistingSupervisedUsers').then( 158 return browserProxy.whenCalled('getExistingSupervisedUsers').then(
156 function(args) { 159 function(args) {
157 // Create is not in progress. 160 // Create is not in progress.
158 assertFalse(createProfileElement.createInProgress_); 161 assertFalse(createProfileElement.createInProgress_);
159 // Message container is visible. 162 // Message container is visible.
160 var messageContainer = 163 var messageContainer =
161 createProfileElement.$$('#message-container'); 164 createProfileElement.$$('#message-container');
162 assertTrue(messageContainer.clientHeight > 0); 165 assertTrue(messageContainer.clientHeight > 0);
163 // Error message is set. 166 // Error message is set.
164 var message = loadTimeData.getString( 167 var message = loadTimeData.getString(
165 'managedProfilesExistingLocalSupervisedUser'); 168 'managedProfilesExistingLocalSupervisedUser');
166 assertEquals(message, createProfileElement.$.message.innerHTML); 169 assertEquals(message, createProfileElement.$.message.innerHTML);
167 }); 170 });
168 }); 171 });
169 172
170 test('Supervised profile name is duplicate (remote)', function() { 173 test('Supervised profile name is duplicate (remote)', function() {
171 // Simulate checking the supervised user checkbox. 174 // Simulate checking the supervised user checkbox.
172 MockInteractions.tap( 175 MockInteractions.tap(
173 createProfileElement.$$("#makeSupervisedCheckbox")); 176 createProfileElement.$$("#makeSupervisedCheckbox"));
174 Polymer.dom.flush(); 177 Polymer.dom.flush();
175 178
176 // There is an existing supervised user with this name on the device. 179 // There is an existing supervised user with this name on the device.
177 createProfileElement.$.nameInput.value = 'existing name 2'; 180 createProfileElement.$.nameInput.value = 'existing name 2';
178 181 selectFirstSignedInUser(createProfileElement.$$('.md-select'));
179 // Select the first signed in user.
180 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
181 var selector = dropdownMenu.querySelector('paper-listbox');
182 selector.selected = 0;
183 182
184 // Simulate clicking 'Create'. 183 // Simulate clicking 'Create'.
185 MockInteractions.tap(createProfileElement.$.save); 184 MockInteractions.tap(createProfileElement.$.save);
186 185
187 return browserProxy.whenCalled('getExistingSupervisedUsers').then( 186 return browserProxy.whenCalled('getExistingSupervisedUsers').then(
188 function(args) { 187 function(args) {
189 // Create is not in progress. 188 // Create is not in progress.
190 assertFalse(createProfileElement.createInProgress_); 189 assertFalse(createProfileElement.createInProgress_);
191 // Message container is visible. 190 // Message container is visible.
192 var messageContainer = 191 var messageContainer =
193 createProfileElement.$$('#message-container'); 192 createProfileElement.$$('#message-container');
194 assertTrue(messageContainer.clientHeight > 0); 193 assertTrue(messageContainer.clientHeight > 0);
195 // Error message contains a link to import the supervised user. 194 // Error message contains a link to import the supervised user.
196 var message = createProfileElement.$.message; 195 var message = createProfileElement.$.message;
197 assertTrue( 196 assertTrue(
198 !!message.querySelector('#supervised-user-import-existing')); 197 !!message.querySelector('#supervised-user-import-existing'));
199 }); 198 });
200 }); 199 });
201 200
202 test('Displays error if custodian has no supervised users', function() { 201 test('Displays error if custodian has no supervised users', function() {
203 browserProxy.setExistingSupervisedUsers([]); 202 browserProxy.setExistingSupervisedUsers([]);
204 203
205 // Simulate checking the supervised user checkbox. 204 // Simulate checking the supervised user checkbox.
206 MockInteractions.tap( 205 MockInteractions.tap(
207 createProfileElement.$$("#makeSupervisedCheckbox")); 206 createProfileElement.$$("#makeSupervisedCheckbox"));
208 Polymer.dom.flush(); 207 Polymer.dom.flush();
209 208
210 // Select the first signed in user. 209 selectFirstSignedInUser(createProfileElement.$$('.md-select'));
211 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu');
212 var selector = dropdownMenu.querySelector('paper-listbox');
213 selector.selected = 0;
214 210
215 // Simulate clicking 'Import supervised user'. 211 // Simulate clicking 'Import supervised user'.
216 MockInteractions.tap(createProfileElement.$$('#import-user')); 212 MockInteractions.tap(createProfileElement.$$('#import-user'));
217 213
218 return browserProxy.whenCalled('getExistingSupervisedUsers').then( 214 return browserProxy.whenCalled('getExistingSupervisedUsers').then(
219 function(args) { 215 function(args) {
220 // Create is not in progress. 216 // Create is not in progress.
221 assertFalse(createProfileElement.createInProgress_); 217 assertFalse(createProfileElement.createInProgress_);
222 // Message container is visible. 218 // Message container is visible.
223 var messageContainer = 219 var messageContainer =
224 createProfileElement.$$('#message-container'); 220 createProfileElement.$$('#message-container');
225 assertTrue(messageContainer.clientHeight > 0); 221 assertTrue(messageContainer.clientHeight > 0);
226 // Error message is set. 222 // Error message is set.
227 var message = loadTimeData.getString( 223 var message = loadTimeData.getString(
228 'noSupervisedUserImportText'); 224 'noSupervisedUserImportText');
229 assertEquals(message, createProfileElement.$.message.innerHTML); 225 assertEquals(message, createProfileElement.$.message.innerHTML);
230 }); 226 });
231 }); 227 });
232 228
233 test('Create supervised profile', function() { 229 test('Create supervised profile', function() {
234 // Simulate checking the supervised user checkbox. 230 // Simulate checking the supervised user checkbox.
235 MockInteractions.tap( 231 MockInteractions.tap(
236 createProfileElement.$$("#makeSupervisedCheckbox")); 232 createProfileElement.$$("#makeSupervisedCheckbox"));
237 Polymer.dom.flush(); 233 Polymer.dom.flush();
238 234
239 // Select the first signed in user. 235 // Select the first signed in user.
240 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); 236 selectFirstSignedInUser(createProfileElement.$$('.md-select'));
241 var selector = dropdownMenu.querySelector('paper-listbox');
242 selector.selected = 0;
243 237
244 // Simulate clicking 'Create'. 238 // Simulate clicking 'Create'.
245 MockInteractions.tap(createProfileElement.$.save); 239 MockInteractions.tap(createProfileElement.$.save);
246 240
247 return browserProxy.whenCalled('createProfile').then(function(args) { 241 return browserProxy.whenCalled('createProfile').then(function(args) {
248 assertEquals('profile name', args.profileName); 242 assertEquals('profile name', args.profileName);
249 assertEquals('icon1.png', args.profileIconUrl); 243 assertEquals('icon1.png', args.profileIconUrl);
250 assertFalse(args.createShortcut); 244 assertFalse(args.createShortcut);
251 assertTrue(args.isSupervised); 245 assertTrue(args.isSupervised);
252 assertEquals('', args.supervisedUserId); 246 assertEquals('', args.supervisedUserId);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 test('Handles no signed in users', function() { 416 test('Handles no signed in users', function() {
423 return browserProxy.whenCalled('getSignedInUsers').then(function() { 417 return browserProxy.whenCalled('getSignedInUsers').then(function() {
424 assertEquals(0, createProfileElement.signedInUsers_.length); 418 assertEquals(0, createProfileElement.signedInUsers_.length);
425 419
426 // Simulate checking the supervised user checkbox. 420 // Simulate checking the supervised user checkbox.
427 MockInteractions.tap( 421 MockInteractions.tap(
428 createProfileElement.$$("#makeSupervisedCheckbox")); 422 createProfileElement.$$("#makeSupervisedCheckbox"));
429 Polymer.dom.flush(); 423 Polymer.dom.flush();
430 424
431 // The dropdown menu is not visible when there are no signed in users. 425 // The dropdown menu is not visible when there are no signed in users.
432 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); 426 assertFalse(!!createProfileElement.$$('.md-select'));
433 427
434 // Instead a message containing a link to the Help Center on how 428 // Instead a message containing a link to the Help Center on how
435 // to sign in to Chrome is displaying. 429 // to sign in to Chrome is displaying.
436 assertTrue(!!createProfileElement.$$('#sign-in-to-chrome')); 430 assertTrue(!!createProfileElement.$$('#sign-in-to-chrome'));
437 }); 431 });
438 }); 432 });
439 433
440 test('Create button is disabled', function() { 434 test('Create button is disabled', function() {
441 assertTrue(createProfileElement.$.save.disabled); 435 assertTrue(createProfileElement.$.save.disabled);
442 }); 436 });
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 createProfileElement.$$("#makeSupervisedCheckbox"); 546 createProfileElement.$$("#makeSupervisedCheckbox");
553 assertTrue(createSupervisedUserCheckbox.clientHeight > 0); 547 assertTrue(createSupervisedUserCheckbox.clientHeight > 0);
554 }); 548 });
555 }); 549 });
556 } 550 }
557 551
558 return { 552 return {
559 registerTests: registerTests, 553 registerTests: registerTests,
560 }; 554 };
561 }); 555 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/extensions/extension_keyboard_shortcuts_test.js ('k') | ui/webui/resources/html/md_select_css.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698