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

Unified Diff: chrome/browser/ui/toolbar/media_router_action_unittest.cc

Issue 2332693003: Show media router toolbar icon ephemerally for active local routes and issues (Closed)
Patch Set: Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/media_router_action_unittest.cc
diff --git a/chrome/browser/ui/toolbar/media_router_action_unittest.cc b/chrome/browser/ui/toolbar/media_router_action_unittest.cc
index d09f0225681e175132a815f50659208f07e74950..c735c1cd111098f093d2beef3c3b7dd3b394df87 100644
--- a/chrome/browser/ui/toolbar/media_router_action_unittest.cc
+++ b/chrome/browser/ui/toolbar/media_router_action_unittest.cc
@@ -2,11 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "base/auto_reset.h"
+#include "base/command_line.h"
#include "base/macros.h"
#include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_action_test_util.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
#include "chrome/browser/ui/toolbar/media_router_action.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
#include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.h"
@@ -44,10 +51,22 @@ class TestMediaRouterAction : public MediaRouterAction {
platform_delegate_(nullptr) {}
~TestMediaRouterAction() override {}
+ void ActiveTabChanged(content::WebContents* old_contents,
+ content::WebContents* new_contents,
imcheng 2016/09/16 21:47:49 nit: please fix indent
takumif 2016/09/20 14:50:46 Done.
+ int index,
+ int reason) override {
+ // This would be null if |controller_| hasn't been set.
+ if (GetMediaRouterDialogController()) {
+ MediaRouterAction::ActiveTabChanged(
+ old_contents, new_contents, index, reason);
+ }
+ }
+
void SetMediaRouterDialogController(
MediaRouterDialogControllerImpl* controller) {
DCHECK(controller);
controller_ = controller;
+ controller_->SetMediaRouterAction(GetWeakPtr());
imcheng 2016/09/16 21:47:49 Is this needed if you don't call SetDelegate a sec
takumif 2016/09/20 14:50:46 No, this is not necessary. Removing.
}
private:
@@ -115,7 +134,7 @@ class MediaRouterActionUnitTest : public MediaRouterTest {
void SetUp() override {
MediaRouterTest::SetUp();
toolbar_model_ = extensions::extension_action_test_util::
- CreateToolbarModelForProfileWithoutWaitingForReady(profile());
+ CreateToolbarModelForProfile(profile());
// browser() will only be valid once BrowserWithTestWindowTest::SetUp()
// has run.
@@ -126,6 +145,8 @@ class MediaRouterActionUnitTest : public MediaRouterTest {
browser(),
browser_action_test_util_->GetToolbarActionsBar()));
+ action()->SetDelegate(new MockToolbarActionViewDelegate());
+
local_display_route_list_.push_back(
media_router::MediaRoute("routeId1", fake_source1_, "sinkId1",
"description", true, std::string(), true));
@@ -138,8 +159,8 @@ class MediaRouterActionUnitTest : public MediaRouterTest {
}
void TearDown() override {
- browser_action_test_util_.reset();
action_.reset();
+ browser_action_test_util_.reset();
MediaRouterTest::TearDown();
}
@@ -320,42 +341,38 @@ TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) {
}
TEST_F(MediaRouterActionUnitTest, IconPressedState) {
+ base::AutoReset<bool> disable_animations(
imcheng 2016/09/16 21:47:49 Please add comments on why this is needed?
takumif 2016/09/20 14:50:46 This is no longer necessary. Removed.
+ &ToolbarActionsBar::disable_animations_for_testing_, true);
+
// Start with one window with one tab.
EXPECT_EQ(0, browser()->tab_strip_model()->count());
chrome::NewTab(browser());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
- // Create a reference to initiator contents.
- WebContents* initiator_ =
- browser()->tab_strip_model()->GetActiveWebContents();
-
- MediaRouterDialogControllerImpl::CreateForWebContents(initiator_);
- MediaRouterDialogControllerImpl* dialog_controller_ =
- MediaRouterDialogControllerImpl::FromWebContents(initiator_);
- ASSERT_TRUE(dialog_controller_);
+ WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
+ MediaRouterDialogControllerImpl::CreateForWebContents(initiator);
+ MediaRouterDialogControllerImpl* dialog_controller =
+ MediaRouterDialogControllerImpl::FromWebContents(initiator);
+ ASSERT_TRUE(dialog_controller);
// Sets the controller to use for TestMediaRouterAction.
- action()->SetMediaRouterDialogController(dialog_controller_);
+ action()->SetMediaRouterDialogController(dialog_controller);
// Create a ToolbarActionViewDelegate to use for MediaRouterAction.
std::unique_ptr<MockToolbarActionViewDelegate> mock_delegate(
new MockToolbarActionViewDelegate());
-
- EXPECT_CALL(*mock_delegate, GetCurrentWebContents()).WillOnce(
- testing::Return(initiator_));
- EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
action()->SetDelegate(mock_delegate.get());
imcheng 2016/09/16 21:47:49 You changed the test to call SetDelegate() during
takumif 2016/09/20 14:50:46 Removed the first call.
- EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1);
action()->ExecuteAction(true);
+ EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog());
// Pressing the icon while the popup is shown should close the popup
- EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
action()->ExecuteAction(true);
+ EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog());
EXPECT_CALL(*mock_delegate, OnPopupShown(true)).Times(1);
- dialog_controller_->CreateMediaRouterDialog();
+ dialog_controller->CreateMediaRouterDialog();
EXPECT_CALL(*mock_delegate, OnPopupClosed()).Times(1);
- dialog_controller_->HideMediaRouterDialog();
+ dialog_controller->HideMediaRouterDialog();
}

Powered by Google App Engine
This is Rietveld 408576698