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

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

Issue 1376703002: Presentation API: reject screen availability observing on Android low ram devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix and add tests Created 5 years, 2 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 <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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } // namespace 63 } // namespace
64 64
65 class MockPresentationServiceDelegate : public PresentationServiceDelegate { 65 class MockPresentationServiceDelegate : public PresentationServiceDelegate {
66 public: 66 public:
67 MOCK_METHOD3(AddObserver, 67 MOCK_METHOD3(AddObserver,
68 void(int render_process_id, 68 void(int render_process_id,
69 int render_frame_id, 69 int render_frame_id,
70 PresentationServiceDelegate::Observer* observer)); 70 PresentationServiceDelegate::Observer* observer));
71 MOCK_METHOD2(RemoveObserver, 71 MOCK_METHOD2(RemoveObserver,
72 void(int render_process_id, int render_frame_id)); 72 void(int render_process_id, int render_frame_id));
73 MOCK_METHOD3(AddScreenAvailabilityListener, 73
74 bool( 74 bool AddScreenAvailabilityListener(
75 int render_process_id, 75 int render_process_id,
76 int routing_id, 76 int routing_id,
77 PresentationScreenAvailabilityListener* listener)); 77 PresentationScreenAvailabilityListener* listener) override {
78 if (!screen_availability_listening_supported_)
79 listener->OnScreenAvailabilityNotSupported();
80
81 return AddScreenAvailabilityListener();
82 }
83 MOCK_METHOD0(AddScreenAvailabilityListener, bool());
84
78 MOCK_METHOD3(RemoveScreenAvailabilityListener, 85 MOCK_METHOD3(RemoveScreenAvailabilityListener,
79 void( 86 void(
80 int render_process_id, 87 int render_process_id,
81 int routing_id, 88 int routing_id,
82 PresentationScreenAvailabilityListener* listener)); 89 PresentationScreenAvailabilityListener* listener));
83 MOCK_METHOD2(Reset, 90 MOCK_METHOD2(Reset,
84 void( 91 void(
85 int render_process_id, 92 int render_process_id,
86 int routing_id)); 93 int routing_id));
87 MOCK_METHOD3(SetDefaultPresentationUrl, 94 MOCK_METHOD3(SetDefaultPresentationUrl,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 scoped_ptr<PresentationSessionMessage> message_request, 132 scoped_ptr<PresentationSessionMessage> message_request,
126 const SendMessageCallback& send_message_cb) override { 133 const SendMessageCallback& send_message_cb) override {
127 SendMessageRawPtr(render_process_id, render_frame_id, session, 134 SendMessageRawPtr(render_process_id, render_frame_id, session,
128 message_request.release(), send_message_cb); 135 message_request.release(), send_message_cb);
129 } 136 }
130 MOCK_METHOD3( 137 MOCK_METHOD3(
131 ListenForSessionStateChange, 138 ListenForSessionStateChange,
132 void(int render_process_id, 139 void(int render_process_id,
133 int render_frame_id, 140 int render_frame_id,
134 const content::SessionStateChangedCallback& state_changed_cb)); 141 const content::SessionStateChangedCallback& state_changed_cb));
142
143 void set_screen_availability_listening_supported(bool value) {
144 screen_availability_listening_supported_ = value;
145 }
146
147 private:
148 bool screen_availability_listening_supported_ = true;
135 }; 149 };
136 150
137 class MockPresentationServiceClient : 151 class MockPresentationServiceClient :
138 public presentation::PresentationServiceClient { 152 public presentation::PresentationServiceClient {
139 public: 153 public:
140 MOCK_METHOD2(OnScreenAvailabilityUpdated, 154 MOCK_METHOD2(OnScreenAvailabilityUpdated,
141 void(const mojo::String& url, bool available)); 155 void(const mojo::String& url, bool available));
142 void OnSessionStateChanged( 156 void OnSessionStateChanged(
143 presentation::PresentationSessionInfoPtr session_info, 157 presentation::PresentationSessionInfoPtr session_info,
144 presentation::PresentationSessionState new_state) override { 158 presentation::PresentationSessionState new_state) override {
145 OnSessionStateChanged(*session_info, new_state); 159 OnSessionStateChanged(*session_info, new_state);
146 } 160 }
147 MOCK_METHOD2(OnSessionStateChanged, 161 MOCK_METHOD2(OnSessionStateChanged,
148 void(const presentation::PresentationSessionInfo& session_info, 162 void(const presentation::PresentationSessionInfo& session_info,
149 presentation::PresentationSessionState new_state)); 163 presentation::PresentationSessionState new_state));
150 void OnScreenAvailabilityNotSupported(const mojo::String& url) override { 164
151 NOTIMPLEMENTED(); 165 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const mojo::String& url));
152 }
153 166
154 void OnSessionMessagesReceived( 167 void OnSessionMessagesReceived(
155 presentation::PresentationSessionInfoPtr session_info, 168 presentation::PresentationSessionInfoPtr session_info,
156 mojo::Array<presentation::SessionMessagePtr> messages) override { 169 mojo::Array<presentation::SessionMessagePtr> messages) override {
157 messages_received_ = messages.Pass(); 170 messages_received_ = messages.Pass();
158 MessagesReceived(); 171 MessagesReceived();
159 } 172 }
160 MOCK_METHOD0(MessagesReceived, void()); 173 MOCK_METHOD0(MessagesReceived, void());
161 174
162 mojo::Array<presentation::SessionMessagePtr> messages_received_; 175 mojo::Array<presentation::SessionMessagePtr> messages_received_;
(...skipping 28 matching lines...) Expand all
191 RenderViewHostImplTestHarness::TearDown(); 204 RenderViewHostImplTestHarness::TearDown();
192 } 205 }
193 206
194 void ListenForScreenAvailabilityAndWait( 207 void ListenForScreenAvailabilityAndWait(
195 const mojo::String& url, bool delegate_success) { 208 const mojo::String& url, bool delegate_success) {
196 base::RunLoop run_loop; 209 base::RunLoop run_loop;
197 // This will call to |service_impl_| via mojo. Process the message 210 // This will call to |service_impl_| via mojo. Process the message
198 // using RunLoop. 211 // using RunLoop.
199 // The callback shouldn't be invoked since there is no availability 212 // The callback shouldn't be invoked since there is no availability
200 // result yet. 213 // result yet.
201 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener(_, _, _)) 214 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener())
202 .WillOnce(DoAll( 215 .WillOnce(DoAll(
203 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 216 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
204 Return(delegate_success))); 217 Return(delegate_success)));
205 service_ptr_->ListenForScreenAvailability(url); 218 service_ptr_->ListenForScreenAvailability(url);
206 run_loop.Run(); 219 run_loop.Run();
207 220
208 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); 221 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
209 } 222 }
210 223
211 void RunLoopFor(base::TimeDelta duration) { 224 void RunLoopFor(base::TimeDelta duration) {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 837
825 EXPECT_CALL(mock_client_, 838 EXPECT_CALL(mock_client_,
826 OnSessionStateChanged( 839 OnSessionStateChanged(
827 Equals(session_info), 840 Equals(session_info),
828 presentation::PRESENTATION_SESSION_STATE_CONNECTED)); 841 presentation::PRESENTATION_SESSION_STATE_CONNECTED));
829 service_impl_->OnSessionStateChanged( 842 service_impl_->OnSessionStateChanged(
830 content::PresentationSessionInfo(kPresentationUrl, kPresentationId), 843 content::PresentationSessionInfo(kPresentationUrl, kPresentationId),
831 content::PRESENTATION_SESSION_STATE_CONNECTED); 844 content::PRESENTATION_SESSION_STATE_CONNECTED);
832 } 845 }
833 846
847 TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) {
848 mock_delegate_.set_screen_availability_listening_supported(false);
849 EXPECT_CALL(mock_client_,
850 OnScreenAvailabilityNotSupported(Eq(kPresentationUrl)));
851
852 ListenForScreenAvailabilityAndWait(kPresentationUrl, false);
853 }
854
834 } // namespace content 855 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698