Chromium Code Reviews| 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_ = {importantSites: []}; | |
|
Dan Beam
2017/05/16 19:46:09
if we change to just an array all of this codes ge
dullweber
2017/05/17 09:57:37
Done.
| |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 assertFalse(!!page.$$('settings-clear-browsing-data-dialog')); | 103 assertFalse(!!page.$$('settings-clear-browsing-data-dialog')); |
| 88 MockInteractions.tap(page.$.clearBrowsingData); | 104 MockInteractions.tap(page.$.clearBrowsingData); |
| 89 Polymer.dom.flush(); | 105 Polymer.dom.flush(); |
| 90 | 106 |
| 91 var dialog = page.$$('settings-clear-browsing-data-dialog'); | 107 var dialog = page.$$('settings-clear-browsing-data-dialog'); |
| 92 assertTrue(!!dialog); | 108 assertTrue(!!dialog); |
| 93 | 109 |
| 94 // Ensure that the dialog is fully opened before returning from this | 110 // Ensure that the dialog is fully opened before returning from this |
| 95 // test, otherwise asynchronous code run in attached() can cause flaky | 111 // test, otherwise asynchronous code run in attached() can cause flaky |
| 96 // errors. | 112 // errors. |
| 97 return test_util.whenAttributeIs(dialog.$.dialog, 'open', ''); | 113 return test_util.whenAttributeIs( |
| 114 dialog.$.clearBrowsingDataDialog, 'open', ''); | |
| 98 }); | 115 }); |
| 99 }); | 116 }); |
| 100 } | 117 } |
| 101 | 118 |
| 102 function registerClearBrowsingDataTests() { | 119 function registerClearBrowsingDataTests() { |
| 103 suite('ClearBrowsingData', function() { | 120 suite('ClearBrowsingData', function() { |
| 104 /** @type {settings.TestClearBrowsingDataBrowserProxy} */ | 121 /** @type {settings.TestClearBrowsingDataBrowserProxy} */ |
| 105 var testBrowserProxy; | 122 var testBrowserProxy; |
| 106 | 123 |
| 107 /** @type {SettingsClearBrowsingDataDialogElement} */ | 124 /** @type {SettingsClearBrowsingDataDialogElement} */ |
| 108 var element; | 125 var element; |
| 109 | 126 |
| 110 setup(function() { | 127 setup(function() { |
| 111 testBrowserProxy = new TestClearBrowsingDataBrowserProxy(); | 128 testBrowserProxy = new TestClearBrowsingDataBrowserProxy(); |
| 112 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy; | 129 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy; |
| 113 PolymerTest.clearBody(); | 130 PolymerTest.clearBody(); |
| 114 element = document.createElement('settings-clear-browsing-data-dialog'); | 131 element = document.createElement('settings-clear-browsing-data-dialog'); |
| 115 document.body.appendChild(element); | 132 document.body.appendChild(element); |
| 116 return testBrowserProxy.whenCalled('initialize'); | 133 return testBrowserProxy.whenCalled('initialize') |
| 117 }); | 134 }); |
| 118 | 135 |
| 119 teardown(function() { element.remove(); }); | 136 teardown(function() { element.remove(); }); |
| 120 | 137 |
| 121 test('ClearBrowsingDataTap', function() { | 138 test('ClearBrowsingDataTap', function() { |
| 122 assertTrue(element.$.dialog.open); | 139 assertTrue(element.$.clearBrowsingDataDialog.open); |
| 140 assertFalse(element.showImportantSitesDialog_); | |
| 123 | 141 |
| 124 var cancelButton = element.$$('.cancel-button'); | 142 var cancelButton = element.$$('.cancel-button'); |
| 125 assertTrue(!!cancelButton); | 143 assertTrue(!!cancelButton); |
| 126 var actionButton = element.$$('.action-button'); | 144 var actionButton = element.$$('.action-button'); |
| 127 assertTrue(!!actionButton); | 145 assertTrue(!!actionButton); |
| 128 var spinner = element.$$('paper-spinner'); | 146 var spinner = element.$$('paper-spinner'); |
| 129 assertTrue(!!spinner); | 147 assertTrue(!!spinner); |
| 130 | 148 |
| 131 assertFalse(cancelButton.disabled); | 149 assertFalse(cancelButton.disabled); |
| 132 assertFalse(actionButton.disabled); | 150 assertFalse(actionButton.disabled); |
| 133 assertFalse(spinner.active); | 151 assertFalse(spinner.active); |
| 134 | 152 |
| 135 var promiseResolver = new PromiseResolver(); | 153 var promiseResolver = new PromiseResolver(); |
| 136 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); | 154 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); |
| 137 MockInteractions.tap(actionButton); | 155 MockInteractions.tap(actionButton); |
| 138 | 156 |
| 139 return testBrowserProxy.whenCalled('clearBrowsingData').then( | 157 return testBrowserProxy.whenCalled('clearBrowsingData') |
| 140 function() { | 158 .then(function(importantSites) { |
| 141 assertTrue(element.$.dialog.open); | 159 assertTrue(element.$.clearBrowsingDataDialog.open); |
| 142 assertTrue(cancelButton.disabled); | 160 assertTrue(cancelButton.disabled); |
| 143 assertTrue(actionButton.disabled); | 161 assertTrue(actionButton.disabled); |
| 144 assertTrue(spinner.active); | 162 assertTrue(spinner.active); |
| 163 assertTrue(importantSites.length == 0); | |
| 145 | 164 |
| 146 // Simulate signal from browser indicating that clearing has | 165 // Simulate signal from browser indicating that clearing has |
| 147 // completed. | 166 // completed. |
| 148 cr.webUIListenerCallback('browsing-data-removing', false); | 167 cr.webUIListenerCallback('browsing-data-removing', false); |
| 149 promiseResolver.resolve(); | 168 promiseResolver.resolve(); |
| 150 // Yields to the message loop to allow the callback chain of the | 169 // Yields to the message loop to allow the callback chain of the |
| 151 // Promise that was just resolved to execute before the | 170 // Promise that was just resolved to execute before the |
| 152 // assertions. | 171 // assertions. |
| 153 }).then(function() { | 172 }) |
| 154 assertFalse(element.$.dialog.open); | 173 .then(function() { |
| 174 assertFalse(element.$.clearBrowsingDataDialog.open); | |
| 155 assertFalse(cancelButton.disabled); | 175 assertFalse(cancelButton.disabled); |
| 156 assertFalse(actionButton.disabled); | 176 assertFalse(actionButton.disabled); |
| 157 assertFalse(spinner.active); | 177 assertFalse(spinner.active); |
| 158 assertFalse(!!element.$$('#notice')); | 178 assertFalse(!!element.$$('#notice')); |
| 179 // Check that the dialog didn't switch to important sites. | |
| 180 assertFalse(element.showImportantSitesDialog_); | |
| 159 }); | 181 }); |
| 160 }); | 182 }); |
| 161 | 183 |
| 162 test('showHistoryDeletionDialog', function() { | 184 test('showHistoryDeletionDialog', function() { |
| 163 assertTrue(element.$.dialog.open); | 185 assertTrue(element.$.clearBrowsingDataDialog.open); |
| 164 var actionButton = element.$$('.action-button'); | 186 var actionButton = element.$$('.action-button'); |
| 165 assertTrue(!!actionButton); | 187 assertTrue(!!actionButton); |
| 166 | 188 |
| 167 var promiseResolver = new PromiseResolver(); | 189 var promiseResolver = new PromiseResolver(); |
| 168 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); | 190 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); |
| 169 MockInteractions.tap(actionButton); | 191 MockInteractions.tap(actionButton); |
| 170 | 192 |
| 171 return testBrowserProxy.whenCalled('clearBrowsingData').then( | 193 return testBrowserProxy.whenCalled('clearBrowsingData').then( |
| 172 function() { | 194 function() { |
| 173 // Passing showNotice = true should trigger the notice about other | 195 // Passing showNotice = true should trigger the notice about other |
| 174 // forms of browsing history to open, and the dialog to stay open. | 196 // forms of browsing history to open, and the dialog to stay open. |
| 175 promiseResolver.resolve(true /* showNotice */); | 197 promiseResolver.resolve(true /* showNotice */); |
| 176 | 198 |
| 177 // Yields to the message loop to allow the callback chain of the | 199 // Yields to the message loop to allow the callback chain of the |
| 178 // Promise that was just resolved to execute before the | 200 // Promise that was just resolved to execute before the |
| 179 // assertions. | 201 // assertions. |
| 180 }).then(function() { | 202 }).then(function() { |
| 181 Polymer.dom.flush(); | 203 Polymer.dom.flush(); |
| 182 var notice = element.$$('#notice'); | 204 var notice = element.$$('#notice'); |
| 183 assertTrue(!!notice); | 205 assertTrue(!!notice); |
| 184 var noticeActionButton = notice.$$('.action-button'); | 206 var noticeActionButton = notice.$$('.action-button'); |
| 185 assertTrue(!!noticeActionButton); | 207 assertTrue(!!noticeActionButton); |
| 186 | 208 |
| 187 assertTrue(element.$.dialog.open); | 209 assertTrue(element.$.clearBrowsingDataDialog.open); |
| 188 assertTrue(notice.$.dialog.open); | 210 assertTrue(notice.$.dialog.open); |
| 189 | 211 |
| 190 MockInteractions.tap(noticeActionButton); | 212 MockInteractions.tap(noticeActionButton); |
| 191 | 213 |
| 192 return new Promise(function(resolve, reject) { | 214 return new Promise(function(resolve, reject) { |
| 193 // Tapping the action button will close the notice. Move to the | 215 // Tapping the action button will close the notice. Move to the |
| 194 // end of the message loop to allow the closing event to | 216 // end of the message loop to allow the closing event to |
| 195 // propagate to the parent dialog. The parent dialog should | 217 // propagate to the parent dialog. The parent dialog should |
| 196 // subsequently close as well. | 218 // subsequently close as well. |
| 197 setTimeout(function() { | 219 setTimeout(function() { |
| 198 var notice = element.$$('#notice'); | 220 var notice = element.$$('#notice'); |
| 199 assertFalse(!!notice); | 221 assertFalse(!!notice); |
| 200 assertFalse(element.$.dialog.open); | 222 assertFalse(element.$.clearBrowsingDataDialog.open); |
| 201 resolve(); | 223 resolve(); |
| 202 }, 0); | 224 }, 0); |
| 203 }); | 225 }); |
| 204 }); | 226 }); |
| 205 }); | 227 }); |
| 206 | 228 |
| 207 test('Counters', function() { | 229 test('Counters', function() { |
| 208 assertTrue(element.$.dialog.open); | 230 assertTrue(element.$.clearBrowsingDataDialog.open); |
| 209 | 231 |
| 210 // Initialize the browsing history pref, which should belong to the | 232 // Initialize the browsing history pref, which should belong to the |
| 211 // first checkbox in the dialog. | 233 // first checkbox in the dialog. |
| 212 element.set('prefs', { | 234 element.set('prefs', { |
| 213 browser: { | 235 browser: { |
| 214 clear_data: { | 236 clear_data: { |
| 215 browsing_history: { | 237 browsing_history: { |
| 216 key: 'browser.clear_data.browsing_history', | 238 key: 'browser.clear_data.browsing_history', |
| 217 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 239 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 218 value: true, | 240 value: true, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 244 Polymer.dom.flush(); | 266 Polymer.dom.flush(); |
| 245 | 267 |
| 246 return testBrowserProxy.whenCalled('initialize').then(function() { | 268 return testBrowserProxy.whenCalled('initialize').then(function() { |
| 247 assertTrue(element.$.browsingCheckbox.hidden); | 269 assertTrue(element.$.browsingCheckbox.hidden); |
| 248 assertTrue(element.$.downloadCheckbox.hidden); | 270 assertTrue(element.$.downloadCheckbox.hidden); |
| 249 }); | 271 }); |
| 250 }); | 272 }); |
| 251 }); | 273 }); |
| 252 } | 274 } |
| 253 | 275 |
| 276 suite('ImportantSites', function() { | |
| 277 /** @type {settings.TestClearBrowsingDataBrowserProxy} */ | |
| 278 var testBrowserProxy; | |
| 279 | |
| 280 /** @type {SettingsClearBrowsingDataDialogElement} */ | |
| 281 var element; | |
| 282 | |
| 283 /** @type {Array<ImportantSite>} */ | |
| 284 var importantSites = [ | |
| 285 {registerableDomain: 'google.com', isChecked: true}, | |
| 286 {registerableDomain: 'yahoo.com', isChecked: true} | |
| 287 ]; | |
| 288 | |
| 289 setup(function() { | |
| 290 loadTimeData.overrideValues({importantSitesInCbd: true}); | |
| 291 testBrowserProxy = new TestClearBrowsingDataBrowserProxy(); | |
| 292 testBrowserProxy.setImportantSitesResponse({ | |
| 293 flagEnabled: true, | |
| 294 importantSites: importantSites, | |
| 295 }); | |
| 296 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy; | |
| 297 PolymerTest.clearBody(); | |
| 298 element = document.createElement('settings-clear-browsing-data-dialog'); | |
| 299 document.body.appendChild(element); | |
| 300 return testBrowserProxy.whenCalled('initialize').then(function() { | |
| 301 return testBrowserProxy.whenCalled('fetchImportantSites'); | |
| 302 }); | |
| 303 }); | |
| 304 | |
| 305 teardown(function() { | |
| 306 element.remove(); | |
| 307 }); | |
| 308 | |
| 309 test('fetchImportantSites', function() { | |
| 310 assertTrue(element.$.clearBrowsingDataDialog.open); | |
| 311 assertFalse(element.showImportantSitesDialog_); | |
| 312 // Select an entry that can have important storage. | |
| 313 element.$.cookiesCheckbox.checked = true; | |
| 314 // Clear browsing data. | |
| 315 MockInteractions.tap(element.$.clearBrowsingDataConfirm); | |
| 316 Polymer.dom.flush(); | |
| 317 assertFalse(element.$.clearBrowsingDataDialog.open); | |
| 318 assertTrue(element.showImportantSitesDialog_); | |
| 319 return new Promise(function(resolve) { element.async(resolve); }) | |
| 320 .then(function() { | |
| 321 assertTrue(element.$$('#importantSitesDialog').open); | |
| 322 var firstImportantSite = element.$$('important-site-checkbox') | |
| 323 assertTrue(!!firstImportantSite); | |
| 324 assertEquals( | |
| 325 firstImportantSite.site.registerableDomain, 'google.com'); | |
| 326 assertTrue(firstImportantSite.site.isChecked) | |
| 327 // Choose to keep storage for google.com. | |
| 328 MockInteractions.tap(firstImportantSite.$.checkbox); | |
| 329 assertFalse(firstImportantSite.site.isChecked) | |
| 330 // Confirm deletion. | |
| 331 MockInteractions.tap(element.$$('#importantSitesConfirm')); | |
| 332 return testBrowserProxy.whenCalled('clearBrowsingData') | |
| 333 .then(function(sites) { | |
| 334 assertEquals(sites.length, 2); | |
| 335 assertEquals(sites[0].registerableDomain, 'google.com'); | |
| 336 assertFalse(sites[0].isChecked); | |
| 337 assertEquals(sites[1].registerableDomain, 'yahoo.com'); | |
| 338 assertTrue(sites[1].isChecked); | |
| 339 }); | |
| 340 }); | |
| 341 }); | |
| 342 }); | |
| 343 | |
| 254 function registerSafeBrowsingExtendedReportingTests() { | 344 function registerSafeBrowsingExtendedReportingTests() { |
| 255 suite('SafeBrowsingExtendedReporting', function() { | 345 suite('SafeBrowsingExtendedReporting', function() { |
| 256 /** @type {settings.TestPrivacyPageBrowserProxy} */ | 346 /** @type {settings.TestPrivacyPageBrowserProxy} */ |
| 257 var testBrowserProxy; | 347 var testBrowserProxy; |
| 258 | 348 |
| 259 /** @type {SettingsPrivacyPageElement} */ | 349 /** @type {SettingsPrivacyPageElement} */ |
| 260 var page; | 350 var page; |
| 261 | 351 |
| 262 setup(function() { | 352 setup(function() { |
| 263 testBrowserProxy = new TestPrivacyPageBrowserProxy(); | 353 testBrowserProxy = new TestPrivacyPageBrowserProxy(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 registerTests: function() { | 386 registerTests: function() { |
| 297 if (cr.isMac || cr.isWin) | 387 if (cr.isMac || cr.isWin) |
| 298 registerNativeCertificateManagerTests(); | 388 registerNativeCertificateManagerTests(); |
| 299 | 389 |
| 300 registerClearBrowsingDataTests(); | 390 registerClearBrowsingDataTests(); |
| 301 registerPrivacyPageTests(); | 391 registerPrivacyPageTests(); |
| 302 registerSafeBrowsingExtendedReportingTests(); | 392 registerSafeBrowsingExtendedReportingTests(); |
| 303 }, | 393 }, |
| 304 }; | 394 }; |
| 305 }); | 395 }); |
| OLD | NEW |