| 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. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // the |elementId| element are equal. | 41 // the |elementId| element are equal. |
| 42 var checkSpanText = function(expected, elementId) { | 42 var checkSpanText = function(expected, elementId) { |
| 43 assertEquals( | 43 assertEquals( |
| 44 expected, | 44 expected, |
| 45 details.$$('#' + elementId).querySelector('span').innerText); | 45 details.$$('#' + elementId).querySelector('span').innerText); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // Checks the default route view is shown. | 48 // Checks the default route view is shown. |
| 49 var checkDefaultViewIsShown = function() { | 49 var checkDefaultViewIsShown = function() { |
| 50 assertFalse(details.$$('#route-information').hasAttribute('hidden')); | 50 assertFalse(details.$$('#route-information').hasAttribute('hidden')); |
| 51 assertTrue(details.$$('extension-view-wrapper').hasAttribute('hidden')); | 51 assertTrue( |
| 52 !details.$$('extension-view-wrapper') || |
| 53 details.$$('extension-view-wrapper').hasAttribute('hidden')); |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 // Checks the start button is shown. | 56 // Checks the start button is shown. |
| 55 var checkStartCastButtonIsShown = function() { | 57 var checkStartCastButtonIsShown = function() { |
| 56 assertFalse(details.$$('#start-casting-to-route-button') | 58 assertFalse(details.$$('#start-casting-to-route-button') |
| 57 .hasAttribute('hidden')); | 59 .hasAttribute('hidden')); |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 // Checks the start button is not shown. | 62 // Checks the start button is not shown. |
| 61 var checkStartCastButtonIsNotShown = function() { | 63 var checkStartCastButtonIsNotShown = function() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 80 suiteSetup(function() { | 82 suiteSetup(function() { |
| 81 return PolymerTest.importHtml( | 83 return PolymerTest.importHtml( |
| 82 'chrome://media-router/elements/route_details/' + | 84 'chrome://media-router/elements/route_details/' + |
| 83 'route_details.html'); | 85 'route_details.html'); |
| 84 }); | 86 }); |
| 85 | 87 |
| 86 // Initialize a route-details before each test. | 88 // Initialize a route-details before each test. |
| 87 setup(function(done) { | 89 setup(function(done) { |
| 88 PolymerTest.clearBody(); | 90 PolymerTest.clearBody(); |
| 89 details = document.createElement('route-details'); | 91 details = document.createElement('route-details'); |
| 90 details.useWebUiRouteControls = false; | |
| 91 document.body.appendChild(details); | 92 document.body.appendChild(details); |
| 92 | 93 |
| 93 // Initialize routes and sinks. | 94 // Initialize routes and sinks. |
| 94 fakeRouteOne = new media_router.Route( | 95 fakeRouteOne = new media_router.Route( |
| 95 'route id 1', 'sink id 1', 'Video 1', 1, true, false, | 96 'route id 1', 'sink id 1', 'Video 1', 1, true, false, |
| 96 fakeRouteOneControllerPath); | 97 fakeRouteOneControllerPath); |
| 97 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2', | 98 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2', |
| 98 'Video 2', 2, false, true); | 99 'Video 2', 2, false, true); |
| 99 fakeSinkOne = new media_router.Sink( | 100 fakeSinkOne = new media_router.Sink( |
| 100 'sink id 1', 'sink 1', 'description', null, | 101 'sink id 1', 'sink 1', 'description', null, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 details.route = fakeRouteTwo; | 203 details.route = fakeRouteTwo; |
| 203 assertEquals(fakeRouteTwo, details.route); | 204 assertEquals(fakeRouteTwo, details.route); |
| 204 checkSpanText(loadTimeData.getStringF('castingActivityStatus', | 205 checkSpanText(loadTimeData.getStringF('castingActivityStatus', |
| 205 fakeRouteTwo.description), 'route-information'); | 206 fakeRouteTwo.description), 'route-information'); |
| 206 checkDefaultViewIsShown(); | 207 checkDefaultViewIsShown(); |
| 207 checkStartCastButtonIsShown(); | 208 checkStartCastButtonIsShown(); |
| 208 }); | 209 }); |
| 209 | 210 |
| 210 // Tests when |route| exists, has a custom controller, and it loads. | 211 // Tests when |route| exists, has a custom controller, and it loads. |
| 211 test('route has custom controller and loading succeeds', function(done) { | 212 test('route has custom controller and loading succeeds', function(done) { |
| 212 details.$$('extension-view-wrapper').$$('#custom-controller').load = | 213 // Get the extension-view-wrapper stamped first, so that we can mock out |
| 213 function(url) { | 214 // the load method. |
| 214 setTimeout(function() { | 215 details.route = fakeRouteTwo; |
| 215 assertEquals( | |
| 216 fakeRouteOneControllerPath, | |
| 217 url.substring(0, fakeRouteOneControllerPath.length)); | |
| 218 checkCustomControllerIsShown(); | |
| 219 done(); | |
| 220 }); | |
| 221 return Promise.resolve(); | |
| 222 }; | |
| 223 | 216 |
| 224 details.route = fakeRouteOne; | 217 setTimeout(function() { |
| 218 details.$$('extension-view-wrapper').$$('#custom-controller').load = |
| 219 function(url) { |
| 220 setTimeout(function() { |
| 221 assertEquals( |
| 222 fakeRouteOneControllerPath, |
| 223 url.substring(0, fakeRouteOneControllerPath.length)); |
| 224 checkCustomControllerIsShown(); |
| 225 done(); |
| 226 }); |
| 227 return Promise.resolve(); |
| 228 }; |
| 229 |
| 230 details.route = fakeRouteOne; |
| 231 }); |
| 225 }); | 232 }); |
| 226 | 233 |
| 227 // Tests when |route| exists, has a custom controller, but fails to load. | 234 // Tests when |route| exists, has a custom controller, but fails to load. |
| 228 test('route has custom controller but loading fails', function(done) { | 235 test('route has custom controller but loading fails', function(done) { |
| 229 details.$$('extension-view-wrapper').$$('#custom-controller').load = | 236 // Get the extension-view-wrapper stamped first, so that we can mock out |
| 230 function(url) { | 237 // the load method. |
| 231 setTimeout(function() { | 238 details.route = fakeRouteTwo; |
| 232 checkDefaultViewIsShown(); | |
| 233 done(); | |
| 234 }); | |
| 235 return Promise.reject(); | |
| 236 }; | |
| 237 | 239 |
| 238 details.route = fakeRouteOne; | 240 setTimeout(function() { |
| 241 details.$$('extension-view-wrapper').$$('#custom-controller').load = |
| 242 function(url) { |
| 243 setTimeout(function() { |
| 244 checkDefaultViewIsShown(); |
| 245 done(); |
| 246 }); |
| 247 return Promise.reject(); |
| 248 }; |
| 249 |
| 250 details.route = fakeRouteOne; |
| 251 }); |
| 239 }); | 252 }); |
| 240 }); | 253 }); |
| 241 } | 254 } |
| 242 | 255 |
| 243 return { | 256 return { |
| 244 registerTests: registerTests, | 257 registerTests: registerTests, |
| 245 }; | 258 }; |
| 246 }); | 259 }); |
| OLD | NEW |