Chromium Code Reviews| 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 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; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 createProfileElement.signedInUsers_[0].username); | 58 createProfileElement.signedInUsers_[0].username); |
| 59 assertEquals('path/to/profile', | 59 assertEquals('path/to/profile', |
| 60 createProfileElement.signedInUsers_[0].profilePath); | 60 createProfileElement.signedInUsers_[0].profilePath); |
| 61 | 61 |
| 62 // The 'learn more' link is visible. | 62 // The 'learn more' link is visible. |
| 63 assertTrue(!!createProfileElement.$$('#learn-more > a')); | 63 assertTrue(!!createProfileElement.$$('#learn-more > a')); |
| 64 | 64 |
| 65 // The dropdown menu becomes visible when the checkbox is checked. | 65 // The dropdown menu becomes visible when the checkbox is checked. |
| 66 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); | 66 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); |
| 67 | 67 |
| 68 // Simulate checking the checkbox. | 68 // Simulate checking the supervised user checkbox. |
| 69 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 69 MockInteractions.tap(createProfileElement.$.makeSupervisedCheckbox); |
| 70 Polymer.dom.flush(); | 70 Polymer.dom.flush(); |
| 71 | 71 |
| 72 // The dropdown menu is visible and is populated with signed in users. | 72 // The dropdown menu is visible and is populated with signed in users. |
| 73 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 73 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 74 assertTrue(!!dropdownMenu); | 74 assertTrue(!!dropdownMenu); |
| 75 var users = dropdownMenu.querySelectorAll('paper-item'); | 75 var users = dropdownMenu.querySelectorAll('paper-item'); |
| 76 assertEquals(1, users.length); | 76 assertEquals(1, users.length); |
| 77 }); | 77 }); |
| 78 }); | 78 }); |
| 79 | 79 |
| 80 test('Name is non-empty by default', function() { | 80 test('Name is non-empty by default', function() { |
| 81 assertEquals('profile name', createProfileElement.$.nameInput.value); | 81 assertEquals('profile name', createProfileElement.$.nameInput.value); |
| 82 }); | 82 }); |
| 83 | 83 |
| 84 test('Create button is disabled if name is empty or invalid', function() { | 84 test('Create button is disabled if name is empty or invalid', function() { |
| 85 assertEquals('profile name', createProfileElement.$.nameInput.value); | 85 assertEquals('profile name', createProfileElement.$.nameInput.value); |
| 86 assertFalse(createProfileElement.$.nameInput.invalid); | 86 assertFalse(createProfileElement.$.nameInput.invalid); |
| 87 assertFalse(createProfileElement.$.save.disabled); | 87 assertFalse(createProfileElement.$.save.disabled); |
| 88 | 88 |
| 89 createProfileElement.$.nameInput.value = ''; | 89 createProfileElement.$.nameInput.value = ''; |
| 90 assertTrue(createProfileElement.$.save.disabled); | 90 assertTrue(createProfileElement.$.save.disabled); |
| 91 | 91 |
| 92 createProfileElement.$.nameInput.value = ' '; | 92 createProfileElement.$.nameInput.value = ' '; |
| 93 assertTrue(createProfileElement.$.nameInput.invalid); | 93 assertTrue(createProfileElement.$.nameInput.invalid); |
| 94 assertTrue(createProfileElement.$.save.disabled); | 94 assertTrue(createProfileElement.$.save.disabled); |
| 95 }); | 95 }); |
| 96 | 96 |
| 97 test('Create a profile', function() { | 97 test('Create a profile', function() { |
| 98 // Create shortcut checkbox is invisible. | |
| 99 var createShortcutCheckbox = | |
| 100 createProfileElement.$.createShortcutCheckbox; | |
| 101 assertTrue(createShortcutCheckbox.clientHeight == 0); | |
| 102 | |
| 98 // Simulate clicking 'Create'. | 103 // Simulate clicking 'Create'. |
| 99 MockInteractions.tap(createProfileElement.$.save); | 104 MockInteractions.tap(createProfileElement.$.save); |
| 100 | 105 |
| 101 return browserProxy.whenCalled('createProfile').then(function(args) { | 106 return browserProxy.whenCalled('createProfile').then(function(args) { |
| 102 assertEquals('profile name', args.profileName); | 107 assertEquals('profile name', args.profileName); |
| 103 assertEquals('icon1.png', args.profileIconUrl); | 108 assertEquals('icon1.png', args.profileIconUrl); |
| 109 assertFalse(args.createShortcut); | |
| 104 assertFalse(args.isSupervised); | 110 assertFalse(args.isSupervised); |
| 105 assertEquals('', args.supervisedUserId); | 111 assertEquals('', args.supervisedUserId); |
| 106 assertEquals('', args.custodianProfilePath); | 112 assertEquals('', args.custodianProfilePath); |
| 107 }); | 113 }); |
| 108 }); | 114 }); |
| 109 | 115 |
| 110 test('Has to select a custodian for the supervised profile', function() { | 116 test('Has to select a custodian for the supervised profile', function() { |
| 111 // Simulate checking the checkbox. | 117 // Simulate checking the supervised user checkbox. |
| 112 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 118 MockInteractions.tap(createProfileElement.$.makeSupervisedCheckbox); |
| 113 Polymer.dom.flush(); | 119 Polymer.dom.flush(); |
| 114 | 120 |
| 115 // Simulate clicking 'Create'. | 121 // Simulate clicking 'Create'. |
| 116 MockInteractions.tap(createProfileElement.$.save); | 122 MockInteractions.tap(createProfileElement.$.save); |
| 117 | 123 |
| 118 // Create is not in progress. | 124 // Create is not in progress. |
| 119 assertFalse(createProfileElement.createInProgress_); | 125 assertFalse(createProfileElement.createInProgress_); |
| 120 // Message container is visible. | 126 // Message container is visible. |
| 121 var messageContainer = | 127 var messageContainer = |
| 122 createProfileElement.$$('#message-container'); | 128 createProfileElement.$$('#message-container'); |
| 123 assertTrue(messageContainer.clientHeight > 0); | 129 assertTrue(messageContainer.clientHeight > 0); |
| 124 // Error message is set. | 130 // Error message is set. |
| 125 assertEquals( | 131 assertEquals( |
| 126 loadTimeData.getString('custodianAccountNotSelectedError'), | 132 loadTimeData.getString('custodianAccountNotSelectedError'), |
| 127 createProfileElement.$.message.innerHTML); | 133 createProfileElement.$.message.innerHTML); |
| 128 }); | 134 }); |
| 129 | 135 |
| 130 test('Supervised profile name is duplicate (on the device)', function() { | 136 test('Supervised profile name is duplicate (on the device)', function() { |
| 131 // Simulate checking the checkbox. | 137 // Simulate checking the supervised user checkbox. |
| 132 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 138 MockInteractions.tap(createProfileElement.$.makeSupervisedCheckbox); |
| 133 Polymer.dom.flush(); | 139 Polymer.dom.flush(); |
| 134 | 140 |
| 135 // There is an existing supervised user with this name on the device. | 141 // There is an existing supervised user with this name on the device. |
| 136 createProfileElement.$.nameInput.value = 'existing name 1'; | 142 createProfileElement.$.nameInput.value = 'existing name 1'; |
| 137 | 143 |
| 138 // Select the first signed in user. | 144 // Select the first signed in user. |
| 139 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 145 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 140 var selector = dropdownMenu.querySelector('paper-listbox'); | 146 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 141 selector.selected = 0; | 147 selector.selected = 0; |
| 142 | 148 |
| 143 // Simulate clicking 'Create'. | 149 // Simulate clicking 'Create'. |
| 144 MockInteractions.tap(createProfileElement.$.save); | 150 MockInteractions.tap(createProfileElement.$.save); |
| 145 | 151 |
| 146 return browserProxy.whenCalled('getExistingSupervisedUsers').then( | 152 return browserProxy.whenCalled('getExistingSupervisedUsers').then( |
| 147 function(args) { | 153 function(args) { |
| 148 // Create is not in progress. | 154 // Create is not in progress. |
| 149 assertFalse(createProfileElement.createInProgress_); | 155 assertFalse(createProfileElement.createInProgress_); |
| 150 // Message container is visible. | 156 // Message container is visible. |
| 151 var messageContainer = | 157 var messageContainer = |
| 152 createProfileElement.$$('#message-container'); | 158 createProfileElement.$$('#message-container'); |
| 153 assertTrue(messageContainer.clientHeight > 0); | 159 assertTrue(messageContainer.clientHeight > 0); |
| 154 // Error message is set. | 160 // Error message is set. |
| 155 var message = loadTimeData.getString( | 161 var message = loadTimeData.getString( |
| 156 'managedProfilesExistingLocalSupervisedUser'); | 162 'managedProfilesExistingLocalSupervisedUser'); |
| 157 assertEquals(message, createProfileElement.$.message.innerHTML); | 163 assertEquals(message, createProfileElement.$.message.innerHTML); |
| 158 }); | 164 }); |
| 159 }); | 165 }); |
| 160 | 166 |
| 161 test('Supervised profile name is duplicate (remote)', function() { | 167 test('Supervised profile name is duplicate (remote)', function() { |
| 162 // Simulate checking the checkbox. | 168 // Simulate checking the supervised user checkbox. |
| 163 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 169 MockInteractions.tap(createProfileElement.$.makeSupervisedCheckbox); |
| 164 Polymer.dom.flush(); | 170 Polymer.dom.flush(); |
| 165 | 171 |
| 166 // 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. |
| 167 createProfileElement.$.nameInput.value = 'existing name 2'; | 173 createProfileElement.$.nameInput.value = 'existing name 2'; |
| 168 | 174 |
| 169 // Select the first signed in user. | 175 // Select the first signed in user. |
| 170 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 176 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 171 var selector = dropdownMenu.querySelector('paper-listbox'); | 177 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 172 selector.selected = 0; | 178 selector.selected = 0; |
| 173 | 179 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 185 // Error message contains a link to import the supervised user. | 191 // Error message contains a link to import the supervised user. |
| 186 var message = createProfileElement.$.message; | 192 var message = createProfileElement.$.message; |
| 187 assertTrue( | 193 assertTrue( |
| 188 !!message.querySelector('#supervised-user-import-existing')); | 194 !!message.querySelector('#supervised-user-import-existing')); |
| 189 }); | 195 }); |
| 190 }); | 196 }); |
| 191 | 197 |
| 192 test('Displays error if custodian has no supervised users', function() { | 198 test('Displays error if custodian has no supervised users', function() { |
| 193 browserProxy.setExistingSupervisedUsers([]); | 199 browserProxy.setExistingSupervisedUsers([]); |
| 194 | 200 |
| 195 // Simulate checking the checkbox. | 201 // Simulate checking the supervised user checkbox. |
| 196 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 202 MockInteractions.tap(createProfileElement.$.makeSupervisedCheckbox); |
| 197 Polymer.dom.flush(); | 203 Polymer.dom.flush(); |
| 198 | 204 |
| 199 // Select the first signed in user. | 205 // Select the first signed in user. |
| 200 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 206 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 201 var selector = dropdownMenu.querySelector('paper-listbox'); | 207 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 202 selector.selected = 0; | 208 selector.selected = 0; |
| 203 | 209 |
| 204 // Simulate clicking 'Import supervised user'. | 210 // Simulate clicking 'Import supervised user'. |
| 205 MockInteractions.tap(createProfileElement.$$('#import-user')); | 211 MockInteractions.tap(createProfileElement.$$('#import-user')); |
| 206 | 212 |
| 207 return browserProxy.whenCalled('getExistingSupervisedUsers').then( | 213 return browserProxy.whenCalled('getExistingSupervisedUsers').then( |
| 208 function(args) { | 214 function(args) { |
| 209 // Create is not in progress. | 215 // Create is not in progress. |
| 210 assertFalse(createProfileElement.createInProgress_); | 216 assertFalse(createProfileElement.createInProgress_); |
| 211 // Message container is visible. | 217 // Message container is visible. |
| 212 var messageContainer = | 218 var messageContainer = |
| 213 createProfileElement.$$('#message-container'); | 219 createProfileElement.$$('#message-container'); |
| 214 assertTrue(messageContainer.clientHeight > 0); | 220 assertTrue(messageContainer.clientHeight > 0); |
| 215 // Error message is set. | 221 // Error message is set. |
| 216 var message = loadTimeData.getString( | 222 var message = loadTimeData.getString( |
| 217 'noSupervisedUserImportText'); | 223 'noSupervisedUserImportText'); |
| 218 assertEquals(message, createProfileElement.$.message.innerHTML); | 224 assertEquals(message, createProfileElement.$.message.innerHTML); |
| 219 }); | 225 }); |
| 220 }); | 226 }); |
| 221 | 227 |
| 222 test('Create supervised profile', function() { | 228 test('Create supervised profile', function() { |
| 223 // Simulate checking the checkbox. | 229 // Simulate checking the supervised user checkbox. |
| 224 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 230 MockInteractions.tap(createProfileElement.$.makeSupervisedCheckbox); |
| 225 Polymer.dom.flush(); | 231 Polymer.dom.flush(); |
| 226 | 232 |
| 227 // Select the first signed in user. | 233 // Select the first signed in user. |
| 228 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 234 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 229 var selector = dropdownMenu.querySelector('paper-listbox'); | 235 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 230 selector.selected = 0; | 236 selector.selected = 0; |
| 231 | 237 |
| 232 // Simulate clicking 'Create'. | 238 // Simulate clicking 'Create'. |
| 233 MockInteractions.tap(createProfileElement.$.save); | 239 MockInteractions.tap(createProfileElement.$.save); |
| 234 | 240 |
| 235 return browserProxy.whenCalled('createProfile').then(function(args) { | 241 return browserProxy.whenCalled('createProfile').then(function(args) { |
| 236 assertEquals('profile name', args.profileName); | 242 assertEquals('profile name', args.profileName); |
| 237 assertEquals('icon1.png', args.profileIconUrl); | 243 assertEquals('icon1.png', args.profileIconUrl); |
| 244 assertFalse(args.createShortcut); | |
| 238 assertTrue(args.isSupervised); | 245 assertTrue(args.isSupervised); |
| 239 assertEquals('', args.supervisedUserId); | 246 assertEquals('', args.supervisedUserId); |
| 240 assertEquals('path/to/profile', args.custodianProfilePath); | 247 assertEquals('path/to/profile', args.custodianProfilePath); |
| 241 }); | 248 }); |
| 242 }); | 249 }); |
| 243 | 250 |
| 244 test('Cancel creating a profile', function() { | 251 test('Cancel creating a profile', function() { |
| 245 // Simulate clicking 'Create'. | 252 // Simulate clicking 'Create'. |
| 246 MockInteractions.tap(createProfileElement.$.save); | 253 MockInteractions.tap(createProfileElement.$.save); |
| 247 | 254 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 teardown(function(done) { | 410 teardown(function(done) { |
| 404 createProfileElement.remove(); | 411 createProfileElement.remove(); |
| 405 // Allow asynchronous tasks to finish. | 412 // Allow asynchronous tasks to finish. |
| 406 setTimeout(done); | 413 setTimeout(done); |
| 407 }); | 414 }); |
| 408 | 415 |
| 409 test('Handles no signed in users', function() { | 416 test('Handles no signed in users', function() { |
| 410 return browserProxy.whenCalled('getSignedInUsers').then(function() { | 417 return browserProxy.whenCalled('getSignedInUsers').then(function() { |
| 411 assertEquals(0, createProfileElement.signedInUsers_.length); | 418 assertEquals(0, createProfileElement.signedInUsers_.length); |
| 412 | 419 |
| 413 // Simulate checking the checkbox. | 420 // Simulate checking the supervised user checkbox. |
| 414 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 421 MockInteractions.tap(createProfileElement.$.makeSupervisedCheckbox); |
| 415 Polymer.dom.flush(); | 422 Polymer.dom.flush(); |
| 416 | 423 |
| 417 // The dropdown menu is not visible when there are no signed in users. | 424 // The dropdown menu is not visible when there are no signed in users. |
| 418 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); | 425 assertFalse(!!createProfileElement.$$('paper-dropdown-menu')); |
| 419 | 426 |
| 420 // Instead a message containing a link to the Help Center on how | 427 // Instead a message containing a link to the Help Center on how |
| 421 // to sign in to Chrome is displaying. | 428 // to sign in to Chrome is displaying. |
| 422 assertTrue(!!createProfileElement.$$('#sign-in-to-chrome')); | 429 assertTrue(!!createProfileElement.$$('#sign-in-to-chrome')); |
| 423 }); | 430 }); |
| 424 }); | 431 }); |
| 425 | 432 |
| 426 test('Create button is disabled', function() { | 433 test('Create button is disabled', function() { |
| 427 assertTrue(createProfileElement.$.save.disabled); | 434 assertTrue(createProfileElement.$.save.disabled); |
| 428 }); | 435 }); |
| 429 }); | 436 }); |
| 437 | |
| 438 suite('CreateProfileTestsProfileShortcutsEnabled', function() { | |
| 439 setup(function() { | |
| 440 browserProxy = new TestProfileBrowserProxy(); | |
| 441 // Replace real proxy with mock proxy. | |
| 442 signin.ProfileBrowserProxyImpl.instance_ = browserProxy; | |
| 443 browserProxy.setDefaultProfileInfo({name: 'profile name'}); | |
| 444 browserProxy.setIcons([{url: 'icon1.png', label: 'icon1'}]); | |
| 445 | |
| 446 // Enable profile shortcuts feature. | |
| 447 loadTimeData.overrideValues({ | |
| 448 profileShortcutsEnabled: true, | |
| 449 }); | |
| 450 | |
| 451 createProfileElement = createElement(); | |
| 452 | |
| 453 // Make sure DOM is up to date. | |
| 454 Polymer.dom.flush(); | |
| 455 }); | |
| 456 | |
| 457 teardown(function(done) { | |
|
tommycli
2016/11/15 01:59:50
Somewhat beyond the scope of this patch: But why i
Moe
2016/11/15 16:03:10
PolymerTest.clearBody() should eliminate the need
tommycli
2016/11/15 16:18:37
Ah okay! That is a very good explanation. Thanks f
| |
| 458 createProfileElement.remove(); | |
| 459 // Allow asynchronous tasks to finish. | |
| 460 setTimeout(done); | |
| 461 }); | |
| 462 | |
| 463 test('Create profile without shortcut', function() { | |
| 464 // Create shortcut checkbox is visible. | |
| 465 var createShortcutCheckbox = | |
| 466 createProfileElement.$.createShortcutCheckbox; | |
| 467 assertTrue(createShortcutCheckbox.clientHeight > 0); | |
| 468 | |
| 469 // Create shortcut checkbox is unchecked. | |
| 470 assertFalse(createShortcutCheckbox.checked); | |
|
tommycli
2016/11/15 01:59:50
I am surprised it's unchecked by default, as state
Moe
2016/11/15 16:03:10
Done.
| |
| 471 | |
| 472 // Simulate clicking 'Create'. | |
| 473 MockInteractions.tap(createProfileElement.$.save); | |
| 474 | |
| 475 return browserProxy.whenCalled('createProfile').then(function(args) { | |
| 476 assertEquals('profile name', args.profileName); | |
| 477 assertEquals('icon1.png', args.profileIconUrl); | |
| 478 assertFalse(args.createShortcut); | |
| 479 assertFalse(args.isSupervised); | |
| 480 assertEquals('', args.supervisedUserId); | |
| 481 assertEquals('', args.custodianProfilePath); | |
| 482 }); | |
| 483 }); | |
| 484 | |
| 485 test('Create profile with shortcut', function() { | |
| 486 // Create shortcut checkbox is visible. | |
| 487 var createShortcutCheckbox = | |
| 488 createProfileElement.$.createShortcutCheckbox; | |
| 489 assertTrue(createShortcutCheckbox.clientHeight > 0); | |
| 490 | |
| 491 // Create shortcut checkbox is unchecked. | |
| 492 assertFalse(createShortcutCheckbox.checked); | |
| 493 | |
| 494 // Simulate checking the create shortcut checkbox. | |
| 495 MockInteractions.tap(createShortcutCheckbox); | |
| 496 | |
| 497 // Simulate clicking 'Create'. | |
| 498 MockInteractions.tap(createProfileElement.$.save); | |
| 499 | |
| 500 return browserProxy.whenCalled('createProfile').then(function(args) { | |
| 501 assertEquals('profile name', args.profileName); | |
| 502 assertEquals('icon1.png', args.profileIconUrl); | |
| 503 assertTrue(args.createShortcut); | |
| 504 assertFalse(args.isSupervised); | |
| 505 assertEquals('', args.supervisedUserId); | |
| 506 assertEquals('', args.custodianProfilePath); | |
| 507 }); | |
| 508 }); | |
| 509 }); | |
|
tommycli
2016/11/15 01:59:50
Nice test!
| |
| 430 } | 510 } |
| 431 | 511 |
| 432 return { | 512 return { |
| 433 registerTests: registerTests, | 513 registerTests: registerTests, |
| 434 }; | 514 }; |
| 435 }); | 515 }); |
| OLD | NEW |