| 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 19 matching lines...) Expand all Loading... |
| 30 assertEquals(expected, | 30 assertEquals(expected, |
| 31 details.$[elementId].querySelector('span').innerText); | 31 details.$[elementId].querySelector('span').innerText); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Checks the default route view is shown. | 34 // Checks the default route view is shown. |
| 35 var checkDefaultViewIsShown = function() { | 35 var checkDefaultViewIsShown = function() { |
| 36 assertFalse(details.$['route-information'].hasAttribute('hidden')); | 36 assertFalse(details.$['route-information'].hasAttribute('hidden')); |
| 37 assertTrue(details.$['custom-controller'].hasAttribute('hidden')); | 37 assertTrue(details.$['custom-controller'].hasAttribute('hidden')); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 // Checks the default route view is shown. |
| 41 var checkJoinButtonIsShown = function() { |
| 42 assertFalse(details.$['join-route-button'].hasAttribute('hidden')); |
| 43 }; |
| 44 |
| 45 // Checks the default route view is not shown. |
| 46 var checkJoinButtonIsNotShown = function() { |
| 47 assertTrue(details.$['join-route-button'].hasAttribute('hidden')); |
| 48 }; |
| 49 |
| 40 // Checks the custom controller is shown. | 50 // Checks the custom controller is shown. |
| 41 var checkCustomControllerIsShown = function() { | 51 var checkCustomControllerIsShown = function() { |
| 42 assertTrue(details.$['route-information'].hasAttribute('hidden')); | 52 assertTrue(details.$['route-information'].hasAttribute('hidden')); |
| 43 assertFalse(details.$['custom-controller'].hasAttribute('hidden')); | 53 assertFalse(details.$['custom-controller'].hasAttribute('hidden')); |
| 44 }; | 54 }; |
| 45 | 55 |
| 46 // Checks whether |expected| and the text in the |elementId| element | 56 // Checks whether |expected| and the text in the |elementId| element |
| 47 // are equal given an id. | 57 // are equal given an id. |
| 48 var checkElementTextWithId = function(expected, elementId) { | 58 var checkElementTextWithId = function(expected, elementId) { |
| 49 assertEquals(expected, details.$[elementId].innerText); | 59 assertEquals(expected, details.$[elementId].innerText); |
| 50 }; | 60 }; |
| 51 | 61 |
| 52 // Import route_details.html before running suite. | 62 // Import route_details.html before running suite. |
| 53 suiteSetup(function() { | 63 suiteSetup(function() { |
| 54 return PolymerTest.importHtml( | 64 return PolymerTest.importHtml( |
| 55 'chrome://media-router/elements/route_details/' + | 65 'chrome://media-router/elements/route_details/' + |
| 56 'route_details.html'); | 66 'route_details.html'); |
| 57 }); | 67 }); |
| 58 | 68 |
| 59 // Initialize a route-details before each test. | 69 // Initialize a route-details before each test. |
| 60 setup(function(done) { | 70 setup(function(done) { |
| 61 PolymerTest.clearBody(); | 71 PolymerTest.clearBody(); |
| 62 details = document.createElement('route-details'); | 72 details = document.createElement('route-details'); |
| 63 document.body.appendChild(details); | 73 document.body.appendChild(details); |
| 64 | 74 |
| 65 // Initialize routes and sinks. | 75 // Initialize routes and sinks. |
| 66 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1', | 76 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1', |
| 67 'Video 1', 1, true, 'chrome-extension://123/custom_view.html'); | 77 'Video 1', 1, true, false, |
| 78 'chrome-extension://123/custom_view.html'); |
| 68 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2', | 79 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2', |
| 69 'Video 2', 2, false); | 80 'Video 2', 2, false, true); |
| 70 | 81 |
| 71 // Allow for the route details to be created and attached. | 82 // Allow for the route details to be created and attached. |
| 72 setTimeout(done); | 83 setTimeout(done); |
| 73 }); | 84 }); |
| 74 | 85 |
| 75 // Tests for 'close-route-click' event firing when the | 86 // Tests for 'close-route-click' event firing when the |
| 76 // 'close-route-button' button is clicked. | 87 // 'close-route-button' button is clicked. |
| 77 test('close route button click', function(done) { | 88 test('close route button click', function(done) { |
| 78 details.addEventListener('close-route-click', function() { | 89 details.addEventListener('close-route-click', function() { |
| 79 done(); | 90 done(); |
| 80 }); | 91 }); |
| 81 MockInteractions.tap(details.$['close-route-button']); | 92 MockInteractions.tap(details.$['close-route-button']); |
| 82 }); | 93 }); |
| 83 | 94 |
| 95 // Tests for 'join-route-click' event firing when the |
| 96 // 'join-route-button' button is clicked. |
| 97 test('join route button click', function(done) { |
| 98 details.addEventListener('join-route-click', function() { |
| 99 done(); |
| 100 }); |
| 101 MockInteractions.tap(details.$['join-route-button']); |
| 102 }); |
| 103 |
| 84 // Tests the initial expected text. | 104 // Tests the initial expected text. |
| 85 test('initial text setting', function() { | 105 test('initial text setting', function() { |
| 86 // <paper-button> text is styled as upper case. | 106 // <paper-button> text is styled as upper case. |
| 87 checkSpanText(loadTimeData.getString('stopCastingButton') | 107 checkSpanText(loadTimeData.getString('stopCastingButton') |
| 88 .toUpperCase(), 'close-route-button'); | 108 .toUpperCase(), 'close-route-button'); |
| 109 checkSpanText(loadTimeData.getString('joinButton'), |
| 110 'join-route-button'); |
| 89 checkSpanText('', 'route-information'); | 111 checkSpanText('', 'route-information'); |
| 90 }); | 112 }); |
| 91 | 113 |
| 92 // Tests when |route| is null or set. | 114 // Tests when |route| is null or set. |
| 93 test('route is null or set', function() { | 115 test('route is null or set', function() { |
| 94 // |route| is null. | 116 // |route| is null. |
| 95 assertEquals(null, details.route); | 117 assertEquals(null, details.route); |
| 96 checkDefaultViewIsShown(); | 118 checkDefaultViewIsShown(); |
| 97 | 119 |
| 98 // Set |route| to be non-null. | 120 // Set |route| to be non-null. |
| 99 details.route = fakeRouteOne; | 121 details.route = fakeRouteOne; |
| 100 assertEquals(fakeRouteOne, details.route); | 122 assertEquals(fakeRouteOne, details.route); |
| 101 checkSpanText(loadTimeData.getStringF('castingActivityStatus', | 123 checkSpanText(loadTimeData.getStringF('castingActivityStatus', |
| 102 fakeRouteOne.description), 'route-information'); | 124 fakeRouteOne.description), 'route-information'); |
| 103 checkDefaultViewIsShown(); | 125 checkDefaultViewIsShown(); |
| 126 checkJoinButtonIsNotShown(); |
| 104 | 127 |
| 105 // Set |route| to a different route. | 128 // Set |route| to a different route. |
| 106 details.route = fakeRouteTwo; | 129 details.route = fakeRouteTwo; |
| 107 assertEquals(fakeRouteTwo, details.route); | 130 assertEquals(fakeRouteTwo, details.route); |
| 108 checkSpanText(loadTimeData.getStringF('castingActivityStatus', | 131 checkSpanText(loadTimeData.getStringF('castingActivityStatus', |
| 109 fakeRouteTwo.description), 'route-information'); | 132 fakeRouteTwo.description), 'route-information'); |
| 110 checkDefaultViewIsShown(); | 133 checkDefaultViewIsShown(); |
| 134 checkJoinButtonIsShown(); |
| 111 }); | 135 }); |
| 112 | 136 |
| 113 // Tests when |route| exists, has a custom controller, and it loads. | 137 // Tests when |route| exists, has a custom controller, and it loads. |
| 114 test('route has custom controller and loading succeeds', function(done) { | 138 test('route has custom controller and loading succeeds', function(done) { |
| 115 var loadInvoked = false; | 139 var loadInvoked = false; |
| 116 details.$['custom-controller'].load = function(url) { | 140 details.$['custom-controller'].load = function(url) { |
| 117 loadInvoked = true; | 141 loadInvoked = true; |
| 118 assertEquals('chrome-extension://123/custom_view.html', url); | 142 assertEquals('chrome-extension://123/custom_view.html', url); |
| 119 return Promise.resolve(); | 143 return Promise.resolve(); |
| 120 }; | 144 }; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 142 done(); | 166 done(); |
| 143 }); | 167 }); |
| 144 }); | 168 }); |
| 145 }); | 169 }); |
| 146 } | 170 } |
| 147 | 171 |
| 148 return { | 172 return { |
| 149 registerTests: registerTests, | 173 registerTests: registerTests, |
| 150 }; | 174 }; |
| 151 }); | 175 }); |
| OLD | NEW |