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

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

Issue 2769863006: [MD settings] unit test for incognito activation (Closed)
Patch Set: js format Created 3 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** @fileoverview Suite of tests for site-list. */ 5 /** @fileoverview Suite of tests for site-list. */
6 cr.define('site_list', function() { 6 cr.define('site_list', function() {
7 /** 7 /**
8 * An example pref with 2 blocked location items and 2 allowed. This pref 8 * An example pref with 2 blocked location items and 2 allowed. This pref
9 * is also used for the All Sites category and therefore needs values for 9 * is also used for the All Sites category and therefore needs values for
10 * all types, even though some might be blank. 10 * all types, even though some might be blank.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 midiDevices: [], 52 midiDevices: [],
53 notifications: [], 53 notifications: [],
54 plugins: [], 54 plugins: [],
55 protectedContent: [], 55 protectedContent: [],
56 popups: [], 56 popups: [],
57 unsandboxed_plugins: [], 57 unsandboxed_plugins: [],
58 } 58 }
59 }; 59 };
60 60
61 /** 61 /**
62 * An example of prefs controlleBy policy.
63 * @type {SiteSettingsPref}
64 */
65 var prefsControlled = {
66 exceptions: {
67 plugins: [
68 {
69 category: 'plugins',
70 embeddingOrigin: 'http://foo-block.com',
71 origin: 'http://foo-block.com',
72 setting: 'block',
73 source: 'policy',
74 },
75 ]
76 }
77 };
78
79 /**
62 * An example pref with mixed schemes (present and absent). 80 * An example pref with mixed schemes (present and absent).
63 * @type {SiteSettingsPref} 81 * @type {SiteSettingsPref}
64 */ 82 */
65 var prefsMixedSchemes = { 83 var prefsMixedSchemes = {
66 exceptions: { 84 exceptions: {
67 geolocation: [ 85 geolocation: [
68 { 86 {
69 category: 'geolocation', 87 category: 'geolocation',
70 embeddingOrigin: 'https://foo-allow.com', 88 embeddingOrigin: 'https://foo-allow.com',
71 origin: 'https://foo-allow.com', 89 origin: 'https://foo-allow.com',
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 var prefsVarious = { 182 var prefsVarious = {
165 exceptions: { 183 exceptions: {
166 auto_downloads: [], 184 auto_downloads: [],
167 background_sync: [], 185 background_sync: [],
168 camera: [], 186 camera: [],
169 cookies: [], 187 cookies: [],
170 geolocation: [ 188 geolocation: [
171 { 189 {
172 category: 'geolocation', 190 category: 'geolocation',
173 embeddingOrigin: 'https://foo.com', 191 embeddingOrigin: 'https://foo.com',
192 incognito: false,
174 origin: 'https://foo.com', 193 origin: 'https://foo.com',
175 setting: 'allow', 194 setting: 'allow',
176 source: 'preference', 195 source: 'preference',
177 }, 196 },
178 { 197 {
179 category: 'geolocation', 198 category: 'geolocation',
180 embeddingOrigin: 'https://bar.com', 199 embeddingOrigin: 'https://bar.com',
200 incognito: false,
181 origin: 'https://bar.com', 201 origin: 'https://bar.com',
182 setting: 'block', 202 setting: 'block',
183 source: 'preference', 203 source: 'preference',
184 }, 204 },
185 ], 205 ],
186 images: [], 206 images: [],
187 javascript: [], 207 javascript: [],
188 mic: [], 208 mic: [],
189 midiDevices: [], 209 midiDevices: [],
190 notifications: [ 210 notifications: [
191 { 211 {
192 category: 'notifications', 212 category: 'notifications',
193 embeddingOrigin: 'https://google.com', 213 embeddingOrigin: 'https://google.com',
214 incognito: false,
194 origin: 'https://google.com', 215 origin: 'https://google.com',
195 setting: 'block', 216 setting: 'block',
196 source: 'preference', 217 source: 'preference',
197 }, 218 },
198 { 219 {
199 category: 'notifications', 220 category: 'notifications',
200 embeddingOrigin: 'https://bar.com', 221 embeddingOrigin: 'https://bar.com',
222 incognito: false,
201 origin: 'https://bar.com', 223 origin: 'https://bar.com',
202 setting: 'block', 224 setting: 'block',
203 source: 'preference', 225 source: 'preference',
204 }, 226 },
205 { 227 {
206 category: 'notifications', 228 category: 'notifications',
207 embeddingOrigin: 'https://foo.com', 229 embeddingOrigin: 'https://foo.com',
230 incognito: false,
208 origin: 'https://foo.com', 231 origin: 'https://foo.com',
209 setting: 'block', 232 setting: 'block',
210 source: 'preference', 233 source: 'preference',
211 }, 234 },
212 ], 235 ],
213 plugins: [], 236 plugins: [],
214 protectedContent: [], 237 protectedContent: [],
215 popups: [], 238 popups: [],
216 unsandboxed_plugins: [], 239 unsandboxed_plugins: [],
217 } 240 }
218 }; 241 };
219 242
220 /** 243 /**
221 * An example pref with 1 allowed location item. 244 * An example pref with 1 allowed location item.
222 * @type {SiteSettingsPref} 245 * @type {SiteSettingsPref}
223 */ 246 */
224 var prefsOneEnabled = { 247 var prefsOneEnabled = {
225 exceptions: { 248 exceptions: {
226 geolocation: [ 249 geolocation: [
227 { 250 {
228 category: 'geolocation', 251 category: 'geolocation',
229 embeddingOrigin: 'https://foo-allow.com:443', 252 embeddingOrigin: 'https://foo-allow.com:443',
253 incognito: false,
230 origin: 'https://foo-allow.com:443', 254 origin: 'https://foo-allow.com:443',
231 setting: 'allow', 255 setting: 'allow',
232 source: 'preference', 256 source: 'preference',
233 }, 257 },
234 ] 258 ]
235 } 259 }
236 }; 260 };
237 261
238 /** 262 /**
239 * An example pref with 1 blocked location item. 263 * An example pref with 1 blocked location item.
240 * @type {SiteSettingsPref} 264 * @type {SiteSettingsPref}
241 */ 265 */
242 var prefsOneDisabled = { 266 var prefsOneDisabled = {
243 exceptions: { 267 exceptions: {
244 geolocation: [ 268 geolocation: [
245 { 269 {
246 category: 'geolocation', 270 category: 'geolocation',
247 embeddingOrigin: 'https://foo-block.com:443', 271 embeddingOrigin: 'https://foo-block.com:443',
272 incognito: false,
248 origin: 'https://foo-block.com:443', 273 origin: 'https://foo-block.com:443',
249 setting: 'block', 274 setting: 'block',
250 source: 'preference', 275 source: 'preference',
251 }, 276 },
252 ] 277 ]
253 } 278 }
254 }; 279 };
255 280
256 /** 281 /**
257 * An example Cookies pref with 1 in each of the three categories. 282 * An example Cookies pref with 1 in each of the three categories.
258 * @type {SiteSettingsPref} 283 * @type {SiteSettingsPref}
259 */ 284 */
260 var prefsSessionOnly = { 285 var prefsSessionOnly = {
261 exceptions: { 286 exceptions: {
262 cookies: [ 287 cookies: [
263 { 288 {
264 category: 'cookies', 289 category: 'cookies',
265 embeddingOrigin: 'http://foo-block.com', 290 embeddingOrigin: 'http://foo-block.com',
291 incognito: false,
266 origin: 'http://foo-block.com', 292 origin: 'http://foo-block.com',
267 setting: 'block', 293 setting: 'block',
268 source: 'preference', 294 source: 'preference',
269 }, 295 },
270 { 296 {
271 category: 'cookies', 297 category: 'cookies',
272 embeddingOrigin: 'http://foo-allow.com', 298 embeddingOrigin: 'http://foo-allow.com',
299 incognito: false,
273 origin: 'http://foo-allow.com', 300 origin: 'http://foo-allow.com',
274 setting: 'allow', 301 setting: 'allow',
275 source: 'preference', 302 source: 'preference',
276 }, 303 },
277 { 304 {
278 category: 'cookies', 305 category: 'cookies',
279 embeddingOrigin: 'http://foo-session.com', 306 embeddingOrigin: 'http://foo-session.com',
307 incognito: false,
280 origin: 'http://foo-session.com', 308 origin: 'http://foo-session.com',
281 setting: 'session_only', 309 setting: 'session_only',
282 source: 'preference', 310 source: 'preference',
283 }, 311 },
284 ] 312 ]
285 } 313 }
286 }; 314 };
287 315
288 /** 316 /**
289 * An example Cookies pref with mixed incognito and regular settings. 317 * An example Cookies pref with mixed incognito and regular settings.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 /** 355 /**
328 * An example Javascript pref with a chrome-extension:// scheme. 356 * An example Javascript pref with a chrome-extension:// scheme.
329 * @type {SiteSettingsPref} 357 * @type {SiteSettingsPref}
330 */ 358 */
331 var prefsChromeExtension = { 359 var prefsChromeExtension = {
332 exceptions: { 360 exceptions: {
333 javascript: [ 361 javascript: [
334 { 362 {
335 category: 'javascript', 363 category: 'javascript',
336 embeddingOrigin: '', 364 embeddingOrigin: '',
365 incognito: false,
337 origin: 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', 366 origin: 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/',
338 setting: 'block', 367 setting: 'block',
339 source: 'preference', 368 source: 'preference',
340 }, 369 },
341 ] 370 ]
342 } 371 }
343 }; 372 };
344 373
345 function registerTests() { 374 function registerTests() {
346 suite('SiteList', function() { 375 suite('SiteList', function() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 function assertMenu(items) { 436 function assertMenu(items) {
408 var menu = testElement.$$('dialog[is=cr-action-menu]'); 437 var menu = testElement.$$('dialog[is=cr-action-menu]');
409 assertTrue(!!menu); 438 assertTrue(!!menu);
410 var menuItems = menu.querySelectorAll('button:not([hidden])'); 439 var menuItems = menu.querySelectorAll('button:not([hidden])');
411 assertEquals(items.length, menuItems.length); 440 assertEquals(items.length, menuItems.length);
412 for (var i = 0; i < items.length; i++) 441 for (var i = 0; i < items.length; i++)
413 assertEquals(items[i], menuItems[i].textContent.trim()); 442 assertEquals(items[i], menuItems[i].textContent.trim());
414 } 443 }
415 444
416 /** 445 /**
446 * @param {HTMLElement} listContainer Node with the exceptions listed.
447 * @return {boolean} Whether the entry is incognito only.
448 */
449 function hasAnIncognito(listContainer) {
450 var descriptions = listContainer.querySelectorAll('#siteDescription');
451 for (var i = 0; i < descriptions.length; ++i) {
452 if (descriptions[i].textContent == 'Current incognito session')
453 return true;
454 }
455 return false;
456 };
Dan Beam 2017/03/30 04:50:43 no ; after function declarations https://develope
dschuyler 2017/03/30 21:06:16 See https://codereview.chromium.org/2787923002/
457
Dan Beam 2017/03/30 04:50:43 one less \n
dschuyler 2017/03/30 21:06:16 See https://codereview.chromium.org/2787923002/
458
459 /**
417 * Configures the test element for a particular category. 460 * Configures the test element for a particular category.
418 * @param {settings.ContentSettingsTypes} category The category to set up. 461 * @param {settings.ContentSettingsTypes} category The category to set up.
419 * @param {settings.PermissionValues} subtype Type of list to use. 462 * @param {settings.PermissionValues} subtype Type of list to use.
420 * @param {Array<dictionary>} prefs The prefs to use. 463 * @param {Array<dictionary>} prefs The prefs to use.
421 */ 464 */
422 function setUpCategory(category, subtype, prefs) { 465 function setUpCategory(category, subtype, prefs) {
423 browserProxy.setPrefs(prefs); 466 browserProxy.setPrefs(prefs);
424 if (category == settings.ALL_SITES) { 467 if (category == settings.ALL_SITES) {
425 testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE; 468 testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE;
426 testElement.allSites = true; 469 testElement.allSites = true;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 testElement.sites[0].origin); 630 testElement.sites[0].origin);
588 631
589 Polymer.dom.flush(); // Populates action menu. 632 Polymer.dom.flush(); // Populates action menu.
590 openActionMenu(0); 633 openActionMenu(0);
591 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement); 634 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement);
592 635
593 assertFalse(testElement.$.category.hidden); 636 assertFalse(testElement.$.category.hidden);
594 }); 637 });
595 }); 638 });
596 639
640 test('update lists for incognito', function() {
641 var contentType = settings.ContentSettingsTypes.PLUGINS;
642 var categorySubtype = settings.PermissionValues.BLOCK;
643 setUpCategory(contentType, categorySubtype, prefsControlled);
644 var list = testElement.$.listContainer;
645 return browserProxy.whenCalled('getExceptionList')
646 .then(function(actualContentType) {
647 Polymer.dom.flush();
648 assertEquals(1, list.querySelectorAll('.list-item').length);
649 assertFalse(hasAnIncognito(list));
650 browserProxy.resetResolver('getExceptionList');
651 browserProxy.setIncognito(true);
652 return browserProxy.whenCalled('getExceptionList');
653 })
654 .then(function() {
655 Polymer.dom.flush();
656 assertEquals(2, list.querySelectorAll('.list-item').length);
657 assertTrue(hasAnIncognito(list));
658 browserProxy.resetResolver('getExceptionList');
659 browserProxy.setIncognito(false);
660 return browserProxy.whenCalled('getExceptionList');
661 })
662 .then(function() {
663 Polymer.dom.flush();
664 assertEquals(1, list.querySelectorAll('.list-item').length);
665 assertFalse(hasAnIncognito(list));
666 browserProxy.resetResolver('getExceptionList');
667 browserProxy.setIncognito(true);
668 return browserProxy.whenCalled('getExceptionList');
669 })
670 .then(function() {
671 Polymer.dom.flush();
672 assertEquals(2, list.querySelectorAll('.list-item').length);
673 assertTrue(hasAnIncognito(list));
674 });
675 });
676
597 test('initial INCOGNITO BLOCK state is correct', function() { 677 test('initial INCOGNITO BLOCK state is correct', function() {
598 var contentType = settings.ContentSettingsTypes.COOKIES; 678 var contentType = settings.ContentSettingsTypes.COOKIES;
599 var categorySubtype = settings.PermissionValues.BLOCK; 679 var categorySubtype = settings.PermissionValues.BLOCK;
600 setUpCategory(contentType, categorySubtype, prefsIncognito); 680 setUpCategory(contentType, categorySubtype, prefsIncognito);
601 return browserProxy.whenCalled('getExceptionList').then( 681 return browserProxy.whenCalled('getExceptionList').then(
602 function(actualContentType) { 682 function(actualContentType) {
603 assertEquals(contentType, actualContentType); 683 assertEquals(contentType, actualContentType);
604 assertEquals(categorySubtype, testElement.categorySubtype); 684 assertEquals(categorySubtype, testElement.categorySubtype);
605 685
606 assertEquals(1, testElement.sites.length); 686 assertEquals(1, testElement.sites.length);
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 1103
1024 assertFalse(dialog.$.dialog.open); 1104 assertFalse(dialog.$.dialog.open);
1025 }); 1105 });
1026 }); 1106 });
1027 }); 1107 });
1028 1108
1029 return { 1109 return {
1030 registerTests: registerTests, 1110 registerTests: registerTests,
1031 }; 1111 };
1032 }); 1112 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698