| 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('settings_people_page', function() { | 5 cr.define('settings_people_page', function() { |
| 6 /** | 6 /** |
| 7 * @constructor | 7 * @constructor |
| 8 * @implements {settings.ProfileInfoBrowserProxy} | 8 * @implements {settings.ProfileInfoBrowserProxy} |
| 9 * @extends {settings.TestBrowserProxy} | 9 * @extends {settings.TestBrowserProxy} |
| 10 */ | 10 */ |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 }); | 165 }); |
| 166 | 166 |
| 167 teardown(function() { peoplePage.remove(); }); | 167 teardown(function() { peoplePage.remove(); }); |
| 168 | 168 |
| 169 test('GetProfileInfo', function() { | 169 test('GetProfileInfo', function() { |
| 170 var disconnectButton = null; | 170 var disconnectButton = null; |
| 171 return browserProxy.whenCalled('getSyncStatus').then(function() { | 171 return browserProxy.whenCalled('getSyncStatus').then(function() { |
| 172 Polymer.dom.flush(); | 172 Polymer.dom.flush(); |
| 173 disconnectButton = peoplePage.$$('#disconnectButton'); | 173 disconnectButton = peoplePage.$$('#disconnectButton'); |
| 174 assertTrue(!!disconnectButton); | 174 assertTrue(!!disconnectButton); |
| 175 assertFalse(!!peoplePage.$$('#disconnectDialog')); |
| 175 | 176 |
| 176 MockInteractions.tap(disconnectButton); | 177 MockInteractions.tap(disconnectButton); |
| 177 Polymer.dom.flush(); | 178 Polymer.dom.flush(); |
| 179 }).then(function() { |
| 180 assertTrue(peoplePage.$$('#disconnectDialog').open); |
| 181 assertFalse(peoplePage.$$('#deleteProfile').hidden); |
| 178 | 182 |
| 179 assertTrue(peoplePage.$.disconnectDialog.open); | |
| 180 var deleteProfileCheckbox = peoplePage.$$('#deleteProfile'); | 183 var deleteProfileCheckbox = peoplePage.$$('#deleteProfile'); |
| 181 assertTrue(!!deleteProfileCheckbox); | 184 assertTrue(!!deleteProfileCheckbox); |
| 182 assertLT(0, deleteProfileCheckbox.clientHeight); | 185 assertLT(0, deleteProfileCheckbox.clientHeight); |
| 183 | 186 |
| 184 var disconnectConfirm = peoplePage.$.disconnectConfirm; | 187 var disconnectConfirm = peoplePage.$$('#disconnectConfirm'); |
| 185 assertTrue(!!disconnectConfirm); | 188 assertTrue(!!disconnectConfirm); |
| 186 assertFalse(disconnectConfirm.hidden); | 189 assertFalse(disconnectConfirm.hidden); |
| 187 | 190 |
| 188 var popstatePromise = new Promise(function(resolve) { | 191 var popstatePromise = new Promise(function(resolve) { |
| 189 listenOnce(window, 'popstate', resolve); | 192 listenOnce(window, 'popstate', resolve); |
| 190 }); | 193 }); |
| 191 | 194 |
| 192 MockInteractions.tap(disconnectConfirm); | 195 MockInteractions.tap(disconnectConfirm); |
| 193 | 196 |
| 194 return popstatePromise; | 197 return popstatePromise; |
| 195 }).then(function() { | 198 }).then(function() { |
| 196 return browserProxy.whenCalled('signOut'); | 199 return browserProxy.whenCalled('signOut'); |
| 197 }).then(function(deleteProfile) { | 200 }).then(function(deleteProfile) { |
| 198 assertFalse(deleteProfile); | 201 assertFalse(deleteProfile); |
| 199 | 202 |
| 200 cr.webUIListenerCallback('sync-status-changed', { | 203 cr.webUIListenerCallback('sync-status-changed', { |
| 201 signedIn: true, | 204 signedIn: true, |
| 202 domain: 'example.com', | 205 domain: 'example.com', |
| 203 }); | 206 }); |
| 204 Polymer.dom.flush(); | 207 Polymer.dom.flush(); |
| 205 | 208 |
| 206 assertFalse(peoplePage.$.disconnectDialog.open); | 209 assertFalse(!!peoplePage.$$('#disconnectDialog')); |
| 207 MockInteractions.tap(disconnectButton); | 210 MockInteractions.tap(disconnectButton); |
| 208 Polymer.dom.flush(); | 211 Polymer.dom.flush(); |
| 209 | 212 |
| 210 assertTrue(peoplePage.$.disconnectDialog.open); | 213 return new Promise(function(resolve) { peoplePage.async(resolve); }); |
| 211 var deleteProfileCheckbox = peoplePage.$$('#deleteProfile'); | 214 }).then(function() { |
| 212 assertTrue(!!deleteProfileCheckbox); | 215 assertTrue(peoplePage.$$('#disconnectDialog').open); |
| 213 assertEquals(0, deleteProfileCheckbox.clientHeight); | 216 assertFalse(!!peoplePage.$$('#deleteProfile')); |
| 214 | 217 |
| 215 var disconnectManagedProfileConfirm = | 218 var disconnectManagedProfileConfirm = |
| 216 peoplePage.$.disconnectManagedProfileConfirm; | 219 peoplePage.$$('#disconnectManagedProfileConfirm'); |
| 217 assertTrue(!!disconnectManagedProfileConfirm); | 220 assertTrue(!!disconnectManagedProfileConfirm); |
| 218 assertFalse(disconnectManagedProfileConfirm.hidden); | 221 assertFalse(disconnectManagedProfileConfirm.hidden); |
| 219 | 222 |
| 220 browserProxy.resetResolver('signOut'); | 223 browserProxy.resetResolver('signOut'); |
| 221 | 224 |
| 222 var popstatePromise = new Promise(function(resolve) { | 225 var popstatePromise = new Promise(function(resolve) { |
| 223 listenOnce(window, 'popstate', resolve); | 226 listenOnce(window, 'popstate', resolve); |
| 224 }); | 227 }); |
| 225 | 228 |
| 226 MockInteractions.tap(disconnectManagedProfileConfirm); | 229 MockInteractions.tap(disconnectManagedProfileConfirm); |
| 227 | 230 |
| 228 return popstatePromise; | 231 return popstatePromise; |
| 229 }).then(function() { | 232 }).then(function() { |
| 230 return browserProxy.whenCalled('signOut'); | 233 return browserProxy.whenCalled('signOut'); |
| 231 }).then(function(deleteProfile) { | 234 }).then(function(deleteProfile) { |
| 232 assertTrue(deleteProfile); | 235 assertTrue(deleteProfile); |
| 233 }); | 236 }); |
| 234 }); | 237 }); |
| 235 | 238 |
| 236 test('getProfileStatsCount', function() { | 239 test('getProfileStatsCount', function() { |
| 237 return profileInfoBrowserProxy.whenCalled('getProfileStatsCount') | 240 return profileInfoBrowserProxy.whenCalled('getProfileStatsCount') |
| 238 .then(function() { | 241 .then(function() { |
| 239 Polymer.dom.flush(); | 242 Polymer.dom.flush(); |
| 240 | 243 |
| 241 // Open the disconnect dialog. | 244 // Open the disconnect dialog. |
| 242 disconnectButton = peoplePage.$$('#disconnectButton'); | 245 disconnectButton = peoplePage.$$('#disconnectButton'); |
| 243 assertTrue(!!disconnectButton); | 246 assertTrue(!!disconnectButton); |
| 244 MockInteractions.tap(disconnectButton); | 247 MockInteractions.tap(disconnectButton); |
| 245 Polymer.dom.flush(); | |
| 246 | 248 |
| 247 assertTrue(peoplePage.$.disconnectDialog.open); | 249 return new Promise(function(resolve) { peoplePage.async(resolve); }); |
| 250 }).then(function() { |
| 251 assertTrue(peoplePage.$$('#disconnectDialog').open); |
| 248 | 252 |
| 249 // Assert the warning message is as expected. | 253 // Assert the warning message is as expected. |
| 250 var warningMessage = peoplePage.$$('.delete-profile-warning'); | 254 var warningMessage = peoplePage.$$('.delete-profile-warning'); |
| 251 | 255 |
| 252 cr.webUIListenerCallback('profile-stats-count-ready', 0); | 256 cr.webUIListenerCallback('profile-stats-count-ready', 0); |
| 253 assertEquals( | 257 assertEquals( |
| 254 loadTimeData.getStringF('deleteProfileWarningWithoutCounts', | 258 loadTimeData.getStringF('deleteProfileWarningWithoutCounts', |
| 255 'fakeUsername'), | 259 'fakeUsername'), |
| 256 warningMessage.textContent.trim()); | 260 warningMessage.textContent.trim()); |
| 257 | 261 |
| 258 cr.webUIListenerCallback('profile-stats-count-ready', 1); | 262 cr.webUIListenerCallback('profile-stats-count-ready', 1); |
| 259 assertEquals( | 263 assertEquals( |
| 260 loadTimeData.getStringF('deleteProfileWarningWithCountsSingular', | 264 loadTimeData.getStringF('deleteProfileWarningWithCountsSingular', |
| 261 'fakeUsername'), | 265 'fakeUsername'), |
| 262 warningMessage.textContent.trim()); | 266 warningMessage.textContent.trim()); |
| 263 | 267 |
| 264 cr.webUIListenerCallback('profile-stats-count-ready', 2); | 268 cr.webUIListenerCallback('profile-stats-count-ready', 2); |
| 265 assertEquals( | 269 assertEquals( |
| 266 loadTimeData.getStringF('deleteProfileWarningWithCountsPlural', 2, | 270 loadTimeData.getStringF('deleteProfileWarningWithCountsPlural', 2, |
| 267 'fakeUsername'), | 271 'fakeUsername'), |
| 268 warningMessage.textContent.trim()); | 272 warningMessage.textContent.trim()); |
| 269 | 273 |
| 270 // Close the disconnect dialog. | 274 // Close the disconnect dialog. |
| 271 MockInteractions.tap(peoplePage.$.disconnectConfirm); | 275 MockInteractions.tap(peoplePage.$$('#disconnectConfirm')); |
| 272 return new Promise(function(resolve) { | 276 return new Promise(function(resolve) { |
| 273 listenOnce(window, 'popstate', resolve); | 277 listenOnce(window, 'popstate', resolve); |
| 274 }); | 278 }); |
| 275 }); | 279 }); |
| 276 }); | 280 }); |
| 277 | 281 |
| 278 test('NavigateDirectlyToSignOutURL', function() { | 282 test('NavigateDirectlyToSignOutURL', function() { |
| 279 // Navigate to chrome://md-settings/signOut | 283 // Navigate to chrome://md-settings/signOut |
| 280 settings.navigateTo(settings.Route.SIGN_OUT); | 284 settings.navigateTo(settings.Route.SIGN_OUT); |
| 281 Polymer.dom.flush(); | |
| 282 | 285 |
| 283 assertTrue(peoplePage.$.disconnectDialog.open); | 286 return new Promise( |
| 284 | 287 function(resolve) { peoplePage.async(resolve); }).then(function() { |
| 285 return profileInfoBrowserProxy.whenCalled('getProfileStatsCount') | 288 assertTrue(peoplePage.$$('#disconnectDialog').open); |
| 286 .then(function() { | 289 return profileInfoBrowserProxy.whenCalled('getProfileStatsCount'); |
| 290 }).then(function() { |
| 287 // 'getProfileStatsCount' can be the first message sent to the handler | 291 // 'getProfileStatsCount' can be the first message sent to the handler |
| 288 // if the user navigates directly to chrome://md-settings/signOut. if | 292 // if the user navigates directly to chrome://md-settings/signOut. if |
| 289 // so, it should not cause a crash. | 293 // so, it should not cause a crash. |
| 290 new settings.ProfileInfoBrowserProxyImpl().getProfileStatsCount(); | 294 new settings.ProfileInfoBrowserProxyImpl().getProfileStatsCount(); |
| 291 | 295 |
| 292 // Close the disconnect dialog. | 296 // Close the disconnect dialog. |
| 293 MockInteractions.tap(peoplePage.$.disconnectConfirm); | 297 MockInteractions.tap(peoplePage.$$('#disconnectConfirm')); |
| 298 }).then(function() { |
| 294 return new Promise(function(resolve) { | 299 return new Promise(function(resolve) { |
| 295 listenOnce(window, 'popstate', resolve); | 300 listenOnce(window, 'popstate', resolve); |
| 296 }); | 301 }); |
| 297 }); | 302 }); |
| 298 }); | 303 }); |
| 299 | 304 |
| 300 test('Signout dialog suppressed when not signed in', function() { | 305 test('Signout dialog suppressed when not signed in', function() { |
| 301 return browserProxy.whenCalled('getSyncStatus').then(function() { | 306 return browserProxy.whenCalled('getSyncStatus').then(function() { |
| 302 Polymer.dom.flush(); | |
| 303 | |
| 304 settings.navigateTo(settings.Route.SIGN_OUT); | 307 settings.navigateTo(settings.Route.SIGN_OUT); |
| 305 Polymer.dom.flush(); | 308 return new Promise(function(resolve) { peoplePage.async(resolve); }); |
| 306 | 309 }).then(function() { |
| 307 assertTrue(peoplePage.$.disconnectDialog.open); | 310 assertTrue(peoplePage.$$('#disconnectDialog').open); |
| 308 | 311 |
| 309 var popstatePromise = new Promise(function(resolve) { | 312 var popstatePromise = new Promise(function(resolve) { |
| 310 listenOnce(window, 'popstate', resolve); | 313 listenOnce(window, 'popstate', resolve); |
| 311 }); | 314 }); |
| 312 | 315 |
| 313 cr.webUIListenerCallback('sync-status-changed', { | 316 cr.webUIListenerCallback('sync-status-changed', { |
| 314 signedIn: false, | 317 signedIn: false, |
| 315 }); | 318 }); |
| 316 | 319 |
| 317 return popstatePromise; | 320 return popstatePromise; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 405 } |
| 403 | 406 |
| 404 return { | 407 return { |
| 405 registerTests: function() { | 408 registerTests: function() { |
| 406 registerProfileInfoTests(); | 409 registerProfileInfoTests(); |
| 407 if (!cr.isChromeOS) | 410 if (!cr.isChromeOS) |
| 408 registerSyncStatusTests(); | 411 registerSyncStatusTests(); |
| 409 }, | 412 }, |
| 410 }; | 413 }; |
| 411 }); | 414 }); |
| OLD | NEW |