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

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

Issue 1430413003: [Media Router] Connection state change listening redesign part 2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix content_unittests compile Created 5 years, 1 month 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 PresentationSessionMessage* message_request, 119 PresentationSessionMessage* message_request,
120 const SendMessageCallback& send_message_cb)); 120 const SendMessageCallback& send_message_cb));
121 void SendMessage(int render_process_id, 121 void SendMessage(int render_process_id,
122 int render_frame_id, 122 int render_frame_id,
123 const content::PresentationSessionInfo& session, 123 const content::PresentationSessionInfo& session,
124 scoped_ptr<PresentationSessionMessage> message_request, 124 scoped_ptr<PresentationSessionMessage> message_request,
125 const SendMessageCallback& send_message_cb) override { 125 const SendMessageCallback& send_message_cb) override {
126 SendMessageRawPtr(render_process_id, render_frame_id, session, 126 SendMessageRawPtr(render_process_id, render_frame_id, session,
127 message_request.release(), send_message_cb); 127 message_request.release(), send_message_cb);
128 } 128 }
129 MOCK_METHOD3( 129 MOCK_METHOD4(ListenForConnectionStateChange,
130 ListenForSessionStateChange, 130 void(int render_process_id,
131 void(int render_process_id, 131 int render_frame_id,
132 int render_frame_id, 132 const content::PresentationSessionInfo& connection,
133 const content::SessionStateChangedCallback& state_changed_cb)); 133 const content::PresentationConnectionStateChangedCallback&
134 state_changed_cb));
134 135
135 void set_screen_availability_listening_supported(bool value) { 136 void set_screen_availability_listening_supported(bool value) {
136 screen_availability_listening_supported_ = value; 137 screen_availability_listening_supported_ = value;
137 } 138 }
138 139
139 private: 140 private:
140 bool screen_availability_listening_supported_ = true; 141 bool screen_availability_listening_supported_ = true;
141 }; 142 };
142 143
143 class MockPresentationServiceClient : 144 class MockPresentationServiceClient :
144 public presentation::PresentationServiceClient { 145 public presentation::PresentationServiceClient {
145 public: 146 public:
146 MOCK_METHOD2(OnScreenAvailabilityUpdated, 147 MOCK_METHOD2(OnScreenAvailabilityUpdated,
147 void(const mojo::String& url, bool available)); 148 void(const mojo::String& url, bool available));
148 void OnSessionStateChanged( 149 void OnConnectionStateChanged(
149 presentation::PresentationSessionInfoPtr session_info, 150 presentation::PresentationSessionInfoPtr connection,
150 presentation::PresentationConnectionState new_state) override { 151 presentation::PresentationConnectionState new_state) override {
151 OnSessionStateChanged(*session_info, new_state); 152 OnConnectionStateChanged(*connection, new_state);
152 } 153 }
153 MOCK_METHOD2(OnSessionStateChanged, 154 MOCK_METHOD2(OnConnectionStateChanged,
154 void(const presentation::PresentationSessionInfo& session_info, 155 void(const presentation::PresentationSessionInfo& connection,
155 presentation::PresentationConnectionState new_state)); 156 presentation::PresentationConnectionState new_state));
156 157
157 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url)); 158 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url));
158 159
159 void OnSessionMessagesReceived( 160 void OnSessionMessagesReceived(
160 presentation::PresentationSessionInfoPtr session_info, 161 presentation::PresentationSessionInfoPtr session_info,
161 mojo::Array<presentation::SessionMessagePtr> messages) override { 162 mojo::Array<presentation::SessionMessagePtr> messages) override {
162 messages_received_ = messages.Pass(); 163 messages_received_ = messages.Pass();
163 MessagesReceived(); 164 MessagesReceived();
164 } 165 }
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 presentation::PresentationSessionInfo session_info; 446 presentation::PresentationSessionInfo session_info;
446 session_info.url = url2; 447 session_info.url = url2;
447 session_info.id = kPresentationId; 448 session_info.id = kPresentationId;
448 base::RunLoop run_loop; 449 base::RunLoop run_loop;
449 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info))) 450 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info)))
450 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 451 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
451 callback.Run(content::PresentationSessionInfo(url2, kPresentationId)); 452 callback.Run(content::PresentationSessionInfo(url2, kPresentationId));
452 run_loop.Run(); 453 run_loop.Run();
453 } 454 }
454 455
456 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
457 content::PresentationSessionInfo connection(kPresentationUrl,
458 kPresentationId);
459 content::PresentationConnectionStateChangedCallback state_changed_cb;
460 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
461 .WillOnce(SaveArg<3>(&state_changed_cb));
462 service_impl_->ListenForConnectionStateChange(connection);
463
464 // Trigger state change. It should be propagated back up to |mock_client_|.
465 presentation::PresentationSessionInfo presentation_connection;
466 presentation_connection.url = kPresentationUrl;
467 presentation_connection.id = kPresentationId;
468 base::RunLoop run_loop;
469 EXPECT_CALL(mock_client_,
470 OnConnectionStateChanged(
471 Equals(presentation_connection),
472 presentation::PRESENTATION_CONNECTION_STATE_CLOSED))
473 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
474 state_changed_cb.Run(content::PRESENTATION_CONNECTION_STATE_CLOSED);
475 run_loop.Run();
476 }
477
455 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { 478 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) {
456 EXPECT_CALL(mock_delegate_, 479 EXPECT_CALL(mock_delegate_,
457 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) 480 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _))
458 .Times(1); 481 .Times(1);
459 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 482 service_impl_->SetDefaultPresentationURL(kPresentationUrl);
460 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 483 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
461 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); 484 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
462 485
463 // Same URL as before; no-ops. 486 // Same URL as before; no-ops.
464 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 487 service_impl_->SetDefaultPresentationURL(kPresentationUrl);
465 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 488 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
466 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); 489 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
467 } 490 }
468 491
469 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { 492 TEST_F(PresentationServiceImplTest, StartSessionSuccess) {
470 service_ptr_->StartSession( 493 service_ptr_->StartSession(
471 kPresentationUrl, 494 kPresentationUrl,
472 base::Bind( 495 base::Bind(
473 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, 496 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
474 base::Unretained(this))); 497 base::Unretained(this)));
475 base::RunLoop run_loop; 498 base::RunLoop run_loop;
476 base::Callback<void(const PresentationSessionInfo&)> success_cb; 499 base::Callback<void(const PresentationSessionInfo&)> success_cb;
477 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) 500 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _))
478 .WillOnce(DoAll( 501 .WillOnce(DoAll(
479 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 502 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
480 SaveArg<3>(&success_cb))); 503 SaveArg<3>(&success_cb)));
481 run_loop.Run(); 504 run_loop.Run();
505
506 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
507 .Times(1);
482 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); 508 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId));
483 SaveQuitClosureAndRunLoop(); 509 SaveQuitClosureAndRunLoop();
484 } 510 }
485 511
486 TEST_F(PresentationServiceImplTest, StartSessionError) { 512 TEST_F(PresentationServiceImplTest, StartSessionError) {
487 service_ptr_->StartSession( 513 service_ptr_->StartSession(
488 kPresentationUrl, 514 kPresentationUrl,
489 base::Bind( 515 base::Bind(
490 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 516 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
491 base::Unretained(this))); 517 base::Unretained(this)));
(...skipping 16 matching lines...) Expand all
508 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, 534 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
509 base::Unretained(this))); 535 base::Unretained(this)));
510 base::RunLoop run_loop; 536 base::RunLoop run_loop;
511 base::Callback<void(const PresentationSessionInfo&)> success_cb; 537 base::Callback<void(const PresentationSessionInfo&)> success_cb;
512 EXPECT_CALL(mock_delegate_, JoinSession( 538 EXPECT_CALL(mock_delegate_, JoinSession(
513 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) 539 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _))
514 .WillOnce(DoAll( 540 .WillOnce(DoAll(
515 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 541 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
516 SaveArg<4>(&success_cb))); 542 SaveArg<4>(&success_cb)));
517 run_loop.Run(); 543 run_loop.Run();
544
545 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
546 .Times(1);
518 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); 547 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId));
519 SaveQuitClosureAndRunLoop(); 548 SaveQuitClosureAndRunLoop();
520 } 549 }
521 550
522 TEST_F(PresentationServiceImplTest, JoinSessionError) { 551 TEST_F(PresentationServiceImplTest, JoinSessionError) {
523 service_ptr_->JoinSession( 552 service_ptr_->JoinSession(
524 kPresentationUrl, 553 kPresentationUrl,
525 kPresentationId, 554 kPresentationId,
526 base::Bind( 555 base::Bind(
527 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 556 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 589
561 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { 590 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) {
562 std::string text_msg(""); 591 std::string text_msg("");
563 std::vector<uint8_t> binary_data; 592 std::vector<uint8_t> binary_data;
564 RunListenForSessionMessages(text_msg, binary_data, false); 593 RunListenForSessionMessages(text_msg, binary_data, false);
565 } 594 }
566 595
567 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 596 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
568 std::string presentation_url1("http://fooUrl"); 597 std::string presentation_url1("http://fooUrl");
569 std::string presentation_url2("http://barUrl"); 598 std::string presentation_url2("http://barUrl");
599 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(presentation_url1), _, _))
600 .Times(1);
570 service_ptr_->StartSession(presentation_url1, 601 service_ptr_->StartSession(presentation_url1,
571 base::Bind(&DoNothing)); 602 base::Bind(&DoNothing));
603
572 // This request should fail immediately, since there is already a StartSession 604 // This request should fail immediately, since there is already a StartSession
573 // in progress. 605 // in progress.
574 service_ptr_->StartSession( 606 service_ptr_->StartSession(
575 presentation_url2, 607 presentation_url2,
576 base::Bind( 608 base::Bind(
577 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 609 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
578 base::Unretained(this))); 610 base::Unretained(this)));
579 SaveQuitClosureAndRunLoop(); 611 SaveQuitClosureAndRunLoop();
580 } 612 }
581 613
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 // Exceeded maximum queue size, should invoke mojo callback with error. 783 // Exceeded maximum queue size, should invoke mojo callback with error.
752 service_ptr_->JoinSession( 784 service_ptr_->JoinSession(
753 base::StringPrintf(presentation_url, i), 785 base::StringPrintf(presentation_url, i),
754 base::StringPrintf(presentation_id, i), 786 base::StringPrintf(presentation_id, i),
755 base::Bind( 787 base::Bind(
756 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 788 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
757 base::Unretained(this))); 789 base::Unretained(this)));
758 SaveQuitClosureAndRunLoop(); 790 SaveQuitClosureAndRunLoop();
759 } 791 }
760 792
761 TEST_F(PresentationServiceImplTest, ListenForSessionStateChange) {
762 base::RunLoop run_loop;
763 EXPECT_CALL(mock_delegate_, ListenForSessionStateChange(_, _, _))
764 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
765 service_ptr_->ListenForSessionStateChange();
766 run_loop.Run();
767
768 presentation::PresentationSessionInfo session_info;
769 session_info.url = kPresentationUrl;
770 session_info.id = kPresentationId;
771
772 EXPECT_CALL(mock_client_,
773 OnSessionStateChanged(
774 Equals(session_info),
775 presentation::PRESENTATION_CONNECTION_STATE_CONNECTED));
776 service_impl_->OnSessionStateChanged(
777 content::PresentationSessionInfo(kPresentationUrl, kPresentationId),
778 content::PRESENTATION_CONNECTION_STATE_CONNECTED);
779 }
780
781 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { 793 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) {
782 mock_delegate_.set_screen_availability_listening_supported(false); 794 mock_delegate_.set_screen_availability_listening_supported(false);
783 EXPECT_CALL(mock_client_, 795 EXPECT_CALL(mock_client_,
784 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))); 796 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl)));
785 797
786 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); 798 ListenForScreenAvailabilityAndWait(kPresentationUrl, false);
787 } 799 }
788 800
789 } // namespace content 801 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698