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

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

Issue 1037483003: [PresentationAPI] Implementing send() from WebPresentationClient to the PresentationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved presentation_message.h/.cc to content/public/browser/ Created 5 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "content/browser/presentation/presentation_service_impl.h" 9 #include "content/browser/presentation/presentation_service_impl.h"
10 #include "content/public/browser/presentation_message.h"
10 #include "content/public/browser/presentation_service_delegate.h" 11 #include "content/public/browser/presentation_service_delegate.h"
11 #include "content/public/browser/presentation_session.h" 12 #include "content/public/browser/presentation_session.h"
12 #include "content/test/test_render_frame_host.h" 13 #include "content/test/test_render_frame_host.h"
13 #include "content/test/test_render_view_host.h" 14 #include "content/test/test_render_view_host.h"
14 #include "content/test/test_web_contents.h" 15 #include "content/test/test_web_contents.h"
15 #include "mojo/public/cpp/bindings/interface_ptr.h" 16 #include "mojo/public/cpp/bindings/interface_ptr.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 18
18 using ::testing::_; 19 using ::testing::_;
19 using ::testing::Eq; 20 using ::testing::Eq;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const PresentationSessionSuccessCallback& success_cb, 71 const PresentationSessionSuccessCallback& success_cb,
71 const PresentationSessionErrorCallback& error_cb)); 72 const PresentationSessionErrorCallback& error_cb));
72 MOCK_METHOD6(JoinSession, 73 MOCK_METHOD6(JoinSession,
73 void( 74 void(
74 int render_process_id, 75 int render_process_id,
75 int render_frame_id, 76 int render_frame_id,
76 const std::string& presentation_url, 77 const std::string& presentation_url,
77 const std::string& presentation_id, 78 const std::string& presentation_id,
78 const PresentationSessionSuccessCallback& success_cb, 79 const PresentationSessionSuccessCallback& success_cb,
79 const PresentationSessionErrorCallback& error_cb)); 80 const PresentationSessionErrorCallback& error_cb));
81 MOCK_METHOD4(SendMessage,
82 void(
83 int render_process_id,
84 int render_frame_id,
85 PresentationMessageRequest* message_request,
86 const SendMessageCallback& send_message_cb));
80 }; 87 };
81 88
82 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 89 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
83 public: 90 public:
84 PresentationServiceImplTest() 91 PresentationServiceImplTest()
85 : callback_count_(0), default_session_started_count_(0) {} 92 : callback_count_(0), default_session_started_count_(0) {}
86 93
87 void SetUp() override { 94 void SetUp() override {
88 RenderViewHostImplTestHarness::SetUp(); 95 RenderViewHostImplTestHarness::SetUp();
89 96
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 215 }
209 216
210 void ExpectDefaultSessionNull( 217 void ExpectDefaultSessionNull(
211 presentation::PresentationSessionInfoPtr actual_session) { 218 presentation::PresentationSessionInfoPtr actual_session) {
212 EXPECT_TRUE(actual_session.is_null()); 219 EXPECT_TRUE(actual_session.is_null());
213 ++default_session_started_count_; 220 ++default_session_started_count_;
214 if (!run_loop_quit_closure_.is_null()) 221 if (!run_loop_quit_closure_.is_null())
215 run_loop_quit_closure_.Run(); 222 run_loop_quit_closure_.Run();
216 } 223 }
217 224
225 void ExpectSendMessageMojoCallback(bool success) {
226 EXPECT_EQ(success, true);
imcheng (use chromium acct) 2015/04/30 20:11:29 EXPECT_TRUE(success)
USE s.singapati at gmail.com 2015/05/04 16:40:28 Done.
227 EXPECT_FALSE(service_impl_->send_message_cb_ptr_);
228 if (!run_loop_quit_closure_.is_null())
229 run_loop_quit_closure_.Run();
230 }
231
218 MockPresentationServiceDelegate mock_delegate_; 232 MockPresentationServiceDelegate mock_delegate_;
219 scoped_ptr<PresentationServiceImpl> service_impl_; 233 scoped_ptr<PresentationServiceImpl> service_impl_;
220 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; 234 mojo::InterfacePtr<presentation::PresentationService> service_ptr_;
221 base::Closure run_loop_quit_closure_; 235 base::Closure run_loop_quit_closure_;
222 int callback_count_; 236 int callback_count_;
223 int default_session_started_count_; 237 int default_session_started_count_;
224 }; 238 };
225 239
226 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { 240 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) {
227 std::string presentation_url("http://fooUrl"); 241 std::string presentation_url("http://fooUrl");
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 base::Unretained(this))); 675 base::Unretained(this)));
662 RunLoopFor(TestTimeouts::tiny_timeout()); 676 RunLoopFor(TestTimeouts::tiny_timeout());
663 677
664 ExpectReset(); 678 ExpectReset();
665 service_impl_->Reset(); 679 service_impl_->Reset();
666 ExpectCleanState(); 680 ExpectCleanState();
667 SaveQuitClosureAndRunLoop(); 681 SaveQuitClosureAndRunLoop();
668 EXPECT_EQ(1, default_session_started_count_); 682 EXPECT_EQ(1, default_session_started_count_);
669 } 683 }
670 684
685 TEST_F(PresentationServiceImplTest, SendStringMessage) {
686 std::string presentation_url("http://fooUrl");
687 std::string presentation_id("presentationId");
688 std::string message("Test presentation session message");
689
690 presentation::SessionMessagePtr message_request(
691 presentation::SessionMessage::New());
692 message_request->presentation_url = presentation_url;
693 message_request->presentation_id = presentation_id;
694 message_request->type = presentation::PresentationMessageType::
695 PRESENTATION_MESSAGE_TYPE_TEXT;
696 message_request->message = message;
697 service_ptr_->SendMessage(
698 message_request.Pass(),
699 base::Bind(
700 &PresentationServiceImplTest::ExpectSendMessageMojoCallback,
701 base::Unretained(this)));
702
703 base::RunLoop run_loop;
704 base::Callback<void()> send_message_cb;
705 PresentationMessageRequest* test_message = nullptr;
imcheng (use chromium acct) 2015/04/30 20:11:29 do we have a memory leak here since the test_messa
USE s.singapati at gmail.com 2015/05/01 10:30:25 yes, delegate is responsible for deleting the Pres
USE s.singapati at gmail.com 2015/05/04 16:40:28 Done. deleting test_message for now. Working on pa
USE s.singapati at gmail.com 2015/05/05 14:26:36 Done. passing scoped_ptr<> to delegate and MOCK Se
706 EXPECT_CALL(mock_delegate_, SendMessage(
707 _, _, _, _))
708 .WillOnce(DoAll(
709 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
710 SaveArg<2>(&test_message),
711 SaveArg<3>(&send_message_cb)));
712 run_loop.Run();
713
714 EXPECT_TRUE(test_message);
715 EXPECT_EQ(presentation_url, test_message->presentation_url);
716 EXPECT_EQ(presentation_id, test_message->presentation_id);
717 EXPECT_EQ(PresentationMessageType::TEXT, test_message->type);
718 EXPECT_EQ(message, test_message->message);
719 EXPECT_EQ(0u, test_message->data.size());
720 send_message_cb.Run();
721 SaveQuitClosureAndRunLoop();
722 }
723
724 TEST_F(PresentationServiceImplTest, SendArrayBuffer) {
725 std::string presentation_url("http://fooUrl");
726 std::string presentation_id("presentationId");
727 // Test Array buffer data.
728 const uint8 buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
729 std::vector<uint8> data;
730 data.assign(buffer, buffer + sizeof(buffer));
731
732 presentation::SessionMessagePtr message_request(
733 presentation::SessionMessage::New());
734 message_request->presentation_url = presentation_url;
735 message_request->presentation_id = presentation_id;
736 message_request->type = presentation::PresentationMessageType::
737 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
738 message_request->data = mojo::Array<uint8>::From(data);
739 service_ptr_->SendMessage(
740 message_request.Pass(),
741 base::Bind(
742 &PresentationServiceImplTest::ExpectSendMessageMojoCallback,
743 base::Unretained(this)));
744
745 base::RunLoop run_loop;
746 base::Callback<void()> send_message_cb;
747 PresentationMessageRequest* test_message = nullptr;
imcheng (use chromium acct) 2015/04/30 20:11:29 ditto on memory leak
USE s.singapati at gmail.com 2015/05/04 16:40:28 Done. deleting test_message for now. Working on pa
USE s.singapati at gmail.com 2015/05/05 14:26:36 Done.
748 EXPECT_CALL(mock_delegate_, SendMessage(
749 _, _, _, _))
750 .WillOnce(DoAll(
751 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
752 SaveArg<2>(&test_message),
753 SaveArg<3>(&send_message_cb)));
754 run_loop.Run();
755
756 EXPECT_TRUE(test_message);
757 EXPECT_EQ(presentation_url, test_message->presentation_url);
758 EXPECT_EQ(presentation_id, test_message->presentation_id);
759 EXPECT_EQ(PresentationMessageType::ARRAY_BUFFER, test_message->type);
760 EXPECT_EQ(0u, test_message->message.size());
761 EXPECT_EQ(data.size(), test_message->data.size());
762 EXPECT_EQ(0, memcmp(buffer, &test_message->data[0], sizeof(buffer)));
763 send_message_cb.Run();
764 SaveQuitClosureAndRunLoop();
765 }
766
671 } // namespace content 767 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698