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