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

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

Issue 1957143002: [OnionSoup] Move persentation_service.mojom from //content to //third_party/WebKit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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 28 matching lines...) Expand all
39 namespace { 39 namespace {
40 40
41 // Matches mojo structs. 41 // Matches mojo structs.
42 MATCHER_P(Equals, expected, "") { 42 MATCHER_P(Equals, expected, "") {
43 return expected.Equals(arg); 43 return expected.Equals(arg);
44 } 44 }
45 45
46 const char *const kPresentationId = "presentationId"; 46 const char *const kPresentationId = "presentationId";
47 const char *const kPresentationUrl = "http://foo.com/index.html"; 47 const char *const kPresentationUrl = "http://foo.com/index.html";
48 48
49 bool ArePresentationSessionMessagesEqual(const mojom::SessionMessage* expected, 49 bool ArePresentationSessionMessagesEqual(
50 const mojom::SessionMessage* actual) { 50 const blink::mojom::SessionMessage* expected,
51 const blink::mojom::SessionMessage* actual) {
51 return expected->type == actual->type && 52 return expected->type == actual->type &&
52 expected->message == actual->message && 53 expected->message == actual->message &&
53 expected->data.Equals(actual->data); 54 expected->data.Equals(actual->data);
54 } 55 }
55 56
56 void DoNothing(mojom::PresentationSessionInfoPtr info, 57 void DoNothing(blink::mojom::PresentationSessionInfoPtr info,
57 mojom::PresentationErrorPtr error) {} 58 blink::mojom::PresentationErrorPtr error) {}
58 59
59 } // namespace 60 } // namespace
60 61
61 class MockPresentationServiceDelegate : public PresentationServiceDelegate { 62 class MockPresentationServiceDelegate : public PresentationServiceDelegate {
62 public: 63 public:
63 MOCK_METHOD3(AddObserver, 64 MOCK_METHOD3(AddObserver,
64 void(int render_process_id, 65 void(int render_process_id,
65 int render_frame_id, 66 int render_frame_id,
66 PresentationServiceDelegate::Observer* observer)); 67 PresentationServiceDelegate::Observer* observer));
67 MOCK_METHOD2(RemoveObserver, 68 MOCK_METHOD2(RemoveObserver,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 state_changed_cb)); 141 state_changed_cb));
141 142
142 void set_screen_availability_listening_supported(bool value) { 143 void set_screen_availability_listening_supported(bool value) {
143 screen_availability_listening_supported_ = value; 144 screen_availability_listening_supported_ = value;
144 } 145 }
145 146
146 private: 147 private:
147 bool screen_availability_listening_supported_ = true; 148 bool screen_availability_listening_supported_ = true;
148 }; 149 };
149 150
150 class MockPresentationServiceClient : public mojom::PresentationServiceClient { 151 class MockPresentationServiceClient
152 : public blink::mojom::PresentationServiceClient {
151 public: 153 public:
152 MOCK_METHOD2(OnScreenAvailabilityUpdated, 154 MOCK_METHOD2(OnScreenAvailabilityUpdated,
153 void(const mojo::String& url, bool available)); 155 void(const mojo::String& url, bool available));
154 void OnConnectionStateChanged( 156 void OnConnectionStateChanged(
155 mojom::PresentationSessionInfoPtr connection, 157 blink::mojom::PresentationSessionInfoPtr connection,
156 mojom::PresentationConnectionState new_state) override { 158 blink::mojom::PresentationConnectionState new_state) override {
157 OnConnectionStateChanged(*connection, new_state); 159 OnConnectionStateChanged(*connection, new_state);
158 } 160 }
159 MOCK_METHOD2(OnConnectionStateChanged, 161 MOCK_METHOD2(OnConnectionStateChanged,
160 void(const mojom::PresentationSessionInfo& connection, 162 void(const blink::mojom::PresentationSessionInfo& connection,
161 mojom::PresentationConnectionState new_state)); 163 blink::mojom::PresentationConnectionState new_state));
162 164
163 void OnConnectionClosed(mojom::PresentationSessionInfoPtr connection, 165 void OnConnectionClosed(
164 mojom::PresentationConnectionCloseReason reason, 166 blink::mojom::PresentationSessionInfoPtr connection,
165 const mojo::String& message) override { 167 blink::mojom::PresentationConnectionCloseReason reason,
168 const mojo::String& message) override {
166 OnConnectionClosed(*connection, reason, message); 169 OnConnectionClosed(*connection, reason, message);
167 } 170 }
168 MOCK_METHOD3(OnConnectionClosed, 171 MOCK_METHOD3(OnConnectionClosed,
169 void(const mojom::PresentationSessionInfo& connection, 172 void(const blink::mojom::PresentationSessionInfo& connection,
170 mojom::PresentationConnectionCloseReason reason, 173 blink::mojom::PresentationConnectionCloseReason reason,
171 const mojo::String& message)); 174 const mojo::String& message));
172 175
173 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url)); 176 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url));
174 177
175 void OnSessionMessagesReceived( 178 void OnSessionMessagesReceived(
176 mojom::PresentationSessionInfoPtr session_info, 179 blink::mojom::PresentationSessionInfoPtr session_info,
177 mojo::Array<mojom::SessionMessagePtr> messages) override { 180 mojo::Array<blink::mojom::SessionMessagePtr> messages) override {
178 messages_received_ = std::move(messages); 181 messages_received_ = std::move(messages);
179 MessagesReceived(); 182 MessagesReceived();
180 } 183 }
181 MOCK_METHOD0(MessagesReceived, void()); 184 MOCK_METHOD0(MessagesReceived, void());
182 185
183 void OnDefaultSessionStarted( 186 void OnDefaultSessionStarted(
184 mojom::PresentationSessionInfoPtr session_info) override { 187 blink::mojom::PresentationSessionInfoPtr session_info) override {
185 OnDefaultSessionStarted(*session_info); 188 OnDefaultSessionStarted(*session_info);
186 } 189 }
187 MOCK_METHOD1(OnDefaultSessionStarted, 190 MOCK_METHOD1(OnDefaultSessionStarted,
188 void(const mojom::PresentationSessionInfo& session_info)); 191 void(const blink::mojom::PresentationSessionInfo& session_info));
189 192
190 mojo::Array<mojom::SessionMessagePtr> messages_received_; 193 mojo::Array<blink::mojom::SessionMessagePtr> messages_received_;
191 }; 194 };
192 195
193 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 196 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
194 public: 197 public:
195 PresentationServiceImplTest() {} 198 PresentationServiceImplTest() {}
196 199
197 void SetUp() override { 200 void SetUp() override {
198 RenderViewHostImplTestHarness::SetUp(); 201 RenderViewHostImplTestHarness::SetUp();
199 202
200 auto request = mojo::GetProxy(&service_ptr_); 203 auto request = mojo::GetProxy(&service_ptr_);
201 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); 204 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1);
202 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame(); 205 TestRenderFrameHost* render_frame_host = contents()->GetMainFrame();
203 render_frame_host->InitializeRenderFrameIfNeeded(); 206 render_frame_host->InitializeRenderFrameIfNeeded();
204 service_impl_.reset(new PresentationServiceImpl( 207 service_impl_.reset(new PresentationServiceImpl(
205 render_frame_host, contents(), &mock_delegate_)); 208 render_frame_host, contents(), &mock_delegate_));
206 service_impl_->Bind(std::move(request)); 209 service_impl_->Bind(std::move(request));
207 210
208 mojom::PresentationServiceClientPtr client_ptr; 211 blink::mojom::PresentationServiceClientPtr client_ptr;
209 client_binding_.reset(new mojo::Binding<mojom::PresentationServiceClient>( 212 client_binding_.reset(
210 &mock_client_, mojo::GetProxy(&client_ptr))); 213 new mojo::Binding<blink::mojom::PresentationServiceClient>(
214 &mock_client_, mojo::GetProxy(&client_ptr)));
211 service_impl_->SetClient(std::move(client_ptr)); 215 service_impl_->SetClient(std::move(client_ptr));
212 } 216 }
213 217
214 void TearDown() override { 218 void TearDown() override {
215 service_ptr_.reset(); 219 service_ptr_.reset();
216 if (service_impl_.get()) { 220 if (service_impl_.get()) {
217 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); 221 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1);
218 service_impl_.reset(); 222 service_impl_.reset();
219 } 223 }
220 RenderViewHostImplTestHarness::TearDown(); 224 RenderViewHostImplTestHarness::TearDown();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 274
271 void ExpectCleanState() { 275 void ExpectCleanState() {
272 EXPECT_TRUE(service_impl_->default_presentation_url_.empty()); 276 EXPECT_TRUE(service_impl_->default_presentation_url_.empty());
273 EXPECT_EQ( 277 EXPECT_EQ(
274 service_impl_->screen_availability_listeners_.find(kPresentationUrl), 278 service_impl_->screen_availability_listeners_.find(kPresentationUrl),
275 service_impl_->screen_availability_listeners_.end()); 279 service_impl_->screen_availability_listeners_.end());
276 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); 280 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get());
277 } 281 }
278 282
279 void ExpectNewSessionMojoCallbackSuccess( 283 void ExpectNewSessionMojoCallbackSuccess(
280 mojom::PresentationSessionInfoPtr info, 284 blink::mojom::PresentationSessionInfoPtr info,
281 mojom::PresentationErrorPtr error) { 285 blink::mojom::PresentationErrorPtr error) {
282 EXPECT_FALSE(info.is_null()); 286 EXPECT_FALSE(info.is_null());
283 EXPECT_TRUE(error.is_null()); 287 EXPECT_TRUE(error.is_null());
284 if (!run_loop_quit_closure_.is_null()) 288 if (!run_loop_quit_closure_.is_null())
285 run_loop_quit_closure_.Run(); 289 run_loop_quit_closure_.Run();
286 } 290 }
287 291
288 void ExpectNewSessionMojoCallbackError(mojom::PresentationSessionInfoPtr info, 292 void ExpectNewSessionMojoCallbackError(
289 mojom::PresentationErrorPtr error) { 293 blink::mojom::PresentationSessionInfoPtr info,
294 blink::mojom::PresentationErrorPtr error) {
290 EXPECT_TRUE(info.is_null()); 295 EXPECT_TRUE(info.is_null());
291 EXPECT_FALSE(error.is_null()); 296 EXPECT_FALSE(error.is_null());
292 if (!run_loop_quit_closure_.is_null()) 297 if (!run_loop_quit_closure_.is_null())
293 run_loop_quit_closure_.Run(); 298 run_loop_quit_closure_.Run();
294 } 299 }
295 300
296 void ExpectSessionMessages( 301 void ExpectSessionMessages(
297 const mojo::Array<mojom::SessionMessagePtr>& expected_msgs, 302 const mojo::Array<blink::mojom::SessionMessagePtr>& expected_msgs,
298 const mojo::Array<mojom::SessionMessagePtr>& actual_msgs) { 303 const mojo::Array<blink::mojom::SessionMessagePtr>& actual_msgs) {
299 EXPECT_EQ(expected_msgs.size(), actual_msgs.size()); 304 EXPECT_EQ(expected_msgs.size(), actual_msgs.size());
300 for (size_t i = 0; i < actual_msgs.size(); ++i) { 305 for (size_t i = 0; i < actual_msgs.size(); ++i) {
301 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs[i].get(), 306 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs[i].get(),
302 actual_msgs[i].get())); 307 actual_msgs[i].get()));
303 } 308 }
304 } 309 }
305 310
306 void ExpectSendMessageMojoCallback(bool success) { 311 void ExpectSendMessageMojoCallback(bool success) {
307 EXPECT_TRUE(success); 312 EXPECT_TRUE(success);
308 EXPECT_FALSE(service_impl_->send_message_callback_); 313 EXPECT_FALSE(service_impl_->send_message_callback_);
309 if (!run_loop_quit_closure_.is_null()) 314 if (!run_loop_quit_closure_.is_null())
310 run_loop_quit_closure_.Run(); 315 run_loop_quit_closure_.Run();
311 } 316 }
312 317
313 void RunListenForSessionMessages(const std::string& text_msg, 318 void RunListenForSessionMessages(const std::string& text_msg,
314 const std::vector<uint8_t>& binary_data, 319 const std::vector<uint8_t>& binary_data,
315 bool pass_ownership) { 320 bool pass_ownership) {
316 mojo::Array<mojom::SessionMessagePtr> expected_msgs(2); 321 mojo::Array<blink::mojom::SessionMessagePtr> expected_msgs(2);
317 expected_msgs[0] = mojom::SessionMessage::New(); 322 expected_msgs[0] = blink::mojom::SessionMessage::New();
318 expected_msgs[0]->type = mojom::PresentationMessageType::TEXT; 323 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT;
319 expected_msgs[0]->message = text_msg; 324 expected_msgs[0]->message = text_msg;
320 expected_msgs[1] = mojom::SessionMessage::New(); 325 expected_msgs[1] = blink::mojom::SessionMessage::New();
321 expected_msgs[1]->type = mojom::PresentationMessageType::ARRAY_BUFFER; 326 expected_msgs[1]->type =
327 blink::mojom::PresentationMessageType::ARRAY_BUFFER;
322 expected_msgs[1]->data = mojo::Array<uint8_t>::From(binary_data); 328 expected_msgs[1]->data = mojo::Array<uint8_t>::From(binary_data);
323 329
324 mojom::PresentationSessionInfoPtr session( 330 blink::mojom::PresentationSessionInfoPtr session(
325 mojom::PresentationSessionInfo::New()); 331 blink::mojom::PresentationSessionInfo::New());
326 session->url = kPresentationUrl; 332 session->url = kPresentationUrl;
327 session->id = kPresentationId; 333 session->id = kPresentationId;
328 334
329 PresentationSessionMessageCallback message_cb; 335 PresentationSessionMessageCallback message_cb;
330 { 336 {
331 base::RunLoop run_loop; 337 base::RunLoop run_loop;
332 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _)) 338 EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _, _))
333 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 339 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
334 SaveArg<3>(&message_cb))); 340 SaveArg<3>(&message_cb)));
335 service_ptr_->ListenForSessionMessages(session.Clone()); 341 service_ptr_->ListenForSessionMessages(session.Clone());
336 run_loop.Run(); 342 run_loop.Run();
337 } 343 }
338 344
339 ScopedVector<PresentationSessionMessage> messages; 345 ScopedVector<PresentationSessionMessage> messages;
340 std::unique_ptr<content::PresentationSessionMessage> message; 346 std::unique_ptr<content::PresentationSessionMessage> message;
341 message.reset( 347 message.reset(
342 new content::PresentationSessionMessage(PresentationMessageType::TEXT)); 348 new content::PresentationSessionMessage(PresentationMessageType::TEXT));
343 message->message = text_msg; 349 message->message = text_msg;
344 messages.push_back(std::move(message)); 350 messages.push_back(std::move(message));
345 message.reset(new content::PresentationSessionMessage( 351 message.reset(new content::PresentationSessionMessage(
346 PresentationMessageType::ARRAY_BUFFER)); 352 PresentationMessageType::ARRAY_BUFFER));
347 message->data.reset(new std::vector<uint8_t>(binary_data)); 353 message->data.reset(new std::vector<uint8_t>(binary_data));
348 messages.push_back(std::move(message)); 354 messages.push_back(std::move(message));
349 355
350 std::vector<mojom::SessionMessagePtr> actual_msgs; 356 std::vector<blink::mojom::SessionMessagePtr> actual_msgs;
351 { 357 {
352 base::RunLoop run_loop; 358 base::RunLoop run_loop;
353 EXPECT_CALL(mock_client_, MessagesReceived()) 359 EXPECT_CALL(mock_client_, MessagesReceived())
354 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 360 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
355 message_cb.Run(std::move(messages), pass_ownership); 361 message_cb.Run(std::move(messages), pass_ownership);
356 run_loop.Run(); 362 run_loop.Run();
357 } 363 }
358 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_); 364 ExpectSessionMessages(expected_msgs, mock_client_.messages_received_);
359 } 365 }
360 366
361 MockPresentationServiceDelegate mock_delegate_; 367 MockPresentationServiceDelegate mock_delegate_;
362 368
363 std::unique_ptr<PresentationServiceImpl> service_impl_; 369 std::unique_ptr<PresentationServiceImpl> service_impl_;
364 mojo::InterfacePtr<mojom::PresentationService> service_ptr_; 370 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_;
365 371
366 MockPresentationServiceClient mock_client_; 372 MockPresentationServiceClient mock_client_;
367 std::unique_ptr<mojo::Binding<mojom::PresentationServiceClient>> 373 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>>
368 client_binding_; 374 client_binding_;
369 375
370 base::Closure run_loop_quit_closure_; 376 base::Closure run_loop_quit_closure_;
371 }; 377 };
372 378
373 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { 379 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) {
374 ListenForScreenAvailabilityAndWait(kPresentationUrl, true); 380 ListenForScreenAvailabilityAndWait(kPresentationUrl, true);
375 381
376 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true); 382 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, true);
377 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, false); 383 SimulateScreenAvailabilityChangeAndWait(kPresentationUrl, false);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 EXPECT_EQ(url1, service_impl_->default_presentation_url_); 454 EXPECT_EQ(url1, service_impl_->default_presentation_url_);
449 455
450 std::string url2("http://barUrl"); 456 std::string url2("http://barUrl");
451 // Sets different DPU. 457 // Sets different DPU.
452 content::PresentationSessionStartedCallback callback; 458 content::PresentationSessionStartedCallback callback;
453 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url2), _)) 459 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url2), _))
454 .WillOnce(SaveArg<3>(&callback)); 460 .WillOnce(SaveArg<3>(&callback));
455 service_impl_->SetDefaultPresentationURL(url2); 461 service_impl_->SetDefaultPresentationURL(url2);
456 EXPECT_EQ(url2, service_impl_->default_presentation_url_); 462 EXPECT_EQ(url2, service_impl_->default_presentation_url_);
457 463
458 mojom::PresentationSessionInfo session_info; 464 blink::mojom::PresentationSessionInfo session_info;
459 session_info.url = url2; 465 session_info.url = url2;
460 session_info.id = kPresentationId; 466 session_info.id = kPresentationId;
461 base::RunLoop run_loop; 467 base::RunLoop run_loop;
462 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info))) 468 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info)))
463 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 469 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
464 callback.Run(content::PresentationSessionInfo(url2, kPresentationId)); 470 callback.Run(content::PresentationSessionInfo(url2, kPresentationId));
465 run_loop.Run(); 471 run_loop.Run();
466 } 472 }
467 473
468 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { 474 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
469 content::PresentationSessionInfo connection(kPresentationUrl, 475 content::PresentationSessionInfo connection(kPresentationUrl,
470 kPresentationId); 476 kPresentationId);
471 content::PresentationConnectionStateChangedCallback state_changed_cb; 477 content::PresentationConnectionStateChangedCallback state_changed_cb;
472 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 478 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
473 .WillOnce(SaveArg<3>(&state_changed_cb)); 479 .WillOnce(SaveArg<3>(&state_changed_cb));
474 service_impl_->ListenForConnectionStateChange(connection); 480 service_impl_->ListenForConnectionStateChange(connection);
475 481
476 // Trigger state change. It should be propagated back up to |mock_client_|. 482 // Trigger state change. It should be propagated back up to |mock_client_|.
477 mojom::PresentationSessionInfo presentation_connection; 483 blink::mojom::PresentationSessionInfo presentation_connection;
478 presentation_connection.url = kPresentationUrl; 484 presentation_connection.url = kPresentationUrl;
479 presentation_connection.id = kPresentationId; 485 presentation_connection.id = kPresentationId;
480 { 486 {
481 base::RunLoop run_loop; 487 base::RunLoop run_loop;
482 EXPECT_CALL(mock_client_, 488 EXPECT_CALL(mock_client_,
483 OnConnectionStateChanged( 489 OnConnectionStateChanged(
484 Equals(presentation_connection), 490 Equals(presentation_connection),
485 mojom::PresentationConnectionState::TERMINATED)) 491 blink::mojom::PresentationConnectionState::TERMINATED))
486 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 492 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
487 state_changed_cb.Run(PresentationConnectionStateChangeInfo( 493 state_changed_cb.Run(PresentationConnectionStateChangeInfo(
488 PRESENTATION_CONNECTION_STATE_TERMINATED)); 494 PRESENTATION_CONNECTION_STATE_TERMINATED));
489 run_loop.Run(); 495 run_loop.Run();
490 } 496 }
491 } 497 }
492 498
493 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { 499 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) {
494 content::PresentationSessionInfo connection(kPresentationUrl, 500 content::PresentationSessionInfo connection(kPresentationUrl,
495 kPresentationId); 501 kPresentationId);
496 content::PresentationConnectionStateChangedCallback state_changed_cb; 502 content::PresentationConnectionStateChangedCallback state_changed_cb;
497 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 503 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
498 .WillOnce(SaveArg<3>(&state_changed_cb)); 504 .WillOnce(SaveArg<3>(&state_changed_cb));
499 service_impl_->ListenForConnectionStateChange(connection); 505 service_impl_->ListenForConnectionStateChange(connection);
500 506
501 // Trigger connection close. It should be propagated back up to 507 // Trigger connection close. It should be propagated back up to
502 // |mock_client_|. 508 // |mock_client_|.
503 mojom::PresentationSessionInfo presentation_connection; 509 blink::mojom::PresentationSessionInfo presentation_connection;
504 presentation_connection.url = kPresentationUrl; 510 presentation_connection.url = kPresentationUrl;
505 presentation_connection.id = kPresentationId; 511 presentation_connection.id = kPresentationId;
506 { 512 {
507 base::RunLoop run_loop; 513 base::RunLoop run_loop;
508 PresentationConnectionStateChangeInfo closed_info( 514 PresentationConnectionStateChangeInfo closed_info(
509 PRESENTATION_CONNECTION_STATE_CLOSED); 515 PRESENTATION_CONNECTION_STATE_CLOSED);
510 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; 516 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY;
511 closed_info.message = "Foo"; 517 closed_info.message = "Foo";
512 518
513 EXPECT_CALL( 519 EXPECT_CALL(mock_client_,
514 mock_client_, 520 OnConnectionClosed(
515 OnConnectionClosed(Equals(presentation_connection), 521 Equals(presentation_connection),
516 mojom::PresentationConnectionCloseReason::WENT_AWAY, 522 blink::mojom::PresentationConnectionCloseReason::WENT_AWAY,
517 mojo::String("Foo"))) 523 mojo::String("Foo")))
518 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 524 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
519 state_changed_cb.Run(closed_info); 525 state_changed_cb.Run(closed_info);
520 run_loop.Run(); 526 run_loop.Run();
521 } 527 }
522 } 528 }
523 529
524 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { 530 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) {
525 EXPECT_CALL(mock_delegate_, 531 EXPECT_CALL(mock_delegate_,
526 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) 532 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _))
527 .Times(1); 533 .Times(1);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 presentation_url2, 667 presentation_url2,
662 base::Bind( 668 base::Bind(
663 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 669 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
664 base::Unretained(this))); 670 base::Unretained(this)));
665 SaveQuitClosureAndRunLoop(); 671 SaveQuitClosureAndRunLoop();
666 } 672 }
667 673
668 TEST_F(PresentationServiceImplTest, SendStringMessage) { 674 TEST_F(PresentationServiceImplTest, SendStringMessage) {
669 std::string message("Test presentation session message"); 675 std::string message("Test presentation session message");
670 676
671 mojom::PresentationSessionInfoPtr session( 677 blink::mojom::PresentationSessionInfoPtr session(
672 mojom::PresentationSessionInfo::New()); 678 blink::mojom::PresentationSessionInfo::New());
673 session->url = kPresentationUrl; 679 session->url = kPresentationUrl;
674 session->id = kPresentationId; 680 session->id = kPresentationId;
675 mojom::SessionMessagePtr message_request(mojom::SessionMessage::New()); 681 blink::mojom::SessionMessagePtr message_request(
676 message_request->type = mojom::PresentationMessageType::TEXT; 682 blink::mojom::SessionMessage::New());
683 message_request->type = blink::mojom::PresentationMessageType::TEXT;
677 message_request->message = message; 684 message_request->message = message;
678 service_ptr_->SendSessionMessage( 685 service_ptr_->SendSessionMessage(
679 std::move(session), std::move(message_request), 686 std::move(session), std::move(message_request),
680 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, 687 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
681 base::Unretained(this))); 688 base::Unretained(this)));
682 689
683 base::RunLoop run_loop; 690 base::RunLoop run_loop;
684 base::Callback<void(bool)> send_message_cb; 691 base::Callback<void(bool)> send_message_cb;
685 PresentationSessionMessage* test_message = nullptr; 692 PresentationSessionMessage* test_message = nullptr;
686 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) 693 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
(...skipping 11 matching lines...) Expand all
698 send_message_cb.Run(true); 705 send_message_cb.Run(true);
699 SaveQuitClosureAndRunLoop(); 706 SaveQuitClosureAndRunLoop();
700 } 707 }
701 708
702 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { 709 TEST_F(PresentationServiceImplTest, SendArrayBuffer) {
703 // Test Array buffer data. 710 // Test Array buffer data.
704 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; 711 const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
705 std::vector<uint8_t> data; 712 std::vector<uint8_t> data;
706 data.assign(buffer, buffer + sizeof(buffer)); 713 data.assign(buffer, buffer + sizeof(buffer));
707 714
708 mojom::PresentationSessionInfoPtr session( 715 blink::mojom::PresentationSessionInfoPtr session(
709 mojom::PresentationSessionInfo::New()); 716 blink::mojom::PresentationSessionInfo::New());
710 session->url = kPresentationUrl; 717 session->url = kPresentationUrl;
711 session->id = kPresentationId; 718 session->id = kPresentationId;
712 mojom::SessionMessagePtr message_request(mojom::SessionMessage::New()); 719 blink::mojom::SessionMessagePtr message_request(
713 message_request->type = mojom::PresentationMessageType::ARRAY_BUFFER; 720 blink::mojom::SessionMessage::New());
721 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
714 message_request->data = mojo::Array<uint8_t>::From(data); 722 message_request->data = mojo::Array<uint8_t>::From(data);
715 service_ptr_->SendSessionMessage( 723 service_ptr_->SendSessionMessage(
716 std::move(session), std::move(message_request), 724 std::move(session), std::move(message_request),
717 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, 725 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
718 base::Unretained(this))); 726 base::Unretained(this)));
719 727
720 base::RunLoop run_loop; 728 base::RunLoop run_loop;
721 base::Callback<void(bool)> send_message_cb; 729 base::Callback<void(bool)> send_message_cb;
722 PresentationSessionMessage* test_message = nullptr; 730 PresentationSessionMessage* test_message = nullptr;
723 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) 731 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
(...skipping 17 matching lines...) Expand all
741 749
742 TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) { 750 TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) {
743 // Create buffer with size exceeding the limit. 751 // Create buffer with size exceeding the limit.
744 // Use same size as in content::kMaxPresentationSessionMessageSize. 752 // Use same size as in content::kMaxPresentationSessionMessageSize.
745 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB. 753 const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB.
746 uint8_t buffer[kMaxBufferSizeInBytes + 1]; 754 uint8_t buffer[kMaxBufferSizeInBytes + 1];
747 memset(buffer, 0, kMaxBufferSizeInBytes+1); 755 memset(buffer, 0, kMaxBufferSizeInBytes+1);
748 std::vector<uint8_t> data; 756 std::vector<uint8_t> data;
749 data.assign(buffer, buffer + sizeof(buffer)); 757 data.assign(buffer, buffer + sizeof(buffer));
750 758
751 mojom::PresentationSessionInfoPtr session( 759 blink::mojom::PresentationSessionInfoPtr session(
752 mojom::PresentationSessionInfo::New()); 760 blink::mojom::PresentationSessionInfo::New());
753 session->url = kPresentationUrl; 761 session->url = kPresentationUrl;
754 session->id = kPresentationId; 762 session->id = kPresentationId;
755 mojom::SessionMessagePtr message_request(mojom::SessionMessage::New()); 763 blink::mojom::SessionMessagePtr message_request(
756 message_request->type = mojom::PresentationMessageType::ARRAY_BUFFER; 764 blink::mojom::SessionMessage::New());
765 message_request->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
757 message_request->data = mojo::Array<uint8_t>::From(data); 766 message_request->data = mojo::Array<uint8_t>::From(data);
758 service_ptr_->SendSessionMessage( 767 service_ptr_->SendSessionMessage(
759 std::move(session), std::move(message_request), 768 std::move(session), std::move(message_request),
760 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, 769 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
761 base::Unretained(this))); 770 base::Unretained(this)));
762 771
763 base::RunLoop run_loop; 772 base::RunLoop run_loop;
764 base::Callback<void(bool)> send_message_cb; 773 base::Callback<void(bool)> send_message_cb;
765 PresentationSessionMessage* test_message = nullptr; 774 PresentationSessionMessage* test_message = nullptr;
766 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) 775 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
767 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 776 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
768 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb))); 777 SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
769 run_loop.Run(); 778 run_loop.Run();
770 779
771 EXPECT_FALSE(test_message); 780 EXPECT_FALSE(test_message);
772 send_message_cb.Run(true); 781 send_message_cb.Run(true);
773 SaveQuitClosureAndRunLoop(); 782 SaveQuitClosureAndRunLoop();
774 } 783 }
775 784
776 TEST_F(PresentationServiceImplTest, SendBlobData) { 785 TEST_F(PresentationServiceImplTest, SendBlobData) {
777 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; 786 const uint8_t buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
778 std::vector<uint8_t> data; 787 std::vector<uint8_t> data;
779 data.assign(buffer, buffer + sizeof(buffer)); 788 data.assign(buffer, buffer + sizeof(buffer));
780 789
781 mojom::PresentationSessionInfoPtr session( 790 blink::mojom::PresentationSessionInfoPtr session(
782 mojom::PresentationSessionInfo::New()); 791 blink::mojom::PresentationSessionInfo::New());
783 session->url = kPresentationUrl; 792 session->url = kPresentationUrl;
784 session->id = kPresentationId; 793 session->id = kPresentationId;
785 mojom::SessionMessagePtr message_request(mojom::SessionMessage::New()); 794 blink::mojom::SessionMessagePtr message_request(
786 message_request->type = mojom::PresentationMessageType::BLOB; 795 blink::mojom::SessionMessage::New());
796 message_request->type = blink::mojom::PresentationMessageType::BLOB;
787 message_request->data = mojo::Array<uint8_t>::From(data); 797 message_request->data = mojo::Array<uint8_t>::From(data);
788 service_ptr_->SendSessionMessage( 798 service_ptr_->SendSessionMessage(
789 std::move(session), std::move(message_request), 799 std::move(session), std::move(message_request),
790 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback, 800 base::Bind(&PresentationServiceImplTest::ExpectSendMessageMojoCallback,
791 base::Unretained(this))); 801 base::Unretained(this)));
792 802
793 base::RunLoop run_loop; 803 base::RunLoop run_loop;
794 base::Callback<void(bool)> send_message_cb; 804 base::Callback<void(bool)> send_message_cb;
795 PresentationSessionMessage* test_message = nullptr; 805 PresentationSessionMessage* test_message = nullptr;
796 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _)) 806 EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 mock_delegate_.set_screen_availability_listening_supported(false); 850 mock_delegate_.set_screen_availability_listening_supported(false);
841 base::RunLoop run_loop; 851 base::RunLoop run_loop;
842 EXPECT_CALL(mock_client_, 852 EXPECT_CALL(mock_client_,
843 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))) 853 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl)))
844 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 854 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
845 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); 855 ListenForScreenAvailabilityAndWait(kPresentationUrl, false);
846 run_loop.Run(); 856 run_loop.Run();
847 } 857 }
848 858
849 } // 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