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

Side by Side Diff: content/browser/presentation/presentation_service_impl_unittest.cc

Issue 2174693004: [Presentation API] Add support to content/ for multiple URLs per PresentationRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 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 "content/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 10 matching lines...) Expand all
21 #include "content/public/browser/presentation_session.h" 21 #include "content/public/browser/presentation_session.h"
22 #include "content/public/common/presentation_constants.h" 22 #include "content/public/common/presentation_constants.h"
23 #include "content/test/test_render_frame_host.h" 23 #include "content/test/test_render_frame_host.h"
24 #include "content/test/test_render_view_host.h" 24 #include "content/test/test_render_view_host.h"
25 #include "content/test/test_web_contents.h" 25 #include "content/test/test_web_contents.h"
26 #include "mojo/public/cpp/bindings/interface_ptr.h" 26 #include "mojo/public/cpp/bindings/interface_ptr.h"
27 #include "mojo/public/cpp/bindings/string.h" 27 #include "mojo/public/cpp/bindings/string.h"
28 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
29 29
30 using ::testing::_; 30 using ::testing::_;
31 using ::testing::ByRef;
31 using ::testing::Eq; 32 using ::testing::Eq;
32 using ::testing::InvokeWithoutArgs; 33 using ::testing::InvokeWithoutArgs;
33 using ::testing::Mock; 34 using ::testing::Mock;
34 using ::testing::Return; 35 using ::testing::Return;
35 using ::testing::SaveArg; 36 using ::testing::SaveArg;
36 37
37 namespace content { 38 namespace content {
38 39
39 namespace { 40 namespace {
40 41
41 // Matches mojo structs. 42 // Matches Mojo structs.
42 MATCHER_P(Equals, expected, "") { 43 MATCHER_P(Equals, expected, "") {
43 return expected.Equals(arg); 44 return expected.Equals(arg);
44 } 45 }
45 46
46 const char *const kPresentationId = "presentationId"; 47 // Matches PresentationSessionInfo passed by reference.
47 const char *const kPresentationUrl = "http://foo.com/index.html"; 48 MATCHER_P(SessionInfoEquals, expected, "") {
49 blink::mojom::PresentationSessionInfo& expected_value = expected;
50 return expected_value.Equals(arg);
51 }
52
53 const char kPresentationId[] = "presentationId";
54 const char kPresentationUrl1[] = "http://foo.com/index.html";
55 const char kPresentationUrl2[] = "http://example.com/index.html";
48 56
49 void DoNothing(blink::mojom::PresentationSessionInfoPtr info, 57 void DoNothing(blink::mojom::PresentationSessionInfoPtr info,
50 blink::mojom::PresentationErrorPtr error) {} 58 blink::mojom::PresentationErrorPtr error) {}
51 59
60 // TODO(crbug.com/632623): Convert downstream APIs to GURL and remove
61 // conversions.
62 std::vector<GURL> ToGURLs(const std::vector<std::string>& urls) {
63 std::vector<GURL> gurls(urls.size());
64 std::transform(urls.begin(), urls.end(), gurls.begin(),
65 [](const std::string& url) { return GURL(url); });
66 return gurls;
67 }
68
52 } // namespace 69 } // namespace
53 70
54 class MockPresentationServiceDelegate : public PresentationServiceDelegate { 71 class MockPresentationServiceDelegate : public PresentationServiceDelegate {
55 public: 72 public:
56 MOCK_METHOD3(AddObserver, 73 MOCK_METHOD3(AddObserver,
57 void(int render_process_id, 74 void(int render_process_id,
58 int render_frame_id, 75 int render_frame_id,
59 PresentationServiceDelegate::Observer* observer)); 76 PresentationServiceDelegate::Observer* observer));
60 MOCK_METHOD2(RemoveObserver, 77 MOCK_METHOD2(RemoveObserver,
61 void(int render_process_id, int render_frame_id)); 78 void(int render_process_id, int render_frame_id));
62 79
63 bool AddScreenAvailabilityListener( 80 bool AddScreenAvailabilityListener(
64 int render_process_id, 81 int render_process_id,
65 int routing_id, 82 int routing_id,
66 PresentationScreenAvailabilityListener* listener) override { 83 PresentationScreenAvailabilityListener* listener) override {
67 if (!screen_availability_listening_supported_) 84 if (!screen_availability_listening_supported_)
68 listener->OnScreenAvailabilityNotSupported(); 85 listener->OnScreenAvailabilityNotSupported();
69 86
70 return AddScreenAvailabilityListener(); 87 return AddScreenAvailabilityListener();
71 } 88 }
72 MOCK_METHOD0(AddScreenAvailabilityListener, bool()); 89 MOCK_METHOD0(AddScreenAvailabilityListener, bool());
73 90
74 MOCK_METHOD3(RemoveScreenAvailabilityListener, 91 MOCK_METHOD3(RemoveScreenAvailabilityListener,
75 void( 92 void(int render_process_id,
76 int render_process_id, 93 int routing_id,
77 int routing_id, 94 PresentationScreenAvailabilityListener* listener));
78 PresentationScreenAvailabilityListener* listener));
79 MOCK_METHOD2(Reset, 95 MOCK_METHOD2(Reset,
80 void( 96 void(int render_process_id,
81 int render_process_id, 97 int routing_id));
82 int routing_id)); 98 MOCK_METHOD4(SetDefaultPresentationUrls,
83 MOCK_METHOD4(SetDefaultPresentationUrl,
84 void(int render_process_id, 99 void(int render_process_id,
85 int routing_id, 100 int routing_id,
86 const std::string& default_presentation_url, 101 const std::vector<std::string>& default_presentation_urls,
87 const PresentationSessionStartedCallback& callback)); 102 const PresentationSessionStartedCallback& callback));
88 MOCK_METHOD5(StartSession, 103 MOCK_METHOD5(StartSession,
89 void(int render_process_id, 104 void(int render_process_id,
90 int render_frame_id, 105 int render_frame_id,
91 const std::string& presentation_url, 106 const std::vector<std::string>& presentation_urls,
92 const PresentationSessionStartedCallback& success_cb, 107 const PresentationSessionStartedCallback& success_cb,
93 const PresentationSessionErrorCallback& error_cb)); 108 const PresentationSessionErrorCallback& error_cb));
94 MOCK_METHOD6(JoinSession, 109 MOCK_METHOD6(JoinSession,
95 void(int render_process_id, 110 void(int render_process_id,
96 int render_frame_id, 111 int render_frame_id,
97 const std::string& presentation_url, 112 const std::vector<std::string>& presentation_urls,
98 const std::string& presentation_id, 113 const std::string& presentation_id,
99 const PresentationSessionStartedCallback& success_cb, 114 const PresentationSessionStartedCallback& success_cb,
100 const PresentationSessionErrorCallback& error_cb)); 115 const PresentationSessionErrorCallback& error_cb));
101 MOCK_METHOD3(CloseConnection, 116 MOCK_METHOD3(CloseConnection,
102 void(int render_process_id, 117 void(int render_process_id,
103 int render_frame_id, 118 int render_frame_id,
104 const std::string& presentation_id)); 119 const std::string& presentation_id));
105 MOCK_METHOD3(Terminate, 120 MOCK_METHOD3(Terminate,
106 void(int render_process_id, 121 void(int render_process_id,
107 int render_frame_id, 122 int render_frame_id,
(...skipping 29 matching lines...) Expand all
137 } 152 }
138 153
139 private: 154 private:
140 bool screen_availability_listening_supported_ = true; 155 bool screen_availability_listening_supported_ = true;
141 }; 156 };
142 157
143 class MockPresentationServiceClient 158 class MockPresentationServiceClient
144 : public blink::mojom::PresentationServiceClient { 159 : public blink::mojom::PresentationServiceClient {
145 public: 160 public:
146 MOCK_METHOD2(OnScreenAvailabilityUpdated, 161 MOCK_METHOD2(OnScreenAvailabilityUpdated,
147 void(const std::string& url, bool available)); 162 void(const GURL& url, bool available));
148 void OnConnectionStateChanged( 163 void OnConnectionStateChanged(
149 blink::mojom::PresentationSessionInfoPtr connection, 164 blink::mojom::PresentationSessionInfoPtr connection,
150 blink::mojom::PresentationConnectionState new_state) override { 165 blink::mojom::PresentationConnectionState new_state) override {
151 OnConnectionStateChanged(*connection, new_state); 166 OnConnectionStateChanged(*connection, new_state);
152 } 167 }
153 MOCK_METHOD2(OnConnectionStateChanged, 168 MOCK_METHOD2(OnConnectionStateChanged,
154 void(const blink::mojom::PresentationSessionInfo& connection, 169 void(const blink::mojom::PresentationSessionInfo& connection,
155 blink::mojom::PresentationConnectionState new_state)); 170 blink::mojom::PresentationConnectionState new_state));
156 171
157 void OnConnectionClosed( 172 void OnConnectionClosed(
158 blink::mojom::PresentationSessionInfoPtr connection, 173 blink::mojom::PresentationSessionInfoPtr connection,
159 blink::mojom::PresentationConnectionCloseReason reason, 174 blink::mojom::PresentationConnectionCloseReason reason,
160 const std::string& message) override { 175 const std::string& message) override {
161 OnConnectionClosed(*connection, reason, message); 176 OnConnectionClosed(*connection, reason, message);
162 } 177 }
163 MOCK_METHOD3(OnConnectionClosed, 178 MOCK_METHOD3(OnConnectionClosed,
164 void(const blink::mojom::PresentationSessionInfo& connection, 179 void(const blink::mojom::PresentationSessionInfo& connection,
165 blink::mojom::PresentationConnectionCloseReason reason, 180 blink::mojom::PresentationConnectionCloseReason reason,
166 const std::string& message)); 181 const std::string& message));
167 182
168 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const std::string& url)); 183 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url));
169 184
170 void OnSessionMessagesReceived( 185 void OnSessionMessagesReceived(
171 blink::mojom::PresentationSessionInfoPtr session_info, 186 blink::mojom::PresentationSessionInfoPtr session_info,
172 std::vector<blink::mojom::SessionMessagePtr> messages) override { 187 std::vector<blink::mojom::SessionMessagePtr> messages) override {
173 messages_received_ = std::move(messages); 188 messages_received_ = std::move(messages);
174 MessagesReceived(); 189 MessagesReceived();
175 } 190 }
176 MOCK_METHOD0(MessagesReceived, void()); 191 MOCK_METHOD0(MessagesReceived, void());
177 192
178 void OnDefaultSessionStarted( 193 void OnDefaultSessionStarted(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 bool delegate_success) { 235 bool delegate_success) {
221 base::RunLoop run_loop; 236 base::RunLoop run_loop;
222 // This will call to |service_impl_| via mojo. Process the message 237 // This will call to |service_impl_| via mojo. Process the message
223 // using RunLoop. 238 // using RunLoop.
224 // The callback shouldn't be invoked since there is no availability 239 // The callback shouldn't be invoked since there is no availability
225 // result yet. 240 // result yet.
226 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener()) 241 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener())
227 .WillOnce(DoAll( 242 .WillOnce(DoAll(
228 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 243 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
229 Return(delegate_success))); 244 Return(delegate_success)));
230 service_ptr_->ListenForScreenAvailability(url); 245 service_ptr_->ListenForScreenAvailability(GURL(url));
231 run_loop.Run(); 246 run_loop.Run();
232 247
233 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 248 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
234 } 249 }
235 250
236 void RunLoopFor(base::TimeDelta duration) { 251 void RunLoopFor(base::TimeDelta duration) {
237 base::RunLoop run_loop; 252 base::RunLoop run_loop;
238 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 253 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
239 FROM_HERE, run_loop.QuitClosure(), duration); 254 FROM_HERE, run_loop.QuitClosure(), duration);
240 run_loop.Run(); 255 run_loop.Run();
241 } 256 }
242 257
243 void SaveQuitClosureAndRunLoop() { 258 void SaveQuitClosureAndRunLoop() {
244 base::RunLoop run_loop; 259 base::RunLoop run_loop;
245 run_loop_quit_closure_ = run_loop.QuitClosure(); 260 run_loop_quit_closure_ = run_loop.QuitClosure();
246 run_loop.Run(); 261 run_loop.Run();
247 run_loop_quit_closure_.Reset(); 262 run_loop_quit_closure_.Reset();
248 } 263 }
249 264
250 void SimulateScreenAvailabilityChangeAndWait( 265 void SimulateScreenAvailabilityChangeAndWait(
251 const std::string& url, bool available) { 266 const std::string& url, bool available) {
252 auto listener_it = service_impl_->screen_availability_listeners_.find(url); 267 auto listener_it = service_impl_->screen_availability_listeners_.find(url);
253 ASSERT_TRUE(listener_it->second); 268 ASSERT_TRUE(listener_it->second);
254 269
255 base::RunLoop run_loop; 270 base::RunLoop run_loop;
256 EXPECT_CALL(mock_client_, OnScreenAvailabilityUpdated(url, available)) 271 EXPECT_CALL(mock_client_, OnScreenAvailabilityUpdated(GURL(url), available))
257 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 272 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
258 listener_it->second->OnScreenAvailabilityChanged(available); 273 listener_it->second->OnScreenAvailabilityChanged(available);
259 run_loop.Run(); 274 run_loop.Run();
260 } 275 }
261 276
262 void ExpectReset() { 277 void ExpectReset() {
263 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); 278 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1);
264 } 279 }
265 280
266 void ExpectCleanState() { 281 void ExpectCleanState() {
267 EXPECT_TRUE(service_impl_->default_presentation_url_.empty()); 282 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty());
268 EXPECT_EQ( 283 EXPECT_EQ(
269 service_impl_->screen_availability_listeners_.find(kPresentationUrl), 284 service_impl_->screen_availability_listeners_.find(kPresentationUrl1),
270 service_impl_->screen_availability_listeners_.end()); 285 service_impl_->screen_availability_listeners_.end());
271 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); 286 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get());
272 } 287 }
273 288
274 void ExpectNewSessionCallbackSuccess( 289 void ExpectNewSessionCallbackSuccess(
275 blink::mojom::PresentationSessionInfoPtr info, 290 blink::mojom::PresentationSessionInfoPtr info,
276 blink::mojom::PresentationErrorPtr error) { 291 blink::mojom::PresentationErrorPtr error) {
277 EXPECT_FALSE(info.is_null()); 292 EXPECT_FALSE(info.is_null());
278 EXPECT_TRUE(error.is_null()); 293 EXPECT_TRUE(error.is_null());
279 if (!run_loop_quit_closure_.is_null()) 294 if (!run_loop_quit_closure_.is_null())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 expected_msgs[0] = blink::mojom::SessionMessage::New(); 326 expected_msgs[0] = blink::mojom::SessionMessage::New();
312 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT; 327 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT;
313 expected_msgs[0]->message = text_msg; 328 expected_msgs[0]->message = text_msg;
314 expected_msgs[1] = blink::mojom::SessionMessage::New(); 329 expected_msgs[1] = blink::mojom::SessionMessage::New();
315 expected_msgs[1]->type = 330 expected_msgs[1]->type =
316 blink::mojom::PresentationMessageType::ARRAY_BUFFER; 331 blink::mojom::PresentationMessageType::ARRAY_BUFFER;
317 expected_msgs[1]->data = binary_data; 332 expected_msgs[1]->data = binary_data;
318 333
319 blink::mojom::PresentationSessionInfoPtr session( 334 blink::mojom::PresentationSessionInfoPtr session(
320 blink::mojom::PresentationSessionInfo::New()); 335 blink::mojom::PresentationSessionInfo::New());
321 session->url = kPresentationUrl; 336 session->url = GURL(kPresentationUrl1);
322 session->id = kPresentationId; 337 session->id = kPresentationId;
323 338
324 PresentationSessionMessageCallback message_cb; 339 PresentationSessionMessageCallback message_cb;
325 { 340 {
326 base::RunLoop run_loop; 341 base::RunLoop run_loop;
327 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)) 342 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _))
328 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 343 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
329 SaveArg<3>(&message_cb))); 344 SaveArg<3>(&message_cb)));
330 service_ptr_->ListenForSessionMessages(session.Clone()); 345 service_ptr_->ListenForSessionMessages(std::move(session));
331 run_loop.Run(); 346 run_loop.Run();
332 } 347 }
333 348
334 ScopedVector<PresentationSessionMessage> messages; 349 ScopedVector<PresentationSessionMessage> messages;
335 std::unique_ptr<content::PresentationSessionMessage> message; 350 std::unique_ptr<content::PresentationSessionMessage> message;
336 message.reset( 351 message.reset(
337 new content::PresentationSessionMessage(PresentationMessageType::TEXT)); 352 new content::PresentationSessionMessage(PresentationMessageType::TEXT));
338 message->message = text_msg; 353 message->message = text_msg;
339 messages.push_back(std::move(message)); 354 messages.push_back(std::move(message));
340 message.reset(new content::PresentationSessionMessage( 355 message.reset(new content::PresentationSessionMessage(
(...skipping 18 matching lines...) Expand all
359 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; 374 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_;
360 375
361 MockPresentationServiceClient mock_client_; 376 MockPresentationServiceClient mock_client_;
362 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> 377 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>>
363 client_binding_; 378 client_binding_;
364 379
365 base::Closure run_loop_quit_closure_; 380 base::Closure run_loop_quit_closure_;
366 }; 381 };
367 382
368 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { 383 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) {
369 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); 384 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true);
370 385
371 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); 386 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true);
372 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, false); 387 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, false);
373 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); 388 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true);
374 } 389 }
375 390
376 TEST_F(PresentationServiceImplTest, Reset) { 391 TEST_F(PresentationServiceImplTest, Reset) {
377 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); 392 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true);
378 393
379 ExpectReset(); 394 ExpectReset();
380 service_impl_->Reset(); 395 service_impl_->Reset();
381 ExpectCleanState(); 396 ExpectCleanState();
382 } 397 }
383 398
384 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) { 399 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) {
385 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); 400 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true);
386 401
387 ExpectReset(); 402 ExpectReset();
388 service_impl_->DidNavigateAnyFrame( 403 service_impl_->DidNavigateAnyFrame(
389 contents()->GetMainFrame(), 404 contents()->GetMainFrame(),
390 content::LoadCommittedDetails(), 405 content::LoadCommittedDetails(),
391 content::FrameNavigateParams()); 406 content::FrameNavigateParams());
392 ExpectCleanState(); 407 ExpectCleanState();
393 } 408 }
394 409
395 TEST_F(PresentationServiceImplTest, DidNavigateOtherFrame) { 410 TEST_F(PresentationServiceImplTest, DidNavigateOtherFrame) {
396 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); 411 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true);
397 412
398 // TODO(imcheng): How to get a different RenderFrameHost? 413 // TODO(imcheng): How to get a different RenderFrameHost?
399 service_impl_->DidNavigateAnyFrame( 414 service_impl_->DidNavigateAnyFrame(
400 nullptr, 415 nullptr,
401 content::LoadCommittedDetails(), 416 content::LoadCommittedDetails(),
402 content::FrameNavigateParams()); 417 content::FrameNavigateParams());
403 418
404 // Availability is reported and callback is invoked since it was not 419 // Availability is reported and callback is invoked since it was not
405 // removed. 420 // removed.
406 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); 421 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true);
407 } 422 }
408 423
409 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) { 424 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) {
410 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); 425 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true);
411 426
412 ExpectReset(); 427 ExpectReset();
413 428
414 // Since the frame matched the service, |service_impl_| will be deleted. 429 // Since the frame matched the service, |service_impl_| will be deleted.
415 PresentationServiceImpl* service = service_impl_.release(); 430 PresentationServiceImpl* service = service_impl_.release();
416 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); 431 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1);
417 service->RenderFrameDeleted(contents()->GetMainFrame()); 432 service->RenderFrameDeleted(contents()->GetMainFrame());
418 } 433 }
419 434
420 TEST_F(PresentationServiceImplTest, OtherRenderFrameDeleted) { 435 TEST_F(PresentationServiceImplTest, OtherRenderFrameDeleted) {
421 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); 436 ListenForScreenAvailabilityAndWait(kPresentationUrl1, true);
422 437
423 // TODO(imcheng): How to get a different RenderFrameHost? 438 // TODO(imcheng): How to get a different RenderFrameHost?
424 service_impl_->RenderFrameDeleted(nullptr); 439 service_impl_->RenderFrameDeleted(nullptr);
425 440
426 // Availability is reported and callback should be invoked since listener 441 // Availability is reported and callback should be invoked since listener
427 // has not been deleted. 442 // has not been deleted.
428 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); 443 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl1, true);
429 } 444 }
430 445
431 TEST_F(PresentationServiceImplTest, DelegateFails) { 446 TEST_F(PresentationServiceImplTest, DelegateFails) {
432 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); 447 ListenForScreenAvailabilityAndWait(kPresentationUrl1, false);
433 ASSERT_EQ( 448 ASSERT_EQ(
434 service_impl_->screen_availability_listeners_.find(kPresentationUrl), 449 service_impl_->screen_availability_listeners_.find(kPresentationUrl1),
435 service_impl_->screen_availability_listeners_.end()); 450 service_impl_->screen_availability_listeners_.end());
436 } 451 }
437 452
438 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) { 453 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrls) {
439 std::string url1("http://fooUrl"); 454 std::vector<std::string> urls({kPresentationUrl1, kPresentationUrl2});
440 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url1), _)) 455 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, urls, _))
441 .Times(1); 456 .Times(1);
442 service_impl_->SetDefaultPresentationURL(url1);
443 EXPECT_EQ(url1, service_impl_->default_presentation_url_);
444 457
445 std::string url2("http://barUrl"); 458 service_impl_->SetDefaultPresentationUrls(ToGURLs(urls));
446 // Sets different DPU. 459
460 // Sets different DPUs.
461 std::vector<std::string> more_urls(
462 {kPresentationUrl1, kPresentationUrl2, "http://barurl.com/"});
463
447 content::PresentationSessionStartedCallback callback; 464 content::PresentationSessionStartedCallback callback;
448 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url2), _)) 465 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _))
449 .WillOnce(SaveArg<3>(&callback)); 466 .WillOnce(SaveArg<3>(&callback));
450 service_impl_->SetDefaultPresentationURL(url2); 467 service_impl_->SetDefaultPresentationUrls(ToGURLs(more_urls));
451 EXPECT_EQ(url2, service_impl_->default_presentation_url_);
452 468
453 blink::mojom::PresentationSessionInfo session_info; 469 blink::mojom::PresentationSessionInfo session_info;
454 session_info.url = url2; 470 session_info.url = GURL(kPresentationUrl2);
455 session_info.id = kPresentationId; 471 session_info.id = kPresentationId;
456 base::RunLoop run_loop; 472 base::RunLoop run_loop;
457 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info))) 473 EXPECT_CALL(mock_client_,
474 OnDefaultSessionStarted(SessionInfoEquals(ByRef(session_info))))
458 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 475 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
459 callback.Run(content::PresentationSessionInfo(url2, kPresentationId)); 476 callback.Run(
477 content::PresentationSessionInfo(kPresentationUrl2, kPresentationId));
460 run_loop.Run(); 478 run_loop.Run();
461 } 479 }
462 480
463 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { 481 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
464 content::PresentationSessionInfo connection(kPresentationUrl, 482 content::PresentationSessionInfo connection(kPresentationUrl1,
465 kPresentationId); 483 kPresentationId);
466 content::PresentationConnectionStateChangedCallback state_changed_cb; 484 content::PresentationConnectionStateChangedCallback state_changed_cb;
467 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 485 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
468 .WillOnce(SaveArg<3>(&state_changed_cb)); 486 .WillOnce(SaveArg<3>(&state_changed_cb));
469 service_impl_->ListenForConnectionStateChange(connection); 487 service_impl_->ListenForConnectionStateChange(connection);
470 488
471 // Trigger state change. It should be propagated back up to |mock_client_|. 489 // Trigger state change. It should be propagated back up to |mock_client_|.
472 blink::mojom::PresentationSessionInfo presentation_connection; 490 blink::mojom::PresentationSessionInfo presentation_connection;
473 presentation_connection.url = kPresentationUrl; 491 presentation_connection.url = GURL(kPresentationUrl1);
474 presentation_connection.id = kPresentationId; 492 presentation_connection.id = kPresentationId;
475 { 493 {
476 base::RunLoop run_loop; 494 base::RunLoop run_loop;
477 EXPECT_CALL(mock_client_, 495 EXPECT_CALL(mock_client_,
478 OnConnectionStateChanged( 496 OnConnectionStateChanged(
479 Equals(presentation_connection), 497 SessionInfoEquals(ByRef(presentation_connection)),
480 blink::mojom::PresentationConnectionState::TERMINATED)) 498 blink::mojom::PresentationConnectionState::TERMINATED))
481 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 499 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
482 state_changed_cb.Run(PresentationConnectionStateChangeInfo( 500 state_changed_cb.Run(PresentationConnectionStateChangeInfo(
483 PRESENTATION_CONNECTION_STATE_TERMINATED)); 501 PRESENTATION_CONNECTION_STATE_TERMINATED));
484 run_loop.Run(); 502 run_loop.Run();
485 } 503 }
486 } 504 }
487 505
488 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { 506 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) {
489 content::PresentationSessionInfo connection(kPresentationUrl, 507 content::PresentationSessionInfo connection(kPresentationUrl1,
490 kPresentationId); 508 kPresentationId);
491 content::PresentationConnectionStateChangedCallback state_changed_cb; 509 content::PresentationConnectionStateChangedCallback state_changed_cb;
492 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 510 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
493 .WillOnce(SaveArg<3>(&state_changed_cb)); 511 .WillOnce(SaveArg<3>(&state_changed_cb));
494 service_impl_->ListenForConnectionStateChange(connection); 512 service_impl_->ListenForConnectionStateChange(connection);
495 513
496 // Trigger connection close. It should be propagated back up to 514 // Trigger connection close. It should be propagated back up to
497 // |mock_client_|. 515 // |mock_client_|.
498 blink::mojom::PresentationSessionInfo presentation_connection; 516 blink::mojom::PresentationSessionInfo presentation_connection;
499 presentation_connection.url = kPresentationUrl; 517 presentation_connection.url = GURL(kPresentationUrl1);
500 presentation_connection.id = kPresentationId; 518 presentation_connection.id = kPresentationId;
501 { 519 {
502 base::RunLoop run_loop; 520 base::RunLoop run_loop;
503 PresentationConnectionStateChangeInfo closed_info( 521 PresentationConnectionStateChangeInfo closed_info(
504 PRESENTATION_CONNECTION_STATE_CLOSED); 522 PRESENTATION_CONNECTION_STATE_CLOSED);
505 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; 523 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY;
506 closed_info.message = "Foo"; 524 closed_info.message = "Foo";
507 525
508 EXPECT_CALL( 526 EXPECT_CALL(
509 mock_client_, 527 mock_client_,
510 OnConnectionClosed( 528 OnConnectionClosed(
511 Equals(presentation_connection), 529 SessionInfoEquals(ByRef(presentation_connection)),
512 blink::mojom::PresentationConnectionCloseReason::WENT_AWAY, "Foo")) 530 blink::mojom::PresentationConnectionCloseReason::WENT_AWAY, "Foo"))
513 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 531 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
514 state_changed_cb.Run(closed_info); 532 state_changed_cb.Run(closed_info);
515 run_loop.Run(); 533 run_loop.Run();
516 } 534 }
517 } 535 }
518 536
519 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { 537 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrls) {
520 EXPECT_CALL(mock_delegate_, 538 std::vector<std::string> urls({kPresentationUrl1, kPresentationUrl2});
521 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) 539
540 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, urls, _))
522 .Times(1); 541 .Times(1);
523 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 542 service_impl_->SetDefaultPresentationUrls(ToGURLs(urls));
524 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 543 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
525 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
526 544
527 // Same URL as before; no-ops. 545 // Same URLs as before; no-ops.
528 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 546 service_impl_->SetDefaultPresentationUrls(ToGURLs(urls));
529 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 547 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
530 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
531 } 548 }
532 549
533 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { 550 TEST_F(PresentationServiceImplTest, StartSessionSuccess) {
551 std::vector<std::string> urls({kPresentationUrl1, kPresentationUrl2});
552
534 service_ptr_->StartSession( 553 service_ptr_->StartSession(
535 kPresentationUrl, 554 ToGURLs(urls),
536 base::Bind( 555 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackSuccess,
537 &PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, 556 base::Unretained(this)));
538 base::Unretained(this)));
539 base::RunLoop run_loop; 557 base::RunLoop run_loop;
540 base::Callback<void(const PresentationSessionInfo&)> success_cb; 558 base::Callback<void(const PresentationSessionInfo&)> success_cb;
541 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) 559 EXPECT_CALL(mock_delegate_, StartSession(_, _, urls, _, _))
542 .WillOnce(DoAll( 560 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
543 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 561 SaveArg<3>(&success_cb)));
544 SaveArg<3>(&success_cb)));
545 run_loop.Run(); 562 run_loop.Run();
546 563
547 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 564 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
548 .Times(1); 565 .Times(1);
549 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); 566 success_cb.Run(PresentationSessionInfo(kPresentationUrl1, kPresentationId));
550 SaveQuitClosureAndRunLoop(); 567 SaveQuitClosureAndRunLoop();
551 } 568 }
552 569
553 TEST_F(PresentationServiceImplTest, StartSessionError) { 570 TEST_F(PresentationServiceImplTest, StartSessionError) {
571 std::vector<std::string> urls({kPresentationUrl1, kPresentationUrl2});
572
554 service_ptr_->StartSession( 573 service_ptr_->StartSession(
555 kPresentationUrl, 574 ToGURLs(urls),
556 base::Bind( 575 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError,
557 &PresentationServiceImplTest::ExpectNewSessionCallbackError, 576 base::Unretained(this)));
558 base::Unretained(this)));
559 base::RunLoop run_loop; 577 base::RunLoop run_loop;
560 base::Callback<void(const PresentationError&)> error_cb; 578 base::Callback<void(const PresentationError&)> error_cb;
561 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) 579 EXPECT_CALL(mock_delegate_, StartSession(_, _, urls, _, _))
562 .WillOnce(DoAll( 580 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
563 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 581 SaveArg<4>(&error_cb)));
564 SaveArg<4>(&error_cb)));
565 run_loop.Run(); 582 run_loop.Run();
566 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); 583 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message"));
567 SaveQuitClosureAndRunLoop(); 584 SaveQuitClosureAndRunLoop();
568 } 585 }
569 586
570 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) { 587 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) {
588 std::vector<std::string> urls({kPresentationUrl1, kPresentationUrl2});
589
571 service_ptr_->JoinSession( 590 service_ptr_->JoinSession(
572 kPresentationUrl, base::Optional<std::string>(kPresentationId), 591 ToGURLs(urls), base::Optional<std::string>(kPresentationId),
573 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackSuccess, 592 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackSuccess,
574 base::Unretained(this))); 593 base::Unretained(this)));
575 base::RunLoop run_loop; 594 base::RunLoop run_loop;
576 base::Callback<void(const PresentationSessionInfo&)> success_cb; 595 base::Callback<void(const PresentationSessionInfo&)> success_cb;
577 EXPECT_CALL(mock_delegate_, JoinSession( 596 EXPECT_CALL(mock_delegate_, JoinSession(_, _, urls, kPresentationId, _, _))
578 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) 597 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
579 .WillOnce(DoAll( 598 SaveArg<4>(&success_cb)));
580 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
581 SaveArg<4>(&success_cb)));
582 run_loop.Run(); 599 run_loop.Run();
583 600
584 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 601 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
585 .Times(1); 602 .Times(1);
586 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); 603 success_cb.Run(PresentationSessionInfo(kPresentationUrl1, kPresentationId));
587 SaveQuitClosureAndRunLoop(); 604 SaveQuitClosureAndRunLoop();
588 } 605 }
589 606
590 TEST_F(PresentationServiceImplTest, JoinSessionError) { 607 TEST_F(PresentationServiceImplTest, JoinSessionError) {
608 std::vector<std::string> urls({kPresentationUrl1, kPresentationUrl2});
609
591 service_ptr_->JoinSession( 610 service_ptr_->JoinSession(
592 kPresentationUrl, base::Optional<std::string>(kPresentationId), 611 ToGURLs(urls), base::Optional<std::string>(kPresentationId),
593 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError, 612 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError,
594 base::Unretained(this))); 613 base::Unretained(this)));
595 base::RunLoop run_loop; 614 base::RunLoop run_loop;
596 base::Callback<void(const PresentationError&)> error_cb; 615 base::Callback<void(const PresentationError&)> error_cb;
597 EXPECT_CALL(mock_delegate_, JoinSession( 616 EXPECT_CALL(mock_delegate_, JoinSession(_, _, urls, kPresentationId, _, _))
598 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) 617 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
599 .WillOnce(DoAll( 618 SaveArg<5>(&error_cb)));
600 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
601 SaveArg<5>(&error_cb)));
602 run_loop.Run(); 619 run_loop.Run();
603 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message")); 620 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message"));
604 SaveQuitClosureAndRunLoop(); 621 SaveQuitClosureAndRunLoop();
605 } 622 }
606 623
607 TEST_F(PresentationServiceImplTest, CloseConnection) { 624 TEST_F(PresentationServiceImplTest, CloseConnection) {
608 service_ptr_->CloseConnection(kPresentationUrl, kPresentationId); 625 GURL url(kPresentationUrl1);
626 service_ptr_->CloseConnection(url, kPresentationId);
627
609 base::RunLoop run_loop; 628 base::RunLoop run_loop;
610 EXPECT_CALL(mock_delegate_, CloseConnection(_, _, Eq(kPresentationId))) 629 EXPECT_CALL(mock_delegate_, CloseConnection(_, _, Eq(kPresentationId)))
611 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 630 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
612 run_loop.Run(); 631 run_loop.Run();
613 } 632 }
614 633
615 TEST_F(PresentationServiceImplTest, Terminate) { 634 TEST_F(PresentationServiceImplTest, Terminate) {
616 service_ptr_->Terminate(kPresentationUrl, kPresentationId); 635 GURL url(kPresentationUrl1);
636 service_ptr_->Terminate(url, kPresentationId);
617 base::RunLoop run_loop; 637 base::RunLoop run_loop;
618 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) 638 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId)))
619 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 639 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
620 run_loop.Run(); 640 run_loop.Run();
621 } 641 }
622 642
623 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesPassed) { 643 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesPassed) {
624 std::string text_msg("123"); 644 std::string text_msg("123");
625 std::vector<uint8_t> binary_data(3, '\1'); 645 std::vector<uint8_t> binary_data(3, '\1');
626 RunListenForSessionMessages(text_msg, binary_data, true); 646 RunListenForSessionMessages(text_msg, binary_data, true);
627 } 647 }
628 648
629 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesCopied) { 649 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesCopied) {
630 std::string text_msg("123"); 650 std::string text_msg("123");
631 std::vector<uint8_t> binary_data(3, '\1'); 651 std::vector<uint8_t> binary_data(3, '\1');
632 RunListenForSessionMessages(text_msg, binary_data, false); 652 RunListenForSessionMessages(text_msg, binary_data, false);
633 } 653 }
634 654
635 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { 655 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) {
636 std::string text_msg(""); 656 std::string text_msg("");
637 std::vector<uint8_t> binary_data; 657 std::vector<uint8_t> binary_data;
638 RunListenForSessionMessages(text_msg, binary_data, false); 658 RunListenForSessionMessages(text_msg, binary_data, false);
639 } 659 }
640 660
641 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 661 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
642 std::string presentation_url1("http://fooUrl"); 662 std::vector<std::string> urls({"http://foourl.com/", "http://barurl.com/"});
643 std::string presentation_url2("http://barUrl"); 663
644 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(presentation_url1), _, _)) 664 EXPECT_CALL(mock_delegate_, StartSession(_, _, urls, _, _)).Times(1);
645 .Times(1); 665 service_ptr_->StartSession(ToGURLs(urls), base::Bind(&DoNothing));
646 service_ptr_->StartSession(presentation_url1,
647 base::Bind(&DoNothing));
648 666
649 // This request should fail immediately, since there is already a StartSession 667 // This request should fail immediately, since there is already a StartSession
650 // in progress. 668 // in progress.
651 service_ptr_->StartSession( 669 service_ptr_->StartSession(
652 presentation_url2, 670 ToGURLs(urls),
653 base::Bind( 671 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError,
654 &PresentationServiceImplTest::ExpectNewSessionCallbackError, 672 base::Unretained(this)));
655 base::Unretained(this)));
656 SaveQuitClosureAndRunLoop(); 673 SaveQuitClosureAndRunLoop();
657 } 674 }
658 675
659 TEST_F(PresentationServiceImplTest, SendStringMessage) { 676 TEST_F(PresentationServiceImplTest, SendStringMessage) {
660 std::string message("Test presentation session message"); 677 std::string message("Test presentation session message");
661 678
662 blink::mojom::PresentationSessionInfoPtr session( 679 blink::mojom::PresentationSessionInfoPtr session(
663 blink::mojom::PresentationSessionInfo::New()); 680 blink::mojom::PresentationSessionInfo::New());
664 session->url = kPresentationUrl; 681 session->url = GURL(kPresentationUrl1);
665 session->id = kPresentationId; 682 session->id = kPresentationId;
666 blink::mojom::SessionMessagePtr message_request( 683 blink::mojom::SessionMessagePtr message_request(
667 blink::mojom::SessionMessage::New()); 684 blink::mojom::SessionMessage::New());
668 message_request->type = blink::mojom::PresentationMessageType::TEXT; 685 message_request->type = blink::mojom::PresentationMessageType::TEXT;
669 message_request->message = message; 686 message_request->message = message;
670 service_ptr_->SendSessionMessage( 687 service_ptr_->SendSessionMessage(
671 std::move(session), std::move(message_request), 688 std::move(session), std::move(message_request),
672 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, 689 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback,
673 base::Unretained(this))); 690 base::Unretained(this)));
674 691
(...skipping 17 matching lines...) Expand all
692 } 709 }
693 710
694 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { 711 TEST_F(PresentationServiceImplTest, SendArrayBuffer) {
695 // Test Array buffer data. 712 // Test Array buffer data.
696 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; 713 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
697 std::vector<uint8_t> data; 714 std::vector<uint8_t> data;
698 data.assign(buffer, buffer + sizeof(buffer)); 715 data.assign(buffer, buffer + sizeof(buffer));
699 716
700 blink::mojom::PresentationSessionInfoPtr session( 717 blink::mojom::PresentationSessionInfoPtr session(
701 blink::mojom::PresentationSessionInfo::New()); 718 blink::mojom::PresentationSessionInfo::New());
702 session->url = kPresentationUrl; 719 session->url = GURL(kPresentationUrl1);
703 session->id = kPresentationId; 720 session->id = kPresentationId;
704 blink::mojom::SessionMessagePtr message_request( 721 blink::mojom::SessionMessagePtr message_request(
705 blink::mojom::SessionMessage::New()); 722 blink::mojom::SessionMessage::New());
706 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; 723 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
707 message_request->data = data; 724 message_request->data = data;
708 service_ptr_->SendSessionMessage( 725 service_ptr_->SendSessionMessage(
709 std::move(session), std::move(message_request), 726 std::move(session), std::move(message_request),
710 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, 727 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback,
711 base::Unretained(this))); 728 base::Unretained(this)));
712 729
(...skipping 23 matching lines...) Expand all
736 // Create buffer with size exceeding the limit. 753 // Create buffer with size exceeding the limit.
737 // Use same size as in content::kMaxPresentationSessionMessageSize. 754 // Use same size as in content::kMaxPresentationSessionMessageSize.
738 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB. 755 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB.
739 uint8_t buffer[kMaxBufferSizeInBytes + 1]; 756 uint8_t buffer[kMaxBufferSizeInBytes + 1];
740 memset(buffer, 0, kMaxBufferSizeInBytes+1); 757 memset(buffer, 0, kMaxBufferSizeInBytes+1);
741 std::vector<uint8_t> data; 758 std::vector<uint8_t> data;
742 data.assign(buffer, buffer + sizeof(buffer)); 759 data.assign(buffer, buffer + sizeof(buffer));
743 760
744 blink::mojom::PresentationSessionInfoPtr session( 761 blink::mojom::PresentationSessionInfoPtr session(
745 blink::mojom::PresentationSessionInfo::New()); 762 blink::mojom::PresentationSessionInfo::New());
746 session->url = kPresentationUrl; 763 session->url = GURL(kPresentationUrl1);
747 session->id = kPresentationId; 764 session->id = kPresentationId;
748 blink::mojom::SessionMessagePtr message_request( 765 blink::mojom::SessionMessagePtr message_request(
749 blink::mojom::SessionMessage::New()); 766 blink::mojom::SessionMessage::New());
750 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; 767 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
751 message_request->data = data; 768 message_request->data = data;
752 service_ptr_->SendSessionMessage( 769 service_ptr_->SendSessionMessage(
753 std::move(session), std::move(message_request), 770 std::move(session), std::move(message_request),
754 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, 771 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback,
755 base::Unretained(this))); 772 base::Unretained(this)));
756 773
(...skipping 10 matching lines...) Expand all
767 SaveQuitClosureAndRunLoop(); 784 SaveQuitClosureAndRunLoop();
768 } 785 }
769 786
770 TEST_F(PresentationServiceImplTest, SendBlobData) { 787 TEST_F(PresentationServiceImplTest, SendBlobData) {
771 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; 788 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
772 std::vector<uint8_t> data; 789 std::vector<uint8_t> data;
773 data.assign(buffer, buffer + sizeof(buffer)); 790 data.assign(buffer, buffer + sizeof(buffer));
774 791
775 blink::mojom::PresentationSessionInfoPtr session( 792 blink::mojom::PresentationSessionInfoPtr session(
776 blink::mojom::PresentationSessionInfo::New()); 793 blink::mojom::PresentationSessionInfo::New());
777 session->url = kPresentationUrl; 794 session->url = GURL(kPresentationUrl1);
778 session->id = kPresentationId; 795 session->id = kPresentationId;
779 blink::mojom::SessionMessagePtr message_request( 796 blink::mojom::SessionMessagePtr message_request(
780 blink::mojom::SessionMessage::New()); 797 blink::mojom::SessionMessage::New());
781 message_request->type = blink::mojom::PresentationMessageType::BLOB; 798 message_request->type = blink::mojom::PresentationMessageType::BLOB;
782 message_request->data = data; 799 message_request->data = data;
783 service_ptr_->SendSessionMessage( 800 service_ptr_->SendSessionMessage(
784 std::move(session), std::move(message_request), 801 std::move(session), std::move(message_request),
785 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback, 802 base::Bind(&PresentationServiceImplTest::ExpectSendSessionMessageCallback,
786 base::Unretained(this))); 803 base::Unretained(this)));
787 804
(...skipping 20 matching lines...) Expand all
808 } 825 }
809 826
810 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) { 827 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) {
811 const char* presentation_url = "http://fooUrl%d"; 828 const char* presentation_url = "http://fooUrl%d";
812 const char* presentation_id = "presentationId%d"; 829 const char* presentation_id = "presentationId%d";
813 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests; 830 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests;
814 int i = 0; 831 int i = 0;
815 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _)) 832 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _))
816 .Times(num_requests); 833 .Times(num_requests);
817 for (; i < num_requests; ++i) { 834 for (; i < num_requests; ++i) {
818 service_ptr_->JoinSession( 835 std::vector<GURL> urls({GURL(base::StringPrintf(presentation_url, i))});
819 base::StringPrintf(presentation_url, i), 836 service_ptr_->JoinSession(urls, base::StringPrintf(presentation_id, i),
820 base::StringPrintf(presentation_id, i), 837 base::Bind(&DoNothing));
821 base::Bind(&DoNothing));
822 } 838 }
823 839
840 std::vector<GURL> urls({GURL(base::StringPrintf(presentation_url, i))});
824 // Exceeded maximum queue size, should invoke mojo callback with error. 841 // Exceeded maximum queue size, should invoke mojo callback with error.
825 service_ptr_->JoinSession( 842 service_ptr_->JoinSession(
826 base::StringPrintf(presentation_url, i), 843 urls, base::StringPrintf(presentation_id, i),
827 base::StringPrintf(presentation_id, i), 844 base::Bind(&PresentationServiceImplTest::ExpectNewSessionCallbackError,
828 base::Bind( 845 base::Unretained(this)));
829 &PresentationServiceImplTest::ExpectNewSessionCallbackError,
830 base::Unretained(this)));
831 SaveQuitClosureAndRunLoop(); 846 SaveQuitClosureAndRunLoop();
832 } 847 }
833 848
834 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { 849 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) {
835 mock_delegate_.set_screen_availability_listening_supported(false); 850 mock_delegate_.set_screen_availability_listening_supported(false);
851 GURL url(kPresentationUrl1);
836 base::RunLoop run_loop; 852 base::RunLoop run_loop;
837 EXPECT_CALL(mock_client_, 853 EXPECT_CALL(mock_client_, OnScreenAvailabilityNotSupported(url))
838 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl)))
839 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 854 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
840 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); 855 ListenForScreenAvailabilityAndWait(kPresentationUrl1, false);
841 run_loop.Run(); 856 run_loop.Run();
842 } 857 }
843 858
844 } // namespace content 859 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/presentation/presentation_service_impl.cc ('k') | content/browser/presentation/presentation_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698