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

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 test 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(settings.ContentSettingsTypes.COOKIES, contentType);
483
484 assertEquals(1, testElement.sites.length);
485 assertEquals(prefsIncognito.exceptions.cookies[0].origin,
486 testElement.sites[0].origin);
487
488 assertEquals(settings.PermissionValues.BLOCK,
489 testElement.categorySubtype);
490 Polymer.dom.flush(); // Populates action menu.
491 // 'Clear on exit' is visible as this is not an incognito item.
492 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement);
493 assertEquals('Block - 1',
494 testElement.$.header.innerText.trim());
495
496 // Select 'Remove from menu'.
497 var menuItems = getMenuItems(testElement.$.listContainer, 0);
498 assertTrue(!!menuItems);
499 MockInteractions.tap(menuItems[2]);
500 return browserProxy.whenCalled(
501 'resetCategoryPermissionForOrigin');
502 }).then(function(arguments) {
503 assertEquals('http://foo.com', arguments[0]);
504 assertEquals('http://foo.com', arguments[1]);
505 assertEquals(settings.ContentSettingsTypes.COOKIES, arguments[2]);
506 assertFalse(arguments[3]); // Incognito.
507 });
508 });
509
510 test('initial INCOGNITO ALLOW state is correct', function() {
511 setupCategory(settings.ContentSettingsTypes.COOKIES,
512 settings.PermissionValues.ALLOW, prefsIncognito);
513 return browserProxy.whenCalled('getExceptionList').then(
514 function(contentType) {
515 assertEquals(
516 settings.ContentSettingsTypes.COOKIES, contentType);
517
518 assertEquals(2, testElement.sites.length);
519 assertEquals(prefsIncognito.exceptions.cookies[2].origin,
520 testElement.sites[0].origin);
521 assertEquals(prefsIncognito.exceptions.cookies[1].origin,
522 testElement.sites[1].origin);
523
524 assertEquals(settings.PermissionValues.ALLOW,
525 testElement.categorySubtype);
526 Polymer.dom.flush(); // Populates action menu.
527 // 'Clear on exit' is hidden for incognito items.
528 assertMenu(['Block', 'Remove'], testElement);
529 assertEquals('Allow - 2',
530 testElement.$.header.innerText.trim());
531
532 // Select 'Remove' from menu on 'foo.com'.
533 var menuItems = getMenuItems(testElement.$.listContainer, 1);
534 assertTrue(!!menuItems);
535 MockInteractions.tap(menuItems[1]);
536 return browserProxy.whenCalled(
537 'resetCategoryPermissionForOrigin');
538 }).then(function(arguments) {
539 assertEquals('http://foo.com', arguments[0]);
540 assertEquals('http://foo.com', arguments[1]);
541 assertEquals(settings.ContentSettingsTypes.COOKIES, arguments[2]);
542 assertTrue(arguments[3]); // Incognito.
543 });
544 });
545
440 test('list items shown and clickable when data is present', function() { 546 test('list items shown and clickable when data is present', function() {
441 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, 547 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
442 settings.PermissionValues.ALLOW, prefs); 548 settings.PermissionValues.ALLOW, prefs);
443 return browserProxy.whenCalled('getExceptionList').then( 549 return browserProxy.whenCalled('getExceptionList').then(
444 function(contentType) { 550 function(contentType) {
445 assertEquals( 551 assertEquals(
446 settings.ContentSettingsTypes.GEOLOCATION, contentType); 552 settings.ContentSettingsTypes.GEOLOCATION, contentType);
447 553
448 // Required for firstItem to be found below. 554 // Required for firstItem to be found below.
449 Polymer.dom.flush(); 555 Polymer.dom.flush();
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 }); 755 });
650 }); 756 });
651 757
652 test('Select menu item', function() { 758 test('Select menu item', function() {
653 // Test for error: "Cannot read property 'origin' of undefined". 759 // Test for error: "Cannot read property 'origin' of undefined".
654 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, 760 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
655 settings.PermissionValues.ALLOW, prefs); 761 settings.PermissionValues.ALLOW, prefs);
656 return browserProxy.whenCalled('getExceptionList').then(function( 762 return browserProxy.whenCalled('getExceptionList').then(function(
657 contentType) { 763 contentType) {
658 Polymer.dom.flush(); 764 Polymer.dom.flush();
659 var menuItems = getMenuItems(testElement.$.listContainer); 765 var menuItems = getMenuItems(testElement.$.listContainer, 0);
660 assertTrue(!!menuItems); 766 assertTrue(!!menuItems);
661 MockInteractions.tap(menuItems[0]); 767 MockInteractions.tap(menuItems[0]);
662 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); 768 return browserProxy.whenCalled('setCategoryPermissionForOrigin');
663 }); 769 });
664 }); 770 });
665 }); 771 });
666 } 772 }
667 return { 773 return {
668 registerTests: registerTests, 774 registerTests: registerTests,
669 }; 775 };
670 }); 776 });
OLDNEW
« no previous file with comments | « chrome/test/base/testing_profile.cc ('k') | chrome/test/data/webui/settings/test_site_settings_prefs_browser_proxy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698