| 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 /** |
| 28 * Fake sink that corresponds to |fakeRouteOne|. |
| 29 * @type {media_router.Sink} |
| 30 */ |
| 31 var fakeSinkOne; |
| 32 |
| 27 // Checks whether |expected| and the text in the span element in | 33 // Checks whether |expected| and the text in the span element in |
| 28 // the |elementId| element are equal. | 34 // the |elementId| element are equal. |
| 29 var checkSpanText = function(expected, elementId) { | 35 var checkSpanText = function(expected, elementId) { |
| 30 assertEquals(expected, | 36 assertEquals(expected, |
| 31 details.$[elementId].querySelector('span').innerText); | 37 details.$[elementId].querySelector('span').innerText); |
| 32 }; | 38 }; |
| 33 | 39 |
| 34 // Checks the default route view is shown. | 40 // Checks the default route view is shown. |
| 35 var checkDefaultViewIsShown = function() { | 41 var checkDefaultViewIsShown = function() { |
| 36 assertFalse(details.$['route-information'].hasAttribute('hidden')); | 42 assertFalse(details.$['route-information'].hasAttribute('hidden')); |
| 37 assertTrue(details.$['custom-controller'].hasAttribute('hidden')); | 43 assertTrue( |
| 44 details.$$('extension-view-wrapper').hasAttribute('hidden')); |
| 38 }; | 45 }; |
| 39 | 46 |
| 40 // Checks the default route view is shown. | 47 // Checks the start button is shown. |
| 41 var checkStartCastButtonIsShown = function() { | 48 var checkStartCastButtonIsShown = function() { |
| 42 assertFalse( | 49 assertFalse( |
| 43 details.$['start-casting-to-route-button'].hasAttribute('hidden')); | 50 details.$['start-casting-to-route-button'].hasAttribute('hidden')); |
| 44 }; | 51 }; |
| 45 | 52 |
| 46 // Checks the default route view is not shown. | 53 // Checks the start button is not shown. |
| 47 var checkStartCastButtonIsNotShown = function() { | 54 var checkStartCastButtonIsNotShown = function() { |
| 48 assertTrue( | 55 assertTrue( |
| 49 details.$['start-casting-to-route-button'].hasAttribute('hidden')); | 56 details.$['start-casting-to-route-button'].hasAttribute('hidden')); |
| 50 }; | 57 }; |
| 51 | 58 |
| 52 // Checks the custom controller is shown. | 59 // Checks the custom controller is shown. |
| 53 var checkCustomControllerIsShown = function() { | 60 var checkCustomControllerIsShown = function() { |
| 54 assertTrue(details.$['route-information'].hasAttribute('hidden')); | 61 assertTrue(details.$['route-information'].hasAttribute('hidden')); |
| 55 assertFalse(details.$['custom-controller'].hasAttribute('hidden')); | 62 assertFalse( |
| 63 details.$$('extension-view-wrapper').hasAttribute('hidden')); |
| 56 }; | 64 }; |
| 57 | 65 |
| 58 // Checks whether |expected| and the text in the |elementId| element | 66 // Checks whether |expected| and the text in the |elementId| element |
| 59 // are equal given an id. | 67 // are equal given an id. |
| 60 var checkElementTextWithId = function(expected, elementId) { | 68 var checkElementTextWithId = function(expected, elementId) { |
| 61 assertEquals(expected, details.$[elementId].innerText); | 69 assertEquals(expected, details.$[elementId].innerText); |
| 62 }; | 70 }; |
| 63 | 71 |
| 64 /** | |
| 65 * Fake sink that corresponds to |fakeRouteOne|. | |
| 66 * @type {media_router.Sink} | |
| 67 */ | |
| 68 var fakeSinkOne; | |
| 69 | |
| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after 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); |
| 206 return Promise.resolve(); | 209 checkCustomControllerIsShown(); |
| 207 }; | 210 done(); |
| 211 }); |
| 212 return Promise.resolve(); |
| 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() { |
| 222 return Promise.reject(); | 223 checkDefaultViewIsShown(); |
| 223 }; | 224 done(); |
| 225 }); |
| 226 return Promise.reject(); |
| 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 |