OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/media/router/offscreen_presentation_manager.h" | 9 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
10 #include "chrome/browser/media/router/test_helper.h" | 10 #include "chrome/browser/media/router/test_helper.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 using testing::_; | 15 using testing::_; |
16 | 16 |
17 namespace media_router { | 17 namespace media_router { |
18 | 18 |
19 namespace { | 19 namespace { |
20 const char kPresentationId[] = "presentationId"; | 20 const char kPresentationId[] = "presentationId"; |
21 const char kPresentationId2[] = "presentationId2"; | 21 const char kPresentationId2[] = "presentationId2"; |
22 const char kPresentationUrl[] = "http://www.example.com/presentation.html"; | 22 const char kPresentationUrl[] = "http://www.example.com/presentation.html"; |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 class MockReceiverConnectionAvailableCallback { | 25 class MockReceiverConnectionAvailableCallback { |
26 public: | 26 public: |
27 void OnReceiverConnectionAvailable( | 27 void OnReceiverConnectionAvailable( |
28 const content::PresentationSessionInfo& session_info, | 28 const content::PresentationSessionInfo& session_info, |
29 content::PresentationConnectionPtr connection_ptr) { | 29 content::PresentationConnectionPtr controller_conn, |
30 OnReceiverConnectionAvailableRaw(session_info, connection_ptr); | 30 content::PresentationConnectionRequest receiver_conn_request) { |
| 31 OnReceiverConnectionAvailableRaw(session_info, controller_conn.get()); |
31 } | 32 } |
32 | 33 |
33 MOCK_METHOD2(OnReceiverConnectionAvailableRaw, | 34 MOCK_METHOD2(OnReceiverConnectionAvailableRaw, |
34 void(const content::PresentationSessionInfo&, | 35 void(const content::PresentationSessionInfo&, |
35 content::PresentationConnectionPtr)); | 36 blink::mojom::PresentationConnection*)); |
36 }; | 37 }; |
37 | 38 |
38 class OffscreenPresentationManagerTest : public ::testing::Test { | 39 class OffscreenPresentationManagerTest : public ::testing::Test { |
39 public: | 40 public: |
40 OffscreenPresentationManagerTest() | 41 OffscreenPresentationManagerTest() |
41 : render_frame_host_id_(1, 1), presentation_url_(kPresentationUrl) {} | 42 : render_frame_host_id_(1, 1), presentation_url_(kPresentationUrl) {} |
42 | 43 |
43 OffscreenPresentationManager* manager() { return &manager_; } | 44 OffscreenPresentationManager* manager() { return &manager_; } |
44 | 45 |
45 void VerifyPresentationsSize(size_t expected) { | 46 void VerifyPresentationsSize(size_t expected) { |
46 EXPECT_EQ(expected, manager_.offscreen_presentations_.size()); | 47 EXPECT_EQ(expected, manager_.offscreen_presentations_.size()); |
47 } | 48 } |
48 | 49 |
49 void VerifyControllerSize(size_t expected, | 50 void VerifyControllerSize(size_t expected, |
50 const std::string& presentationId) { | 51 const std::string& presentationId) { |
51 EXPECT_TRUE( | 52 EXPECT_TRUE( |
52 base::ContainsKey(manager_.offscreen_presentations_, presentationId)); | 53 base::ContainsKey(manager_.offscreen_presentations_, presentationId)); |
53 EXPECT_EQ(expected, manager_.offscreen_presentations_[presentationId] | 54 EXPECT_EQ(expected, manager_.offscreen_presentations_[presentationId] |
54 ->pending_controllers_.size()); | 55 ->pending_controllers_.size()); |
55 } | 56 } |
56 | 57 |
57 void RegisterController(const std::string& presentation_id, | 58 void RegisterController(const std::string& presentation_id, |
58 content::PresentationConnectionPtr controller) { | 59 content::PresentationConnectionPtr controller) { |
| 60 content::PresentationConnectionRequest receiver_conn_request; |
59 manager()->RegisterOffscreenPresentationController( | 61 manager()->RegisterOffscreenPresentationController( |
60 presentation_id, presentation_url_, render_frame_host_id_, | 62 presentation_id, presentation_url_, render_frame_host_id_, |
61 std::move(controller)); | 63 std::move(controller), std::move(receiver_conn_request)); |
62 } | 64 } |
63 | 65 |
64 void RegisterController(const RenderFrameHostId& render_frame_id, | 66 void RegisterController(const RenderFrameHostId& render_frame_id, |
65 content::PresentationConnectionPtr controller) { | 67 content::PresentationConnectionPtr controller) { |
| 68 content::PresentationConnectionRequest receiver_conn_request; |
66 manager()->RegisterOffscreenPresentationController( | 69 manager()->RegisterOffscreenPresentationController( |
67 kPresentationId, presentation_url_, render_frame_id, | 70 kPresentationId, presentation_url_, render_frame_id, |
68 std::move(controller)); | 71 std::move(controller), std::move(receiver_conn_request)); |
69 } | 72 } |
70 | 73 |
71 void RegisterController(content::PresentationConnectionPtr controller) { | 74 void RegisterController(content::PresentationConnectionPtr controller) { |
| 75 content::PresentationConnectionRequest receiver_conn_request; |
72 manager()->RegisterOffscreenPresentationController( | 76 manager()->RegisterOffscreenPresentationController( |
73 kPresentationId, presentation_url_, render_frame_host_id_, | 77 kPresentationId, presentation_url_, render_frame_host_id_, |
74 std::move(controller)); | 78 std::move(controller), std::move(receiver_conn_request)); |
75 } | 79 } |
76 | 80 |
77 void RegisterReceiver( | 81 void RegisterReceiver( |
78 MockReceiverConnectionAvailableCallback& receiver_callback) { | 82 MockReceiverConnectionAvailableCallback& receiver_callback) { |
79 RegisterReceiver(kPresentationId, receiver_callback); | 83 RegisterReceiver(kPresentationId, receiver_callback); |
80 } | 84 } |
81 | 85 |
82 void RegisterReceiver( | 86 void RegisterReceiver( |
83 const std::string& presentation_id, | 87 const std::string& presentation_id, |
84 MockReceiverConnectionAvailableCallback& receiver_callback) { | 88 MockReceiverConnectionAvailableCallback& receiver_callback) { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 .Times(1); | 292 .Times(1); |
289 RegisterReceiver(kPresentationId2, receiver_callback2); | 293 RegisterReceiver(kPresentationId2, receiver_callback2); |
290 | 294 |
291 VerifyPresentationsSize(2); | 295 VerifyPresentationsSize(2); |
292 | 296 |
293 UnregisterReceiver(); | 297 UnregisterReceiver(); |
294 VerifyPresentationsSize(1); | 298 VerifyPresentationsSize(1); |
295 } | 299 } |
296 | 300 |
297 } // namespace media_router | 301 } // namespace media_router |
OLD | NEW |