| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 embeddingOrigin: '', | 275 embeddingOrigin: '', |
| 276 incognito: true, | 276 incognito: true, |
| 277 origin: 'http://bar.com', | 277 origin: 'http://bar.com', |
| 278 setting: 'allow', | 278 setting: 'allow', |
| 279 source: 'preference', | 279 source: 'preference', |
| 280 }, | 280 }, |
| 281 ] | 281 ] |
| 282 } | 282 } |
| 283 }; | 283 }; |
| 284 | 284 |
| 285 /** |
| 286 * An example Javascript pref with a chrome-extension:// scheme. |
| 287 * @type {SiteSettingsPref} |
| 288 */ |
| 289 var prefsChromeExtension = { |
| 290 exceptions: { |
| 291 javascript: [ |
| 292 { |
| 293 embeddingOrigin: '', |
| 294 origin: 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', |
| 295 setting: 'block', |
| 296 source: 'preference', |
| 297 }, |
| 298 ] |
| 299 } |
| 300 }; |
| 301 |
| 285 // Import necessary html before running suite. | 302 // Import necessary html before running suite. |
| 286 suiteSetup(function() { | 303 suiteSetup(function() { |
| 287 CrSettingsPrefs.setInitialized(); | 304 CrSettingsPrefs.setInitialized(); |
| 288 return PolymerTest.importHtml( | 305 return PolymerTest.importHtml( |
| 289 'chrome://md-settings/site_settings/site_list.html'); | 306 'chrome://md-settings/site_settings/site_list.html'); |
| 290 }); | 307 }); |
| 291 | 308 |
| 292 suiteTeardown(function() { | 309 suiteTeardown(function() { |
| 293 CrSettingsPrefs.resetForTesting(); | 310 CrSettingsPrefs.resetForTesting(); |
| 294 }); | 311 }); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement); | 509 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement); |
| 493 assertEquals('Block - 1', | 510 assertEquals('Block - 1', |
| 494 testElement.$.header.innerText.trim()); | 511 testElement.$.header.innerText.trim()); |
| 495 | 512 |
| 496 // Select 'Remove from menu'. | 513 // Select 'Remove from menu'. |
| 497 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 514 var menuItems = getMenuItems(testElement.$.listContainer, 0); |
| 498 assertTrue(!!menuItems); | 515 assertTrue(!!menuItems); |
| 499 MockInteractions.tap(menuItems[2]); | 516 MockInteractions.tap(menuItems[2]); |
| 500 return browserProxy.whenCalled( | 517 return browserProxy.whenCalled( |
| 501 'resetCategoryPermissionForOrigin'); | 518 'resetCategoryPermissionForOrigin'); |
| 502 }).then(function(arguments) { | 519 }).then(function(args) { |
| 503 assertEquals('http://foo.com', arguments[0]); | 520 assertEquals('http://foo.com', args[0]); |
| 504 assertEquals('http://foo.com', arguments[1]); | 521 assertEquals('http://foo.com', args[1]); |
| 505 assertEquals(settings.ContentSettingsTypes.COOKIES, arguments[2]); | 522 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 506 assertFalse(arguments[3]); // Incognito. | 523 assertFalse(args[3]); // Incognito. |
| 507 }); | 524 }); |
| 508 }); | 525 }); |
| 509 | 526 |
| 510 test('initial INCOGNITO ALLOW state is correct', function() { | 527 test('initial INCOGNITO ALLOW state is correct', function() { |
| 511 setupCategory(settings.ContentSettingsTypes.COOKIES, | 528 setupCategory(settings.ContentSettingsTypes.COOKIES, |
| 512 settings.PermissionValues.ALLOW, prefsIncognito); | 529 settings.PermissionValues.ALLOW, prefsIncognito); |
| 513 return browserProxy.whenCalled('getExceptionList').then( | 530 return browserProxy.whenCalled('getExceptionList').then( |
| 514 function(contentType) { | 531 function(contentType) { |
| 515 assertEquals( | 532 assertEquals( |
| 516 settings.ContentSettingsTypes.COOKIES, contentType); | 533 settings.ContentSettingsTypes.COOKIES, contentType); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 528 assertMenu(['Block', 'Remove'], testElement); | 545 assertMenu(['Block', 'Remove'], testElement); |
| 529 assertEquals('Allow - 2', | 546 assertEquals('Allow - 2', |
| 530 testElement.$.header.innerText.trim()); | 547 testElement.$.header.innerText.trim()); |
| 531 | 548 |
| 532 // Select 'Remove' from menu on 'foo.com'. | 549 // Select 'Remove' from menu on 'foo.com'. |
| 533 var menuItems = getMenuItems(testElement.$.listContainer, 1); | 550 var menuItems = getMenuItems(testElement.$.listContainer, 1); |
| 534 assertTrue(!!menuItems); | 551 assertTrue(!!menuItems); |
| 535 MockInteractions.tap(menuItems[1]); | 552 MockInteractions.tap(menuItems[1]); |
| 536 return browserProxy.whenCalled( | 553 return browserProxy.whenCalled( |
| 537 'resetCategoryPermissionForOrigin'); | 554 'resetCategoryPermissionForOrigin'); |
| 538 }).then(function(arguments) { | 555 }).then(function(args) { |
| 539 assertEquals('http://foo.com', arguments[0]); | 556 assertEquals('http://foo.com', args[0]); |
| 540 assertEquals('http://foo.com', arguments[1]); | 557 assertEquals('http://foo.com', args[1]); |
| 541 assertEquals(settings.ContentSettingsTypes.COOKIES, arguments[2]); | 558 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 542 assertTrue(arguments[3]); // Incognito. | 559 assertTrue(args[3]); // Incognito. |
| 543 }); | 560 }); |
| 544 }); | 561 }); |
| 545 | 562 |
| 546 test('list items shown and clickable when data is present', function() { | 563 test('list items shown and clickable when data is present', function() { |
| 547 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, | 564 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, |
| 548 settings.PermissionValues.ALLOW, prefs); | 565 settings.PermissionValues.ALLOW, prefs); |
| 549 return browserProxy.whenCalled('getExceptionList').then( | 566 return browserProxy.whenCalled('getExceptionList').then( |
| 550 function(contentType) { | 567 function(contentType) { |
| 551 assertEquals( | 568 assertEquals( |
| 552 settings.ContentSettingsTypes.GEOLOCATION, contentType); | 569 settings.ContentSettingsTypes.GEOLOCATION, contentType); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 settings.PermissionValues.ALLOW, prefs); | 778 settings.PermissionValues.ALLOW, prefs); |
| 762 return browserProxy.whenCalled('getExceptionList').then(function( | 779 return browserProxy.whenCalled('getExceptionList').then(function( |
| 763 contentType) { | 780 contentType) { |
| 764 Polymer.dom.flush(); | 781 Polymer.dom.flush(); |
| 765 var menuItems = getMenuItems(testElement.$.listContainer, 0); | 782 var menuItems = getMenuItems(testElement.$.listContainer, 0); |
| 766 assertTrue(!!menuItems); | 783 assertTrue(!!menuItems); |
| 767 MockInteractions.tap(menuItems[0]); | 784 MockInteractions.tap(menuItems[0]); |
| 768 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); | 785 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 769 }); | 786 }); |
| 770 }); | 787 }); |
| 788 |
| 789 test('Chrome Extension scheme', function() { |
| 790 setupCategory(settings.ContentSettingsTypes.JAVASCRIPT, |
| 791 settings.PermissionValues.BLOCK, prefsChromeExtension); |
| 792 return browserProxy.whenCalled('getExceptionList').then(function( |
| 793 contentType) { |
| 794 Polymer.dom.flush(); |
| 795 assertMenu(['Allow', 'Remove'], testElement); |
| 796 |
| 797 var menuItems = getMenuItems(testElement.$.listContainer, 0); |
| 798 assertTrue(!!menuItems); |
| 799 MockInteractions.tap(menuItems[0]); // Action: Allow. |
| 800 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 801 }).then(function(args) { |
| 802 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', |
| 803 args[0]); |
| 804 assertEquals('', args[1]); |
| 805 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); |
| 806 assertEquals('allow', args[3]); |
| 807 }); |
| 808 }); |
| 771 }); | 809 }); |
| 772 } | 810 } |
| 773 return { | 811 return { |
| 774 registerTests: registerTests, | 812 registerTests: registerTests, |
| 775 }; | 813 }; |
| 776 }); | 814 }); |
| OLD | NEW |