| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 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 MediaRouterWebUITest { | 46 class MediaRouterActionControllerUnitTest : public MediaRouterWebUITest { |
| 47 public: | 47 public: |
| 48 MediaRouterActionControllerUnitTest() | 48 MediaRouterActionControllerUnitTest() |
| 49 : issue_(media_router::Issue( | 49 : issue_(media_router::IssueInfo( |
| 50 "title notification", | 50 "title notification", |
| 51 "message notification", | 51 media_router::IssueInfo::Action::DISMISS, |
| 52 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), | 52 media_router::IssueInfo::Severity::NOTIFICATION)), |
| 53 std::vector<media_router::IssueAction>(), | |
| 54 "route_id", | |
| 55 media_router::Issue::NOTIFICATION, | |
| 56 false, | |
| 57 -1)), | |
| 58 source1_("fakeSource1"), | 53 source1_("fakeSource1"), |
| 59 source2_("fakeSource2") {} | 54 source2_("fakeSource2") {} |
| 60 | 55 |
| 61 ~MediaRouterActionControllerUnitTest() override {} | 56 ~MediaRouterActionControllerUnitTest() override {} |
| 62 | 57 |
| 63 // MediaRouterWebUITest: | 58 // MediaRouterWebUITest: |
| 64 void SetUp() override { | 59 void SetUp() override { |
| 65 MediaRouterWebUITest::SetUp(); | 60 MediaRouterWebUITest::SetUp(); |
| 66 | 61 |
| 67 router_.reset(new media_router::MockMediaRouter()); | 62 router_.reset(new media_router::MockMediaRouter()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 98 ComponentToolbarActionsFactory::kMediaRouterActionId); | 93 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 99 } | 94 } |
| 100 | 95 |
| 101 void SetAlwaysShowActionPref(bool always_show) { | 96 void SetAlwaysShowActionPref(bool always_show) { |
| 102 component_migration_helper_->SetComponentActionPref( | 97 component_migration_helper_->SetComponentActionPref( |
| 103 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); | 98 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); |
| 104 } | 99 } |
| 105 | 100 |
| 106 MediaRouterActionController* controller() { return controller_.get(); } | 101 MediaRouterActionController* controller() { return controller_.get(); } |
| 107 | 102 |
| 108 const media_router::Issue* issue() { return &issue_; } | 103 const media_router::Issue& issue() { return issue_; } |
| 109 const std::vector<media_router::MediaRoute>& local_display_route_list() | 104 const std::vector<media_router::MediaRoute>& local_display_route_list() |
| 110 const { | 105 const { |
| 111 return local_display_route_list_; | 106 return local_display_route_list_; |
| 112 } | 107 } |
| 113 const std::vector<media_router::MediaRoute>& non_local_display_route_list() | 108 const std::vector<media_router::MediaRoute>& non_local_display_route_list() |
| 114 const { | 109 const { |
| 115 return non_local_display_route_list_; | 110 return non_local_display_route_list_; |
| 116 } | 111 } |
| 117 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { | 112 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { |
| 118 return empty_route_id_list_; | 113 return empty_route_id_list_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 145 empty_route_id_list()); | 140 empty_route_id_list()); |
| 146 EXPECT_TRUE(controller()->has_local_display_route_); | 141 EXPECT_TRUE(controller()->has_local_display_route_); |
| 147 EXPECT_TRUE(ActionExists()); | 142 EXPECT_TRUE(ActionExists()); |
| 148 // Removing the local route should hide the icon. | 143 // Removing the local route should hide the icon. |
| 149 controller()->OnRoutesUpdated(non_local_display_route_list(), | 144 controller()->OnRoutesUpdated(non_local_display_route_list(), |
| 150 empty_route_id_list()); | 145 empty_route_id_list()); |
| 151 EXPECT_FALSE(controller()->has_local_display_route_); | 146 EXPECT_FALSE(controller()->has_local_display_route_); |
| 152 EXPECT_FALSE(ActionExists()); | 147 EXPECT_FALSE(ActionExists()); |
| 153 | 148 |
| 154 // Creating an issue should show the action icon. | 149 // Creating an issue should show the action icon. |
| 155 controller()->OnIssueUpdated(issue()); | 150 controller()->OnIssue(issue()); |
| 156 EXPECT_TRUE(controller()->has_issue_); | 151 EXPECT_TRUE(controller()->has_issue_); |
| 157 EXPECT_TRUE(ActionExists()); | 152 EXPECT_TRUE(ActionExists()); |
| 158 // Removing the issue should hide the icon. | 153 // Removing the issue should hide the icon. |
| 159 controller()->OnIssueUpdated(nullptr); | 154 controller()->OnIssuesCleared(); |
| 160 EXPECT_FALSE(controller()->has_issue_); | 155 EXPECT_FALSE(controller()->has_issue_); |
| 161 EXPECT_FALSE(ActionExists()); | 156 EXPECT_FALSE(ActionExists()); |
| 162 | 157 |
| 163 controller()->OnIssueUpdated(issue()); | 158 controller()->OnIssue(issue()); |
| 164 controller()->OnRoutesUpdated(local_display_route_list(), | 159 controller()->OnRoutesUpdated(local_display_route_list(), |
| 165 empty_route_id_list()); | 160 empty_route_id_list()); |
| 166 controller()->OnIssueUpdated(nullptr); | 161 controller()->OnIssuesCleared(); |
| 167 // When the issue disappears, the icon should remain visible if there's | 162 // When the issue disappears, the icon should remain visible if there's |
| 168 // a local route. | 163 // a local route. |
| 169 EXPECT_TRUE(ActionExists()); | 164 EXPECT_TRUE(ActionExists()); |
| 170 controller()->OnRoutesUpdated(std::vector<media_router::MediaRoute>(), | 165 controller()->OnRoutesUpdated(std::vector<media_router::MediaRoute>(), |
| 171 empty_route_id_list()); | 166 empty_route_id_list()); |
| 172 EXPECT_FALSE(ActionExists()); | 167 EXPECT_FALSE(ActionExists()); |
| 173 } | 168 } |
| 174 | 169 |
| 175 TEST_F(MediaRouterActionControllerUnitTest, EphemeralIconForDialog) { | 170 TEST_F(MediaRouterActionControllerUnitTest, EphemeralIconForDialog) { |
| 176 EXPECT_FALSE(ActionExists()); | 171 EXPECT_FALSE(ActionExists()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 194 empty_route_id_list()); | 189 empty_route_id_list()); |
| 195 // Hiding the dialog while there are local routes shouldn't hide the icon. | 190 // Hiding the dialog while there are local routes shouldn't hide the icon. |
| 196 controller()->OnDialogHidden(); | 191 controller()->OnDialogHidden(); |
| 197 EXPECT_TRUE(ActionExists()); | 192 EXPECT_TRUE(ActionExists()); |
| 198 controller()->OnRoutesUpdated(non_local_display_route_list(), | 193 controller()->OnRoutesUpdated(non_local_display_route_list(), |
| 199 empty_route_id_list()); | 194 empty_route_id_list()); |
| 200 EXPECT_FALSE(ActionExists()); | 195 EXPECT_FALSE(ActionExists()); |
| 201 | 196 |
| 202 controller()->OnDialogShown(); | 197 controller()->OnDialogShown(); |
| 203 EXPECT_TRUE(ActionExists()); | 198 EXPECT_TRUE(ActionExists()); |
| 204 controller()->OnIssueUpdated(issue()); | 199 controller()->OnIssue(issue()); |
| 205 // Hiding the dialog while there is an issue shouldn't hide the icon. | 200 // Hiding the dialog while there is an issue shouldn't hide the icon. |
| 206 controller()->OnDialogHidden(); | 201 controller()->OnDialogHidden(); |
| 207 EXPECT_TRUE(ActionExists()); | 202 EXPECT_TRUE(ActionExists()); |
| 208 controller()->OnIssueUpdated(nullptr); | 203 controller()->OnIssuesCleared(); |
| 209 EXPECT_FALSE(ActionExists()); | 204 EXPECT_FALSE(ActionExists()); |
| 210 } | 205 } |
| 211 | 206 |
| 212 TEST_F(MediaRouterActionControllerUnitTest, ObserveAlwaysShowPrefChange) { | 207 TEST_F(MediaRouterActionControllerUnitTest, ObserveAlwaysShowPrefChange) { |
| 213 EXPECT_FALSE(ActionExists()); | 208 EXPECT_FALSE(ActionExists()); |
| 214 | 209 |
| 215 SetAlwaysShowActionPref(true); | 210 SetAlwaysShowActionPref(true); |
| 216 EXPECT_TRUE(ActionExists()); | 211 EXPECT_TRUE(ActionExists()); |
| 217 | 212 |
| 218 controller()->OnRoutesUpdated(local_display_route_list(), | 213 controller()->OnRoutesUpdated(local_display_route_list(), |
| 219 empty_route_id_list()); | 214 empty_route_id_list()); |
| 220 SetAlwaysShowActionPref(false); | 215 SetAlwaysShowActionPref(false); |
| 221 // Unchecking the option while having a local route shouldn't hide the icon. | 216 // Unchecking the option while having a local route shouldn't hide the icon. |
| 222 EXPECT_TRUE(ActionExists()); | 217 EXPECT_TRUE(ActionExists()); |
| 223 | 218 |
| 224 SetAlwaysShowActionPref(true); | 219 SetAlwaysShowActionPref(true); |
| 225 controller()->OnRoutesUpdated(non_local_display_route_list(), | 220 controller()->OnRoutesUpdated(non_local_display_route_list(), |
| 226 empty_route_id_list()); | 221 empty_route_id_list()); |
| 227 // Removing the local route should not hide the icon. | 222 // Removing the local route should not hide the icon. |
| 228 EXPECT_TRUE(ActionExists()); | 223 EXPECT_TRUE(ActionExists()); |
| 229 | 224 |
| 230 SetAlwaysShowActionPref(false); | 225 SetAlwaysShowActionPref(false); |
| 231 EXPECT_FALSE(ActionExists()); | 226 EXPECT_FALSE(ActionExists()); |
| 232 } | 227 } |
| OLD | NEW |