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

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

Issue 2716333002: Implement important sites dialog for desktop. (Closed)
Patch Set: fix comments 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.$.importantSitesDialog.open);
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.$.importantSitesDialog.open);
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,
219 } 244 }
220 } 245 }
221 } 246 }
222 }); 247 });
223 var checkbox = element.$$('settings-checkbox'); 248 var checkbox = element.$$('settings-checkbox');
224 assertEquals('browser.clear_data.browsing_history', checkbox.pref.key); 249 assertEquals('browser.clear_data.browsing_history', checkbox.pref.key);
225 250
226 // Simulate a browsing data counter result for history. This checkbox's 251 // Simulate a browsing data counter result for history. This checkbox's
227 // sublabel should be updated. 252 // sublabel should be updated.
228 cr.webUIListenerCallback( 253 cr.webUIListenerCallback(
229 'update-counter-text', checkbox.pref.key, 'result'); 254 'update-counter-text', checkbox.pref.key, 'result');
230 assertEquals('result', checkbox.subLabel); 255 assertEquals('result', checkbox.subLabel);
231 }); 256 });
232 }); 257 });
233 } 258 }
234 259
260 suite('ImportantSites', function() {
261 /** @type {settings.TestClearBrowsingDataBrowserProxy} */
262 var testBrowserProxy;
263
264 /** @type {SettingsClearBrowsingDataDialogElement} */
265 var element;
266
267 /** @type {Array<ImportantSite>} */
268 var importantSites = [
269 {registerableDomain: 'google.com', isChecked: true},
270 {registerableDomain: 'yahoo.com', isChecked: true}
271 ]
Dan Beam 2017/05/09 19:23:18 ] -> ];
dullweber 2017/05/11 13:13:48 Done.
272
273 setup(function() {
274 testBrowserProxy = new TestClearBrowsingDataBrowserProxy();
275 testBrowserProxy.setImportantSitesResponse({
276 flagEnabled: true,
277 importantSites: importantSites,
278 });
279 settings.ClearBrowsingDataBrowserProxyImpl.instance_ = testBrowserProxy;
280 PolymerTest.clearBody();
281 element = document.createElement('settings-clear-browsing-data-dialog');
282 document.body.appendChild(element);
283 return testBrowserProxy.whenCalled('initialize').then(function() {
284 return testBrowserProxy.whenCalled('fetchImportantSites');
285 });
286 });
287
288 teardown(function() {
289 element.remove();
290 });
291
292 test('fetchImportantSites', function() {
293 assertTrue(element.$.clearBrowsingDataDialog.open);
294 assertFalse(element.$.importantSitesDialog.open);
295 // Select an entry that can have important storage.
296 element.$.cookiesCheckbox.checked = true;
297 // Clear browsing data.
298 MockInteractions.tap(element.$.clearBrowsingDataConfirm);
299 assertFalse(element.$.clearBrowsingDataDialog.open);
300 assertTrue(element.$.importantSitesDialog.open);
301
302 Polymer.dom.flush();
303 var firstImportantSite = element.$$('important-site-checkbox')
304 assertTrue(!!firstImportantSite);
305 assertEquals(firstImportantSite.site.registerableDomain, 'google.com');
306 assertTrue(firstImportantSite.site.isChecked)
307 // Choose to keep storage for google.com.
308 MockInteractions.tap(firstImportantSite.$.checkbox);
309 assertFalse(firstImportantSite.site.isChecked)
310 // Confirm deletion.
311 MockInteractions.tap(element.$.importantSitesConfirm);
312 return testBrowserProxy.whenCalled('clearBrowsingData')
313 .then(function(sites) {
314 assertEquals(sites.length, 2);
315 assertEquals(sites[0].registerableDomain, 'google.com');
316 assertFalse(sites[0].isChecked);
317 assertEquals(sites[1].registerableDomain, 'yahoo.com');
318 assertTrue(sites[1].isChecked);
319 });
320 });
321 });
322
235 function registerSafeBrowsingExtendedReportingTests() { 323 function registerSafeBrowsingExtendedReportingTests() {
236 suite('SafeBrowsingExtendedReporting', function() { 324 suite('SafeBrowsingExtendedReporting', function() {
237 /** @type {settings.TestPrivacyPageBrowserProxy} */ 325 /** @type {settings.TestPrivacyPageBrowserProxy} */
238 var testBrowserProxy; 326 var testBrowserProxy;
239 327
240 /** @type {SettingsPrivacyPageElement} */ 328 /** @type {SettingsPrivacyPageElement} */
241 var page; 329 var page;
242 330
243 setup(function() { 331 setup(function() {
244 testBrowserProxy = new TestPrivacyPageBrowserProxy(); 332 testBrowserProxy = new TestPrivacyPageBrowserProxy();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 registerTests: function() { 365 registerTests: function() {
278 if (cr.isMac || cr.isWin) 366 if (cr.isMac || cr.isWin)
279 registerNativeCertificateManagerTests(); 367 registerNativeCertificateManagerTests();
280 368
281 registerClearBrowsingDataTests(); 369 registerClearBrowsingDataTests();
282 registerPrivacyPageTests(); 370 registerPrivacyPageTests();
283 registerSafeBrowsingExtendedReportingTests(); 371 registerSafeBrowsingExtendedReportingTests();
284 }, 372 },
285 }; 373 };
286 }); 374 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698