Chromium Code Reviews| 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() {} |
| 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 } |
| (...skipping 23 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_.reset(new media_router::MockMediaRouter()); |
|
msw
2017/02/08 02:14:02
optional nit: base::MakeUnique here and twice more
takumif
2017/02/08 03:35:41
Done.
| |
| 63 component_action_delegate_.reset(new FakeComponentActionDelegate()); | 61 component_action_delegate_.reset(new FakeComponentActionDelegate()); |
| 64 component_migration_helper_.reset(new ComponentMigrationHelper( | |
| 65 profile(), component_action_delegate_.get())); | |
| 66 controller_.reset(new MediaRouterActionController( | 62 controller_.reset(new MediaRouterActionController( |
| 67 profile(), router_.get(), component_action_delegate_.get(), | 63 profile(), router_.get(), component_action_delegate_.get())); |
| 68 component_migration_helper_.get())); | |
| 69 | 64 |
| 70 SetAlwaysShowActionPref(false); | 65 SetAlwaysShowActionPref(false); |
| 71 | 66 |
| 72 local_display_route_list_.push_back( | 67 local_display_route_list_.push_back( |
| 73 media_router::MediaRoute("routeId1", source1_, "sinkId1", "description", | 68 media_router::MediaRoute("routeId1", source1_, "sinkId1", "description", |
| 74 true, std::string(), true)); | 69 true, std::string(), true)); |
| 75 non_local_display_route_list_.push_back( | 70 non_local_display_route_list_.push_back( |
| 76 media_router::MediaRoute("routeId2", source1_, "sinkId2", "description", | 71 media_router::MediaRoute("routeId2", source1_, "sinkId2", "description", |
| 77 false, std::string(), true)); | 72 false, std::string(), true)); |
| 78 non_local_display_route_list_.push_back( | 73 non_local_display_route_list_.push_back( |
| 79 media_router::MediaRoute("routeId3", source2_, "sinkId3", "description", | 74 media_router::MediaRoute("routeId3", source2_, "sinkId3", "description", |
| 80 true, std::string(), false)); | 75 true, std::string(), false)); |
| 81 } | 76 } |
| 82 | 77 |
| 83 void TearDown() override { | 78 void TearDown() override { |
| 84 controller_.reset(); | 79 controller_.reset(); |
| 85 component_migration_helper_.reset(); | |
| 86 component_action_delegate_.reset(); | 80 component_action_delegate_.reset(); |
| 87 router_.reset(); | 81 router_.reset(); |
| 88 MediaRouterWebUITest::TearDown(); | 82 MediaRouterWebUITest::TearDown(); |
| 89 } | 83 } |
| 90 | 84 |
| 91 bool ActionExists() { | 85 bool ActionExists() { |
| 92 return component_action_delegate_->HasComponentAction( | 86 return component_action_delegate_->HasComponentAction( |
| 93 ComponentToolbarActionsFactory::kMediaRouterActionId); | 87 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 94 } | 88 } |
| 95 | 89 |
| 96 void SetAlwaysShowActionPref(bool always_show) { | 90 void SetAlwaysShowActionPref(bool always_show) { |
| 97 component_migration_helper_->SetComponentActionPref( | 91 MediaRouterActionController::SetAlwaysShowActionPref(profile(), |
| 98 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); | 92 always_show); |
| 99 } | 93 } |
| 100 | 94 |
| 101 MediaRouterActionController* controller() { return controller_.get(); } | 95 MediaRouterActionController* controller() { return controller_.get(); } |
| 102 | 96 |
| 103 const media_router::Issue& issue() { return issue_; } | 97 const media_router::Issue& issue() { return issue_; } |
| 104 const std::vector<media_router::MediaRoute>& local_display_route_list() | 98 const std::vector<media_router::MediaRoute>& local_display_route_list() |
| 105 const { | 99 const { |
| 106 return local_display_route_list_; | 100 return local_display_route_list_; |
| 107 } | 101 } |
| 108 const std::vector<media_router::MediaRoute>& non_local_display_route_list() | 102 const std::vector<media_router::MediaRoute>& non_local_display_route_list() |
| 109 const { | 103 const { |
| 110 return non_local_display_route_list_; | 104 return non_local_display_route_list_; |
| 111 } | 105 } |
| 112 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { | 106 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { |
| 113 return empty_route_id_list_; | 107 return empty_route_id_list_; |
| 114 } | 108 } |
| 115 | 109 |
| 116 private: | 110 private: |
| 117 std::unique_ptr<MediaRouterActionController> controller_; | 111 std::unique_ptr<MediaRouterActionController> controller_; |
| 118 std::unique_ptr<media_router::MockMediaRouter> router_; | 112 std::unique_ptr<media_router::MockMediaRouter> router_; |
| 119 std::unique_ptr<FakeComponentActionDelegate> component_action_delegate_; | 113 std::unique_ptr<FakeComponentActionDelegate> component_action_delegate_; |
| 120 std::unique_ptr<ComponentMigrationHelper> component_migration_helper_; | |
| 121 | 114 |
| 122 const media_router::Issue issue_; | 115 const media_router::Issue issue_; |
| 123 | 116 |
| 124 // Fake Sources, used for the Routes. | 117 // Fake Sources, used for the Routes. |
| 125 const media_router::MediaSource source1_; | 118 const media_router::MediaSource source1_; |
| 126 const media_router::MediaSource source2_; | 119 const media_router::MediaSource source2_; |
| 127 | 120 |
| 128 std::vector<media_router::MediaRoute> local_display_route_list_; | 121 std::vector<media_router::MediaRoute> local_display_route_list_; |
| 129 std::vector<media_router::MediaRoute> non_local_display_route_list_; | 122 std::vector<media_router::MediaRoute> non_local_display_route_list_; |
| 130 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; | 123 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 211 |
| 219 SetAlwaysShowActionPref(true); | 212 SetAlwaysShowActionPref(true); |
| 220 controller()->OnRoutesUpdated(non_local_display_route_list(), | 213 controller()->OnRoutesUpdated(non_local_display_route_list(), |
| 221 empty_route_id_list()); | 214 empty_route_id_list()); |
| 222 // Removing the local route should not hide the icon. | 215 // Removing the local route should not hide the icon. |
| 223 EXPECT_TRUE(ActionExists()); | 216 EXPECT_TRUE(ActionExists()); |
| 224 | 217 |
| 225 SetAlwaysShowActionPref(false); | 218 SetAlwaysShowActionPref(false); |
| 226 EXPECT_FALSE(ActionExists()); | 219 EXPECT_FALSE(ActionExists()); |
| 227 } | 220 } |
| OLD | NEW |