Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/test/data/webui/settings/privacy_page_test.js

Issue 2716333002: Implement important sites dialog for desktop. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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', true); 113 return test_util.whenAttributeIs(
114 dialog.$.clearBrowsingDataDialog, 'open', true);
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').then(function() {
134 return testBrowserProxy.whenCalled('fetchImportantSites');
135 });
117 }); 136 });
118 137
119 teardown(function() { element.remove(); }); 138 teardown(function() { element.remove(); });
120 139
121 test('ClearBrowsingDataTap', function() { 140 test('ClearBrowsingDataTap', function() {
122 assertTrue(element.$.dialog.open); 141 assertTrue(element.$.clearBrowsingDataDialog.open);
142 assertFalse(element.showImportantSitesDialog_);
143 assertFalse(element.importantSitesFlagEnabled_);
123 144
124 var cancelButton = element.$$('.cancel-button'); 145 var cancelButton = element.$$('.cancel-button');
125 assertTrue(!!cancelButton); 146 assertTrue(!!cancelButton);
126 var actionButton = element.$$('.action-button'); 147 var actionButton = element.$$('.action-button');
127 assertTrue(!!actionButton); 148 assertTrue(!!actionButton);
128 var spinner = element.$$('paper-spinner'); 149 var spinner = element.$$('paper-spinner');
129 assertTrue(!!spinner); 150 assertTrue(!!spinner);
130 151
131 assertFalse(cancelButton.disabled); 152 assertFalse(cancelButton.disabled);
132 assertFalse(actionButton.disabled); 153 assertFalse(actionButton.disabled);
133 assertFalse(spinner.active); 154 assertFalse(spinner.active);
134 155
135 var promiseResolver = new PromiseResolver(); 156 var promiseResolver = new PromiseResolver();
136 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); 157 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise);
137 MockInteractions.tap(actionButton); 158 MockInteractions.tap(actionButton);
138 159
139 return testBrowserProxy.whenCalled('clearBrowsingData').then( 160 return testBrowserProxy.whenCalled('clearBrowsingData')
140 function() { 161 .then(function(importantSites) {
141 assertTrue(element.$.dialog.open); 162 assertTrue(element.$.clearBrowsingDataDialog.open);
142 assertTrue(cancelButton.disabled); 163 assertTrue(cancelButton.disabled);
143 assertTrue(actionButton.disabled); 164 assertTrue(actionButton.disabled);
144 assertTrue(spinner.active); 165 assertTrue(spinner.active);
166 assertTrue(importantSites.length == 0);
145 167
146 // Simulate signal from browser indicating that clearing has 168 // Simulate signal from browser indicating that clearing has
147 // completed. 169 // completed.
148 cr.webUIListenerCallback('browsing-data-removing', false); 170 cr.webUIListenerCallback('browsing-data-removing', false);
149 promiseResolver.resolve(); 171 promiseResolver.resolve();
150 // Yields to the message loop to allow the callback chain of the 172 // Yields to the message loop to allow the callback chain of the
151 // Promise that was just resolved to execute before the 173 // Promise that was just resolved to execute before the
152 // assertions. 174 // assertions.
153 }).then(function() { 175 })
154 assertFalse(element.$.dialog.open); 176 .then(function() {
177 assertFalse(element.$.clearBrowsingDataDialog.open);
155 assertFalse(cancelButton.disabled); 178 assertFalse(cancelButton.disabled);
156 assertFalse(actionButton.disabled); 179 assertFalse(actionButton.disabled);
157 assertFalse(spinner.active); 180 assertFalse(spinner.active);
158 assertFalse(!!element.$$('#notice')); 181 assertFalse(!!element.$$('#notice'));
182 // Check that the dialog didn't switch to important sites.
183 assertFalse(element.showImportantSitesDialog_);
159 }); 184 });
160 }); 185 });
161 186
162 test('showHistoryDeletionDialog', function() { 187 test('showHistoryDeletionDialog', function() {
163 assertTrue(element.$.dialog.open); 188 assertTrue(element.$.clearBrowsingDataDialog.open);
164 var actionButton = element.$$('.action-button'); 189 var actionButton = element.$$('.action-button');
165 assertTrue(!!actionButton); 190 assertTrue(!!actionButton);
166 191
167 var promiseResolver = new PromiseResolver(); 192 var promiseResolver = new PromiseResolver();
168 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise); 193 testBrowserProxy.setClearBrowsingDataPromise(promiseResolver.promise);
169 MockInteractions.tap(actionButton); 194 MockInteractions.tap(actionButton);
170 195
171 return testBrowserProxy.whenCalled('clearBrowsingData').then( 196 return testBrowserProxy.whenCalled('clearBrowsingData').then(
172 function() { 197 function() {
173 // Passing showNotice = true should trigger the notice about other 198 // Passing showNotice = true should trigger the notice about other
174 // forms of browsing history to open, and the dialog to stay open. 199 // forms of browsing history to open, and the dialog to stay open.
175 promiseResolver.resolve(true /* showNotice */); 200 promiseResolver.resolve(true /* showNotice */);
176 201
177 // Yields to the message loop to allow the callback chain of the 202 // Yields to the message loop to allow the callback chain of the
178 // Promise that was just resolved to execute before the 203 // Promise that was just resolved to execute before the
179 // assertions. 204 // assertions.
180 }).then(function() { 205 }).then(function() {
181 Polymer.dom.flush(); 206 Polymer.dom.flush();
182 var notice = element.$$('#notice'); 207 var notice = element.$$('#notice');
183 assertTrue(!!notice); 208 assertTrue(!!notice);
184 var noticeActionButton = notice.$$('.action-button'); 209 var noticeActionButton = notice.$$('.action-button');
185 assertTrue(!!noticeActionButton); 210 assertTrue(!!noticeActionButton);
186 211
187 assertTrue(element.$.dialog.open); 212 assertTrue(element.$.clearBrowsingDataDialog.open);
188 assertTrue(notice.$.dialog.open); 213 assertTrue(notice.$.dialog.open);
189 214
190 MockInteractions.tap(noticeActionButton); 215 MockInteractions.tap(noticeActionButton);
191 216
192 return new Promise(function(resolve, reject) { 217 return new Promise(function(resolve, reject) {
193 // Tapping the action button will close the notice. Move to the 218 // Tapping the action button will close the notice. Move to the
194 // end of the message loop to allow the closing event to 219 // end of the message loop to allow the closing event to
195 // propagate to the parent dialog. The parent dialog should 220 // propagate to the parent dialog. The parent dialog should
196 // subsequently close as well. 221 // subsequently close as well.
197 setTimeout(function() { 222 setTimeout(function() {
198 var notice = element.$$('#notice'); 223 var notice = element.$$('#notice');
199 assertFalse(!!notice); 224 assertFalse(!!notice);
200 assertFalse(element.$.dialog.open); 225 assertFalse(element.$.clearBrowsingDataDialog.open);
201 resolve(); 226 resolve();
202 }, 0); 227 }, 0);
203 }); 228 });
204 }); 229 });
205 }); 230 });
206 231
207 test('Counters', function() { 232 test('Counters', function() {
208 assertTrue(element.$.dialog.open); 233 assertTrue(element.$.clearBrowsingDataDialog.open);
209 234
210 // Initialize the browsing history pref, which should belong to the 235 // Initialize the browsing history pref, which should belong to the
211 // first checkbox in the dialog. 236 // first checkbox in the dialog.
212 element.set('prefs', { 237 element.set('prefs', {
213 browser: { 238 browser: {
214 clear_data: { 239 clear_data: {
215 browsing_history: { 240 browsing_history: {
216 key: 'browser.clear_data.browsing_history', 241 key: 'browser.clear_data.browsing_history',
217 type: chrome.settingsPrivate.PrefType.BOOLEAN, 242 type: chrome.settingsPrivate.PrefType.BOOLEAN,
218 value: true, 243 value: true,
(...skipping 25 matching lines...) Expand all
244 Polymer.dom.flush(); 269 Polymer.dom.flush();
245 270
246 return testBrowserProxy.whenCalled('initialize').then(function() { 271 return testBrowserProxy.whenCalled('initialize').then(function() {
247 assertTrue(element.$.browsingCheckbox.hidden); 272 assertTrue(element.$.browsingCheckbox.hidden);
248 assertTrue(element.$.downloadCheckbox.hidden); 273 assertTrue(element.$.downloadCheckbox.hidden);
249 }); 274 });
250 }); 275 });
251 }); 276 });
252 } 277 }
253 278
279 suite('ImportantSites', function() {
280 /** @type {settings.TestClearBrowsingDataBrowserProxy} */
281 var testBrowserProxy;
282
283 /** @type {SettingsClearBrowsingDataDialogElement} */
284 var element;
285
286 /** @type {Array<ImportantSite>} */
287 var importantSites = [
288 {registerableDomain: 'google.com', isChecked: true},
289 {registerableDomain: 'yahoo.com', isChecked: true}
290 ];
291
292 setup(function() {
293 testBrowserProxy = new TestClearBrowsingDataBrowserProxy();
294 testBrowserProxy.setImportantSitesResponse({
295 flagEnabled: true,
296 importantSites: importantSites,
297 });
298 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy;
299 PolymerTest.clearBody();
300 element = document.createElement('settings-clear-browsing-data-dialog');
301 document.body.appendChild(element);
302 return testBrowserProxy.whenCalled('initialize').then(function() {
303 return testBrowserProxy.whenCalled('fetchImportantSites');
304 });
305 });
306
307 teardown(function() {
308 element.remove();
309 });
310
311 test('fetchImportantSites', function() {
312 assertTrue(element.$.clearBrowsingDataDialog.open);
313 assertFalse(element.showImportantSitesDialog_);
314 // Select an entry that can have important storage.
315 element.$.cookiesCheckbox.checked = true;
316 // Clear browsing data.
317 MockInteractions.tap(element.$.clearBrowsingDataConfirm);
318 assertFalse(element.$.clearBrowsingDataDialog.open);
319 assertTrue(element.showImportantSitesDialog_);
320 assertTrue(element.$$('#importantSitesDialog').open);
321
322 Polymer.dom.flush();
323 var firstImportantSite = element.$$('important-site-checkbox')
324 assertTrue(!!firstImportantSite);
325 assertEquals(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
254 function registerSafeBrowsingExtendedReportingTests() { 343 function registerSafeBrowsingExtendedReportingTests() {
255 suite('SafeBrowsingExtendedReporting', function() { 344 suite('SafeBrowsingExtendedReporting', function() {
256 /** @type {settings.TestPrivacyPageBrowserProxy} */ 345 /** @type {settings.TestPrivacyPageBrowserProxy} */
257 var testBrowserProxy; 346 var testBrowserProxy;
258 347
259 /** @type {SettingsPrivacyPageElement} */ 348 /** @type {SettingsPrivacyPageElement} */
260 var page; 349 var page;
261 350
262 setup(function() { 351 setup(function() {
263 testBrowserProxy = new TestPrivacyPageBrowserProxy(); 352 testBrowserProxy = new TestPrivacyPageBrowserProxy();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 registerTests: function() { 385 registerTests: function() {
297 if (cr.isMac || cr.isWin) 386 if (cr.isMac || cr.isWin)
298 registerNativeCertificateManagerTests(); 387 registerNativeCertificateManagerTests();
299 388
300 registerClearBrowsingDataTests(); 389 registerClearBrowsingDataTests();
301 registerPrivacyPageTests(); 390 registerPrivacyPageTests();
302 registerSafeBrowsingExtendedReportingTests(); 391 registerSafeBrowsingExtendedReportingTests();
303 }, 392 },
304 }; 393 };
305 }); 394 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698