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 protocol_handlers. */ | 5 /** @fileoverview Suite of tests for protocol_handlers. */ |
dschuyler
2017/05/03 00:42:41
The cr.define wrapper was removed.
The rest of the
| |
6 cr.define('protocol_handlers', function() { | 6 suite('ProtocolHandlers', function() { |
7 function registerTests() { | 7 /** |
8 suite('ProtocolHandlers', function() { | 8 * A dummy protocol handler element created before each test. |
9 /** | 9 * @type {ProtocolHandlers} |
10 * A dummy protocol handler element created before each test. | 10 */ |
11 * @type {ProtocolHandlers} | 11 var testElement; |
12 */ | |
13 var testElement; | |
14 | 12 |
15 /** | 13 /** |
16 * A list of ProtocolEntry fixtures. | 14 * A list of ProtocolEntry fixtures. |
17 * @type {!Array<!ProtocolEntry>} | 15 * @type {!Array<!ProtocolEntry>} |
18 */ | 16 */ |
19 var protocols = [ | 17 var protocols = [ |
18 { | |
19 default_handler: 0, | |
20 handlers: [{ | |
21 host: 'www.google.com', | |
22 protocol: 'mailto', | |
23 spec: 'http://www.google.com/%s' | |
24 }], | |
25 has_policy_recommendations: false, | |
26 is_default_handler_set_by_user: true, | |
27 protocol: 'mailto' | |
28 }, | |
29 { | |
30 default_handler: 0, | |
31 handlers: [ | |
20 { | 32 { |
21 default_handler: 0, | 33 host: 'www.google1.com', |
22 handlers: [ | 34 protocol: 'webcal', |
23 { | 35 spec: 'http://www.google1.com/%s' |
24 host: 'www.google.com', | 36 }, |
25 protocol: 'mailto', | 37 { |
26 spec: 'http://www.google.com/%s' | 38 host: 'www.google2.com', |
27 } | 39 protocol: 'webcal', |
28 ], | 40 spec: 'http://www.google2.com/%s' |
29 has_policy_recommendations: false, | |
30 is_default_handler_set_by_user: true, | |
31 protocol: 'mailto' | |
32 }, { | |
33 default_handler: 0, | |
34 handlers: [ | |
35 { | |
36 host: 'www.google1.com', | |
37 protocol: 'webcal', | |
38 spec: 'http://www.google1.com/%s' | |
39 }, { | |
40 host: 'www.google2.com', | |
41 protocol: 'webcal', | |
42 spec: 'http://www.google2.com/%s' | |
43 } | |
44 ], | |
45 has_policy_recommendations: false, | |
46 is_default_handler_set_by_user: true, | |
47 protocol: 'webcal' | |
48 } | 41 } |
49 ]; | 42 ], |
43 has_policy_recommendations: false, | |
44 is_default_handler_set_by_user: true, | |
45 protocol: 'webcal' | |
46 } | |
47 ]; | |
50 | 48 |
51 /** | 49 /** |
52 * The mock proxy object to use during test. | 50 * The mock proxy object to use during test. |
53 * @type {TestSiteSettingsPrefsBrowserProxy} | 51 * @type {TestSiteSettingsPrefsBrowserProxy} |
54 */ | 52 */ |
55 var browserProxy = null; | 53 var browserProxy = null; |
56 | 54 |
57 setup(function() { | 55 setup(function() { |
58 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | 56 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
59 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; | 57 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
60 }); | 58 }); |
61 | 59 |
62 teardown(function() { | 60 teardown(function() { |
63 testElement.remove(); | 61 testElement.remove(); |
64 testElement = null; | 62 testElement = null; |
65 }); | 63 }); |
66 | 64 |
67 /** @return {!Promise} */ | 65 /** @return {!Promise} */ |
68 function initPage() { | 66 function initPage() { |
69 browserProxy.reset(); | 67 browserProxy.reset(); |
70 PolymerTest.clearBody(); | 68 PolymerTest.clearBody(); |
71 testElement = document.createElement('protocol-handlers'); | 69 testElement = document.createElement('protocol-handlers'); |
72 document.body.appendChild(testElement); | 70 document.body.appendChild(testElement); |
73 return browserProxy.whenCalled('observeProtocolHandlers'). | 71 return browserProxy.whenCalled('observeProtocolHandlers') |
74 then(Polymer.dom.flush.bind(Polymer.dom)); | 72 .then(Polymer.dom.flush.bind(Polymer.dom)); |
75 } | 73 } |
76 | 74 |
77 test('empty list', function() { | 75 test('empty list', function() { |
78 return initPage().then(function(){ | 76 return initPage().then(function() { |
79 var listFrames = testElement.root.querySelectorAll('.list-frame'); | 77 var listFrames = testElement.root.querySelectorAll('.list-frame'); |
80 assertEquals(0, listFrames.length); | 78 assertEquals(0, listFrames.length); |
81 }); | 79 }); |
82 }); | 80 }); |
83 | 81 |
84 test('non-empty list', function() { | 82 test('non-empty list', function() { |
85 browserProxy.setProtocolHandlers(protocols); | 83 browserProxy.setProtocolHandlers(protocols); |
86 | 84 |
87 return initPage().then(function(){ | 85 return initPage().then(function() { |
88 var listFrames = testElement.root.querySelectorAll('.list-frame'); | 86 var listFrames = testElement.root.querySelectorAll('.list-frame'); |
89 var listItems = testElement.root.querySelectorAll('.list-item'); | 87 var listItems = testElement.root.querySelectorAll('.list-item'); |
90 // There are two protocols: ["mailto", "webcal"]. | 88 // There are two protocols: ["mailto", "webcal"]. |
91 assertEquals(2, listFrames.length); | 89 assertEquals(2, listFrames.length); |
92 // There are three total handlers within the two protocols. | 90 // There are three total handlers within the two protocols. |
93 assertEquals(3, listItems.length); | 91 assertEquals(3, listItems.length); |
94 | 92 |
95 // Check that item hosts are rendered correctly. | 93 // Check that item hosts are rendered correctly. |
96 var hosts = testElement.root.querySelectorAll('.protocol-host'); | 94 var hosts = testElement.root.querySelectorAll('.protocol-host'); |
97 assertEquals('www.google.com', hosts[0].textContent); | 95 assertEquals('www.google.com', hosts[0].textContent); |
98 assertEquals('www.google1.com', hosts[1].textContent); | 96 assertEquals('www.google1.com', hosts[1].textContent); |
99 assertEquals('www.google2.com', hosts[2].textContent); | 97 assertEquals('www.google2.com', hosts[2].textContent); |
100 | 98 |
101 // Check that item default subtexts are rendered correctly. | 99 // Check that item default subtexts are rendered correctly. |
102 var defText = testElement.root.querySelectorAll('.protocol-default'); | 100 var defText = testElement.root.querySelectorAll('.protocol-default'); |
103 assertFalse(defText[0].hidden); | 101 assertFalse(defText[0].hidden); |
104 assertFalse(defText[1].hidden); | 102 assertFalse(defText[1].hidden); |
105 assertTrue(defText[2].hidden); | 103 assertTrue(defText[2].hidden); |
106 }); | 104 }); |
107 }); | 105 }); |
108 | 106 |
109 /** | 107 /** |
110 * A reusable function to test different action buttons. | 108 * A reusable function to test different action buttons. |
111 * @param {string} button id of the button to test. | 109 * @param {string} button id of the button to test. |
112 * @param {string} handler name of browserProxy handler to react. | 110 * @param {string} handler name of browserProxy handler to react. |
113 * @return {!Promise} | 111 * @return {!Promise} |
114 */ | 112 */ |
115 function testButtonFlow(button, browserProxyHandler) { | 113 function testButtonFlow(button, browserProxyHandler) { |
116 var menuButtons, functionButton, dialog; | 114 var menuButtons, functionButton, dialog; |
117 | 115 |
118 return initPage().then(function(){ | 116 return initPage() |
117 .then(function() { | |
119 // Initiating the elements | 118 // Initiating the elements |
120 menuButtons = testElement.root. | 119 menuButtons = testElement.root.querySelectorAll('paper-icon-button'); |
121 querySelectorAll('paper-icon-button'); | |
122 functionButton = testElement.$[button]; | 120 functionButton = testElement.$[button]; |
123 dialog = testElement.$$('dialog[is=cr-action-menu]'); | 121 dialog = testElement.$$('dialog[is=cr-action-menu]'); |
124 assertEquals(3, menuButtons.length); | 122 assertEquals(3, menuButtons.length); |
125 | 123 |
126 // Test the button for the first protocol handler | 124 // Test the button for the first protocol handler |
127 MockInteractions.tap(menuButtons[0]); | 125 MockInteractions.tap(menuButtons[0]); |
128 assertTrue(dialog.open); | 126 assertTrue(dialog.open); |
129 | 127 |
130 MockInteractions.tap(functionButton); | 128 MockInteractions.tap(functionButton); |
131 | 129 |
132 return browserProxy.whenCalled(browserProxyHandler); | 130 return browserProxy.whenCalled(browserProxyHandler); |
133 }).then(function(args) { | 131 }) |
132 .then(function(args) { | |
134 // BrowserProxy's handler is expected to be called with arguments as | 133 // BrowserProxy's handler is expected to be called with arguments as |
135 // [protocol, url]. | 134 // [protocol, url]. |
136 assertEquals(protocols[0].protocol, args[0]); | 135 assertEquals(protocols[0].protocol, args[0]); |
137 assertEquals(protocols[0].handlers[0].spec, args[1]); | 136 assertEquals(protocols[0].handlers[0].spec, args[1]); |
138 | 137 |
139 var dialog = testElement.$$('dialog[is=cr-action-menu]'); | 138 var dialog = testElement.$$('dialog[is=cr-action-menu]'); |
140 assertFalse(dialog.open); | 139 assertFalse(dialog.open); |
141 | 140 |
142 // Test the button for the second protocol handler | 141 // Test the button for the second protocol handler |
143 browserProxy.reset(); | 142 browserProxy.reset(); |
144 MockInteractions.tap(menuButtons[1]); | 143 MockInteractions.tap(menuButtons[1]); |
145 assertTrue(dialog.open); | 144 assertTrue(dialog.open); |
146 MockInteractions.tap(functionButton); | 145 MockInteractions.tap(functionButton); |
147 | 146 |
148 return browserProxy.whenCalled(browserProxyHandler); | 147 return browserProxy.whenCalled(browserProxyHandler); |
149 }).then(function(args) { | 148 }) |
149 .then(function(args) { | |
150 assertEquals(protocols[1].protocol, args[0]); | 150 assertEquals(protocols[1].protocol, args[0]); |
151 assertEquals(protocols[1].handlers[0].spec, args[1]); | 151 assertEquals(protocols[1].handlers[0].spec, args[1]); |
152 }); | 152 }); |
153 } | |
154 | |
155 test('remove button works', function() { | |
156 browserProxy.setProtocolHandlers(protocols); | |
157 return testButtonFlow('removeButton', 'removeProtocolHandler'); | |
158 }); | |
159 | |
160 test('default button works', function() { | |
161 browserProxy.setProtocolHandlers(protocols); | |
162 return testButtonFlow('defaultButton', 'setProtocolDefault'); | |
163 }); | |
164 }); | |
165 } | 153 } |
166 | 154 |
167 return { | 155 test('remove button works', function() { |
168 registerTests: registerTests, | 156 browserProxy.setProtocolHandlers(protocols); |
169 }; | 157 return testButtonFlow('removeButton', 'removeProtocolHandler'); |
158 }); | |
159 | |
160 test('default button works', function() { | |
161 browserProxy.setProtocolHandlers(protocols); | |
162 return testButtonFlow('defaultButton', 'setProtocolDefault'); | |
163 }); | |
170 }); | 164 }); |
OLD | NEW |