| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 MOCK_METHOD2(OnReceiverConnectionAvailableRaw, | 34 MOCK_METHOD2(OnReceiverConnectionAvailableRaw, |
| 35 void(const content::PresentationInfo&, | 35 void(const content::PresentationInfo&, |
| 36 blink::mojom::PresentationConnection*)); | 36 blink::mojom::PresentationConnection*)); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class OffscreenPresentationManagerTest : public ::testing::Test { | 39 class OffscreenPresentationManagerTest : public ::testing::Test { |
| 40 public: | 40 public: |
| 41 OffscreenPresentationManagerTest() | 41 OffscreenPresentationManagerTest() |
| 42 : render_frame_host_id_(1, 1), | 42 : render_frame_host_id_(1, 1), |
| 43 presentation_url_(kPresentationUrl), | 43 presentation_info_(GURL(kPresentationUrl), kPresentationId), |
| 44 route_("route_1", | 44 route_("route_1", |
| 45 MediaSource("source_1"), | 45 MediaSource("source_1"), |
| 46 "sink_1", | 46 "sink_1", |
| 47 "", | 47 "", |
| 48 false, | 48 false, |
| 49 "", | 49 "", |
| 50 false) {} | 50 false) {} |
| 51 | 51 |
| 52 OffscreenPresentationManager* manager() { return &manager_; } | 52 OffscreenPresentationManager* manager() { return &manager_; } |
| 53 | 53 |
| 54 void VerifyPresentationsSize(size_t expected) { | 54 void VerifyPresentationsSize(size_t expected) { |
| 55 EXPECT_EQ(expected, manager_.offscreen_presentations_.size()); | 55 EXPECT_EQ(expected, manager_.offscreen_presentations_.size()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void VerifyControllerSize(size_t expected, | 58 void VerifyControllerSize(size_t expected, |
| 59 const std::string& presentationId) { | 59 const std::string& presentationId) { |
| 60 EXPECT_TRUE( | 60 EXPECT_TRUE( |
| 61 base::ContainsKey(manager_.offscreen_presentations_, presentationId)); | 61 base::ContainsKey(manager_.offscreen_presentations_, presentationId)); |
| 62 EXPECT_EQ(expected, manager_.offscreen_presentations_[presentationId] | 62 EXPECT_EQ(expected, manager_.offscreen_presentations_[presentationId] |
| 63 ->pending_controllers_.size()); | 63 ->pending_controllers_.size()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void RegisterController(const std::string& presentation_id, | 66 void RegisterController(const std::string& presentation_id, |
| 67 content::PresentationConnectionPtr controller) { | 67 content::PresentationConnectionPtr controller) { |
| 68 content::PresentationConnectionRequest receiver_conn_request; | 68 RegisterController( |
| 69 manager()->RegisterOffscreenPresentationController( | 69 content::PresentationInfo(GURL(kPresentationUrl), presentation_id), |
| 70 presentation_id, presentation_url_, render_frame_host_id_, | 70 render_frame_host_id_, std::move(controller)); |
| 71 std::move(controller), std::move(receiver_conn_request), route_); | |
| 72 } | 71 } |
| 73 | 72 |
| 74 void RegisterController(const RenderFrameHostId& render_frame_id, | 73 void RegisterController(const RenderFrameHostId& render_frame_id, |
| 75 content::PresentationConnectionPtr controller) { | 74 content::PresentationConnectionPtr controller) { |
| 76 content::PresentationConnectionRequest receiver_conn_request; | 75 RegisterController(presentation_info_, render_frame_id, |
| 77 manager()->RegisterOffscreenPresentationController( | 76 std::move(controller)); |
| 78 kPresentationId, presentation_url_, render_frame_id, | |
| 79 std::move(controller), std::move(receiver_conn_request), route_); | |
| 80 } | 77 } |
| 81 | 78 |
| 82 void RegisterController(content::PresentationConnectionPtr controller) { | 79 void RegisterController(content::PresentationConnectionPtr controller) { |
| 80 RegisterController(presentation_info_, render_frame_host_id_, |
| 81 std::move(controller)); |
| 82 } |
| 83 |
| 84 void RegisterController(const content::PresentationInfo& presentation_info, |
| 85 const RenderFrameHostId& render_frame_id, |
| 86 content::PresentationConnectionPtr controller) { |
| 83 content::PresentationConnectionRequest receiver_conn_request; | 87 content::PresentationConnectionRequest receiver_conn_request; |
| 84 manager()->RegisterOffscreenPresentationController( | 88 manager()->RegisterOffscreenPresentationController( |
| 85 kPresentationId, presentation_url_, render_frame_host_id_, | 89 presentation_info, render_frame_id, std::move(controller), |
| 86 std::move(controller), std::move(receiver_conn_request), route_); | 90 std::move(receiver_conn_request), route_); |
| 87 } | 91 } |
| 88 | 92 |
| 89 void RegisterReceiver( | 93 void RegisterReceiver( |
| 90 MockReceiverConnectionAvailableCallback& receiver_callback) { | 94 MockReceiverConnectionAvailableCallback& receiver_callback) { |
| 91 RegisterReceiver(kPresentationId, receiver_callback); | 95 RegisterReceiver(kPresentationId, receiver_callback); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void RegisterReceiver( | 98 void RegisterReceiver( |
| 95 const std::string& presentation_id, | 99 const std::string& presentation_id, |
| 96 MockReceiverConnectionAvailableCallback& receiver_callback) { | 100 MockReceiverConnectionAvailableCallback& receiver_callback) { |
| 97 manager()->OnOffscreenPresentationReceiverCreated( | 101 manager()->OnOffscreenPresentationReceiverCreated( |
| 98 presentation_id, presentation_url_, | 102 content::PresentationInfo(GURL(kPresentationUrl), presentation_id), |
| 99 base::Bind(&MockReceiverConnectionAvailableCallback:: | 103 base::Bind(&MockReceiverConnectionAvailableCallback:: |
| 100 OnReceiverConnectionAvailable, | 104 OnReceiverConnectionAvailable, |
| 101 base::Unretained(&receiver_callback))); | 105 base::Unretained(&receiver_callback))); |
| 102 } | 106 } |
| 103 | 107 |
| 104 void UnregisterController(const RenderFrameHostId& render_frame_id) { | 108 void UnregisterController(const RenderFrameHostId& render_frame_id) { |
| 105 manager()->UnregisterOffscreenPresentationController(kPresentationId, | 109 manager()->UnregisterOffscreenPresentationController(kPresentationId, |
| 106 render_frame_id); | 110 render_frame_id); |
| 107 } | 111 } |
| 108 | 112 |
| 109 void UnregisterController() { | 113 void UnregisterController() { |
| 110 manager()->UnregisterOffscreenPresentationController(kPresentationId, | 114 manager()->UnregisterOffscreenPresentationController(kPresentationId, |
| 111 render_frame_host_id_); | 115 render_frame_host_id_); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void UnregisterReceiver() { | 118 void UnregisterReceiver() { |
| 115 manager()->OnOffscreenPresentationReceiverTerminated(kPresentationId); | 119 manager()->OnOffscreenPresentationReceiverTerminated(kPresentationId); |
| 116 } | 120 } |
| 117 | 121 |
| 118 private: | 122 private: |
| 119 const RenderFrameHostId render_frame_host_id_; | 123 const RenderFrameHostId render_frame_host_id_; |
| 120 GURL presentation_url_; | 124 const content::PresentationInfo presentation_info_; |
| 121 OffscreenPresentationManager manager_; | 125 OffscreenPresentationManager manager_; |
| 122 MediaRoute route_; | 126 MediaRoute route_; |
| 123 }; | 127 }; |
| 124 | 128 |
| 125 TEST_F(OffscreenPresentationManagerTest, RegisterUnregisterController) { | 129 TEST_F(OffscreenPresentationManagerTest, RegisterUnregisterController) { |
| 126 content::PresentationConnectionPtr controller; | 130 content::PresentationConnectionPtr controller; |
| 127 RegisterController(std::move(controller)); | 131 RegisterController(std::move(controller)); |
| 128 VerifyPresentationsSize(1); | 132 VerifyPresentationsSize(1); |
| 129 UnregisterController(); | 133 UnregisterController(); |
| 130 VerifyPresentationsSize(0); | 134 VerifyPresentationsSize(0); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 EXPECT_FALSE(manager()->GetRoute(kPresentationId)); | 325 EXPECT_FALSE(manager()->GetRoute(kPresentationId)); |
| 322 content::PresentationConnectionPtr controller; | 326 content::PresentationConnectionPtr controller; |
| 323 RegisterController(std::move(controller)); | 327 RegisterController(std::move(controller)); |
| 324 | 328 |
| 325 auto* actual_route = manager()->GetRoute(kPresentationId); | 329 auto* actual_route = manager()->GetRoute(kPresentationId); |
| 326 EXPECT_TRUE(actual_route); | 330 EXPECT_TRUE(actual_route); |
| 327 EXPECT_TRUE(route.Equals(*actual_route)); | 331 EXPECT_TRUE(route.Equals(*actual_route)); |
| 328 } | 332 } |
| 329 | 333 |
| 330 } // namespace media_router | 334 } // namespace media_router |
| OLD | NEW |