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