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

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

Issue 2862463002: [MD settings] split up site settings tests (Closed)
Patch Set: mocha grep 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
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
7 /**
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
10 * all types, even though some might be blank.
11 * @type {SiteSettingsPref}
12 */
13 var prefs = {
14 exceptions: {
15 auto_downloads: [],
16 background_sync: [],
17 camera: [],
18 cookies: [],
19 geolocation: [
20 {
21 embeddingOrigin: 'https://bar-allow.com:443',
22 origin: 'https://bar-allow.com:443',
23 setting: 'allow',
24 source: 'preference',
25 },
26 {
27 embeddingOrigin: 'https://foo-allow.com:443',
28 origin: 'https://foo-allow.com:443',
29 setting: 'allow',
30 source: 'preference',
31 },
32 {
33 embeddingOrigin: 'https://bar-block.com:443',
34 origin: 'https://bar-block.com:443',
35 setting: 'block',
36 source: 'preference',
37 },
38 {
39 embeddingOrigin: 'https://foo-block.com:443',
40 origin: 'https://foo-block.com:443',
41 setting: 'block',
42 source: 'preference',
43 },
44 ],
45 images: [],
46 javascript: [],
47 mic: [],
48 midiDevices: [],
49 notifications: [],
50 plugins: [],
51 protectedContent: [],
52 popups: [],
53 subresource_filter: [],
54 unsandboxed_plugins: [],
55 }
56 };
57
58 /**
59 * An example of prefs controlledBy policy.
60 * @type {SiteSettingsPref}
61 */
62 var prefsControlled = {
63 exceptions: {
64 plugins: [
65 {
66 embeddingOrigin: 'http://foo-block.com',
67 origin: 'http://foo-block.com',
68 setting: 'block',
69 source: 'policy',
70 },
71 ]
72 }
73 };
74
75 /**
76 * An example pref with mixed schemes (present and absent).
77 * @type {SiteSettingsPref}
78 */
79 var prefsMixedSchemes = {
80 exceptions: {
81 geolocation: [
82 {
83 embeddingOrigin: 'https://foo-allow.com',
84 origin: 'https://foo-allow.com',
85 setting: 'allow',
86 source: 'preference',
87 },
88 {
89 embeddingOrigin: 'bar-allow.com',
90 origin: 'bar-allow.com',
91 setting: 'allow',
92 source: 'preference',
93 },
94 ]
95 }
96 };
97
98
99 /**
100 * An example pref with exceptions with origins and patterns from
101 * different providers.
102 * @type {SiteSettingsPref}
103 */
104 var prefsMixedProvider = {
105 exceptions: {
106 geolocation: [
107 {
108 embeddingOrigin: 'https://[*.]foo.com',
109 origin: 'https://[*.]foo.com',
110 setting: 'block',
111 source: 'policy',
112 },
113 {
114 embeddingOrigin: 'https://bar.foo.com',
115 origin: 'https://bar.foo.com',
116 setting: 'block',
117 source: 'preference',
118 },
119 {
120 embeddingOrigin: 'https://[*.]foo.com',
121 origin: 'https://[*.]foo.com',
122 setting: 'block',
123 source: 'preference',
124 },
125 ]
126 }
127 };
128
129 /**
130 * An example pref with mixed origin and pattern.
131 * @type {SiteSettingsPref}
132 */
133 var prefsMixedOriginAndPattern = {
134 exceptions: {
135 auto_downloads: [],
136 background_sync: [],
137 camera: [],
138 cookies: [],
139 geolocation: [
140 {
141 origin: 'https://foo.com',
142 embeddingOrigin: '*',
143 setting: 'allow',
144 source: 'preference',
145 },
146 ],
147 images: [],
148 javascript: [
149 {
150 origin: 'https://[*.]foo.com',
151 embeddingOrigin: '*',
152 setting: 'allow',
153 source: 'preference',
154 },
155 ],
156 mic: [],
157 notifications: [],
158 plugins: [],
159 midiDevices: [],
160 protectedContent: [],
161 popups: [],
162 subresource_filter: [],
163 unsandboxed_plugins: [],
164 }
165 };
166
167 /**
168 * An example pref with multiple categories and multiple allow/block
169 * state.
170 * @type {SiteSettingsPref}
171 */
172 var prefsVarious = {
173 exceptions: {
174 auto_downloads: [],
175 background_sync: [],
176 camera: [],
177 cookies: [],
178 geolocation: [
179 {
180 embeddingOrigin: 'https://foo.com',
181 incognito: false,
182 origin: 'https://foo.com',
183 setting: 'allow',
184 source: 'preference',
185 },
186 {
187 embeddingOrigin: 'https://bar.com',
188 incognito: false,
189 origin: 'https://bar.com',
190 setting: 'block',
191 source: 'preference',
192 },
193 ],
194 images: [],
195 javascript: [],
196 mic: [],
197 midiDevices: [],
198 notifications: [
199 {
200 embeddingOrigin: 'https://google.com',
201 incognito: false,
202 origin: 'https://google.com',
203 setting: 'block',
204 source: 'preference',
205 },
206 {
207 embeddingOrigin: 'https://bar.com',
208 incognito: false,
209 origin: 'https://bar.com',
210 setting: 'block',
211 source: 'preference',
212 },
213 {
214 embeddingOrigin: 'https://foo.com',
215 incognito: false,
216 origin: 'https://foo.com',
217 setting: 'block',
218 source: 'preference',
219 },
220 ],
221 plugins: [],
222 protectedContent: [],
223 popups: [],
224 subresource_filter: [],
225 unsandboxed_plugins: [],
226 }
227 };
228
229 /**
230 * An example pref with 1 allowed location item.
231 * @type {SiteSettingsPref}
232 */
233 var prefsOneEnabled = {
234 exceptions: {
235 geolocation: [
236 {
237 embeddingOrigin: 'https://foo-allow.com:443',
238 incognito: false,
239 origin: 'https://foo-allow.com:443',
240 setting: 'allow',
241 source: 'preference',
242 },
243 ]
244 }
245 };
246
247 /**
248 * An example pref with 1 blocked location item.
249 * @type {SiteSettingsPref}
250 */
251 var prefsOneDisabled = {
252 exceptions: {
253 geolocation: [
254 {
255 embeddingOrigin: 'https://foo-block.com:443',
256 incognito: false,
257 origin: 'https://foo-block.com:443',
258 setting: 'block',
259 source: 'preference',
260 },
261 ]
262 }
263 };
264
265 /**
266 * An example Cookies pref with 1 in each of the three categories.
267 * @type {SiteSettingsPref}
268 */
269 var prefsSessionOnly = {
270 exceptions: {
271 cookies: [
272 {
273 embeddingOrigin: 'http://foo-block.com',
274 incognito: false,
275 origin: 'http://foo-block.com',
276 setting: 'block',
277 source: 'preference',
278 },
279 {
280 embeddingOrigin: 'http://foo-allow.com',
281 incognito: false,
282 origin: 'http://foo-allow.com',
283 setting: 'allow',
284 source: 'preference',
285 },
286 {
287 embeddingOrigin: 'http://foo-session.com',
288 incognito: false,
289 origin: 'http://foo-session.com',
290 setting: 'session_only',
291 source: 'preference',
292 },
293 ]
294 }
295 };
296
297 /**
298 * An example Cookies pref with mixed incognito and regular settings.
299 * @type {SiteSettingsPref}
300 */
301 var prefsIncognito = {
302 exceptions: {
303 cookies: [
304 // foo.com is blocked for regular sessions.
305 {
306 embeddingOrigin: 'http://foo.com',
307 incognito: false,
308 origin: 'http://foo.com',
309 setting: 'block',
310 source: 'preference',
311 },
312 // bar.com is an allowed incognito item without an embedder.
313 {
314 embeddingOrigin: '',
315 incognito: true,
316 origin: 'http://bar.com',
317 setting: 'allow',
318 source: 'preference',
319 },
320 // foo.com is allowed in incognito (overridden).
321 {
322 embeddingOrigin: 'http://foo.com',
323 incognito: true,
324 origin: 'http://foo.com',
325 setting: 'allow',
326 source: 'preference',
327 },
328
329 ]
330 }
331 };
332
333 /**
334 * An example Javascript pref with a chrome-extension:// scheme.
335 * @type {SiteSettingsPref}
336 */
337 var prefsChromeExtension = {
338 exceptions: {
339 javascript: [
340 {
341 embeddingOrigin: '',
342 incognito: false,
343 origin: 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/',
344 setting: 'block',
345 source: 'preference',
346 },
347 ]
348 }
349 };
350
351
352 suite('SiteList', function() {
7 /** 353 /**
8 * An example pref with 2 blocked location items and 2 allowed. This pref 354 * A site list element created before each test.
9 * is also used for the All Sites category and therefore needs values for 355 * @type {SiteList}
10 * all types, even though some might be blank.
11 * @type {SiteSettingsPref}
12 */ 356 */
13 var prefs = { 357 var testElement;
14 exceptions: { 358
15 auto_downloads: [], 359 /**
16 background_sync: [], 360 * The mock proxy object to use during test.
17 camera: [], 361 * @type {TestSiteSettingsPrefsBrowserProxy}
18 cookies: [], 362 */
19 geolocation: [ 363 var browserProxy = null;
20 { 364
21 embeddingOrigin: 'https://bar-allow.com:443', 365
22 origin: 'https://bar-allow.com:443', 366 suiteSetup(function() {
23 setting: 'allow', 367 CrSettingsPrefs.setInitialized();
24 source: 'preference', 368 });
25 }, 369
26 { 370 suiteTeardown(function() {
27 embeddingOrigin: 'https://foo-allow.com:443', 371 CrSettingsPrefs.resetForTesting();
28 origin: 'https://foo-allow.com:443', 372 });
29 setting: 'allow', 373
30 source: 'preference', 374 // Initialize a site-list before each test.
31 }, 375 setup(function() {
32 { 376 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
33 embeddingOrigin: 'https://bar-block.com:443', 377 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
34 origin: 'https://bar-block.com:443', 378 PolymerTest.clearBody();
35 setting: 'block', 379 testElement = document.createElement('site-list');
36 source: 'preference', 380 document.body.appendChild(testElement);
37 }, 381 });
38 { 382
39 embeddingOrigin: 'https://foo-block.com:443', 383 teardown(function() {
40 origin: 'https://foo-block.com:443', 384 closeActionMenu();
41 setting: 'block', 385 // The code being tested changes the Route. Reset so that state is not
42 source: 'preference', 386 // leaked across tests.
43 }, 387 settings.resetRouteForTesting();
44 ], 388 });
45 images: [], 389
46 javascript: [], 390 /**
47 mic: [], 391 * Opens the action menu for a particular element in the list.
48 midiDevices: [], 392 * @param {number} index The index of the child element (which site) to
49 notifications: [], 393 * open the action menu for.
50 plugins: [], 394 */
51 protectedContent: [], 395 function openActionMenu(index) {
52 popups: [], 396 var item = testElement.$.listContainer.children[index];
53 subresource_filter: [], 397 var dots = item.querySelector('#actionMenuButton');
54 unsandboxed_plugins: [], 398 MockInteractions.tap(dots);
399 Polymer.dom.flush();
400 }
401
402 /** Closes the action menu. */
403 function closeActionMenu() {
404 var menu = testElement.$$('dialog[is=cr-action-menu]');
405 if (menu.open)
406 menu.close();
407 }
408
409 /**
410 * Asserts the menu looks as expected.
411 * @param {Array<string>} items The items expected to show in the menu.
412 */
413 function assertMenu(items) {
414 var menu = testElement.$$('dialog[is=cr-action-menu]');
415 assertTrue(!!menu);
416 var menuItems = menu.querySelectorAll('button:not([hidden])');
417 assertEquals(items.length, menuItems.length);
418 for (var i = 0; i < items.length; i++)
419 assertEquals(items[i], menuItems[i].textContent.trim());
420 }
421
422 /**
423 * @param {HTMLElement} listContainer Node with the exceptions listed.
424 * @return {boolean} Whether the entry is incognito only.
425 */
426 function hasAnIncognito(listContainer) {
427 var descriptions = listContainer.querySelectorAll('#siteDescription');
428 for (var i = 0; i < descriptions.length; ++i) {
429 if (descriptions[i].textContent == 'Current incognito session')
430 return true;
55 } 431 }
56 }; 432 return false;
433 }
57 434
58 /** 435 /**
59 * An example of prefs controlleBy policy. 436 * Configures the test element for a particular category.
60 * @type {SiteSettingsPref} 437 * @param {settings.ContentSettingsTypes} category The category to set up.
438 * @param {settings.PermissionValues} subtype Type of list to use.
439 * @param {Array<dictionary>} prefs The prefs to use.
61 */ 440 */
62 var prefsControlled = { 441 function setUpCategory(category, subtype, prefs) {
63 exceptions: { 442 browserProxy.setPrefs(prefs);
64 plugins: [ 443 if (category == settings.ALL_SITES) {
65 { 444 testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE;
66 embeddingOrigin: 'http://foo-block.com', 445 testElement.allSites = true;
67 origin: 'http://foo-block.com', 446 } else {
68 setting: 'block', 447 testElement.categorySubtype = subtype;
69 source: 'policy', 448 testElement.allSites = false;
70 },
71 ]
72 } 449 }
73 }; 450 // Some route is needed, but the actual route doesn't matter.
74 451 testElement.currentRoute = {
75 /** 452 page: 'dummy',
76 * An example pref with mixed schemes (present and absent). 453 section: 'privacy',
77 * @type {SiteSettingsPref} 454 subpage: ['site-settings', 'site-settings-category-location'],
78 */ 455 };
79 var prefsMixedSchemes = { 456 testElement.category = category;
80 exceptions: { 457 }
81 geolocation: [ 458
82 { 459 test('read-only attribute', function() {
83 embeddingOrigin: 'https://foo-allow.com', 460 setUpCategory(
84 origin: 'https://foo-allow.com', 461 settings.ContentSettingsTypes.GEOLOCATION,
85 setting: 'allow', 462 settings.PermissionValues.ALLOW, prefsVarious);
86 source: 'preference', 463 return browserProxy.whenCalled('getExceptionList')
87 }, 464 .then(function(contentType) {
88 { 465 // Flush to be sure list container is populated.
89 embeddingOrigin: 'bar-allow.com', 466 Polymer.dom.flush();
90 origin: 'bar-allow.com', 467 var dotsMenu =
91 setting: 'allow', 468 testElement.$.listContainer.querySelector('#actionMenuButton');
92 source: 'preference', 469 assertFalse(dotsMenu.hidden);
93 }, 470 testElement.setAttribute('read-only-list', true);
94 ] 471 Polymer.dom.flush();
95 } 472 assertTrue(dotsMenu.hidden);
96 }; 473 testElement.removeAttribute('read-only-list');
97 474 Polymer.dom.flush();
98 475 assertFalse(dotsMenu.hidden);
99 /** 476 });
100 * An example pref with exceptions with origins and patterns from 477 });
101 * different providers. 478
102 * @type {SiteSettingsPref} 479 test('getExceptionList API used', function() {
103 */ 480 setUpCategory(
104 var prefsMixedProvider = { 481 settings.ContentSettingsTypes.GEOLOCATION,
105 exceptions: { 482 settings.PermissionValues.ALLOW, prefsEmpty);
106 geolocation: [ 483 return browserProxy.whenCalled('getExceptionList')
107 { 484 .then(function(contentType) {
108 embeddingOrigin: 'https://[*.]foo.com', 485 assertEquals(settings.ContentSettingsTypes.GEOLOCATION, contentType);
109 origin: 'https://[*.]foo.com', 486 });
110 setting: 'block', 487 });
111 source: 'policy', 488
112 }, 489 test('Empty list', function() {
113 { 490 setUpCategory(
114 embeddingOrigin: 'https://bar.foo.com', 491 settings.ContentSettingsTypes.GEOLOCATION,
115 origin: 'https://bar.foo.com', 492 settings.PermissionValues.ALLOW, prefsEmpty);
116 setting: 'block', 493 return browserProxy.whenCalled('getExceptionList')
117 source: 'preference', 494 .then(function(contentType) {
118 }, 495 assertEquals(settings.ContentSettingsTypes.GEOLOCATION, contentType);
119 { 496
120 embeddingOrigin: 'https://[*.]foo.com', 497 assertEquals(0, testElement.sites.length);
121 origin: 'https://[*.]foo.com', 498
122 setting: 'block', 499 assertEquals(
123 source: 'preference', 500 settings.PermissionValues.ALLOW, testElement.categorySubtype);
124 }, 501
125 ] 502 assertFalse(testElement.$.category.hidden);
126 } 503 });
127 }; 504 });
128 505
129 /** 506 test('initial ALLOW state is correct', function() {
130 * An example pref with mixed origin and pattern. 507 setUpCategory(
131 * @type {SiteSettingsPref} 508 settings.ContentSettingsTypes.GEOLOCATION,
132 */ 509 settings.PermissionValues.ALLOW, prefs);
133 var prefsMixedOriginAndPattern = { 510 return browserProxy.whenCalled('getExceptionList')
134 exceptions: { 511 .then(function(contentType) {
135 auto_downloads: [], 512 assertEquals(settings.ContentSettingsTypes.GEOLOCATION, contentType);
136 background_sync: [], 513
137 camera: [], 514 assertEquals(2, testElement.sites.length);
138 cookies: [], 515 assertEquals(
139 geolocation: [ 516 prefs.exceptions.geolocation[0].origin,
140 { 517 testElement.sites[0].origin);
141 origin: 'https://foo.com', 518 assertEquals(
142 embeddingOrigin: '*', 519 prefs.exceptions.geolocation[1].origin,
143 setting: 'allow', 520 testElement.sites[1].origin);
144 source: 'preference', 521 assertEquals(
145 }, 522 settings.PermissionValues.ALLOW, testElement.categorySubtype);
146 ],
147 images: [],
148 javascript: [
149 {
150 origin: 'https://[*.]foo.com',
151 embeddingOrigin: '*',
152 setting: 'allow',
153 source: 'preference',
154 },
155 ],
156 mic: [],
157 notifications: [],
158 plugins: [],
159 midiDevices: [],
160 protectedContent: [],
161 popups: [],
162 subresource_filter: [],
163 unsandboxed_plugins: [],
164 }
165 };
166
167 /**
168 * An example pref with multiple categories and multiple allow/block
169 * state.
170 * @type {SiteSettingsPref}
171 */
172 var prefsVarious = {
173 exceptions: {
174 auto_downloads: [],
175 background_sync: [],
176 camera: [],
177 cookies: [],
178 geolocation: [
179 {
180 embeddingOrigin: 'https://foo.com',
181 incognito: false,
182 origin: 'https://foo.com',
183 setting: 'allow',
184 source: 'preference',
185 },
186 {
187 embeddingOrigin: 'https://bar.com',
188 incognito: false,
189 origin: 'https://bar.com',
190 setting: 'block',
191 source: 'preference',
192 },
193 ],
194 images: [],
195 javascript: [],
196 mic: [],
197 midiDevices: [],
198 notifications: [
199 {
200 embeddingOrigin: 'https://google.com',
201 incognito: false,
202 origin: 'https://google.com',
203 setting: 'block',
204 source: 'preference',
205 },
206 {
207 embeddingOrigin: 'https://bar.com',
208 incognito: false,
209 origin: 'https://bar.com',
210 setting: 'block',
211 source: 'preference',
212 },
213 {
214 embeddingOrigin: 'https://foo.com',
215 incognito: false,
216 origin: 'https://foo.com',
217 setting: 'block',
218 source: 'preference',
219 },
220 ],
221 plugins: [],
222 protectedContent: [],
223 popups: [],
224 subresource_filter: [],
225 unsandboxed_plugins: [],
226 }
227 };
228
229 /**
230 * An example pref with 1 allowed location item.
231 * @type {SiteSettingsPref}
232 */
233 var prefsOneEnabled = {
234 exceptions: {
235 geolocation: [
236 {
237 embeddingOrigin: 'https://foo-allow.com:443',
238 incognito: false,
239 origin: 'https://foo-allow.com:443',
240 setting: 'allow',
241 source: 'preference',
242 },
243 ]
244 }
245 };
246
247 /**
248 * An example pref with 1 blocked location item.
249 * @type {SiteSettingsPref}
250 */
251 var prefsOneDisabled = {
252 exceptions: {
253 geolocation: [
254 {
255 embeddingOrigin: 'https://foo-block.com:443',
256 incognito: false,
257 origin: 'https://foo-block.com:443',
258 setting: 'block',
259 source: 'preference',
260 },
261 ]
262 }
263 };
264
265 /**
266 * An example Cookies pref with 1 in each of the three categories.
267 * @type {SiteSettingsPref}
268 */
269 var prefsSessionOnly = {
270 exceptions: {
271 cookies: [
272 {
273 embeddingOrigin: 'http://foo-block.com',
274 incognito: false,
275 origin: 'http://foo-block.com',
276 setting: 'block',
277 source: 'preference',
278 },
279 {
280 embeddingOrigin: 'http://foo-allow.com',
281 incognito: false,
282 origin: 'http://foo-allow.com',
283 setting: 'allow',
284 source: 'preference',
285 },
286 {
287 embeddingOrigin: 'http://foo-session.com',
288 incognito: false,
289 origin: 'http://foo-session.com',
290 setting: 'session_only',
291 source: 'preference',
292 },
293 ]
294 }
295 };
296
297 /**
298 * An example Cookies pref with mixed incognito and regular settings.
299 * @type {SiteSettingsPref}
300 */
301 var prefsIncognito = {
302 exceptions: {
303 cookies: [
304 // foo.com is blocked for regular sessions.
305 {
306 embeddingOrigin: 'http://foo.com',
307 incognito: false,
308 origin: 'http://foo.com',
309 setting: 'block',
310 source: 'preference',
311 },
312 // bar.com is an allowed incognito item without an embedder.
313 {
314 embeddingOrigin: '',
315 incognito: true,
316 origin: 'http://bar.com',
317 setting: 'allow',
318 source: 'preference',
319 },
320 // foo.com is allowed in incognito (overridden).
321 {
322 embeddingOrigin: 'http://foo.com',
323 incognito: true,
324 origin: 'http://foo.com',
325 setting: 'allow',
326 source: 'preference',
327 },
328
329 ]
330 }
331 };
332
333 /**
334 * An example Javascript pref with a chrome-extension:// scheme.
335 * @type {SiteSettingsPref}
336 */
337 var prefsChromeExtension = {
338 exceptions: {
339 javascript: [
340 {
341 embeddingOrigin: '',
342 incognito: false,
343 origin: 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/',
344 setting: 'block',
345 source: 'preference',
346 },
347 ]
348 }
349 };
350
351 function registerTests() {
352 suite('SiteList', function() {
353 /**
354 * A site list element created before each test.
355 * @type {SiteList}
356 */
357 var testElement;
358
359 /**
360 * The mock proxy object to use during test.
361 * @type {TestSiteSettingsPrefsBrowserProxy}
362 */
363 var browserProxy = null;
364
365
366 suiteSetup(function() {
367 CrSettingsPrefs.setInitialized();
368 });
369
370 suiteTeardown(function() {
371 CrSettingsPrefs.resetForTesting();
372 });
373
374 // Initialize a site-list before each test.
375 setup(function() {
376 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
377 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
378 PolymerTest.clearBody();
379 testElement = document.createElement('site-list');
380 document.body.appendChild(testElement);
381 });
382
383 teardown(function() {
384 closeActionMenu();
385 // The code being tested changes the Route. Reset so that state is not
386 // leaked across tests.
387 settings.resetRouteForTesting();
388 });
389
390 /**
391 * Opens the action menu for a particular element in the list.
392 * @param {number} index The index of the child element (which site) to
393 * open the action menu for.
394 */
395 function openActionMenu(index) {
396 var item = testElement.$.listContainer.children[index];
397 var dots = item.querySelector('#actionMenuButton');
398 MockInteractions.tap(dots);
399 Polymer.dom.flush();
400 }
401
402 /** Closes the action menu. */
403 function closeActionMenu() {
404 var menu = testElement.$$('dialog[is=cr-action-menu]');
405 if (menu.open)
406 menu.close();
407 }
408
409 /**
410 * Asserts the menu looks as expected.
411 * @param {Array<string>} items The items expected to show in the menu.
412 */
413 function assertMenu(items) {
414 var menu = testElement.$$('dialog[is=cr-action-menu]');
415 assertTrue(!!menu);
416 var menuItems = menu.querySelectorAll('button:not([hidden])');
417 assertEquals(items.length, menuItems.length);
418 for (var i = 0; i < items.length; i++)
419 assertEquals(items[i], menuItems[i].textContent.trim());
420 }
421
422 /**
423 * @param {HTMLElement} listContainer Node with the exceptions listed.
424 * @return {boolean} Whether the entry is incognito only.
425 */
426 function hasAnIncognito(listContainer) {
427 var descriptions = listContainer.querySelectorAll('#siteDescription');
428 for (var i = 0; i < descriptions.length; ++i) {
429 if (descriptions[i].textContent == 'Current incognito session')
430 return true;
431 }
432 return false;
433 }
434
435 /**
436 * Configures the test element for a particular category.
437 * @param {settings.ContentSettingsTypes} category The category to set up.
438 * @param {settings.PermissionValues} subtype Type of list to use.
439 * @param {Array<dictionary>} prefs The prefs to use.
440 */
441 function setUpCategory(category, subtype, prefs) {
442 browserProxy.setPrefs(prefs);
443 if (category == settings.ALL_SITES) {
444 testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE;
445 testElement.allSites = true;
446 } else {
447 testElement.categorySubtype = subtype;
448 testElement.allSites = false;
449 }
450 // Some route is needed, but the actual route doesn't matter.
451 testElement.currentRoute = {
452 page: 'dummy',
453 section: 'privacy',
454 subpage: ['site-settings', 'site-settings-category-location'],
455 };
456 testElement.category = category;
457 }
458
459 test('read-only attribute', function() {
460 setUpCategory(
461 settings.ContentSettingsTypes.GEOLOCATION,
462 settings.PermissionValues.ALLOW, prefsVarious);
463 return browserProxy.whenCalled('getExceptionList')
464 .then(function(contentType) {
465 // Flush to be sure list container is populated.
466 Polymer.dom.flush();
467 var dotsMenu = testElement.$.listContainer.querySelector(
468 '#actionMenuButton');
469 assertFalse(dotsMenu.hidden);
470 testElement.setAttribute('read-only-list', true);
471 Polymer.dom.flush();
472 assertTrue(dotsMenu.hidden);
473 testElement.removeAttribute('read-only-list');
474 Polymer.dom.flush();
475 assertFalse(dotsMenu.hidden);
476 });
477 });
478
479 test('getExceptionList API used', function() {
480 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION,
481 settings.PermissionValues.ALLOW, prefsEmpty);
482 return browserProxy.whenCalled('getExceptionList').then(
483 function(contentType) {
484 assertEquals(
485 settings.ContentSettingsTypes.GEOLOCATION, contentType);
486 });
487 });
488
489 test('Empty list', function() {
490 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION,
491 settings.PermissionValues.ALLOW, prefsEmpty);
492 return browserProxy.whenCalled('getExceptionList').then(
493 function(contentType) {
494 assertEquals(
495 settings.ContentSettingsTypes.GEOLOCATION, contentType);
496
497 assertEquals(0, testElement.sites.length);
498
499 assertEquals(
500 settings.PermissionValues.ALLOW, testElement.categorySubtype);
501
502 assertFalse(testElement.$.category.hidden);
503 });
504 });
505
506 test('initial ALLOW state is correct', function() {
507 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION,
508 settings.PermissionValues.ALLOW, prefs);
509 return browserProxy.whenCalled('getExceptionList').then(
510 function(contentType) {
511 assertEquals(
512 settings.ContentSettingsTypes.GEOLOCATION, contentType);
513
514 assertEquals(2, testElement.sites.length);
515 assertEquals(prefs.exceptions.geolocation[0].origin,
516 testElement.sites[0].origin);
517 assertEquals(prefs.exceptions.geolocation[1].origin,
518 testElement.sites[1].origin);
519 assertEquals(
520 settings.PermissionValues.ALLOW, testElement.categorySubtype);
521 Polymer.dom.flush(); // Populates action menu.
522 openActionMenu(0);
523 assertMenu(['Block', 'Edit', 'Remove'], testElement);
524
525 assertFalse(testElement.$.category.hidden);
526 });
527 });
528
529 test('action menu closes when list changes', function() {
530 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION,
531 settings.PermissionValues.ALLOW, prefs);
532 var actionMenu = testElement.$$('dialog[is=cr-action-menu]');
533 return browserProxy.whenCalled('getExceptionList').then(
534 function(contentType) {
535 Polymer.dom.flush(); // Populates action menu.
536 openActionMenu(0);
537 assertTrue(actionMenu.open);
538
539 browserProxy.resetResolver('getExceptionList');
540 // Simulate a change in the underlying model.
541 cr.webUIListenerCallback(
542 'contentSettingSitePermissionChanged',
543 settings.ContentSettingsTypes.GEOLOCATION);
544 return browserProxy.whenCalled('getExceptionList');
545 }).then(function() {
546 // Check that the action menu was closed.
547 assertFalse(actionMenu.open);
548 });
549 });
550
551 test('exceptions are not reordered in non-ALL_SITES', function() {
552 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION,
553 settings.PermissionValues.BLOCK, prefsMixedProvider);
554 return browserProxy.whenCalled('getExceptionList')
555 .then(function(contentType) {
556 assertEquals(
557 settings.ContentSettingsTypes.GEOLOCATION, contentType);
558
559 assertEquals(3, testElement.sites.length);
560 for(var i = 0; i < 3; i++) {
561 assertEquals(
562 prefsMixedProvider.exceptions.geolocation[0].origin,
563 testElement.sites[0].origin);
564 assertEquals(
565 kControlledByLookup
566 [prefsMixedProvider.exceptions.geolocation[0].source],
567 testElement.sites[0].controlledBy);
568 }
569 });
570 });
571
572 test('initial BLOCK state is correct', function() {
573 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
574 var categorySubtype = settings.PermissionValues.BLOCK;
575 setUpCategory(contentType, categorySubtype, prefs);
576 return browserProxy.whenCalled('getExceptionList').then(
577 function(actualContentType) {
578 assertEquals(contentType, actualContentType);
579 assertEquals(categorySubtype, testElement.categorySubtype);
580
581 assertEquals(2, testElement.sites.length);
582 assertEquals(
583 prefs.exceptions.geolocation[2].origin,
584 testElement.sites[0].origin);
585 assertEquals(
586 prefs.exceptions.geolocation[3].origin,
587 testElement.sites[1].origin);
588 Polymer.dom.flush(); // Populates action menu.
589 openActionMenu(0);
590 assertMenu(['Allow', 'Edit', 'Remove'], testElement);
591
592 assertFalse(testElement.$.category.hidden);
593 });
594 });
595
596 test('initial SESSION ONLY state is correct', function() {
597 var contentType = settings.ContentSettingsTypes.COOKIES;
598 var categorySubtype = settings.PermissionValues.SESSION_ONLY;
599 setUpCategory(contentType, categorySubtype, prefsSessionOnly);
600 return browserProxy.whenCalled('getExceptionList').then(
601 function(actualContentType) {
602 assertEquals(contentType, actualContentType);
603 assertEquals(categorySubtype, testElement.categorySubtype);
604
605 assertEquals(1, testElement.sites.length);
606 assertEquals(
607 prefsSessionOnly.exceptions.cookies[2].origin,
608 testElement.sites[0].origin);
609
610 Polymer.dom.flush(); // Populates action menu.
611 openActionMenu(0);
612 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement);
613
614 assertFalse(testElement.$.category.hidden);
615 });
616 });
617
618 test('update lists for incognito', function() {
619 var contentType = settings.ContentSettingsTypes.PLUGINS;
620 var categorySubtype = settings.PermissionValues.BLOCK;
621 setUpCategory(contentType, categorySubtype, prefsControlled);
622 var list = testElement.$.listContainer;
623 return browserProxy.whenCalled('getExceptionList')
624 .then(function(actualContentType) {
625 Polymer.dom.flush();
626 assertEquals(1, list.querySelectorAll('.list-item').length);
627 assertFalse(hasAnIncognito(list));
628 browserProxy.resetResolver('getExceptionList');
629 browserProxy.setIncognito(true);
630 return browserProxy.whenCalled('getExceptionList');
631 })
632 .then(function() {
633 Polymer.dom.flush();
634 assertEquals(2, list.querySelectorAll('.list-item').length);
635 assertTrue(hasAnIncognito(list));
636 browserProxy.resetResolver('getExceptionList');
637 browserProxy.setIncognito(false);
638 return browserProxy.whenCalled('getExceptionList');
639 })
640 .then(function() {
641 Polymer.dom.flush();
642 assertEquals(1, list.querySelectorAll('.list-item').length);
643 assertFalse(hasAnIncognito(list));
644 browserProxy.resetResolver('getExceptionList');
645 browserProxy.setIncognito(true);
646 return browserProxy.whenCalled('getExceptionList');
647 })
648 .then(function() {
649 Polymer.dom.flush();
650 assertEquals(2, list.querySelectorAll('.list-item').length);
651 assertTrue(hasAnIncognito(list));
652 });
653 });
654
655 test('initial INCOGNITO BLOCK state is correct', function() {
656 var contentType = settings.ContentSettingsTypes.COOKIES;
657 var categorySubtype = settings.PermissionValues.BLOCK;
658 setUpCategory(contentType, categorySubtype, prefsIncognito);
659 return browserProxy.whenCalled('getExceptionList').then(
660 function(actualContentType) {
661 assertEquals(contentType, actualContentType);
662 assertEquals(categorySubtype, testElement.categorySubtype);
663
664 assertEquals(1, testElement.sites.length);
665 assertEquals(
666 prefsIncognito.exceptions.cookies[0].origin,
667 testElement.sites[0].origin);
668
669 Polymer.dom.flush(); // Populates action menu.
670 openActionMenu(0);
671 // 'Clear on exit' is visible as this is not an incognito item.
672 assertMenu(
673 ['Allow', 'Clear on exit', 'Edit', 'Remove'], testElement);
674
675 // Select 'Remove' from menu.
676 var remove = testElement.$.reset;
677 assertTrue(!!remove);
678 MockInteractions.tap(remove);
679 return browserProxy.whenCalled(
680 'resetCategoryPermissionForOrigin');
681 }).then(function(args) {
682 assertEquals('http://foo.com', args[0]);
683 assertEquals('http://foo.com', args[1]);
684 assertEquals(contentType, args[2]);
685 assertFalse(args[3]); // Incognito.
686 });
687 });
688
689 test('initial INCOGNITO ALLOW state is correct', function() {
690 var contentType = settings.ContentSettingsTypes.COOKIES;
691 var categorySubtype = settings.PermissionValues.ALLOW;
692 setUpCategory(contentType, categorySubtype, prefsIncognito);
693 return browserProxy.whenCalled('getExceptionList').then(
694 function(actualContentType) {
695 assertEquals(contentType, actualContentType);
696 assertEquals(categorySubtype, testElement.categorySubtype);
697
698 assertEquals(2, testElement.sites.length);
699 assertEquals(
700 prefsIncognito.exceptions.cookies[1].origin,
701 testElement.sites[0].origin);
702 assertEquals(
703 prefsIncognito.exceptions.cookies[2].origin,
704 testElement.sites[1].origin);
705
706 Polymer.dom.flush(); // Populates action menu.
707 openActionMenu(0);
708 // 'Clear on exit' is hidden for incognito items.
709 assertMenu(['Block', 'Edit', 'Remove'], testElement);
710 closeActionMenu();
711
712 // Select 'Remove' from menu on 'foo.com'.
713 openActionMenu(1);
714 var remove = testElement.$.reset;
715 assertTrue(!!remove);
716 MockInteractions.tap(remove);
717 return browserProxy.whenCalled(
718 'resetCategoryPermissionForOrigin');
719 }).then(function(args) {
720 assertEquals('http://foo.com', args[0]);
721 assertEquals('http://foo.com', args[1]);
722 assertEquals(contentType, args[2]);
723 assertTrue(args[3]); // Incognito.
724 });
725 });
726
727 test('reset button works for read-only content types', function() {
728 testElement.readOnlyList = true;
729 Polymer.dom.flush();
730
731 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
732 var categorySubtype = settings.PermissionValues.ALLOW;
733 setUpCategory(contentType, categorySubtype, prefsOneEnabled);
734 return browserProxy.whenCalled('getExceptionList')
735 .then(function(actualContentType) {
736 assertEquals(contentType, actualContentType);
737 assertEquals(categorySubtype, testElement.categorySubtype);
738
739 assertEquals(1, testElement.sites.length);
740 assertEquals(
741 prefsOneEnabled.exceptions.geolocation[0].origin,
742 testElement.sites[0].origin);
743
744 Polymer.dom.flush();
745
746 var item = testElement.$.listContainer.children[0];
747
748 // Assert action button is hidden.
749 var dots = item.querySelector('#actionMenuButton');
750 assertTrue(!!dots);
751 assertTrue(dots.hidden);
752
753 // Assert reset button is visible.
754 var resetButton = item.querySelector('#resetSite');
755 assertTrue(!!resetButton);
756 assertFalse(resetButton.hidden);
757
758 MockInteractions.tap(resetButton);
759 return browserProxy.whenCalled(
760 'resetCategoryPermissionForOrigin');
761 })
762 .then(function(args) {
763 assertEquals('https://foo-allow.com:443', args[0]);
764 assertEquals('https://foo-allow.com:443', args[1]);
765 assertEquals(contentType, args[2]);
766 });
767 });
768
769 test('edit action menu opens edit exception dialog', function() {
770 setUpCategory(
771 settings.ContentSettingsTypes.COOKIES,
772 settings.PermissionValues.SESSION_ONLY,
773 prefsSessionOnly);
774
775 return browserProxy.whenCalled('getExceptionList').then(function() {
776 Polymer.dom.flush(); // Populates action menu. 523 Polymer.dom.flush(); // Populates action menu.
777 524 openActionMenu(0);
525 assertMenu(['Block', 'Edit', 'Remove'], testElement);
526
527 assertFalse(testElement.$.category.hidden);
528 });
529 });
530
531 test('action menu closes when list changes', function() {
532 setUpCategory(
533 settings.ContentSettingsTypes.GEOLOCATION,
534 settings.PermissionValues.ALLOW, prefs);
535 var actionMenu = testElement.$$('dialog[is=cr-action-menu]');
536 return browserProxy.whenCalled('getExceptionList')
537 .then(function(contentType) {
538 Polymer.dom.flush(); // Populates action menu.
539 openActionMenu(0);
540 assertTrue(actionMenu.open);
541
542 browserProxy.resetResolver('getExceptionList');
543 // Simulate a change in the underlying model.
544 cr.webUIListenerCallback(
545 'contentSettingSitePermissionChanged',
546 settings.ContentSettingsTypes.GEOLOCATION);
547 return browserProxy.whenCalled('getExceptionList');
548 })
549 .then(function() {
550 // Check that the action menu was closed.
551 assertFalse(actionMenu.open);
552 });
553 });
554
555 test('exceptions are not reordered in non-ALL_SITES', function() {
556 setUpCategory(
557 settings.ContentSettingsTypes.GEOLOCATION,
558 settings.PermissionValues.BLOCK, prefsMixedProvider);
559 return browserProxy.whenCalled('getExceptionList')
560 .then(function(contentType) {
561 assertEquals(settings.ContentSettingsTypes.GEOLOCATION, contentType);
562
563 assertEquals(3, testElement.sites.length);
564 for (var i = 0; i < 3; i++) {
565 assertEquals(
566 prefsMixedProvider.exceptions.geolocation[0].origin,
567 testElement.sites[0].origin);
568 assertEquals(
569 kControlledByLookup[prefsMixedProvider.exceptions.geolocation[0]
570 .source],
571 testElement.sites[0].controlledBy);
572 }
573 });
574 });
575
576 test('initial BLOCK state is correct', function() {
577 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
578 var categorySubtype = settings.PermissionValues.BLOCK;
579 setUpCategory(contentType, categorySubtype, prefs);
580 return browserProxy.whenCalled('getExceptionList')
581 .then(function(actualContentType) {
582 assertEquals(contentType, actualContentType);
583 assertEquals(categorySubtype, testElement.categorySubtype);
584
585 assertEquals(2, testElement.sites.length);
586 assertEquals(
587 prefs.exceptions.geolocation[2].origin,
588 testElement.sites[0].origin);
589 assertEquals(
590 prefs.exceptions.geolocation[3].origin,
591 testElement.sites[1].origin);
592 Polymer.dom.flush(); // Populates action menu.
593 openActionMenu(0);
594 assertMenu(['Allow', 'Edit', 'Remove'], testElement);
595
596 assertFalse(testElement.$.category.hidden);
597 });
598 });
599
600 test('initial SESSION ONLY state is correct', function() {
601 var contentType = settings.ContentSettingsTypes.COOKIES;
602 var categorySubtype = settings.PermissionValues.SESSION_ONLY;
603 setUpCategory(contentType, categorySubtype, prefsSessionOnly);
604 return browserProxy.whenCalled('getExceptionList')
605 .then(function(actualContentType) {
606 assertEquals(contentType, actualContentType);
607 assertEquals(categorySubtype, testElement.categorySubtype);
608
609 assertEquals(1, testElement.sites.length);
610 assertEquals(
611 prefsSessionOnly.exceptions.cookies[2].origin,
612 testElement.sites[0].origin);
613
614 Polymer.dom.flush(); // Populates action menu.
778 openActionMenu(0); 615 openActionMenu(0);
779 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement); 616 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement);
780 var menu = testElement.$$('dialog[is=cr-action-menu]'); 617
781 assertTrue(menu.open); 618 assertFalse(testElement.$.category.hidden);
782 var edit = testElement.$.edit; 619 });
783 assertTrue(!!edit); 620 });
784 MockInteractions.tap(edit); 621
622 test('update lists for incognito', function() {
623 var contentType = settings.ContentSettingsTypes.PLUGINS;
624 var categorySubtype = settings.PermissionValues.BLOCK;
625 setUpCategory(contentType, categorySubtype, prefsControlled);
626 var list = testElement.$.listContainer;
627 return browserProxy.whenCalled('getExceptionList')
628 .then(function(actualContentType) {
785 Polymer.dom.flush(); 629 Polymer.dom.flush();
786 assertFalse(menu.open); 630 assertEquals(1, list.querySelectorAll('.list-item').length);
787 631 assertFalse(hasAnIncognito(list));
788 assertTrue(!!testElement.$$('settings-edit-exception-dialog')); 632 browserProxy.resetResolver('getExceptionList');
789 }); 633 browserProxy.setIncognito(true);
790 }); 634 return browserProxy.whenCalled('getExceptionList');
791 635 })
792 test('list items shown and clickable when data is present', function() { 636 .then(function() {
793 var contentType = settings.ContentSettingsTypes.GEOLOCATION; 637 Polymer.dom.flush();
794 setUpCategory(contentType, settings.PermissionValues.ALLOW, prefs); 638 assertEquals(2, list.querySelectorAll('.list-item').length);
795 return browserProxy.whenCalled('getExceptionList').then( 639 assertTrue(hasAnIncognito(list));
796 function(actualContentType) { 640 browserProxy.resetResolver('getExceptionList');
797 assertEquals(contentType, actualContentType); 641 browserProxy.setIncognito(false);
798 642 return browserProxy.whenCalled('getExceptionList');
799 // Required for firstItem to be found below. 643 })
800 Polymer.dom.flush(); 644 .then(function() {
801 645 Polymer.dom.flush();
802 // Validate that the sites gets populated from pre-canned prefs. 646 assertEquals(1, list.querySelectorAll('.list-item').length);
803 assertEquals(2, testElement.sites.length); 647 assertFalse(hasAnIncognito(list));
648 browserProxy.resetResolver('getExceptionList');
649 browserProxy.setIncognito(true);
650 return browserProxy.whenCalled('getExceptionList');
651 })
652 .then(function() {
653 Polymer.dom.flush();
654 assertEquals(2, list.querySelectorAll('.list-item').length);
655 assertTrue(hasAnIncognito(list));
656 });
657 });
658
659 test('initial INCOGNITO BLOCK state is correct', function() {
660 var contentType = settings.ContentSettingsTypes.COOKIES;
661 var categorySubtype = settings.PermissionValues.BLOCK;
662 setUpCategory(contentType, categorySubtype, prefsIncognito);
663 return browserProxy.whenCalled('getExceptionList')
664 .then(function(actualContentType) {
665 assertEquals(contentType, actualContentType);
666 assertEquals(categorySubtype, testElement.categorySubtype);
667
668 assertEquals(1, testElement.sites.length);
669 assertEquals(
670 prefsIncognito.exceptions.cookies[0].origin,
671 testElement.sites[0].origin);
672
673 Polymer.dom.flush(); // Populates action menu.
674 openActionMenu(0);
675 // 'Clear on exit' is visible as this is not an incognito item.
676 assertMenu(['Allow', 'Clear on exit', 'Edit', 'Remove'], testElement);
677
678 // Select 'Remove' from menu.
679 var remove = testElement.$.reset;
680 assertTrue(!!remove);
681 MockInteractions.tap(remove);
682 return browserProxy.whenCalled('resetCategoryPermissionForOrigin');
683 })
684 .then(function(args) {
685 assertEquals('http://foo.com', args[0]);
686 assertEquals('http://foo.com', args[1]);
687 assertEquals(contentType, args[2]);
688 assertFalse(args[3]); // Incognito.
689 });
690 });
691
692 test('initial INCOGNITO ALLOW state is correct', function() {
693 var contentType = settings.ContentSettingsTypes.COOKIES;
694 var categorySubtype = settings.PermissionValues.ALLOW;
695 setUpCategory(contentType, categorySubtype, prefsIncognito);
696 return browserProxy.whenCalled('getExceptionList')
697 .then(function(actualContentType) {
698 assertEquals(contentType, actualContentType);
699 assertEquals(categorySubtype, testElement.categorySubtype);
700
701 assertEquals(2, testElement.sites.length);
702 assertEquals(
703 prefsIncognito.exceptions.cookies[1].origin,
704 testElement.sites[0].origin);
705 assertEquals(
706 prefsIncognito.exceptions.cookies[2].origin,
707 testElement.sites[1].origin);
708
709 Polymer.dom.flush(); // Populates action menu.
710 openActionMenu(0);
711 // 'Clear on exit' is hidden for incognito items.
712 assertMenu(['Block', 'Edit', 'Remove'], testElement);
713 closeActionMenu();
714
715 // Select 'Remove' from menu on 'foo.com'.
716 openActionMenu(1);
717 var remove = testElement.$.reset;
718 assertTrue(!!remove);
719 MockInteractions.tap(remove);
720 return browserProxy.whenCalled('resetCategoryPermissionForOrigin');
721 })
722 .then(function(args) {
723 assertEquals('http://foo.com', args[0]);
724 assertEquals('http://foo.com', args[1]);
725 assertEquals(contentType, args[2]);
726 assertTrue(args[3]); // Incognito.
727 });
728 });
729
730 test('reset button works for read-only content types', function() {
731 testElement.readOnlyList = true;
732 Polymer.dom.flush();
733
734 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
735 var categorySubtype = settings.PermissionValues.ALLOW;
736 setUpCategory(contentType, categorySubtype, prefsOneEnabled);
737 return browserProxy.whenCalled('getExceptionList')
738 .then(function(actualContentType) {
739 assertEquals(contentType, actualContentType);
740 assertEquals(categorySubtype, testElement.categorySubtype);
741
742 assertEquals(1, testElement.sites.length);
743 assertEquals(
744 prefsOneEnabled.exceptions.geolocation[0].origin,
745 testElement.sites[0].origin);
746
747 Polymer.dom.flush();
748
749 var item = testElement.$.listContainer.children[0];
750
751 // Assert action button is hidden.
752 var dots = item.querySelector('#actionMenuButton');
753 assertTrue(!!dots);
754 assertTrue(dots.hidden);
755
756 // Assert reset button is visible.
757 var resetButton = item.querySelector('#resetSite');
758 assertTrue(!!resetButton);
759 assertFalse(resetButton.hidden);
760
761 MockInteractions.tap(resetButton);
762 return browserProxy.whenCalled('resetCategoryPermissionForOrigin');
763 })
764 .then(function(args) {
765 assertEquals('https://foo-allow.com:443', args[0]);
766 assertEquals('https://foo-allow.com:443', args[1]);
767 assertEquals(contentType, args[2]);
768 });
769 });
770
771 test('edit action menu opens edit exception dialog', function() {
772 setUpCategory(
773 settings.ContentSettingsTypes.COOKIES,
774 settings.PermissionValues.SESSION_ONLY, prefsSessionOnly);
775
776 return browserProxy.whenCalled('getExceptionList').then(function() {
777 Polymer.dom.flush(); // Populates action menu.
778
779 openActionMenu(0);
780 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement);
781 var menu = testElement.$$('dialog[is=cr-action-menu]');
782 assertTrue(menu.open);
783 var edit = testElement.$.edit;
784 assertTrue(!!edit);
785 MockInteractions.tap(edit);
786 Polymer.dom.flush();
787 assertFalse(menu.open);
788
789 assertTrue(!!testElement.$$('settings-edit-exception-dialog'));
790 });
791 });
792
793 test('list items shown and clickable when data is present', function() {
794 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
795 setUpCategory(contentType, settings.PermissionValues.ALLOW, prefs);
796 return browserProxy.whenCalled('getExceptionList')
797 .then(function(actualContentType) {
798 assertEquals(contentType, actualContentType);
799
800 // Required for firstItem to be found below.
801 Polymer.dom.flush();
802
803 // Validate that the sites gets populated from pre-canned prefs.
804 assertEquals(2, testElement.sites.length);
805 assertEquals(
806 prefs.exceptions.geolocation[0].origin,
807 testElement.sites[0].origin);
808 assertEquals(
809 prefs.exceptions.geolocation[1].origin,
810 testElement.sites[1].origin);
811 assertFalse(!!testElement.selectedOrigin);
812
813 // Validate that the sites are shown in UI and can be selected.
814 var firstItem = testElement.$.listContainer.children[0];
815 var clickable = firstItem.querySelector('.middle');
816 assertTrue(!!clickable);
817 MockInteractions.tap(clickable);
818 assertEquals(
819 prefs.exceptions.geolocation[0].origin,
820 settings.getQueryParameters().get('site'));
821 });
822 });
823
824 test('Block list open when Allow list is empty', function() {
825 // Prefs: One item in Block list, nothing in Allow list.
826 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
827 setUpCategory(
828 contentType, settings.PermissionValues.BLOCK, prefsOneDisabled);
829 return browserProxy.whenCalled('getExceptionList')
830 .then(function(actualContentType) {
831 assertEquals(contentType, actualContentType);
832 assertFalse(testElement.$.category.hidden);
833 })
834 .then(function() {
835 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
836 });
837 });
838
839 test('Block list closed when Allow list is not empty', function() {
840 // Prefs: Items in both Block and Allow list.
841 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
842 setUpCategory(contentType, settings.PermissionValues.BLOCK, prefs);
843 return browserProxy.whenCalled('getExceptionList')
844 .then(function(actualContentType) {
845 assertEquals(contentType, actualContentType);
846 assertFalse(testElement.$.category.hidden);
847 assertEquals(0, testElement.$.listContainer.offsetHeight);
848 });
849 });
850
851 test('Allow list is always open (Block list empty)', function() {
852 // Prefs: One item in Allow list, nothing in Block list.
853 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
854 setUpCategory(
855 contentType, settings.PermissionValues.ALLOW, prefsOneEnabled);
856 return browserProxy.whenCalled('getExceptionList')
857 .then(function(actualContentType) {
858 assertEquals(contentType, actualContentType);
859 assertFalse(testElement.$.category.hidden);
860 })
861 .then(function() {
862 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
863 });
864 });
865
866 test('Allow list is always open (Block list non-empty)', function() {
867 // Prefs: Items in both Block and Allow list.
868 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
869 setUpCategory(contentType, settings.PermissionValues.ALLOW, prefs);
870 return browserProxy.whenCalled('getExceptionList')
871 .then(function(actualContentType) {
872 assertEquals(contentType, actualContentType);
873 assertFalse(testElement.$.category.hidden);
874 })
875 .then(function() {
876 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
877 });
878 });
879
880 test('Block list not hidden when empty', function() {
881 // Prefs: One item in Allow list, nothing in Block list.
882 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
883 setUpCategory(
884 contentType, settings.PermissionValues.BLOCK, prefsOneEnabled);
885 return browserProxy.whenCalled('getExceptionList')
886 .then(function(actualContentType) {
887 assertEquals(contentType, actualContentType);
888 assertFalse(testElement.$.category.hidden);
889 });
890 });
891
892 test('Allow list not hidden when empty', function() {
893 // Prefs: One item in Block list, nothing in Allow list.
894 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
895 setUpCategory(
896 contentType, settings.PermissionValues.ALLOW, prefsOneDisabled);
897 return browserProxy.whenCalled('getExceptionList')
898 .then(function(actualContentType) {
899 assertEquals(contentType, actualContentType);
900 assertFalse(testElement.$.category.hidden);
901 });
902 });
903
904 test('All sites category no action menu', function() {
905 setUpCategory(settings.ALL_SITES, '', prefsVarious);
906 return browserProxy.whenCalled('getExceptionList')
907 .then(function(contentType) {
908 // Use resolver to ensure that the list container is populated.
909 var resolver = new PromiseResolver();
910 testElement.async(resolver.resolve);
911 return resolver.promise.then(function() {
912 var item = testElement.$.listContainer.children[0];
913 var dots = item.querySelector('#actionMenuButton');
914 assertTrue(!!dots);
915 assertTrue(dots.hidden);
916 });
917 });
918 });
919
920 test('All sites category', function() {
921 // Prefs: Multiple and overlapping sites.
922 setUpCategory(settings.ALL_SITES, '', prefsVarious);
923
924 return browserProxy.whenCalled('getExceptionList')
925 .then(function(contentType) {
926 // Use resolver to ensure asserts bubble up to the framework with
927 // meaningful errors.
928 var resolver = new PromiseResolver();
929 testElement.async(resolver.resolve);
930 return resolver.promise.then(function() {
931 // All Sites calls getExceptionList for all categories, starting
932 // with Cookies.
933 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType);
934
935 // Required for firstItem to be found below.
936 Polymer.dom.flush();
937
938 assertFalse(testElement.$.category.hidden);
939 // Validate that the sites gets populated from pre-canned prefs.
940 assertEquals(
941 3, testElement.sites.length,
942 'If this fails with 5 instead of the expected 3, then ' +
943 'the de-duping of sites is not working for site_list');
944 assertEquals(
945 prefsVarious.exceptions.geolocation[1].origin,
946 testElement.sites[0].origin);
947 assertEquals(
948 prefsVarious.exceptions.geolocation[0].origin,
949 testElement.sites[1].origin);
950 assertEquals(
951 prefsVarious.exceptions.notifications[0].origin,
952 testElement.sites[2].origin);
953 assertEquals(undefined, testElement.selectedOrigin);
954
955 // Validate that the sites are shown in UI and can be selected.
956 var firstItem = testElement.$.listContainer.children[1];
957 var clickable = firstItem.querySelector('.middle');
958 assertNotEquals(undefined, clickable);
959 MockInteractions.tap(clickable);
960 assertEquals(
961 prefsVarious.exceptions.geolocation[0].origin,
962 settings.getQueryParameters().get('site'));
963 });
964 });
965 });
966
967 test('All sites mixed pattern and origin', function() {
968 // Prefs: One site, represented as origin and pattern.
969 setUpCategory(settings.ALL_SITES, '', prefsMixedOriginAndPattern);
970
971 return browserProxy.whenCalled('getExceptionList')
972 .then(function(contentType) {
973 // Use resolver to ensure asserts bubble up to the framework with
974 // meaningful errors.
975 var resolver = new PromiseResolver();
976 testElement.async(resolver.resolve);
977 return resolver.promise.then(function() {
978 // All Sites calls getExceptionList for all categories, starting
979 // with Cookies.
980 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType);
981
982 // Required for firstItem to be found below.
983 Polymer.dom.flush();
984
985 assertFalse(testElement.$.category.hidden);
986 // Validate that the sites gets populated from pre-canned prefs.
987 // TODO(dschuyler): de-duping of sites is under discussion, so
988 // it is currently disabled. It should be enabled again or this
989 // code should be removed.
990 assertEquals(
991 2, testElement.sites.length,
992 'If this fails with 1 instead of the expected 2, then ' +
993 'the de-duping of sites has been enabled for site_list.');
994 if (testElement.sites.length == 1) {
804 assertEquals( 995 assertEquals(
805 prefs.exceptions.geolocation[0].origin, 996 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
806 testElement.sites[0].origin); 997 testElement.sites[0].displayName);
998 }
999
1000 assertEquals(undefined, testElement.selectedOrigin);
1001 // Validate that the sites are shown in UI and can be selected.
1002 var firstItem = testElement.$.listContainer.children[0];
1003 var clickable = firstItem.querySelector('.middle');
1004 assertNotEquals(undefined, clickable);
1005 MockInteractions.tap(clickable);
1006 if (testElement.sites.length == 1) {
807 assertEquals( 1007 assertEquals(
808 prefs.exceptions.geolocation[1].origin, 1008 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
809 testElement.sites[1].origin); 1009 testElement.sites[0].displayName);
810 assertFalse(!!testElement.selectedOrigin); 1010 }
811 1011 });
812 // Validate that the sites are shown in UI and can be selected. 1012 });
813 var firstItem = testElement.$.listContainer.children[0]; 1013 });
814 var clickable = firstItem.querySelector('.middle'); 1014
815 assertTrue(!!clickable); 1015 test('Mixed schemes (present and absent)', function() {
816 MockInteractions.tap(clickable); 1016 // Prefs: One item with scheme and one without.
817 assertEquals( 1017 setUpCategory(
818 prefs.exceptions.geolocation[0].origin, 1018 settings.ContentSettingsTypes.GEOLOCATION,
819 settings.getQueryParameters().get('site')); 1019 settings.PermissionValues.ALLOW, prefsMixedSchemes);
820 }); 1020 return browserProxy.whenCalled('getExceptionList')
821 }); 1021 .then(function(contentType) {
822 1022 // No further checks needed. If this fails, it will hang the test.
823 test('Block list open when Allow list is empty', function() { 1023 });
824 // Prefs: One item in Block list, nothing in Allow list. 1024 });
825 var contentType = settings.ContentSettingsTypes.GEOLOCATION; 1025
826 setUpCategory( 1026 test('Select menu item', function() {
827 contentType, settings.PermissionValues.BLOCK, prefsOneDisabled); 1027 // Test for error: "Cannot read property 'origin' of undefined".
828 return browserProxy.whenCalled('getExceptionList').then( 1028 setUpCategory(
829 function(actualContentType) { 1029 settings.ContentSettingsTypes.GEOLOCATION,
830 assertEquals(contentType, actualContentType); 1030 settings.PermissionValues.ALLOW, prefs);
831 assertFalse(testElement.$.category.hidden); 1031 return browserProxy.whenCalled('getExceptionList')
832 }).then(function() { 1032 .then(function(contentType) {
833 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
834 });
835 });
836
837 test('Block list closed when Allow list is not empty', function() {
838 // Prefs: Items in both Block and Allow list.
839 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
840 setUpCategory(contentType, settings.PermissionValues.BLOCK, prefs);
841 return browserProxy.whenCalled('getExceptionList').then(
842 function(actualContentType) {
843 assertEquals(contentType, actualContentType);
844 assertFalse(testElement.$.category.hidden);
845 assertEquals(0, testElement.$.listContainer.offsetHeight);
846 });
847 });
848
849 test('Allow list is always open (Block list empty)', function() {
850 // Prefs: One item in Allow list, nothing in Block list.
851 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
852 setUpCategory(
853 contentType, settings.PermissionValues.ALLOW, prefsOneEnabled);
854 return browserProxy.whenCalled('getExceptionList').then(
855 function(actualContentType) {
856 assertEquals(contentType, actualContentType);
857 assertFalse(testElement.$.category.hidden);
858 }).then(function() {
859 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
860 });
861 });
862
863 test('Allow list is always open (Block list non-empty)', function() {
864 // Prefs: Items in both Block and Allow list.
865 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
866 setUpCategory(contentType, settings.PermissionValues.ALLOW, prefs);
867 return browserProxy.whenCalled('getExceptionList').then(
868 function(actualContentType) {
869 assertEquals(contentType, actualContentType);
870 assertFalse(testElement.$.category.hidden);
871 }).then(function() {
872 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
873 });
874 });
875
876 test('Block list not hidden when empty', function() {
877 // Prefs: One item in Allow list, nothing in Block list.
878 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
879 setUpCategory(
880 contentType, settings.PermissionValues.BLOCK, prefsOneEnabled);
881 return browserProxy.whenCalled('getExceptionList').then(
882 function(actualContentType) {
883 assertEquals(contentType, actualContentType);
884 assertFalse(testElement.$.category.hidden);
885 });
886 });
887
888 test('Allow list not hidden when empty', function() {
889 // Prefs: One item in Block list, nothing in Allow list.
890 var contentType = settings.ContentSettingsTypes.GEOLOCATION;
891 setUpCategory(
892 contentType, settings.PermissionValues.ALLOW, prefsOneDisabled);
893 return browserProxy.whenCalled('getExceptionList').then(
894 function(actualContentType) {
895 assertEquals(contentType, actualContentType);
896 assertFalse(testElement.$.category.hidden);
897 });
898 });
899
900 test('All sites category no action menu', function() {
901 setUpCategory(settings.ALL_SITES, '', prefsVarious);
902 return browserProxy.whenCalled('getExceptionList').then(
903 function(contentType) {
904 // Use resolver to ensure that the list container is populated.
905 var resolver = new PromiseResolver();
906 testElement.async(resolver.resolve);
907 return resolver.promise.then(function() {
908 var item = testElement.$.listContainer.children[0];
909 var dots = item.querySelector('#actionMenuButton');
910 assertTrue(!!dots);
911 assertTrue(dots.hidden);
912 });
913 });
914 });
915
916 test('All sites category', function() {
917 // Prefs: Multiple and overlapping sites.
918 setUpCategory(settings.ALL_SITES, '', prefsVarious);
919
920 return browserProxy.whenCalled('getExceptionList').then(
921 function(contentType) {
922 // Use resolver to ensure asserts bubble up to the framework with
923 // meaningful errors.
924 var resolver = new PromiseResolver();
925 testElement.async(resolver.resolve);
926 return resolver.promise.then(function() {
927 // All Sites calls getExceptionList for all categories, starting
928 // with Cookies.
929 assertEquals(
930 settings.ContentSettingsTypes.COOKIES, contentType);
931
932 // Required for firstItem to be found below.
933 Polymer.dom.flush();
934
935 assertFalse(testElement.$.category.hidden);
936 // Validate that the sites gets populated from pre-canned prefs.
937 assertEquals(3, testElement.sites.length,
938 'If this fails with 5 instead of the expected 3, then ' +
939 'the de-duping of sites is not working for site_list');
940 assertEquals(prefsVarious.exceptions.geolocation[1].origin,
941 testElement.sites[0].origin);
942 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
943 testElement.sites[1].origin);
944 assertEquals(prefsVarious.exceptions.notifications[0].origin,
945 testElement.sites[2].origin);
946 assertEquals(undefined, testElement.selectedOrigin);
947
948 // Validate that the sites are shown in UI and can be selected.
949 var firstItem = testElement.$.listContainer.children[1];
950 var clickable = firstItem.querySelector('.middle');
951 assertNotEquals(undefined, clickable);
952 MockInteractions.tap(clickable);
953 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
954 settings.getQueryParameters().get('site'));
955 });
956 });
957 });
958
959 test('All sites mixed pattern and origin', function() {
960 // Prefs: One site, represented as origin and pattern.
961 setUpCategory(settings.ALL_SITES, '', prefsMixedOriginAndPattern);
962
963 return browserProxy.whenCalled('getExceptionList').then(
964 function(contentType) {
965 // Use resolver to ensure asserts bubble up to the framework with
966 // meaningful errors.
967 var resolver = new PromiseResolver();
968 testElement.async(resolver.resolve);
969 return resolver.promise.then(function() {
970 // All Sites calls getExceptionList for all categories, starting
971 // with Cookies.
972 assertEquals(
973 settings.ContentSettingsTypes.COOKIES, contentType);
974
975 // Required for firstItem to be found below.
976 Polymer.dom.flush();
977
978 assertFalse(testElement.$.category.hidden);
979 // Validate that the sites gets populated from pre-canned prefs.
980 // TODO(dschuyler): de-duping of sites is under discussion, so
981 // it is currently disabled. It should be enabled again or this
982 // code should be removed.
983 assertEquals(2, testElement.sites.length,
984 'If this fails with 1 instead of the expected 2, then ' +
985 'the de-duping of sites has been enabled for site_list.');
986 if (testElement.sites.length == 1) {
987 assertEquals(
988 prefsMixedOriginAndPattern.exceptions.
989 geolocation[0].
990 origin,
991 testElement.sites[0].displayName);
992 }
993
994 assertEquals(undefined, testElement.selectedOrigin);
995 // Validate that the sites are shown in UI and can be selected.
996 var firstItem = testElement.$.listContainer.children[0];
997 var clickable = firstItem.querySelector('.middle');
998 assertNotEquals(undefined, clickable);
999 MockInteractions.tap(clickable);
1000 if (testElement.sites.length == 1) {
1001 assertEquals(
1002 prefsMixedOriginAndPattern.exceptions.
1003 geolocation[0].
1004 origin,
1005 testElement.sites[0].displayName);
1006 }
1007 });
1008 });
1009 });
1010
1011 test('Mixed schemes (present and absent)', function() {
1012 // Prefs: One item with scheme and one without.
1013 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION,
1014 settings.PermissionValues.ALLOW, prefsMixedSchemes);
1015 return browserProxy.whenCalled('getExceptionList').then(
1016 function(contentType) {
1017 // No further checks needed. If this fails, it will hang the test.
1018 });
1019 });
1020
1021 test('Select menu item', function() {
1022 // Test for error: "Cannot read property 'origin' of undefined".
1023 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION,
1024 settings.PermissionValues.ALLOW, prefs);
1025 return browserProxy.whenCalled('getExceptionList').then(function(
1026 contentType) {
1027 Polymer.dom.flush(); 1033 Polymer.dom.flush();
1028 openActionMenu(0); 1034 openActionMenu(0);
1029 var allow = testElement.$.allow; 1035 var allow = testElement.$.allow;
1030 assertTrue(!!allow); 1036 assertTrue(!!allow);
1031 MockInteractions.tap(allow); 1037 MockInteractions.tap(allow);
1032 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); 1038 return browserProxy.whenCalled('setCategoryPermissionForOrigin');
1033 }); 1039 });
1034 }); 1040 });
1035 1041
1036 test('Chrome Extension scheme', function() { 1042 test('Chrome Extension scheme', function() {
1037 setUpCategory(settings.ContentSettingsTypes.JAVASCRIPT, 1043 setUpCategory(
1038 settings.PermissionValues.BLOCK, prefsChromeExtension); 1044 settings.ContentSettingsTypes.JAVASCRIPT,
1039 return browserProxy.whenCalled('getExceptionList').then(function( 1045 settings.PermissionValues.BLOCK, prefsChromeExtension);
1040 contentType) { 1046 return browserProxy.whenCalled('getExceptionList')
1047 .then(function(contentType) {
1041 Polymer.dom.flush(); 1048 Polymer.dom.flush();
1042 openActionMenu(0); 1049 openActionMenu(0);
1043 assertMenu(['Allow', 'Edit', 'Remove'], testElement); 1050 assertMenu(['Allow', 'Edit', 'Remove'], testElement);
1044 1051
1045 var allow = testElement.$.allow; 1052 var allow = testElement.$.allow;
1046 assertTrue(!!allow); 1053 assertTrue(!!allow);
1047 MockInteractions.tap(allow); 1054 MockInteractions.tap(allow);
1048 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); 1055 return browserProxy.whenCalled('setCategoryPermissionForOrigin');
1049 }).then(function(args) { 1056 })
1050 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', 1057 .then(function(args) {
1051 args[0]); 1058 assertEquals(
1059 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', args[0]);
1052 assertEquals('', args[1]); 1060 assertEquals('', args[1]);
1053 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); 1061 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]);
1054 assertEquals('allow', args[3]); 1062 assertEquals('allow', args[3]);
1055 }); 1063 });
1056 }); 1064 });
1057 }); 1065 });
1058 }
1059 1066
1060 suite('EditExceptionDialog', function() { 1067 suite('EditExceptionDialog', function() {
1061 /** @type {SettingsEditExceptionDialogElement} */ var dialog; 1068 /** @type {SettingsEditExceptionDialogElement} */ var dialog;
1062 1069
1063 /** 1070 /**
1064 * The dialog tests don't call |getExceptionList| so the exception needs to 1071 * The dialog tests don't call |getExceptionList| so the exception needs to
1065 * be processes as a |SiteSettingsPref|. 1072 * be processes as a |SiteSettingsPref|.
1066 * @type {SiteSettingsPref} 1073 * @type {SiteSettingsPref}
1067 */ 1074 */
1068 var cookieException = { 1075 var cookieException = {
1069 category: 'cookies', 1076 category: 'cookies',
1070 embeddingOrigin: 'http://foo.com', 1077 embeddingOrigin: 'http://foo.com',
1071 incognito: false, 1078 incognito: false,
1072 origin: 'http://foo.com', 1079 origin: 'http://foo.com',
1073 setting: 'block', 1080 setting: 'block',
1074 enforcement: '', 1081 enforcement: '',
1075 controlledBy: 'USER_POLICY', 1082 controlledBy: 'USER_POLICY',
1076 }; 1083 };
1077 1084
1078 setup(function() { 1085 setup(function() {
1079 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); 1086 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
1080 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; 1087 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
1081 PolymerTest.clearBody(); 1088 PolymerTest.clearBody();
1082 dialog = document.createElement('settings-edit-exception-dialog'); 1089 dialog = document.createElement('settings-edit-exception-dialog');
1083 dialog.model = cookieException; 1090 dialog.model = cookieException;
1084 document.body.appendChild(dialog); 1091 document.body.appendChild(dialog);
1085 }); 1092 });
1086 1093
1087 teardown(function() { 1094 teardown(function() {
1088 dialog.remove(); 1095 dialog.remove();
1089 }); 1096 });
1090 1097
1091 test('invalid input', function() { 1098 test('invalid input', function() {
1092 var input = dialog.$$('paper-input'); 1099 var input = dialog.$$('paper-input');
1093 assertTrue(!!input); 1100 assertTrue(!!input);
1094 assertFalse(input.invalid); 1101 assertFalse(input.invalid);
1095 1102
1096 var actionButton = dialog.$.actionButton; 1103 var actionButton = dialog.$.actionButton;
1097 assertTrue(!!actionButton); 1104 assertTrue(!!actionButton);
1098 assertFalse(actionButton.disabled); 1105 assertFalse(actionButton.disabled);
1099 1106
1100 // Simulate user input of whitespace only text. 1107 // Simulate user input of whitespace only text.
1101 input.value = ' '; 1108 input.value = ' ';
1102 input.fire('input'); 1109 input.fire('input');
1103 Polymer.dom.flush(); 1110 Polymer.dom.flush();
1111 assertTrue(actionButton.disabled);
1112 assertTrue(input.invalid);
1113
1114 // Simulate user input of invalid text.
1115 browserProxy.setIsPatternValid(false);
1116 var expectedPattern = 'foobarbaz';
1117 input.value = expectedPattern;
1118 input.fire('input');
1119
1120 return browserProxy.whenCalled('isPatternValid').then(function(pattern) {
1121 assertEquals(expectedPattern, pattern);
1104 assertTrue(actionButton.disabled); 1122 assertTrue(actionButton.disabled);
1105 assertTrue(input.invalid); 1123 assertTrue(input.invalid);
1106
1107 // Simulate user input of invalid text.
1108 browserProxy.setIsPatternValid(false);
1109 var expectedPattern = 'foobarbaz';
1110 input.value = expectedPattern;
1111 input.fire('input');
1112
1113 return browserProxy.whenCalled('isPatternValid').then(function(pattern) {
1114 assertEquals(expectedPattern, pattern);
1115 assertTrue(actionButton.disabled);
1116 assertTrue(input.invalid);
1117 });
1118 });
1119
1120 test('action button calls proxy', function() {
1121 var input = dialog.$$('paper-input');
1122 assertTrue(!!input);
1123 // Simulate user edit.
1124 var newValue = input.value + ':1234';
1125 input.value = newValue;
1126
1127 var actionButton = dialog.$.actionButton;
1128 assertTrue(!!actionButton);
1129 assertFalse(actionButton.disabled);
1130
1131 MockInteractions.tap(actionButton);
1132 return browserProxy.whenCalled('resetCategoryPermissionForOrigin')
1133 .then(function(args) {
1134 assertEquals(cookieException.origin, args[0]);
1135 assertEquals(cookieException.embeddingOrigin, args[1]);
1136 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]);
1137 assertEquals(cookieException.incognito, args[3]);
1138
1139 return browserProxy.whenCalled('setCategoryPermissionForOrigin');
1140 })
1141 .then(function(args) {
1142 assertEquals(newValue, args[0]);
1143 assertEquals(newValue, args[1]);
1144 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]);
1145 assertEquals(cookieException.setting, args[3]);
1146 assertEquals(cookieException.incognito, args[4]);
1147
1148 assertFalse(dialog.$.dialog.open);
1149 });
1150 }); 1124 });
1151 }); 1125 });
1152 1126
1153 suite('AddExceptionDialog', function() { 1127 test('action button calls proxy', function() {
1154 /** @type {AddSiteDialogElement} */ var dialog; 1128 var input = dialog.$$('paper-input');
1129 assertTrue(!!input);
1130 // Simulate user edit.
1131 var newValue = input.value + ':1234';
1132 input.value = newValue;
1155 1133
1156 setup(function() { 1134 var actionButton = dialog.$.actionButton;
1157 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); 1135 assertTrue(!!actionButton);
1158 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; 1136 assertFalse(actionButton.disabled);
1159 PolymerTest.clearBody();
1160 dialog = document.createElement('add-site-dialog');
1161 dialog.category = settings.ContentSettingsTypes.GEOLOCATION;
1162 dialog.contentSetting = settings.PermissionValues.ALLOW;
1163 document.body.appendChild(dialog);
1164 dialog.open();
1165 });
1166 1137
1167 teardown(function() { 1138 MockInteractions.tap(actionButton);
1168 dialog.remove(); 1139 return browserProxy.whenCalled('resetCategoryPermissionForOrigin')
1169 }); 1140 .then(function(args) {
1141 assertEquals(cookieException.origin, args[0]);
1142 assertEquals(cookieException.embeddingOrigin, args[1]);
1143 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]);
1144 assertEquals(cookieException.incognito, args[3]);
1170 1145
1171 test('incognito', function() { 1146 return browserProxy.whenCalled('setCategoryPermissionForOrigin');
1172 cr.webUIListenerCallback( 1147 })
1173 'onIncognitoStatusChanged', 1148 .then(function(args) {
1174 /*hasIncognito=*/true); 1149 assertEquals(newValue, args[0]);
1175 assertFalse(dialog.$.incognito.checked); 1150 assertEquals(newValue, args[1]);
1176 dialog.$.incognito.checked = true; 1151 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]);
1177 // Changing the incognito status will reset the checkbox. 1152 assertEquals(cookieException.setting, args[3]);
1178 cr.webUIListenerCallback( 1153 assertEquals(cookieException.incognito, args[4]);
1179 'onIncognitoStatusChanged',
1180 /*hasIncognito=*/false);
1181 assertFalse(dialog.$.incognito.checked);
1182 });
1183 1154
1184 test('invalid input', function() { 1155 assertFalse(dialog.$.dialog.open);
1185 // Initially the action button should be disabled, but the error warning 1156 });
1186 // should not be shown for an empty input. 1157 });
1187 var input = dialog.$$('paper-input'); 1158 });
1188 assertTrue(!!input);
1189 assertFalse(input.invalid);
1190 1159
1191 var actionButton = dialog.$.add; 1160 suite('AddExceptionDialog', function() {
1192 assertTrue(!!actionButton); 1161 /** @type {AddSiteDialogElement} */ var dialog;
1162
1163 setup(function() {
1164 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
1165 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
1166 PolymerTest.clearBody();
1167 dialog = document.createElement('add-site-dialog');
1168 dialog.category = settings.ContentSettingsTypes.GEOLOCATION;
1169 dialog.contentSetting = settings.PermissionValues.ALLOW;
1170 document.body.appendChild(dialog);
1171 dialog.open();
1172 });
1173
1174 teardown(function() {
1175 dialog.remove();
1176 });
1177
1178 test('incognito', function() {
1179 cr.webUIListenerCallback(
1180 'onIncognitoStatusChanged',
1181 /*hasIncognito=*/true);
1182 assertFalse(dialog.$.incognito.checked);
1183 dialog.$.incognito.checked = true;
1184 // Changing the incognito status will reset the checkbox.
1185 cr.webUIListenerCallback(
1186 'onIncognitoStatusChanged',
1187 /*hasIncognito=*/false);
1188 assertFalse(dialog.$.incognito.checked);
1189 });
1190
1191 test('invalid input', function() {
1192 // Initially the action button should be disabled, but the error warning
1193 // should not be shown for an empty input.
1194 var input = dialog.$$('paper-input');
1195 assertTrue(!!input);
1196 assertFalse(input.invalid);
1197
1198 var actionButton = dialog.$.add;
1199 assertTrue(!!actionButton);
1200 assertTrue(actionButton.disabled);
1201
1202 // Simulate user input of invalid text.
1203 browserProxy.setIsPatternValid(false);
1204 var expectedPattern = 'foobarbaz';
1205 input.value = expectedPattern;
1206 input.fire('input');
1207
1208 return browserProxy.whenCalled('isPatternValid').then(function(pattern) {
1209 assertEquals(expectedPattern, pattern);
1193 assertTrue(actionButton.disabled); 1210 assertTrue(actionButton.disabled);
1194 1211 assertTrue(input.invalid);
1195 // Simulate user input of invalid text.
1196 browserProxy.setIsPatternValid(false);
1197 var expectedPattern = 'foobarbaz';
1198 input.value = expectedPattern;
1199 input.fire('input');
1200
1201 return browserProxy.whenCalled('isPatternValid').then(function(pattern) {
1202 assertEquals(expectedPattern, pattern);
1203 assertTrue(actionButton.disabled);
1204 assertTrue(input.invalid);
1205 });
1206 }); 1212 });
1207 }); 1213 });
1208
1209 return {
1210 registerTests: registerTests,
1211 };
1212 }); 1214 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698