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

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

Issue 2298283002: Site Settings Desktop: Support adding exceptions for incognito mode. (Closed)
Patch Set: Fix remaining tests Created 4 years, 3 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 function registerTests() { 7 function registerTests() {
8 suite('SiteList', function() { 8 suite('SiteList', function() {
9 /** 9 /**
10 * A site list element created before each test. 10 * A site list element created before each test.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 { 240 {
241 embeddingOrigin: 'http://foo-session.com', 241 embeddingOrigin: 'http://foo-session.com',
242 origin: 'http://foo-session.com', 242 origin: 'http://foo-session.com',
243 setting: 'session_only', 243 setting: 'session_only',
244 source: 'preference', 244 source: 'preference',
245 }, 245 },
246 ] 246 ]
247 } 247 }
248 }; 248 };
249 249
250 /**
251 * An example Cookies pref with mixed incognito and regular settings.
252 * @type {SiteSettingsPref}
253 */
254 var prefsIncognito = {
255 exceptions: {
256 cookies: [
257 // foo.com is blocked for regular sessions.
258 {
259 embeddingOrigin: 'http://foo.com',
260 incognito: false,
261 origin: 'http://foo.com',
262 setting: 'block',
263 source: 'preference',
264 },
265 // foo.com is allowed in incognito (overridden).
266 {
267 embeddingOrigin: 'http://foo.com',
268 incognito: true,
269 origin: 'http://foo.com',
270 setting: 'allow',
271 source: 'preference',
272 },
273 // bar.com is an allowed incognito item without an embedder.
274 {
275 embeddingOrigin: '',
276 incognito: true,
277 origin: 'http://bar.com',
278 setting: 'allow',
279 source: 'preference',
280 },
281 ]
282 }
283 };
284
250 // Import necessary html before running suite. 285 // Import necessary html before running suite.
251 suiteSetup(function() { 286 suiteSetup(function() {
252 CrSettingsPrefs.setInitialized(); 287 CrSettingsPrefs.setInitialized();
253 return PolymerTest.importHtml( 288 return PolymerTest.importHtml(
254 'chrome://md-settings/site_settings/site_list.html'); 289 'chrome://md-settings/site_settings/site_list.html');
255 }); 290 });
256 291
257 suiteTeardown(function() { 292 suiteTeardown(function() {
258 CrSettingsPrefs.resetForTesting(); 293 CrSettingsPrefs.resetForTesting();
259 }); 294 });
260 295
261 // Initialize a site-list before each test. 296 // Initialize a site-list before each test.
262 setup(function() { 297 setup(function() {
263 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); 298 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
264 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; 299 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
265 PolymerTest.clearBody(); 300 PolymerTest.clearBody();
266 testElement = document.createElement('site-list'); 301 testElement = document.createElement('site-list');
267 document.body.appendChild(testElement); 302 document.body.appendChild(testElement);
268 }); 303 });
269 304
270 /** 305 /**
271 * Fetch the non-hidden menu items from the list. 306 * Fetch the non-hidden menu items from the list.
272 * @param {!HTMLElement} parentElement 307 * @param {!HTMLElement} parentElement
308 * @param {number} index The index of the child element (which site) to
309 * fetch.
273 */ 310 */
274 function getMenuItems(listContainer) { 311 function getMenuItems(listContainer, index) {
275 return listContainer.children[0].querySelectorAll( 312 return listContainer.children[index].querySelectorAll(
276 'paper-menu-button paper-item:not([hidden])'); 313 'paper-menu-button paper-item:not([hidden])');
277 } 314 }
278 315
279 /** 316 /**
280 * Asserts the menu looks as expected. 317 * Asserts the menu looks as expected.
281 * @param {Array<string>} items The items expected to show in the menu. 318 * @param {Array<string>} items The items expected to show in the menu.
282 * @param {!HTMLElement} parentElement The parent node to start looking 319 * @param {!HTMLElement} parentElement The parent node to start looking
283 * in. 320 * in.
284 */ 321 */
285 function assertMenu(items, parentElement) { 322 function assertMenu(items, parentElement) {
286 var menuItems = getMenuItems(parentElement.$.listContainer); 323 var menuItems = getMenuItems(parentElement.$.listContainer, 0);
287 assertEquals(items.length, menuItems.length); 324 assertEquals(items.length, menuItems.length);
288 for (var i = 0; i < items.length; i++) 325 for (var i = 0; i < items.length; i++)
289 assertEquals(items[i], menuItems[i].textContent.trim()); 326 assertEquals(items[i], menuItems[i].textContent.trim());
290 } 327 }
291 328
292 /** 329 /**
293 * Configures the test element for a particular category. 330 * Configures the test element for a particular category.
294 * @param {settings.ContentSettingsTypes} category The category to setup. 331 * @param {settings.ContentSettingsTypes} category The category to setup.
295 * @param {settings.PermissionValues} subtype Type of list to use. 332 * @param {settings.PermissionValues} subtype Type of list to use.
296 * @param {Array<dictionary>} prefs The prefs to use. 333 * @param {Array<dictionary>} prefs The prefs to use.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 assertFalse(testElement.$.category.hidden); 467 assertFalse(testElement.$.category.hidden);
431 browserProxy.resetResolver('getExceptionList'); 468 browserProxy.resetResolver('getExceptionList');
432 testElement.categoryEnabled = false; 469 testElement.categoryEnabled = false;
433 return browserProxy.whenCalled('getExceptionList'); 470 return browserProxy.whenCalled('getExceptionList');
434 }).then(function(contentType) { 471 }).then(function(contentType) {
435 assertFalse(testElement.$.category.hidden); 472 assertFalse(testElement.$.category.hidden);
436 assertEquals('Clear on exit - 1', testElement.$.header.innerText); 473 assertEquals('Clear on exit - 1', testElement.$.header.innerText);
437 }); 474 });
438 }); 475 });
439 476
477 test('initial INCOGNITO BLOCK state is correct', function() {
478 setupCategory(settings.ContentSettingsTypes.COOKIES,
479 settings.PermissionValues.BLOCK, prefsIncognito);
480 return browserProxy.whenCalled('getExceptionList').then(
481 function(contentType) {
482 assertEquals(
483 settings.ContentSettingsTypes.COOKIES, contentType);
dschuyler 2016/09/02 22:49:38 nit: Could this unwrap?
Finnur 2016/09/05 11:37:54 Done.
484
485 assertEquals(1, testElement.sites.length);
486 assertEquals(prefsIncognito.exceptions.cookies[0].origin,
487 testElement.sites[0].origin);
488
489 assertEquals(settings.PermissionValues.BLOCK,
490 testElement.categorySubtype);
491 Polymer.dom.flush(); // Populates action menu.
492 // 'Clear on exit' is visible as this is not an incognito item.
493 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement);
494 assertEquals('Block - 1',
495 testElement.$.header.innerText.trim());
496
497 // Select 'Remove from menu'.
498 var menuItems = getMenuItems(testElement.$.listContainer, 0);
499 assertTrue(!!menuItems);
500 MockInteractions.tap(menuItems[2]);
501 return browserProxy.whenCalled(
502 'resetCategoryPermissionForOrigin');
503 }).then(function(arguments) {
504 assertEquals('http://foo.com', arguments[0]);
505 assertEquals('http://foo.com', arguments[1]);
506 assertEquals(settings.ContentSettingsTypes.COOKIES, arguments[2]);
507 assertFalse(arguments[3]); // Incognito.
508 });
509 });
510
511 test('initial INCOGNITO ALLOW state is correct', function() {
512 setupCategory(settings.ContentSettingsTypes.COOKIES,
513 settings.PermissionValues.ALLOW, prefsIncognito);
514 return browserProxy.whenCalled('getExceptionList').then(
515 function(contentType) {
516 assertEquals(
517 settings.ContentSettingsTypes.COOKIES, contentType);
518
519 assertEquals(2, testElement.sites.length);
520 assertEquals(prefsIncognito.exceptions.cookies[2].origin,
521 testElement.sites[0].origin);
522 assertEquals(prefsIncognito.exceptions.cookies[1].origin,
523 testElement.sites[1].origin);
524
525 assertEquals(settings.PermissionValues.ALLOW,
526 testElement.categorySubtype);
527 Polymer.dom.flush(); // Populates action menu.
528 // 'Clear on exit' is hidden for incognito items.
529 assertMenu(['Block', 'Remove'], testElement);
530 assertEquals('Allow - 2',
531 testElement.$.header.innerText.trim());
532
533 // Select 'Remove' from menu on 'foo.com'.
534 var menuItems = getMenuItems(testElement.$.listContainer, 1);
535 assertTrue(!!menuItems);
536 MockInteractions.tap(menuItems[1]);
537 return browserProxy.whenCalled(
538 'resetCategoryPermissionForOrigin');
539 }).then(function(arguments) {
540 assertEquals('http://foo.com', arguments[0]);
541 assertEquals('http://foo.com', arguments[1]);
542 assertEquals(settings.ContentSettingsTypes.COOKIES, arguments[2]);
543 assertTrue(arguments[3]); // Incognito.
544 });
545 });
546
440 test('list items shown and clickable when data is present', function() { 547 test('list items shown and clickable when data is present', function() {
441 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, 548 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
442 settings.PermissionValues.ALLOW, prefs); 549 settings.PermissionValues.ALLOW, prefs);
443 return browserProxy.whenCalled('getExceptionList').then( 550 return browserProxy.whenCalled('getExceptionList').then(
444 function(contentType) { 551 function(contentType) {
445 assertEquals( 552 assertEquals(
446 settings.ContentSettingsTypes.GEOLOCATION, contentType); 553 settings.ContentSettingsTypes.GEOLOCATION, contentType);
447 554
448 // Required for firstItem to be found below. 555 // Required for firstItem to be found below.
449 Polymer.dom.flush(); 556 Polymer.dom.flush();
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 }); 756 });
650 }); 757 });
651 758
652 test('Select menu item', function() { 759 test('Select menu item', function() {
653 // Test for error: "Cannot read property 'origin' of undefined". 760 // Test for error: "Cannot read property 'origin' of undefined".
654 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, 761 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
655 settings.PermissionValues.ALLOW, prefs); 762 settings.PermissionValues.ALLOW, prefs);
656 return browserProxy.whenCalled('getExceptionList').then(function( 763 return browserProxy.whenCalled('getExceptionList').then(function(
657 contentType) { 764 contentType) {
658 Polymer.dom.flush(); 765 Polymer.dom.flush();
659 var menuItems = getMenuItems(testElement.$.listContainer); 766 var menuItems = getMenuItems(testElement.$.listContainer, 0);
660 assertTrue(!!menuItems); 767 assertTrue(!!menuItems);
661 MockInteractions.tap(menuItems[0]); 768 MockInteractions.tap(menuItems[0]);
662 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); 769 return browserProxy.whenCalled('setCategoryPermissionForOrigin');
663 }); 770 });
664 }); 771 });
665 }); 772 });
666 } 773 }
667 return { 774 return {
668 registerTests: registerTests, 775 registerTests: registerTests,
669 }; 776 };
670 }); 777 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698