OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** @fileoverview Suite of tests for zoom-levels. */ |
| 6 cr.define('zoom_levels', function() { |
| 7 function registerTests() { |
| 8 suite('ZoomLevels', function() { |
| 9 /** |
| 10 * A zoom levels category created before each test. |
| 11 * @type {ZoomLevels} |
| 12 */ |
| 13 var testElement; |
| 14 |
| 15 /** |
| 16 * The mock proxy object to use during test. |
| 17 * @type {TestSiteSettingsPrefsBrowserProxy} |
| 18 */ |
| 19 var browserProxy = null; |
| 20 |
| 21 /** |
| 22 * An example zoom list. |
| 23 * @type {!Array<ZoomLevelEntry>} |
| 24 */ |
| 25 var zoomList = [ |
| 26 { |
| 27 origin: 'http://www.google.com', |
| 28 setting: '', |
| 29 source: '', |
| 30 zoom: '125%', |
| 31 }, |
| 32 { |
| 33 origin: 'http://www.chromium.org', |
| 34 setting: '', |
| 35 source: '', |
| 36 zoom: '125%', |
| 37 }, |
| 38 ]; |
| 39 |
| 40 // Import necessary html before running suite. |
| 41 suiteSetup(function() { |
| 42 return PolymerTest.importHtml( |
| 43 'chrome://md-settings/site_settings/zoom_levels.html'); |
| 44 }); |
| 45 |
| 46 setup(function() { |
| 47 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
| 48 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
| 49 return initPage(); |
| 50 }); |
| 51 |
| 52 teardown(function() { |
| 53 testElement.remove(); |
| 54 testElement = null; |
| 55 }); |
| 56 |
| 57 /** @return {!Promise} */ |
| 58 function initPage() { |
| 59 browserProxy.reset(); |
| 60 PolymerTest.clearBody(); |
| 61 testElement = document.createElement('zoom-levels'); |
| 62 document.body.appendChild(testElement); |
| 63 return browserProxy.whenCalled('fetchZoomLevels'); |
| 64 } |
| 65 |
| 66 /** |
| 67 * Fetch the remove button from the list. |
| 68 * @param {!HTMLElement} listContainer The list to use for the lookup. |
| 69 * @param {number} index The index of the child element (which site) to |
| 70 * fetch. |
| 71 */ |
| 72 function getRemoveButton(listContainer, index) { |
| 73 return listContainer.children[index].querySelector('paper-icon-button'); |
| 74 } |
| 75 |
| 76 test('empty zoom state', function() { |
| 77 var list = testElement.$.list; |
| 78 assertTrue(!!list); |
| 79 assertEquals(0, list.items.length); |
| 80 }); |
| 81 |
| 82 test('non-empty zoom state', function() { |
| 83 browserProxy.setZoomList(zoomList); |
| 84 |
| 85 return initPage().then(function() { |
| 86 var list = testElement.$.list; |
| 87 assertTrue(!!list); |
| 88 assertEquals(2, list.items.length); |
| 89 |
| 90 var removeButton = |
| 91 getRemoveButton(testElement.$.listContainer, 0); |
| 92 assert(!!removeButton); |
| 93 MockInteractions.tap(removeButton); |
| 94 return browserProxy.whenCalled('removeZoomLevel'); |
| 95 }).then(function(arguments) { |
| 96 assertEquals("http://www.google.com", arguments[0]); |
| 97 }); |
| 98 }); |
| 99 }); |
| 100 } |
| 101 |
| 102 return { |
| 103 registerTests: registerTests, |
| 104 }; |
| 105 }); |
OLD | NEW |