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

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 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(connection,
475 content::PRESENTATION_CONNECTION_STATE_CLOSED);
476 run_loop.Run();
477 }
478
455 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { 479 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) {
456 EXPECT_CALL(mock_delegate_, 480 EXPECT_CALL(mock_delegate_,
457 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) 481 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _))
458 .Times(1); 482 .Times(1);
459 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 483 service_impl_->SetDefaultPresentationURL(kPresentationUrl);
460 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 484 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
461 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); 485 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
462 486
463 // Same URL as before; no-ops. 487 // Same URL as before; no-ops.
464 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 488 service_impl_->SetDefaultPresentationURL(kPresentationUrl);
465 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 489 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
466 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); 490 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
467 } 491 }
468 492
469 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { 493 TEST_F(PresentationServiceImplTest, StartSessionSuccess) {
470 service_ptr_->StartSession( 494 service_ptr_->StartSession(
471 kPresentationUrl, 495 kPresentationUrl,
472 base::Bind( 496 base::Bind(
473 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, 497 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
474 base::Unretained(this))); 498 base::Unretained(this)));
475 base::RunLoop run_loop; 499 base::RunLoop run_loop;
476 base::Callback<void(const PresentationSessionInfo&)> success_cb; 500 base::Callback<void(const PresentationSessionInfo&)> success_cb;
477 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _)) 501 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(kPresentationUrl), _, _))
478 .WillOnce(DoAll( 502 .WillOnce(DoAll(
479 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 503 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
480 SaveArg<3>(&success_cb))); 504 SaveArg<3>(&success_cb)));
481 run_loop.Run(); 505 run_loop.Run();
506
507 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
508 .Times(1);
482 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); 509 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId));
483 SaveQuitClosureAndRunLoop(); 510 SaveQuitClosureAndRunLoop();
484 } 511 }
485 512
486 TEST_F(PresentationServiceImplTest, StartSessionError) { 513 TEST_F(PresentationServiceImplTest, StartSessionError) {
487 service_ptr_->StartSession( 514 service_ptr_->StartSession(
488 kPresentationUrl, 515 kPresentationUrl,
489 base::Bind( 516 base::Bind(
490 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 517 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
491 base::Unretained(this))); 518 base::Unretained(this)));
(...skipping 16 matching lines...) Expand all
508 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, 535 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
509 base::Unretained(this))); 536 base::Unretained(this)));
510 base::RunLoop run_loop; 537 base::RunLoop run_loop;
511 base::Callback<void(const PresentationSessionInfo&)> success_cb; 538 base::Callback<void(const PresentationSessionInfo&)> success_cb;
512 EXPECT_CALL(mock_delegate_, JoinSession( 539 EXPECT_CALL(mock_delegate_, JoinSession(
513 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _)) 540 _, _, Eq(kPresentationUrl), Eq(kPresentationId), _, _))
514 .WillOnce(DoAll( 541 .WillOnce(DoAll(
515 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 542 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
516 SaveArg<4>(&success_cb))); 543 SaveArg<4>(&success_cb)));
517 run_loop.Run(); 544 run_loop.Run();
545
546 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
547 .Times(1);
518 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId)); 548 success_cb.Run(PresentationSessionInfo(kPresentationUrl, kPresentationId));
519 SaveQuitClosureAndRunLoop(); 549 SaveQuitClosureAndRunLoop();
520 } 550 }
521 551
522 TEST_F(PresentationServiceImplTest, JoinSessionError) { 552 TEST_F(PresentationServiceImplTest, JoinSessionError) {
523 service_ptr_->JoinSession( 553 service_ptr_->JoinSession(
524 kPresentationUrl, 554 kPresentationUrl,
525 kPresentationId, 555 kPresentationId,
526 base::Bind( 556 base::Bind(
527 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 557 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 590
561 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) { 591 TEST_F(PresentationServiceImplTest, ListenForSessionMessagesWithEmptyMsg) {
562 std::string text_msg(""); 592 std::string text_msg("");
563 std::vector<uint8_t> binary_data; 593 std::vector<uint8_t> binary_data;
564 RunListenForSessionMessages(text_msg, binary_data, false); 594 RunListenForSessionMessages(text_msg, binary_data, false);
565 } 595 }
566 596
567 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 597 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
568 std::string presentation_url1("http://fooUrl"); 598 std::string presentation_url1("http://fooUrl");
569 std::string presentation_url2("http://barUrl"); 599 std::string presentation_url2("http://barUrl");
600 EXPECT_CALL(mock_delegate_, StartSession(_, _, Eq(presentation_url1), _, _))
601 .Times(1);
570 service_ptr_->StartSession(presentation_url1, 602 service_ptr_->StartSession(presentation_url1,
571 base::Bind(&DoNothing)); 603 base::Bind(&DoNothing));
604
572 // This request should fail immediately, since there is already a StartSession 605 // This request should fail immediately, since there is already a StartSession
573 // in progress. 606 // in progress.
574 service_ptr_->StartSession( 607 service_ptr_->StartSession(
575 presentation_url2, 608 presentation_url2,
576 base::Bind( 609 base::Bind(
577 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 610 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
578 base::Unretained(this))); 611 base::Unretained(this)));
579 SaveQuitClosureAndRunLoop(); 612 SaveQuitClosureAndRunLoop();
580 } 613 }
581 614
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 // Exceeded maximum queue size, should invoke mojo callback with error. 784 // Exceeded maximum queue size, should invoke mojo callback with error.
752 service_ptr_->JoinSession( 785 service_ptr_->JoinSession(
753 base::StringPrintf(presentation_url, i), 786 base::StringPrintf(presentation_url, i),
754 base::StringPrintf(presentation_id, i), 787 base::StringPrintf(presentation_id, i),
755 base::Bind( 788 base::Bind(
756 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 789 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
757 base::Unretained(this))); 790 base::Unretained(this)));
758 SaveQuitClosureAndRunLoop(); 791 SaveQuitClosureAndRunLoop();
759 } 792 }
760 793
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) { 794 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) {
782 mock_delegate_.set_screen_availability_listening_supported(false); 795 mock_delegate_.set_screen_availability_listening_supported(false);
783 EXPECT_CALL(mock_client_, 796 EXPECT_CALL(mock_client_,
784 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))); 797 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl)));
785 798
786 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); 799 ListenForScreenAvailabilityAndWait(kPresentationUrl, false);
787 } 800 }
788 801
789 } // namespace content 802 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698