| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after 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. |
| 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 |