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 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/media/router/media_source.h" | 11 #include "chrome/browser/media/router/media_source.h" |
12 #include "chrome/browser/media/router/media_source_helper.h" | 12 #include "chrome/browser/media/router/media_source_helper.h" |
13 #include "chrome/browser/media/router/mock_media_router.h" | 13 #include "chrome/browser/media/router/mock_media_router.h" |
14 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | 14 #include "chrome/browser/media/router/mock_screen_availability_listener.h" |
| 15 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
| 16 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
| 17 #include "chrome/browser/media/router/receiver_presentation_service_delegate_imp
l.h" |
15 #include "chrome/browser/media/router/route_request_result.h" | 18 #include "chrome/browser/media/router/route_request_result.h" |
16 #include "chrome/browser/media/router/test_helper.h" | 19 #include "chrome/browser/media/router/test_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
20 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
21 #include "content/public/browser/presentation_screen_availability_listener.h" | 24 #include "content/public/browser/presentation_screen_availability_listener.h" |
22 #include "content/public/browser/presentation_session.h" | 25 #include "content/public/browser/presentation_session.h" |
23 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
25 #include "content/public/test/web_contents_tester.h" | 28 #include "content/public/test/web_contents_tester.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
28 | 31 |
29 using ::testing::_; | 32 using ::testing::_; |
30 using ::testing::Mock; | 33 using ::testing::Mock; |
31 using ::testing::Return; | 34 using ::testing::Return; |
32 using ::testing::SaveArg; | 35 using ::testing::SaveArg; |
33 using ::testing::StrictMock; | 36 using ::testing::StrictMock; |
34 | 37 |
35 namespace media_router { | 38 namespace media_router { |
36 | 39 |
| 40 using OffscreenPresentationConnection = |
| 41 OffscreenPresentationManager::OffscreenPresentationConnection; |
| 42 |
37 class MockDelegateObserver | 43 class MockDelegateObserver |
38 : public content::PresentationServiceDelegate::Observer { | 44 : public content::PresentationServiceDelegate::Observer { |
39 public: | 45 public: |
40 MOCK_METHOD0(OnDelegateDestroyed, void()); | 46 MOCK_METHOD0(OnDelegateDestroyed, void()); |
41 MOCK_METHOD1(OnDefaultPresentationStarted, | 47 MOCK_METHOD1(OnDefaultPresentationStarted, |
42 void(const content::PresentationSessionInfo&)); | 48 void(const content::PresentationSessionInfo&)); |
43 }; | 49 }; |
44 | 50 |
45 class MockDefaultPresentationRequestObserver | 51 class MockDefaultPresentationRequestObserver |
46 : public PresentationServiceDelegateImpl:: | 52 : public PresentationServiceDelegateImpl:: |
47 DefaultPresentationRequestObserver { | 53 DefaultPresentationRequestObserver { |
48 public: | 54 public: |
49 MOCK_METHOD1(OnDefaultPresentationChanged, void(const PresentationRequest&)); | 55 MOCK_METHOD1(OnDefaultPresentationChanged, void(const PresentationRequest&)); |
50 MOCK_METHOD0(OnDefaultPresentationRemoved, void()); | 56 MOCK_METHOD0(OnDefaultPresentationRemoved, void()); |
51 }; | 57 }; |
52 | 58 |
53 class MockCreatePresentationConnnectionCallbacks { | 59 class MockCreatePresentationConnnectionCallbacks { |
54 public: | 60 public: |
55 MOCK_METHOD1(OnCreateConnectionSuccess, | 61 MOCK_METHOD1(OnCreateConnectionSuccess, |
56 void(const content::PresentationSessionInfo& connection)); | 62 void(const content::PresentationSessionInfo& connection)); |
57 MOCK_METHOD1(OnCreateConnectionError, | 63 MOCK_METHOD1(OnCreateConnectionError, |
58 void(const content::PresentationError& error)); | 64 void(const content::PresentationError& error)); |
59 }; | 65 }; |
60 | 66 |
61 class PresentationServiceDelegateImplTest | 67 class PresentationServiceDelegateImplTest |
62 : public ChromeRenderViewHostTestHarness { | 68 : public ChromeRenderViewHostTestHarness { |
63 public: | 69 public: |
64 PresentationServiceDelegateImplTest() : delegate_impl_(nullptr) {} | 70 PresentationServiceDelegateImplTest() |
| 71 : delegate_impl_(nullptr), |
| 72 receiver_web_contents_(nullptr), |
| 73 receiver_delegate_impl_(nullptr), |
| 74 receiver_render_process_id_(0), |
| 75 receiver_routing_id_(0) {} |
65 | 76 |
66 void SetUp() override { | 77 void SetUp() override { |
67 ChromeRenderViewHostTestHarness::SetUp(); | 78 ChromeRenderViewHostTestHarness::SetUp(); |
68 content::WebContents* wc = GetWebContents(); | 79 content::WebContents* wc = GetWebContents(); |
69 ASSERT_TRUE(wc); | 80 ASSERT_TRUE(wc); |
70 PresentationServiceDelegateImpl::CreateForWebContents(wc); | 81 PresentationServiceDelegateImpl::CreateForWebContents(wc); |
71 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); | 82 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); |
72 delegate_impl_->SetMediaRouterForTest(&router_); | 83 delegate_impl_->SetMediaRouterForTest(&router_); |
73 } | 84 } |
74 | 85 |
| 86 void TearDown() override { |
| 87 delete receiver_web_contents_; |
| 88 ChromeRenderViewHostTestHarness::TearDown(); |
| 89 } |
| 90 |
75 MOCK_METHOD1(OnDefaultPresentationStarted, | 91 MOCK_METHOD1(OnDefaultPresentationStarted, |
76 void(const content::PresentationSessionInfo& session_info)); | 92 void(const content::PresentationSessionInfo& session_info)); |
| 93 MOCK_METHOD1(OnReceiverConnectionAvailable, |
| 94 void(const content::PresentationSessionInfo&)); |
77 | 95 |
78 protected: | 96 protected: |
79 virtual content::WebContents* GetWebContents() { return web_contents(); } | 97 virtual content::WebContents* GetWebContents() { return web_contents(); } |
| 98 virtual bool IsOffTheRecord() { return false; } |
80 | 99 |
81 void RunDefaultPresentationUrlCallbackTest(bool off_the_record) { | 100 void RunDefaultPresentationUrlCallbackTest() { |
82 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 101 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
83 ASSERT_TRUE(main_frame); | 102 ASSERT_TRUE(main_frame); |
84 int render_process_id = main_frame->GetProcess()->GetID(); | 103 int render_process_id = main_frame->GetProcess()->GetID(); |
85 int routing_id = main_frame->GetRoutingID(); | 104 int routing_id = main_frame->GetRoutingID(); |
86 | 105 |
87 auto callback = base::Bind( | 106 auto callback = base::Bind( |
88 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, | 107 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, |
89 base::Unretained(this)); | 108 base::Unretained(this)); |
90 std::string presentation_url1("http://foo.fakeUrl"); | 109 std::string presentation_url1("http://foo.fakeUrl"); |
91 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, | 110 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, |
(...skipping 10 matching lines...) Expand all Loading... |
102 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); | 121 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); |
103 | 122 |
104 // Should not trigger callback since request doesn't match. | 123 // Should not trigger callback since request doesn't match. |
105 std::string presentation_url2("http://bar.fakeUrl"); | 124 std::string presentation_url2("http://bar.fakeUrl"); |
106 PresentationRequest different_request( | 125 PresentationRequest different_request( |
107 RenderFrameHostId(100, 200), presentation_url2, | 126 RenderFrameHostId(100, 200), presentation_url2, |
108 GURL("http://anotherFrameUrl.fakeUrl")); | 127 GURL("http://anotherFrameUrl.fakeUrl")); |
109 MediaRoute* media_route = new MediaRoute( | 128 MediaRoute* media_route = new MediaRoute( |
110 "differentRouteId", MediaSourceForPresentationUrl(presentation_url2), | 129 "differentRouteId", MediaSourceForPresentationUrl(presentation_url2), |
111 "mediaSinkId", "", true, "", true); | 130 "mediaSinkId", "", true, "", true); |
112 media_route->set_off_the_record(off_the_record); | 131 media_route->set_off_the_record(IsOffTheRecord()); |
113 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route), | 132 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route), |
114 "differentPresentationId"); | 133 "differentPresentationId"); |
115 delegate_impl_->OnRouteResponse(different_request, *result); | 134 delegate_impl_->OnRouteResponse(different_request, *result); |
116 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); | 135 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); |
117 | 136 |
118 // Should trigger callback since request matches. | 137 // Should trigger callback since request matches. |
119 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1); | 138 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1); |
120 MediaRoute* media_route2 = new MediaRoute( | 139 MediaRoute* media_route2 = new MediaRoute( |
121 "routeId", MediaSourceForPresentationUrl(presentation_url1), | 140 "routeId", MediaSourceForPresentationUrl(presentation_url1), |
122 "mediaSinkId", "", true, "", true); | 141 "mediaSinkId", "", true, "", true); |
123 media_route2->set_off_the_record(off_the_record); | 142 media_route2->set_off_the_record(IsOffTheRecord()); |
124 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route2), | 143 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route2), |
125 "presentationId"); | 144 "presentationId"); |
126 delegate_impl_->OnRouteResponse(request, *result); | 145 delegate_impl_->OnRouteResponse(request, *result); |
127 } | 146 } |
128 | 147 |
| 148 void RunOffscreenPresentationTest() { |
| 149 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 150 ASSERT_TRUE(main_frame); |
| 151 int render_process_id = main_frame->GetProcess()->GetID(); |
| 152 int routing_id = main_frame->GetRoutingID(); |
| 153 |
| 154 const std::string kPresentationUrl("http://url1.fakeUrl"); |
| 155 const std::string kPresentationId("pid"); |
| 156 content::PresentationSessionInfo connection(kPresentationUrl, |
| 157 kPresentationId); |
| 158 content::PresentationSessionInfo receiver_connection("", kPresentationId); |
| 159 |
| 160 // |receiver_delegate_impl_| listens for new receiver presentations with |
| 161 // |kPresentationId|. |
| 162 CreateReceiverDelegate(kPresentationId); |
| 163 ASSERT_TRUE(receiver_delegate_impl_); |
| 164 |
| 165 // This should have created a presentation connection in |
| 166 // |receiver_delegate_impl_|. |
| 167 // Get current receiver connections and continue to listen for new |
| 168 // connections. |
| 169 CreateOffscreenPresentationRoute(render_process_id, routing_id, |
| 170 kPresentationUrl, kPresentationId, |
| 171 "routeId1", "sinkId1"); |
| 172 std::vector<content::PresentationSessionInfo> receiver_connections = |
| 173 receiver_delegate_impl_->GetReceiverConnections( |
| 174 receiver_render_process_id_, receiver_routing_id_, |
| 175 base::Bind(&PresentationServiceDelegateImplTest:: |
| 176 OnReceiverConnectionAvailable, |
| 177 base::Unretained(this))); |
| 178 ASSERT_EQ(1u, receiver_connections.size()); |
| 179 EXPECT_EQ(receiver_connection.presentation_url, |
| 180 receiver_connections[0].presentation_url); |
| 181 EXPECT_EQ(receiver_connection.presentation_id, |
| 182 receiver_connections[0].presentation_id); |
| 183 |
| 184 EXPECT_CALL(*this, |
| 185 OnReceiverConnectionAvailable( |
| 186 PresentationConnectionInfoEquals(receiver_connection))); |
| 187 CreateOffscreenPresentationRoute(render_process_id + 1, routing_id + 1, |
| 188 kPresentationUrl, kPresentationId, |
| 189 "routeId2", "sinkId2"); |
| 190 |
| 191 MockPresentationMessagesCallback controller_messages_callback; |
| 192 MockPresentationMessagesCallback receiver_messages_callback; |
| 193 |
| 194 // The controller of the presentation will listen for messages from both |
| 195 // |router_| and the receiver. |
| 196 EXPECT_CALL(router_, RegisterPresentationSessionMessagesObserver(_)); |
| 197 delegate_impl_->ListenForSessionMessages( |
| 198 render_process_id, routing_id, connection, |
| 199 base::Bind(&MockPresentationMessagesCallback::OnMessagesReceived, |
| 200 base::Unretained(&controller_messages_callback))); |
| 201 receiver_delegate_impl_->ListenForSessionMessages( |
| 202 receiver_render_process_id_, receiver_routing_id_, receiver_connection, |
| 203 base::Bind(&MockPresentationMessagesCallback::OnMessagesReceived, |
| 204 base::Unretained(&receiver_messages_callback))); |
| 205 |
| 206 // Send messages from controller to receiver and vice versa. |
| 207 std::string message_text("controller to receiver"); |
| 208 std::unique_ptr<content::PresentationSessionMessage> message( |
| 209 new content::PresentationSessionMessage( |
| 210 content::PresentationMessageType::TEXT)); |
| 211 message->message = message_text; |
| 212 EXPECT_CALL(controller_messages_callback, OnMessageSent(true)); |
| 213 EXPECT_CALL(receiver_messages_callback, DoOnMessagesReceived(message_text)); |
| 214 delegate_impl_->SendMessage( |
| 215 render_process_id, routing_id, connection, std::move(message), |
| 216 base::Bind(&MockPresentationMessagesCallback::OnMessageSent, |
| 217 base::Unretained(&controller_messages_callback))); |
| 218 |
| 219 message_text = "receiver to controller"; |
| 220 message.reset(new content::PresentationSessionMessage( |
| 221 content::PresentationMessageType::TEXT)); |
| 222 message->message = message_text; |
| 223 EXPECT_CALL(receiver_messages_callback, OnMessageSent(true)); |
| 224 EXPECT_CALL(controller_messages_callback, |
| 225 DoOnMessagesReceived(message_text)); |
| 226 receiver_delegate_impl_->SendMessage( |
| 227 receiver_render_process_id_, receiver_routing_id_, receiver_connection, |
| 228 std::move(message), |
| 229 base::Bind(&MockPresentationMessagesCallback::OnMessageSent, |
| 230 base::Unretained(&receiver_messages_callback))); |
| 231 |
| 232 MockPresentationConnectionStateChangedCallback |
| 233 controller_state_change_callback; |
| 234 MockPresentationConnectionStateChangedCallback |
| 235 receiver_state_change_callback; |
| 236 |
| 237 // The controller of the offscreen presentation will listen for state change |
| 238 // from both |router_| and the receiver. |
| 239 content::PresentationConnectionStateChangedCallback state_change_callback = |
| 240 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, |
| 241 base::Unretained(&controller_state_change_callback)); |
| 242 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( |
| 243 Equals(state_change_callback))); |
| 244 delegate_impl_->ListenForConnectionStateChange( |
| 245 render_process_id, routing_id, connection, state_change_callback); |
| 246 receiver_delegate_impl_->ListenForConnectionStateChange( |
| 247 receiver_render_process_id_, receiver_routing_id_, receiver_connection, |
| 248 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, |
| 249 base::Unretained(&receiver_state_change_callback))); |
| 250 |
| 251 // Calling Reset() on |receiver_delegate_impl_| will destroy the receiver |
| 252 // connection, which causes state change on the controller. |
| 253 content::PresentationConnectionStateChangeInfo info( |
| 254 content::PRESENTATION_CONNECTION_STATE_CLOSED); |
| 255 info.close_reason = content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; |
| 256 EXPECT_CALL(controller_state_change_callback, |
| 257 Run(StateChageInfoEquals(info))); |
| 258 receiver_delegate_impl_->Reset(receiver_render_process_id_, |
| 259 receiver_routing_id_); |
| 260 |
| 261 EXPECT_CALL(router_, UnregisterPresentationSessionMessagesObserver(_)); |
| 262 } |
| 263 |
| 264 void CreateReceiverDelegate(const std::string& presentation_id) { |
| 265 content::WebContents* receiver_wc = GetReceiverWebContents(); |
| 266 ReceiverPresentationServiceDelegateImpl::CreateForWebContents( |
| 267 receiver_wc, presentation_id); |
| 268 receiver_delegate_impl_ = |
| 269 ReceiverPresentationServiceDelegateImpl::FromWebContents(receiver_wc); |
| 270 |
| 271 content::RenderFrameHost* main_frame = |
| 272 GetReceiverWebContents()->GetMainFrame(); |
| 273 ASSERT_TRUE(main_frame); |
| 274 receiver_render_process_id_ = main_frame->GetProcess()->GetID(); |
| 275 receiver_routing_id_ = main_frame->GetRoutingID(); |
| 276 } |
| 277 |
| 278 content::WebContents* GetReceiverWebContents() { |
| 279 if (!receiver_web_contents_) { |
| 280 Profile* otr_profile = profile()->GetOffTheRecordProfile(); |
| 281 receiver_web_contents_ = |
| 282 content::WebContentsTester::CreateTestWebContents(otr_profile, |
| 283 nullptr); |
| 284 } |
| 285 return receiver_web_contents_; |
| 286 } |
| 287 |
| 288 void CreateOffscreenPresentationRoute(int render_process_id, |
| 289 int routing_id, |
| 290 const std::string& presentation_url, |
| 291 const std::string& presentation_id, |
| 292 const MediaRoute::Id& route_id, |
| 293 const MediaSink::Id& sink_id) { |
| 294 // Use JoinRoute to create a route with a fixed presentation ID. |
| 295 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 296 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, IsOffTheRecord())) |
| 297 .WillOnce(SaveArg<4>(&route_response_callbacks)); |
| 298 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 299 delegate_impl_->JoinSession( |
| 300 render_process_id, routing_id, presentation_url, presentation_id, |
| 301 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 302 OnCreateConnectionSuccess, |
| 303 base::Unretained(&mock_create_connection_callbacks)), |
| 304 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 305 OnCreateConnectionError, |
| 306 base::Unretained(&mock_create_connection_callbacks))); |
| 307 |
| 308 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) |
| 309 .Times(1); |
| 310 std::unique_ptr<MediaRoute> route(new MediaRoute( |
| 311 route_id, MediaSourceForPresentationUrl(presentation_url), sink_id, |
| 312 "description", true, "", true)); |
| 313 route->set_off_the_record(IsOffTheRecord()); |
| 314 route->set_is_offscreen_presentation(true); |
| 315 std::unique_ptr<RouteRequestResult> result = |
| 316 RouteRequestResult::FromSuccess(std::move(route), presentation_id); |
| 317 for (const auto& route_response_callback : route_response_callbacks) |
| 318 route_response_callback.Run(*result); |
| 319 } |
| 320 |
129 PresentationServiceDelegateImpl* delegate_impl_; | 321 PresentationServiceDelegateImpl* delegate_impl_; |
130 MockMediaRouter router_; | 322 MockMediaRouter router_; |
| 323 |
| 324 content::WebContents* receiver_web_contents_; |
| 325 ReceiverPresentationServiceDelegateImpl* receiver_delegate_impl_; |
| 326 int receiver_render_process_id_; |
| 327 int receiver_routing_id_; |
131 }; | 328 }; |
132 | 329 |
133 class PresentationServiceDelegateImplIncognitoTest | 330 class PresentationServiceDelegateImplIncognitoTest |
134 : public PresentationServiceDelegateImplTest { | 331 : public PresentationServiceDelegateImplTest { |
135 public: | 332 public: |
136 PresentationServiceDelegateImplIncognitoTest() : | 333 PresentationServiceDelegateImplIncognitoTest() : |
137 incognito_web_contents_(nullptr) {} | 334 incognito_web_contents_(nullptr) {} |
138 | 335 |
139 protected: | 336 protected: |
140 content::WebContents* GetWebContents() override { | 337 content::WebContents* GetWebContents() override { |
141 if (!incognito_web_contents_) { | 338 if (!incognito_web_contents_) { |
142 Profile* incognito_profile = profile()->GetOffTheRecordProfile(); | 339 Profile* incognito_profile = profile()->GetOffTheRecordProfile(); |
143 incognito_web_contents_ = | 340 incognito_web_contents_ = |
144 content::WebContentsTester::CreateTestWebContents(incognito_profile, | 341 content::WebContentsTester::CreateTestWebContents(incognito_profile, |
145 nullptr); | 342 nullptr); |
146 } | 343 } |
147 return incognito_web_contents_; | 344 return incognito_web_contents_; |
148 } | 345 } |
149 | 346 |
| 347 bool IsOffTheRecord() override { return true; } |
| 348 |
150 void TearDown() override { | 349 void TearDown() override { |
151 // We must delete the incognito WC first, as that triggers observers which | 350 // We must delete the incognito WC first, as that triggers observers which |
152 // require RenderViewHost, etc., that in turn are deleted by | 351 // require RenderViewHost, etc., that in turn are deleted by |
153 // RenderViewHostTestHarness::TearDown(). | 352 // RenderViewHostTestHarness::TearDown(). |
154 delete incognito_web_contents_; | 353 delete incognito_web_contents_; |
155 PresentationServiceDelegateImplTest::TearDown(); | 354 PresentationServiceDelegateImplTest::TearDown(); |
156 } | 355 } |
157 | 356 |
158 content::WebContents* incognito_web_contents_; | 357 content::WebContents* incognito_web_contents_; |
159 }; | 358 }; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 request2.render_frame_host_id()); | 498 request2.render_frame_host_id()); |
300 EXPECT_EQ(frame_url, request2.frame_url()); | 499 EXPECT_EQ(frame_url, request2.frame_url()); |
301 | 500 |
302 // Remove default presentation URL. | 501 // Remove default presentation URL. |
303 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", | 502 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", |
304 callback); | 503 callback); |
305 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); | 504 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); |
306 } | 505 } |
307 | 506 |
308 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) { | 507 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) { |
309 RunDefaultPresentationUrlCallbackTest(false); | 508 RunDefaultPresentationUrlCallbackTest(); |
310 } | 509 } |
311 | 510 |
312 TEST_F(PresentationServiceDelegateImplIncognitoTest, | 511 TEST_F(PresentationServiceDelegateImplIncognitoTest, |
313 DefaultPresentationUrlCallback) { | 512 DefaultPresentationUrlCallback) { |
314 RunDefaultPresentationUrlCallbackTest(true); | 513 RunDefaultPresentationUrlCallbackTest(); |
315 } | 514 } |
316 | 515 |
317 TEST_F(PresentationServiceDelegateImplTest, | 516 TEST_F(PresentationServiceDelegateImplTest, |
318 DefaultPresentationRequestObserver) { | 517 DefaultPresentationRequestObserver) { |
319 auto callback = base::Bind( | 518 auto callback = base::Bind( |
320 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, | 519 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, |
321 base::Unretained(this)); | 520 base::Unretained(this)); |
322 | 521 |
323 StrictMock<MockDefaultPresentationRequestObserver> observer; | 522 StrictMock<MockDefaultPresentationRequestObserver> observer; |
324 delegate_impl_->AddDefaultPresentationRequestObserver(&observer); | 523 delegate_impl_->AddDefaultPresentationRequestObserver(&observer); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 EXPECT_TRUE(request2.Equals(observed_request2)); | 558 EXPECT_TRUE(request2.Equals(observed_request2)); |
360 | 559 |
361 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); | 560 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); |
362 | 561 |
363 // Remove default presentation URL. | 562 // Remove default presentation URL. |
364 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1); | 563 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1); |
365 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", | 564 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", |
366 callback); | 565 callback); |
367 } | 566 } |
368 | 567 |
369 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) { | 568 TEST_F(PresentationServiceDelegateImplTest, ListenForConnectionStateChange) { |
370 GURL frame_url("http://www.google.com"); | 569 GURL frame_url("http://www.google.com"); |
371 content::WebContentsTester::For(GetWebContents()) | 570 content::WebContentsTester::For(GetWebContents()) |
372 ->NavigateAndCommit(frame_url); | 571 ->NavigateAndCommit(frame_url); |
373 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 572 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
374 ASSERT_TRUE(main_frame); | 573 ASSERT_TRUE(main_frame); |
375 int render_process_id = main_frame->GetProcess()->GetID(); | 574 int render_process_id = main_frame->GetProcess()->GetID(); |
376 int routing_id = main_frame->GetRoutingID(); | 575 int routing_id = main_frame->GetRoutingID(); |
377 | 576 |
378 // Set up a PresentationConnection so we can listen to it. | 577 // Set up a PresentationConnection so we can listen to it. |
379 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 578 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
(...skipping 15 matching lines...) Expand all Loading... |
395 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) | 594 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) |
396 .Times(1); | 595 .Times(1); |
397 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( | 596 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( |
398 base::WrapUnique(new MediaRoute( | 597 base::WrapUnique(new MediaRoute( |
399 "routeId", MediaSourceForPresentationUrl(kPresentationUrl), | 598 "routeId", MediaSourceForPresentationUrl(kPresentationUrl), |
400 "mediaSinkId", "description", true, "", true)), | 599 "mediaSinkId", "description", true, "", true)), |
401 kPresentationId); | 600 kPresentationId); |
402 for (const auto& route_response_callback : route_response_callbacks) | 601 for (const auto& route_response_callback : route_response_callbacks) |
403 route_response_callback.Run(*result); | 602 route_response_callback.Run(*result); |
404 | 603 |
405 MockPresentationConnectionStateChangedCallback mock_callback; | 604 MockPresentationConnectionStateChangedCallback mock_state_change_callback; |
406 content::PresentationConnectionStateChangedCallback callback = | 605 content::PresentationConnectionStateChangedCallback callback = |
407 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, | 606 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, |
408 base::Unretained(&mock_callback)); | 607 base::Unretained(&mock_state_change_callback)); |
409 content::PresentationSessionInfo connection(kPresentationUrl, | 608 content::PresentationSessionInfo connection(kPresentationUrl, |
410 kPresentationId); | 609 kPresentationId); |
411 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( | 610 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( |
412 Equals(callback))); | 611 Equals(callback))); |
413 delegate_impl_->ListenForConnectionStateChange(render_process_id, routing_id, | 612 delegate_impl_->ListenForConnectionStateChange(render_process_id, routing_id, |
414 connection, callback); | 613 connection, callback); |
415 } | 614 } |
416 | 615 |
| 616 TEST_F(PresentationServiceDelegateImplIncognitoTest, OffscreenPresentation) { |
| 617 RunOffscreenPresentationTest(); |
| 618 } |
| 619 |
| 620 TEST_F(PresentationServiceDelegateImplTest, OffscreenPresentation) { |
| 621 RunOffscreenPresentationTest(); |
| 622 } |
| 623 |
417 TEST_F(PresentationServiceDelegateImplTest, Reset) { | 624 TEST_F(PresentationServiceDelegateImplTest, Reset) { |
418 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) | 625 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) |
419 .WillRepeatedly(Return(true)); | 626 .WillRepeatedly(Return(true)); |
420 | 627 |
421 std::string presentation_url1("http://url1.fakeUrl"); | 628 std::string presentation_url1("http://url1.fakeUrl"); |
422 MediaSource source = MediaSourceForPresentationUrl(presentation_url1); | 629 MediaSource source = MediaSourceForPresentationUrl(presentation_url1); |
423 MockScreenAvailabilityListener listener1(presentation_url1); | 630 MockScreenAvailabilityListener listener1(presentation_url1); |
424 | 631 |
425 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 632 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
426 ASSERT_TRUE(main_frame); | 633 ASSERT_TRUE(main_frame); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 int render_process_id = main_frame->GetProcess()->GetID(); | 670 int render_process_id = main_frame->GetProcess()->GetID(); |
464 int render_frame_id = main_frame->GetRoutingID(); | 671 int render_frame_id = main_frame->GetRoutingID(); |
465 | 672 |
466 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 673 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
467 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); | 674 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); |
468 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 675 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
469 render_process_id, render_frame_id, &listener)); | 676 render_process_id, render_frame_id, &listener)); |
470 } | 677 } |
471 | 678 |
472 } // namespace media_router | 679 } // namespace media_router |
OLD | NEW |