Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc

Issue 1693963003: Pass origin to StartObservingMediaSinks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cache off media source Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/media/router/media_source.h" 8 #include "chrome/browser/media/router/media_source.h"
9 #include "chrome/browser/media/router/media_source_helper.h" 9 #include "chrome/browser/media/router/media_source_helper.h"
10 #include "chrome/browser/media/router/mock_media_router.h" 10 #include "chrome/browser/media/router/mock_media_router.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 void RunDefaultPresentationUrlCallbackTest(bool off_the_record) { 79 void RunDefaultPresentationUrlCallbackTest(bool off_the_record) {
80 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); 80 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
81 ASSERT_TRUE(main_frame); 81 ASSERT_TRUE(main_frame);
82 int render_process_id = main_frame->GetProcess()->GetID(); 82 int render_process_id = main_frame->GetProcess()->GetID();
83 int routing_id = main_frame->GetRoutingID(); 83 int routing_id = main_frame->GetRoutingID();
84 84
85 auto callback = base::Bind( 85 auto callback = base::Bind(
86 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, 86 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted,
87 base::Unretained(this)); 87 base::Unretained(this));
88 std::string presentation_url1("http://foo.fakeUrl"); 88 std::string presentation_url1("http://foo.fakeUrl");
mark a. foltz 2016/03/03 22:58:36 Similar comment about URLs/origins in tests.
matt.boetger 2016/03/04 00:22:11 Done.
89 std::string origin_url1("http://foo.fakeUrl");
89 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, 90 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id,
90 presentation_url1, callback); 91 presentation_url1, callback);
91 92
92 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 93 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
93 PresentationRequest request = 94 PresentationRequest request =
94 delegate_impl_->GetDefaultPresentationRequest(); 95 delegate_impl_->GetDefaultPresentationRequest();
95 96
96 // Should not trigger callback since route response is error. 97 // Should not trigger callback since route response is error.
97 scoped_ptr<RouteRequestResult> result = RouteRequestResult::FromError( 98 scoped_ptr<RouteRequestResult> result = RouteRequestResult::FromError(
98 "Error", RouteRequestResult::UNKNOWN_ERROR); 99 "Error", RouteRequestResult::UNKNOWN_ERROR);
99 delegate_impl_->OnRouteResponse(request, *result); 100 delegate_impl_->OnRouteResponse(request, *result);
100 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); 101 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this));
101 102
102 // Should not trigger callback since request doesn't match. 103 // Should not trigger callback since request doesn't match.
103 std::string presentation_url2("http://bar.fakeUrl"); 104 std::string presentation_url2("http://bar.fakeUrl");
105 std::string origin_url2("http://bar.fakeUrl");
104 PresentationRequest different_request( 106 PresentationRequest different_request(
105 RenderFrameHostId(100, 200), presentation_url2, 107 RenderFrameHostId(100, 200), presentation_url2,
106 GURL("http://anotherFrameUrl.fakeUrl")); 108 GURL("http://anotherFrameUrl.fakeUrl"));
107 MediaRoute* media_route = new MediaRoute( 109 MediaRoute* media_route = new MediaRoute(
108 "differentRouteId", MediaSourceForPresentationUrl(presentation_url2), 110 "differentRouteId", MediaSourceForPresentationUrl(presentation_url2,
111 origin_url2),
109 "mediaSinkId", "", true, "", true); 112 "mediaSinkId", "", true, "", true);
110 media_route->set_off_the_record(off_the_record); 113 media_route->set_off_the_record(off_the_record);
111 result = RouteRequestResult::FromSuccess(make_scoped_ptr(media_route), 114 result = RouteRequestResult::FromSuccess(make_scoped_ptr(media_route),
112 "differentPresentationId"); 115 "differentPresentationId");
113 delegate_impl_->OnRouteResponse(different_request, *result); 116 delegate_impl_->OnRouteResponse(different_request, *result);
114 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); 117 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this));
115 118
116 // Should trigger callback since request matches. 119 // Should trigger callback since request matches.
117 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1); 120 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1);
118 MediaRoute* media_route2 = new MediaRoute( 121 MediaRoute* media_route2 = new MediaRoute(
119 "routeId", MediaSourceForPresentationUrl(presentation_url1), 122 "routeId", MediaSourceForPresentationUrl(presentation_url1,
123 origin_url1),
120 "mediaSinkId", "", true, "", true); 124 "mediaSinkId", "", true, "", true);
121 media_route2->set_off_the_record(off_the_record); 125 media_route2->set_off_the_record(off_the_record);
122 result = RouteRequestResult::FromSuccess(make_scoped_ptr(media_route2), 126 result = RouteRequestResult::FromSuccess(make_scoped_ptr(media_route2),
123 "presentationId"); 127 "presentationId");
124 delegate_impl_->OnRouteResponse(request, *result); 128 delegate_impl_->OnRouteResponse(request, *result);
125 } 129 }
126 130
127 PresentationServiceDelegateImpl* delegate_impl_; 131 PresentationServiceDelegateImpl* delegate_impl_;
128 MockMediaRouter router_; 132 MockMediaRouter router_;
129 }; 133 };
(...skipping 21 matching lines...) Expand all
151 // RenderViewHostTestHarness::TearDown(). 155 // RenderViewHostTestHarness::TearDown().
152 delete incognito_web_contents_; 156 delete incognito_web_contents_;
153 PresentationServiceDelegateImplTest::TearDown(); 157 PresentationServiceDelegateImplTest::TearDown();
154 } 158 }
155 159
156 content::WebContents* incognito_web_contents_; 160 content::WebContents* incognito_web_contents_;
157 }; 161 };
158 162
159 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) { 163 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) {
160 std::string presentation_url1("http://url1.fakeUrl"); 164 std::string presentation_url1("http://url1.fakeUrl");
165 std::string origin_url1("http://url1.fakeUrl");
161 std::string presentation_url2("http://url2.fakeUrl"); 166 std::string presentation_url2("http://url2.fakeUrl");
162 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1); 167 std::string origin_url2("http://url2.fakeUrl");
163 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2); 168 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1,
169 origin_url1);
170 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2,
171 origin_url2);
164 MockScreenAvailabilityListener listener1(presentation_url1); 172 MockScreenAvailabilityListener listener1(presentation_url1);
165 MockScreenAvailabilityListener listener2(presentation_url2); 173 MockScreenAvailabilityListener listener2(presentation_url2);
166 int render_process_id = 10; 174 int render_process_id = 10;
167 int render_frame_id1 = 1; 175 int render_frame_id1 = 1;
168 int render_frame_id2 = 2; 176 int render_frame_id2 = 2;
169 177
170 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) 178 EXPECT_CALL(router_, RegisterMediaSinksObserver(_))
171 .Times(2) 179 .Times(2)
172 .WillRepeatedly(Return(true)); 180 .WillRepeatedly(Return(true));
173 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 181 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
(...skipping 15 matching lines...) Expand all
189 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 197 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
190 render_process_id, render_frame_id1, source1.id())); 198 render_process_id, render_frame_id1, source1.id()));
191 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 199 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
192 render_process_id, render_frame_id2, source2.id())); 200 render_process_id, render_frame_id2, source2.id()));
193 } 201 }
194 202
195 TEST_F(PresentationServiceDelegateImplTest, AddMultipleListenersToFrame) { 203 TEST_F(PresentationServiceDelegateImplTest, AddMultipleListenersToFrame) {
196 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true)); 204 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true));
197 205
198 std::string presentation_url1("http://url1.com"); 206 std::string presentation_url1("http://url1.com");
207 std::string origin_url1("http://url1.com");
199 std::string presentation_url2("http://url2.com"); 208 std::string presentation_url2("http://url2.com");
200 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1); 209 std::string origin_url2("http://url2.com");
201 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2); 210 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1,
211 origin_url1);
212 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2,
213 origin_url2);
202 MockScreenAvailabilityListener listener1(presentation_url1); 214 MockScreenAvailabilityListener listener1(presentation_url1);
203 MockScreenAvailabilityListener listener2(presentation_url2); 215 MockScreenAvailabilityListener listener2(presentation_url2);
204 int render_process_id = 10; 216 int render_process_id = 10;
205 int render_frame_id = 1; 217 int render_frame_id = 1;
206 218
207 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(2); 219 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(2);
208 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 220 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
209 render_process_id, render_frame_id, &listener1)); 221 render_process_id, render_frame_id, &listener1));
210 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 222 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
211 render_process_id, render_frame_id, &listener2)); 223 render_process_id, render_frame_id, &listener2));
(...skipping 10 matching lines...) Expand all
222 delegate_impl_->RemoveScreenAvailabilityListener( 234 delegate_impl_->RemoveScreenAvailabilityListener(
223 render_process_id, render_frame_id, &listener2); 235 render_process_id, render_frame_id, &listener2);
224 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 236 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
225 render_process_id, render_frame_id, source1.id())); 237 render_process_id, render_frame_id, source1.id()));
226 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 238 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
227 render_process_id, render_frame_id, source2.id())); 239 render_process_id, render_frame_id, source2.id()));
228 } 240 }
229 241
230 TEST_F(PresentationServiceDelegateImplTest, AddSameListenerTwice) { 242 TEST_F(PresentationServiceDelegateImplTest, AddSameListenerTwice) {
231 std::string presentation_url1("http://url1.fakeUrl"); 243 std::string presentation_url1("http://url1.fakeUrl");
232 MediaSource source1(MediaSourceForPresentationUrl(presentation_url1)); 244 MediaSource source1(MediaSourceForPresentationUrl(presentation_url1,
245 presentation_url1));
233 MockScreenAvailabilityListener listener1(presentation_url1); 246 MockScreenAvailabilityListener listener1(presentation_url1);
234 int render_process_id = 1; 247 int render_process_id = 1;
235 int render_frame_id = 0; 248 int render_frame_id = 0;
236 249
237 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true)); 250 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true));
238 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 251 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
239 render_process_id, render_frame_id, &listener1)); 252 render_process_id, render_frame_id, &listener1));
240 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 253 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
241 render_process_id, render_frame_id, &listener1)); 254 render_process_id, render_frame_id, &listener1));
242 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 255 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 ASSERT_TRUE(main_frame); 376 ASSERT_TRUE(main_frame);
364 int render_process_id = main_frame->GetProcess()->GetID(); 377 int render_process_id = main_frame->GetProcess()->GetID();
365 int routing_id = main_frame->GetRoutingID(); 378 int routing_id = main_frame->GetRoutingID();
366 379
367 // Set up a PresentationConnection so we can listen to it. 380 // Set up a PresentationConnection so we can listen to it.
368 std::vector<MediaRouteResponseCallback> route_response_callbacks; 381 std::vector<MediaRouteResponseCallback> route_response_callbacks;
369 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false)) 382 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false))
370 .WillOnce(SaveArg<4>(&route_response_callbacks)); 383 .WillOnce(SaveArg<4>(&route_response_callbacks));
371 384
372 const std::string kPresentationUrl("http://url1.fakeUrl"); 385 const std::string kPresentationUrl("http://url1.fakeUrl");
386 const std::string kOriginUrl("http://url1.fakeUrl");
373 const std::string kPresentationId("pid"); 387 const std::string kPresentationId("pid");
374 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; 388 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
375 delegate_impl_->JoinSession( 389 delegate_impl_->JoinSession(
376 render_process_id, routing_id, kPresentationUrl, kPresentationId, 390 render_process_id, routing_id, kPresentationUrl, kPresentationId,
377 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 391 base::Bind(&MockCreatePresentationConnnectionCallbacks::
378 OnCreateConnectionSuccess, 392 OnCreateConnectionSuccess,
379 base::Unretained(&mock_create_connection_callbacks)), 393 base::Unretained(&mock_create_connection_callbacks)),
380 base::Bind( 394 base::Bind(
381 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 395 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
382 base::Unretained(&mock_create_connection_callbacks))); 396 base::Unretained(&mock_create_connection_callbacks)));
383 397
384 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) 398 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_))
385 .Times(1); 399 .Times(1);
386 scoped_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( 400 scoped_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess(
387 make_scoped_ptr(new MediaRoute( 401 make_scoped_ptr(new MediaRoute(
388 "routeId", MediaSourceForPresentationUrl(kPresentationUrl), 402 "routeId", MediaSourceForPresentationUrl(kPresentationUrl,
403 kOriginUrl),
389 "mediaSinkId", "description", true, "", true)), 404 "mediaSinkId", "description", true, "", true)),
390 kPresentationId); 405 kPresentationId);
391 for (const auto& route_response_callback : route_response_callbacks) 406 for (const auto& route_response_callback : route_response_callbacks)
392 route_response_callback.Run(*result); 407 route_response_callback.Run(*result);
393 408
394 MockPresentationConnectionStateChangedCallback mock_callback; 409 MockPresentationConnectionStateChangedCallback mock_callback;
395 content::PresentationConnectionStateChangedCallback callback = 410 content::PresentationConnectionStateChangedCallback callback =
396 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, 411 base::Bind(&MockPresentationConnectionStateChangedCallback::Run,
397 base::Unretained(&mock_callback)); 412 base::Unretained(&mock_callback));
398 content::PresentationSessionInfo connection(kPresentationUrl, 413 content::PresentationSessionInfo connection(kPresentationUrl,
399 kPresentationId); 414 kPresentationId);
400 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( 415 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked(
401 Equals(callback))); 416 Equals(callback)));
402 delegate_impl_->ListenForConnectionStateChange(render_process_id, routing_id, 417 delegate_impl_->ListenForConnectionStateChange(render_process_id, routing_id,
403 connection, callback); 418 connection, callback);
404 } 419 }
405 420
406 TEST_F(PresentationServiceDelegateImplTest, Reset) { 421 TEST_F(PresentationServiceDelegateImplTest, Reset) {
407 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) 422 EXPECT_CALL(router_, RegisterMediaSinksObserver(_))
408 .WillRepeatedly(Return(true)); 423 .WillRepeatedly(Return(true));
409 424
410 std::string presentation_url1("http://url1.fakeUrl"); 425 std::string presentation_url1("http://url1.fakeUrl");
411 MediaSource source = MediaSourceForPresentationUrl(presentation_url1); 426 std::string origin_url1("http://url1.fakeUrl");
427 MediaSource source = MediaSourceForPresentationUrl(presentation_url1,
428 origin_url1);
412 MockScreenAvailabilityListener listener1(presentation_url1); 429 MockScreenAvailabilityListener listener1(presentation_url1);
413 int render_process_id = 1; 430 int render_process_id = 1;
414 int render_frame_id = 0; 431 int render_frame_id = 0;
415 432
416 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 433 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
417 render_process_id, render_frame_id, &listener1)); 434 render_process_id, render_frame_id, &listener1));
418 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 435 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
419 render_process_id, render_frame_id, source.id())); 436 render_process_id, render_frame_id, source.id()));
420 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1); 437 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1);
421 delegate_impl_->Reset(render_process_id, render_frame_id); 438 delegate_impl_->Reset(render_process_id, render_frame_id);
(...skipping 25 matching lines...) Expand all
447 const int render_process_id = 10; 464 const int render_process_id = 10;
448 const int render_frame_id = 1; 465 const int render_frame_id = 1;
449 466
450 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); 467 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false));
451 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); 468 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported());
452 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 469 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
453 render_process_id, render_frame_id, &listener)); 470 render_process_id, render_frame_id, &listener));
454 } 471 }
455 472
456 } // namespace media_router 473 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698