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

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

Issue 1436703002: Revert of [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 23 matching lines...) Expand all
34 namespace { 34 namespace {
35 35
36 // Matches mojo structs. 36 // Matches mojo structs.
37 MATCHER_P(Equals, expected, "") { 37 MATCHER_P(Equals, expected, "") {
38 return expected.Equals(arg); 38 return expected.Equals(arg);
39 } 39 }
40 40
41 const char *const kPresentationId = "presentationId"; 41 const char *const kPresentationId = "presentationId";
42 const char *const kPresentationUrl = "http://foo.com/index.html"; 42 const char *const kPresentationUrl = "http://foo.com/index.html";
43 43
44 bool ArePresentationSessionsEqual(
45 const presentation::PresentationSessionInfo& expected,
46 const presentation::PresentationSessionInfo& actual) {
47 return expected.url == actual.url && expected.id == actual.id;
48 }
49
44 bool ArePresentationSessionMessagesEqual( 50 bool ArePresentationSessionMessagesEqual(
45 const presentation::SessionMessage* expected, 51 const presentation::SessionMessage* expected,
46 const presentation::SessionMessage* actual) { 52 const presentation::SessionMessage* actual) {
47 return expected->type == actual->type && 53 return expected->type == actual->type &&
48 expected->message == actual->message && 54 expected->message == actual->message &&
49 expected->data.Equals(actual->data); 55 expected->data.Equals(actual->data);
50 } 56 }
51 57
52 void DoNothing( 58 void DoNothing(
53 presentation::PresentationSessionInfoPtr info, 59 presentation::PresentationSessionInfoPtr info,
(...skipping 24 matching lines...) Expand all
78 84
79 MOCK_METHOD3(RemoveScreenAvailabilityListener, 85 MOCK_METHOD3(RemoveScreenAvailabilityListener,
80 void( 86 void(
81 int render_process_id, 87 int render_process_id,
82 int routing_id, 88 int routing_id,
83 PresentationScreenAvailabilityListener* listener)); 89 PresentationScreenAvailabilityListener* listener));
84 MOCK_METHOD2(Reset, 90 MOCK_METHOD2(Reset,
85 void( 91 void(
86 int render_process_id, 92 int render_process_id,
87 int routing_id)); 93 int routing_id));
88 MOCK_METHOD4(SetDefaultPresentationUrl, 94 MOCK_METHOD3(SetDefaultPresentationUrl,
89 void(int render_process_id, 95 void(
90 int routing_id, 96 int render_process_id,
91 const std::string& default_presentation_url, 97 int routing_id,
92 const PresentationSessionStartedCallback& callback)); 98 const std::string& default_presentation_url));
93 MOCK_METHOD5(StartSession, 99 MOCK_METHOD5(StartSession,
94 void(int render_process_id, 100 void(
95 int render_frame_id, 101 int render_process_id,
96 const std::string& presentation_url, 102 int render_frame_id,
97 const PresentationSessionStartedCallback& success_cb, 103 const std::string& presentation_url,
98 const PresentationSessionErrorCallback& error_cb)); 104 const PresentationSessionSuccessCallback& success_cb,
105 const PresentationSessionErrorCallback& error_cb));
99 MOCK_METHOD6(JoinSession, 106 MOCK_METHOD6(JoinSession,
100 void(int render_process_id, 107 void(
101 int render_frame_id, 108 int render_process_id,
102 const std::string& presentation_url, 109 int render_frame_id,
103 const std::string& presentation_id, 110 const std::string& presentation_url,
104 const PresentationSessionStartedCallback& success_cb, 111 const std::string& presentation_id,
105 const PresentationSessionErrorCallback& error_cb)); 112 const PresentationSessionSuccessCallback& success_cb,
113 const PresentationSessionErrorCallback& error_cb));
106 MOCK_METHOD3(CloseSession, 114 MOCK_METHOD3(CloseSession,
107 void(int render_process_id, 115 void(int render_process_id,
108 int render_frame_id, 116 int render_frame_id,
109 const std::string& presentation_id)); 117 const std::string& presentation_id));
110 MOCK_METHOD4(ListenForSessionMessages, 118 MOCK_METHOD4(ListenForSessionMessages,
111 void(int render_process_id, 119 void(int render_process_id,
112 int render_frame_id, 120 int render_frame_id,
113 const content::PresentationSessionInfo& session, 121 const content::PresentationSessionInfo& session,
114 const PresentationSessionMessageCallback& message_cb)); 122 const PresentationSessionMessageCallback& message_cb));
115 MOCK_METHOD5(SendMessageRawPtr, 123 MOCK_METHOD5(SendMessageRawPtr,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url)); 165 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url));
158 166
159 void OnSessionMessagesReceived( 167 void OnSessionMessagesReceived(
160 presentation::PresentationSessionInfoPtr session_info, 168 presentation::PresentationSessionInfoPtr session_info,
161 mojo::Array<presentation::SessionMessagePtr> messages) override { 169 mojo::Array<presentation::SessionMessagePtr> messages) override {
162 messages_received_ = messages.Pass(); 170 messages_received_ = messages.Pass();
163 MessagesReceived(); 171 MessagesReceived();
164 } 172 }
165 MOCK_METHOD0(MessagesReceived, void()); 173 MOCK_METHOD0(MessagesReceived, void());
166 174
167 void OnDefaultSessionStarted(
168 presentation::PresentationSessionInfoPtr session_info) override {
169 OnDefaultSessionStarted(*session_info);
170 }
171 MOCK_METHOD1(OnDefaultSessionStarted,
172 void(const presentation::PresentationSessionInfo& session_info));
173
174 mojo::Array<presentation::SessionMessagePtr> messages_received_; 175 mojo::Array<presentation::SessionMessagePtr> messages_received_;
175 }; 176 };
176 177
177 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 178 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
178 public: 179 public:
179 PresentationServiceImplTest() : default_session_started_count_(0) {} 180 PresentationServiceImplTest() : default_session_started_count_(0) {}
180 181
181 void SetUp() override { 182 void SetUp() override {
182 RenderViewHostImplTestHarness::SetUp(); 183 RenderViewHostImplTestHarness::SetUp();
183 184
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 250
250 void ExpectReset() { 251 void ExpectReset() {
251 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); 252 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1);
252 } 253 }
253 254
254 void ExpectCleanState() { 255 void ExpectCleanState() {
255 EXPECT_TRUE(service_impl_->default_presentation_url_.empty()); 256 EXPECT_TRUE(service_impl_->default_presentation_url_.empty());
256 EXPECT_EQ( 257 EXPECT_EQ(
257 service_impl_->screen_availability_listeners_.find(kPresentationUrl), 258 service_impl_->screen_availability_listeners_.find(kPresentationUrl),
258 service_impl_->screen_availability_listeners_.end()); 259 service_impl_->screen_availability_listeners_.end());
260 EXPECT_FALSE(service_impl_->default_session_start_context_.get());
259 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); 261 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get());
260 } 262 }
261 263
262 void ExpectNewSessionMojoCallbackSuccess( 264 void ExpectNewSessionMojoCallbackSuccess(
263 presentation::PresentationSessionInfoPtr info, 265 presentation::PresentationSessionInfoPtr info,
264 presentation::PresentationErrorPtr error) { 266 presentation::PresentationErrorPtr error) {
265 EXPECT_FALSE(info.is_null()); 267 EXPECT_FALSE(info.is_null());
266 EXPECT_TRUE(error.is_null()); 268 EXPECT_TRUE(error.is_null());
267 if (!run_loop_quit_closure_.is_null()) 269 if (!run_loop_quit_closure_.is_null())
268 run_loop_quit_closure_.Run(); 270 run_loop_quit_closure_.Run();
269 } 271 }
270 272
271 void ExpectNewSessionMojoCallbackError( 273 void ExpectNewSessionMojoCallbackError(
272 presentation::PresentationSessionInfoPtr info, 274 presentation::PresentationSessionInfoPtr info,
273 presentation::PresentationErrorPtr error) { 275 presentation::PresentationErrorPtr error) {
274 EXPECT_TRUE(info.is_null()); 276 EXPECT_TRUE(info.is_null());
275 EXPECT_FALSE(error.is_null()); 277 EXPECT_FALSE(error.is_null());
276 if (!run_loop_quit_closure_.is_null()) 278 if (!run_loop_quit_closure_.is_null())
277 run_loop_quit_closure_.Run(); 279 run_loop_quit_closure_.Run();
278 } 280 }
281
282 void ExpectDefaultSessionStarted(
283 const presentation::PresentationSessionInfo& expected_session,
284 presentation::PresentationSessionInfoPtr actual_session) {
285 ASSERT_TRUE(!actual_session.is_null());
286 EXPECT_TRUE(ArePresentationSessionsEqual(
287 expected_session, *actual_session));
288 ++default_session_started_count_;
289 if (!run_loop_quit_closure_.is_null())
290 run_loop_quit_closure_.Run();
291 }
292
293 void ExpectDefaultSessionNull(
294 presentation::PresentationSessionInfoPtr actual_session) {
295 EXPECT_TRUE(actual_session.is_null());
296 ++default_session_started_count_;
297 if (!run_loop_quit_closure_.is_null())
298 run_loop_quit_closure_.Run();
299 }
279 300
280 void ExpectSessionMessages( 301 void ExpectSessionMessages(
281 const mojo::Array<presentation::SessionMessagePtr>& expected_msgs, 302 const mojo::Array<presentation::SessionMessagePtr>& expected_msgs,
282 const mojo::Array<presentation::SessionMessagePtr>& actual_msgs) { 303 const mojo::Array<presentation::SessionMessagePtr>& actual_msgs) {
283 EXPECT_EQ(expected_msgs.size(), actual_msgs.size()); 304 EXPECT_EQ(expected_msgs.size(), actual_msgs.size());
284 for (size_t i = 0; i < actual_msgs.size(); ++i) { 305 for (size_t i = 0; i < actual_msgs.size(); ++i) {
285 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs[i].get(), 306 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs[i].get(),
286 actual_msgs[i].get())); 307 actual_msgs[i].get()));
287 } 308 }
288 } 309 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 443
423 TEST_F(PresentationServiceImplTest, DelegateFails) { 444 TEST_F(PresentationServiceImplTest, DelegateFails) {
424 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); 445 ListenForScreenAvailabilityAndWait(kPresentationUrl, false);
425 ASSERT_EQ( 446 ASSERT_EQ(
426 service_impl_->screen_availability_listeners_.find(kPresentationUrl), 447 service_impl_->screen_availability_listeners_.find(kPresentationUrl),
427 service_impl_->screen_availability_listeners_.end()); 448 service_impl_->screen_availability_listeners_.end());
428 } 449 }
429 450
430 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) { 451 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) {
431 std::string url1("http://fooUrl"); 452 std::string url1("http://fooUrl");
432 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url1), _)) 453 EXPECT_CALL(mock_delegate_,
454 SetDefaultPresentationUrl(_, _, Eq(url1)))
433 .Times(1); 455 .Times(1);
434 service_impl_->SetDefaultPresentationURL(url1); 456 service_impl_->SetDefaultPresentationURL(url1);
435 EXPECT_EQ(url1, service_impl_->default_presentation_url_); 457 EXPECT_EQ(url1, service_impl_->default_presentation_url_);
436 458
437 std::string url2("http://barUrl"); 459 std::string url2("http://barUrl");
438 // Sets different DPU. 460 // Sets different DPU.
439 content::PresentationSessionStartedCallback callback; 461 EXPECT_CALL(mock_delegate_,
440 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrl(_, _, Eq(url2), _)) 462 SetDefaultPresentationUrl(_, _, Eq(url2)))
441 .WillOnce(SaveArg<3>(&callback)); 463 .Times(1);
442 service_impl_->SetDefaultPresentationURL(url2); 464 service_impl_->SetDefaultPresentationURL(url2);
443 EXPECT_EQ(url2, service_impl_->default_presentation_url_); 465 EXPECT_EQ(url2, service_impl_->default_presentation_url_);
444
445 presentation::PresentationSessionInfo session_info;
446 session_info.url = url2;
447 session_info.id = kPresentationId;
448 EXPECT_CALL(mock_client_, OnDefaultSessionStarted(Equals(session_info)))
449 .Times(1);
450 callback.Run(content::PresentationSessionInfo(url2, kPresentationId));
451 } 466 }
452 467
453 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { 468 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) {
454 EXPECT_CALL(mock_delegate_, 469 EXPECT_CALL(mock_delegate_,
455 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl), _)) 470 SetDefaultPresentationUrl(_, _, Eq(kPresentationUrl)))
456 .Times(1); 471 .Times(1);
457 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 472 service_impl_->SetDefaultPresentationURL(kPresentationUrl);
458 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 473 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
459 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); 474 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
460 475
461 // Same URL as before; no-ops. 476 // Same URL as before; no-ops.
462 service_impl_->SetDefaultPresentationURL(kPresentationUrl); 477 service_impl_->SetDefaultPresentationURL(kPresentationUrl);
463 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 478 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
464 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_); 479 EXPECT_EQ(kPresentationUrl, service_impl_->default_presentation_url_);
465 } 480 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 // This request should fail immediately, since there is already a StartSession 585 // This request should fail immediately, since there is already a StartSession
571 // in progress. 586 // in progress.
572 service_ptr_->StartSession( 587 service_ptr_->StartSession(
573 presentation_url2, 588 presentation_url2,
574 base::Bind( 589 base::Bind(
575 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError, 590 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
576 base::Unretained(this))); 591 base::Unretained(this)));
577 SaveQuitClosureAndRunLoop(); 592 SaveQuitClosureAndRunLoop();
578 } 593 }
579 594
595 TEST_F(PresentationServiceImplTest, ListenForDefaultSessionStart) {
596 presentation::PresentationSessionInfo expected_session;
597 expected_session.url = kPresentationUrl;
598 expected_session.id = kPresentationId;
599 service_ptr_->ListenForDefaultSessionStart(
600 base::Bind(&PresentationServiceImplTest::ExpectDefaultSessionStarted,
601 base::Unretained(this),
602 expected_session));
603 RunLoopFor(base::TimeDelta::FromMilliseconds(50));
604 service_impl_->OnDefaultPresentationStarted(
605 content::PresentationSessionInfo(kPresentationUrl, kPresentationId));
606 SaveQuitClosureAndRunLoop();
607 EXPECT_EQ(1, default_session_started_count_);
608 }
609
610 TEST_F(PresentationServiceImplTest, ListenForDefaultSessionStartAfterSet) {
611 // Note that the callback will only pick up presentation_url2/id2 since
612 // ListenForDefaultSessionStart wasn't called yet when the DPU was still
613 // presentation_url1.
614 std::string presentation_url1("http://fooUrl1");
615 std::string presentation_id1("presentationId1");
616 std::string presentation_url2("http://fooUrl2");
617 std::string presentation_id2("presentationId2");
618 service_impl_->OnDefaultPresentationStarted(
619 content::PresentationSessionInfo(presentation_url1, presentation_id1));
620
621 presentation::PresentationSessionInfo expected_session;
622 expected_session.url = presentation_url2;
623 expected_session.id = presentation_id2;
624 service_ptr_->ListenForDefaultSessionStart(
625 base::Bind(&PresentationServiceImplTest::ExpectDefaultSessionStarted,
626 base::Unretained(this),
627 expected_session));
628 RunLoopFor(base::TimeDelta::FromMilliseconds(50));
629 service_impl_->OnDefaultPresentationStarted(
630 content::PresentationSessionInfo(presentation_url2, presentation_id2));
631 SaveQuitClosureAndRunLoop();
632 EXPECT_EQ(1, default_session_started_count_);
633 }
634
635 TEST_F(PresentationServiceImplTest, DefaultSessionStartReset) {
636 service_ptr_->ListenForDefaultSessionStart(
637 base::Bind(&PresentationServiceImplTest::ExpectDefaultSessionNull,
638 base::Unretained(this)));
639 RunLoopFor(TestTimeouts::tiny_timeout());
640
641 ExpectReset();
642 service_impl_->Reset();
643 ExpectCleanState();
644 SaveQuitClosureAndRunLoop();
645 EXPECT_EQ(1, default_session_started_count_);
646 }
647
580 TEST_F(PresentationServiceImplTest, SendStringMessage) { 648 TEST_F(PresentationServiceImplTest, SendStringMessage) {
581 std::string message("Test presentation session message"); 649 std::string message("Test presentation session message");
582 650
583 presentation::PresentationSessionInfoPtr session( 651 presentation::PresentationSessionInfoPtr session(
584 presentation::PresentationSessionInfo::New()); 652 presentation::PresentationSessionInfo::New());
585 session->url = kPresentationUrl; 653 session->url = kPresentationUrl;
586 session->id = kPresentationId; 654 session->id = kPresentationId;
587 presentation::SessionMessagePtr message_request( 655 presentation::SessionMessagePtr message_request(
588 presentation::SessionMessage::New()); 656 presentation::SessionMessage::New());
589 message_request->type = presentation::PresentationMessageType:: 657 message_request->type = presentation::PresentationMessageType::
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 846
779 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { 847 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) {
780 mock_delegate_.set_screen_availability_listening_supported(false); 848 mock_delegate_.set_screen_availability_listening_supported(false);
781 EXPECT_CALL(mock_client_, 849 EXPECT_CALL(mock_client_,
782 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl))); 850 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl)));
783 851
784 ListenForScreenAvailabilityAndWait(kPresentationUrl, false); 852 ListenForScreenAvailabilityAndWait(kPresentationUrl, false);
785 } 853 }
786 854
787 } // namespace content 855 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/presentation/presentation_service_impl.cc ('k') | content/common/presentation/presentation_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698