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

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

Issue 1141683002: [Presentation API] Limit the number of pending Start/JoinSession (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Anton's comments 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_service_delegate.h" 10 #include "content/public/browser/presentation_service_delegate.h"
(...skipping 25 matching lines...) Expand all
36 bool ArePresentationSessionMessagesEqual( 36 bool ArePresentationSessionMessagesEqual(
37 const presentation::SessionMessage* expected, 37 const presentation::SessionMessage* expected,
38 const presentation::SessionMessage* actual) { 38 const presentation::SessionMessage* actual) {
39 return expected->presentation_url == actual->presentation_url && 39 return expected->presentation_url == actual->presentation_url &&
40 expected->presentation_id == actual->presentation_id && 40 expected->presentation_id == actual->presentation_id &&
41 expected->type == actual->type && 41 expected->type == actual->type &&
42 expected->message == actual->message && 42 expected->message == actual->message &&
43 expected->data.Equals(actual->data); 43 expected->data.Equals(actual->data);
44 } 44 }
45 45
46 void DoNothing(
47 presentation::PresentationSessionInfoPtr info,
48 presentation::PresentationErrorPtr error) {
49 }
50
46 } // namespace 51 } // namespace
47 52
48 class MockPresentationServiceDelegate : public PresentationServiceDelegate { 53 class MockPresentationServiceDelegate : public PresentationServiceDelegate {
49 public: 54 public:
50 MOCK_METHOD3(AddObserver, 55 MOCK_METHOD3(AddObserver,
51 void(int render_process_id, 56 void(int render_process_id,
52 int render_frame_id, 57 int render_frame_id,
53 PresentationServiceDelegate::Observer* observer)); 58 PresentationServiceDelegate::Observer* observer));
54 MOCK_METHOD2(RemoveObserver, 59 MOCK_METHOD2(RemoveObserver,
55 void(int render_process_id, int render_frame_id)); 60 void(int render_process_id, int render_frame_id));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 }; 122 };
118 123
119 class MockPresentationServiceClient : 124 class MockPresentationServiceClient :
120 public presentation::PresentationServiceClient { 125 public presentation::PresentationServiceClient {
121 public: 126 public:
122 MOCK_METHOD1(OnScreenAvailabilityUpdated, void(bool available)); 127 MOCK_METHOD1(OnScreenAvailabilityUpdated, void(bool available));
123 }; 128 };
124 129
125 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 130 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
126 public: 131 public:
127 PresentationServiceImplTest() 132 PresentationServiceImplTest() : default_session_started_count_(0) {}
128 : default_session_started_count_(0) {}
129 133
130 void SetUp() override { 134 void SetUp() override {
131 RenderViewHostImplTestHarness::SetUp(); 135 RenderViewHostImplTestHarness::SetUp();
132 136
133 auto request = mojo::GetProxy(&service_ptr_); 137 auto request = mojo::GetProxy(&service_ptr_);
134 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); 138 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1);
135 service_impl_.reset(new PresentationServiceImpl( 139 service_impl_.reset(new PresentationServiceImpl(
136 contents()->GetMainFrame(), contents(), &mock_delegate_)); 140 contents()->GetMainFrame(), contents(), &mock_delegate_));
137 service_impl_->Bind(request.Pass()); 141 service_impl_->Bind(request.Pass());
138 142
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 781 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
778 SaveArg<2>(&test_message), 782 SaveArg<2>(&test_message),
779 SaveArg<3>(&send_message_cb))); 783 SaveArg<3>(&send_message_cb)));
780 run_loop.Run(); 784 run_loop.Run();
781 785
782 EXPECT_FALSE(test_message); 786 EXPECT_FALSE(test_message);
783 send_message_cb.Run(); 787 send_message_cb.Run();
784 SaveQuitClosureAndRunLoop(); 788 SaveQuitClosureAndRunLoop();
785 } 789 }
786 790
791 TEST_F(PresentationServiceImplTest, MaxPendingStartSessionRequests) {
792 const char* presentation_url = "http://fooUrl%d";
793 const char* presentation_id = "presentationId%d";
794 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests + 1;
795 int i = 0;
796 // First request will be processed. The subsequent
797 // |kMaxNumQueuedSessionRequests| requests will be queued.
798 EXPECT_CALL(mock_delegate_, StartSession(_, _, _, _, _, _)).Times(1);
799 for (; i < num_requests; ++i) {
800 service_ptr_->StartSession(
801 base::StringPrintf(presentation_url, i),
802 base::StringPrintf(presentation_id, i),
803 base::Bind(&DoNothing));
804 }
805
806 // Exceeded maximum queue size, should invoke mojo callback with error.
807 service_ptr_->StartSession(
808 base::StringPrintf(presentation_url, i),
809 base::StringPrintf(presentation_id, i),
810 base::Bind(
811 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
812 base::Unretained(this)));
813 SaveQuitClosureAndRunLoop();
814 }
815
816 TEST_F(PresentationServiceImplTest, MaxPendingJoinSessionRequests) {
817 const char* presentation_url = "http://fooUrl%d";
818 const char* presentation_id = "presentationId%d";
819 int num_requests = PresentationServiceImpl::kMaxNumQueuedSessionRequests;
820 int i = 0;
821 EXPECT_CALL(mock_delegate_, JoinSession(_, _, _, _, _, _))
822 .Times(num_requests);
823 for (; i < num_requests; ++i) {
824 service_ptr_->JoinSession(
825 base::StringPrintf(presentation_url, i),
826 base::StringPrintf(presentation_id, i),
827 base::Bind(&DoNothing));
828 }
829
830 // Exceeded maximum queue size, should invoke mojo callback with error.
831 service_ptr_->JoinSession(
832 base::StringPrintf(presentation_url, i),
833 base::StringPrintf(presentation_id, i),
834 base::Bind(
835 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
836 base::Unretained(this)));
837 SaveQuitClosureAndRunLoop();
838 }
839
787 } // namespace content 840 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698