| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_TEST_HELPER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_TEST_HELPER_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | 7 |
| 11 #include <string> | 8 #include <string> |
| 12 #include <vector> | |
| 13 | 9 |
| 14 #include "base/macros.h" | 10 #include "base/macros.h" |
| 15 #include "chrome/browser/media/router/issues_observer.h" | 11 #include "base/memory/ref_counted.h" |
| 16 #include "chrome/browser/media/router/media_router.mojom.h" | 12 #include "chrome/browser/media/router/media_router.mojom.h" |
| 17 #include "chrome/browser/media/router/media_router_mojo_impl.h" | 13 #include "chrome/browser/media/router/mock_media_router.h" |
| 18 #include "chrome/browser/media/router/media_routes_observer.h" | 14 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" |
| 19 #include "chrome/browser/media/router/media_sinks_observer.h" | 15 #include "chrome/browser/media/router/test_helper.h" |
| 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "extensions/browser/event_page_tracker.h" | 18 #include "extensions/browser/event_page_tracker.h" |
| 19 #include "extensions/common/extension.h" |
| 20 #include "mojo/public/cpp/bindings/binding.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 23 |
| 23 namespace media_router { | 24 namespace media_router { |
| 24 | 25 |
| 25 // Matcher for objects that uses Equals() member function for equality check. | 26 class MediaRouterMojoImpl; |
| 26 MATCHER_P(Equals, other, "") { | |
| 27 return arg.Equals(other); | |
| 28 } | |
| 29 | |
| 30 // Matcher for a sequence of objects that uses Equals() member function for | |
| 31 // equality check. | |
| 32 MATCHER_P(SequenceEquals, other, "") { | |
| 33 if (arg.size() != other.size()) { | |
| 34 return false; | |
| 35 } | |
| 36 for (size_t i = 0; i < arg.size(); ++i) { | |
| 37 if (!arg[i].Equals(other[i])) { | |
| 38 return false; | |
| 39 } | |
| 40 } | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 // Matcher for checking all fields in Issue objects except the ID. | |
| 45 MATCHER_P(EqualsIssue, other, "") { | |
| 46 if (arg.title() != other.title()) | |
| 47 return false; | |
| 48 | |
| 49 if (arg.message() != other.message()) | |
| 50 return false; | |
| 51 | |
| 52 if (!arg.default_action().Equals(other.default_action())) | |
| 53 return false; | |
| 54 | |
| 55 if (arg.secondary_actions().size() != other.secondary_actions().size()) | |
| 56 return false; | |
| 57 | |
| 58 for (size_t i = 0; i < arg.secondary_actions().size(); ++i) { | |
| 59 if (!arg.secondary_actions()[i].Equals(other.secondary_actions()[i])) | |
| 60 return false; | |
| 61 } | |
| 62 | |
| 63 if (arg.route_id() != other.route_id()) | |
| 64 return false; | |
| 65 | |
| 66 if (arg.severity() != other.severity()) | |
| 67 return false; | |
| 68 | |
| 69 if (arg.is_blocking() != other.is_blocking()) | |
| 70 return false; | |
| 71 | |
| 72 if (arg.help_url() != other.help_url()) | |
| 73 return false; | |
| 74 | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 MATCHER_P(IssueTitleEquals, title, "") { | |
| 79 return arg.title() == title; | |
| 80 } | |
| 81 | |
| 82 MATCHER_P(StateChageInfoEquals, other, "") { | |
| 83 return arg.state == other.state && arg.close_reason == other.close_reason && | |
| 84 arg.message == other.message; | |
| 85 } | |
| 86 | |
| 87 class MockIssuesObserver : public IssuesObserver { | |
| 88 public: | |
| 89 explicit MockIssuesObserver(MediaRouter* router); | |
| 90 ~MockIssuesObserver() override; | |
| 91 | |
| 92 MOCK_METHOD1(OnIssueUpdated, void(const Issue* issue)); | |
| 93 }; | |
| 94 | 27 |
| 95 class MockMediaRouteProvider : public interfaces::MediaRouteProvider { | 28 class MockMediaRouteProvider : public interfaces::MediaRouteProvider { |
| 96 public: | 29 public: |
| 97 MockMediaRouteProvider(); | 30 MockMediaRouteProvider(); |
| 98 ~MockMediaRouteProvider() override; | 31 ~MockMediaRouteProvider() override; |
| 99 | 32 |
| 100 MOCK_METHOD8(CreateRoute, | 33 MOCK_METHOD8(CreateRoute, |
| 101 void(const mojo::String& source_urn, | 34 void(const mojo::String& source_urn, |
| 102 const mojo::String& sink_id, | 35 const mojo::String& sink_id, |
| 103 const mojo::String& presentation_id, | 36 const mojo::String& presentation_id, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 MOCK_METHOD1(OnPresentationSessionDetached, | 82 MOCK_METHOD1(OnPresentationSessionDetached, |
| 150 void(const mojo::String& route_id)); | 83 void(const mojo::String& route_id)); |
| 151 MOCK_METHOD1(StartObservingMediaRoutes, void(const mojo::String& source)); | 84 MOCK_METHOD1(StartObservingMediaRoutes, void(const mojo::String& source)); |
| 152 MOCK_METHOD1(StopObservingMediaRoutes, void(const mojo::String& source)); | 85 MOCK_METHOD1(StopObservingMediaRoutes, void(const mojo::String& source)); |
| 153 MOCK_METHOD0(EnableMdnsDiscovery, void()); | 86 MOCK_METHOD0(EnableMdnsDiscovery, void()); |
| 154 | 87 |
| 155 private: | 88 private: |
| 156 DISALLOW_COPY_AND_ASSIGN(MockMediaRouteProvider); | 89 DISALLOW_COPY_AND_ASSIGN(MockMediaRouteProvider); |
| 157 }; | 90 }; |
| 158 | 91 |
| 159 class MockMediaSinksObserver : public MediaSinksObserver { | |
| 160 public: | |
| 161 MockMediaSinksObserver(MediaRouter* router, | |
| 162 const MediaSource& source, | |
| 163 const GURL& origin); | |
| 164 ~MockMediaSinksObserver() override; | |
| 165 | |
| 166 MOCK_METHOD1(OnSinksReceived, void(const std::vector<MediaSink>& sinks)); | |
| 167 }; | |
| 168 | |
| 169 class MockMediaRoutesObserver : public MediaRoutesObserver { | |
| 170 public: | |
| 171 explicit MockMediaRoutesObserver(MediaRouter* router, | |
| 172 const MediaSource::Id source_id = std::string()); | |
| 173 ~MockMediaRoutesObserver() override; | |
| 174 | |
| 175 MOCK_METHOD2(OnRoutesUpdated, void(const std::vector<MediaRoute>& routes, | |
| 176 const std::vector<MediaRoute::Id>& joinable_route_ids)); | |
| 177 }; | |
| 178 | |
| 179 class MockEventPageTracker : public extensions::EventPageTracker { | 92 class MockEventPageTracker : public extensions::EventPageTracker { |
| 180 public: | 93 public: |
| 181 MockEventPageTracker(); | 94 MockEventPageTracker(); |
| 182 ~MockEventPageTracker(); | 95 ~MockEventPageTracker(); |
| 183 | 96 |
| 184 MOCK_METHOD1(IsEventPageSuspended, bool(const std::string& extension_id)); | 97 MOCK_METHOD1(IsEventPageSuspended, bool(const std::string& extension_id)); |
| 185 MOCK_METHOD2(WakeEventPage, | 98 MOCK_METHOD2(WakeEventPage, |
| 186 bool(const std::string& extension_id, | 99 bool(const std::string& extension_id, |
| 187 const base::Callback<void(bool)>& callback)); | 100 const base::Callback<void(bool)>& callback)); |
| 188 }; | 101 }; |
| 189 | 102 |
| 190 class MockPresentationConnectionStateChangedCallback { | 103 // Tests the API call flow between the MediaRouterMojoImpl and the Media Router |
| 104 // Mojo service in both directions. |
| 105 class MediaRouterMojoTest : public ::testing::Test { |
| 191 public: | 106 public: |
| 192 MockPresentationConnectionStateChangedCallback(); | 107 MediaRouterMojoTest(); |
| 193 ~MockPresentationConnectionStateChangedCallback(); | 108 ~MediaRouterMojoTest() override; |
| 194 MOCK_METHOD1(Run, | 109 |
| 195 void(const content::PresentationConnectionStateChangeInfo&)); | 110 protected: |
| 111 void SetUp() override; |
| 112 |
| 113 void ProcessEventLoop(); |
| 114 |
| 115 void ConnectProviderManagerService(); |
| 116 |
| 117 const std::string& extension_id() const { return extension_->id(); } |
| 118 |
| 119 MediaRouterMojoImpl* router() const { return mock_media_router_.get(); } |
| 120 |
| 121 // Mock objects. |
| 122 MockMediaRouteProvider mock_media_route_provider_; |
| 123 testing::NiceMock<MockEventPageTracker> mock_event_page_tracker_; |
| 124 |
| 125 // Mojo proxy object for |mock_media_router_| |
| 126 media_router::interfaces::MediaRouterPtr media_router_proxy_; |
| 127 |
| 128 private: |
| 129 content::TestBrowserThreadBundle test_thread_bundle_; |
| 130 scoped_refptr<extensions::Extension> extension_; |
| 131 scoped_ptr<MediaRouterMojoImpl> mock_media_router_; |
| 132 scoped_ptr<mojo::Binding<interfaces::MediaRouteProvider>> binding_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoTest); |
| 196 }; | 135 }; |
| 197 | 136 |
| 198 } // namespace media_router | 137 } // namespace media_router |
| 199 | 138 |
| 200 #endif // CHROME_BROWSER_MEDIA_ROUTER_TEST_HELPER_H_ | 139 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ |
| OLD | NEW |