Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: chrome/test/data/webui/settings/all_sites_tests.js

Issue 2846723002: [MD settings] separate all-sites from site-list (Closed)
Patch Set: review changes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * An example pref with exceptions with origins and patterns from
7 * different providers.
8 * @type {SiteSettingsPref}
9 */
10 var prefsMixedProvider = {
11 exceptions: {
12 geolocation: [
13 {
14 embeddingOrigin: '',
15 origin: 'https://[*.]foo.com',
16 setting: 'block',
17 source: 'policy',
18 },
19 {
20 embeddingOrigin: '',
21 origin: 'https://bar.foo.com',
22 setting: 'block',
23 source: 'preference',
24 },
25 {
26 embeddingOrigin: '',
27 origin: 'https://[*.]foo.com',
28 setting: 'block',
29 source: 'preference',
30 },
31 ],
32 images: [],
33 }
34 };
35
36 /**
37 * An example pref with mixed origin and pattern.
38 * @type {SiteSettingsPref}
39 */
40 var prefsMixedOriginAndPattern = {
41 exceptions: {
42 auto_downloads: [],
43 background_sync: [],
44 camera: [],
45 cookies: [],
46 geolocation: [
47 {
48 embeddingOrigin: '',
49 origin: 'https://foo.com',
50 setting: 'allow',
51 source: 'preference',
52 },
53 ],
54 images: [],
55 javascript: [
56 {
57 embeddingOrigin: '',
58 origin: 'https://[*.]foo.com',
59 setting: 'allow',
60 source: 'preference',
61 },
62 ],
63 mic: [],
64 notifications: [],
65 plugins: [],
66 midiDevices: [],
67 protectedContent: [],
68 popups: [],
69 subresource_filter: [],
70 unsandboxed_plugins: [],
71 }
72 };
73
74 /**
75 * An example pref with multiple categories and multiple allow/block
76 * state.
77 * @type {SiteSettingsPref}
78 */
79 var prefsVarious = {
80 exceptions: {
81 auto_downloads: [],
82 background_sync: [],
83 camera: [],
84 cookies: [],
85 geolocation: [
86 {
87 embeddingOrigin: '',
88 incognito: false,
89 origin: 'https://foo.com',
90 setting: 'allow',
91 source: 'preference',
92 },
93 {
94 embeddingOrigin: '',
95 incognito: false,
96 origin: 'https://bar.com',
97 setting: 'block',
98 source: 'preference',
99 },
100 ],
101 images: [],
102 javascript: [],
103 mic: [],
104 midiDevices: [],
105 notifications: [
106 {
107 embeddingOrigin: '',
108 incognito: false,
109 origin: 'https://google.com',
110 setting: 'block',
111 source: 'preference',
112 },
113 {
114 embeddingOrigin: '',
115 incognito: false,
116 origin: 'https://bar.com',
117 setting: 'block',
118 source: 'preference',
119 },
120 {
121 embeddingOrigin: '',
122 incognito: false,
123 origin: 'https://foo.com',
124 setting: 'block',
125 source: 'preference',
126 },
127 ],
128 plugins: [],
129 protectedContent: [],
130 popups: [],
131 subresource_filter: [],
132 unsandboxed_plugins: [],
133 }
134 };
135
136 suite('AllSites', function() {
137 /**
138 * A site list element created before each test.
139 * @type {SiteList}
140 */
141 var testElement;
142
143 /**
144 * The mock proxy object to use during test.
145 * @type {TestSiteSettingsPrefsBrowserProxy}
146 */
147 var browserProxy = null;
148
149 suiteSetup(function() {
150 CrSettingsPrefs.setInitialized();
151 });
152
153 suiteTeardown(function() {
154 CrSettingsPrefs.resetForTesting();
155 });
156
157 // Initialize a site-list before each test.
158 setup(function() {
159 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
160 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
161 PolymerTest.clearBody();
162 browserProxy.setPrefs(prefsMixedOriginAndPattern);
163 testElement = document.createElement('all-sites');
164 assertTrue(!!testElement);
165 document.body.appendChild(testElement);
166 });
167
168 teardown(function() {
169 // The code being tested changes the Route. Reset so that state is not
170 // leaked across tests.
171 settings.resetRouteForTesting();
172 });
173
174 /**
175 * Configures the test element.
176 * @param {Array<dictionary>} prefs The prefs to use.
177 */
178 function setUpCategory(prefs) {
179 browserProxy.setPrefs(prefs);
180 // Some route is needed, but the actual route doesn't matter.
181 testElement.currentRoute = {
182 page: 'dummy',
183 section: 'privacy',
184 subpage: ['site-settings', 'site-settings-category-location'],
185 };
186 }
187
188 test('All sites category no action menu', function() {
189 setUpCategory(prefsVarious);
190 return browserProxy.whenCalled('getExceptionList')
191 .then(function(contentType) {
192 // Use resolver to ensure that the list container is populated.
193 var resolver = new PromiseResolver();
194 testElement.async(resolver.resolve);
195 return resolver.promise.then(function() {
196 var item = testElement.$.listContainer.children[0];
197 var name = item.querySelector('#displayName');
198 assertTrue(!!name);
199 });
200 });
201 });
202
203 test('All sites category', function() {
204 // Prefs: Multiple and overlapping sites.
205 setUpCategory(prefsVarious);
206
207 return browserProxy.whenCalled('getExceptionList')
208 .then(function(contentType) {
209 // Use resolver to ensure asserts bubble up to the framework with
210 // meaningful errors.
211 var resolver = new PromiseResolver();
212 testElement.async(resolver.resolve);
213 return resolver.promise.then(function() {
214 // All Sites calls getExceptionList for all categories, starting
215 // with Cookies.
216 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType);
217
218 // Required for firstItem to be found below.
219 Polymer.dom.flush();
220
221 // Validate that the sites gets populated from pre-canned prefs.
222 assertEquals(
223 3, testElement.sites.length,
224 'If this fails with 5 instead of the expected 3, then ' +
225 'the de-duping of sites is not working for site_list');
226 assertEquals(
227 prefsVarious.exceptions.geolocation[1].origin,
228 testElement.sites[0].origin);
229 assertEquals(
230 prefsVarious.exceptions.geolocation[0].origin,
231 testElement.sites[1].origin);
232 assertEquals(
233 prefsVarious.exceptions.notifications[0].origin,
234 testElement.sites[2].origin);
235 assertEquals(undefined, testElement.selectedOrigin);
236
237 // Validate that the sites are shown in UI and can be selected.
238 var firstItem = testElement.$.listContainer.children[1];
239 var clickable = firstItem.querySelector('.middle');
240 assertNotEquals(undefined, clickable);
241 MockInteractions.tap(clickable);
242 assertEquals(
243 prefsVarious.exceptions.geolocation[0].origin,
244 settings.getQueryParameters().get('site'));
245 });
246 });
247 });
248
249 test('All sites mixed pattern and origin', function() {
250 // Prefs: One site, represented as origin and pattern.
251 setUpCategory(prefsMixedOriginAndPattern);
252
253 return browserProxy.whenCalled('getExceptionList')
254 .then(function(contentType) {
255 // Use resolver to ensure asserts bubble up to the framework with
256 // meaningful errors.
257 var resolver = new PromiseResolver();
258 testElement.async(resolver.resolve);
259 return resolver.promise.then(function() {
260 // All Sites calls getExceptionList for all categories, starting
261 // with Cookies.
262 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType);
263
264 // Required for firstItem to be found below.
265 Polymer.dom.flush();
266
267 // Validate that the sites gets populated from pre-canned prefs.
268 // TODO(dschuyler): de-duping of sites is under discussion, so
269 // it is currently disabled. It should be enabled again or this
270 // code should be removed.
271 assertEquals(
272 2, testElement.sites.length,
273 'If this fails with 1 instead of the expected 2, then ' +
274 'the de-duping of sites has been enabled for site_list.');
275 if (testElement.sites.length == 1) {
276 assertEquals(
277 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
278 testElement.sites[0].displayName);
279 }
280
281 assertEquals(undefined, testElement.selectedOrigin);
282 // Validate that the sites are shown in UI and can be selected.
283 var firstItem = testElement.$.listContainer.children[0];
284 var clickable = firstItem.querySelector('.middle');
285 assertNotEquals(undefined, clickable);
286 MockInteractions.tap(clickable);
287 if (testElement.sites.length == 1) {
288 assertEquals(
289 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
290 testElement.sites[0].displayName);
291 }
292 });
293 });
294 });
295 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698