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_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ |
6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/test/mock_callback.h" |
12 #include "chrome/browser/media/router/mock_media_router.h" | 13 #include "chrome/browser/media/router/mock_media_router.h" |
13 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" | 14 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" |
14 #include "chrome/browser/media/router/test_helper.h" | 15 #include "chrome/browser/media/router/test_helper.h" |
15 #include "chrome/common/media_router/mojo/media_router.mojom.h" | 16 #include "chrome/common/media_router/mojo/media_router.mojom.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "extensions/browser/event_page_tracker.h" | 19 #include "extensions/browser/event_page_tracker.h" |
19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
20 #include "mojo/public/cpp/bindings/binding.h" | 21 #include "mojo/public/cpp/bindings/binding.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 class MockMediaRouteControllerObserver : public MediaRouteController::Observer { | 151 class MockMediaRouteControllerObserver : public MediaRouteController::Observer { |
151 public: | 152 public: |
152 MockMediaRouteControllerObserver( | 153 MockMediaRouteControllerObserver( |
153 scoped_refptr<MediaRouteController> controller); | 154 scoped_refptr<MediaRouteController> controller); |
154 ~MockMediaRouteControllerObserver() override; | 155 ~MockMediaRouteControllerObserver() override; |
155 | 156 |
156 MOCK_METHOD1(OnMediaStatusUpdated, void(const MediaStatus& status)); | 157 MOCK_METHOD1(OnMediaStatusUpdated, void(const MediaStatus& status)); |
157 MOCK_METHOD0(OnControllerInvalidated, void()); | 158 MOCK_METHOD0(OnControllerInvalidated, void()); |
158 }; | 159 }; |
159 | 160 |
| 161 // Mockable class for awaiting RegisterMediaRouteProvider callbacks. |
| 162 class RegisterMediaRouteProviderHandler { |
| 163 public: |
| 164 RegisterMediaRouteProviderHandler(); |
| 165 ~RegisterMediaRouteProviderHandler(); |
| 166 |
| 167 // A wrapper function to deal with move only parameter |config|. |
| 168 void Invoke(const std::string& instance_id, |
| 169 mojom::MediaRouteProviderConfigPtr config) { |
| 170 InvokeRaw(instance_id, config.get()); |
| 171 } |
| 172 |
| 173 MOCK_METHOD2(InvokeRaw, |
| 174 void(const std::string& instance_id, |
| 175 mojom::MediaRouteProviderConfig* config)); |
| 176 }; |
| 177 |
160 // Tests the API call flow between the MediaRouterMojoImpl and the Media Router | 178 // Tests the API call flow between the MediaRouterMojoImpl and the Media Router |
161 // Mojo service in both directions. | 179 // Mojo service in both directions. |
162 class MediaRouterMojoTest : public ::testing::Test { | 180 class MediaRouterMojoTest : public ::testing::Test { |
163 public: | 181 public: |
164 MediaRouterMojoTest(); | 182 MediaRouterMojoTest(); |
165 ~MediaRouterMojoTest() override; | 183 ~MediaRouterMojoTest() override; |
166 | 184 |
167 protected: | 185 protected: |
168 void SetUp() override; | 186 void SetUp() override; |
169 void TearDown() override; | 187 void TearDown() override; |
170 | 188 |
171 void ProcessEventLoop(); | 189 void ProcessEventLoop(); |
172 | 190 |
173 void ConnectProviderManagerService(); | 191 void ConnectProviderManagerService(); |
174 | 192 |
175 const std::string& extension_id() const { return extension_->id(); } | 193 const std::string& extension_id() const { return extension_->id(); } |
176 | 194 |
177 MediaRouterMojoImpl* router() const { return mock_media_router_.get(); } | 195 MediaRouterMojoImpl* router() const { return mock_media_router_.get(); } |
178 | 196 |
179 // Mock objects. | 197 // Mock objects. |
180 MockMediaRouteProvider mock_media_route_provider_; | 198 MockMediaRouteProvider mock_media_route_provider_; |
181 testing::NiceMock<MockEventPageTracker> mock_event_page_tracker_; | 199 testing::NiceMock<MockEventPageTracker> mock_event_page_tracker_; |
182 | 200 |
183 // Mojo proxy object for |mock_media_router_| | 201 // Mojo proxy object for |mock_media_router_| |
184 media_router::mojom::MediaRouterPtr media_router_proxy_; | 202 media_router::mojom::MediaRouterPtr media_router_proxy_; |
185 | 203 |
| 204 RegisterMediaRouteProviderHandler provide_handler_; |
| 205 |
186 private: | 206 private: |
187 content::TestBrowserThreadBundle test_thread_bundle_; | 207 content::TestBrowserThreadBundle test_thread_bundle_; |
188 scoped_refptr<extensions::Extension> extension_; | 208 scoped_refptr<extensions::Extension> extension_; |
| 209 TestingProfile profile_; |
189 std::unique_ptr<MediaRouterMojoImpl> mock_media_router_; | 210 std::unique_ptr<MediaRouterMojoImpl> mock_media_router_; |
190 std::unique_ptr<mojo::Binding<mojom::MediaRouteProvider>> binding_; | 211 std::unique_ptr<mojo::Binding<mojom::MediaRouteProvider>> binding_; |
191 | 212 |
192 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoTest); | 213 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoTest); |
193 }; | 214 }; |
194 | 215 |
195 } // namespace media_router | 216 } // namespace media_router |
196 | 217 |
197 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ | 218 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ |
OLD | NEW |