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_privacy_page', function() { | 5 cr.define('settings_privacy_page', function() { |
6 /** | 6 /** |
7 * @constructor | 7 * @constructor |
8 * @extends {TestBrowserProxy} | 8 * @extends {TestBrowserProxy} |
9 * @implements {settings.ClearBrowsingDataBrowserProxy} | 9 * @implements {settings.ClearBrowsingDataBrowserProxy} |
10 */ | 10 */ |
11 function TestClearBrowsingDataBrowserProxy() { | 11 function TestClearBrowsingDataBrowserProxy() { |
12 settings.TestBrowserProxy.call(this, [ | 12 settings.TestBrowserProxy.call( |
13 'initialize', | 13 this, ['initialize', 'clearBrowsingData', 'fetchImportantSites']); |
14 'clearBrowsingData', | |
15 ]); | |
16 | 14 |
17 /** | 15 /** |
18 * The promise to return from |clearBrowsingData|. | 16 * The promise to return from |clearBrowsingData|. |
19 * Allows testing code to test what happens after the call is made, and | 17 * Allows testing code to test what happens after the call is made, and |
20 * before the browser responds. | 18 * before the browser responds. |
21 * @private {?Promise} | 19 * @private {?Promise} |
22 */ | 20 */ |
23 this.clearBrowsingDataPromise_ = null; | 21 this.clearBrowsingDataPromise_ = null; |
| 22 |
| 23 /** |
| 24 * Default response for fetchImportantSites. It tells the ui that important |
| 25 * sites are disabled. |
| 26 * @private {!ImportantSitesResponse} |
| 27 */ |
| 28 this.importantSitesResponse_ = {flagEnabled: false, importantSites: []}; |
24 } | 29 } |
25 | 30 |
26 TestClearBrowsingDataBrowserProxy.prototype = { | 31 TestClearBrowsingDataBrowserProxy.prototype = { |
27 __proto__: settings.TestBrowserProxy.prototype, | 32 __proto__: settings.TestBrowserProxy.prototype, |
28 | 33 |
29 /** @param {!Promise} promise */ | 34 /** @param {!Promise} promise */ |
30 setClearBrowsingDataPromise: function(promise) { | 35 setClearBrowsingDataPromise: function(promise) { |
31 this.clearBrowsingDataPromise_ = promise; | 36 this.clearBrowsingDataPromise_ = promise; |
32 }, | 37 }, |
33 | 38 |
34 /** @override */ | 39 /** @override */ |
35 clearBrowsingData: function() { | 40 clearBrowsingData: function(importantSites) { |
36 this.methodCalled('clearBrowsingData'); | 41 this.methodCalled('clearBrowsingData', importantSites); |
37 cr.webUIListenerCallback('browsing-data-removing', true); | 42 cr.webUIListenerCallback('browsing-data-removing', true); |
38 return this.clearBrowsingDataPromise_ !== null ? | 43 return this.clearBrowsingDataPromise_ !== null ? |
39 this.clearBrowsingDataPromise_ : Promise.resolve(); | 44 this.clearBrowsingDataPromise_ : Promise.resolve(); |
40 }, | 45 }, |
41 | 46 |
| 47 /** @param {!ImportantSitesResponse} response */ |
| 48 setImportantSitesResponse: function(response) { |
| 49 this.importantSitesResponse_ = response; |
| 50 }, |
| 51 |
| 52 /** @override */ |
| 53 fetchImportantSites: function() { |
| 54 this.methodCalled('fetchImportantSites'); |
| 55 return Promise.resolve(this.importantSitesResponse_); |
| 56 }, |
| 57 |
42 /** @override */ | 58 /** @override */ |
43 initialize: function() { | 59 initialize: function() { |
44 this.methodCalled('initialize'); | 60 this.methodCalled('initialize'); |
45 return Promise.resolve(false); | 61 return Promise.resolve(false); |
46 }, | 62 }, |
47 }; | 63 }; |
48 | 64 |
49 function registerNativeCertificateManagerTests() { | 65 function registerNativeCertificateManagerTests() { |
50 suite('NativeCertificateManager', function() { | 66 suite('NativeCertificateManager', function() { |
51 /** @type {settings.TestPrivacyPageBrowserProxy} */ | 67 /** @type {settings.TestPrivacyPageBrowserProxy} */ |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 122 |
107 /** @type {SettingsClearBrowsingDataDialogElement} */ | 123 /** @type {SettingsClearBrowsingDataDialogElement} */ |
108 var element; | 124 var element; |
109 | 125 |
110 setup(function() { | 126 setup(function() { |
111 testBrowserProxy = new TestClearBrowsingDataBrowserProxy(); | 127 testBrowserProxy = new TestClearBrowsingDataBrowserProxy(); |
112 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy; | 128 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy; |
113 PolymerTest.clearBody(); | 129 PolymerTest.clearBody(); |
114 element = document.createElement('settings-clear-browsing-data-dialog'); | 130 element = document.createElement('settings-clear-browsing-data-dialog'); |
115 document.body.appendChild(element); | 131 document.body.appendChild(element); |
116 return testBrowserProxy.whenCalled('initialize'); | 132 return testBrowserProxy.whenCalled('initialize').then(function() { |
| 133 return testBrowserProxy.whenCalled('fetchImportantSites'); |
| 134 }); |
117 }); | 135 }); |
118 | 136 |
119 teardown(function() { element.remove(); }); | 137 teardown(function() { element.remove(); }); |
120 | 138 |
121 test('ClearBrowsingDataTap', function() { | 139 test('ClearBrowsingDataTap', function() { |
122 assertTrue(element.$.dialog.open); | 140 assertTrue(element.$.dialog.open); |
| 141 assertFalse(element.importantSitesFlagEnabled_); |
| 142 assertEquals(element.dialogState_, 'clearBrowsingData'); |
123 | 143 |
124 var cancelButton = element.$$('.cancel-button'); | 144 var cancelButton = element.$$('.cancel-button'); |
125 assertTrue(!!cancelButton); | 145 assertTrue(!!cancelButton); |
126 var actionButton = element.$$('.action-button'); | 146 var actionButton = element.$$('.action-button'); |
127 assertTrue(!!actionButton); | 147 assertTrue(!!actionButton); |
128 var spinner = element.$$('paper-spinner'); | 148 var spinner = element.$$('paper-spinner'); |
129 assertTrue(!!spinner); | 149 assertTrue(!!spinner); |
130 | 150 |
131 assertFalse(cancelButton.disabled); | 151 assertFalse(cancelButton.disabled); |
132 assertFalse(actionButton.disabled); | 152 assertFalse(actionButton.disabled); |
133 assertFalse(spinner.active); | 153 assertFalse(spinner.active); |
134 | 154 |
135 var promiseResolver = new PromiseResolver(); | 155 var promiseResolver = new PromiseResolver(); |
136 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); | 156 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); |
137 MockInteractions.tap(actionButton); | 157 MockInteractions.tap(actionButton); |
138 | 158 |
139 return testBrowserProxy.whenCalled('clearBrowsingData').then( | 159 return testBrowserProxy.whenCalled('clearBrowsingData') |
140 function() { | 160 .then(function(importantSites) { |
141 assertTrue(element.$.dialog.open); | 161 assertTrue(element.$.dialog.open); |
142 assertTrue(cancelButton.disabled); | 162 assertTrue(cancelButton.disabled); |
143 assertTrue(actionButton.disabled); | 163 assertTrue(actionButton.disabled); |
144 assertTrue(spinner.active); | 164 assertTrue(spinner.active); |
| 165 assertTrue(importantSites.length == 0); |
145 | 166 |
146 // Simulate signal from browser indicating that clearing has | 167 // Simulate signal from browser indicating that clearing has |
147 // completed. | 168 // completed. |
148 cr.webUIListenerCallback('browsing-data-removing', false); | 169 cr.webUIListenerCallback('browsing-data-removing', false); |
149 promiseResolver.resolve(); | 170 promiseResolver.resolve(); |
150 // Yields to the message loop to allow the callback chain of the | 171 // Yields to the message loop to allow the callback chain of the |
151 // Promise that was just resolved to execute before the | 172 // Promise that was just resolved to execute before the |
152 // assertions. | 173 // assertions. |
153 }).then(function() { | 174 }) |
| 175 .then(function() { |
154 assertFalse(element.$.dialog.open); | 176 assertFalse(element.$.dialog.open); |
155 assertFalse(cancelButton.disabled); | 177 assertFalse(cancelButton.disabled); |
156 assertFalse(actionButton.disabled); | 178 assertFalse(actionButton.disabled); |
157 assertFalse(spinner.active); | 179 assertFalse(spinner.active); |
158 assertFalse(!!element.$$('#notice')); | 180 assertFalse(!!element.$$('#notice')); |
| 181 // Check that the dialog didn't switch to important sites. |
| 182 assertEquals(element.dialogState_, 'clearBrowsingData'); |
159 }); | 183 }); |
160 }); | 184 }); |
161 | 185 |
162 test('showHistoryDeletionDialog', function() { | 186 test('showHistoryDeletionDialog', function() { |
163 assertTrue(element.$.dialog.open); | 187 assertTrue(element.$.dialog.open); |
164 var actionButton = element.$$('.action-button'); | 188 var actionButton = element.$$('.action-button'); |
165 assertTrue(!!actionButton); | 189 assertTrue(!!actionButton); |
166 | 190 |
167 var promiseResolver = new PromiseResolver(); | 191 var promiseResolver = new PromiseResolver(); |
168 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); | 192 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 249 |
226 // Simulate a browsing data counter result for history. This checkbox's | 250 // Simulate a browsing data counter result for history. This checkbox's |
227 // sublabel should be updated. | 251 // sublabel should be updated. |
228 cr.webUIListenerCallback( | 252 cr.webUIListenerCallback( |
229 'update-counter-text', checkbox.pref.key, 'result'); | 253 'update-counter-text', checkbox.pref.key, 'result'); |
230 assertEquals('result', checkbox.subLabel); | 254 assertEquals('result', checkbox.subLabel); |
231 }); | 255 }); |
232 }); | 256 }); |
233 } | 257 } |
234 | 258 |
| 259 suite('ImportantSites', function() { |
| 260 /** @type {settings.TestClearBrowsingDataBrowserProxy} */ |
| 261 var testBrowserProxy; |
| 262 |
| 263 /** @type {SettingsClearBrowsingDataDialogElement} */ |
| 264 var element; |
| 265 |
| 266 /** @type {Array<ImportantSite>} */ |
| 267 var importantSites = [ |
| 268 {registerableDomain: 'google.com', isChecked: true}, |
| 269 {registerableDomain: 'yahoo.com', isChecked: true} |
| 270 ] |
| 271 |
| 272 setup(function() { |
| 273 testBrowserProxy = new TestClearBrowsingDataBrowserProxy(); |
| 274 testBrowserProxy.setImportantSitesResponse({ |
| 275 flagEnabled: true, |
| 276 importantSites: importantSites, |
| 277 }); |
| 278 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy; |
| 279 PolymerTest.clearBody(); |
| 280 element = document.createElement('settings-clear-browsing-data-dialog'); |
| 281 document.body.appendChild(element); |
| 282 return testBrowserProxy.whenCalled('initialize').then(function() { |
| 283 return testBrowserProxy.whenCalled('fetchImportantSites'); |
| 284 }); |
| 285 }); |
| 286 |
| 287 teardown(function() { |
| 288 element.remove(); |
| 289 }); |
| 290 |
| 291 test('fetchImportantSites', function() { |
| 292 assertTrue(element.$.dialog.open); |
| 293 assertEquals(element.dialogState_, 'clearBrowsingData'); |
| 294 // Select an entry that can have important storage. |
| 295 element.$.cookiesCheckbox.checked = true; |
| 296 var actionButton = element.$$('.action-button'); |
| 297 assertTrue(!!actionButton); |
| 298 // Clear browsing data. |
| 299 MockInteractions.tap(actionButton); |
| 300 assertEquals(element.dialogState_, 'importantSites'); |
| 301 |
| 302 Polymer.dom.flush(); |
| 303 var firstImportantSite = element.$$('important-site-checkbox') |
| 304 assertTrue(!!firstImportantSite); |
| 305 assertEquals(firstImportantSite.site.registerableDomain, 'google.com'); |
| 306 assertTrue(firstImportantSite.site.isChecked) |
| 307 // Choose to keep storage for google.com. |
| 308 MockInteractions.tap(firstImportantSite.$.checkbox); |
| 309 assertFalse(firstImportantSite.site.isChecked) |
| 310 // Confirm deletion. |
| 311 MockInteractions.tap(actionButton); |
| 312 return testBrowserProxy.whenCalled('clearBrowsingData') |
| 313 .then(function(sites) { |
| 314 assertEquals(sites.length, 2); |
| 315 assertEquals(sites[0].registerableDomain, 'google.com'); |
| 316 assertFalse(sites[0].isChecked); |
| 317 assertEquals(sites[1].registerableDomain, 'yahoo.com'); |
| 318 assertTrue(sites[1].isChecked); |
| 319 }); |
| 320 }); |
| 321 }); |
| 322 |
235 function registerSafeBrowsingExtendedReportingTests() { | 323 function registerSafeBrowsingExtendedReportingTests() { |
236 suite('SafeBrowsingExtendedReporting', function() { | 324 suite('SafeBrowsingExtendedReporting', function() { |
237 /** @type {settings.TestPrivacyPageBrowserProxy} */ | 325 /** @type {settings.TestPrivacyPageBrowserProxy} */ |
238 var testBrowserProxy; | 326 var testBrowserProxy; |
239 | 327 |
240 /** @type {SettingsPrivacyPageElement} */ | 328 /** @type {SettingsPrivacyPageElement} */ |
241 var page; | 329 var page; |
242 | 330 |
243 setup(function() { | 331 setup(function() { |
244 testBrowserProxy = new TestPrivacyPageBrowserProxy(); | 332 testBrowserProxy = new TestPrivacyPageBrowserProxy(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 registerTests: function() { | 365 registerTests: function() { |
278 if (cr.isMac || cr.isWin) | 366 if (cr.isMac || cr.isWin) |
279 registerNativeCertificateManagerTests(); | 367 registerNativeCertificateManagerTests(); |
280 | 368 |
281 registerClearBrowsingDataTests(); | 369 registerClearBrowsingDataTests(); |
282 registerPrivacyPageTests(); | 370 registerPrivacyPageTests(); |
283 registerSafeBrowsingExtendedReportingTests(); | 371 registerSafeBrowsingExtendedReportingTests(); |
284 }, | 372 }, |
285 }; | 373 }; |
286 }); | 374 }); |
OLD | NEW |