OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/media/router/mock_media_router.h" | |
6 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | |
7 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | |
8 #include "chrome/browser/ui/webui/media_router/media_router_test.h" | |
9 #include "chrome/common/pref_names.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 | |
12 using extensions::ComponentMigrationHelper; | |
13 | |
14 class TestComponentActionDelegate | |
mark a. foltz
2016/09/13 18:23:05
Nit: This class reads like a "fake" to me, so Fake
takumif
2016/09/14 04:00:52
Done.
| |
15 : public ComponentMigrationHelper::ComponentActionDelegate { | |
16 public: | |
17 TestComponentActionDelegate() : has_media_router_action_(false) {} | |
18 ~TestComponentActionDelegate() {} | |
19 | |
20 void AddComponentAction(const std::string& action_id) override { | |
21 if (action_id == ComponentToolbarActionsFactory::kMediaRouterActionId) { | |
mark a. foltz
2016/09/13 18:23:05
using ComponentToolbarActionsFactory::kMediaRouter
takumif
2016/09/14 04:00:52
using ComponentToolbarActionsFactory::kMediaRouter
| |
22 EXPECT_FALSE(HasComponentAction( | |
23 ComponentToolbarActionsFactory::kMediaRouterActionId)); | |
24 has_media_router_action_ = true; | |
25 } | |
26 } | |
27 | |
28 void RemoveComponentAction(const std::string& action_id) override { | |
29 if (action_id == ComponentToolbarActionsFactory::kMediaRouterActionId) { | |
30 EXPECT_TRUE(HasComponentAction( | |
31 ComponentToolbarActionsFactory::kMediaRouterActionId)); | |
32 has_media_router_action_ = false; | |
33 } | |
34 } | |
35 | |
36 bool HasComponentAction(const std::string& action_id) const override { | |
37 if (action_id == ComponentToolbarActionsFactory::kMediaRouterActionId) | |
38 return has_media_router_action_; | |
39 return false; | |
40 } | |
41 | |
42 private: | |
43 bool has_media_router_action_; | |
44 }; | |
45 | |
46 class MediaRouterActionControllerUnitTest : public MediaRouterTest { | |
47 public: | |
48 MediaRouterActionControllerUnitTest() | |
49 : fake_issue_(media_router::Issue( | |
50 "title notification", | |
51 "message notification", | |
52 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), | |
53 std::vector<media_router::IssueAction>(), | |
54 "route_id", | |
55 media_router::Issue::NOTIFICATION, | |
56 false, | |
57 -1)), | |
58 fake_source1_("fakeSource1"), | |
59 fake_source2_("fakeSource2") {} | |
60 | |
61 ~MediaRouterActionControllerUnitTest() override {} | |
62 | |
63 // MediaRouterTest: | |
64 void SetUp() override { | |
65 MediaRouterTest::SetUp(); | |
66 | |
67 router_.reset(new media_router::MockMediaRouter()); | |
68 component_action_delegate_.reset(new TestComponentActionDelegate()); | |
69 component_migration_helper_.reset(new ComponentMigrationHelper( | |
70 profile(), component_action_delegate_.get())); | |
71 controller_.reset(new MediaRouterActionController( | |
72 profile(), router_.get(), component_action_delegate_.get(), | |
73 component_migration_helper_.get())); | |
74 | |
75 local_display_route_list_.push_back( | |
76 media_router::MediaRoute("routeId1", fake_source1_, "sinkId1", | |
77 "description", true, std::string(), true)); | |
78 non_local_display_route_list_.push_back( | |
79 media_router::MediaRoute("routeId2", fake_source1_, "sinkId2", | |
80 "description", false, std::string(), true)); | |
81 non_local_display_route_list_.push_back( | |
82 media_router::MediaRoute("routeId3", fake_source2_, "sinkId3", | |
83 "description", true, std::string(), false)); | |
84 } | |
85 | |
86 void TearDown() override { | |
87 controller_.reset(); | |
88 component_migration_helper_.reset(); | |
89 component_action_delegate_.reset(); | |
90 router_.reset(); | |
91 MediaRouterTest::TearDown(); | |
92 } | |
93 | |
94 bool ActionExists() { | |
95 return component_action_delegate_->HasComponentAction( | |
96 ComponentToolbarActionsFactory::kMediaRouterActionId); | |
97 } | |
98 | |
99 MediaRouterActionController* controller() { return controller_.get(); } | |
100 | |
101 const media_router::Issue* fake_issue() { return &fake_issue_; } | |
102 const std::vector<media_router::MediaRoute>& local_display_route_list() | |
103 const { | |
104 return local_display_route_list_; | |
105 } | |
106 const std::vector<media_router::MediaRoute>& non_local_display_route_list() | |
107 const { | |
108 return non_local_display_route_list_; | |
109 } | |
110 const std::vector<media_router::MediaRoute::Id>& empty_route_id_list() const { | |
111 return empty_route_id_list_; | |
112 } | |
113 | |
114 private: | |
115 std::unique_ptr<MediaRouterActionController> controller_; | |
116 std::unique_ptr<media_router::MockMediaRouter> router_; | |
117 std::unique_ptr<TestComponentActionDelegate> component_action_delegate_; | |
118 std::unique_ptr<ComponentMigrationHelper> component_migration_helper_; | |
119 | |
120 const media_router::Issue fake_issue_; | |
mark a. foltz
2016/09/13 18:23:05
Nit: It's implied that data declared in a test is
takumif
2016/09/14 04:00:52
Okay. Renaming.
| |
121 | |
122 // Fake Sources, used for the Routes. | |
123 const media_router::MediaSource fake_source1_; | |
124 const media_router::MediaSource fake_source2_; | |
125 | |
126 std::vector<media_router::MediaRoute> local_display_route_list_; | |
127 std::vector<media_router::MediaRoute> non_local_display_route_list_; | |
128 std::vector<media_router::MediaRoute::Id> empty_route_id_list_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionControllerUnitTest); | |
131 }; | |
132 | |
133 TEST_F(MediaRouterActionControllerUnitTest, EphemeralIcon) { | |
134 EXPECT_FALSE(ActionExists()); | |
135 | |
136 // Creating a local route should show the action icon. | |
137 controller()->OnRoutesUpdated(local_display_route_list(), | |
138 empty_route_id_list()); | |
139 EXPECT_TRUE(controller()->has_local_display_route_); | |
140 EXPECT_TRUE(ActionExists()); | |
141 // Removing the local route should hide the icon. | |
142 controller()->OnRoutesUpdated(non_local_display_route_list(), | |
143 empty_route_id_list()); | |
144 EXPECT_FALSE(controller()->has_local_display_route_); | |
145 EXPECT_FALSE(ActionExists()); | |
146 | |
147 // Creating an issue should show the action icon. | |
148 controller()->OnIssueUpdated(fake_issue()); | |
149 EXPECT_TRUE(controller()->has_issue_); | |
150 EXPECT_TRUE(ActionExists()); | |
151 // Removing the issue should hide the icon. | |
152 controller()->OnIssueUpdated(nullptr); | |
153 EXPECT_FALSE(controller()->has_issue_); | |
154 EXPECT_FALSE(ActionExists()); | |
155 | |
156 controller()->OnIssueUpdated(fake_issue()); | |
157 controller()->OnRoutesUpdated(local_display_route_list(), | |
158 empty_route_id_list()); | |
159 controller()->OnIssueUpdated(nullptr); | |
160 // When the issue disappears, the icon should remain visible if there's | |
161 // a local route. | |
162 EXPECT_TRUE(ActionExists()); | |
163 controller()->OnRoutesUpdated(non_local_display_route_list(), | |
164 empty_route_id_list()); | |
165 EXPECT_FALSE(ActionExists()); | |
mark a. foltz
2016/09/13 18:23:05
Also test removing route and verify that action no
takumif
2016/09/14 04:00:52
Done.
| |
166 } | |
167 | |
168 TEST_F(MediaRouterActionControllerUnitTest, ObserveAlwaysShowPrefChange) { | |
mark a. foltz
2016/09/13 18:23:05
Also test changing the pref to false while there i
takumif
2016/09/14 04:00:52
Done.
| |
169 EXPECT_FALSE(ActionExists()); | |
170 | |
171 std::unique_ptr<DictionaryPrefUpdate> pref(new DictionaryPrefUpdate( | |
172 profile()->GetPrefs(), ::prefs::kToolbarMigratedComponentActionStatus)); | |
173 (*pref.get()) | |
174 ->SetBoolean(ComponentToolbarActionsFactory::kMediaRouterActionId, true); | |
175 // Reset |pref| to flush the changes. | |
176 pref.reset(new DictionaryPrefUpdate( | |
177 profile()->GetPrefs(), ::prefs::kToolbarMigratedComponentActionStatus)); | |
178 EXPECT_TRUE(ActionExists()); | |
179 | |
180 (*pref.get()) | |
181 ->SetBoolean(ComponentToolbarActionsFactory::kMediaRouterActionId, false); | |
182 pref.reset(); | |
183 EXPECT_FALSE(ActionExists()); | |
184 } | |
OLD | NEW |