| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "chrome/browser/media/router/mock_media_router.h" | 8 #include "chrome/browser/media/router/mock_media_router.h" |
| 9 #include "chrome/browser/ui/toolbar/component_action_delegate.h" |
| 9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 10 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 10 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | 11 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" |
| 11 #include "chrome/browser/ui/webui/media_router/media_router_web_ui_test.h" | 12 #include "chrome/browser/ui/webui/media_router/media_router_web_ui_test.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 15 |
| 15 using extensions::ComponentMigrationHelper; | 16 class FakeComponentActionDelegate : public ComponentActionDelegate { |
| 16 | |
| 17 class FakeComponentActionDelegate | |
| 18 : public ComponentMigrationHelper::ComponentActionDelegate { | |
| 19 public: | 17 public: |
| 20 FakeComponentActionDelegate() {} | 18 FakeComponentActionDelegate() {} |
| 21 ~FakeComponentActionDelegate() {} | 19 ~FakeComponentActionDelegate() override {} |
| 22 | 20 |
| 23 void AddComponentAction(const std::string& action_id) override { | 21 void AddComponentAction(const std::string& action_id) override { |
| 24 EXPECT_EQ(action_id, ComponentToolbarActionsFactory::kMediaRouterActionId); | 22 EXPECT_EQ(action_id, ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 25 EXPECT_FALSE(HasComponentAction( | 23 EXPECT_FALSE(HasComponentAction( |
| 26 ComponentToolbarActionsFactory::kMediaRouterActionId)); | 24 ComponentToolbarActionsFactory::kMediaRouterActionId)); |
| 27 has_media_router_action_ = true; | 25 has_media_router_action_ = true; |
| 28 } | 26 } |
| 29 | 27 |
| 30 void RemoveComponentAction(const std::string& action_id) override { | 28 void RemoveComponentAction(const std::string& action_id) override { |
| 31 EXPECT_EQ(action_id, ComponentToolbarActionsFactory::kMediaRouterActionId); | 29 EXPECT_EQ(action_id, ComponentToolbarActionsFactory::kMediaRouterActionId); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 52 media_router::IssueInfo::Severity::NOTIFICATION)), | 50 media_router::IssueInfo::Severity::NOTIFICATION)), |
| 53 source1_("fakeSource1"), | 51 source1_("fakeSource1"), |
| 54 source2_("fakeSource2") {} | 52 source2_("fakeSource2") {} |
| 55 | 53 |
| 56 ~MediaRouterActionControllerUnitTest() override {} | 54 ~MediaRouterActionControllerUnitTest() override {} |
| 57 | 55 |
| 58 // MediaRouterWebUITest: | 56 // MediaRouterWebUITest: |
| 59 void SetUp() override { | 57 void SetUp() override { |
| 60 MediaRouterWebUITest::SetUp(); | 58 MediaRouterWebUITest::SetUp(); |
| 61 | 59 |
| 62 router_.reset(new media_router::MockMediaRouter()); | 60 router_ = base::MakeUnique<media_router::MockMediaRouter>(); |
| 63 component_action_delegate_.reset(new FakeComponentActionDelegate()); | 61 component_action_delegate_ = |
| 64 component_migration_helper_.reset(new ComponentMigrationHelper( | 62 base::MakeUnique<FakeComponentActionDelegate>(); |
| 65 profile(), component_action_delegate_.get())); | 63 controller_ = base::MakeUnique<MediaRouterActionController>( |
| 66 controller_.reset(new MediaRouterActionController( | 64 profile(), router_.get(), component_action_delegate_.get()); |
| 67 profile(), router_.get(), component_action_delegate_.get(), | |
| 68 component_migration_helper_.get())); | |
| 69 | 65 |
| 70 SetAlwaysShowActionPref(false); | 66 SetAlwaysShowActionPref(false); |
| 71 | 67 |
| 72 local_display_route_list_.push_back( | 68 local_display_route_list_.push_back( |
| 73 media_router::MediaRoute("routeId1", source1_, "sinkId1", "description", | 69 media_router::MediaRoute("routeId1", source1_, "sinkId1", "description", |
| 74 true, std::string(), true)); | 70 true, std::string(), true)); |
| 75 non_local_display_route_list_.push_back( | 71 non_local_display_route_list_.push_back( |
| 76 media_router::MediaRoute("routeId2", source1_, "sinkId2", "description", | 72 media_router::MediaRoute("routeId2", source1_, "sinkId2", "description", |
| 77 false, std::string(), true)); | 73 false, std::string(), true)); |
| 78 non_local_display_route_list_.push_back( | 74 non_local_display_route_list_.push_back( |
| 79 media_router::MediaRoute("routeId3", source2_, "sinkId3", "description", | 75 media_router::MediaRoute("routeId3", source2_, "sinkId3", "description", |
| 80 true, std::string(), false)); | 76 true, std::string(), false)); |
| 81 } | 77 } |
| 82 | 78 |
| 83 void TearDown() override { | 79 void TearDown() override { |
| 84 controller_.reset(); | 80 controller_.reset(); |
| 85 component_migration_helper_.reset(); | |
| 86 component_action_delegate_.reset(); | 81 component_action_delegate_.reset(); |
| 87 router_.reset(); | 82 router_.reset(); |
| 88 MediaRouterWebUITest::TearDown(); | 83 MediaRouterWebUITest::TearDown(); |
| 89 } | 84 } |
| 90 | 85 |
| 91 bool ActionExists() { | 86 bool ActionExists() { |
| 92 return component_action_delegate_->HasComponentAction( | 87 return component_action_delegate_->HasComponentAction( |
| 93 ComponentToolbarActionsFactory::kMediaRouterActionId); | 88 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 94 } | 89 } |
| 95 | 90 |
| 96 void SetAlwaysShowActionPref(bool always_show) { | 91 void SetAlwaysShowActionPref(bool always_show) { |
| 97 component_migration_helper_->SetComponentActionPref( | 92 MediaRouterActionController::SetAlwaysShowActionPref(profile(), |
| 98 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); | 93 always_show); |
| 99 } | 94 } |
| 100 | 95 |
| 101 MediaRouterActionController* controller() { return controller_.get(); } | 96 MediaRouterActionController* controller() { return controller_.get(); } |
| 102 | 97 |
| 103 const media_router::Issue& issue() { return issue_; } | 98 const media_router::Issue& issue() { return issue_; } |
| 104 const std::vector<media_router::MediaRoute>& local_display_route_list() | 99 const std::vector<media_router::MediaRoute>& local_display_route_list() |
| 105 const { | 100 const { |
| 106 return local_display_route_list_; | 101 return local_display_route_list_; |
| 107 } | 102 } |
| 108 const std::vector<media_router::MediaRoute>& non_local_display_route_list() | 103 const std::vector<media_router::MediaRoute>& non_local_display_route_list() |
| 109 const { | 104 const { |
| 110 return non_local_display_route_list_; | 105 return non_local_display_route_list_; |
| 111 } | 106 } |
| 112 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { | 107 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { |
| 113 return empty_route_id_list_; | 108 return empty_route_id_list_; |
| 114 } | 109 } |
| 115 | 110 |
| 116 private: | 111 private: |
| 117 std::unique_ptr<MediaRouterActionController> controller_; | 112 std::unique_ptr<MediaRouterActionController> controller_; |
| 118 std::unique_ptr<media_router::MockMediaRouter> router_; | 113 std::unique_ptr<media_router::MockMediaRouter> router_; |
| 119 std::unique_ptr<FakeComponentActionDelegate> component_action_delegate_; | 114 std::unique_ptr<FakeComponentActionDelegate> component_action_delegate_; |
| 120 std::unique_ptr<ComponentMigrationHelper> component_migration_helper_; | |
| 121 | 115 |
| 122 const media_router::Issue issue_; | 116 const media_router::Issue issue_; |
| 123 | 117 |
| 124 // Fake Sources, used for the Routes. | 118 // Fake Sources, used for the Routes. |
| 125 const media_router::MediaSource source1_; | 119 const media_router::MediaSource source1_; |
| 126 const media_router::MediaSource source2_; | 120 const media_router::MediaSource source2_; |
| 127 | 121 |
| 128 std::vector<media_router::MediaRoute> local_display_route_list_; | 122 std::vector<media_router::MediaRoute> local_display_route_list_; |
| 129 std::vector<media_router::MediaRoute> non_local_display_route_list_; | 123 std::vector<media_router::MediaRoute> non_local_display_route_list_; |
| 130 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; | 124 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 212 |
| 219 SetAlwaysShowActionPref(true); | 213 SetAlwaysShowActionPref(true); |
| 220 controller()->OnRoutesUpdated(non_local_display_route_list(), | 214 controller()->OnRoutesUpdated(non_local_display_route_list(), |
| 221 empty_route_id_list()); | 215 empty_route_id_list()); |
| 222 // Removing the local route should not hide the icon. | 216 // Removing the local route should not hide the icon. |
| 223 EXPECT_TRUE(ActionExists()); | 217 EXPECT_TRUE(ActionExists()); |
| 224 | 218 |
| 225 SetAlwaysShowActionPref(false); | 219 SetAlwaysShowActionPref(false); |
| 226 EXPECT_FALSE(ActionExists()); | 220 EXPECT_FALSE(ActionExists()); |
| 227 } | 221 } |
| OLD | NEW |