Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** @fileoverview Suite of tests for site-list. */ | 5 /** @fileoverview Suite of tests for site-list. */ |
| 6 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 // Initialize a site-list before each test. | 261 // Initialize a site-list before each test. |
| 262 setup(function() { | 262 setup(function() { |
| 263 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | 263 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
| 264 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; | 264 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
| 265 PolymerTest.clearBody(); | 265 PolymerTest.clearBody(); |
| 266 testElement = document.createElement('settings-site-list'); | 266 testElement = document.createElement('settings-site-list'); |
| 267 document.body.appendChild(testElement); | 267 document.body.appendChild(testElement); |
| 268 }); | 268 }); |
| 269 | 269 |
| 270 /** | 270 /** |
| 271 * Fetch the non-hidden menu items from the list. | |
| 272 * @param {!HTMLElement} parentElement | |
| 273 */ | |
| 274 function getMenuItems(listContainer) { | |
| 275 return listContainer.children[0].querySelectorAll( | |
| 276 'paper-menu-button paper-item:not([hidden])'); | |
| 277 } | |
| 278 | |
| 279 /** | |
| 271 * Asserts the menu looks as expected. | 280 * Asserts the menu looks as expected. |
| 272 * @param {Array<string>} items The items expected to show in the menu. | 281 * @param {Array<string>} items The items expected to show in the menu. |
| 273 * @param {!HTMLElement} parentElement The parent node to start looking | 282 * @param {!HTMLElement} parentElement The parent node to start looking |
| 274 * in. | 283 * in. |
| 275 */ | 284 */ |
| 276 function assertMenu(items, parentElement) { | 285 function assertMenu(items, parentElement) { |
| 277 var listItem = parentElement.$.listContainer.children[0]; | 286 var menuItems = getMenuItems(parentElement.$.listContainer); |
| 278 var menuItems = listItem.querySelectorAll( | |
| 279 'paper-menu-button paper-item:not([hidden])'); | |
| 280 assertEquals(items.length, menuItems.length); | 287 assertEquals(items.length, menuItems.length); |
| 281 for (var i = 0; i < items.length; i++) | 288 for (var i = 0; i < items.length; i++) |
| 282 assertEquals(items[i], menuItems[i].textContent.trim()); | 289 assertEquals(items[i], menuItems[i].textContent.trim()); |
| 283 } | 290 } |
| 284 | 291 |
| 285 /** | 292 /** |
| 286 * Configures the test element for a particular category. | 293 * Configures the test element for a particular category. |
| 287 * @param {settings.ContentSettingsTypes} category The category to setup. | 294 * @param {settings.ContentSettingsTypes} category The category to setup. |
| 288 * @param {settings.PermissionValues} subtype Type of list to use. | 295 * @param {settings.PermissionValues} subtype Type of list to use. |
| 289 * @param {Array<dictionary>} prefs The prefs to use. | 296 * @param {Array<dictionary>} prefs The prefs to use. |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 | 641 |
| 635 test('Mixed schemes (present and absent)', function() { | 642 test('Mixed schemes (present and absent)', function() { |
| 636 // Prefs: One item with scheme and one without. | 643 // Prefs: One item with scheme and one without. |
| 637 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, | 644 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, |
| 638 settings.PermissionValues.ALLOW, prefsMixedSchemes); | 645 settings.PermissionValues.ALLOW, prefsMixedSchemes); |
| 639 return browserProxy.whenCalled('getExceptionList').then( | 646 return browserProxy.whenCalled('getExceptionList').then( |
| 640 function(contentType) { | 647 function(contentType) { |
| 641 // No further checks needed. If this fails, it will hang the test. | 648 // No further checks needed. If this fails, it will hang the test. |
| 642 }); | 649 }); |
| 643 }); | 650 }); |
| 651 | |
| 652 test('Select menu item', function() { | |
| 653 // Test for error: "Cannot read property 'origin' of undefined". | |
| 654 setupCategory(settings.ContentSettingsTypes.GEOLOCATION, | |
| 655 settings.PermissionValues.ALLOW, prefs); | |
| 656 return browserProxy.whenCalled('getExceptionList').then(function( | |
| 657 contentType) { | |
| 658 Polymer.dom.flush(); | |
| 659 var menuItems = getMenuItems(testElement.$.listContainer); | |
| 660 assertTrue(!!menuItems); | |
| 661 MockInteractions.tap(menuItems[0]); | |
| 662 return Promise.race([ | |
|
tommycli
2016/08/11 22:46:24
Since we control the test data, we know which of t
dschuyler
2016/08/11 22:56:39
Done.
| |
| 663 browserProxy.whenCalled('resetCategoryPermissionForOrigin'), | |
| 664 browserProxy.whenCalled('setCategoryPermissionForOrigin'), | |
| 665 ]).then(function(contentType) { | |
|
tommycli
2016/08/11 22:46:24
no need for 'then'
dschuyler
2016/08/11 22:56:39
Done.
| |
| 666 // Nothing to do here. | |
| 667 }); | |
| 668 }); | |
| 669 }); | |
| 644 }); | 670 }); |
| 645 } | 671 } |
| 646 return { | 672 return { |
| 647 registerTests: registerTests, | 673 registerTests: registerTests, |
| 648 }; | 674 }; |
| 649 }); | 675 }); |
| OLD | NEW |