| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Simulate checking the checkbox. | 111 // Simulate checking the checkbox. |
| 112 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 112 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
| 113 Polymer.dom.flush(); | 113 Polymer.dom.flush(); |
| 114 | 114 |
| 115 // Simulate clicking 'Create'. | 115 // Simulate clicking 'Create'. |
| 116 MockInteractions.tap(createProfileElement.$.save); | 116 MockInteractions.tap(createProfileElement.$.save); |
| 117 | 117 |
| 118 // Create is not in progress. | 118 // Create is not in progress. |
| 119 assertFalse(createProfileElement.createInProgress_); | 119 assertFalse(createProfileElement.createInProgress_); |
| 120 // Message container is visible. | 120 // Message container is visible. |
| 121 assertFalse(createProfileElement.$$('#message-container').hidden); | 121 var messageContainer = |
| 122 createProfileElement.$$('#message-container'); |
| 123 assertTrue(messageContainer.clientHeight > 0); |
| 122 // Error message is set. | 124 // Error message is set. |
| 123 assertEquals( | 125 assertEquals( |
| 124 loadTimeData.getString('custodianAccountNotSelectedError'), | 126 loadTimeData.getString('custodianAccountNotSelectedError'), |
| 125 createProfileElement.$.message.innerHTML); | 127 createProfileElement.$.message.innerHTML); |
| 126 }); | 128 }); |
| 127 | 129 |
| 128 test('Supervised profile name is duplicate (on the device)', function() { | 130 test('Supervised profile name is duplicate (on the device)', function() { |
| 129 // Simulate checking the checkbox. | 131 // Simulate checking the checkbox. |
| 130 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 132 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
| 131 Polymer.dom.flush(); | 133 Polymer.dom.flush(); |
| 132 | 134 |
| 133 // There is an existing supervised user with this name on the device. | 135 // There is an existing supervised user with this name on the device. |
| 134 createProfileElement.$.nameInput.value = 'existing name 1'; | 136 createProfileElement.$.nameInput.value = 'existing name 1'; |
| 135 | 137 |
| 136 // Select the first signed in user. | 138 // Select the first signed in user. |
| 137 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 139 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 138 var selector = dropdownMenu.querySelector('paper-listbox'); | 140 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 139 selector.selected = 0; | 141 selector.selected = 0; |
| 140 | 142 |
| 141 // Simulate clicking 'Create'. | 143 // Simulate clicking 'Create'. |
| 142 MockInteractions.tap(createProfileElement.$.save); | 144 MockInteractions.tap(createProfileElement.$.save); |
| 143 | 145 |
| 144 return browserProxy.whenCalled('getExistingSupervisedUsers').then( | 146 return browserProxy.whenCalled('getExistingSupervisedUsers').then( |
| 145 function(args) { | 147 function(args) { |
| 146 // Create is not in progress. | 148 // Create is not in progress. |
| 147 assertFalse(createProfileElement.createInProgress_); | 149 assertFalse(createProfileElement.createInProgress_); |
| 148 // Message container is visible. | 150 // Message container is visible. |
| 149 assertFalse(createProfileElement.$$('#message-container').hidden); | 151 var messageContainer = |
| 152 createProfileElement.$$('#message-container'); |
| 153 assertTrue(messageContainer.clientHeight > 0); |
| 150 // Error message is set. | 154 // Error message is set. |
| 151 var message = loadTimeData.getString( | 155 var message = loadTimeData.getString( |
| 152 'managedProfilesExistingLocalSupervisedUser'); | 156 'managedProfilesExistingLocalSupervisedUser'); |
| 153 assertEquals(message, createProfileElement.$.message.innerHTML); | 157 assertEquals(message, createProfileElement.$.message.innerHTML); |
| 154 }); | 158 }); |
| 155 }); | 159 }); |
| 156 | 160 |
| 157 test('Supervised profile name is duplicate (remote)', function() { | 161 test('Supervised profile name is duplicate (remote)', function() { |
| 158 // Simulate checking the checkbox. | 162 // Simulate checking the checkbox. |
| 159 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 163 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
| 160 Polymer.dom.flush(); | 164 Polymer.dom.flush(); |
| 161 | 165 |
| 162 // There is an existing supervised user with this name on the device. | 166 // There is an existing supervised user with this name on the device. |
| 163 createProfileElement.$.nameInput.value = 'existing name 2'; | 167 createProfileElement.$.nameInput.value = 'existing name 2'; |
| 164 | 168 |
| 165 // Select the first signed in user. | 169 // Select the first signed in user. |
| 166 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 170 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 167 var selector = dropdownMenu.querySelector('paper-listbox'); | 171 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 168 selector.selected = 0; | 172 selector.selected = 0; |
| 169 | 173 |
| 170 // Simulate clicking 'Create'. | 174 // Simulate clicking 'Create'. |
| 171 MockInteractions.tap(createProfileElement.$.save); | 175 MockInteractions.tap(createProfileElement.$.save); |
| 172 | 176 |
| 173 return browserProxy.whenCalled('getExistingSupervisedUsers').then( | 177 return browserProxy.whenCalled('getExistingSupervisedUsers').then( |
| 174 function(args) { | 178 function(args) { |
| 175 // Create is not in progress. | 179 // Create is not in progress. |
| 176 assertFalse(createProfileElement.createInProgress_); | 180 assertFalse(createProfileElement.createInProgress_); |
| 177 // Message container is visible. | 181 // Message container is visible. |
| 178 assertFalse(createProfileElement.$$('#message-container').hidden); | 182 var messageContainer = |
| 183 createProfileElement.$$('#message-container'); |
| 184 assertTrue(messageContainer.clientHeight > 0); |
| 179 // Error message contains a link to import the supervised user. | 185 // Error message contains a link to import the supervised user. |
| 180 var message = createProfileElement.$.message; | 186 var message = createProfileElement.$.message; |
| 181 assertTrue( | 187 assertTrue( |
| 182 !!message.querySelector('#supervised-user-import-existing')); | 188 !!message.querySelector('#supervised-user-import-existing')); |
| 183 }); | 189 }); |
| 184 }); | 190 }); |
| 185 | 191 |
| 192 test('Displays error if custodian has no supervised users', function() { |
| 193 browserProxy.setExistingSupervisedUsers([]); |
| 194 |
| 195 // Simulate checking the checkbox. |
| 196 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
| 197 Polymer.dom.flush(); |
| 198 |
| 199 // Select the first signed in user. |
| 200 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 201 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 202 selector.selected = 0; |
| 203 |
| 204 // Simulate clicking 'Import supervised user'. |
| 205 MockInteractions.tap(createProfileElement.$$('#import-user')); |
| 206 |
| 207 return browserProxy.whenCalled('getExistingSupervisedUsers').then( |
| 208 function(args) { |
| 209 // Create is not in progress. |
| 210 assertFalse(createProfileElement.createInProgress_); |
| 211 // Message container is visible. |
| 212 var messageContainer = |
| 213 createProfileElement.$$('#message-container'); |
| 214 assertTrue(messageContainer.clientHeight > 0); |
| 215 // Error message is set. |
| 216 var message = loadTimeData.getString( |
| 217 'noSupervisedUserImportText'); |
| 218 assertEquals(message, createProfileElement.$.message.innerHTML); |
| 219 }); |
| 220 }); |
| 221 |
| 186 test('Create supervised profile', function() { | 222 test('Create supervised profile', function() { |
| 187 // Simulate checking the checkbox. | 223 // Simulate checking the checkbox. |
| 188 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); | 224 MockInteractions.tap(createProfileElement.$$('paper-checkbox')); |
| 189 Polymer.dom.flush(); | 225 Polymer.dom.flush(); |
| 190 | 226 |
| 191 // Select the first signed in user. | 227 // Select the first signed in user. |
| 192 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); | 228 var dropdownMenu = createProfileElement.$$('paper-dropdown-menu'); |
| 193 var selector = dropdownMenu.querySelector('paper-listbox'); | 229 var selector = dropdownMenu.querySelector('paper-listbox'); |
| 194 selector.selected = 0; | 230 selector.selected = 0; |
| 195 | 231 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 test('Create button is disabled', function() { | 426 test('Create button is disabled', function() { |
| 391 assertTrue(createProfileElement.$.save.disabled); | 427 assertTrue(createProfileElement.$.save.disabled); |
| 392 }); | 428 }); |
| 393 }); | 429 }); |
| 394 } | 430 } |
| 395 | 431 |
| 396 return { | 432 return { |
| 397 registerTests: registerTests, | 433 registerTests: registerTests, |
| 398 }; | 434 }; |
| 399 }); | 435 }); |
| OLD | NEW |