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

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

Issue 1963013002: [MD settings] layout of site settings sub-pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge with master Created 4 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
« no previous file with comments | « chrome/browser/resources/settings/site_settings/site_settings_category.html ('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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 }); 224 });
225 225
226 /** 226 /**
227 * Asserts if a menu action is incorrectly hidden. 227 * Asserts if a menu action is incorrectly hidden.
228 * @param {!HTMLElement} parentElement The parent node to start looking 228 * @param {!HTMLElement} parentElement The parent node to start looking
229 * in. 229 * in.
230 * @param {string} textForHiddenAction Text content of the only node that 230 * @param {string} textForHiddenAction Text content of the only node that
231 * should be hidden. 231 * should be hidden.
232 */ 232 */
233 function assertMenuActionHidden(parentElement, textForHiddenAction) { 233 function assertMenuActionHidden(parentElement, textForHiddenAction) {
234 var listItem = parentElement.$.listContainer.items[0]; 234 var listItem = parentElement.$.listContainer.children[0];
235 var menuItems = 235 var menuItems =
236 listItem.querySelectorAll('paper-menu-button paper-item'); 236 listItem.querySelectorAll('paper-menu-button paper-item');
237 assertNotEquals(0, menuItems.length); 237 assertNotEquals(0, menuItems.length);
238 238
239 var found = false; 239 var found = false;
240 menuItems.forEach(function(item) { 240 menuItems.forEach(function(item) {
241 var text = item.textContent.trim(); 241 var text = item.textContent.trim();
242 if (text == textForHiddenAction) 242 if (text == textForHiddenAction)
243 found = true; 243 found = true;
244 assertEquals(text == textForHiddenAction, item.hidden); 244 assertEquals(text == textForHiddenAction, item.hidden);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 setupLocationCategory(settings.PermissionValues.ALLOW, prefsEmpty); 296 setupLocationCategory(settings.PermissionValues.ALLOW, prefsEmpty);
297 return browserProxy.whenCalled('getExceptionList').then( 297 return browserProxy.whenCalled('getExceptionList').then(
298 function(contentType) { 298 function(contentType) {
299 assertEquals( 299 assertEquals(
300 settings.ContentSettingsTypes.GEOLOCATION, contentType); 300 settings.ContentSettingsTypes.GEOLOCATION, contentType);
301 301
302 assertEquals(0, testElement.sites.length); 302 assertEquals(0, testElement.sites.length);
303 303
304 assertEquals( 304 assertEquals(
305 settings.PermissionValues.ALLOW, testElement.categorySubtype); 305 settings.PermissionValues.ALLOW, testElement.categorySubtype);
306 assertEquals('Allow - 0', testElement.$.header.innerText); 306 assertEquals('Allow - 0', testElement.$.header.innerText.trim());
307 307
308 // Site list should not show, no matter what category default is set 308 // Site list should not show, no matter what category default is set
309 // to. 309 // to.
310 assertTrue(testElement.$.category.hidden); 310 assertTrue(testElement.$.category.hidden);
311 browserProxy.resetResolver('getExceptionList'); 311 browserProxy.resetResolver('getExceptionList');
312 testElement.categoryEnabled = false; 312 testElement.categoryEnabled = false;
313 return browserProxy.whenCalled('getExceptionList').then( 313 return browserProxy.whenCalled('getExceptionList').then(
314 function(contentType) { 314 function(contentType) {
315 assertTrue(testElement.$.category.hidden); 315 assertTrue(testElement.$.category.hidden);
316 assertEquals('Exceptions - 0', testElement.$.header.innerText); 316 assertEquals('Exceptions - 0',
317 testElement.$.header.innerText.trim());
317 }); 318 });
318 }); 319 });
319 }); 320 });
320 321
321 test('initial ALLOW state is correct', function() { 322 test('initial ALLOW state is correct', function() {
322 setupLocationCategory(settings.PermissionValues.ALLOW, prefs); 323 setupLocationCategory(settings.PermissionValues.ALLOW, prefs);
323 return browserProxy.whenCalled('getExceptionList').then( 324 return browserProxy.whenCalled('getExceptionList').then(
324 function(contentType) { 325 function(contentType) {
325 assertEquals( 326 assertEquals(
326 settings.ContentSettingsTypes.GEOLOCATION, contentType); 327 settings.ContentSettingsTypes.GEOLOCATION, contentType);
327 328
328 assertEquals(2, testElement.sites.length); 329 assertEquals(2, testElement.sites.length);
329 assertEquals(prefs.exceptions.geolocation[1].origin, 330 assertEquals(prefs.exceptions.geolocation[1].origin,
330 testElement.sites[0].origin); 331 testElement.sites[0].origin);
331 assertEquals( 332 assertEquals(
332 settings.PermissionValues.ALLOW, testElement.categorySubtype); 333 settings.PermissionValues.ALLOW, testElement.categorySubtype);
333 Polymer.dom.flush(); // Populates action menu. 334 Polymer.dom.flush(); // Populates action menu.
334 assertMenuActionHidden(testElement, 'Allow'); 335 assertMenuActionHidden(testElement, 'Allow');
335 assertEquals('Allow - 2', testElement.$.header.innerText); 336 assertEquals('Allow - 2', testElement.$.header.innerText.trim());
336 337
337 // Site list should show, no matter what category default is set to. 338 // Site list should show, no matter what category default is set to.
338 assertFalse(testElement.$.category.hidden); 339 assertFalse(testElement.$.category.hidden);
339 browserProxy.resetResolver('getExceptionList'); 340 browserProxy.resetResolver('getExceptionList');
340 testElement.categoryEnabled = false; 341 testElement.categoryEnabled = false;
341 return browserProxy.whenCalled('getExceptionList').then( 342 return browserProxy.whenCalled('getExceptionList').then(
342 function(contentType) { 343 function(contentType) {
343 assertFalse(testElement.$.category.hidden); 344 assertFalse(testElement.$.category.hidden);
344 assertEquals('Exceptions - 2', testElement.$.header.innerText); 345 assertEquals('Exceptions - 2', testElement.$.header.innerText);
345 }); 346 });
346 }); 347 });
347 }); 348 });
348 349
349 test('initial BLOCK state is correct', function() { 350 test('initial BLOCK state is correct', function() {
350 setupLocationCategory(settings.PermissionValues.BLOCK, prefs); 351 setupLocationCategory(settings.PermissionValues.BLOCK, prefs);
351 return browserProxy.whenCalled('getExceptionList').then( 352 return browserProxy.whenCalled('getExceptionList').then(
352 function(contentType) { 353 function(contentType) {
353 assertEquals( 354 assertEquals(
354 settings.ContentSettingsTypes.GEOLOCATION, contentType); 355 settings.ContentSettingsTypes.GEOLOCATION, contentType);
355 356
356 assertEquals(2, testElement.sites.length); 357 assertEquals(2, testElement.sites.length);
357 assertEquals(prefs.exceptions.geolocation[3].origin, 358 assertEquals(prefs.exceptions.geolocation[3].origin,
358 testElement.sites[0].origin); 359 testElement.sites[0].origin);
359 360
360 assertEquals( 361 assertEquals(
361 settings.PermissionValues.BLOCK, testElement.categorySubtype); 362 settings.PermissionValues.BLOCK, testElement.categorySubtype);
362 Polymer.dom.flush(); // Populates action menu. 363 Polymer.dom.flush(); // Populates action menu.
363 assertMenuActionHidden(testElement, 'Block'); 364 assertMenuActionHidden(testElement, 'Block');
364 assertEquals('Block - 2', testElement.$.header.innerText); 365 assertEquals('Block - 2', testElement.$.header.innerText.trim());
365 366
366 // Site list should only show when category default is enabled. 367 // Site list should only show when category default is enabled.
367 assertFalse(testElement.$.category.hidden); 368 assertFalse(testElement.$.category.hidden);
368 browserProxy.resetResolver('getExceptionList'); 369 browserProxy.resetResolver('getExceptionList');
369 testElement.categoryEnabled = false; 370 testElement.categoryEnabled = false;
370 return browserProxy.whenCalled('getExceptionList').then( 371 return browserProxy.whenCalled('getExceptionList').then(
371 function(contentType) { 372 function(contentType) {
372 assertTrue(testElement.$.category.hidden); 373 assertTrue(testElement.$.category.hidden);
373 }); 374 });
374 }); 375 });
375 }); 376 });
376 377
377 test('list items shown and clickable when data is present', function() { 378 test('list items shown and clickable when data is present', function() {
378 setupLocationCategory(settings.PermissionValues.ALLOW, prefs); 379 setupLocationCategory(settings.PermissionValues.ALLOW, prefs);
379 return browserProxy.whenCalled('getExceptionList').then( 380 return browserProxy.whenCalled('getExceptionList').then(
380 function(contentType) { 381 function(contentType) {
381 assertEquals( 382 assertEquals(
382 settings.ContentSettingsTypes.GEOLOCATION, contentType); 383 settings.ContentSettingsTypes.GEOLOCATION, contentType);
383 384
384 // Required for firstItem to be found below. 385 // Required for firstItem to be found below.
385 Polymer.dom.flush(); 386 Polymer.dom.flush();
386 387
387 // Validate that the sites gets populated from pre-canned prefs. 388 // Validate that the sites gets populated from pre-canned prefs.
388 assertEquals(2, testElement.sites.length); 389 assertEquals(2, testElement.sites.length);
389 assertEquals(prefs.exceptions.geolocation[1].origin, 390 assertEquals(prefs.exceptions.geolocation[1].origin,
390 testElement.sites[0].origin); 391 testElement.sites[0].origin);
391 assertEquals(undefined, testElement.selectedOrigin); 392 assertEquals(undefined, testElement.selectedOrigin);
392 393
393 // Validate that the sites are shown in UI and can be selected. 394 // Validate that the sites are shown in UI and can be selected.
394 var firstItem = testElement.$.listContainer.items[0]; 395 var firstItem = testElement.$.listContainer.children[0];
395 var clickable = firstItem.querySelector('.flex paper-item-body'); 396 var clickable = firstItem.querySelector('.middle');
396 assertNotEquals(undefined, clickable); 397 assertNotEquals(undefined, clickable);
397 MockInteractions.tap(clickable); 398 MockInteractions.tap(clickable);
398 assertEquals(prefs.exceptions.geolocation[1].origin, 399 assertEquals(prefs.exceptions.geolocation[1].origin,
399 testElement.selectedSite.origin); 400 testElement.selectedSite.origin);
400 }); 401 });
401 }); 402 });
402 403
403 test('Block list open when Allow list is empty', function() { 404 test('Block list open when Allow list is empty', function() {
404 // Prefs: One item in Block list, nothing in Allow list. 405 // Prefs: One item in Block list, nothing in Allow list.
405 setupLocationCategory(settings.PermissionValues.BLOCK, 406 setupLocationCategory(settings.PermissionValues.BLOCK,
406 prefsOneDisabled); 407 prefsOneDisabled);
407 return browserProxy.whenCalled('getExceptionList').then( 408 return browserProxy.whenCalled('getExceptionList').then(
408 function(contentType) { 409 function(contentType) {
409 assertEquals( 410 assertEquals(
410 settings.ContentSettingsTypes.GEOLOCATION, contentType); 411 settings.ContentSettingsTypes.GEOLOCATION, contentType);
411 412
412 assertFalse(testElement.$.category.hidden); 413 assertFalse(testElement.$.category.hidden);
413 assertTrue(testElement.$.category.opened); 414 assertTrue(testElement.$.category.opened);
415 }).then(function() {
414 assertNotEquals(0, testElement.$.listContainer.offsetHeight); 416 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
415 }); 417 });
416 }); 418 });
417 419
418 test('Block list closed when Allow list is not empty', function() { 420 test('Block list closed when Allow list is not empty', function() {
419 // Prefs: Items in both Block and Allow list. 421 // Prefs: Items in both Block and Allow list.
420 setupLocationCategory(settings.PermissionValues.BLOCK, prefs); 422 setupLocationCategory(settings.PermissionValues.BLOCK, prefs);
421 return browserProxy.whenCalled('getExceptionList').then( 423 return browserProxy.whenCalled('getExceptionList').then(
422 function(contentType) { 424 function(contentType) {
423 assertEquals( 425 assertEquals(
424 settings.ContentSettingsTypes.GEOLOCATION, contentType); 426 settings.ContentSettingsTypes.GEOLOCATION, contentType);
425 427
426 assertFalse(testElement.$.category.hidden); 428 assertFalse(testElement.$.category.hidden);
427 assertFalse(testElement.$.category.opened); 429 assertFalse(testElement.$.category.opened);
428 assertEquals(0, testElement.$.listContainer.offsetHeight); 430 assertEquals(0, testElement.$.listContainer.offsetHeight);
429 }); 431 });
430 }); 432 });
431 433
432 test('Allow list is always open (Block list empty)', function() { 434 test('Allow list is always open (Block list empty)', function() {
433 // Prefs: One item in Allow list, nothing in Block list. 435 // Prefs: One item in Allow list, nothing in Block list.
434 setupLocationCategory( 436 setupLocationCategory(
435 settings.PermissionValues.ALLOW, prefsOneEnabled); 437 settings.PermissionValues.ALLOW, prefsOneEnabled);
436 return browserProxy.whenCalled('getExceptionList').then( 438 return browserProxy.whenCalled('getExceptionList').then(
437 function(contentType) { 439 function(contentType) {
438 assertEquals( 440 assertEquals(
439 settings.ContentSettingsTypes.GEOLOCATION, contentType); 441 settings.ContentSettingsTypes.GEOLOCATION, contentType);
440 442
441 assertFalse(testElement.$.category.hidden); 443 assertFalse(testElement.$.category.hidden);
442 assertTrue(testElement.$.category.opened); 444 assertTrue(testElement.$.category.opened);
445 }).then(function() {
443 assertNotEquals(0, testElement.$.listContainer.offsetHeight); 446 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
444 }); 447 });
445 }); 448 });
446 449
447 test('Allow list is always open (Block list non-empty)', function() { 450 test('Allow list is always open (Block list non-empty)', function() {
448 // Prefs: Items in both Block and Allow list. 451 // Prefs: Items in both Block and Allow list.
449 setupLocationCategory(settings.PermissionValues.ALLOW, prefs); 452 setupLocationCategory(settings.PermissionValues.ALLOW, prefs);
450 return browserProxy.whenCalled('getExceptionList').then( 453 return browserProxy.whenCalled('getExceptionList').then(
451 function(contentType) { 454 function(contentType) {
452 assertEquals( 455 assertEquals(
453 settings.ContentSettingsTypes.GEOLOCATION, contentType); 456 settings.ContentSettingsTypes.GEOLOCATION, contentType);
454 457
455 assertFalse(testElement.$.category.hidden); 458 assertFalse(testElement.$.category.hidden);
456 assertTrue(testElement.$.category.opened); 459 assertTrue(testElement.$.category.opened);
460 }).then(function() {
457 assertNotEquals(0, testElement.$.listContainer.offsetHeight); 461 assertNotEquals(0, testElement.$.listContainer.offsetHeight);
458 }); 462 });
459 }); 463 });
460 464
461 test('Block list hidden when empty', function() { 465 test('Block list hidden when empty', function() {
462 // Prefs: One item in Allow list, nothing in Block list. 466 // Prefs: One item in Allow list, nothing in Block list.
463 setupLocationCategory( 467 setupLocationCategory(
464 settings.PermissionValues.BLOCK, prefsOneEnabled); 468 settings.PermissionValues.BLOCK, prefsOneEnabled);
465 return browserProxy.whenCalled('getExceptionList').then( 469 return browserProxy.whenCalled('getExceptionList').then(
466 function(contentType) { 470 function(contentType) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 'de-duping of sites is not working for site_list'); 514 'de-duping of sites is not working for site_list');
511 assertEquals(prefsVarious.exceptions.geolocation[1].origin, 515 assertEquals(prefsVarious.exceptions.geolocation[1].origin,
512 testElement.sites[0].origin); 516 testElement.sites[0].origin);
513 assertEquals(prefsVarious.exceptions.geolocation[0].origin, 517 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
514 testElement.sites[1].origin); 518 testElement.sites[1].origin);
515 assertEquals(prefsVarious.exceptions.notifications[0].origin, 519 assertEquals(prefsVarious.exceptions.notifications[0].origin,
516 testElement.sites[2].origin); 520 testElement.sites[2].origin);
517 assertEquals(undefined, testElement.selectedOrigin); 521 assertEquals(undefined, testElement.selectedOrigin);
518 522
519 // Validate that the sites are shown in UI and can be selected. 523 // Validate that the sites are shown in UI and can be selected.
520 var firstItem = testElement.$.listContainer.items[1]; 524 var firstItem = testElement.$.listContainer.children[1];
521 var clickable = firstItem.querySelector('.flex paper-item-body'); 525 var clickable = firstItem.querySelector('.middle');
522 assertNotEquals(undefined, clickable); 526 assertNotEquals(undefined, clickable);
523 MockInteractions.tap(clickable); 527 MockInteractions.tap(clickable);
524 assertEquals(prefsVarious.exceptions.geolocation[0].origin, 528 assertEquals(prefsVarious.exceptions.geolocation[0].origin,
525 testElement.selectedSite.origin); 529 testElement.selectedSite.origin);
526 }); 530 });
527 }); 531 });
528 }); 532 });
529 533
530 test('All sites mixed pattern and origin', function() { 534 test('All sites mixed pattern and origin', function() {
531 // Prefs: One site, represented as origin and pattern. 535 // Prefs: One site, represented as origin and pattern.
(...skipping 18 matching lines...) Expand all
550 // Validate that the sites gets populated from pre-canned prefs. 554 // Validate that the sites gets populated from pre-canned prefs.
551 assertEquals(1, testElement.sites.length, 555 assertEquals(1, testElement.sites.length,
552 'If this fails with 2 instead of the expected 1, then the ' + 556 'If this fails with 2 instead of the expected 1, then the ' +
553 'de-duping of sites is not working for site_list'); 557 'de-duping of sites is not working for site_list');
554 assertEquals( 558 assertEquals(
555 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin, 559 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
556 testElement.sites[0].originForDisplay); 560 testElement.sites[0].originForDisplay);
557 561
558 assertEquals(undefined, testElement.selectedOrigin); 562 assertEquals(undefined, testElement.selectedOrigin);
559 // Validate that the sites are shown in UI and can be selected. 563 // Validate that the sites are shown in UI and can be selected.
560 var firstItem = testElement.$.listContainer.items[0]; 564 var firstItem = testElement.$.listContainer.children[0];
561 var clickable = firstItem.querySelector('.flex paper-item-body'); 565 var clickable = firstItem.querySelector('.middle');
562 assertNotEquals(undefined, clickable); 566 assertNotEquals(undefined, clickable);
563 MockInteractions.tap(clickable); 567 MockInteractions.tap(clickable);
564 assertEquals( 568 assertEquals(
565 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin, 569 prefsMixedOriginAndPattern.exceptions.geolocation[0].origin,
566 testElement.selectedSite.originForDisplay); 570 testElement.selectedSite.originForDisplay);
567 }); 571 });
568 }); 572 });
569 }); 573 });
570 574
571 test('Mixed schemes (present and absent)', function() { 575 test('Mixed schemes (present and absent)', function() {
572 // Prefs: One item with scheme and one without. 576 // Prefs: One item with scheme and one without.
573 setupLocationCategory(settings.PermissionValues.ALLOW, 577 setupLocationCategory(settings.PermissionValues.ALLOW,
574 prefsMixedSchemes); 578 prefsMixedSchemes);
575 return browserProxy.whenCalled('getExceptionList').then( 579 return browserProxy.whenCalled('getExceptionList').then(
576 function(contentType) { 580 function(contentType) {
577 // No further checks needed. If this fails, it will hang the test. 581 // No further checks needed. If this fails, it will hang the test.
578 }); 582 });
579 }); 583 });
580 }); 584 });
581 } 585 }
582 return { 586 return {
583 registerTests: registerTests, 587 registerTests: registerTests,
584 }; 588 };
585 }); 589 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/site_settings/site_settings_category.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698