| 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 | 6 |
| 7 /** | 7 /** |
| 8 * An example pref with 2 blocked location items and 2 allowed. This pref | 8 * An example pref with 2 blocked location items and 2 allowed. This pref |
| 9 * is also used for the All Sites category and therefore needs values for | 9 * is also used for the All Sites category and therefore needs values for |
| 10 * all types, even though some might be blank. | 10 * all types, even though some might be blank. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 origin: 'https://bar.com', | 143 origin: 'https://bar.com', |
| 144 embeddingOrigin: '', | 144 embeddingOrigin: '', |
| 145 setting: 'allow', | 145 setting: 'allow', |
| 146 source: 'preference', | 146 source: 'preference', |
| 147 }, | 147 }, |
| 148 ], | 148 ], |
| 149 } | 149 } |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * An example pref with mixed origin and pattern. | |
| 154 * @type {SiteSettingsPref} | |
| 155 */ | |
| 156 var prefsMixedOriginAndPattern = { | |
| 157 exceptions: { | |
| 158 auto_downloads: [], | |
| 159 background_sync: [], | |
| 160 camera: [], | |
| 161 cookies: [], | |
| 162 geolocation: [ | |
| 163 { | |
| 164 origin: 'https://foo.com', | |
| 165 embeddingOrigin: 'https://example.com', | |
| 166 setting: 'allow', | |
| 167 source: 'preference', | |
| 168 }, | |
| 169 ], | |
| 170 images: [], | |
| 171 javascript: [ | |
| 172 { | |
| 173 origin: 'https://[*.]foo.com', | |
| 174 embeddingOrigin: '', | |
| 175 setting: 'allow', | |
| 176 source: 'preference', | |
| 177 }, | |
| 178 ], | |
| 179 mic: [], | |
| 180 notifications: [], | |
| 181 plugins: [], | |
| 182 midiDevices: [], | |
| 183 protectedContent: [], | |
| 184 popups: [], | |
| 185 subresource_filter: [], | |
| 186 unsandboxed_plugins: [], | |
| 187 } | |
| 188 }; | |
| 189 | |
| 190 /** | |
| 191 * An example pref with multiple categories and multiple allow/block | 153 * An example pref with multiple categories and multiple allow/block |
| 192 * state. | 154 * state. |
| 193 * @type {SiteSettingsPref} | 155 * @type {SiteSettingsPref} |
| 194 */ | 156 */ |
| 195 var prefsVarious = { | 157 var prefsVarious = { |
| 196 exceptions: { | 158 exceptions: { |
| 197 auto_downloads: [], | 159 auto_downloads: [], |
| 198 background_sync: [], | 160 background_sync: [], |
| 199 camera: [], | 161 camera: [], |
| 200 cookies: [], | 162 cookies: [], |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 418 } |
| 457 | 419 |
| 458 /** | 420 /** |
| 459 * Configures the test element for a particular category. | 421 * Configures the test element for a particular category. |
| 460 * @param {settings.ContentSettingsTypes} category The category to set up. | 422 * @param {settings.ContentSettingsTypes} category The category to set up. |
| 461 * @param {settings.PermissionValues} subtype Type of list to use. | 423 * @param {settings.PermissionValues} subtype Type of list to use. |
| 462 * @param {Array<dictionary>} prefs The prefs to use. | 424 * @param {Array<dictionary>} prefs The prefs to use. |
| 463 */ | 425 */ |
| 464 function setUpCategory(category, subtype, prefs) { | 426 function setUpCategory(category, subtype, prefs) { |
| 465 browserProxy.setPrefs(prefs); | 427 browserProxy.setPrefs(prefs); |
| 466 if (category == settings.ALL_SITES) { | 428 testElement.categorySubtype = subtype; |
| 467 testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE; | |
| 468 testElement.allSites = true; | |
| 469 } else { | |
| 470 testElement.categorySubtype = subtype; | |
| 471 testElement.allSites = false; | |
| 472 } | |
| 473 // Some route is needed, but the actual route doesn't matter. | 429 // Some route is needed, but the actual route doesn't matter. |
| 474 testElement.currentRoute = { | 430 testElement.currentRoute = { |
| 475 page: 'dummy', | 431 page: 'dummy', |
| 476 section: 'privacy', | 432 section: 'privacy', |
| 477 subpage: ['site-settings', 'site-settings-category-location'], | 433 subpage: ['site-settings', 'site-settings-category-location'], |
| 478 }; | 434 }; |
| 479 testElement.category = category; | 435 testElement.category = category; |
| 480 } | 436 } |
| 481 | 437 |
| 482 test('read-only attribute', function() { | 438 test('read-only attribute', function() { |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 var contentType = settings.ContentSettingsTypes.GEOLOCATION; | 873 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 918 setUpCategory( | 874 setUpCategory( |
| 919 contentType, settings.PermissionValues.ALLOW, prefsOneDisabled); | 875 contentType, settings.PermissionValues.ALLOW, prefsOneDisabled); |
| 920 return browserProxy.whenCalled('getExceptionList') | 876 return browserProxy.whenCalled('getExceptionList') |
| 921 .then(function(actualContentType) { | 877 .then(function(actualContentType) { |
| 922 assertEquals(contentType, actualContentType); | 878 assertEquals(contentType, actualContentType); |
| 923 assertFalse(testElement.$.category.hidden); | 879 assertFalse(testElement.$.category.hidden); |
| 924 }); | 880 }); |
| 925 }); | 881 }); |
| 926 | 882 |
| 927 test('All sites category no action menu', function() { | |
| 928 setUpCategory(settings.ALL_SITES, '', prefsVarious); | |
| 929 return browserProxy.whenCalled('getExceptionList') | |
| 930 .then(function(contentType) { | |
| 931 // Use resolver to ensure that the list container is populated. | |
| 932 var resolver = new PromiseResolver(); | |
| 933 testElement.async(resolver.resolve); | |
| 934 return resolver.promise.then(function() { | |
| 935 var item = testElement.$.listContainer.children[0]; | |
| 936 var dots = item.querySelector('#actionMenuButton'); | |
| 937 assertTrue(!!dots); | |
| 938 assertTrue(dots.hidden); | |
| 939 }); | |
| 940 }); | |
| 941 }); | |
| 942 | |
| 943 test('All sites category', function() { | |
| 944 // Prefs: Multiple and overlapping sites. | |
| 945 setUpCategory(settings.ALL_SITES, '', prefsVarious); | |
| 946 | |
| 947 return browserProxy.whenCalled('getExceptionList') | |
| 948 .then(function(contentType) { | |
| 949 // Use resolver to ensure asserts bubble up to the framework with | |
| 950 // meaningful errors. | |
| 951 var resolver = new PromiseResolver(); | |
| 952 testElement.async(resolver.resolve); | |
| 953 return resolver.promise.then(function() { | |
| 954 // All Sites calls getExceptionList for all categories, starting | |
| 955 // with Cookies. | |
| 956 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); | |
| 957 | |
| 958 // Required for firstItem to be found below. | |
| 959 Polymer.dom.flush(); | |
| 960 | |
| 961 assertFalse(testElement.$.category.hidden); | |
| 962 // Validate that the sites gets populated from pre-canned prefs. | |
| 963 assertEquals( | |
| 964 3, testElement.sites.length, | |
| 965 'If this fails with 5 instead of the expected 3, then ' + | |
| 966 'the de-duping of sites is not working for site_list'); | |
| 967 assertEquals( | |
| 968 prefsVarious.exceptions.geolocation[1].origin, | |
| 969 testElement.sites[0].origin); | |
| 970 assertEquals( | |
| 971 prefsVarious.exceptions.geolocation[0].origin, | |
| 972 testElement.sites[1].origin); | |
| 973 assertEquals( | |
| 974 prefsVarious.exceptions.notifications[0].origin, | |
| 975 testElement.sites[2].origin); | |
| 976 assertEquals(undefined, testElement.selectedOrigin); | |
| 977 | |
| 978 // Validate that the sites are shown in UI and can be selected. | |
| 979 var firstItem = testElement.$.listContainer.children[1]; | |
| 980 var clickable = firstItem.querySelector('.middle'); | |
| 981 assertNotEquals(undefined, clickable); | |
| 982 MockInteractions.tap(clickable); | |
| 983 assertEquals( | |
| 984 prefsVarious.exceptions.geolocation[0].origin, | |
| 985 settings.getQueryParameters().get('site')); | |
| 986 }); | |
| 987 }); | |
| 988 }); | |
| 989 | |
| 990 test('All sites mixed pattern and origin', function() { | |
| 991 // Prefs: One site, represented as origin and pattern. | |
| 992 setUpCategory(settings.ALL_SITES, '', prefsMixedOriginAndPattern); | |
| 993 | |
| 994 return browserProxy.whenCalled('getExceptionList') | |
| 995 .then(function(contentType) { | |
| 996 // Use resolver to ensure asserts bubble up to the framework with | |
| 997 // meaningful errors. | |
| 998 var resolver = new PromiseResolver(); | |
| 999 testElement.async(resolver.resolve); | |
| 1000 return resolver.promise.then(function() { | |
| 1001 // All Sites calls getExceptionList for all categories, starting | |
| 1002 // with Cookies. | |
| 1003 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); | |
| 1004 | |
| 1005 // Required for firstItem to be found below. | |
| 1006 Polymer.dom.flush(); | |
| 1007 | |
| 1008 assertFalse(testElement.$.category.hidden); | |
| 1009 // Validate that the sites gets populated from pre-canned prefs. | |
| 1010 // TODO(dschuyler): de-duping of sites is under discussion, so | |
| 1011 // it is currently disabled. It should be enabled again or this | |
| 1012 // code should be removed. | |
| 1013 assertEquals( | |
| 1014 2, testElement.sites.length, | |
| 1015 'If this fails with 1 instead of the expected 2, then ' + | |
| 1016 'the de-duping of sites has been enabled for site_list.'); | |
| 1017 if (testElement.sites.length == 1) { | |
| 1018 assertEquals( | |
| 1019 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin, | |
| 1020 testElement.sites[0].displayName); | |
| 1021 } | |
| 1022 | |
| 1023 assertEquals(undefined, testElement.selectedOrigin); | |
| 1024 // Validate that the sites are shown in UI and can be selected. | |
| 1025 var firstItem = testElement.$.listContainer.children[0]; | |
| 1026 var clickable = firstItem.querySelector('.middle'); | |
| 1027 assertNotEquals(undefined, clickable); | |
| 1028 MockInteractions.tap(clickable); | |
| 1029 if (testElement.sites.length == 1) { | |
| 1030 assertEquals( | |
| 1031 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin, | |
| 1032 testElement.sites[0].displayName); | |
| 1033 } | |
| 1034 }); | |
| 1035 }); | |
| 1036 }); | |
| 1037 | |
| 1038 test('Mixed embeddingOrigin', function() { | 883 test('Mixed embeddingOrigin', function() { |
| 1039 setUpCategory( | 884 setUpCategory( |
| 1040 settings.ContentSettingsTypes.IMAGES, settings.PermissionValues.ALLOW, | 885 settings.ContentSettingsTypes.IMAGES, settings.PermissionValues.ALLOW, |
| 1041 prefsMixedEmbeddingOrigin); | 886 prefsMixedEmbeddingOrigin); |
| 1042 return browserProxy.whenCalled('getExceptionList') | 887 return browserProxy.whenCalled('getExceptionList') |
| 1043 .then(function(contentType) { | 888 .then(function(contentType) { |
| 1044 // Required for firstItem to be found below. | 889 // Required for firstItem to be found below. |
| 1045 Polymer.dom.flush(); | 890 Polymer.dom.flush(); |
| 1046 // Validate that embeddingOrigin sites cannot be edited. | 891 // Validate that embeddingOrigin sites cannot be edited. |
| 1047 var firstItem = testElement.$.listContainer.children[0]; | 892 var firstItem = testElement.$.listContainer.children[0]; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 input.value = expectedPattern; | 1092 input.value = expectedPattern; |
| 1248 input.fire('input'); | 1093 input.fire('input'); |
| 1249 | 1094 |
| 1250 return browserProxy.whenCalled('isPatternValid').then(function(pattern) { | 1095 return browserProxy.whenCalled('isPatternValid').then(function(pattern) { |
| 1251 assertEquals(expectedPattern, pattern); | 1096 assertEquals(expectedPattern, pattern); |
| 1252 assertTrue(actionButton.disabled); | 1097 assertTrue(actionButton.disabled); |
| 1253 assertTrue(input.invalid); | 1098 assertTrue(input.invalid); |
| 1254 }); | 1099 }); |
| 1255 }); | 1100 }); |
| 1256 }); | 1101 }); |
| OLD | NEW |