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 route-details. */ | 5 /** @fileoverview Suite of tests for route-details. */ |
6 cr.define('route_details', function() { | 6 cr.define('route_details', function() { |
7 function registerTests() { | 7 function registerTests() { |
8 suite('RouteDetails', function() { | 8 suite('RouteDetails', function() { |
9 /** | 9 /** |
10 * Route Details created before each test. | 10 * Route Details created before each test. |
11 * @type {RouteDetails} | 11 * @type {RouteDetails} |
12 */ | 12 */ |
13 var details; | 13 var details; |
14 | 14 |
15 /** | 15 /** |
16 * First fake route created before each test. | 16 * First fake route created before each test. |
17 * @type {media_router.Route} | 17 * @type {media_router.Route} |
18 */ | 18 */ |
19 var fakeRouteOne; | 19 var fakeRouteOne; |
20 | 20 |
21 /** | 21 /** |
22 * Second fake route created before each test. | 22 * Second fake route created before each test. |
23 * @type {media_router.Route} | 23 * @type {media_router.Route} |
24 */ | 24 */ |
25 var fakeRouteTwo; | 25 var fakeRouteTwo; |
26 | 26 |
27 // Checks whether |expected| and the text in the span element in | |
28 // the |elementId| element are equal. | |
29 var checkSpanText = function(expected, elementId) { | |
30 assertEquals(expected, | |
31 details.$[elementId].querySelector('span').innerText); | |
32 }; | |
33 | |
34 // Checks the default route view is shown. | |
35 var checkDefaultViewIsShown = function() { | |
36 assertFalse(details.$['route-information'].hasAttribute('hidden')); | |
37 assertTrue(details.$['custom-controller'].hasAttribute('hidden')); | |
38 }; | |
39 | |
40 // Checks the default route view is shown. | |
41 var checkStartCastButtonIsShown = function() { | |
42 assertFalse( | |
43 details.$['start-casting-to-route-button'].hasAttribute('hidden')); | |
44 }; | |
45 | |
46 // Checks the default route view is not shown. | |
47 var checkStartCastButtonIsNotShown = function() { | |
48 assertTrue( | |
49 details.$['start-casting-to-route-button'].hasAttribute('hidden')); | |
50 }; | |
51 | |
52 // Checks the custom controller is shown. | |
53 var checkCustomControllerIsShown = function() { | |
54 assertTrue(details.$['route-information'].hasAttribute('hidden')); | |
55 assertFalse(details.$['custom-controller'].hasAttribute('hidden')); | |
56 }; | |
57 | |
58 // Checks whether |expected| and the text in the |elementId| element | |
59 // are equal given an id. | |
60 var checkElementTextWithId = function(expected, elementId) { | |
61 assertEquals(expected, details.$[elementId].innerText); | |
62 }; | |
63 | |
64 /** | 27 /** |
65 * Fake sink that corresponds to |fakeRouteOne|. | 28 * Fake sink that corresponds to |fakeRouteOne|. |
66 * @type {media_router.Sink} | 29 * @type {media_router.Sink} |
67 */ | 30 */ |
68 var fakeSinkOne; | 31 var fakeSinkOne; |
69 | 32 |
| 33 // Checks whether |expected| and the text in the span element in |
| 34 // the |elementId| element are equal. |
| 35 var checkSpanText = function(expected, elementId) { |
| 36 assertEquals( |
| 37 expected, |
| 38 details.$$('#' + elementId).querySelector('span').innerText); |
| 39 }; |
| 40 |
| 41 // Checks the default route view is shown. |
| 42 var checkDefaultViewIsShown = function() { |
| 43 assertFalse(details.$$('#route-information').hasAttribute('hidden')); |
| 44 assertTrue(details.$$('extension-view-wrapper').hasAttribute('hidden')); |
| 45 }; |
| 46 |
| 47 // Checks the start button is shown. |
| 48 var checkStartCastButtonIsShown = function() { |
| 49 assertFalse(details.$$('#start-casting-to-route-button') |
| 50 .hasAttribute('hidden')); |
| 51 }; |
| 52 |
| 53 // Checks the start button is not shown. |
| 54 var checkStartCastButtonIsNotShown = function() { |
| 55 assertTrue(details.$$('#start-casting-to-route-button') |
| 56 .hasAttribute('hidden')); |
| 57 }; |
| 58 |
| 59 // Checks the custom controller is shown. |
| 60 var checkCustomControllerIsShown = function() { |
| 61 assertTrue(details.$$('#route-information').hasAttribute('hidden')); |
| 62 assertFalse( |
| 63 details.$$('extension-view-wrapper').hasAttribute('hidden')); |
| 64 }; |
| 65 |
| 66 // Checks whether |expected| and the text in the |elementId| element |
| 67 // are equal given an id. |
| 68 var checkElementTextWithId = function(expected, elementId) { |
| 69 assertEquals(expected, details.$$('#' + elementId).innerText); |
| 70 }; |
| 71 |
70 // Import route_details.html before running suite. | 72 // Import route_details.html before running suite. |
71 suiteSetup(function() { | 73 suiteSetup(function() { |
72 return PolymerTest.importHtml( | 74 return PolymerTest.importHtml( |
73 'chrome://media-router/elements/route_details/' + | 75 'chrome://media-router/elements/route_details/' + |
74 'route_details.html'); | 76 'route_details.html'); |
75 }); | 77 }); |
76 | 78 |
77 // Initialize a route-details before each test. | 79 // Initialize a route-details before each test. |
78 setup(function(done) { | 80 setup(function(done) { |
79 PolymerTest.clearBody(); | 81 PolymerTest.clearBody(); |
80 details = document.createElement('route-details'); | 82 details = document.createElement('route-details'); |
| 83 details.useWebUiRouteControls = false; |
81 document.body.appendChild(details); | 84 document.body.appendChild(details); |
82 | 85 |
83 // Initialize routes and sinks. | 86 // Initialize routes and sinks. |
84 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1', | 87 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1', |
85 'Video 1', 1, true, false, | 88 'Video 1', 1, true, false, |
86 'chrome-extension://123/custom_view.html'); | 89 'chrome-extension://123/custom_view.html'); |
87 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2', | 90 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2', |
88 'Video 2', 2, false, true); | 91 'Video 2', 2, false, true); |
89 fakeSinkOne = new media_router.Sink( | 92 fakeSinkOne = new media_router.Sink( |
90 'sink id 1', 'sink 1', 'description', null, | 93 'sink id 1', 'sink 1', 'description', null, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 details.isAnySinkCurrentlyLaunching = false; | 136 details.isAnySinkCurrentlyLaunching = false; |
134 checkStartCastButtonIsShown(); | 137 checkStartCastButtonIsShown(); |
135 }); | 138 }); |
136 | 139 |
137 // Tests for 'close-route-click' event firing when the | 140 // Tests for 'close-route-click' event firing when the |
138 // 'close-route-button' button is clicked. | 141 // 'close-route-button' button is clicked. |
139 test('close route button click', function(done) { | 142 test('close route button click', function(done) { |
140 details.addEventListener('close-route', function() { | 143 details.addEventListener('close-route', function() { |
141 done(); | 144 done(); |
142 }); | 145 }); |
143 MockInteractions.tap(details.$['close-route-button']); | 146 MockInteractions.tap(details.$$('#close-route-button')); |
144 }); | 147 }); |
145 | 148 |
146 // Tests for 'join-route-click' event firing when the | 149 // Tests for 'join-route-click' event firing when the |
147 // 'start-casting-to-route-button' button is clicked when the current | 150 // 'start-casting-to-route-button' button is clicked when the current |
148 // route is joinable. | 151 // route is joinable. |
149 test('start casting to route button click', function(done) { | 152 test('start casting to route button click', function(done) { |
150 details.addEventListener('join-route-click', function() { done(); }); | 153 details.addEventListener('join-route-click', function() { done(); }); |
151 details.route = fakeRouteTwo; | 154 details.route = fakeRouteTwo; |
152 MockInteractions.tap(details.$['start-casting-to-route-button']); | 155 MockInteractions.tap(details.$$('#start-casting-to-route-button')); |
153 }); | 156 }); |
154 | 157 |
155 // Tests for 'replace-route-click' event firing when the | 158 // Tests for 'replace-route-click' event firing when the |
156 // 'start-casting-to-route-button' button is clicked when the current | 159 // 'start-casting-to-route-button' button is clicked when the current |
157 // route is not joinable. | 160 // route is not joinable. |
158 test('start casting button click replaces route', function(done) { | 161 test('start casting button click replaces route', function(done) { |
159 details.addEventListener( | 162 details.addEventListener( |
160 'change-route-source-click', function() { done(); }); | 163 'change-route-source-click', function() { done(); }); |
161 details.route = fakeRouteOne; | 164 details.route = fakeRouteOne; |
162 details.availableCastModes = 1; | 165 details.availableCastModes = 1; |
163 MockInteractions.tap(details.$['start-casting-to-route-button']); | 166 MockInteractions.tap(details.$$('#start-casting-to-route-button')); |
164 }); | 167 }); |
165 | 168 |
166 // Tests the initial expected text. | 169 // Tests the initial expected text. |
167 test('initial text setting', function() { | 170 test('initial text setting', function() { |
168 // <paper-button> text is styled as upper case. | 171 // <paper-button> text is styled as upper case. |
169 checkSpanText(loadTimeData.getString('stopCastingButtonText') | 172 checkSpanText(loadTimeData.getString('stopCastingButtonText') |
170 .toUpperCase(), 'close-route-button'); | 173 .toUpperCase(), 'close-route-button'); |
171 checkSpanText( | 174 checkSpanText( |
172 loadTimeData.getString('startCastingButtonText').toUpperCase(), | 175 loadTimeData.getString('startCastingButtonText').toUpperCase(), |
173 'start-casting-to-route-button'); | 176 'start-casting-to-route-button'); |
(...skipping 18 matching lines...) Expand all Loading... |
192 details.route = fakeRouteTwo; | 195 details.route = fakeRouteTwo; |
193 assertEquals(fakeRouteTwo, details.route); | 196 assertEquals(fakeRouteTwo, details.route); |
194 checkSpanText(loadTimeData.getStringF('castingActivityStatus', | 197 checkSpanText(loadTimeData.getStringF('castingActivityStatus', |
195 fakeRouteTwo.description), 'route-information'); | 198 fakeRouteTwo.description), 'route-information'); |
196 checkDefaultViewIsShown(); | 199 checkDefaultViewIsShown(); |
197 checkStartCastButtonIsShown(); | 200 checkStartCastButtonIsShown(); |
198 }); | 201 }); |
199 | 202 |
200 // Tests when |route| exists, has a custom controller, and it loads. | 203 // Tests when |route| exists, has a custom controller, and it loads. |
201 test('route has custom controller and loading succeeds', function(done) { | 204 test('route has custom controller and loading succeeds', function(done) { |
202 var loadInvoked = false; | 205 details.$$('extension-view-wrapper').$$('#custom-controller').load = |
203 details.$['custom-controller'].load = function(url) { | 206 function(url) { |
204 loadInvoked = true; | 207 setTimeout(function() { |
205 assertEquals('chrome-extension://123/custom_view.html', url); | 208 assertEquals('chrome-extension://123/custom_view.html', url); |
| 209 checkCustomControllerIsShown(); |
| 210 done(); |
| 211 }); |
206 return Promise.resolve(); | 212 return Promise.resolve(); |
207 }; | 213 }; |
208 | 214 |
209 details.route = fakeRouteOne; | 215 details.route = fakeRouteOne; |
210 setTimeout(function() { | |
211 assertTrue(loadInvoked); | |
212 checkCustomControllerIsShown(); | |
213 done(); | |
214 }); | |
215 }); | 216 }); |
216 | 217 |
217 // Tests when |route| exists, has a custom controller, but fails to load. | 218 // Tests when |route| exists, has a custom controller, but fails to load. |
218 test('route has custom controller but loading fails', function(done) { | 219 test('route has custom controller but loading fails', function(done) { |
219 var loadInvoked = false; | 220 details.$$('extension-view-wrapper').$$('#custom-controller').load = |
220 details.$['custom-controller'].load = function(url) { | 221 function(url) { |
221 loadInvoked = true; | 222 setTimeout(function() { |
| 223 checkDefaultViewIsShown(); |
| 224 done(); |
| 225 }); |
222 return Promise.reject(); | 226 return Promise.reject(); |
223 }; | 227 }; |
224 | 228 |
225 details.route = fakeRouteOne; | 229 details.route = fakeRouteOne; |
226 setTimeout(function() { | |
227 assertTrue(loadInvoked); | |
228 checkDefaultViewIsShown(); | |
229 done(); | |
230 }); | |
231 }); | 230 }); |
232 }); | 231 }); |
233 } | 232 } |
234 | 233 |
235 return { | 234 return { |
236 registerTests: registerTests, | 235 registerTests: registerTests, |
237 }; | 236 }; |
238 }); | 237 }); |
OLD | NEW |