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

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

Issue 2055823003: Site Settings Desktop: Implement the 'Clear on exit' menu for Cookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ready Created 4 years, 6 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
« no previous file with comments | « chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cr.define('site_list', function() {
7 function registerTests() { 7 function registerTests() {
8 suite('SiteList', function() { 8 suite('SiteList', function() {
9 /** 9 /**
10 * A site list element created before each test. 10 * A site list element created before each test.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 { 211 {
212 embeddingOrigin: 'https://foo-block.com:443', 212 embeddingOrigin: 'https://foo-block.com:443',
213 origin: 'https://foo-block.com:443', 213 origin: 'https://foo-block.com:443',
214 setting: 'block', 214 setting: 'block',
215 source: 'preference', 215 source: 'preference',
216 }, 216 },
217 ] 217 ]
218 } 218 }
219 }; 219 };
220 220
221 /**
222 * An example Cookies pref with 1 in each of the three categories.
223 * @type {SiteSettingsPref}
224 */
225 var prefsSessionOnly = {
226 exceptions: {
227 cookies: [
228 {
229 embeddingOrigin: 'http://foo-block.com',
230 origin: 'http://foo-block.com',
231 setting: 'block',
232 source: 'preference',
233 },
234 {
235 embeddingOrigin: 'http://foo-allow.com',
236 origin: 'http://foo-allow.com',
237 setting: 'allow',
238 source: 'preference',
239 },
240 {
241 embeddingOrigin: 'http://foo-session.com',
242 origin: 'http://foo-session.com',
243 setting: 'session_only',
244 source: 'preference',
245 },
246 ]
247 }
248 };
249
221 // Import necessary html before running suite. 250 // Import necessary html before running suite.
222 suiteSetup(function() { 251 suiteSetup(function() {
223 CrSettingsPrefs.setInitialized(); 252 CrSettingsPrefs.setInitialized();
224 return PolymerTest.importHtml( 253 return PolymerTest.importHtml(
225 'chrome://md-settings/site_settings/site_list.html'); 254 'chrome://md-settings/site_settings/site_list.html');
226 }); 255 });
227 256
228 suiteTeardown(function() { 257 suiteTeardown(function() {
229 CrSettingsPrefs.resetForTesting(); 258 CrSettingsPrefs.resetForTesting();
230 }); 259 });
231 260
232 // Initialize a site-list before each test. 261 // Initialize a site-list before each test.
233 setup(function() { 262 setup(function() {
234 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); 263 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
235 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; 264 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
236 PolymerTest.clearBody(); 265 PolymerTest.clearBody();
237 testElement = document.createElement('settings-site-list'); 266 testElement = document.createElement('settings-site-list');
238 document.body.appendChild(testElement); 267 document.body.appendChild(testElement);
239 }); 268 });
240 269
241 /** 270 /**
242 * Asserts if a menu action is incorrectly hidden. 271 * Asserts the menu looks as expected.
272 * @param {Array<string>} items The items expected to show in the menu.
243 * @param {!HTMLElement} parentElement The parent node to start looking 273 * @param {!HTMLElement} parentElement The parent node to start looking
244 * in. 274 * in.
245 * @param {string} textForHiddenAction Text content of the only node that
246 * should be hidden.
247 */ 275 */
248 function assertMenuActionHidden(parentElement, textForHiddenAction) { 276 function assertMenu(items, parentElement) {
249 var listItem = parentElement.$.listContainer.children[0]; 277 var listItem = parentElement.$.listContainer.children[0];
250 var menuItems = 278 var menuItems = listItem.querySelectorAll(
251 listItem.querySelectorAll('paper-menu-button paper-item'); 279 'paper-menu-button paper-item:not([hidden])');
252 assertNotEquals(0, menuItems.length); 280 assertEquals(items.length, menuItems.length);
253 281 for (var i = 0; i < items.length; i++)
254 var found = false; 282 assertEquals(items[i], menuItems[i].textContent.trim());
255 menuItems.forEach(function(item) {
256 var text = item.textContent.trim();
257 if (text == textForHiddenAction)
258 found = true;
259 assertEquals(text == textForHiddenAction, item.hidden);
260 });
261 assertTrue(found);
262 } 283 }
263 284
264 /** 285 /**
265 * Configures the test element as a location category. 286 * Configures the test element for a particular category.
266 * @param {settings.PermissionValues} subtype Type of list to use: ALLOW 287 * @param {settings.ContentSettingsTypes} category The category to setup.
267 * or BLOCK. 288 * @param {settings.PermissionValues} subtype Type of list to use.
268 * @param Array<dictionary> prefs The prefs to use. 289 * @param {Array<dictionary>} prefs The prefs to use.
269 */ 290 */
270 function setupLocationCategory(subtype, prefs) { 291 function setupCategory(category, subtype, prefs) {
271 browserProxy.setPrefs(prefs); 292 browserProxy.setPrefs(prefs);
272 testElement.categorySubtype = subtype; 293 if (category == settings.ALL_SITES) {
273 testElement.categoryEnabled = true; 294 testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE;
274 testElement.allSites = false; 295 testElement.allSites = true;
296 } else {
297 testElement.categorySubtype = subtype;
298 testElement.allSites = false;
299 }
300 // Some route is needed, but the actual route doesn't matter.
275 testElement.currentRoute = { 301 testElement.currentRoute = {
276 page: 'dummy', 302 page: 'dummy',
277 section: 'privacy', 303 section: 'privacy',
278 subpage: ['site-settings', 'site-settings-category-location'], 304 subpage: ['site-settings', 'site-settings-category-location'],
279 }; 305 };
280 testElement.category = settings.ContentSettingsTypes.GEOLOCATION; 306 testElement.category = category;
281 }
282
283 /**
284 * Configures the test element as the all sites category.
285 * @param {dictionary} prefs The prefs to use.
286 */
287 function setupAllSitesCategory(prefs) {
288 browserProxy.setPrefs(prefs);
289 testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE;
290 testElement.categoryEnabled = true;
291 testElement.allSites = true;
292 testElement.prefs = prefs;
293 testElement.currentRoute = {
294 page: 'dummy',
295 section: 'privacy',
296 subpage: ['site-settings', 'site-settings-category-location'],
297 };
298 testElement.category = settings.ALL_SITES;
299 } 307 }
300 308
301 test('getExceptionList API used', function() { 309 test('getExceptionList API used', function() {
302 setupLocationCategory(settings.PermissionValues.ALLOW, prefsEmpty); 310 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
311 settings.PermissionValues.ALLOW, prefsEmpty);
303 return browserProxy.whenCalled('getExceptionList').then( 312 return browserProxy.whenCalled('getExceptionList').then(
304 function(contentType) { 313 function(contentType) {
305 assertEquals( 314 assertEquals(
306 settings.ContentSettingsTypes.GEOLOCATION, contentType); 315 settings.ContentSettingsTypes.GEOLOCATION, contentType);
307 }); 316 });
308 }); 317 });
309 318
310 test('Empty list', function() { 319 test('Empty list', function() {
311 setupLocationCategory(settings.PermissionValues.ALLOW, prefsEmpty); 320 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
312 return browserProxy.whenCalled('getExceptionList').then( 321 settings.PermissionValues.ALLOW, prefsEmpty);
313 function(contentType) { 322 return browserProxy.whenCalled('getExceptionList').then(
314 assertEquals( 323 function(contentType) {
315 settings.ContentSettingsTypes.GEOLOCATION, contentType); 324 assertEquals(
316 325 settings.ContentSettingsTypes.GEOLOCATION, contentType);
317 assertEquals(0, testElement.sites.length); 326
318 327 assertEquals(0, testElement.sites.length);
319 assertEquals( 328
320 settings.PermissionValues.ALLOW, testElement.categorySubtype); 329 assertEquals(
321 assertEquals('Allow - 0', testElement.$.header.innerText.trim()); 330 settings.PermissionValues.ALLOW, testElement.categorySubtype);
322 331 assertEquals('Allow - 0', testElement.$.header.innerText.trim());
323 assertFalse(testElement.$.category.hidden); 332
324 browserProxy.resetResolver('getExceptionList'); 333 assertFalse(testElement.$.category.hidden);
325 testElement.categoryEnabled = false; 334 browserProxy.resetResolver('getExceptionList');
326 return browserProxy.whenCalled('getExceptionList').then( 335 testElement.categoryEnabled = false;
327 function(contentType) { 336 return browserProxy.whenCalled('getExceptionList').then(
328 assertFalse(testElement.$.category.hidden); 337 function(contentType) {
329 assertEquals('Exceptions - 0', 338 assertFalse(testElement.$.category.hidden);
330 testElement.$.header.innerText.trim()); 339 assertEquals('Exceptions - 0',
331 }); 340 testElement.$.header.innerText.trim());
332 }); 341 });
342 });
333 }); 343 });
334 344
335 test('initial ALLOW state is correct', function() { 345 test('initial ALLOW state is correct', function() {
336 setupLocationCategory(settings.PermissionValues.ALLOW, prefs); 346 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
337 return browserProxy.whenCalled('getExceptionList').then( 347 settings.PermissionValues.ALLOW, prefs);
338 function(contentType) { 348 return browserProxy.whenCalled('getExceptionList').then(
339 assertEquals( 349 function(contentType) {
340 settings.ContentSettingsTypes.GEOLOCATION, contentType); 350 assertEquals(
341 351 settings.ContentSettingsTypes.GEOLOCATION, contentType);
342 assertEquals(2, testElement.sites.length); 352
343 assertEquals(prefs.exceptions.geolocation[1].origin, 353 assertEquals(2, testElement.sites.length);
344 testElement.sites[0].origin); 354 assertEquals(prefs.exceptions.geolocation[1].origin,
345 assertEquals( 355 testElement.sites[0].origin);
346 settings.PermissionValues.ALLOW, testElement.categorySubtype); 356 assertEquals(
347 Polymer.dom.flush(); // Populates action menu. 357 settings.PermissionValues.ALLOW, testElement.categorySubtype);
348 assertMenuActionHidden(testElement, 'Allow'); 358 Polymer.dom.flush(); // Populates action menu.
349 assertEquals('Allow - 2', testElement.$.header.innerText.trim()); 359 assertMenu(['Block', 'Reset to ask'], testElement);
350 360 assertEquals('Allow - 2', testElement.$.header.innerText.trim());
351 // Site list should show, no matter what category default is set to. 361
352 assertFalse(testElement.$.category.hidden); 362 // Site list should show, no matter what category default is set
353 browserProxy.resetResolver('getExceptionList'); 363 // to.
354 testElement.categoryEnabled = false; 364 assertFalse(testElement.$.category.hidden);
355 return browserProxy.whenCalled('getExceptionList').then( 365 browserProxy.resetResolver('getExceptionList');
356 function(contentType) { 366 testElement.categoryEnabled = false;
357 assertFalse(testElement.$.category.hidden); 367 return browserProxy.whenCalled('getExceptionList').then(
358 assertEquals('Exceptions - 2', testElement.$.header.innerText); 368 function(contentType) {
359 }); 369 assertFalse(testElement.$.category.hidden);
360 }); 370 assertEquals('Exceptions - 2',
371 testElement.$.header.innerText.trim());
372 });
373 });
361 }); 374 });
362 375
363 test('initial BLOCK state is correct', function() { 376 test('initial BLOCK state is correct', function() {
364 setupLocationCategory(settings.PermissionValues.BLOCK, prefs); 377 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
365 return browserProxy.whenCalled('getExceptionList').then( 378 settings.PermissionValues.BLOCK, prefs);
366 function(contentType) { 379 return browserProxy.whenCalled('getExceptionList').then(
367 assertEquals( 380 function(contentType) {
368 settings.ContentSettingsTypes.GEOLOCATION, contentType); 381 assertEquals(
369 382 settings.ContentSettingsTypes.GEOLOCATION, contentType);
370 assertEquals(2, testElement.sites.length); 383
371 assertEquals(prefs.exceptions.geolocation[3].origin, 384 assertEquals(2, testElement.sites.length);
372 testElement.sites[0].origin); 385 assertEquals(prefs.exceptions.geolocation[3].origin,
373 386 testElement.sites[0].origin);
374 assertEquals( 387
375 settings.PermissionValues.BLOCK, testElement.categorySubtype); 388 assertEquals(
376 Polymer.dom.flush(); // Populates action menu. 389 settings.PermissionValues.BLOCK, testElement.categorySubtype);
377 assertMenuActionHidden(testElement, 'Block'); 390 Polymer.dom.flush(); // Populates action menu.
378 assertEquals('Block - 2', testElement.$.header.innerText.trim()); 391 assertMenu(['Allow', 'Reset to ask'], testElement);
379 392 assertEquals('Block - 2', testElement.$.header.innerText.trim());
380 // Site list should only show when category default is enabled. 393
381 assertFalse(testElement.$.category.hidden); 394 // Site list should only show when category default is enabled.
382 browserProxy.resetResolver('getExceptionList'); 395 assertFalse(testElement.$.category.hidden);
383 testElement.categoryEnabled = false; 396 browserProxy.resetResolver('getExceptionList');
384 return browserProxy.whenCalled('getExceptionList').then( 397 testElement.categoryEnabled = false;
385 function(contentType) { 398 return browserProxy.whenCalled('getExceptionList').then(
386 assertTrue(testElement.$.category.hidden); 399 function(contentType) {
387 }); 400 assertTrue(testElement.$.category.hidden);
388 }); 401 });
402 });
403 });
404
405 test('initial SESSION ONLY state is correct', function() {
406 setupCategory(settings.ContentSettingsTypes.COOKIES,
407 settings.PermissionValues.SESSION_ONLY, prefsSessionOnly);
408 return browserProxy.whenCalled('getExceptionList').then(
409 function(contentType) {
410 assertEquals(
411 settings.ContentSettingsTypes.COOKIES, contentType);
412
413 assertEquals(1, testElement.sites.length);
414 assertEquals(prefsSessionOnly.exceptions.cookies[2].origin,
415 testElement.sites[0].origin);
416
417 assertEquals(settings.PermissionValues.SESSION_ONLY,
418 testElement.categorySubtype);
419 Polymer.dom.flush(); // Populates action menu.
420 assertMenu(['Allow', 'Block', 'Reset to ask'], testElement);
421 assertEquals('Clear on exit - 1',
422 testElement.$.header.innerText.trim());
423
424 // Site list should show, no matter what category default is set
425 // to.
426 assertFalse(testElement.$.category.hidden);
427 browserProxy.resetResolver('getExceptionList');
428 testElement.categoryEnabled = false;
429 return browserProxy.whenCalled('getExceptionList').then(
430 function(contentType) {
431 assertFalse(testElement.$.category.hidden);
432 assertEquals('Clear on exit - 1',
433 testElement.$.header.innerText);
434 });
435 });
389 }); 436 });
390 437
391 test('list items shown and clickable when data is present', function() { 438 test('list items shown and clickable when data is present', function() {
392 setupLocationCategory(settings.PermissionValues.ALLOW, prefs); 439 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
393 return browserProxy.whenCalled('getExceptionList').then( 440 settings.PermissionValues.ALLOW, prefs);
394 function(contentType) { 441 return browserProxy.whenCalled('getExceptionList').then(
395 assertEquals( 442 function(contentType) {
396 settings.ContentSettingsTypes.GEOLOCATION, contentType); 443 assertEquals(
397 444 settings.ContentSettingsTypes.GEOLOCATION, contentType);
398 // Required for firstItem to be found below.
399 Polymer.dom.flush();
400
401 // Validate that the sites gets populated from pre-canned prefs.
402 assertEquals(2, testElement.sites.length);
403 assertEquals(prefs.exceptions.geolocation[1].origin,
404 testElement.sites[0].origin);
405 assertEquals(undefined, testElement.selectedOrigin);
406
407 // Validate that the sites are shown in UI and can be selected.
408 var firstItem = testElement.$.listContainer.children[0];
409 var clickable = firstItem.querySelector('.middle');
410 assertNotEquals(undefined, clickable);
411 MockInteractions.tap(clickable);
412 assertEquals(prefs.exceptions.geolocation[1].origin,
413 testElement.selectedSite.origin);
414 });
415 });
416
417 test('Block list open when Allow list is empty', function() {
418 // Prefs: One item in Block list, nothing in Allow list.
419 setupLocationCategory(settings.PermissionValues.BLOCK,
420 prefsOneDisabled);
421 return browserProxy.whenCalled('getExceptionList').then(
422 function(contentType) {
423 assertEquals(
424 settings.ContentSettingsTypes.GEOLOCATION, contentType);
425
426 assertFalse(testElement.$.category.hidden);
427 assertTrue(testElement.$.category.opened);
428 }).then(function() {
429 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
430 });
431 });
432
433 test('Block list closed when Allow list is not empty', function() {
434 // Prefs: Items in both Block and Allow list.
435 setupLocationCategory(settings.PermissionValues.BLOCK, prefs);
436 return browserProxy.whenCalled('getExceptionList').then(
437 function(contentType) {
438 assertEquals(
439 settings.ContentSettingsTypes.GEOLOCATION, contentType);
440
441 assertFalse(testElement.$.category.hidden);
442 assertFalse(testElement.$.category.opened);
443 assertEquals(0, testElement.$.listContainer.offsetHeight);
444 });
445 });
446
447 test('Allow list is always open (Block list empty)', function() {
448 // Prefs: One item in Allow list, nothing in Block list.
449 setupLocationCategory(
450 settings.PermissionValues.ALLOW, prefsOneEnabled);
451 return browserProxy.whenCalled('getExceptionList').then(
452 function(contentType) {
453 assertEquals(
454 settings.ContentSettingsTypes.GEOLOCATION, contentType);
455
456 assertFalse(testElement.$.category.hidden);
457 assertTrue(testElement.$.category.opened);
458 }).then(function() {
459 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
460 });
461 });
462
463 test('Allow list is always open (Block list non-empty)', function() {
464 // Prefs: Items in both Block and Allow list.
465 setupLocationCategory(settings.PermissionValues.ALLOW, prefs);
466 return browserProxy.whenCalled('getExceptionList').then(
467 function(contentType) {
468 assertEquals(
469 settings.ContentSettingsTypes.GEOLOCATION, contentType);
470
471 assertFalse(testElement.$.category.hidden);
472 assertTrue(testElement.$.category.opened);
473 }).then(function() {
474 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
475 });
476 });
477
478 test('Block list not hidden when empty', function() {
479 // Prefs: One item in Allow list, nothing in Block list.
480 setupLocationCategory(
481 settings.PermissionValues.BLOCK, prefsOneEnabled);
482 return browserProxy.whenCalled('getExceptionList').then(
483 function(contentType) {
484 assertEquals(
485 settings.ContentSettingsTypes.GEOLOCATION, contentType);
486
487 assertFalse(testElement.$.category.hidden);
488 });
489 });
490
491 test('Allow list not hidden when empty', function() {
492 // Prefs: One item in Block list, nothing in Allow list.
493 setupLocationCategory(settings.PermissionValues.ALLOW,
494 prefsOneDisabled);
495 return browserProxy.whenCalled('getExceptionList').then(
496 function(contentType) {
497 assertEquals(
498 settings.ContentSettingsTypes.GEOLOCATION, contentType);
499
500 assertFalse(testElement.$.category.hidden);
501 });
502 });
503
504 test('All sites category', function() {
505 // Prefs: Multiple and overlapping sites.
506 setupAllSitesCategory(prefsVarious);
507
508 return browserProxy.whenCalled('getExceptionList').then(
509 function(contentType) {
510 // Use resolver to ensure asserts bubble up to the framework with
511 // meaningful errors.
512 var resolver = new PromiseResolver();
513 testElement.async(resolver.resolve);
514 return resolver.promise.then(function() {
515 // All Sites calls getExceptionList for all categories, starting
516 // with Cookies.
517 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType);
518 445
519 // Required for firstItem to be found below. 446 // Required for firstItem to be found below.
520 Polymer.dom.flush(); 447 Polymer.dom.flush();
521 448
522 assertTrue(testElement.$.category.opened);
523 assertFalse(testElement.$.category.hidden);
524 // Validate that the sites gets populated from pre-canned prefs. 449 // Validate that the sites gets populated from pre-canned prefs.
525 assertEquals(3, testElement.sites.length, 450 assertEquals(2, testElement.sites.length);
526 'If this fails with 5 instead of the expected 3, then the ' + 451 assertEquals(prefs.exceptions.geolocation[1].origin,
527 'de-duping of sites is not working for site_list');
528 assertEquals(prefsVarious.exceptions.geolocation[1].origin,
529 testElement.sites[0].origin); 452 testElement.sites[0].origin);
530 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
531 testElement.sites[1].origin);
532 assertEquals(prefsVarious.exceptions.notifications[0].origin,
533 testElement.sites[2].origin);
534 assertEquals(undefined, testElement.selectedOrigin); 453 assertEquals(undefined, testElement.selectedOrigin);
535 454
536 // Validate that the sites are shown in UI and can be selected. 455 // Validate that the sites are shown in UI and can be selected.
537 var firstItem = testElement.$.listContainer.children[1];
538 var clickable = firstItem.querySelector('.middle');
539 assertNotEquals(undefined, clickable);
540 MockInteractions.tap(clickable);
541 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
542 testElement.selectedSite.origin);
543 });
544 });
545 });
546
547 test('All sites mixed pattern and origin', function() {
548 // Prefs: One site, represented as origin and pattern.
549 setupAllSitesCategory(prefsMixedOriginAndPattern);
550
551 return browserProxy.whenCalled('getExceptionList').then(
552 function(contentType) {
553 // Use resolver to ensure asserts bubble up to the framework with
554 // meaningful errors.
555 var resolver = new PromiseResolver();
556 testElement.async(resolver.resolve);
557 return resolver.promise.then(function() {
558 // All Sites calls getExceptionList for all categories, starting
559 // with Cookies.
560 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType);
561
562 // Required for firstItem to be found below.
563 Polymer.dom.flush();
564
565 assertTrue(testElement.$.category.opened);
566 assertFalse(testElement.$.category.hidden);
567 // Validate that the sites gets populated from pre-canned prefs.
568 assertEquals(1, testElement.sites.length,
569 'If this fails with 2 instead of the expected 1, then the ' +
570 'de-duping of sites is not working for site_list');
571 assertEquals(
572 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
573 testElement.sites[0].originForDisplay);
574
575 assertEquals(undefined, testElement.selectedOrigin);
576 // Validate that the sites are shown in UI and can be selected.
577 var firstItem = testElement.$.listContainer.children[0]; 456 var firstItem = testElement.$.listContainer.children[0];
578 var clickable = firstItem.querySelector('.middle'); 457 var clickable = firstItem.querySelector('.middle');
579 assertNotEquals(undefined, clickable); 458 assertNotEquals(undefined, clickable);
580 MockInteractions.tap(clickable); 459 MockInteractions.tap(clickable);
581 assertEquals( 460 assertEquals(prefs.exceptions.geolocation[1].origin,
582 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin, 461 testElement.selectedSite.origin);
583 testElement.selectedSite.originForDisplay); 462 });
584 }); 463 });
585 }); 464
465 test('Block list open when Allow list is empty', function() {
466 // Prefs: One item in Block list, nothing in Allow list.
467 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
468 settings.PermissionValues.BLOCK, prefsOneDisabled);
469 return browserProxy.whenCalled('getExceptionList').then(
470 function(contentType) {
471 assertEquals(
472 settings.ContentSettingsTypes.GEOLOCATION, contentType);
473
474 assertFalse(testElement.$.category.hidden);
475 assertTrue(testElement.$.category.opened);
476 }).then(function() {
477 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
478 });
479 });
480
481 test('Block list closed when Allow list is not empty', function() {
482 // Prefs: Items in both Block and Allow list.
483 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
484 settings.PermissionValues.BLOCK, prefs);
485 return browserProxy.whenCalled('getExceptionList').then(
486 function(contentType) {
487 assertEquals(
488 settings.ContentSettingsTypes.GEOLOCATION, contentType);
489
490 assertFalse(testElement.$.category.hidden);
491 assertFalse(testElement.$.category.opened);
492 assertEquals(0, testElement.$.listContainer.offsetHeight);
493 });
494 });
495
496 test('Allow list is always open (Block list empty)', function() {
497 // Prefs: One item in Allow list, nothing in Block list.
498 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
499 settings.PermissionValues.ALLOW, prefsOneEnabled);
500 return browserProxy.whenCalled('getExceptionList').then(
501 function(contentType) {
502 assertEquals(
503 settings.ContentSettingsTypes.GEOLOCATION, contentType);
504
505 assertFalse(testElement.$.category.hidden);
506 assertTrue(testElement.$.category.opened);
507 }).then(function() {
508 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
509 });
510 });
511
512 test('Allow list is always open (Block list non-empty)', function() {
513 // Prefs: Items in both Block and Allow list.
514 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
515 settings.PermissionValues.ALLOW, prefs);
516 return browserProxy.whenCalled('getExceptionList').then(
517 function(contentType) {
518 assertEquals(
519 settings.ContentSettingsTypes.GEOLOCATION, contentType);
520
521 assertFalse(testElement.$.category.hidden);
522 assertTrue(testElement.$.category.opened);
523 }).then(function() {
524 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
525 });
526 });
527
528 test('Block list not hidden when empty', function() {
529 // Prefs: One item in Allow list, nothing in Block list.
530 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
531 settings.PermissionValues.BLOCK, prefsOneEnabled);
532 return browserProxy.whenCalled('getExceptionList').then(
533 function(contentType) {
534 assertEquals(
535 settings.ContentSettingsTypes.GEOLOCATION, contentType);
536
537 assertFalse(testElement.$.category.hidden);
538 });
539 });
540
541 test('Allow list not hidden when empty', function() {
542 // Prefs: One item in Block list, nothing in Allow list.
543 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
544 settings.PermissionValues.ALLOW, prefsOneDisabled);
545 return browserProxy.whenCalled('getExceptionList').then(
546 function(contentType) {
547 assertEquals(
548 settings.ContentSettingsTypes.GEOLOCATION, contentType);
549
550 assertFalse(testElement.$.category.hidden);
551 });
552 });
553
554 test('All sites category', function() {
555 // Prefs: Multiple and overlapping sites.
556 setupCategory(settings.ALL_SITES, '', prefsVarious);
557
558 return browserProxy.whenCalled('getExceptionList').then(
559 function(contentType) {
560 // Use resolver to ensure asserts bubble up to the framework with
561 // meaningful errors.
562 var resolver = new PromiseResolver();
563 testElement.async(resolver.resolve);
564 return resolver.promise.then(function() {
565 // All Sites calls getExceptionList for all categories, starting
566 // with Cookies.
567 assertEquals(
568 settings.ContentSettingsTypes.COOKIES, contentType);
569
570 // Required for firstItem to be found below.
571 Polymer.dom.flush();
572
573 assertTrue(testElement.$.category.opened);
574 assertFalse(testElement.$.category.hidden);
575 // Validate that the sites gets populated from pre-canned prefs.
576 assertEquals(3, testElement.sites.length,
577 'If this fails with 5 instead of the expected 3, then ' +
578 'the de-duping of sites is not working for site_list');
579 assertEquals(prefsVarious.exceptions.geolocation[1].origin,
580 testElement.sites[0].origin);
581 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
582 testElement.sites[1].origin);
583 assertEquals(prefsVarious.exceptions.notifications[0].origin,
584 testElement.sites[2].origin);
585 assertEquals(undefined, testElement.selectedOrigin);
586
587 // Validate that the sites are shown in UI and can be selected.
588 var firstItem = testElement.$.listContainer.children[1];
589 var clickable = firstItem.querySelector('.middle');
590 assertNotEquals(undefined, clickable);
591 MockInteractions.tap(clickable);
592 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
593 testElement.selectedSite.origin);
594 });
595 });
596 });
597
598 test('All sites mixed pattern and origin', function() {
599 // Prefs: One site, represented as origin and pattern.
600 setupCategory(settings.ALL_SITES, '', prefsMixedOriginAndPattern);
601
602 return browserProxy.whenCalled('getExceptionList').then(
603 function(contentType) {
604 // Use resolver to ensure asserts bubble up to the framework with
605 // meaningful errors.
606 var resolver = new PromiseResolver();
607 testElement.async(resolver.resolve);
608 return resolver.promise.then(function() {
609 // All Sites calls getExceptionList for all categories, starting
610 // with Cookies.
611 assertEquals(
612 settings.ContentSettingsTypes.COOKIES, contentType);
613
614 // Required for firstItem to be found below.
615 Polymer.dom.flush();
616
617 assertTrue(testElement.$.category.opened);
618 assertFalse(testElement.$.category.hidden);
619 // Validate that the sites gets populated from pre-canned prefs.
620 assertEquals(1, testElement.sites.length,
621 'If this fails with 2 instead of the expected 1, then ' +
622 'the de-duping of sites is not working for site_list');
623 assertEquals(
624 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
625 testElement.sites[0].originForDisplay);
626
627 assertEquals(undefined, testElement.selectedOrigin);
628 // Validate that the sites are shown in UI and can be selected.
629 var firstItem = testElement.$.listContainer.children[0];
630 var clickable = firstItem.querySelector('.middle');
631 assertNotEquals(undefined, clickable);
632 MockInteractions.tap(clickable);
633 assertEquals(
634 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
635 testElement.selectedSite.originForDisplay);
636 });
637 });
586 }); 638 });
587 639
588 test('Mixed schemes (present and absent)', function() { 640 test('Mixed schemes (present and absent)', function() {
589 // Prefs: One item with scheme and one without. 641 // Prefs: One item with scheme and one without.
590 setupLocationCategory(settings.PermissionValues.ALLOW, 642 setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
591 prefsMixedSchemes); 643 settings.PermissionValues.ALLOW, prefsMixedSchemes);
592 return browserProxy.whenCalled('getExceptionList').then( 644 return browserProxy.whenCalled('getExceptionList').then(
593 function(contentType) { 645 function(contentType) {
594 // No further checks needed. If this fails, it will hang the test. 646 // No further checks needed. If this fails, it will hang the test.
595 }); 647 });
596 }); 648 });
597 }); 649 });
598 } 650 }
599 return { 651 return {
600 registerTests: registerTests, 652 registerTests: registerTests,
601 }; 653 };
602 }); 654 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698