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_toolbar_actions_factory.h" | 9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 10 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | 10 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" |
| 11 #include "chrome/browser/ui/webui/media_router/media_router_test.h" | 11 #include "chrome/browser/ui/webui/media_router/media_router_web_ui_test.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 14 |
| 15 using extensions::ComponentMigrationHelper; | 15 using extensions::ComponentMigrationHelper; |
| 16 | 16 |
| 17 class FakeComponentActionDelegate | 17 class FakeComponentActionDelegate |
| 18 : public ComponentMigrationHelper::ComponentActionDelegate { | 18 : public ComponentMigrationHelper::ComponentActionDelegate { |
| 19 public: | 19 public: |
| 20 FakeComponentActionDelegate() {} | 20 FakeComponentActionDelegate() {} |
| 21 ~FakeComponentActionDelegate() {} | 21 ~FakeComponentActionDelegate() {} |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 bool HasComponentAction(const std::string& action_id) const override { | 37 bool HasComponentAction(const std::string& action_id) const override { |
| 38 EXPECT_EQ(action_id, ComponentToolbarActionsFactory::kMediaRouterActionId); | 38 EXPECT_EQ(action_id, ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 39 return has_media_router_action_; | 39 return has_media_router_action_; |
| 40 } | 40 } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 bool has_media_router_action_ = false; | 43 bool has_media_router_action_ = false; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class MediaRouterActionControllerUnitTest : public MediaRouterTest { | 46 class MediaRouterActionControllerUnitTest : public MediaRouterWebUITest { |
| 47 public: | 47 public: |
| 48 MediaRouterActionControllerUnitTest() | 48 MediaRouterActionControllerUnitTest() |
| 49 : issue_(media_router::Issue( | 49 : issue_(media_router::Issue( |
| 50 "title notification", | 50 "title notification", |
| 51 "message notification", | 51 "message notification", |
| 52 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), | 52 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), |
| 53 std::vector<media_router::IssueAction>(), | 53 std::vector<media_router::IssueAction>(), |
| 54 "route_id", | 54 "route_id", |
| 55 media_router::Issue::NOTIFICATION, | 55 media_router::Issue::NOTIFICATION, |
| 56 false, | 56 false, |
| 57 -1)), | 57 -1)), |
| 58 source1_("fakeSource1"), | 58 source1_("fakeSource1"), |
| 59 source2_("fakeSource2") {} | 59 source2_("fakeSource2") {} |
| 60 | 60 |
| 61 ~MediaRouterActionControllerUnitTest() override {} | 61 ~MediaRouterActionControllerUnitTest() override {} |
| 62 | 62 |
| 63 // MediaRouterTest: | 63 // MediaRouterWebUITest: |
| 64 void SetUp() override { | 64 void SetUp() override { |
| 65 MediaRouterTest::SetUp(); | 65 MediaRouterWebUITest::SetUp(); |
| 66 | 66 |
| 67 router_.reset(new media_router::MockMediaRouter()); | 67 router_.reset(new media_router::MockMediaRouter()); |
| 68 component_action_delegate_.reset(new FakeComponentActionDelegate()); | 68 component_action_delegate_.reset(new FakeComponentActionDelegate()); |
| 69 component_migration_helper_.reset(new ComponentMigrationHelper( | 69 component_migration_helper_.reset(new ComponentMigrationHelper( |
| 70 profile(), component_action_delegate_.get())); | 70 profile(), component_action_delegate_.get())); |
| 71 controller_.reset(new MediaRouterActionController( | 71 controller_.reset(new MediaRouterActionController( |
| 72 profile(), router_.get(), component_action_delegate_.get(), | 72 profile(), router_.get(), component_action_delegate_.get(), |
| 73 component_migration_helper_.get())); | 73 component_migration_helper_.get())); |
| 74 | 74 |
| 75 SetAlwaysShowActionPref(false); | 75 SetAlwaysShowActionPref(false); |
| 76 | 76 |
| 77 local_display_route_list_.push_back( | 77 local_display_route_list_.push_back( |
| 78 media_router::MediaRoute("routeId1", source1_, "sinkId1", "description", | 78 media_router::MediaRoute("routeId1", source1_, "sinkId1", "description", |
| 79 true, std::string(), true)); | 79 true, std::string(), true)); |
| 80 non_local_display_route_list_.push_back( | 80 non_local_display_route_list_.push_back( |
| 81 media_router::MediaRoute("routeId2", source1_, "sinkId2", "description", | 81 media_router::MediaRoute("routeId2", source1_, "sinkId2", "description", |
| 82 false, std::string(), true)); | 82 false, std::string(), true)); |
| 83 non_local_display_route_list_.push_back( | 83 non_local_display_route_list_.push_back( |
| 84 media_router::MediaRoute("routeId3", source2_, "sinkId3", "description", | 84 media_router::MediaRoute("routeId3", source2_, "sinkId3", "description", |
| 85 true, std::string(), false)); | 85 true, std::string(), false)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void TearDown() override { | 88 void TearDown() override { |
| 89 controller_.reset(); | 89 controller_.reset(); |
| 90 component_migration_helper_.reset(); | 90 component_migration_helper_.reset(); |
| 91 component_action_delegate_.reset(); | 91 component_action_delegate_.reset(); |
| 92 router_.reset(); | 92 router_.reset(); |
| 93 MediaRouterTest::TearDown(); | 93 MediaRouterWebUITest::TearDown(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ActionExists() { | 96 bool ActionExists() { |
| 97 return component_action_delegate_->HasComponentAction( | 97 return component_action_delegate_->HasComponentAction( |
| 98 ComponentToolbarActionsFactory::kMediaRouterActionId); | 98 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SetAlwaysShowActionPref(bool always_show) { | 101 void SetAlwaysShowActionPref(bool always_show) { |
| 102 component_migration_helper_->SetComponentActionPref( | 102 component_migration_helper_->SetComponentActionPref( |
| 103 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); | 103 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 130 const media_router::MediaSource source1_; | 130 const media_router::MediaSource source1_; |
| 131 const media_router::MediaSource source2_; | 131 const media_router::MediaSource source2_; |
| 132 | 132 |
| 133 std::vector<media_router::MediaRoute> local_display_route_list_; | 133 std::vector<media_router::MediaRoute> local_display_route_list_; |
| 134 std::vector<media_router::MediaRoute> non_local_display_route_list_; | 134 std::vector<media_router::MediaRoute> non_local_display_route_list_; |
| 135 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; | 135 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionControllerUnitTest); | 137 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionControllerUnitTest); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 TEST_F(MediaRouterActionControllerUnitTest, EphemeralIcon) { | 140 TEST_F(MediaRouterActionControllerUnitTest, EphemeralIconForRoutesAndIssues) { |
| 141 EXPECT_FALSE(ActionExists()); | 141 EXPECT_FALSE(ActionExists()); |
| 142 | 142 |
| 143 // Creating a local route should show the action icon. | 143 // Creating a local route should show the action icon. |
| 144 controller()->OnRoutesUpdated(local_display_route_list(), | 144 controller()->OnRoutesUpdated(local_display_route_list(), |
| 145 empty_route_id_list()); | 145 empty_route_id_list()); |
| 146 EXPECT_TRUE(controller()->has_local_display_route_); | 146 EXPECT_TRUE(controller()->has_local_display_route_); |
| 147 EXPECT_TRUE(ActionExists()); | 147 EXPECT_TRUE(ActionExists()); |
| 148 // Removing the local route should hide the icon. | 148 // Removing the local route should hide the icon. |
| 149 controller()->OnRoutesUpdated(non_local_display_route_list(), | 149 controller()->OnRoutesUpdated(non_local_display_route_list(), |
| 150 empty_route_id_list()); | 150 empty_route_id_list()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 165 empty_route_id_list()); | 165 empty_route_id_list()); |
| 166 controller()->OnIssueUpdated(nullptr); | 166 controller()->OnIssueUpdated(nullptr); |
| 167 // When the issue disappears, the icon should remain visible if there's | 167 // When the issue disappears, the icon should remain visible if there's |
| 168 // a local route. | 168 // a local route. |
| 169 EXPECT_TRUE(ActionExists()); | 169 EXPECT_TRUE(ActionExists()); |
| 170 controller()->OnRoutesUpdated(std::vector<media_router::MediaRoute>(), | 170 controller()->OnRoutesUpdated(std::vector<media_router::MediaRoute>(), |
| 171 empty_route_id_list()); | 171 empty_route_id_list()); |
| 172 EXPECT_FALSE(ActionExists()); | 172 EXPECT_FALSE(ActionExists()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(MediaRouterActionControllerUnitTest, EphemeralIconForDialog) { | |
| 176 EXPECT_FALSE(ActionExists()); | |
| 177 | |
| 178 // Showing a dialog should show the icon. | |
| 179 controller()->OnDialogShown(); | |
| 180 EXPECT_TRUE(ActionExists()); | |
| 181 // Showing and hiding a dialog shouldn't hide the icon as long as we have a | |
| 182 // positive number of dialogs. | |
| 183 controller()->OnDialogShown(); | |
| 184 EXPECT_TRUE(ActionExists()); | |
| 185 controller()->OnDialogHidden(); | |
| 186 EXPECT_TRUE(ActionExists()); | |
| 187 // When we have zero dialogs, the icon should be hidden. | |
| 188 controller()->OnDialogHidden(); | |
| 189 EXPECT_FALSE(ActionExists()); | |
| 190 | |
| 191 controller()->OnDialogShown(); | |
| 192 EXPECT_TRUE(ActionExists()); | |
| 193 controller()->OnRoutesUpdated(local_display_route_list(), | |
| 194 empty_route_id_list()); | |
| 195 // Hiding the dialog while there are local routes shouldn't hide the icon. | |
|
mark a. foltz
2016/11/01 02:00:08
Add one more test case for hiding dialog + issue s
takumif
2016/11/02 03:16:54
Done.
| |
| 196 controller()->OnDialogHidden(); | |
| 197 EXPECT_TRUE(ActionExists()); | |
| 198 controller()->OnRoutesUpdated(non_local_display_route_list(), | |
| 199 empty_route_id_list()); | |
| 200 EXPECT_FALSE(ActionExists()); | |
| 201 } | |
| 202 | |
| 175 TEST_F(MediaRouterActionControllerUnitTest, ObserveAlwaysShowPrefChange) { | 203 TEST_F(MediaRouterActionControllerUnitTest, ObserveAlwaysShowPrefChange) { |
| 176 EXPECT_FALSE(ActionExists()); | 204 EXPECT_FALSE(ActionExists()); |
| 177 | 205 |
| 178 SetAlwaysShowActionPref(true); | 206 SetAlwaysShowActionPref(true); |
| 179 EXPECT_TRUE(ActionExists()); | 207 EXPECT_TRUE(ActionExists()); |
| 180 | 208 |
| 181 controller()->OnRoutesUpdated(local_display_route_list(), | 209 controller()->OnRoutesUpdated(local_display_route_list(), |
| 182 empty_route_id_list()); | 210 empty_route_id_list()); |
| 183 SetAlwaysShowActionPref(false); | 211 SetAlwaysShowActionPref(false); |
| 184 // Unchecking the option while having a local route shouldn't hide the icon. | 212 // Unchecking the option while having a local route shouldn't hide the icon. |
| 185 EXPECT_TRUE(ActionExists()); | 213 EXPECT_TRUE(ActionExists()); |
| 186 | 214 |
| 187 SetAlwaysShowActionPref(true); | 215 SetAlwaysShowActionPref(true); |
| 188 controller()->OnRoutesUpdated(non_local_display_route_list(), | 216 controller()->OnRoutesUpdated(non_local_display_route_list(), |
| 189 empty_route_id_list()); | 217 empty_route_id_list()); |
| 190 // Removing the local route should not hide the icon. | 218 // Removing the local route should not hide the icon. |
| 191 EXPECT_TRUE(ActionExists()); | 219 EXPECT_TRUE(ActionExists()); |
| 192 | 220 |
| 193 SetAlwaysShowActionPref(false); | 221 SetAlwaysShowActionPref(false); |
| 194 EXPECT_FALSE(ActionExists()); | 222 EXPECT_FALSE(ActionExists()); |
| 195 } | 223 } |
| OLD | NEW |