| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 class TestMediaRouterAction : public MediaRouterAction { | 38 class TestMediaRouterAction : public MediaRouterAction { |
| 39 public: | 39 public: |
| 40 TestMediaRouterAction(Browser* browser, | 40 TestMediaRouterAction(Browser* browser, |
| 41 ToolbarActionsBar* toolbar_actions_bar) | 41 ToolbarActionsBar* toolbar_actions_bar) |
| 42 : MediaRouterAction(browser, toolbar_actions_bar), | 42 : MediaRouterAction(browser, toolbar_actions_bar), |
| 43 controller_(nullptr), | 43 controller_(nullptr), |
| 44 platform_delegate_(nullptr) {} | 44 platform_delegate_(nullptr) {} |
| 45 ~TestMediaRouterAction() override {} | 45 ~TestMediaRouterAction() override {} |
| 46 | 46 |
| 47 // MediaRouterAction: |
| 48 void ActiveTabChanged(content::WebContents* old_contents, |
| 49 content::WebContents* new_contents, |
| 50 int index, |
| 51 int reason) override { |
| 52 // This would be null if |controller_| hasn't been set. |
| 53 if (GetMediaRouterDialogController()) { |
| 54 MediaRouterAction::ActiveTabChanged(old_contents, new_contents, index, |
| 55 reason); |
| 56 } |
| 57 } |
| 58 |
| 47 void SetMediaRouterDialogController( | 59 void SetMediaRouterDialogController( |
| 48 MediaRouterDialogControllerImpl* controller) { | 60 MediaRouterDialogControllerImpl* controller) { |
| 49 DCHECK(controller); | 61 DCHECK(controller); |
| 50 controller_ = controller; | 62 controller_ = controller; |
| 51 } | 63 } |
| 52 | 64 |
| 53 private: | 65 private: |
| 66 // MediaRouterAction: |
| 54 MediaRouterDialogControllerImpl* GetMediaRouterDialogController() | 67 MediaRouterDialogControllerImpl* GetMediaRouterDialogController() |
| 55 override { | 68 override { |
| 56 return controller_; | 69 return controller_; |
| 57 } | 70 } |
| 58 | |
| 59 MediaRouterActionPlatformDelegate* GetPlatformDelegate() override { | 71 MediaRouterActionPlatformDelegate* GetPlatformDelegate() override { |
| 60 return platform_delegate_; | 72 return platform_delegate_; |
| 61 } | 73 } |
| 62 | 74 |
| 63 MediaRouterDialogControllerImpl* controller_; | 75 MediaRouterDialogControllerImpl* controller_; |
| 64 MediaRouterActionPlatformDelegate* platform_delegate_; | 76 MediaRouterActionPlatformDelegate* platform_delegate_; |
| 65 }; | 77 }; |
| 66 | 78 |
| 67 class MediaRouterActionUnitTest : public MediaRouterTest { | 79 class MediaRouterActionUnitTest : public MediaRouterTest { |
| 68 public: | 80 public: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 gfx::kPlaceholderColor)), | 119 gfx::kPlaceholderColor)), |
| 108 warning_icon_( | 120 warning_icon_( |
| 109 gfx::CreateVectorIcon(gfx::VectorIconId::MEDIA_ROUTER_WARNING, | 121 gfx::CreateVectorIcon(gfx::VectorIconId::MEDIA_ROUTER_WARNING, |
| 110 gfx::kPlaceholderColor)) {} | 122 gfx::kPlaceholderColor)) {} |
| 111 | 123 |
| 112 ~MediaRouterActionUnitTest() override {} | 124 ~MediaRouterActionUnitTest() override {} |
| 113 | 125 |
| 114 // MediaRouterTest: | 126 // MediaRouterTest: |
| 115 void SetUp() override { | 127 void SetUp() override { |
| 116 MediaRouterTest::SetUp(); | 128 MediaRouterTest::SetUp(); |
| 117 toolbar_model_ = extensions::extension_action_test_util:: | 129 toolbar_model_ = |
| 118 CreateToolbarModelForProfileWithoutWaitingForReady(profile()); | 130 extensions::extension_action_test_util::CreateToolbarModelForProfile( |
| 131 profile()); |
| 119 | 132 |
| 120 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() | 133 // browser() will only be valid once BrowserWithTestWindowTest::SetUp() |
| 121 // has run. | 134 // has run. |
| 122 browser_action_test_util_.reset( | 135 browser_action_test_util_.reset( |
| 123 new BrowserActionTestUtil(browser(), false)); | 136 new BrowserActionTestUtil(browser(), false)); |
| 124 action_.reset( | 137 action_.reset( |
| 125 new TestMediaRouterAction( | 138 new TestMediaRouterAction( |
| 126 browser(), | 139 browser(), |
| 127 browser_action_test_util_->GetToolbarActionsBar())); | 140 browser_action_test_util_->GetToolbarActionsBar())); |
| 128 | 141 |
| 129 local_display_route_list_.push_back( | 142 local_display_route_list_.push_back( |
| 130 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", | 143 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", |
| 131 "description", true, std::string(), true)); | 144 "description", true, std::string(), true)); |
| 132 non_local_display_route_list_.push_back( | 145 non_local_display_route_list_.push_back( |
| 133 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", | 146 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", |
| 134 "description", false, std::string(), true)); | 147 "description", false, std::string(), true)); |
| 135 non_local_display_route_list_.push_back( | 148 non_local_display_route_list_.push_back( |
| 136 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", | 149 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", |
| 137 "description", true, std::string(), false)); | 150 "description", true, std::string(), false)); |
| 138 } | 151 } |
| 139 | 152 |
| 140 void TearDown() override { | 153 void TearDown() override { |
| 154 action_.reset(); |
| 141 browser_action_test_util_.reset(); | 155 browser_action_test_util_.reset(); |
| 142 action_.reset(); | |
| 143 MediaRouterTest::TearDown(); | 156 MediaRouterTest::TearDown(); |
| 144 } | 157 } |
| 145 | 158 |
| 146 TestMediaRouterAction* action() { return action_.get(); } | 159 TestMediaRouterAction* action() { return action_.get(); } |
| 147 const media_router::Issue* fake_issue_notification() { | 160 const media_router::Issue* fake_issue_notification() { |
| 148 return &fake_issue_notification_; | 161 return &fake_issue_notification_; |
| 149 } | 162 } |
| 150 const media_router::Issue* fake_issue_warning() { | 163 const media_router::Issue* fake_issue_warning() { |
| 151 return &fake_issue_warning_; | 164 return &fake_issue_warning_; |
| 152 } | 165 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 EXPECT_TRUE(gfx::test::AreImagesEqual( | 331 EXPECT_TRUE(gfx::test::AreImagesEqual( |
| 319 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); | 332 idle_icon(), action()->GetIcon(nullptr, gfx::Size()))); |
| 320 } | 333 } |
| 321 | 334 |
| 322 TEST_F(MediaRouterActionUnitTest, IconPressedState) { | 335 TEST_F(MediaRouterActionUnitTest, IconPressedState) { |
| 323 // Start with one window with one tab. | 336 // Start with one window with one tab. |
| 324 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 337 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 325 chrome::NewTab(browser()); | 338 chrome::NewTab(browser()); |
| 326 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 339 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 327 | 340 |
| 328 // Create a reference to initiator contents. | 341 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); |
| 329 WebContents* initiator_ = | 342 MediaRouterDialogControllerImpl::CreateForWebContents(initiator); |
| 330 browser()->tab_strip_model()->GetActiveWebContents(); | 343 MediaRouterDialogControllerImpl* dialog_controller = |
| 331 | 344 MediaRouterDialogControllerImpl::FromWebContents(initiator); |
| 332 MediaRouterDialogControllerImpl::CreateForWebContents(initiator_); | 345 ASSERT_TRUE(dialog_controller); |
| 333 MediaRouterDialogControllerImpl* dialog_controller_ = | |
| 334 MediaRouterDialogControllerImpl::FromWebContents(initiator_); | |
| 335 ASSERT_TRUE(dialog_controller_); | |
| 336 | 346 |
| 337 // Sets the controller to use for TestMediaRouterAction. | 347 // Sets the controller to use for TestMediaRouterAction. |
| 338 action()->SetMediaRouterDialogController(dialog_controller_); | 348 action()->SetMediaRouterDialogController(dialog_controller); |
| 339 | 349 |
| 340 // Create a ToolbarActionViewDelegate to use for MediaRouterAction. | 350 // Create a ToolbarActionViewDelegate to use for MediaRouterAction. |
| 341 std::unique_ptr<MockToolbarActionViewDelegate> mock_delegate( | 351 std::unique_ptr<MockToolbarActionViewDelegate> mock_delegate( |
| 342 new MockToolbarActionViewDelegate()); | 352 new MockToolbarActionViewDelegate()); |
| 343 | 353 |
| 344 EXPECT_CALL(*mock_delegate, GetCurrentWebContents()).WillOnce( | 354 EXPECT_CALL(*mock_delegate, GetCurrentWebContents()) |
| 345 testing::Return(initiator_)); | 355 .WillOnce(testing::Return(initiator)); |
| 346 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); | |
| 347 action()->SetDelegate(mock_delegate.get()); | 356 action()->SetDelegate(mock_delegate.get()); |
| 348 | 357 |
| 349 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); | 358 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); |
| 350 action()->ExecuteAction(true); | 359 action()->ExecuteAction(true); |
| 360 EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog()); |
| 351 | 361 |
| 352 // Pressing the icon while the popup is shown should close the popup | 362 // Pressing the icon while the popup is shown should close the popup |
| 353 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); | 363 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); |
| 354 action()->ExecuteAction(true); | 364 action()->ExecuteAction(true); |
| 365 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); |
| 355 | 366 |
| 356 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); | 367 EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1); |
| 357 dialog_controller_->CreateMediaRouterDialog(); | 368 dialog_controller->CreateMediaRouterDialog(); |
| 358 | 369 |
| 359 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); | 370 EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1); |
| 360 dialog_controller_->HideMediaRouterDialog(); | 371 dialog_controller->HideMediaRouterDialog(); |
| 361 } | 372 } |
| OLD | NEW |