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

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

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Respond to dcheng@ comments Created 3 years, 9 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 "content/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <iterator>
10 #include <memory> 11 #include <memory>
11 #include <string> 12 #include <string>
12 #include <utility> 13 #include <utility>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/location.h" 16 #include "base/location.h"
16 #include "base/run_loop.h" 17 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/test/test_timeouts.h" 19 #include "base/test/test_timeouts.h"
19 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
20 #include "content/public/browser/navigation_handle.h" 21 #include "content/public/browser/navigation_handle.h"
21 #include "content/public/browser/presentation_service_delegate.h" 22 #include "content/public/browser/presentation_service_delegate.h"
22 #include "content/public/common/presentation_constants.h" 23 #include "content/public/common/presentation_connection_message.h"
23 #include "content/public/common/presentation_session.h" 24 #include "content/public/common/presentation_session.h"
24 #include "content/test/test_render_frame_host.h" 25 #include "content/test/test_render_frame_host.h"
25 #include "content/test/test_render_view_host.h" 26 #include "content/test/test_render_view_host.h"
26 #include "content/test/test_web_contents.h" 27 #include "content/test/test_web_contents.h"
27 #include "mojo/public/cpp/bindings/interface_ptr.h" 28 #include "mojo/public/cpp/bindings/interface_ptr.h"
28 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
29 30
30 using ::testing::_; 31 using ::testing::_;
32 using ::testing::ByRef;
31 using ::testing::Eq; 33 using ::testing::Eq;
34 using ::testing::Invoke;
32 using ::testing::InvokeWithoutArgs; 35 using ::testing::InvokeWithoutArgs;
33 using ::testing::Mock; 36 using ::testing::Mock;
34 using ::testing::Return; 37 using ::testing::Return;
35 using ::testing::SaveArg; 38 using ::testing::SaveArg;
39 using ::testing::WithArgs;
36 40
37 namespace content { 41 namespace content {
38 42
39 namespace { 43 namespace {
40 44
41 // Matches Mojo structs.
42 MATCHER_P(Equals, expected, "") {
43 return expected.Equals(arg);
44 }
45
46 // Matches content::PresentationSessionInfo. 45 // Matches content::PresentationSessionInfo.
47 MATCHER_P(SessionInfoEquals, expected, "") { 46 MATCHER_P(SessionInfoEquals, expected, "") {
48 return expected.presentation_url == arg.presentation_url && 47 return expected.presentation_url == arg.presentation_url &&
49 expected.presentation_id == arg.presentation_id; 48 expected.presentation_id == arg.presentation_id;
50 } 49 }
51 50
52 const char kPresentationId[] = "presentationId"; 51 const char kPresentationId[] = "presentationId";
53 const char kPresentationUrl1[] = "http://foo.com/index.html"; 52 const char kPresentationUrl1[] = "http://foo.com/index.html";
54 const char kPresentationUrl2[] = "http://example.com/index.html"; 53 const char kPresentationUrl2[] = "http://example.com/index.html";
55 const char kPresentationUrl3[] = "http://example.net/index.html"; 54 const char kPresentationUrl3[] = "http://example.net/index.html";
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void(int render_process_id, 108 void(int render_process_id,
110 int render_frame_id, 109 int render_frame_id,
111 const std::string& presentation_id)); 110 const std::string& presentation_id));
112 MOCK_METHOD3(Terminate, 111 MOCK_METHOD3(Terminate,
113 void(int render_process_id, 112 void(int render_process_id,
114 int render_frame_id, 113 int render_frame_id,
115 const std::string& presentation_id)); 114 const std::string& presentation_id));
116 MOCK_METHOD4(ListenForConnectionMessages, 115 MOCK_METHOD4(ListenForConnectionMessages,
117 void(int render_process_id, 116 void(int render_process_id,
118 int render_frame_id, 117 int render_frame_id,
119 const content::PresentationSessionInfo& session, 118 const PresentationSessionInfo& session,
120 const PresentationConnectionMessageCallback& message_cb)); 119 const PresentationConnectionMessageCallback& message_cb));
121 MOCK_METHOD5(SendMessageRawPtr, 120 // PresentationConnectionMessage is move-only.
121 void SendMessage(int render_process_id,
122 int render_frame_id,
123 const PresentationSessionInfo& session,
124 PresentationConnectionMessage message,
125 const SendMessageCallback& send_message_cb) {
126 SendMessageInternal(render_process_id, render_frame_id, session, message,
127 send_message_cb);
128 }
129 MOCK_METHOD5(SendMessageInternal,
122 void(int render_process_id, 130 void(int render_process_id,
123 int render_frame_id, 131 int render_frame_id,
124 const content::PresentationSessionInfo& session, 132 const PresentationSessionInfo& session,
125 PresentationConnectionMessage* message_request, 133 const PresentationConnectionMessage& message,
126 const SendMessageCallback& send_message_cb)); 134 const SendMessageCallback& send_message_cb));
127 void SendMessage( 135 MOCK_METHOD4(
128 int render_process_id, 136 ListenForConnectionStateChange,
129 int render_frame_id, 137 void(int render_process_id,
130 const content::PresentationSessionInfo& session, 138 int render_frame_id,
131 std::unique_ptr<PresentationConnectionMessage> message_request, 139 const PresentationSessionInfo& connection,
132 const SendMessageCallback& send_message_cb) override { 140 const PresentationConnectionStateChangedCallback& state_changed_cb));
133 SendMessageRawPtr(render_process_id, render_frame_id, session,
134 message_request.release(), send_message_cb);
135 }
136 MOCK_METHOD4(ListenForConnectionStateChange,
137 void(int render_process_id,
138 int render_frame_id,
139 const content::PresentationSessionInfo& connection,
140 const content::PresentationConnectionStateChangedCallback&
141 state_changed_cb));
142 141
143 void ConnectToPresentation( 142 void ConnectToPresentation(
144 int render_process_id, 143 int render_process_id,
145 int render_frame_id, 144 int render_frame_id,
146 const content::PresentationSessionInfo& session, 145 const PresentationSessionInfo& session,
147 PresentationConnectionPtr controller_conn_ptr, 146 PresentationConnectionPtr controller_conn_ptr,
148 PresentationConnectionRequest receiver_conn_request) override { 147 PresentationConnectionRequest receiver_conn_request) override {
149 RegisterOffscreenPresentationConnectionRaw( 148 RegisterOffscreenPresentationConnectionRaw(
150 render_process_id, render_frame_id, session, controller_conn_ptr.get()); 149 render_process_id, render_frame_id, session, controller_conn_ptr.get());
151 } 150 }
152 151
153 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw, 152 MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw,
154 void(int render_process_id, 153 void(int render_process_id,
155 int render_frame_id, 154 int render_frame_id,
156 const content::PresentationSessionInfo& session, 155 const PresentationSessionInfo& session,
157 blink::mojom::PresentationConnection* connection)); 156 blink::mojom::PresentationConnection* connection));
158 157
159 void set_screen_availability_listening_supported(bool value) { 158 void set_screen_availability_listening_supported(bool value) {
160 screen_availability_listening_supported_ = value; 159 screen_availability_listening_supported_ = value;
161 } 160 }
162 161
163 private: 162 private:
164 bool screen_availability_listening_supported_ = true; 163 bool screen_availability_listening_supported_ = true;
165 }; 164 };
166 165
167 class MockReceiverPresentationServiceDelegate 166 class MockReceiverPresentationServiceDelegate
168 : public ReceiverPresentationServiceDelegate { 167 : public ReceiverPresentationServiceDelegate {
169 public: 168 public:
170 MOCK_METHOD3(AddObserver, 169 MOCK_METHOD3(AddObserver,
171 void(int render_process_id, 170 void(int render_process_id,
172 int render_frame_id, 171 int render_frame_id,
173 PresentationServiceDelegate::Observer* observer)); 172 PresentationServiceDelegate::Observer* observer));
174 MOCK_METHOD2(RemoveObserver, 173 MOCK_METHOD2(RemoveObserver,
175 void(int render_process_id, int render_frame_id)); 174 void(int render_process_id, int render_frame_id));
176 MOCK_METHOD2(Reset, void(int render_process_id, int routing_id)); 175 MOCK_METHOD2(Reset, void(int render_process_id, int routing_id));
177 MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback, 176 MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback,
178 void(const content::ReceiverConnectionAvailableCallback&)); 177 void(const ReceiverConnectionAvailableCallback&));
179 }; 178 };
180 179
181 class MockPresentationConnection : public blink::mojom::PresentationConnection { 180 class MockPresentationConnection : public blink::mojom::PresentationConnection {
182 public: 181 public:
183 void OnMessage(blink::mojom::ConnectionMessagePtr message, 182 // PresentationConnectionMessage is move-only.
184 const base::Callback<void(bool)>& send_message_cb) override { 183 void OnMessage(PresentationConnectionMessage message,
185 OnConnectionMessageReceived(*message); 184 const base::Callback<void(bool)>& send_message_cb) {
185 OnMessageInternal(message, send_message_cb);
186 } 186 }
187 MOCK_METHOD1(OnConnectionMessageReceived, 187 MOCK_METHOD2(OnMessageInternal,
188 void(const blink::mojom::ConnectionMessage& message)); 188 void(const PresentationConnectionMessage& message,
189 const base::Callback<void(bool)>& send_message_cb));
189 MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state)); 190 MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state));
190 }; 191 };
191 192
192 class MockPresentationServiceClient 193 class MockPresentationServiceClient
193 : public blink::mojom::PresentationServiceClient { 194 : public blink::mojom::PresentationServiceClient {
194 public: 195 public:
195 MOCK_METHOD2(OnScreenAvailabilityUpdated, 196 MOCK_METHOD2(OnScreenAvailabilityUpdated,
196 void(const GURL& url, bool available)); 197 void(const GURL& url, bool available));
197 MOCK_METHOD2(OnConnectionStateChanged, 198 MOCK_METHOD2(OnConnectionStateChanged,
198 void(const content::PresentationSessionInfo& connection, 199 void(const PresentationSessionInfo& connection,
199 PresentationConnectionState new_state)); 200 PresentationConnectionState new_state));
200 MOCK_METHOD3(OnConnectionClosed, 201 MOCK_METHOD3(OnConnectionClosed,
201 void(const content::PresentationSessionInfo& connection, 202 void(const PresentationSessionInfo& connection,
202 PresentationConnectionCloseReason reason, 203 PresentationConnectionCloseReason reason,
203 const std::string& message)); 204 const std::string& message));
204 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url)); 205 MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url));
205 206 // PresentationConnectionMessage is move-only.
206 void OnConnectionMessagesReceived( 207 void OnConnectionMessagesReceived(
207 const content::PresentationSessionInfo& session_info, 208 const PresentationSessionInfo& session_info,
208 std::vector<blink::mojom::ConnectionMessagePtr> messages) override { 209 std::vector<PresentationConnectionMessage> messages) {
209 messages_received_ = std::move(messages); 210 OnConnectionMessagesReceivedInternal(session_info, messages);
210 MessagesReceived();
211 } 211 }
212 MOCK_METHOD0(MessagesReceived, void()); 212 MOCK_METHOD2(
213 213 OnConnectionMessagesReceivedInternal,
214 void(const PresentationSessionInfo& session_info,
215 const std::vector<PresentationConnectionMessage>& messages));
214 MOCK_METHOD1(OnDefaultSessionStarted, 216 MOCK_METHOD1(OnDefaultSessionStarted,
215 void(const content::PresentationSessionInfo& session_info)); 217 void(const PresentationSessionInfo& session_info));
216 218
217 void OnReceiverConnectionAvailable( 219 void OnReceiverConnectionAvailable(
218 const content::PresentationSessionInfo& session_info, 220 const PresentationSessionInfo& session_info,
219 blink::mojom::PresentationConnectionPtr controller_conn_ptr, 221 blink::mojom::PresentationConnectionPtr controller_conn_ptr,
220 blink::mojom::PresentationConnectionRequest receiver_conn_request) 222 blink::mojom::PresentationConnectionRequest receiver_conn_request)
221 override { 223 override {
222 OnReceiverConnectionAvailable(session_info); 224 OnReceiverConnectionAvailable(session_info);
223 } 225 }
224 MOCK_METHOD1(OnReceiverConnectionAvailable, 226 MOCK_METHOD1(OnReceiverConnectionAvailable,
225 void(const content::PresentationSessionInfo& session_info)); 227 void(const PresentationSessionInfo& session_info));
226
227 std::vector<blink::mojom::ConnectionMessagePtr> messages_received_;
228 }; 228 };
229 229
230 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 230 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
231 public: 231 public:
232 PresentationServiceImplTest() 232 PresentationServiceImplTest()
233 : presentation_url1_(GURL(kPresentationUrl1)), 233 : presentation_url1_(GURL(kPresentationUrl1)),
234 presentation_url2_(GURL(kPresentationUrl2)), 234 presentation_url2_(GURL(kPresentationUrl2)),
235 presentation_url3_(GURL(kPresentationUrl3)) {} 235 presentation_url3_(GURL(kPresentationUrl3)) {}
236 236
237 void SetUp() override { 237 void SetUp() override {
(...skipping 23 matching lines...) Expand all
261 void TearDown() override { 261 void TearDown() override {
262 service_ptr_.reset(); 262 service_ptr_.reset();
263 if (service_impl_.get()) { 263 if (service_impl_.get()) {
264 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); 264 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1);
265 service_impl_.reset(); 265 service_impl_.reset();
266 } 266 }
267 RenderViewHostImplTestHarness::TearDown(); 267 RenderViewHostImplTestHarness::TearDown();
268 } 268 }
269 269
270 void Navigate(bool main_frame) { 270 void Navigate(bool main_frame) {
271 content::RenderFrameHost* rfh = main_rfh(); 271 RenderFrameHost* rfh = main_rfh();
272 content::RenderFrameHostTester* rfh_tester = 272 RenderFrameHostTester* rfh_tester = RenderFrameHostTester::For(rfh);
273 content::RenderFrameHostTester::For(rfh);
274 if (!main_frame) 273 if (!main_frame)
275 rfh = rfh_tester->AppendChild("subframe"); 274 rfh = rfh_tester->AppendChild("subframe");
276 std::unique_ptr<NavigationHandle> navigation_handle = 275 std::unique_ptr<NavigationHandle> navigation_handle =
277 NavigationHandle::CreateNavigationHandleForTesting( 276 NavigationHandle::CreateNavigationHandleForTesting(
278 GURL(), rfh, true); 277 GURL(), rfh, true);
279 // Destructor calls DidFinishNavigation. 278 // Destructor calls DidFinishNavigation.
280 } 279 }
281 280
282 void ListenForScreenAvailabilityAndWait(const GURL& url, 281 void ListenForScreenAvailabilityAndWait(const GURL& url,
283 bool delegate_success) { 282 bool delegate_success) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 326 }
328 327
329 void ExpectCleanState() { 328 void ExpectCleanState() {
330 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); 329 EXPECT_TRUE(service_impl_->default_presentation_urls_.empty());
331 EXPECT_EQ( 330 EXPECT_EQ(
332 service_impl_->screen_availability_listeners_.find(presentation_url1_), 331 service_impl_->screen_availability_listeners_.find(presentation_url1_),
333 service_impl_->screen_availability_listeners_.end()); 332 service_impl_->screen_availability_listeners_.end());
334 } 333 }
335 334
336 void ExpectNewSessionCallbackSuccess( 335 void ExpectNewSessionCallbackSuccess(
337 const base::Optional<content::PresentationSessionInfo>& info, 336 const base::Optional<PresentationSessionInfo>& info,
338 const base::Optional<content::PresentationError>& error) { 337 const base::Optional<PresentationError>& error) {
339 EXPECT_TRUE(info); 338 EXPECT_TRUE(info);
340 EXPECT_FALSE(error); 339 EXPECT_FALSE(error);
341 if (!run_loop_quit_closure_.is_null()) 340 if (!run_loop_quit_closure_.is_null())
342 run_loop_quit_closure_.Run(); 341 run_loop_quit_closure_.Run();
343 } 342 }
344 343
345 void ExpectNewSessionCallbackError( 344 void ExpectNewSessionCallbackError(
346 const base::Optional<content::PresentationSessionInfo>& info, 345 const base::Optional<PresentationSessionInfo>& info,
347 const base::Optional<content::PresentationError>& error) { 346 const base::Optional<PresentationError>& error) {
348 EXPECT_FALSE(info); 347 EXPECT_FALSE(info);
349 EXPECT_TRUE(error); 348 EXPECT_TRUE(error);
350 if (!run_loop_quit_closure_.is_null()) 349 if (!run_loop_quit_closure_.is_null())
351 run_loop_quit_closure_.Run(); 350 run_loop_quit_closure_.Run();
352 } 351 }
353 352
354 void ExpectConnectionMessages( 353 void ExpectConnectionMessages(
355 const std::vector<blink::mojom::ConnectionMessagePtr>& expected_msgs, 354 const std::vector<PresentationConnectionMessage>& expected_msgs,
356 const std::vector<blink::mojom::ConnectionMessagePtr>& actual_msgs) { 355 const std::vector<PresentationConnectionMessage>& actual_msgs) {
357 EXPECT_EQ(expected_msgs.size(), actual_msgs.size()); 356 EXPECT_EQ(expected_msgs.size(), actual_msgs.size());
358 for (size_t i = 0; i < actual_msgs.size(); ++i) 357 for (size_t i = 0; i < actual_msgs.size(); ++i)
359 EXPECT_TRUE(expected_msgs[i].Equals(actual_msgs[i])); 358 EXPECT_EQ(expected_msgs[i], actual_msgs[i]);
360 }
361
362 void RunListenForConnectionMessages(const std::string& text_msg,
363 const std::vector<uint8_t>& binary_data,
364 bool pass_ownership) {
365 std::vector<blink::mojom::ConnectionMessagePtr> expected_msgs(2);
366 expected_msgs[0] = blink::mojom::ConnectionMessage::New();
367 expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT;
368 expected_msgs[0]->message = text_msg;
369 expected_msgs[1] = blink::mojom::ConnectionMessage::New();
370 expected_msgs[1]->type = blink::mojom::PresentationMessageType::BINARY;
371 expected_msgs[1]->data = binary_data;
372
373 content::PresentationSessionInfo session(presentation_url1_,
374 kPresentationId);
375
376 PresentationConnectionMessageCallback message_cb;
377 {
378 base::RunLoop run_loop;
379 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _))
380 .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
381 SaveArg<3>(&message_cb)));
382 service_ptr_->ListenForConnectionMessages(session);
383 run_loop.Run();
384 }
385
386 std::vector<std::unique_ptr<PresentationConnectionMessage>> messages;
387 std::unique_ptr<content::PresentationConnectionMessage> message;
388 message.reset(new content::PresentationConnectionMessage(
389 PresentationMessageType::TEXT));
390 message->message = text_msg;
391 messages.push_back(std::move(message));
392 message.reset(new content::PresentationConnectionMessage(
393 PresentationMessageType::BINARY));
394 message->data.reset(new std::vector<uint8_t>(binary_data));
395 messages.push_back(std::move(message));
396
397 std::vector<blink::mojom::ConnectionMessagePtr> actual_msgs;
398 {
399 base::RunLoop run_loop;
400 EXPECT_CALL(mock_client_, MessagesReceived())
401 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
402 message_cb.Run(std::move(messages), pass_ownership);
403 run_loop.Run();
404 }
405 ExpectConnectionMessages(expected_msgs, mock_client_.messages_received_);
406 } 359 }
407 360
408 MockPresentationServiceDelegate mock_delegate_; 361 MockPresentationServiceDelegate mock_delegate_;
409 MockReceiverPresentationServiceDelegate mock_receiver_delegate_; 362 MockReceiverPresentationServiceDelegate mock_receiver_delegate_;
410 363
411 std::unique_ptr<PresentationServiceImpl> service_impl_; 364 std::unique_ptr<PresentationServiceImpl> service_impl_;
412 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_; 365 mojo::InterfacePtr<blink::mojom::PresentationService> service_ptr_;
413 366
414 MockPresentationServiceClient mock_client_; 367 MockPresentationServiceClient mock_client_;
415 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>> 368 std::unique_ptr<mojo::Binding<blink::mojom::PresentationServiceClient>>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 EXPECT_CALL(mock_delegate_, 443 EXPECT_CALL(mock_delegate_,
491 SetDefaultPresentationUrls(_, _, presentation_urls_, _)) 444 SetDefaultPresentationUrls(_, _, presentation_urls_, _))
492 .Times(1); 445 .Times(1);
493 446
494 service_impl_->SetDefaultPresentationUrls(presentation_urls_); 447 service_impl_->SetDefaultPresentationUrls(presentation_urls_);
495 448
496 // Sets different DPUs. 449 // Sets different DPUs.
497 std::vector<GURL> more_urls = presentation_urls_; 450 std::vector<GURL> more_urls = presentation_urls_;
498 more_urls.push_back(presentation_url3_); 451 more_urls.push_back(presentation_url3_);
499 452
500 content::PresentationSessionStartedCallback callback; 453 PresentationSessionStartedCallback callback;
501 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _)) 454 EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _))
502 .WillOnce(SaveArg<3>(&callback)); 455 .WillOnce(SaveArg<3>(&callback));
503 service_impl_->SetDefaultPresentationUrls(more_urls); 456 service_impl_->SetDefaultPresentationUrls(more_urls);
504 457
505 content::PresentationSessionInfo session_info(presentation_url2_, 458 PresentationSessionInfo session_info(presentation_url2_, kPresentationId);
506 kPresentationId);
507 459
508 base::RunLoop run_loop; 460 base::RunLoop run_loop;
509 EXPECT_CALL(mock_client_, 461 EXPECT_CALL(mock_client_,
510 OnDefaultSessionStarted(SessionInfoEquals(session_info))) 462 OnDefaultSessionStarted(SessionInfoEquals(session_info)))
511 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 463 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
512 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); 464 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _));
513 callback.Run( 465 callback.Run(PresentationSessionInfo(presentation_url2_, kPresentationId));
514 content::PresentationSessionInfo(presentation_url2_, kPresentationId));
515 run_loop.Run(); 466 run_loop.Run();
516 } 467 }
517 468
518 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { 469 TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
519 content::PresentationSessionInfo connection(presentation_url1_, 470 PresentationSessionInfo connection(presentation_url1_, kPresentationId);
520 kPresentationId); 471 PresentationConnectionStateChangedCallback state_changed_cb;
521 content::PresentationConnectionStateChangedCallback state_changed_cb;
522 // Trigger state change. It should be propagated back up to |mock_client_|. 472 // Trigger state change. It should be propagated back up to |mock_client_|.
523 content::PresentationSessionInfo presentation_connection(presentation_url1_, 473 PresentationSessionInfo presentation_connection(presentation_url1_,
524 kPresentationId); 474 kPresentationId);
525 475
526 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 476 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
527 .WillOnce(SaveArg<3>(&state_changed_cb)); 477 .WillOnce(SaveArg<3>(&state_changed_cb));
528 service_impl_->ListenForConnectionStateChange(connection); 478 service_impl_->ListenForConnectionStateChange(connection);
529 479
530 { 480 {
531 base::RunLoop run_loop; 481 base::RunLoop run_loop;
532 EXPECT_CALL(mock_client_, 482 EXPECT_CALL(mock_client_, OnConnectionStateChanged(
533 OnConnectionStateChanged( 483 SessionInfoEquals(presentation_connection),
534 SessionInfoEquals(presentation_connection), 484 PRESENTATION_CONNECTION_STATE_TERMINATED))
535 content::PRESENTATION_CONNECTION_STATE_TERMINATED))
536 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 485 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
537 state_changed_cb.Run(PresentationConnectionStateChangeInfo( 486 state_changed_cb.Run(PresentationConnectionStateChangeInfo(
538 PRESENTATION_CONNECTION_STATE_TERMINATED)); 487 PRESENTATION_CONNECTION_STATE_TERMINATED));
539 run_loop.Run(); 488 run_loop.Run();
540 } 489 }
541 } 490 }
542 491
543 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { 492 TEST_F(PresentationServiceImplTest, ListenForConnectionClose) {
544 content::PresentationSessionInfo connection(presentation_url1_, 493 PresentationSessionInfo connection(presentation_url1_, kPresentationId);
545 kPresentationId); 494 PresentationConnectionStateChangedCallback state_changed_cb;
546 content::PresentationConnectionStateChangedCallback state_changed_cb;
547 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) 495 EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
548 .WillOnce(SaveArg<3>(&state_changed_cb)); 496 .WillOnce(SaveArg<3>(&state_changed_cb));
549 service_impl_->ListenForConnectionStateChange(connection); 497 service_impl_->ListenForConnectionStateChange(connection);
550 498
551 // Trigger connection close. It should be propagated back up to 499 // Trigger connection close. It should be propagated back up to
552 // |mock_client_|. 500 // |mock_client_|.
553 content::PresentationSessionInfo presentation_connection(presentation_url1_, 501 PresentationSessionInfo presentation_connection(presentation_url1_,
554 kPresentationId); 502 kPresentationId);
555 { 503 {
556 base::RunLoop run_loop; 504 base::RunLoop run_loop;
557 PresentationConnectionStateChangeInfo closed_info( 505 PresentationConnectionStateChangeInfo closed_info(
558 PRESENTATION_CONNECTION_STATE_CLOSED); 506 PRESENTATION_CONNECTION_STATE_CLOSED);
559 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; 507 closed_info.close_reason = PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY;
560 closed_info.message = "Foo"; 508 closed_info.message = "Foo";
561 509
562 EXPECT_CALL(mock_client_, 510 EXPECT_CALL(mock_client_,
563 OnConnectionClosed( 511 OnConnectionClosed(
564 SessionInfoEquals(presentation_connection), 512 SessionInfoEquals(presentation_connection),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 607 }
660 608
661 TEST_F(PresentationServiceImplTest, Terminate) { 609 TEST_F(PresentationServiceImplTest, Terminate) {
662 service_ptr_->Terminate(presentation_url1_, kPresentationId); 610 service_ptr_->Terminate(presentation_url1_, kPresentationId);
663 base::RunLoop run_loop; 611 base::RunLoop run_loop;
664 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))) 612 EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId)))
665 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 613 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
666 run_loop.Run(); 614 run_loop.Run();
667 } 615 }
668 616
669 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesPassed) {
670 std::string text_msg("123");
671 std::vector<uint8_t> binary_data(3, '\1');
672 RunListenForConnectionMessages(text_msg, binary_data, true);
673 }
674
675 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesCopied) {
676 std::string text_msg("123");
677 std::vector<uint8_t> binary_data(3, '\1');
678 RunListenForConnectionMessages(text_msg, binary_data, false);
679 }
680
681 TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesWithEmptyMsg) {
682 std::string text_msg("");
683 std::vector<uint8_t> binary_data;
684 RunListenForConnectionMessages(text_msg, binary_data, false);
685 }
686
687 TEST_F(PresentationServiceImplTest, SetPresentationConnection) { 617 TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
688 content::PresentationSessionInfo session(presentation_url1_, kPresentationId); 618 PresentationSessionInfo session(presentation_url1_, kPresentationId);
689 619
690 blink::mojom::PresentationConnectionPtr connection; 620 blink::mojom::PresentationConnectionPtr connection;
691 MockPresentationConnection mock_presentation_connection; 621 MockPresentationConnection mock_presentation_connection;
692 mojo::Binding<blink::mojom::PresentationConnection> connection_binding( 622 mojo::Binding<blink::mojom::PresentationConnection> connection_binding(
693 &mock_presentation_connection, mojo::MakeRequest(&connection)); 623 &mock_presentation_connection, mojo::MakeRequest(&connection));
694 blink::mojom::PresentationConnectionPtr receiver_connection; 624 blink::mojom::PresentationConnectionPtr receiver_connection;
695 auto request = mojo::MakeRequest(&receiver_connection); 625 auto request = mojo::MakeRequest(&receiver_connection);
696 626
697 content::PresentationSessionInfo expected(presentation_url1_, 627 PresentationSessionInfo expected(presentation_url1_, kPresentationId);
698 kPresentationId);
699 EXPECT_CALL(mock_delegate_, RegisterOffscreenPresentationConnectionRaw( 628 EXPECT_CALL(mock_delegate_, RegisterOffscreenPresentationConnectionRaw(
700 _, _, SessionInfoEquals(expected), _)); 629 _, _, SessionInfoEquals(expected), _));
701 630
702 service_impl_->SetPresentationConnection(session, std::move(connection), 631 service_impl_->SetPresentationConnection(session, std::move(connection),
703 std::move(request)); 632 std::move(request));
704 } 633 }
705 634
706 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) { 635 TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
707 MockReceiverPresentationServiceDelegate mock_receiver_delegate; 636 MockReceiverPresentationServiceDelegate mock_receiver_delegate;
708 637
709 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(), 638 PresentationServiceImpl service_impl(contents()->GetMainFrame(), contents(),
710 nullptr, &mock_receiver_delegate); 639 nullptr, &mock_receiver_delegate);
711 640
712 ReceiverConnectionAvailableCallback callback; 641 ReceiverConnectionAvailableCallback callback;
713 EXPECT_CALL(mock_receiver_delegate, 642 EXPECT_CALL(mock_receiver_delegate,
714 RegisterReceiverConnectionAvailableCallback(_)) 643 RegisterReceiverConnectionAvailableCallback(_))
715 .WillOnce(SaveArg<0>(&callback)); 644 .WillOnce(SaveArg<0>(&callback));
716 645
717 blink::mojom::PresentationServiceClientPtr client_ptr; 646 blink::mojom::PresentationServiceClientPtr client_ptr;
718 client_binding_.reset( 647 client_binding_.reset(
719 new mojo::Binding<blink::mojom::PresentationServiceClient>( 648 new mojo::Binding<blink::mojom::PresentationServiceClient>(
720 &mock_client_, mojo::MakeRequest(&client_ptr))); 649 &mock_client_, mojo::MakeRequest(&client_ptr)));
721 service_impl.controller_delegate_ = nullptr; 650 service_impl.controller_delegate_ = nullptr;
722 service_impl.SetClient(std::move(client_ptr)); 651 service_impl.SetClient(std::move(client_ptr));
723 EXPECT_FALSE(callback.is_null()); 652 EXPECT_FALSE(callback.is_null());
724 653
725 // NO-OP for ControllerPresentationServiceDelegate API functions 654 // NO-OP for ControllerPresentationServiceDelegate API functions
726 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0); 655 EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0);
727 656
728 content::PresentationSessionInfo session(presentation_url1_, kPresentationId); 657 PresentationSessionInfo session(presentation_url1_, kPresentationId);
729 service_impl.ListenForConnectionMessages(session); 658 service_impl.ListenForConnectionMessages(session);
730 } 659 }
731 660
732 TEST_F(PresentationServiceImplTest, StartSessionInProgress) { 661 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
733 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _)) 662 EXPECT_CALL(mock_delegate_, StartSession(_, _, presentation_urls_, _, _))
734 .Times(1); 663 .Times(1);
735 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing)); 664 service_ptr_->StartSession(presentation_urls_, base::Bind(&DoNothing));
736 665
737 // This request should fail immediately, since there is already a StartSession 666 // This request should fail immediately, since there is already a StartSession
738 // in progress. 667 // in progress.
(...skipping 30 matching lines...) Expand all
769 mock_delegate_.set_screen_availability_listening_supported(false); 698 mock_delegate_.set_screen_availability_listening_supported(false);
770 base::RunLoop run_loop; 699 base::RunLoop run_loop;
771 EXPECT_CALL(mock_client_, 700 EXPECT_CALL(mock_client_,
772 OnScreenAvailabilityNotSupported(presentation_url1_)) 701 OnScreenAvailabilityNotSupported(presentation_url1_))
773 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 702 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
774 ListenForScreenAvailabilityAndWait(presentation_url1_, false); 703 ListenForScreenAvailabilityAndWait(presentation_url1_, false);
775 run_loop.Run(); 704 run_loop.Run();
776 } 705 }
777 706
778 } // namespace content 707 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698