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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 class MockMediaRouteControllerObserver : public MediaRouteController::Observer { | 168 class MockMediaRouteControllerObserver : public MediaRouteController::Observer { |
168 public: | 169 public: |
169 MockMediaRouteControllerObserver( | 170 MockMediaRouteControllerObserver( |
170 scoped_refptr<MediaRouteController> controller); | 171 scoped_refptr<MediaRouteController> controller); |
171 ~MockMediaRouteControllerObserver() override; | 172 ~MockMediaRouteControllerObserver() override; |
172 | 173 |
173 MOCK_METHOD1(OnMediaStatusUpdated, void(const MediaStatus& status)); | 174 MOCK_METHOD1(OnMediaStatusUpdated, void(const MediaStatus& status)); |
174 MOCK_METHOD0(OnControllerInvalidated, void()); | 175 MOCK_METHOD0(OnControllerInvalidated, void()); |
175 }; | 176 }; |
176 | 177 |
| 178 // Mockable class for awaiting RegisterMediaRouteProvider callbacks. |
| 179 class RegisterMediaRouteProviderHandler { |
| 180 public: |
| 181 RegisterMediaRouteProviderHandler(); |
| 182 ~RegisterMediaRouteProviderHandler(); |
| 183 |
| 184 // A wrapper function to deal with move only parameter |config|. |
| 185 void Invoke(const std::string& instance_id, |
| 186 mojom::MediaRouteProviderConfigPtr config) { |
| 187 InvokeRaw(instance_id, config.get()); |
| 188 } |
| 189 |
| 190 MOCK_METHOD2(InvokeRaw, |
| 191 void(const std::string& instance_id, |
| 192 mojom::MediaRouteProviderConfig* config)); |
| 193 }; |
| 194 |
177 // Tests the API call flow between the MediaRouterMojoImpl and the Media Router | 195 // Tests the API call flow between the MediaRouterMojoImpl and the Media Router |
178 // Mojo service in both directions. | 196 // Mojo service in both directions. |
179 class MediaRouterMojoTest : public ::testing::Test { | 197 class MediaRouterMojoTest : public ::testing::Test { |
180 public: | 198 public: |
181 MediaRouterMojoTest(); | 199 MediaRouterMojoTest(); |
182 ~MediaRouterMojoTest() override; | 200 ~MediaRouterMojoTest() override; |
183 | 201 |
184 protected: | 202 protected: |
185 void SetUp() override; | 203 void SetUp() override; |
186 void TearDown() override; | 204 void TearDown() override; |
187 | 205 |
188 void ProcessEventLoop(); | 206 void ProcessEventLoop(); |
189 | 207 |
190 void ConnectProviderManagerService(); | 208 void ConnectProviderManagerService(); |
191 | 209 |
192 const std::string& extension_id() const { return extension_->id(); } | 210 const std::string& extension_id() const { return extension_->id(); } |
193 | 211 |
194 MediaRouterMojoImpl* router() const { return mock_media_router_.get(); } | 212 MediaRouterMojoImpl* router() const { return mock_media_router_.get(); } |
195 | 213 |
196 // Mock objects. | 214 // Mock objects. |
197 MockMediaRouteProvider mock_media_route_provider_; | 215 MockMediaRouteProvider mock_media_route_provider_; |
198 testing::NiceMock<MockEventPageTracker> mock_event_page_tracker_; | 216 testing::NiceMock<MockEventPageTracker> mock_event_page_tracker_; |
199 | 217 |
200 // Mojo proxy object for |mock_media_router_| | 218 // Mojo proxy object for |mock_media_router_| |
201 media_router::mojom::MediaRouterPtr media_router_proxy_; | 219 media_router::mojom::MediaRouterPtr media_router_proxy_; |
202 | 220 |
| 221 RegisterMediaRouteProviderHandler provide_handler_; |
| 222 |
203 private: | 223 private: |
204 content::TestBrowserThreadBundle test_thread_bundle_; | 224 content::TestBrowserThreadBundle test_thread_bundle_; |
205 scoped_refptr<extensions::Extension> extension_; | 225 scoped_refptr<extensions::Extension> extension_; |
| 226 TestingProfile profile_; |
206 std::unique_ptr<MediaRouterMojoImpl> mock_media_router_; | 227 std::unique_ptr<MediaRouterMojoImpl> mock_media_router_; |
207 std::unique_ptr<mojo::Binding<mojom::MediaRouteProvider>> binding_; | 228 std::unique_ptr<mojo::Binding<mojom::MediaRouteProvider>> binding_; |
208 | 229 |
209 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoTest); | 230 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoTest); |
210 }; | 231 }; |
211 | 232 |
212 } // namespace media_router | 233 } // namespace media_router |
213 | 234 |
214 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ | 235 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_ |
OLD | NEW |