| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 312 |
| 313 // Initialize a site-list before each test. | 313 // Initialize a site-list before each test. |
| 314 setup(function() { | 314 setup(function() { |
| 315 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | 315 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
| 316 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; | 316 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
| 317 PolymerTest.clearBody(); | 317 PolymerTest.clearBody(); |
| 318 testElement = document.createElement('site-list'); | 318 testElement = document.createElement('site-list'); |
| 319 document.body.appendChild(testElement); | 319 document.body.appendChild(testElement); |
| 320 }); | 320 }); |
| 321 | 321 |
| 322 teardown(function() { |
| 323 closeActionMenu(); |
| 324 }); |
| 325 |
| 322 /** | 326 /** |
| 323 * Fetch the non-hidden menu items from the list. | 327 * Fetch the non-hidden menu items from the action menu. |
| 324 * @param {!HTMLElement} parentElement | |
| 325 * @param {number} index The index of the child element (which site) to | |
| 326 * fetch. | |
| 327 */ | 328 */ |
| 328 function getMenuItems(listContainer, index) { | 329 function getMenuItems() { |
| 329 return listContainer.children[index].querySelectorAll( | 330 var menu = testElement.$$('dialog[is=settings-action-menu]'); |
| 330 'iron-dropdown .dropdown-item:not([hidden])'); | 331 assertTrue(!!menu); |
| 332 return menu.querySelectorAll('button:not([hidden])'); |
| 331 } | 333 } |
| 332 | 334 |
| 333 /** | 335 /** |
| 334 * Opens the action menu for a particular element in the list. | 336 * Opens the action menu for a particular element in the list. |
| 335 * @param {number} index The index of the child element (which site) to | 337 * @param {number} index The index of the child element (which site) to |
| 336 * open the action menu for. | 338 * open the action menu for. |
| 337 */ | 339 */ |
| 338 function openActionMenu(index) { | 340 function openActionMenu(index) { |
| 339 var item = testElement.$.listContainer.children[index]; | 341 var item = testElement.$.listContainer.children[index]; |
| 340 var dots = item.querySelector('paper-icon-button'); | 342 var dots = item.querySelector('paper-icon-button'); |
| 341 MockInteractions.tap(dots); | 343 MockInteractions.tap(dots); |
| 342 Polymer.dom.flush(); | 344 Polymer.dom.flush(); |
| 343 } | 345 } |
| 344 | 346 |
| 347 /** Closes the action menu. */ |
| 348 function closeActionMenu() { |
| 349 var menu = testElement.$$('dialog[is=settings-action-menu]'); |
| 350 if (menu.open) |
| 351 menu.close(); |
| 352 } |
| 353 |
| 345 /** | 354 /** |
| 346 * Asserts the menu looks as expected. | 355 * Asserts the menu looks as expected. |
| 347 * @param {Array<string>} items The items expected to show in the menu. | 356 * @param {Array<string>} items The items expected to show in the menu. |
| 348 * @param {!HTMLElement} parentElement The parent node to start looking | |
| 349 * in. | |
| 350 */ | 357 */ |
| 351 function assertMenu(items, parentElement) { | 358 function assertMenu(items) { |
| 352 var menuItems = getMenuItems(parentElement.$.listContainer, 0); | 359 var menuItems = getMenuItems(); |
| 353 assertEquals(items.length, menuItems.length); | 360 assertEquals(items.length, menuItems.length); |
| 354 for (var i = 0; i < items.length; i++) | 361 for (var i = 0; i < items.length; i++) |
| 355 assertEquals(items[i], menuItems[i].textContent.trim()); | 362 assertEquals(items[i], menuItems[i].textContent.trim()); |
| 356 } | 363 } |
| 357 | 364 |
| 358 /** | 365 /** |
| 359 * Configures the test element for a particular category. | 366 * Configures the test element for a particular category. |
| 360 * @param {settings.ContentSettingsTypes} category The category to setup. | 367 * @param {settings.ContentSettingsTypes} category The category to setup. |
| 361 * @param {settings.PermissionValues} subtype Type of list to use. | 368 * @param {settings.PermissionValues} subtype Type of list to use. |
| 362 * @param {Array<dictionary>} prefs The prefs to use. | 369 * @param {Array<dictionary>} prefs The prefs to use. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 testElement.sites[0].origin); | 515 testElement.sites[0].origin); |
| 509 | 516 |
| 510 assertEquals(settings.PermissionValues.BLOCK, | 517 assertEquals(settings.PermissionValues.BLOCK, |
| 511 testElement.categorySubtype); | 518 testElement.categorySubtype); |
| 512 Polymer.dom.flush(); // Populates action menu. | 519 Polymer.dom.flush(); // Populates action menu. |
| 513 openActionMenu(0); | 520 openActionMenu(0); |
| 514 // 'Clear on exit' is visible as this is not an incognito item. | 521 // 'Clear on exit' is visible as this is not an incognito item. |
| 515 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement); | 522 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement); |
| 516 | 523 |
| 517 // Select 'Remove from menu'. | 524 // Select 'Remove from menu'. |
| 518 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 525 var menuItems = getMenuItems(); |
| 519 assertTrue(!!menuItems); | 526 assertTrue(!!menuItems); |
| 520 MockInteractions.tap(menuItems[2]); | 527 MockInteractions.tap(menuItems[2]); |
| 521 return browserProxy.whenCalled( | 528 return browserProxy.whenCalled( |
| 522 'resetCategoryPermissionForOrigin'); | 529 'resetCategoryPermissionForOrigin'); |
| 523 }).then(function(args) { | 530 }).then(function(args) { |
| 524 assertEquals('http://foo.com', args[0]); | 531 assertEquals('http://foo.com', args[0]); |
| 525 assertEquals('http://foo.com', args[1]); | 532 assertEquals('http://foo.com', args[1]); |
| 526 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); | 533 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 527 assertFalse(args[3]); // Incognito. | 534 assertFalse(args[3]); // Incognito. |
| 528 }); | 535 }); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 541 testElement.sites[0].origin); | 548 testElement.sites[0].origin); |
| 542 assertEquals(prefsIncognito.exceptions.cookies[1].origin, | 549 assertEquals(prefsIncognito.exceptions.cookies[1].origin, |
| 543 testElement.sites[1].origin); | 550 testElement.sites[1].origin); |
| 544 | 551 |
| 545 assertEquals(settings.PermissionValues.ALLOW, | 552 assertEquals(settings.PermissionValues.ALLOW, |
| 546 testElement.categorySubtype); | 553 testElement.categorySubtype); |
| 547 Polymer.dom.flush(); // Populates action menu. | 554 Polymer.dom.flush(); // Populates action menu. |
| 548 openActionMenu(0); | 555 openActionMenu(0); |
| 549 // 'Clear on exit' is hidden for incognito items. | 556 // 'Clear on exit' is hidden for incognito items. |
| 550 assertMenu(['Block', 'Remove'], testElement); | 557 assertMenu(['Block', 'Remove'], testElement); |
| 558 closeActionMenu(); |
| 551 | 559 |
| 552 // Select 'Remove' from menu on 'foo.com'. | 560 // Select 'Remove' from menu on 'foo.com'. |
| 553 openActionMenu(1); | 561 openActionMenu(1); |
| 554 var menuItems = getMenuItems(testElement.$.listContainer, 1); | 562 var menuItems = getMenuItems(); |
| 555 assertTrue(!!menuItems); | 563 assertTrue(!!menuItems); |
| 556 MockInteractions.tap(menuItems[1]); | 564 MockInteractions.tap(menuItems[1]); |
| 557 return browserProxy.whenCalled( | 565 return browserProxy.whenCalled( |
| 558 'resetCategoryPermissionForOrigin'); | 566 'resetCategoryPermissionForOrigin'); |
| 559 }).then(function(args) { | 567 }).then(function(args) { |
| 560 assertEquals('http://foo.com', args[0]); | 568 assertEquals('http://foo.com', args[0]); |
| 561 assertEquals('http://foo.com', args[1]); | 569 assertEquals('http://foo.com', args[1]); |
| 562 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); | 570 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 563 assertTrue(args[3]); // Incognito. | 571 assertTrue(args[3]); // Incognito. |
| 564 }); | 572 }); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 }); | 777 }); |
| 770 | 778 |
| 771 test('Select menu item', function() { | 779 test('Select menu item', function() { |
| 772 // Test for error: "Cannot read property 'origin' of undefined". | 780 // Test for error: "Cannot read property 'origin' of undefined". |
| 773 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, | 781 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, |
| 774 settings.PermissionValues.ALLOW, prefs); | 782 settings.PermissionValues.ALLOW, prefs); |
| 775 return browserProxy.whenCalled('getExceptionList').then(function( | 783 return browserProxy.whenCalled('getExceptionList').then(function( |
| 776 contentType) { | 784 contentType) { |
| 777 Polymer.dom.flush(); | 785 Polymer.dom.flush(); |
| 778 openActionMenu(0); | 786 openActionMenu(0); |
| 779 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 787 var menuItems = getMenuItems(); |
| 780 assertTrue(!!menuItems); | 788 assertTrue(!!menuItems); |
| 781 MockInteractions.tap(menuItems[0]); | 789 MockInteractions.tap(menuItems[0]); |
| 782 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); | 790 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 783 }); | 791 }); |
| 784 }); | 792 }); |
| 785 | 793 |
| 786 test('Chrome Extension scheme', function() { | 794 test('Chrome Extension scheme', function() { |
| 787 setupCategory(settings.ContentSettingsTypes.JAVASCRIPT, | 795 setupCategory(settings.ContentSettingsTypes.JAVASCRIPT, |
| 788 settings.PermissionValues.BLOCK, prefsChromeExtension); | 796 settings.PermissionValues.BLOCK, prefsChromeExtension); |
| 789 return browserProxy.whenCalled('getExceptionList').then(function( | 797 return browserProxy.whenCalled('getExceptionList').then(function( |
| 790 contentType) { | 798 contentType) { |
| 791 Polymer.dom.flush(); | 799 Polymer.dom.flush(); |
| 792 openActionMenu(0); | 800 openActionMenu(0); |
| 793 assertMenu(['Allow', 'Remove'], testElement); | 801 assertMenu(['Allow', 'Remove'], testElement); |
| 794 | 802 |
| 795 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 803 var menuItems = getMenuItems(); |
| 796 assertTrue(!!menuItems); | 804 assertTrue(!!menuItems); |
| 797 MockInteractions.tap(menuItems[0]); // Action: Allow. | 805 MockInteractions.tap(menuItems[0]); // Action: Allow. |
| 798 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); | 806 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 799 }).then(function(args) { | 807 }).then(function(args) { |
| 800 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', | 808 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', |
| 801 args[0]); | 809 args[0]); |
| 802 assertEquals('', args[1]); | 810 assertEquals('', args[1]); |
| 803 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); | 811 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); |
| 804 assertEquals('allow', args[3]); | 812 assertEquals('allow', args[3]); |
| 805 }); | 813 }); |
| 806 }); | 814 }); |
| 807 }); | 815 }); |
| 808 } | 816 } |
| 809 return { | 817 return { |
| 810 registerTests: registerTests, | 818 registerTests: registerTests, |
| 811 }; | 819 }; |
| 812 }); | 820 }); |
| OLD | NEW |