Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/test/data/webui/media_router/route_details_tests.js

Issue 1415533019: [Media Router] Use common media-router-header for MR UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per imcheng@'s comments. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webui/media_router/media_router_container_tests.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * First fake sink created before each test.
29 * @type {media_router.Sink}
30 */
31 var fakeSinkOne;
32
33 /**
34 * Second fake sink created before each test.
35 * @type {media_router.Sink}
36 */
37 var fakeSinkTwo;
38
39 // Checks whether |expected| and the text in the span element in 27 // Checks whether |expected| and the text in the span element in
40 // the |elementId| element are equal. 28 // the |elementId| element are equal.
41 var checkSpanText = function(expected, elementId) { 29 var checkSpanText = function(expected, elementId) {
42 assertEquals(expected, 30 assertEquals(expected,
43 details.$[elementId].querySelector('span').innerText); 31 details.$[elementId].querySelector('span').innerText);
44 }; 32 };
45 33
46 // Checks the default route view is shown. 34 // Checks the default route view is shown.
47 var checkDefaultViewIsShown = function() { 35 var checkDefaultViewIsShown = function() {
48 assertFalse(details.$['route-information'].hasAttribute('hidden')); 36 assertFalse(details.$['route-information'].hasAttribute('hidden'));
(...skipping 23 matching lines...) Expand all
72 setup(function(done) { 60 setup(function(done) {
73 PolymerTest.clearBody(); 61 PolymerTest.clearBody();
74 details = document.createElement('route-details'); 62 details = document.createElement('route-details');
75 document.body.appendChild(details); 63 document.body.appendChild(details);
76 64
77 // Initialize routes and sinks. 65 // Initialize routes and sinks.
78 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1', 66 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1',
79 'Video 1', 1, true, 'chrome-extension://123/custom_view.html'); 67 'Video 1', 1, true, 'chrome-extension://123/custom_view.html');
80 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2', 68 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2',
81 'Video 2', 2, false); 69 'Video 2', 2, false);
82 fakeSinkOne = new media_router.Sink('sink id 1', 'Living Room',
83 media_router.SinkIconType.CAST,
84 media_router.SinkStatus.ACTIVE, [0, 1, 2]);
85 fakeSinkTwo = new media_router.Sink('sink id 2', 'my device',
86 media_router.SinkIconType.CAST,
87 media_router.SinkStatus.ACTIVE, [0, 1, 2]);
88 70
89 // Allow for the route details to be created and attached. 71 // Allow for the route details to be created and attached.
90 setTimeout(done); 72 setTimeout(done);
91 }); 73 });
92 74
93 // Tests for 'close-route-click' event firing when the 75 // Tests for 'close-route-click' event firing when the
94 // 'close-route-button' button is clicked. 76 // 'close-route-button' button is clicked.
95 test('close route button click', function(done) { 77 test('close route button click', function(done) {
96 details.addEventListener('close-route-click', function() { 78 details.addEventListener('close-route-click', function() {
97 done(); 79 done();
98 }); 80 });
99 MockInteractions.tap(details.$['close-route-button']); 81 MockInteractions.tap(details.$['close-route-button']);
100 }); 82 });
101 83
102 // Tests the initial expected text. 84 // Tests the initial expected text.
103 test('initial text setting', function() { 85 test('initial text setting', function() {
104 // <paper-button> text is styled as upper case. 86 // <paper-button> text is styled as upper case.
105 checkSpanText(loadTimeData.getString('stopCastingButton') 87 checkSpanText(loadTimeData.getString('stopCastingButton')
106 .toUpperCase(), 'close-route-button'); 88 .toUpperCase(), 'close-route-button');
107 checkSpanText('', 'route-information'); 89 checkSpanText('', 'route-information');
108 }); 90 });
109 91
110 // Tests when |route| exists but |sink| is null. 92 // Tests when |route| is null or set.
111 test('route is set', function() { 93 test('route is null or set', function() {
112 // |route| is null. 94 // |route| is null.
113 assertEquals(null, details.route); 95 assertEquals(null, details.route);
114 checkDefaultViewIsShown(); 96 checkDefaultViewIsShown();
115 97
116 // Set |route| to be non-null. 98 // Set |route| to be non-null.
117 details.route = fakeRouteOne; 99 details.route = fakeRouteOne;
118 assertEquals(fakeRouteOne, details.route); 100 assertEquals(fakeRouteOne, details.route);
119 checkSpanText(loadTimeData.getStringF('castingActivityStatus', 101 checkSpanText(loadTimeData.getStringF('castingActivityStatus',
120 fakeRouteOne.description), 'route-information'); 102 fakeRouteOne.description), 'route-information');
121 assertEquals(null, details.sink);
122 checkDefaultViewIsShown(); 103 checkDefaultViewIsShown();
123 104
124 // Set |route| to a different route. 105 // Set |route| to a different route.
125 details.route = fakeRouteTwo; 106 details.route = fakeRouteTwo;
126 assertEquals(fakeRouteTwo, details.route); 107 assertEquals(fakeRouteTwo, details.route);
127 checkSpanText(loadTimeData.getStringF('castingActivityStatus', 108 checkSpanText(loadTimeData.getStringF('castingActivityStatus',
128 fakeRouteTwo.description), 'route-information'); 109 fakeRouteTwo.description), 'route-information');
129 checkDefaultViewIsShown(); 110 checkDefaultViewIsShown();
130 }); 111 });
131 112
132 // Tests when |sink| exists but |route| is null. 113 // Tests when |route| exists, has a custom controller, and it loads.
133 test('sink is set', function() {
134 // |sink| is null.
135 assertEquals(null, details.sink);
136 checkSpanText('', 'route-information');
137
138 // Set |sink| to be non-null. 'route-information' should be updated.
139 details.sink = fakeSinkOne;
140 assertEquals(fakeSinkOne, details.sink);
141 assertEquals(null, details.route);
142 checkSpanText('', 'route-information');
143
144 // Set |sink| to be a different sink. 'route-information' text should
145 // be updated.
146 details.sink = fakeSinkTwo;
147 assertEquals(fakeSinkTwo, details.sink);
148 checkSpanText('', 'route-information');
149 });
150
151 // Tests when |route| and |sink| both exist.
152 test('sink and route are set', function() {
153 details.route = fakeRouteOne;
154 details.sink = fakeSinkOne;
155 assertEquals(fakeSinkOne, details.sink);
156 assertEquals(fakeRouteOne, details.route);
157 checkSpanText(loadTimeData.getStringF('castingActivityStatus',
158 fakeRouteOne.description), 'route-information');
159 });
160
161 // Tests when |route| and |sink| are both null.
162 test('sink and route are null', function() {
163 assertEquals(null, details.route);
164 assertEquals(null, details.sink);
165 checkSpanText('', 'route-information');
166 });
167
168 // Tests when |route| and |sink| both exist and |route| has custom
169 // controller and it loads.
170 test('route has custom controller and loading succeeds', function(done) { 114 test('route has custom controller and loading succeeds', function(done) {
171 var loadInvoked = false; 115 var loadInvoked = false;
172 details.$['custom-controller'].load = function(url) { 116 details.$['custom-controller'].load = function(url) {
173 loadInvoked = true; 117 loadInvoked = true;
174 assertEquals('chrome-extension://123/custom_view.html', url); 118 assertEquals('chrome-extension://123/custom_view.html', url);
175 return Promise.resolve(); 119 return Promise.resolve();
176 }; 120 };
177 121
178 details.route = fakeRouteOne; 122 details.route = fakeRouteOne;
179 details.sink = fakeSinkOne;
180 setTimeout(function() { 123 setTimeout(function() {
181 assertTrue(loadInvoked); 124 assertTrue(loadInvoked);
182 checkCustomControllerIsShown(); 125 checkCustomControllerIsShown();
183 done(); 126 done();
184 }); 127 });
185 }); 128 });
186 129
187 // Tests when |route| and |sink| both exist and |route| has custom 130 // Tests when |route| exists, has a custom controller, but fails to load.
188 // controller but it fails to load.
189 test('route has custom controller but loading fails', function(done) { 131 test('route has custom controller but loading fails', function(done) {
190 var loadInvoked = false; 132 var loadInvoked = false;
191 details.$['custom-controller'].load = function(url) { 133 details.$['custom-controller'].load = function(url) {
192 loadInvoked = true; 134 loadInvoked = true;
193 return Promise.reject(); 135 return Promise.reject();
194 }; 136 };
195 137
196 details.route = fakeRouteOne; 138 details.route = fakeRouteOne;
197 details.sink = fakeSinkOne;
198 setTimeout(function() { 139 setTimeout(function() {
199 assertTrue(loadInvoked); 140 assertTrue(loadInvoked);
200 checkDefaultViewIsShown(); 141 checkDefaultViewIsShown();
201 done(); 142 done();
202 }); 143 });
203 }); 144 });
204 }); 145 });
205 } 146 }
206 147
207 return { 148 return {
208 registerTests: registerTests, 149 registerTests: registerTests,
209 }; 150 };
210 }); 151 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/media_router/media_router_container_tests.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698