Chromium Code Reviews| 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); |
| 81 fakeSinkOne = new media_router.Sink('sink id 1', 'Living Room', | |
|
apacible
2015/12/09 19:56:25
What are fakeSinkOne and fakeSinkTwo used for?
matt.boetger
2015/12/16 00:21:08
Nothing anymore. Thanks for catching.
| |
| 82 media_router.SinkIconType.CAST, | |
| 83 media_router.SinkStatus.ACTIVE, [0, 1, 2]); | |
| 84 fakeSinkTwo = new media_router.Sink('sink id 2', 'my device', | |
| 85 media_router.SinkIconType.CAST, | |
| 86 media_router.SinkStatus.ACTIVE, [0, 1, 2]); | |
| 70 | 87 |
| 71 // Allow for the route details to be created and attached. | 88 // Allow for the route details to be created and attached. |
| 72 setTimeout(done); | 89 setTimeout(done); |
| 73 }); | 90 }); |
| 74 | 91 |
| 75 // Tests for 'close-route-click' event firing when the | 92 // Tests for 'close-route-click' event firing when the |
| 76 // 'close-route-button' button is clicked. | 93 // 'close-route-button' button is clicked. |
| 77 test('close route button click', function(done) { | 94 test('close route button click', function(done) { |
| 78 details.addEventListener('close-route-click', function() { | 95 details.addEventListener('close-route-click', function() { |
| 79 done(); | 96 done(); |
| 80 }); | 97 }); |
| 81 MockInteractions.tap(details.$['close-route-button']); | 98 MockInteractions.tap(details.$['close-route-button']); |
| 82 }); | 99 }); |
| 83 | 100 |
| 101 // Tests for 'close-route-click' event firing when the | |
| 102 // 'close-route-button' button is clicked. | |
|
apacible
2015/12/09 19:56:25
nit: 'join-route-button'
matt.boetger
2015/12/16 00:21:08
Done.
| |
| 103 test('join route button click', function(done) { | |
| 104 details.addEventListener('join-route-click', function() { | |
| 105 done(); | |
| 106 }); | |
| 107 MockInteractions.tap(details.$['join-route-button']); | |
| 108 }); | |
| 109 | |
| 84 // Tests the initial expected text. | 110 // Tests the initial expected text. |
| 85 test('initial text setting', function() { | 111 test('initial text setting', function() { |
| 86 // <paper-button> text is styled as upper case. | 112 // <paper-button> text is styled as upper case. |
| 87 checkSpanText(loadTimeData.getString('stopCastingButton') | 113 checkSpanText(loadTimeData.getString('stopCastingButton') |
| 88 .toUpperCase(), 'close-route-button'); | 114 .toUpperCase(), 'close-route-button'); |
| 115 // unless it's hidden (join is hidden unless the route can be joined) | |
|
apacible
2015/12/09 19:56:25
This is a fragment; is this a continuation from th
apacible
2015/12/09 19:56:25
nit: period at the end.
matt.boetger
2015/12/16 00:21:08
Done.
matt.boetger
2015/12/16 00:21:08
Done.
| |
| 116 checkSpanText(loadTimeData.getString('joinButton'), | |
| 117 'join-route-button'); | |
| 89 checkSpanText('', 'route-information'); | 118 checkSpanText('', 'route-information'); |
| 90 }); | 119 }); |
| 91 | 120 |
| 92 // Tests when |route| is null or set. | 121 // Tests when |route| is null or set. |
| 93 test('route is null or set', function() { | 122 test('route is null or set', function() { |
| 94 // |route| is null. | 123 // |route| is null. |
| 95 assertEquals(null, details.route); | 124 assertEquals(null, details.route); |
| 96 checkDefaultViewIsShown(); | 125 checkDefaultViewIsShown(); |
| 97 | 126 |
| 98 // Set |route| to be non-null. | 127 // Set |route| to be non-null. |
| 99 details.route = fakeRouteOne; | 128 details.route = fakeRouteOne; |
| 100 assertEquals(fakeRouteOne, details.route); | 129 assertEquals(fakeRouteOne, details.route); |
| 101 checkSpanText(loadTimeData.getStringF('castingActivityStatus', | 130 checkSpanText(loadTimeData.getStringF('castingActivityStatus', |
| 102 fakeRouteOne.description), 'route-information'); | 131 fakeRouteOne.description), 'route-information'); |
| 103 checkDefaultViewIsShown(); | 132 checkDefaultViewIsShown(); |
| 133 checkJoinButtonIsNotShown(); | |
| 104 | 134 |
| 105 // Set |route| to a different route. | 135 // Set |route| to a different route. |
| 106 details.route = fakeRouteTwo; | 136 details.route = fakeRouteTwo; |
| 107 assertEquals(fakeRouteTwo, details.route); | 137 assertEquals(fakeRouteTwo, details.route); |
| 108 checkSpanText(loadTimeData.getStringF('castingActivityStatus', | 138 checkSpanText(loadTimeData.getStringF('castingActivityStatus', |
| 109 fakeRouteTwo.description), 'route-information'); | 139 fakeRouteTwo.description), 'route-information'); |
| 110 checkDefaultViewIsShown(); | 140 checkDefaultViewIsShown(); |
| 141 checkJoinButtonIsShown(); | |
| 111 }); | 142 }); |
| 112 | 143 |
| 113 // Tests when |route| exists, has a custom controller, and it loads. | 144 // Tests when |route| exists, has a custom controller, and it loads. |
| 114 test('route has custom controller and loading succeeds', function(done) { | 145 test('route has custom controller and loading succeeds', function(done) { |
| 115 var loadInvoked = false; | 146 var loadInvoked = false; |
| 116 details.$['custom-controller'].load = function(url) { | 147 details.$['custom-controller'].load = function(url) { |
| 117 loadInvoked = true; | 148 loadInvoked = true; |
| 118 assertEquals('chrome-extension://123/custom_view.html', url); | 149 assertEquals('chrome-extension://123/custom_view.html', url); |
| 119 return Promise.resolve(); | 150 return Promise.resolve(); |
| 120 }; | 151 }; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 142 done(); | 173 done(); |
| 143 }); | 174 }); |
| 144 }); | 175 }); |
| 145 }); | 176 }); |
| 146 } | 177 } |
| 147 | 178 |
| 148 return { | 179 return { |
| 149 registerTests: registerTests, | 180 registerTests: registerTests, |
| 150 }; | 181 }; |
| 151 }); | 182 }); |
| OLD | NEW |