OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/ui/toolbar/media_router_action.h" |
| 6 #include "chrome/browser/ui/webui/media_router/media_router_test.h" |
| 7 #include "chrome/grit/generated_resources.h" |
| 8 #include "content/public/test/test_utils.h" |
| 9 #include "grit/theme_resources.h" |
| 10 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/image/image_unittest_util.h" |
| 13 |
| 14 class MediaRouterActionUnitTest : public MediaRouterTest { |
| 15 public: |
| 16 MediaRouterActionUnitTest() |
| 17 : fake_issue_notification_(media_router::Issue( |
| 18 "title notification", |
| 19 "message notification", |
| 20 media_router::IssueAction(media_router::IssueAction::TYPE_OK), |
| 21 std::vector<media_router::IssueAction>(), |
| 22 "route_id", |
| 23 media_router::Issue::NOTIFICATION, |
| 24 false, std::string())), |
| 25 fake_issue_warning_(media_router::Issue( |
| 26 "title warning", |
| 27 "message warning", |
| 28 media_router::IssueAction( |
| 29 media_router::IssueAction::TYPE_LEARN_MORE), |
| 30 std::vector<media_router::IssueAction>(), |
| 31 "route_id", |
| 32 media_router::Issue::WARNING, |
| 33 false, |
| 34 "www.google.com")), |
| 35 fake_issue_fatal_(media_router::Issue( |
| 36 "title fatal", |
| 37 "message fatal", |
| 38 media_router::IssueAction(media_router::IssueAction::TYPE_OK), |
| 39 std::vector<media_router::IssueAction>(), |
| 40 "route_id", |
| 41 media_router::Issue::FATAL, |
| 42 true, |
| 43 std::string())), |
| 44 fake_sink1_("fakeSink1", "Fake Sink 1"), |
| 45 fake_sink2_("fakeSink2", "Fake Sink 2"), |
| 46 fake_source1_("fakeSource1"), |
| 47 fake_source2_("fakeSource2"), |
| 48 fake_route_local_("route1", fake_source1_, fake_sink1_, "desc1", |
| 49 true, "path.html"), |
| 50 fake_route_remote_("route2", fake_source2_, fake_sink2_, "desc2", |
| 51 false, "path.html"), |
| 52 active_icon_(ui::ResourceBundle::GetSharedInstance(). |
| 53 GetImageNamed(IDR_MEDIA_ROUTER_ACTIVE_ICON)), |
| 54 error_icon_(ui::ResourceBundle::GetSharedInstance(). |
| 55 GetImageNamed(IDR_MEDIA_ROUTER_ERROR_ICON)), |
| 56 idle_icon_(ui::ResourceBundle::GetSharedInstance(). |
| 57 GetImageNamed(IDR_MEDIA_ROUTER_IDLE_ICON)), |
| 58 warning_icon_(ui::ResourceBundle::GetSharedInstance(). |
| 59 GetImageNamed(IDR_MEDIA_ROUTER_WARNING_ICON)) { |
| 60 } |
| 61 |
| 62 ~MediaRouterActionUnitTest() override {} |
| 63 |
| 64 // BrowserWithTestWindowTest: |
| 65 void SetUp() override { |
| 66 BrowserWithTestWindowTest::SetUp(); |
| 67 action_.reset(new MediaRouterAction(browser())); |
| 68 } |
| 69 |
| 70 void TearDown() override { |
| 71 action_.reset(); |
| 72 BrowserWithTestWindowTest::TearDown(); |
| 73 } |
| 74 |
| 75 MediaRouterAction* action() { return action_.get(); } |
| 76 const media_router::Issue* fake_issue_notification() { |
| 77 return &fake_issue_notification_; |
| 78 } |
| 79 const media_router::Issue* fake_issue_warning() { |
| 80 return &fake_issue_warning_; |
| 81 } |
| 82 const media_router::Issue* fake_issue_fatal() { |
| 83 return &fake_issue_fatal_; |
| 84 } |
| 85 const media_router::MediaRoute fake_route_local() { |
| 86 return fake_route_local_; |
| 87 } |
| 88 const media_router::MediaRoute fake_route_remote() { |
| 89 return fake_route_remote_; |
| 90 } |
| 91 const gfx::Image active_icon() { return active_icon_; } |
| 92 const gfx::Image error_icon() { return error_icon_; } |
| 93 const gfx::Image idle_icon() { return idle_icon_; } |
| 94 const gfx::Image warning_icon() { return warning_icon_; } |
| 95 |
| 96 private: |
| 97 scoped_ptr<MediaRouterAction> action_; |
| 98 |
| 99 // Fake Issues. |
| 100 const media_router::Issue fake_issue_notification_; |
| 101 const media_router::Issue fake_issue_warning_; |
| 102 const media_router::Issue fake_issue_fatal_; |
| 103 |
| 104 // Fake Sinks and Sources, used for the Routes. |
| 105 const media_router::MediaSink fake_sink1_; |
| 106 const media_router::MediaSink fake_sink2_; |
| 107 const media_router::MediaSource fake_source1_; |
| 108 const media_router::MediaSource fake_source2_; |
| 109 |
| 110 // Fake Routes. |
| 111 const media_router::MediaRoute fake_route_local_; |
| 112 const media_router::MediaRoute fake_route_remote_; |
| 113 |
| 114 // Cached images. |
| 115 const gfx::Image active_icon_; |
| 116 const gfx::Image error_icon_; |
| 117 const gfx::Image idle_icon_; |
| 118 const gfx::Image warning_icon_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest); |
| 121 }; |
| 122 |
| 123 // Tests the initial state of MediaRouterAction after construction. |
| 124 TEST_F(MediaRouterActionUnitTest, Initialization) { |
| 125 EXPECT_EQ("media_router_action", action()->GetId()); |
| 126 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE), |
| 127 action()->GetActionName()); |
| 128 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 129 action()->GetIcon(nullptr, gfx::Size()))); |
| 130 } |
| 131 |
| 132 // Tests the MediaRouterAction icon based on updates to issues. |
| 133 TEST_F(MediaRouterActionUnitTest, UpdateIssues) { |
| 134 // Initially, there are no issues. |
| 135 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 136 action()->GetIcon(nullptr, gfx::Size()))); |
| 137 |
| 138 // Don't update |current_icon_| since the issue is only a notification. |
| 139 action()->OnIssueUpdated(fake_issue_notification()); |
| 140 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 141 action()->GetIcon(nullptr, gfx::Size()))); |
| 142 |
| 143 // Update |current_icon_| since the issue is a warning. |
| 144 action()->OnIssueUpdated(fake_issue_warning()); |
| 145 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), |
| 146 action()->GetIcon(nullptr, gfx::Size()))); |
| 147 |
| 148 // Update |current_icon_| since the issue is fatal. |
| 149 action()->OnIssueUpdated(fake_issue_fatal()); |
| 150 EXPECT_TRUE(gfx::test::IsEqual(error_icon(), |
| 151 action()->GetIcon(nullptr, gfx::Size()))); |
| 152 |
| 153 // Clear the issue. |
| 154 action()->OnIssueUpdated(nullptr); |
| 155 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 156 action()->GetIcon(nullptr, gfx::Size()))); |
| 157 } |
| 158 |
| 159 // Tests the MediaRouterAction state based on updates to routes. |
| 160 TEST_F(MediaRouterActionUnitTest, UpdateRoutes) { |
| 161 scoped_ptr<std::vector<media_router::MediaRoute>> routes( |
| 162 new std::vector<media_router::MediaRoute>()); |
| 163 |
| 164 // Initially, there are no routes. |
| 165 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 166 action()->GetIcon(nullptr, gfx::Size()))); |
| 167 |
| 168 // Update |current_icon_| since there is a local route. |
| 169 routes->push_back(fake_route_local()); |
| 170 routes->push_back(fake_route_remote()); |
| 171 action()->OnRoutesUpdated(*routes.get()); |
| 172 EXPECT_TRUE(gfx::test::IsEqual(active_icon(), |
| 173 action()->GetIcon(nullptr, gfx::Size()))); |
| 174 |
| 175 // Update |current_icon_| since there are no more local routes. |
| 176 routes->clear(); |
| 177 routes->push_back(fake_route_remote()); |
| 178 action()->OnRoutesUpdated(*routes.get()); |
| 179 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 180 action()->GetIcon(nullptr, gfx::Size()))); |
| 181 |
| 182 // |current_icon_| stays the same if there are no local routes or no routes. |
| 183 routes->clear(); |
| 184 action()->OnRoutesUpdated(*routes.get()); |
| 185 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 186 action()->GetIcon(nullptr, gfx::Size()))); |
| 187 } |
| 188 |
| 189 // Tests the MediaRouterAction icon based on updates to both issues and routes. |
| 190 TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { |
| 191 scoped_ptr<std::vector<media_router::MediaRoute>> routes( |
| 192 new std::vector<media_router::MediaRoute>()); |
| 193 |
| 194 // Initially, there are no issues or routes. |
| 195 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 196 action()->GetIcon(nullptr, gfx::Size()))); |
| 197 |
| 198 // There is no change in |current_icon_| since notification issues do not |
| 199 // update the state. |
| 200 action()->OnIssueUpdated(fake_issue_notification()); |
| 201 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 202 action()->GetIcon(nullptr, gfx::Size()))); |
| 203 |
| 204 // Non-local routes also do not have an effect on |current_icon_|. |
| 205 routes->push_back(fake_route_remote()); |
| 206 action()->OnRoutesUpdated(*routes.get()); |
| 207 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 208 action()->GetIcon(nullptr, gfx::Size()))); |
| 209 |
| 210 // Update |current_icon_| since there is a local route. |
| 211 routes->clear(); |
| 212 routes->push_back(fake_route_local()); |
| 213 action()->OnRoutesUpdated(*routes.get()); |
| 214 EXPECT_TRUE(gfx::test::IsEqual(active_icon(), |
| 215 action()->GetIcon(nullptr, gfx::Size()))); |
| 216 |
| 217 // Update |current_icon_|, with a priority to reflect the warning issue |
| 218 // rather than the local route. |
| 219 action()->OnIssueUpdated(fake_issue_warning()); |
| 220 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), |
| 221 action()->GetIcon(nullptr, gfx::Size()))); |
| 222 |
| 223 // Swapping the local route for a non-local one makes no difference to the |
| 224 // |current_icon_|. |
| 225 routes->clear(); |
| 226 routes->push_back(fake_route_remote()); |
| 227 action()->OnRoutesUpdated(*routes.get()); |
| 228 EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), |
| 229 action()->GetIcon(nullptr, gfx::Size()))); |
| 230 |
| 231 // Update |current_icon_| since the issue has been updated to fatal. |
| 232 action()->OnIssueUpdated(fake_issue_fatal()); |
| 233 EXPECT_TRUE(gfx::test::IsEqual(error_icon(), |
| 234 action()->GetIcon(nullptr, gfx::Size()))); |
| 235 |
| 236 // Fatal issues still take precedent over local routes. |
| 237 routes->clear(); |
| 238 routes->push_back(fake_route_local()); |
| 239 action()->OnRoutesUpdated(*routes.get()); |
| 240 EXPECT_TRUE(gfx::test::IsEqual(error_icon(), |
| 241 action()->GetIcon(nullptr, gfx::Size()))); |
| 242 |
| 243 // When the fatal issue is dismissed, |current_icon_| reflects the existing |
| 244 // local route. |
| 245 action()->OnIssueUpdated(nullptr); |
| 246 EXPECT_TRUE(gfx::test::IsEqual(active_icon(), |
| 247 action()->GetIcon(nullptr, gfx::Size()))); |
| 248 |
| 249 // Update |current_icon_| when the local route is swapped out for a non-local |
| 250 // route. |
| 251 routes->clear(); |
| 252 routes->push_back(fake_route_remote()); |
| 253 action()->OnRoutesUpdated(*routes.get()); |
| 254 EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
| 255 action()->GetIcon(nullptr, gfx::Size()))); |
| 256 } |
OLD | NEW |