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 #include "base/macros.h" | 5 #include "base/macros.h" |
6 #include "chrome/browser/extensions/browser_action_test_util.h" | 6 #include "chrome/browser/extensions/browser_action_test_util.h" |
7 #include "chrome/browser/extensions/extension_action_test_util.h" | 7 #include "chrome/browser/extensions/extension_action_test_util.h" |
8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/browser/ui/toolbar/media_router_action.h" | 10 #include "chrome/browser/ui/toolbar/media_router_action.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 CreateToolbarModelForProfileWithoutWaitingForReady(profile()); | 116 CreateToolbarModelForProfileWithoutWaitingForReady(profile()); |
117 | 117 |
118 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() | 118 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() |
119 // has run. | 119 // has run. |
120 browser_action_test_util_.reset( | 120 browser_action_test_util_.reset( |
121 new BrowserActionTestUtil(browser(), false)); | 121 new BrowserActionTestUtil(browser(), false)); |
122 action_.reset( | 122 action_.reset( |
123 new TestMediaRouterAction( | 123 new TestMediaRouterAction( |
124 browser(), | 124 browser(), |
125 browser_action_test_util_->GetToolbarActionsBar())); | 125 browser_action_test_util_->GetToolbarActionsBar())); |
| 126 |
| 127 local_display_route_list_.push_back( |
| 128 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", |
| 129 "description", true, std::string(), true)); |
| 130 non_local_display_route_list_.push_back( |
| 131 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", |
| 132 "description", false, std::string(), true)); |
| 133 non_local_display_route_list_.push_back( |
| 134 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", |
| 135 "description", true, std::string(), false)); |
126 } | 136 } |
127 | 137 |
128 void TearDown() override { | 138 void TearDown() override { |
129 browser_action_test_util_.reset(); | 139 browser_action_test_util_.reset(); |
130 action_.reset(); | 140 action_.reset(); |
131 MediaRouterTest::TearDown(); | 141 MediaRouterTest::TearDown(); |
132 } | 142 } |
133 | 143 |
134 TestMediaRouterAction* action() { return action_.get(); } | 144 TestMediaRouterAction* action() { return action_.get(); } |
135 const media_router::Issue* fake_issue_notification() { | 145 const media_router::Issue* fake_issue_notification() { |
136 return &fake_issue_notification_; | 146 return &fake_issue_notification_; |
137 } | 147 } |
138 const media_router::Issue* fake_issue_warning() { | 148 const media_router::Issue* fake_issue_warning() { |
139 return &fake_issue_warning_; | 149 return &fake_issue_warning_; |
140 } | 150 } |
141 const media_router::Issue* fake_issue_fatal() { | 151 const media_router::Issue* fake_issue_fatal() { |
142 return &fake_issue_fatal_; | 152 return &fake_issue_fatal_; |
143 } | 153 } |
144 const gfx::Image active_icon() { return active_icon_; } | 154 const gfx::Image active_icon() { return active_icon_; } |
145 const gfx::Image error_icon() { return error_icon_; } | 155 const gfx::Image error_icon() { return error_icon_; } |
146 const gfx::Image idle_icon() { return idle_icon_; } | 156 const gfx::Image idle_icon() { return idle_icon_; } |
147 const gfx::Image warning_icon() { return warning_icon_; } | 157 const gfx::Image warning_icon() { return warning_icon_; } |
| 158 const std::vector<media_router::MediaRoute>& local_display_route_list() |
| 159 const { |
| 160 return local_display_route_list_; |
| 161 } |
| 162 const std::vector<media_router::MediaRoute>& non_local_display_route_list() |
| 163 const { |
| 164 return non_local_display_route_list_; |
| 165 } |
| 166 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { |
| 167 return empty_route_id_list_; |
| 168 } |
148 | 169 |
149 private: | 170 private: |
150 // A BrowserActionTestUtil object constructed with the associated | 171 // A BrowserActionTestUtil object constructed with the associated |
151 // ToolbarActionsBar. | 172 // ToolbarActionsBar. |
152 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; | 173 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; |
153 | 174 |
154 scoped_ptr<TestMediaRouterAction> action_; | 175 scoped_ptr<TestMediaRouterAction> action_; |
155 | 176 |
156 // The associated ToolbarActionsModel (owned by the keyed service setup). | 177 // The associated ToolbarActionsModel (owned by the keyed service setup). |
157 ToolbarActionsModel* toolbar_model_; | 178 ToolbarActionsModel* toolbar_model_; |
158 | 179 |
159 // Fake Issues. | 180 // Fake Issues. |
160 const media_router::Issue fake_issue_notification_; | 181 const media_router::Issue fake_issue_notification_; |
161 const media_router::Issue fake_issue_warning_; | 182 const media_router::Issue fake_issue_warning_; |
162 const media_router::Issue fake_issue_fatal_; | 183 const media_router::Issue fake_issue_fatal_; |
163 | 184 |
164 // Fake Sources, used for the Routes. | 185 // Fake Sources, used for the Routes. |
165 const media_router::MediaSource fake_source1_; | 186 const media_router::MediaSource fake_source1_; |
166 const media_router::MediaSource fake_source2_; | 187 const media_router::MediaSource fake_source2_; |
167 | 188 |
168 // Cached images. | 189 // Cached images. |
169 const gfx::Image active_icon_; | 190 const gfx::Image active_icon_; |
170 const gfx::Image error_icon_; | 191 const gfx::Image error_icon_; |
171 const gfx::Image idle_icon_; | 192 const gfx::Image idle_icon_; |
172 const gfx::Image warning_icon_; | 193 const gfx::Image warning_icon_; |
173 | 194 |
| 195 std::vector<media_router::MediaRoute> local_display_route_list_; |
| 196 std::vector<media_router::MediaRoute> non_local_display_route_list_; |
| 197 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; |
| 198 |
174 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest); | 199 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest); |
175 }; | 200 }; |
176 | 201 |
177 // Tests the initial state of MediaRouterAction after construction. | 202 // Tests the initial state of MediaRouterAction after construction. |
178 TEST_F(MediaRouterActionUnitTest, Initialization) { | 203 TEST_F(MediaRouterActionUnitTest, Initialization) { |
179 EXPECT_EQ("media_router_action", action()->GetId()); | 204 EXPECT_EQ("media_router_action", action()->GetId()); |
180 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE), | 205 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE), |
181 action()->GetActionName()); | 206 action()->GetActionName()); |
182 EXPECT_TRUE(gfx::test::AreImagesEqual( | 207 EXPECT_TRUE(gfx::test::AreImagesEqual( |
183 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 208 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
(...skipping 27 matching lines...) Expand all Loading... |
211 } | 236 } |
212 | 237 |
213 // Tests the MediaRouterAction state updates based on whether there are local | 238 // Tests the MediaRouterAction state updates based on whether there are local |
214 // routes. | 239 // routes. |
215 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) { | 240 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) { |
216 // Initially, there are no routes. | 241 // Initially, there are no routes. |
217 EXPECT_TRUE(gfx::test::AreImagesEqual( | 242 EXPECT_TRUE(gfx::test::AreImagesEqual( |
218 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 243 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
219 | 244 |
220 // Update |current_icon_| since there is a local route. | 245 // Update |current_icon_| since there is a local route. |
221 action()->OnHasLocalDisplayRouteUpdated(true); | 246 action()->OnRoutesUpdated(local_display_route_list(), empty_route_id_list()); |
222 EXPECT_TRUE(gfx::test::AreImagesEqual( | 247 EXPECT_TRUE(gfx::test::AreImagesEqual( |
223 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 248 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
224 | 249 |
225 // Update |current_icon_| since there are no local routes. | 250 // Update |current_icon_| since there are no local routes. |
226 action()->OnHasLocalDisplayRouteUpdated(false); | 251 action()->OnRoutesUpdated(non_local_display_route_list(), |
| 252 empty_route_id_list()); |
| 253 EXPECT_TRUE(gfx::test::AreImagesEqual( |
| 254 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
| 255 |
| 256 action()->OnRoutesUpdated(std::vector<media_router::MediaRoute>(), |
| 257 empty_route_id_list()); |
227 EXPECT_TRUE(gfx::test::AreImagesEqual( | 258 EXPECT_TRUE(gfx::test::AreImagesEqual( |
228 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 259 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
229 } | 260 } |
230 | 261 |
231 // Tests the MediaRouterAction icon based on updates to both issues and routes. | 262 // Tests the MediaRouterAction icon based on updates to both issues and routes. |
232 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { | 263 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { |
233 // Initially, there are no issues or routes. | 264 // Initially, there are no issues or routes. |
234 EXPECT_TRUE(gfx::test::AreImagesEqual( | 265 EXPECT_TRUE(gfx::test::AreImagesEqual( |
235 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 266 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
236 | 267 |
237 // There is no change in |current_icon_| since notification issues do not | 268 // There is no change in |current_icon_| since notification issues do not |
238 // update the state. | 269 // update the state. |
239 action()->OnIssueUpdated(fake_issue_notification()); | 270 action()->OnIssueUpdated(fake_issue_notification()); |
240 EXPECT_TRUE(gfx::test::AreImagesEqual( | 271 EXPECT_TRUE(gfx::test::AreImagesEqual( |
241 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 272 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
242 | 273 |
243 // Non-local routes also do not have an effect on |current_icon_|. | 274 // Non-local routes also do not have an effect on |current_icon_|. |
244 action()->OnHasLocalDisplayRouteUpdated(false); | 275 action()->OnRoutesUpdated(non_local_display_route_list(), |
| 276 empty_route_id_list()); |
245 EXPECT_TRUE(gfx::test::AreImagesEqual( | 277 EXPECT_TRUE(gfx::test::AreImagesEqual( |
246 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 278 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
247 | 279 |
248 // Update |current_icon_| since there is a local route. | 280 // Update |current_icon_| since there is a local route. |
249 action()->OnHasLocalDisplayRouteUpdated(true); | 281 action()->OnRoutesUpdated(local_display_route_list(), empty_route_id_list()); |
250 EXPECT_TRUE(gfx::test::AreImagesEqual( | 282 EXPECT_TRUE(gfx::test::AreImagesEqual( |
251 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 283 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
252 | 284 |
253 // Update |current_icon_|, with a priority to reflect the warning issue | 285 // Update |current_icon_|, with a priority to reflect the warning issue |
254 // rather than the local route. | 286 // rather than the local route. |
255 action()->OnIssueUpdated(fake_issue_warning()); | 287 action()->OnIssueUpdated(fake_issue_warning()); |
256 EXPECT_TRUE(gfx::test::AreImagesEqual( | 288 EXPECT_TRUE(gfx::test::AreImagesEqual( |
257 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 289 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
258 | 290 |
259 // Closing a local route makes no difference to |current_icon_|. | 291 // Closing a local route makes no difference to |current_icon_|. |
260 action()->OnHasLocalDisplayRouteUpdated(false); | 292 action()->OnRoutesUpdated(non_local_display_route_list(), |
| 293 empty_route_id_list()); |
261 EXPECT_TRUE(gfx::test::AreImagesEqual( | 294 EXPECT_TRUE(gfx::test::AreImagesEqual( |
262 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 295 warning_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
263 | 296 |
264 // Update |current_icon_| since the issue has been updated to fatal. | 297 // Update |current_icon_| since the issue has been updated to fatal. |
265 action()->OnIssueUpdated(fake_issue_fatal()); | 298 action()->OnIssueUpdated(fake_issue_fatal()); |
266 EXPECT_TRUE(gfx::test::AreImagesEqual( | 299 EXPECT_TRUE(gfx::test::AreImagesEqual( |
267 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 300 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
268 | 301 |
269 // Fatal issues still take precedent over local routes. | 302 // Fatal issues still take precedent over local routes. |
270 action()->OnHasLocalDisplayRouteUpdated(true); | 303 action()->OnRoutesUpdated(local_display_route_list(), empty_route_id_list()); |
271 EXPECT_TRUE(gfx::test::AreImagesEqual( | 304 EXPECT_TRUE(gfx::test::AreImagesEqual( |
272 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 305 error_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
273 | 306 |
274 // When the fatal issue is dismissed, |current_icon_| reflects the existing | 307 // When the fatal issue is dismissed, |current_icon_| reflects the existing |
275 // local route. | 308 // local route. |
276 action()->OnIssueUpdated(nullptr); | 309 action()->OnIssueUpdated(nullptr); |
277 EXPECT_TRUE(gfx::test::AreImagesEqual( | 310 EXPECT_TRUE(gfx::test::AreImagesEqual( |
278 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 311 active_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
279 | 312 |
280 // Update |current_icon_| when the local route is closed. | 313 // Update |current_icon_| when the local route is closed. |
281 action()->OnHasLocalDisplayRouteUpdated(false); | 314 action()->OnRoutesUpdated(non_local_display_route_list(), |
| 315 empty_route_id_list()); |
282 EXPECT_TRUE(gfx::test::AreImagesEqual( | 316 EXPECT_TRUE(gfx::test::AreImagesEqual( |
283 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 317 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
284 } | 318 } |
285 | 319 |
286 TEST_F(MediaRouterActionUnitTest, IconPressedState) { | 320 TEST_F(MediaRouterActionUnitTest, IconPressedState) { |
287 // Start with one window with one tab. | 321 // Start with one window with one tab. |
288 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 322 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
289 chrome::NewTab(browser()); | 323 chrome::NewTab(browser()); |
290 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 324 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
291 | 325 |
(...skipping 23 matching lines...) Expand all Loading... |
315 | 349 |
316 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); | 350 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); |
317 dialog_controller_->HideMediaRouterDialog(); | 351 dialog_controller_->HideMediaRouterDialog(); |
318 | 352 |
319 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); | 353 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); |
320 dialog_controller_->CreateMediaRouterDialog(); | 354 dialog_controller_->CreateMediaRouterDialog(); |
321 | 355 |
322 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); | 356 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); |
323 dialog_controller_->HideMediaRouterDialog(); | 357 dialog_controller_->HideMediaRouterDialog(); |
324 } | 358 } |
OLD | NEW |