Chromium Code Reviews| Index: chrome/test/data/webui/settings/privacy_page_test.js | 
| diff --git a/chrome/test/data/webui/settings/privacy_page_test.js b/chrome/test/data/webui/settings/privacy_page_test.js | 
| index 0488099c61caf12b4cc1e8dd97dfd7fcc128c55a..01c1bd219d4890ab4b579ce0a22d607dd0a097fd 100644 | 
| --- a/chrome/test/data/webui/settings/privacy_page_test.js | 
| +++ b/chrome/test/data/webui/settings/privacy_page_test.js | 
| @@ -9,10 +9,8 @@ cr.define('settings_privacy_page', function() { | 
| * @implements {settings.ClearBrowsingDataBrowserProxy} | 
| */ | 
| function TestClearBrowsingDataBrowserProxy() { | 
| - settings.TestBrowserProxy.call(this, [ | 
| - 'initialize', | 
| - 'clearBrowsingData', | 
| - ]); | 
| + settings.TestBrowserProxy.call( | 
| + this, ['initialize', 'clearBrowsingData', 'fetchImportantSites']); | 
| /** | 
| * The promise to return from |clearBrowsingData|. | 
| @@ -21,6 +19,13 @@ cr.define('settings_privacy_page', function() { | 
| * @private {?Promise} | 
| */ | 
| this.clearBrowsingDataPromise_ = null; | 
| + | 
| + /** | 
| + * Default response for fetchImportantSites. It tells the ui that important | 
| + * sites are disabled. | 
| + * @private {!ImportantSitesResponse} | 
| + */ | 
| + this.importantSitesResponse_ = {flagEnabled: false, importantSites: []}; | 
| } | 
| TestClearBrowsingDataBrowserProxy.prototype = { | 
| @@ -32,13 +37,24 @@ cr.define('settings_privacy_page', function() { | 
| }, | 
| /** @override */ | 
| - clearBrowsingData: function() { | 
| - this.methodCalled('clearBrowsingData'); | 
| + clearBrowsingData: function(importantSites) { | 
| + this.methodCalled('clearBrowsingData', importantSites); | 
| cr.webUIListenerCallback('browsing-data-removing', true); | 
| return this.clearBrowsingDataPromise_ !== null ? | 
| this.clearBrowsingDataPromise_ : Promise.resolve(); | 
| }, | 
| + /** @param {!ImportantSitesResponse} response */ | 
| + setImportantSitesResponse: function(response) { | 
| + this.importantSitesResponse_ = response; | 
| + }, | 
| + | 
| + /** @override */ | 
| + fetchImportantSites: function() { | 
| + this.methodCalled('fetchImportantSites'); | 
| + return Promise.resolve(this.importantSitesResponse_); | 
| + }, | 
| + | 
| /** @override */ | 
| initialize: function() { | 
| this.methodCalled('initialize'); | 
| @@ -94,7 +110,8 @@ cr.define('settings_privacy_page', function() { | 
| // Ensure that the dialog is fully opened before returning from this | 
| // test, otherwise asynchronous code run in attached() can cause flaky | 
| // errors. | 
| - return test_util.whenAttributeIs(dialog.$.dialog, 'open', true); | 
| + return test_util.whenAttributeIs( | 
| + dialog.$.clearBrowsingDataDialog, 'open', true); | 
| }); | 
| }); | 
| } | 
| @@ -113,13 +130,17 @@ cr.define('settings_privacy_page', function() { | 
| PolymerTest.clearBody(); | 
| element = document.createElement('settings-clear-browsing-data-dialog'); | 
| document.body.appendChild(element); | 
| - return testBrowserProxy.whenCalled('initialize'); | 
| + return testBrowserProxy.whenCalled('initialize').then(function() { | 
| + return testBrowserProxy.whenCalled('fetchImportantSites'); | 
| + }); | 
| }); | 
| teardown(function() { element.remove(); }); | 
| test('ClearBrowsingDataTap', function() { | 
| - assertTrue(element.$.dialog.open); | 
| + assertTrue(element.$.clearBrowsingDataDialog.open); | 
| + assertFalse(element.$.importantSitesDialog.open); | 
| + assertFalse(element.importantSitesFlagEnabled_); | 
| var cancelButton = element.$$('.cancel-button'); | 
| assertTrue(!!cancelButton); | 
| @@ -136,12 +157,13 @@ cr.define('settings_privacy_page', function() { | 
| testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); | 
| MockInteractions.tap(actionButton); | 
| - return testBrowserProxy.whenCalled('clearBrowsingData').then( | 
| - function() { | 
| - assertTrue(element.$.dialog.open); | 
| + return testBrowserProxy.whenCalled('clearBrowsingData') | 
| + .then(function(importantSites) { | 
| + assertTrue(element.$.clearBrowsingDataDialog.open); | 
| assertTrue(cancelButton.disabled); | 
| assertTrue(actionButton.disabled); | 
| assertTrue(spinner.active); | 
| + assertTrue(importantSites.length == 0); | 
| // Simulate signal from browser indicating that clearing has | 
| // completed. | 
| @@ -150,17 +172,20 @@ cr.define('settings_privacy_page', function() { | 
| // Yields to the message loop to allow the callback chain of the | 
| // Promise that was just resolved to execute before the | 
| // assertions. | 
| - }).then(function() { | 
| - assertFalse(element.$.dialog.open); | 
| + }) | 
| + .then(function() { | 
| + assertFalse(element.$.clearBrowsingDataDialog.open); | 
| assertFalse(cancelButton.disabled); | 
| assertFalse(actionButton.disabled); | 
| assertFalse(spinner.active); | 
| assertFalse(!!element.$$('#notice')); | 
| + // Check that the dialog didn't switch to important sites. | 
| + assertFalse(element.$.importantSitesDialog.open); | 
| }); | 
| }); | 
| test('showHistoryDeletionDialog', function() { | 
| - assertTrue(element.$.dialog.open); | 
| + assertTrue(element.$.clearBrowsingDataDialog.open); | 
| var actionButton = element.$$('.action-button'); | 
| assertTrue(!!actionButton); | 
| @@ -184,7 +209,7 @@ cr.define('settings_privacy_page', function() { | 
| var noticeActionButton = notice.$$('.action-button'); | 
| assertTrue(!!noticeActionButton); | 
| - assertTrue(element.$.dialog.open); | 
| + assertTrue(element.$.clearBrowsingDataDialog.open); | 
| assertTrue(notice.$.dialog.open); | 
| MockInteractions.tap(noticeActionButton); | 
| @@ -197,7 +222,7 @@ cr.define('settings_privacy_page', function() { | 
| setTimeout(function() { | 
| var notice = element.$$('#notice'); | 
| assertFalse(!!notice); | 
| - assertFalse(element.$.dialog.open); | 
| + assertFalse(element.$.clearBrowsingDataDialog.open); | 
| resolve(); | 
| }, 0); | 
| }); | 
| @@ -205,7 +230,7 @@ cr.define('settings_privacy_page', function() { | 
| }); | 
| test('Counters', function() { | 
| - assertTrue(element.$.dialog.open); | 
| + assertTrue(element.$.clearBrowsingDataDialog.open); | 
| // Initialize the browsing history pref, which should belong to the | 
| // first checkbox in the dialog. | 
| @@ -232,6 +257,69 @@ cr.define('settings_privacy_page', function() { | 
| }); | 
| } | 
| + suite('ImportantSites', function() { | 
| + /** @type {settings.TestClearBrowsingDataBrowserProxy} */ | 
| + var testBrowserProxy; | 
| + | 
| + /** @type {SettingsClearBrowsingDataDialogElement} */ | 
| + var element; | 
| + | 
| + /** @type {Array<ImportantSite>} */ | 
| + var importantSites = [ | 
| + {registerableDomain: 'google.com', isChecked: true}, | 
| + {registerableDomain: 'yahoo.com', isChecked: true} | 
| + ] | 
| 
 
Dan Beam
2017/05/09 19:23:18
] -> ];
 
dullweber
2017/05/11 13:13:48
Done.
 
 | 
| + | 
| + setup(function() { | 
| + testBrowserProxy = new TestClearBrowsingDataBrowserProxy(); | 
| + testBrowserProxy.setImportantSitesResponse({ | 
| + flagEnabled: true, | 
| + importantSites: importantSites, | 
| + }); | 
| + settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy; | 
| + PolymerTest.clearBody(); | 
| + element = document.createElement('settings-clear-browsing-data-dialog'); | 
| + document.body.appendChild(element); | 
| + return testBrowserProxy.whenCalled('initialize').then(function() { | 
| + return testBrowserProxy.whenCalled('fetchImportantSites'); | 
| + }); | 
| + }); | 
| + | 
| + teardown(function() { | 
| + element.remove(); | 
| + }); | 
| + | 
| + test('fetchImportantSites', function() { | 
| + assertTrue(element.$.clearBrowsingDataDialog.open); | 
| + assertFalse(element.$.importantSitesDialog.open); | 
| + // Select an entry that can have important storage. | 
| + element.$.cookiesCheckbox.checked = true; | 
| + // Clear browsing data. | 
| + MockInteractions.tap(element.$.clearBrowsingDataConfirm); | 
| + assertFalse(element.$.clearBrowsingDataDialog.open); | 
| + assertTrue(element.$.importantSitesDialog.open); | 
| + | 
| + Polymer.dom.flush(); | 
| + var firstImportantSite = element.$$('important-site-checkbox') | 
| + assertTrue(!!firstImportantSite); | 
| + assertEquals(firstImportantSite.site.registerableDomain, 'google.com'); | 
| + assertTrue(firstImportantSite.site.isChecked) | 
| + // Choose to keep storage for google.com. | 
| + MockInteractions.tap(firstImportantSite.$.checkbox); | 
| + assertFalse(firstImportantSite.site.isChecked) | 
| + // Confirm deletion. | 
| + MockInteractions.tap(element.$.importantSitesConfirm); | 
| + return testBrowserProxy.whenCalled('clearBrowsingData') | 
| + .then(function(sites) { | 
| + assertEquals(sites.length, 2); | 
| + assertEquals(sites[0].registerableDomain, 'google.com'); | 
| + assertFalse(sites[0].isChecked); | 
| + assertEquals(sites[1].registerableDomain, 'yahoo.com'); | 
| + assertTrue(sites[1].isChecked); | 
| + }); | 
| + }); | 
| + }); | 
| + | 
| function registerSafeBrowsingExtendedReportingTests() { | 
| suite('SafeBrowsingExtendedReporting', function() { | 
| /** @type {settings.TestPrivacyPageBrowserProxy} */ |