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