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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 embeddingOrigin: 'bar-allow.com', | 80 embeddingOrigin: 'bar-allow.com', |
81 origin: 'bar-allow.com', | 81 origin: 'bar-allow.com', |
82 setting: 'allow', | 82 setting: 'allow', |
83 source: 'preference', | 83 source: 'preference', |
84 }, | 84 }, |
85 ] | 85 ] |
86 } | 86 } |
87 }; | 87 }; |
88 | 88 |
89 /** | 89 /** |
| 90 * An example pref with mixed origin and pattern. |
| 91 * @type {SiteSettingsPref} |
| 92 */ |
| 93 var prefsMixedOriginAndPattern = { |
| 94 exceptions: { |
| 95 media_stream_camera: [], |
| 96 cookies: [], |
| 97 fullscreen: [], |
| 98 geolocation: [ |
| 99 { |
| 100 origin: 'https://foo.com', |
| 101 embeddingOrigin: '*', |
| 102 setting: 'allow', |
| 103 source: 'preference', |
| 104 }, |
| 105 ], |
| 106 javascript: [ |
| 107 { |
| 108 origin: 'https://[*.]foo.com', |
| 109 embeddingOrigin: '*', |
| 110 setting: 'allow', |
| 111 source: 'preference', |
| 112 }, |
| 113 ], |
| 114 images: [], |
| 115 media_stream_mic: [], |
| 116 notifications: [], |
| 117 popups: [], |
| 118 } |
| 119 }; |
| 120 |
| 121 /** |
90 * An example pref with multiple categories and multiple allow/block | 122 * An example pref with multiple categories and multiple allow/block |
91 * state. | 123 * state. |
92 * @type {SiteSettingsPref} | 124 * @type {SiteSettingsPref} |
93 */ | 125 */ |
94 var prefsVarious = { | 126 var prefsVarious = { |
95 exceptions: { | 127 exceptions: { |
96 media_stream_camera: [], | 128 media_stream_camera: [], |
97 cookies: [], | 129 cookies: [], |
98 fullscreen: [], | 130 fullscreen: [], |
99 geolocation: [ | 131 geolocation: [ |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 prefsOneDisabled); | 477 prefsOneDisabled); |
446 return browserProxy.whenCalled('getExceptionList').then( | 478 return browserProxy.whenCalled('getExceptionList').then( |
447 function(contentType) { | 479 function(contentType) { |
448 assertEquals( | 480 assertEquals( |
449 settings.ContentSettingsTypes.GEOLOCATION, contentType); | 481 settings.ContentSettingsTypes.GEOLOCATION, contentType); |
450 | 482 |
451 assertTrue(testElement.$.category.hidden); | 483 assertTrue(testElement.$.category.hidden); |
452 }); | 484 }); |
453 }); | 485 }); |
454 | 486 |
455 test('All sites category', function(done) { | 487 test('All sites category', function() { |
456 // Prefs: Multiple and overlapping sites. | 488 // Prefs: Multiple and overlapping sites. |
457 setupAllSitesCategory(prefsVarious); | 489 setupAllSitesCategory(prefsVarious); |
458 | 490 |
459 browserProxy.whenCalled('getExceptionList').then( | 491 return browserProxy.whenCalled('getExceptionList').then( |
460 function(contentType) { | 492 function(contentType) { |
461 testElement.async(function() { | 493 // Use resolver to ensure asserts bubble up to the framework with |
| 494 // meaningful errors. |
| 495 var resolver = new PromiseResolver(); |
| 496 testElement.async(resolver.resolve); |
| 497 return resolver.promise.then(function() { |
462 // All Sites calls getExceptionList for all categories, starting | 498 // All Sites calls getExceptionList for all categories, starting |
463 // with Cookies. | 499 // with Cookies. |
464 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); | 500 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); |
465 | 501 |
466 // Required for firstItem to be found below. | 502 // Required for firstItem to be found below. |
467 Polymer.dom.flush(); | 503 Polymer.dom.flush(); |
468 | 504 |
469 assertTrue(testElement.$.category.opened); | 505 assertTrue(testElement.$.category.opened); |
470 assertFalse(testElement.$.category.hidden); | 506 assertFalse(testElement.$.category.hidden); |
471 // Validate that the sites gets populated from pre-canned prefs. | 507 // Validate that the sites gets populated from pre-canned prefs. |
472 // If this fails with 5 instead of the expected 3, then the | 508 assertEquals(3, testElement.sites.length, |
473 // de-duping of sites is not working for site_list. | 509 'If this fails with 5 instead of the expected 3, then the ' + |
474 assertEquals(3, testElement.sites.length); | 510 'de-duping of sites is not working for site_list'); |
475 assertEquals(prefsVarious.exceptions.geolocation[1].origin, | 511 assertEquals(prefsVarious.exceptions.geolocation[1].origin, |
476 testElement.sites[0].origin); | 512 testElement.sites[0].origin); |
477 assertEquals(prefsVarious.exceptions.geolocation[0].origin, | 513 assertEquals(prefsVarious.exceptions.geolocation[0].origin, |
478 testElement.sites[1].origin); | 514 testElement.sites[1].origin); |
479 assertEquals(prefsVarious.exceptions.notifications[0].origin, | 515 assertEquals(prefsVarious.exceptions.notifications[0].origin, |
480 testElement.sites[2].origin); | 516 testElement.sites[2].origin); |
481 assertEquals(undefined, testElement.selectedOrigin); | 517 assertEquals(undefined, testElement.selectedOrigin); |
482 | 518 |
483 // Validate that the sites are shown in UI and can be selected. | 519 // Validate that the sites are shown in UI and can be selected. |
484 var firstItem = testElement.$.listContainer.items[1]; | 520 var firstItem = testElement.$.listContainer.items[1]; |
485 var clickable = firstItem.querySelector('.flex paper-item-body'); | 521 var clickable = firstItem.querySelector('.flex paper-item-body'); |
486 assertNotEquals(undefined, clickable); | 522 assertNotEquals(undefined, clickable); |
487 MockInteractions.tap(clickable); | 523 MockInteractions.tap(clickable); |
488 assertEquals(prefsVarious.exceptions.geolocation[0].origin, | 524 assertEquals(prefsVarious.exceptions.geolocation[0].origin, |
489 testElement.selectedSite.origin); | 525 testElement.selectedSite.origin); |
| 526 }); |
| 527 }); |
| 528 }); |
490 | 529 |
491 done(); | 530 test('All sites mixed pattern and origin', function() { |
| 531 // Prefs: One site, represented as origin and pattern. |
| 532 setupAllSitesCategory(prefsMixedOriginAndPattern); |
| 533 |
| 534 return browserProxy.whenCalled('getExceptionList').then( |
| 535 function(contentType) { |
| 536 // Use resolver to ensure asserts bubble up to the framework with |
| 537 // meaningful errors. |
| 538 var resolver = new PromiseResolver(); |
| 539 testElement.async(resolver.resolve); |
| 540 return resolver.promise.then(function() { |
| 541 // All Sites calls getExceptionList for all categories, starting |
| 542 // with Cookies. |
| 543 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); |
| 544 |
| 545 // Required for firstItem to be found below. |
| 546 Polymer.dom.flush(); |
| 547 |
| 548 assertTrue(testElement.$.category.opened); |
| 549 assertFalse(testElement.$.category.hidden); |
| 550 // Validate that the sites gets populated from pre-canned prefs. |
| 551 assertEquals(1, testElement.sites.length, |
| 552 'If this fails with 2 instead of the expected 1, then the ' + |
| 553 'de-duping of sites is not working for site_list'); |
| 554 assertEquals( |
| 555 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin, |
| 556 testElement.sites[0].originForDisplay); |
| 557 |
| 558 assertEquals(undefined, testElement.selectedOrigin); |
| 559 // Validate that the sites are shown in UI and can be selected. |
| 560 var firstItem = testElement.$.listContainer.items[0]; |
| 561 var clickable = firstItem.querySelector('.flex paper-item-body'); |
| 562 assertNotEquals(undefined, clickable); |
| 563 MockInteractions.tap(clickable); |
| 564 assertEquals( |
| 565 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin, |
| 566 testElement.selectedSite.originForDisplay); |
| 567 }); |
492 }); | 568 }); |
493 }); | |
494 }); | 569 }); |
495 | 570 |
496 test('Mixed schemes (present and absent)', function() { | 571 test('Mixed schemes (present and absent)', function() { |
497 // Prefs: One item with scheme and one without. | 572 // Prefs: One item with scheme and one without. |
498 setupLocationCategory(settings.PermissionValues.ALLOW, | 573 setupLocationCategory(settings.PermissionValues.ALLOW, |
499 prefsMixedSchemes); | 574 prefsMixedSchemes); |
500 return browserProxy.whenCalled('getExceptionList').then( | 575 return browserProxy.whenCalled('getExceptionList').then( |
501 function(contentType) { | 576 function(contentType) { |
502 // No further checks needed. If this fails, it will hang the test. | 577 // No further checks needed. If this fails, it will hang the test. |
503 }); | 578 }); |
504 }); | 579 }); |
505 }); | 580 }); |
506 } | 581 } |
507 return { | 582 return { |
508 registerTests: registerTests, | 583 registerTests: registerTests, |
509 }; | 584 }; |
510 }); | 585 }); |
OLD | NEW |