| OLD | NEW |
| 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 }); | 320 }); |
| 321 | 321 |
| 322 /** | 322 /** |
| 323 * Fetch the non-hidden menu items from the list. | 323 * Fetch the non-hidden menu items from the list. |
| 324 * @param {!HTMLElement} parentElement | 324 * @param {!HTMLElement} parentElement |
| 325 * @param {number} index The index of the child element (which site) to | 325 * @param {number} index The index of the child element (which site) to |
| 326 * fetch. | 326 * fetch. |
| 327 */ | 327 */ |
| 328 function getMenuItems(listContainer, index) { | 328 function getMenuItems(listContainer, index) { |
| 329 return listContainer.children[index].querySelectorAll( | 329 return listContainer.children[index].querySelectorAll( |
| 330 'paper-menu-button paper-item:not([hidden])'); | 330 'iron-dropdown .dropdown-item:not([hidden])'); |
| 331 } | 331 } |
| 332 | 332 |
| 333 /** | 333 /** |
| 334 * Opens the action menu for a particular element in the list. |
| 335 * @param {number} index The index of the child element (which site) to |
| 336 * open the action menu for. |
| 337 */ |
| 338 function openActionMenu(index) { |
| 339 var item = testElement.$.listContainer.children[index]; |
| 340 var dots = item.querySelector('paper-icon-button'); |
| 341 MockInteractions.tap(dots); |
| 342 Polymer.dom.flush(); |
| 343 } |
| 344 |
| 345 /** |
| 334 * Asserts the menu looks as expected. | 346 * Asserts the menu looks as expected. |
| 335 * @param {Array<string>} items The items expected to show in the menu. | 347 * @param {Array<string>} items The items expected to show in the menu. |
| 336 * @param {!HTMLElement} parentElement The parent node to start looking | 348 * @param {!HTMLElement} parentElement The parent node to start looking |
| 337 * in. | 349 * in. |
| 338 */ | 350 */ |
| 339 function assertMenu(items, parentElement) { | 351 function assertMenu(items, parentElement) { |
| 340 var menuItems = getMenuItems(parentElement.$.listContainer, 0); | 352 var menuItems = getMenuItems(parentElement.$.listContainer, 0); |
| 341 assertEquals(items.length, menuItems.length); | 353 assertEquals(items.length, menuItems.length); |
| 342 for (var i = 0; i < items.length; i++) | 354 for (var i = 0; i < items.length; i++) |
| 343 assertEquals(items[i], menuItems[i].textContent.trim()); | 355 assertEquals(items[i], menuItems[i].textContent.trim()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 function(contentType) { | 421 function(contentType) { |
| 410 assertEquals( | 422 assertEquals( |
| 411 settings.ContentSettingsTypes.GEOLOCATION, contentType); | 423 settings.ContentSettingsTypes.GEOLOCATION, contentType); |
| 412 | 424 |
| 413 assertEquals(2, testElement.sites.length); | 425 assertEquals(2, testElement.sites.length); |
| 414 assertEquals(prefs.exceptions.geolocation[1].origin, | 426 assertEquals(prefs.exceptions.geolocation[1].origin, |
| 415 testElement.sites[0].origin); | 427 testElement.sites[0].origin); |
| 416 assertEquals( | 428 assertEquals( |
| 417 settings.PermissionValues.ALLOW, testElement.categorySubtype); | 429 settings.PermissionValues.ALLOW, testElement.categorySubtype); |
| 418 Polymer.dom.flush(); // Populates action menu. | 430 Polymer.dom.flush(); // Populates action menu. |
| 431 openActionMenu(0); |
| 419 assertMenu(['Block', 'Remove'], testElement); | 432 assertMenu(['Block', 'Remove'], testElement); |
| 420 assertEquals('Allow - 2', testElement.$.header.innerText.trim()); | 433 assertEquals('Allow - 2', testElement.$.header.innerText.trim()); |
| 421 | 434 |
| 422 // Site list should show, no matter what category default is set | 435 // Site list should show, no matter what category default is set |
| 423 // to. | 436 // to. |
| 424 assertFalse(testElement.$.category.hidden); | 437 assertFalse(testElement.$.category.hidden); |
| 425 browserProxy.resetResolver('getExceptionList'); | 438 browserProxy.resetResolver('getExceptionList'); |
| 426 testElement.categoryEnabled = false; | 439 testElement.categoryEnabled = false; |
| 427 return browserProxy.whenCalled('getExceptionList'); | 440 return browserProxy.whenCalled('getExceptionList'); |
| 428 }).then(function(contentType) { | 441 }).then(function(contentType) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 440 assertEquals( | 453 assertEquals( |
| 441 settings.ContentSettingsTypes.GEOLOCATION, contentType); | 454 settings.ContentSettingsTypes.GEOLOCATION, contentType); |
| 442 | 455 |
| 443 assertEquals(2, testElement.sites.length); | 456 assertEquals(2, testElement.sites.length); |
| 444 assertEquals(prefs.exceptions.geolocation[3].origin, | 457 assertEquals(prefs.exceptions.geolocation[3].origin, |
| 445 testElement.sites[0].origin); | 458 testElement.sites[0].origin); |
| 446 | 459 |
| 447 assertEquals( | 460 assertEquals( |
| 448 settings.PermissionValues.BLOCK, testElement.categorySubtype); | 461 settings.PermissionValues.BLOCK, testElement.categorySubtype); |
| 449 Polymer.dom.flush(); // Populates action menu. | 462 Polymer.dom.flush(); // Populates action menu. |
| 463 openActionMenu(0); |
| 450 assertMenu(['Allow', 'Remove'], testElement); | 464 assertMenu(['Allow', 'Remove'], testElement); |
| 451 assertEquals('Block - 2', testElement.$.header.innerText.trim()); | 465 assertEquals('Block - 2', testElement.$.header.innerText.trim()); |
| 452 | 466 |
| 453 // Site list should only show when category default is enabled. | 467 // Site list should only show when category default is enabled. |
| 454 assertFalse(testElement.$.category.hidden); | 468 assertFalse(testElement.$.category.hidden); |
| 455 browserProxy.resetResolver('getExceptionList'); | 469 browserProxy.resetResolver('getExceptionList'); |
| 456 testElement.categoryEnabled = false; | 470 testElement.categoryEnabled = false; |
| 457 return browserProxy.whenCalled('getExceptionList'); | 471 return browserProxy.whenCalled('getExceptionList'); |
| 458 }).then(function(contentType) { | 472 }).then(function(contentType) { |
| 459 assertTrue(testElement.$.category.hidden); | 473 assertTrue(testElement.$.category.hidden); |
| 460 }); | 474 }); |
| 461 }); | 475 }); |
| 462 | 476 |
| 463 test('initial SESSION ONLY state is correct', function() { | 477 test('initial SESSION ONLY state is correct', function() { |
| 464 setupCategory(settings.ContentSettingsTypes.COOKIES, | 478 setupCategory(settings.ContentSettingsTypes.COOKIES, |
| 465 settings.PermissionValues.SESSION_ONLY, prefsSessionOnly); | 479 settings.PermissionValues.SESSION_ONLY, prefsSessionOnly); |
| 466 return browserProxy.whenCalled('getExceptionList').then( | 480 return browserProxy.whenCalled('getExceptionList').then( |
| 467 function(contentType) { | 481 function(contentType) { |
| 468 assertEquals( | 482 assertEquals( |
| 469 settings.ContentSettingsTypes.COOKIES, contentType); | 483 settings.ContentSettingsTypes.COOKIES, contentType); |
| 470 | 484 |
| 471 assertEquals(1, testElement.sites.length); | 485 assertEquals(1, testElement.sites.length); |
| 472 assertEquals(prefsSessionOnly.exceptions.cookies[2].origin, | 486 assertEquals(prefsSessionOnly.exceptions.cookies[2].origin, |
| 473 testElement.sites[0].origin); | 487 testElement.sites[0].origin); |
| 474 | 488 |
| 475 assertEquals(settings.PermissionValues.SESSION_ONLY, | 489 assertEquals(settings.PermissionValues.SESSION_ONLY, |
| 476 testElement.categorySubtype); | 490 testElement.categorySubtype); |
| 477 Polymer.dom.flush(); // Populates action menu. | 491 Polymer.dom.flush(); // Populates action menu. |
| 492 openActionMenu(0); |
| 478 assertMenu(['Allow', 'Block', 'Remove'], testElement); | 493 assertMenu(['Allow', 'Block', 'Remove'], testElement); |
| 479 assertEquals('Clear on exit - 1', | 494 assertEquals('Clear on exit - 1', |
| 480 testElement.$.header.innerText.trim()); | 495 testElement.$.header.innerText.trim()); |
| 481 | 496 |
| 482 // Site list should show, no matter what category default is set | 497 // Site list should show, no matter what category default is set |
| 483 // to. | 498 // to. |
| 484 assertFalse(testElement.$.category.hidden); | 499 assertFalse(testElement.$.category.hidden); |
| 485 browserProxy.resetResolver('getExceptionList'); | 500 browserProxy.resetResolver('getExceptionList'); |
| 486 testElement.categoryEnabled = false; | 501 testElement.categoryEnabled = false; |
| 487 return browserProxy.whenCalled('getExceptionList'); | 502 return browserProxy.whenCalled('getExceptionList'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 498 function(contentType) { | 513 function(contentType) { |
| 499 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); | 514 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); |
| 500 | 515 |
| 501 assertEquals(1, testElement.sites.length); | 516 assertEquals(1, testElement.sites.length); |
| 502 assertEquals(prefsIncognito.exceptions.cookies[0].origin, | 517 assertEquals(prefsIncognito.exceptions.cookies[0].origin, |
| 503 testElement.sites[0].origin); | 518 testElement.sites[0].origin); |
| 504 | 519 |
| 505 assertEquals(settings.PermissionValues.BLOCK, | 520 assertEquals(settings.PermissionValues.BLOCK, |
| 506 testElement.categorySubtype); | 521 testElement.categorySubtype); |
| 507 Polymer.dom.flush(); // Populates action menu. | 522 Polymer.dom.flush(); // Populates action menu. |
| 523 openActionMenu(0); |
| 508 // 'Clear on exit' is visible as this is not an incognito item. | 524 // 'Clear on exit' is visible as this is not an incognito item. |
| 509 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement); | 525 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement); |
| 510 assertEquals('Block - 1', | 526 assertEquals('Block - 1', |
| 511 testElement.$.header.innerText.trim()); | 527 testElement.$.header.innerText.trim()); |
| 512 | 528 |
| 513 // Select 'Remove from menu'. | 529 // Select 'Remove from menu'. |
| 514 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 530 var menuItems = getMenuItems(testElement.$.listContainer, 0); |
| 515 assertTrue(!!menuItems); | 531 assertTrue(!!menuItems); |
| 516 MockInteractions.tap(menuItems[2]); | 532 MockInteractions.tap(menuItems[2]); |
| 517 return browserProxy.whenCalled( | 533 return browserProxy.whenCalled( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 534 | 550 |
| 535 assertEquals(2, testElement.sites.length); | 551 assertEquals(2, testElement.sites.length); |
| 536 assertEquals(prefsIncognito.exceptions.cookies[2].origin, | 552 assertEquals(prefsIncognito.exceptions.cookies[2].origin, |
| 537 testElement.sites[0].origin); | 553 testElement.sites[0].origin); |
| 538 assertEquals(prefsIncognito.exceptions.cookies[1].origin, | 554 assertEquals(prefsIncognito.exceptions.cookies[1].origin, |
| 539 testElement.sites[1].origin); | 555 testElement.sites[1].origin); |
| 540 | 556 |
| 541 assertEquals(settings.PermissionValues.ALLOW, | 557 assertEquals(settings.PermissionValues.ALLOW, |
| 542 testElement.categorySubtype); | 558 testElement.categorySubtype); |
| 543 Polymer.dom.flush(); // Populates action menu. | 559 Polymer.dom.flush(); // Populates action menu. |
| 560 openActionMenu(0); |
| 544 // 'Clear on exit' is hidden for incognito items. | 561 // 'Clear on exit' is hidden for incognito items. |
| 545 assertMenu(['Block', 'Remove'], testElement); | 562 assertMenu(['Block', 'Remove'], testElement); |
| 546 assertEquals('Allow - 2', | 563 assertEquals('Allow - 2', |
| 547 testElement.$.header.innerText.trim()); | 564 testElement.$.header.innerText.trim()); |
| 548 | 565 |
| 549 // Select 'Remove' from menu on 'foo.com'. | 566 // Select 'Remove' from menu on 'foo.com'. |
| 567 openActionMenu(1); |
| 550 var menuItems = getMenuItems(testElement.$.listContainer, 1); | 568 var menuItems = getMenuItems(testElement.$.listContainer, 1); |
| 551 assertTrue(!!menuItems); | 569 assertTrue(!!menuItems); |
| 552 MockInteractions.tap(menuItems[1]); | 570 MockInteractions.tap(menuItems[1]); |
| 553 return browserProxy.whenCalled( | 571 return browserProxy.whenCalled( |
| 554 'resetCategoryPermissionForOrigin'); | 572 'resetCategoryPermissionForOrigin'); |
| 555 }).then(function(args) { | 573 }).then(function(args) { |
| 556 assertEquals('http://foo.com', args[0]); | 574 assertEquals('http://foo.com', args[0]); |
| 557 assertEquals('http://foo.com', args[1]); | 575 assertEquals('http://foo.com', args[1]); |
| 558 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); | 576 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 559 assertTrue(args[3]); // Incognito. | 577 assertTrue(args[3]); // Incognito. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 }); | 790 }); |
| 773 }); | 791 }); |
| 774 | 792 |
| 775 test('Select menu item', function() { | 793 test('Select menu item', function() { |
| 776 // Test for error: "Cannot read property 'origin' of undefined". | 794 // Test for error: "Cannot read property 'origin' of undefined". |
| 777 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, | 795 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, |
| 778 settings.PermissionValues.ALLOW, prefs); | 796 settings.PermissionValues.ALLOW, prefs); |
| 779 return browserProxy.whenCalled('getExceptionList').then(function( | 797 return browserProxy.whenCalled('getExceptionList').then(function( |
| 780 contentType) { | 798 contentType) { |
| 781 Polymer.dom.flush(); | 799 Polymer.dom.flush(); |
| 800 openActionMenu(0); |
| 782 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 801 var menuItems = getMenuItems(testElement.$.listContainer, 0); |
| 783 assertTrue(!!menuItems); | 802 assertTrue(!!menuItems); |
| 784 MockInteractions.tap(menuItems[0]); | 803 MockInteractions.tap(menuItems[0]); |
| 785 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); | 804 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 786 }); | 805 }); |
| 787 }); | 806 }); |
| 788 | 807 |
| 789 test('Chrome Extension scheme', function() { | 808 test('Chrome Extension scheme', function() { |
| 790 setupCategory(settings.ContentSettingsTypes.JAVASCRIPT, | 809 setupCategory(settings.ContentSettingsTypes.JAVASCRIPT, |
| 791 settings.PermissionValues.BLOCK, prefsChromeExtension); | 810 settings.PermissionValues.BLOCK, prefsChromeExtension); |
| 792 return browserProxy.whenCalled('getExceptionList').then(function( | 811 return browserProxy.whenCalled('getExceptionList').then(function( |
| 793 contentType) { | 812 contentType) { |
| 794 Polymer.dom.flush(); | 813 Polymer.dom.flush(); |
| 814 openActionMenu(0); |
| 795 assertMenu(['Allow', 'Remove'], testElement); | 815 assertMenu(['Allow', 'Remove'], testElement); |
| 796 | 816 |
| 797 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 817 var menuItems = getMenuItems(testElement.$.listContainer, 0); |
| 798 assertTrue(!!menuItems); | 818 assertTrue(!!menuItems); |
| 799 MockInteractions.tap(menuItems[0]); // Action: Allow. | 819 MockInteractions.tap(menuItems[0]); // Action: Allow. |
| 800 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); | 820 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 801 }).then(function(args) { | 821 }).then(function(args) { |
| 802 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', | 822 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', |
| 803 args[0]); | 823 args[0]); |
| 804 assertEquals('', args[1]); | 824 assertEquals('', args[1]); |
| 805 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); | 825 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); |
| 806 assertEquals('allow', args[3]); | 826 assertEquals('allow', args[3]); |
| 807 }); | 827 }); |
| 808 }); | 828 }); |
| 809 }); | 829 }); |
| 810 } | 830 } |
| 811 return { | 831 return { |
| 812 registerTests: registerTests, | 832 registerTests: registerTests, |
| 813 }; | 833 }; |
| 814 }); | 834 }); |
| OLD | NEW |