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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 }; | 55 }; |
56 | 56 |
57 TestSyncBrowserProxy.prototype = { | 57 TestSyncBrowserProxy.prototype = { |
58 __proto__: settings.TestBrowserProxy.prototype, | 58 __proto__: settings.TestBrowserProxy.prototype, |
59 | 59 |
60 /** @override */ | 60 /** @override */ |
61 getSyncStatus: function() { | 61 getSyncStatus: function() { |
62 this.methodCalled('getSyncStatus'); | 62 this.methodCalled('getSyncStatus'); |
63 return Promise.resolve({ | 63 return Promise.resolve({ |
64 signedIn: true, | 64 signedIn: true, |
| 65 signedInUsername: 'fakeUsername' |
65 }); | 66 }); |
66 }, | 67 }, |
67 | 68 |
68 /** @override */ | 69 /** @override */ |
69 signOut: function(deleteProfile) { | 70 signOut: function(deleteProfile) { |
70 this.methodCalled('signOut', deleteProfile); | 71 this.methodCalled('signOut', deleteProfile); |
71 }, | 72 }, |
72 }; | 73 }; |
73 | 74 |
74 function registerProfileInfoTests() { | 75 function registerProfileInfoTests() { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 assertTrue(!!peoplePage.$$('#manageSupervisedUsersContainer')); | 135 assertTrue(!!peoplePage.$$('#manageSupervisedUsersContainer')); |
135 }); | 136 }); |
136 }); | 137 }); |
137 }); | 138 }); |
138 } | 139 } |
139 | 140 |
140 function registerSyncStatusTests() { | 141 function registerSyncStatusTests() { |
141 suite('SyncStatusTests', function() { | 142 suite('SyncStatusTests', function() { |
142 var peoplePage = null; | 143 var peoplePage = null; |
143 var browserProxy = null; | 144 var browserProxy = null; |
| 145 var profileInfoBrowserProxy = null; |
144 | 146 |
145 suiteSetup(function() { | 147 suiteSetup(function() { |
146 // Force easy unlock off. Those have their own ChromeOS-only tests. | 148 // Force easy unlock off. Those have their own ChromeOS-only tests. |
147 loadTimeData.overrideValues({ | 149 loadTimeData.overrideValues({ |
148 easyUnlockAllowed: false, | 150 easyUnlockAllowed: false, |
149 }); | 151 }); |
150 }); | 152 }); |
151 | 153 |
152 setup(function() { | 154 setup(function() { |
153 browserProxy = new TestSyncBrowserProxy(); | 155 browserProxy = new TestSyncBrowserProxy(); |
154 settings.SyncBrowserProxyImpl.instance_ = browserProxy; | 156 settings.SyncBrowserProxyImpl.instance_ = browserProxy; |
155 | 157 |
| 158 profileInfoBrowserProxy = new TestProfileInfoBrowserProxy(); |
| 159 settings.ProfileInfoBrowserProxyImpl.instance_ = |
| 160 profileInfoBrowserProxy; |
| 161 |
156 PolymerTest.clearBody(); | 162 PolymerTest.clearBody(); |
157 peoplePage = document.createElement('settings-people-page'); | 163 peoplePage = document.createElement('settings-people-page'); |
158 document.body.appendChild(peoplePage); | 164 document.body.appendChild(peoplePage); |
159 }); | 165 }); |
160 | 166 |
161 teardown(function() { peoplePage.remove(); }); | 167 teardown(function() { peoplePage.remove(); }); |
162 | 168 |
163 test('GetProfileInfo', function() { | 169 test('GetProfileInfo', function() { |
164 var disconnectButton = null; | 170 var disconnectButton = null; |
165 return browserProxy.whenCalled('getSyncStatus').then(function() { | 171 return browserProxy.whenCalled('getSyncStatus').then(function() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 MockInteractions.tap(disconnectManagedProfileConfirm); | 226 MockInteractions.tap(disconnectManagedProfileConfirm); |
221 | 227 |
222 return popstatePromise; | 228 return popstatePromise; |
223 }).then(function() { | 229 }).then(function() { |
224 return browserProxy.whenCalled('signOut'); | 230 return browserProxy.whenCalled('signOut'); |
225 }).then(function(deleteProfile) { | 231 }).then(function(deleteProfile) { |
226 assertTrue(deleteProfile); | 232 assertTrue(deleteProfile); |
227 }); | 233 }); |
228 }); | 234 }); |
229 | 235 |
| 236 test('getProfileStatsCount', function() { |
| 237 return profileInfoBrowserProxy.whenCalled('getProfileStatsCount') |
| 238 .then(function() { |
| 239 Polymer.dom.flush(); |
| 240 |
| 241 // Open the disconnect dialog. |
| 242 disconnectButton = peoplePage.$$('#disconnectButton'); |
| 243 assertTrue(!!disconnectButton); |
| 244 MockInteractions.tap(disconnectButton); |
| 245 Polymer.dom.flush(); |
| 246 |
| 247 assertTrue(peoplePage.$.disconnectDialog.open); |
| 248 |
| 249 // Assert the warning message is as expected. |
| 250 var warningMessage = peoplePage.$$('.delete-profile-warning'); |
| 251 |
| 252 cr.webUIListenerCallback('profile-stats-count-ready', 0); |
| 253 assertEquals( |
| 254 loadTimeData.getStringF('deleteProfileWarningWithoutCounts', |
| 255 'fakeUsername'), |
| 256 warningMessage.textContent.trim()); |
| 257 |
| 258 cr.webUIListenerCallback('profile-stats-count-ready', 1); |
| 259 assertEquals( |
| 260 loadTimeData.getStringF('deleteProfileWarningWithCountsSingular', |
| 261 'fakeUsername'), |
| 262 warningMessage.textContent.trim()); |
| 263 |
| 264 cr.webUIListenerCallback('profile-stats-count-ready', 2); |
| 265 assertEquals( |
| 266 loadTimeData.getStringF('deleteProfileWarningWithCountsPlural', 2, |
| 267 'fakeUsername'), |
| 268 warningMessage.textContent.trim()); |
| 269 |
| 270 // Close the disconnect dialog. |
| 271 MockInteractions.tap(peoplePage.$.disconnectConfirm); |
| 272 return new Promise(function(resolve) { |
| 273 listenOnce(window, 'popstate', resolve); |
| 274 }); |
| 275 }); |
| 276 }); |
| 277 |
| 278 test('NavigateDirectlyToSignOutURL', function() { |
| 279 // Navigate to chrome://md-settings/signOut |
| 280 settings.navigateTo(settings.Route.SIGN_OUT); |
| 281 Polymer.dom.flush(); |
| 282 |
| 283 assertTrue(peoplePage.$.disconnectDialog.open); |
| 284 |
| 285 return profileInfoBrowserProxy.whenCalled('getProfileStatsCount') |
| 286 .then(function() { |
| 287 // 'getProfileStatsCount' can be the first message sent to the handler |
| 288 // if the user navigates directly to chrome://md-settings/signOut. if |
| 289 // so, it should not cause a crash. |
| 290 new settings.ProfileInfoBrowserProxyImpl().getProfileStatsCount(); |
| 291 |
| 292 // Close the disconnect dialog. |
| 293 MockInteractions.tap(peoplePage.$.disconnectConfirm); |
| 294 return new Promise(function(resolve) { |
| 295 listenOnce(window, 'popstate', resolve); |
| 296 }); |
| 297 }); |
| 298 }); |
| 299 |
230 test('Signout dialog suppressed when not signed in', function() { | 300 test('Signout dialog suppressed when not signed in', function() { |
231 return browserProxy.whenCalled('getSyncStatus').then(function() { | 301 return browserProxy.whenCalled('getSyncStatus').then(function() { |
232 Polymer.dom.flush(); | 302 Polymer.dom.flush(); |
233 | 303 |
234 settings.navigateTo(settings.Route.SIGN_OUT); | 304 settings.navigateTo(settings.Route.SIGN_OUT); |
235 Polymer.dom.flush(); | 305 Polymer.dom.flush(); |
236 | 306 |
237 assertTrue(peoplePage.$.disconnectDialog.open); | 307 assertTrue(peoplePage.$.disconnectDialog.open); |
238 | 308 |
239 var popstatePromise = new Promise(function(resolve) { | 309 var popstatePromise = new Promise(function(resolve) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 402 } |
333 | 403 |
334 return { | 404 return { |
335 registerTests: function() { | 405 registerTests: function() { |
336 registerProfileInfoTests(); | 406 registerProfileInfoTests(); |
337 if (!cr.isChromeOS) | 407 if (!cr.isChromeOS) |
338 registerSyncStatusTests(); | 408 registerSyncStatusTests(); |
339 }, | 409 }, |
340 }; | 410 }; |
341 }); | 411 }); |
OLD | NEW |