Chromium Code Reviews| Index: chrome/browser/ui/toolbar/media_router_action_controller_unittest.cc |
| diff --git a/chrome/browser/ui/toolbar/media_router_action_controller_unittest.cc b/chrome/browser/ui/toolbar/media_router_action_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bd0609f035fc5f36a1c0bc4c6f611aeb61c86f5b |
| --- /dev/null |
| +++ b/chrome/browser/ui/toolbar/media_router_action_controller_unittest.cc |
| @@ -0,0 +1,184 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/media/router/mock_media_router.h" |
| +#include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| +#include "chrome/browser/ui/toolbar/media_router_action_controller.h" |
| +#include "chrome/browser/ui/webui/media_router/media_router_test.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| + |
| +using extensions::ComponentMigrationHelper; |
| + |
| +class TestComponentActionDelegate |
|
mark a. foltz
2016/09/13 18:23:05
Nit: This class reads like a "fake" to me, so Fake
takumif
2016/09/14 04:00:52
Done.
|
| + : public ComponentMigrationHelper::ComponentActionDelegate { |
| + public: |
| + TestComponentActionDelegate() : has_media_router_action_(false) {} |
| + ~TestComponentActionDelegate() {} |
| + |
| + void AddComponentAction(const std::string& action_id) override { |
| + if (action_id == ComponentToolbarActionsFactory::kMediaRouterActionId) { |
|
mark a. foltz
2016/09/13 18:23:05
using ComponentToolbarActionsFactory::kMediaRouter
takumif
2016/09/14 04:00:52
using ComponentToolbarActionsFactory::kMediaRouter
|
| + EXPECT_FALSE(HasComponentAction( |
| + ComponentToolbarActionsFactory::kMediaRouterActionId)); |
| + has_media_router_action_ = true; |
| + } |
| + } |
| + |
| + void RemoveComponentAction(const std::string& action_id) override { |
| + if (action_id == ComponentToolbarActionsFactory::kMediaRouterActionId) { |
| + EXPECT_TRUE(HasComponentAction( |
| + ComponentToolbarActionsFactory::kMediaRouterActionId)); |
| + has_media_router_action_ = false; |
| + } |
| + } |
| + |
| + bool HasComponentAction(const std::string& action_id) const override { |
| + if (action_id == ComponentToolbarActionsFactory::kMediaRouterActionId) |
| + return has_media_router_action_; |
| + return false; |
| + } |
| + |
| + private: |
| + bool has_media_router_action_; |
| +}; |
| + |
| +class MediaRouterActionControllerUnitTest : public MediaRouterTest { |
| + public: |
| + MediaRouterActionControllerUnitTest() |
| + : fake_issue_(media_router::Issue( |
| + "title notification", |
| + "message notification", |
| + media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), |
| + std::vector<media_router::IssueAction>(), |
| + "route_id", |
| + media_router::Issue::NOTIFICATION, |
| + false, |
| + -1)), |
| + fake_source1_("fakeSource1"), |
| + fake_source2_("fakeSource2") {} |
| + |
| + ~MediaRouterActionControllerUnitTest() override {} |
| + |
| + // MediaRouterTest: |
| + void SetUp() override { |
| + MediaRouterTest::SetUp(); |
| + |
| + router_.reset(new media_router::MockMediaRouter()); |
| + component_action_delegate_.reset(new TestComponentActionDelegate()); |
| + component_migration_helper_.reset(new ComponentMigrationHelper( |
| + profile(), component_action_delegate_.get())); |
| + controller_.reset(new MediaRouterActionController( |
| + profile(), router_.get(), component_action_delegate_.get(), |
| + component_migration_helper_.get())); |
| + |
| + local_display_route_list_.push_back( |
| + media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", |
| + "description", true, std::string(), true)); |
| + non_local_display_route_list_.push_back( |
| + media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", |
| + "description", false, std::string(), true)); |
| + non_local_display_route_list_.push_back( |
| + media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", |
| + "description", true, std::string(), false)); |
| + } |
| + |
| + void TearDown() override { |
| + controller_.reset(); |
| + component_migration_helper_.reset(); |
| + component_action_delegate_.reset(); |
| + router_.reset(); |
| + MediaRouterTest::TearDown(); |
| + } |
| + |
| + bool ActionExists() { |
| + return component_action_delegate_->HasComponentAction( |
| + ComponentToolbarActionsFactory::kMediaRouterActionId); |
| + } |
| + |
| + MediaRouterActionController* controller() { return controller_.get(); } |
| + |
| + const media_router::Issue* fake_issue() { return &fake_issue_; } |
| + const std::vector<media_router::MediaRoute>& local_display_route_list() |
| + const { |
| + return local_display_route_list_; |
| + } |
| + const std::vector<media_router::MediaRoute>& non_local_display_route_list() |
| + const { |
| + return non_local_display_route_list_; |
| + } |
| + const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { |
| + return empty_route_id_list_; |
| + } |
| + |
| + private: |
| + std::unique_ptr<MediaRouterActionController> controller_; |
| + std::unique_ptr<media_router::MockMediaRouter> router_; |
| + std::unique_ptr<TestComponentActionDelegate> component_action_delegate_; |
| + std::unique_ptr<ComponentMigrationHelper> component_migration_helper_; |
| + |
| + const media_router::Issue fake_issue_; |
|
mark a. foltz
2016/09/13 18:23:05
Nit: It's implied that data declared in a test is
takumif
2016/09/14 04:00:52
Okay. Renaming.
|
| + |
| + // Fake Sources, used for the Routes. |
| + const media_router::MediaSource fake_source1_; |
| + const media_router::MediaSource fake_source2_; |
| + |
| + std::vector<media_router::MediaRoute> local_display_route_list_; |
| + std::vector<media_router::MediaRoute> non_local_display_route_list_; |
| + std::vector<media_router::MediaRoute::Id> empty_route_id_list_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MediaRouterActionControllerUnitTest); |
| +}; |
| + |
| +TEST_F(MediaRouterActionControllerUnitTest, EphemeralIcon) { |
| + EXPECT_FALSE(ActionExists()); |
| + |
| + // Creating a local route should show the action icon. |
| + controller()->OnRoutesUpdated(local_display_route_list(), |
| + empty_route_id_list()); |
| + EXPECT_TRUE(controller()->has_local_display_route_); |
| + EXPECT_TRUE(ActionExists()); |
| + // Removing the local route should hide the icon. |
| + controller()->OnRoutesUpdated(non_local_display_route_list(), |
| + empty_route_id_list()); |
| + EXPECT_FALSE(controller()->has_local_display_route_); |
| + EXPECT_FALSE(ActionExists()); |
| + |
| + // Creating an issue should show the action icon. |
| + controller()->OnIssueUpdated(fake_issue()); |
| + EXPECT_TRUE(controller()->has_issue_); |
| + EXPECT_TRUE(ActionExists()); |
| + // Removing the issue should hide the icon. |
| + controller()->OnIssueUpdated(nullptr); |
| + EXPECT_FALSE(controller()->has_issue_); |
| + EXPECT_FALSE(ActionExists()); |
| + |
| + controller()->OnIssueUpdated(fake_issue()); |
| + controller()->OnRoutesUpdated(local_display_route_list(), |
| + empty_route_id_list()); |
| + controller()->OnIssueUpdated(nullptr); |
| + // When the issue disappears, the icon should remain visible if there's |
| + // a local route. |
| + EXPECT_TRUE(ActionExists()); |
| + controller()->OnRoutesUpdated(non_local_display_route_list(), |
| + empty_route_id_list()); |
| + EXPECT_FALSE(ActionExists()); |
|
mark a. foltz
2016/09/13 18:23:05
Also test removing route and verify that action no
takumif
2016/09/14 04:00:52
Done.
|
| +} |
| + |
| +TEST_F(MediaRouterActionControllerUnitTest, ObserveAlwaysShowPrefChange) { |
|
mark a. foltz
2016/09/13 18:23:05
Also test changing the pref to false while there i
takumif
2016/09/14 04:00:52
Done.
|
| + EXPECT_FALSE(ActionExists()); |
| + |
| + std::unique_ptr<DictionaryPrefUpdate> pref(new DictionaryPrefUpdate( |
| + profile()->GetPrefs(), ::prefs::kToolbarMigratedComponentActionStatus)); |
| + (*pref.get()) |
| + ->SetBoolean(ComponentToolbarActionsFactory::kMediaRouterActionId, true); |
| + // Reset |pref| to flush the changes. |
| + pref.reset(new DictionaryPrefUpdate( |
| + profile()->GetPrefs(), ::prefs::kToolbarMigratedComponentActionStatus)); |
| + EXPECT_TRUE(ActionExists()); |
| + |
| + (*pref.get()) |
| + ->SetBoolean(ComponentToolbarActionsFactory::kMediaRouterActionId, false); |
| + pref.reset(); |
| + EXPECT_FALSE(ActionExists()); |
| +} |