Index: chrome/browser/ui/toolbar/media_router_action_unittest.cc |
diff --git a/chrome/browser/ui/toolbar/media_router_action_unittest.cc b/chrome/browser/ui/toolbar/media_router_action_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1312d6d1c497b3c28ace9464dbc9047c96fca5ad |
--- /dev/null |
+++ b/chrome/browser/ui/toolbar/media_router_action_unittest.cc |
@@ -0,0 +1,230 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/toolbar/media_router_action.h" |
+#include "chrome/browser/ui/webui/media_router/media_router_test.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "content/public/test/test_utils.h" |
+#include "grit/theme_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/image/image_unittest_util.h" |
+ |
+class MediaRouterActionUnitTest : public MediaRouterTest { |
+ public: |
+ MediaRouterActionUnitTest() |
+ : fake_issue_notification_(media_router::Issue("title notification", |
+ "message notification", |
+ media_router::IssueAction(media_router::IssueAction::TYPE_OK), |
+ std::vector<media_router::IssueAction>(), |
+ "route_id", |
+ media_router::Issue::NOTIFICATION, |
+ false, std::string())), |
+ fake_issue_warning_(media_router::Issue("title warning", |
+ "message warning", |
+ media_router::IssueAction( |
+ media_router::IssueAction::TYPE_LEARN_MORE), |
+ std::vector<media_router::IssueAction>(), |
+ "route_id", |
+ media_router::Issue::WARNING, |
+ false, |
+ "www.google.com")), |
+ fake_issue_fatal_(media_router::Issue("title fatal", |
+ "message fatal", |
+ media_router::IssueAction(media_router::IssueAction::TYPE_OK), |
+ std::vector<media_router::IssueAction>(), |
+ "route_id", |
+ media_router::Issue::FATAL, |
+ true, |
+ std::string())), |
+ fake_sink1_("fakeSink1", "Fake Sink 1"), |
+ fake_sink2_("fakeSink2", "Fake Sink 2"), |
+ fake_source1_("fakeSource1"), |
+ fake_source2_("fakeSource2"), |
+ fake_route_local_("route1", fake_source1_, fake_sink1_, "desc1", |
+ true, "path.html"), |
+ fake_route_remote_("route2", fake_source2_, fake_sink2_, "desc2", |
+ false, "path.html"), |
+ active_icon_(ui::ResourceBundle::GetSharedInstance(). |
+ GetImageNamed(IDR_MEDIA_ROUTER_ACTIVE_ICON)), |
+ error_icon_(ui::ResourceBundle::GetSharedInstance(). |
+ GetImageNamed(IDR_MEDIA_ROUTER_ERROR_ICON)), |
+ idle_icon_(ui::ResourceBundle::GetSharedInstance(). |
+ GetImageNamed(IDR_MEDIA_ROUTER_IDLE_ICON)), |
+ warning_icon_(ui::ResourceBundle::GetSharedInstance(). |
+ GetImageNamed(IDR_MEDIA_ROUTER_WARNING_ICON)) { |
+ } |
+ |
+ ~MediaRouterActionUnitTest() override {} |
+ |
+ // BrowserWithTestWindowTest: |
+ void SetUp() override { |
+ BrowserWithTestWindowTest::SetUp(); |
+ action_ = new MediaRouterAction(browser()); |
+ } |
+ |
+ MediaRouterAction* action() { return action_; } |
+ media_router::Issue fake_issue_notification() { |
+ return fake_issue_notification_; |
+ } |
+ media_router::Issue fake_issue_warning() { return fake_issue_warning_; } |
+ media_router::Issue fake_issue_fatal() { return fake_issue_fatal_; } |
+ media_router::MediaRoute fake_route_local() { return fake_route_local_; } |
+ media_router::MediaRoute fake_route_remote() { return fake_route_remote_; } |
+ gfx::Image active_icon() { return active_icon_; } |
+ gfx::Image error_icon() { return error_icon_; } |
+ gfx::Image idle_icon() { return idle_icon_; } |
+ gfx::Image warning_icon() { return warning_icon_; } |
+ |
+ private: |
+ MediaRouterAction* action_; |
+ |
+ // Fake Issues. |
+ media_router::Issue fake_issue_notification_; |
+ media_router::Issue fake_issue_warning_; |
+ media_router::Issue fake_issue_fatal_; |
+ |
+ // Fake Sinks and Sources, used for the Routes. |
+ media_router::MediaSink fake_sink1_; |
+ media_router::MediaSink fake_sink2_; |
+ media_router::MediaSource fake_source1_; |
+ media_router::MediaSource fake_source2_; |
+ |
+ // Fake Routes. |
+ media_router::MediaRoute fake_route_local_; |
+ media_router::MediaRoute fake_route_remote_; |
+ |
+ // Cached images. |
+ gfx::Image active_icon_; |
+ gfx::Image error_icon_; |
+ gfx::Image idle_icon_; |
+ gfx::Image warning_icon_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MediaRouterActionUnitTest); |
+}; |
+ |
+// Tests the initial state of MediaRouterAction after construction. |
+TEST_F(MediaRouterActionUnitTest, Initialization) { |
+ EXPECT_EQ("media_router_action", action()->GetId()); |
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MEDIA_ROUTER_TITLE), |
+ action()->GetActionName()); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+} |
+ |
+// Tests the state of the MediaRouterAction based on updates to issues. |
+TEST_F(MediaRouterActionUnitTest, UpdateIssues) { |
+ // Initially, there are no issues. |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Don't update |state_| since the issue is only a notification. |
+ action()->OnIssueUpdated(new media_router::Issue(fake_issue_notification())); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Update |state_| since the issue is a warning. |
+ action()->OnIssueUpdated(new media_router::Issue(fake_issue_warning())); |
+ EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Update |state_| since the issue is fatal. |
+ action()->OnIssueUpdated(new media_router::Issue(fake_issue_fatal())); |
+ EXPECT_TRUE(gfx::test::IsEqual(error_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Clear the issue. |
+ action()->OnIssueUpdated(nullptr); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+} |
+ |
+// Tests the state of the MediaRouterAction based on updates to routes. |
+TEST_F(MediaRouterActionUnitTest, UpdateRoutes) { |
+ // Initially, there are no routes. |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ std::vector<media_router::MediaRoute> routes = |
+ { fake_route_local(), fake_route_remote() }; |
+ |
+ // Update |state_| since there is a local route. |
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(active_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Update |state_| since there are no more local routes. |
+ routes = { fake_route_remote() }; |
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // |state_| stays the same if there are no local routes or no routes. |
+ routes = {}; |
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+} |
+ |
+// Tests the state of the MediaRouterAction based on updates to both issues |
+// and routes. |
+TEST_F(MediaRouterActionUnitTest, UpdateIssuesAndRoutes) { |
+ // Initially, there are no issues or routes. |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // There is no change in |state_| since notification issues do not update |
+ // the state. |
+ action()->OnIssueUpdated(new media_router::Issue(fake_issue_notification())); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Non-local routes also do not have an effect on |state_|. |
+ std::vector<media_router::MediaRoute> routes = { fake_route_remote() }; |
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Update |state_| since there is a local route. |
+ routes = { fake_route_local() }; |
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(active_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Update |state_|, with a priority to reflect the warning issue rather than |
+ // local route. |
+ action()->OnIssueUpdated(new media_router::Issue(fake_issue_warning())); |
+ EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Swapping the local route for a non-local one makes no difference to the |
+ // |state_|. |
+ routes = { fake_route_remote() }; |
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(warning_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Update |state_| since the issue has been updated to fatal. |
+ action()->OnIssueUpdated(new media_router::Issue(fake_issue_fatal())); |
+ EXPECT_TRUE(gfx::test::IsEqual(error_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Fatal issues still take precedent over local routes. |
+ routes = { fake_route_local() }; |
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(error_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // When the fatal issue is dismissed, |state_| reflects the existing local |
+ // route. |
+ action()->OnIssueUpdated(nullptr); |
+ EXPECT_TRUE(gfx::test::IsEqual(active_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+ |
+ // Update |state_| when the local route is swapped out for a non-local route. |
+ routes = { fake_route_remote() }; |
Kevin M
2015/08/05 20:20:28
This type of assignment isn't allowed :(
see "(Un
apacible
2015/08/05 22:13:52
Updated. Thanks!
|
+ action()->OnRoutesUpdated(routes); |
+ EXPECT_TRUE(gfx::test::IsEqual(idle_icon(), |
+ action()->GetIcon(nullptr, gfx::Size()))); |
+} |