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

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

Issue 979413002: [Presentation API] Additional plumbing for PresentationServiceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@REAL-NEW-MASTER
Patch Set: rm presentation_session.mojom Created 5 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 "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 "content/browser/presentation/presentation_service_impl.h" 8 #include "content/browser/presentation/presentation_service_impl.h"
9 #include "content/public/browser/presentation_service_delegate.h" 9 #include "content/public/browser/presentation_service_delegate.h"
10 #include "content/public/browser/presentation_session.h"
10 #include "content/test/test_render_frame_host.h" 11 #include "content/test/test_render_frame_host.h"
11 #include "content/test/test_render_view_host.h" 12 #include "content/test/test_render_view_host.h"
12 #include "content/test/test_web_contents.h" 13 #include "content/test/test_web_contents.h"
13 #include "mojo/public/cpp/bindings/interface_ptr.h" 14 #include "mojo/public/cpp/bindings/interface_ptr.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 16
16 using ::testing::_; 17 using ::testing::_;
17 using ::testing::Eq; 18 using ::testing::Eq;
18 using ::testing::InvokeWithoutArgs; 19 using ::testing::InvokeWithoutArgs;
19 using ::testing::Mock; 20 using ::testing::Mock;
20 using ::testing::Return; 21 using ::testing::Return;
22 using ::testing::SaveArg;
21 23
22 namespace content { 24 namespace content {
23 25
24 class MockPresentationServiceDelegate : public PresentationServiceDelegate { 26 class MockPresentationServiceDelegate : public PresentationServiceDelegate {
25 public: 27 public:
26 MOCK_METHOD1(AddObserver, 28 MOCK_METHOD1(AddObserver,
27 void(PresentationServiceDelegate::Observer* observer)); 29 void(PresentationServiceDelegate::Observer* observer));
28 MOCK_METHOD1(RemoveObserver, 30 MOCK_METHOD1(RemoveObserver,
29 void(PresentationServiceDelegate::Observer* observer)); 31 void(PresentationServiceDelegate::Observer* observer));
30 MOCK_METHOD3(AddScreenAvailabilityListener, 32 MOCK_METHOD3(AddScreenAvailabilityListener,
31 bool( 33 bool(
32 int render_process_id, 34 int render_process_id,
33 int routing_id, 35 int routing_id,
34 PresentationScreenAvailabilityListener* listener)); 36 PresentationScreenAvailabilityListener* listener));
35 MOCK_METHOD3(RemoveScreenAvailabilityListener, 37 MOCK_METHOD3(RemoveScreenAvailabilityListener,
36 void( 38 void(
37 int render_process_id, 39 int render_process_id,
38 int routing_id, 40 int routing_id,
39 PresentationScreenAvailabilityListener* listener)); 41 PresentationScreenAvailabilityListener* listener));
40 MOCK_METHOD2(RemoveAllScreenAvailabilityListeners, 42 MOCK_METHOD2(Reset,
41 void( 43 void(
42 int render_process_id, 44 int render_process_id,
43 int routing_id)); 45 int routing_id));
46 MOCK_METHOD4(SetDefaultPresentationUrl,
47 void(
48 int render_process_id,
49 int routing_id,
50 const std::string& default_presentation_url,
51 const std::string& default_presentation_id));
52 MOCK_METHOD6(StartSession,
53 void(
54 int render_process_id,
55 int render_frame_id,
56 const std::string& presentation_url,
57 const std::string& presentation_id,
58 const PresentationSessionSuccessCallback& success_cb,
59 const PresentationSessionErrorCallback& error_cb));
60 MOCK_METHOD6(JoinSession,
61 void(
62 int render_process_id,
63 int render_frame_id,
64 const std::string& presentation_url,
65 const std::string& presentation_id,
66 const PresentationSessionSuccessCallback& success_cb,
67 const PresentationSessionErrorCallback& error_cb));
44 }; 68 };
45 69
46 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { 70 class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
47 public: 71 public:
48 PresentationServiceImplTest() : callback_count_(0) {} 72 PresentationServiceImplTest() : callback_count_(0) {}
49 73
50 void SetUp() override { 74 void SetUp() override {
51 RenderViewHostImplTestHarness::SetUp(); 75 RenderViewHostImplTestHarness::SetUp();
52 76
53 EXPECT_CALL(mock_delegate_, AddObserver(_)).Times(1); 77 EXPECT_CALL(mock_delegate_, AddObserver(_)).Times(1);
54 service_impl_.reset(mojo::WeakBindToProxy( 78 service_impl_.reset(mojo::WeakBindToProxy(
55 new PresentationServiceImpl( 79 new PresentationServiceImpl(
56 contents()->GetMainFrame(), contents(), &mock_delegate_), 80 contents()->GetMainFrame(), contents(), &mock_delegate_),
57 &service_ptr_)); 81 &service_ptr_));
58 } 82 }
59 83
60 void TearDown() override { 84 void TearDown() override {
61 service_ptr_.reset(); 85 service_ptr_.reset();
62 86
63 EXPECT_CALL(mock_delegate_, RemoveObserver(Eq(service_impl_.get()))) 87 EXPECT_CALL(mock_delegate_, RemoveObserver(Eq(service_impl_.get())))
64 .Times(1); 88 .Times(1);
65 service_impl_.reset(); 89 service_impl_.reset();
66 90
67 RenderViewHostImplTestHarness::TearDown(); 91 RenderViewHostImplTestHarness::TearDown();
68 } 92 }
69 93
70 void GetScreenAvailabilityAndWait( 94 void GetScreenAvailabilityAndWait(
71 const std::string& presentation_url, 95 const std::string& presentation_url,
72 const base::Callback<void(bool)>& callback, 96 const base::Callback<void(const std::string&, bool)>& callback,
73 bool delegate_success) { 97 bool delegate_success) {
74 VLOG(1) << "GetScreenAvailabilityAndWait for " << presentation_url;
75 base::RunLoop run_loop; 98 base::RunLoop run_loop;
76 // This will call to |service_impl_| via mojo. Process the message 99 // This will call to |service_impl_| via mojo. Process the message
77 // using RunLoop. 100 // using RunLoop.
78 // The callback shouldn't be invoked since there is no availability 101 // The callback shouldn't be invoked since there is no availability
79 // result yet. 102 // result yet.
80 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener(_, _, _)) 103 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener(_, _, _))
81 .WillOnce(DoAll( 104 .WillOnce(DoAll(
82 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), 105 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
83 Return(delegate_success))); 106 Return(delegate_success)));
84 service_ptr_->GetScreenAvailability(presentation_url, callback); 107 service_ptr_->GetScreenAvailability(presentation_url, callback);
(...skipping 15 matching lines...) Expand all
100 run_loop.Run(); 123 run_loop.Run();
101 } 124 }
102 125
103 void SaveQuitClosureAndRunLoop() { 126 void SaveQuitClosureAndRunLoop() {
104 base::RunLoop run_loop; 127 base::RunLoop run_loop;
105 run_loop_quit_closure_ = run_loop.QuitClosure(); 128 run_loop_quit_closure_ = run_loop.QuitClosure();
106 run_loop.Run(); 129 run_loop.Run();
107 run_loop_quit_closure_.Reset(); 130 run_loop_quit_closure_.Reset();
108 } 131 }
109 132
110 void ShouldNotBeCalled(bool available) { 133 void ShouldNotBeCalled(const std::string& presentation_url, bool available) {
111 FAIL() << "Callback unexpectedly invoked with available = " << available; 134 FAIL() << "Callback unexpectedly invoked with "
135 << "url = " << presentation_url << ", available = " << available;
112 } 136 }
113 137
114 void SimulateScreenAvailabilityChange( 138 void SimulateScreenAvailabilityChange(
115 const std::string& presentation_url, bool available) { 139 const std::string& presentation_url, bool available) {
116 const auto& contexts = service_impl_->availability_contexts_; 140 const auto& contexts = service_impl_->availability_contexts_;
117 auto it = contexts.find(presentation_url); 141 auto it = contexts.find(presentation_url);
118 ASSERT_TRUE(it != contexts.end()); 142 ASSERT_TRUE(it != contexts.end());
119 it->second->OnScreenAvailabilityChanged(available); 143 it->second->OnScreenAvailabilityChanged(available);
120 } 144 }
121 145
122 void ScreenAvailabilityChangedCallback(bool expected, bool available) { 146 void ScreenAvailabilityChangedCallback(
147 bool expected,
148 const std::string& presentation_url,
149 bool available) {
123 ++callback_count_; 150 ++callback_count_;
124 EXPECT_EQ(expected, available); 151 EXPECT_EQ(expected, available);
125 if (!run_loop_quit_closure_.is_null()) 152 if (!run_loop_quit_closure_.is_null())
126 run_loop_quit_closure_.Run(); 153 run_loop_quit_closure_.Run();
127 } 154 }
128 155
156 void ExpectReset() {
157 EXPECT_CALL(mock_delegate_, Reset(_, _))
158 .Times(1);
159 }
160
161 void ExpectCleanState() {
162 EXPECT_TRUE(service_impl_->availability_contexts_.empty());
163 EXPECT_TRUE(service_impl_->default_presentation_url_.empty());
164 EXPECT_TRUE(service_impl_->default_presentation_id_.empty());
165 EXPECT_TRUE(service_impl_->queued_start_session_requests_.empty());
166 }
167
168 void ExpectNewSessionMojoCallbackSuccess(
169 presentation::PresentationSessionInfoPtr info,
170 presentation::PresentationErrorPtr error) {
171 EXPECT_FALSE(info.is_null());
172 EXPECT_TRUE(error.is_null());
173 if (!run_loop_quit_closure_.is_null())
174 run_loop_quit_closure_.Run();
175 }
176
177 void ExpectNewSessionMojoCallbackError(
178 presentation::PresentationSessionInfoPtr info,
179 presentation::PresentationErrorPtr error) {
180 EXPECT_TRUE(info.is_null());
181 EXPECT_FALSE(error.is_null());
182 if (!run_loop_quit_closure_.is_null())
183 run_loop_quit_closure_.Run();
184 }
185
129 MockPresentationServiceDelegate mock_delegate_; 186 MockPresentationServiceDelegate mock_delegate_;
130 scoped_ptr<PresentationServiceImpl> service_impl_; 187 scoped_ptr<PresentationServiceImpl> service_impl_;
131 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; 188 mojo::InterfacePtr<presentation::PresentationService> service_ptr_;
132 base::Closure run_loop_quit_closure_; 189 base::Closure run_loop_quit_closure_;
133 int callback_count_; 190 int callback_count_;
134 }; 191 };
135 192
136 TEST_F(PresentationServiceImplTest, GetScreenAvailability) { 193 TEST_F(PresentationServiceImplTest, GetScreenAvailability) {
137 std::string presentation_url("http://fooUrl"); 194 std::string presentation_url("http://fooUrl");
138 GetScreenAvailabilityAndWait( 195 GetScreenAvailabilityAndWait(
(...skipping 24 matching lines...) Expand all
163 service_ptr_->GetScreenAvailability( 220 service_ptr_->GetScreenAvailability(
164 presentation_url, 221 presentation_url,
165 base::Bind( 222 base::Bind(
166 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, 223 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback,
167 base::Unretained(this), 224 base::Unretained(this),
168 false)); 225 false));
169 SaveQuitClosureAndRunLoop(); 226 SaveQuitClosureAndRunLoop();
170 EXPECT_EQ(2, callback_count_); 227 EXPECT_EQ(2, callback_count_);
171 } 228 }
172 229
173 TEST_F(PresentationServiceImplTest, RemoveAllListeners) { 230 TEST_F(PresentationServiceImplTest, Reset) {
174 std::string presentation_url("http://fooUrl"); 231 std::string presentation_url("http://fooUrl");
175 GetScreenAvailabilityAndWait( 232 GetScreenAvailabilityAndWait(
176 presentation_url, 233 presentation_url,
177 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, 234 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled,
178 base::Unretained(this)), 235 base::Unretained(this)),
179 true); 236 true);
180 237
181 service_impl_->RemoveAllListeners(); 238 ExpectReset();
182 239 service_impl_->Reset();
183 ExpectListenerDoesNotExist(presentation_url); 240 ExpectCleanState();
184 241
185 EXPECT_EQ(0, callback_count_); 242 EXPECT_EQ(0, callback_count_);
186 } 243 }
187 244
188 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) { 245 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) {
189 std::string presentation_url("http://fooUrl"); 246 std::string presentation_url("http://fooUrl");
190 GetScreenAvailabilityAndWait( 247 GetScreenAvailabilityAndWait(
191 presentation_url, 248 presentation_url,
192 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, 249 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled,
193 base::Unretained(this)), 250 base::Unretained(this)),
194 true); 251 true);
195 252
253 ExpectReset();
196 service_impl_->DidNavigateAnyFrame( 254 service_impl_->DidNavigateAnyFrame(
197 contents()->GetMainFrame(), 255 contents()->GetMainFrame(),
198 content::LoadCommittedDetails(), 256 content::LoadCommittedDetails(),
199 content::FrameNavigateParams()); 257 content::FrameNavigateParams());
200 258 ExpectCleanState();
201 ExpectListenerDoesNotExist(presentation_url);
202 } 259 }
203 260
204 TEST_F(PresentationServiceImplTest, DidNavigateNotThisFrame) { 261 TEST_F(PresentationServiceImplTest, DidNavigateNotThisFrame) {
205 std::string presentation_url("http://fooUrl"); 262 std::string presentation_url("http://fooUrl");
206 GetScreenAvailabilityAndWait( 263 GetScreenAvailabilityAndWait(
207 presentation_url, 264 presentation_url,
208 base::Bind( 265 base::Bind(
209 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, 266 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback,
210 base::Unretained(this), 267 base::Unretained(this),
211 true), 268 true),
(...skipping 13 matching lines...) Expand all
225 } 282 }
226 283
227 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) { 284 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) {
228 std::string presentation_url("http://fooUrl"); 285 std::string presentation_url("http://fooUrl");
229 GetScreenAvailabilityAndWait( 286 GetScreenAvailabilityAndWait(
230 presentation_url, 287 presentation_url,
231 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, 288 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled,
232 base::Unretained(this)), 289 base::Unretained(this)),
233 true); 290 true);
234 291
292 ExpectReset();
235 service_impl_->RenderFrameDeleted(contents()->GetMainFrame()); 293 service_impl_->RenderFrameDeleted(contents()->GetMainFrame());
236 294 ExpectCleanState();
237 ExpectListenerDoesNotExist(presentation_url);
238 } 295 }
239 296
240 TEST_F(PresentationServiceImplTest, NotThisRenderFrameDeleted) { 297 TEST_F(PresentationServiceImplTest, NotThisRenderFrameDeleted) {
241 std::string presentation_url("http://fooUrl"); 298 std::string presentation_url("http://fooUrl");
242 GetScreenAvailabilityAndWait( 299 GetScreenAvailabilityAndWait(
243 presentation_url, 300 presentation_url,
244 base::Bind( 301 base::Bind(
245 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, 302 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback,
246 base::Unretained(this), 303 base::Unretained(this),
247 true), 304 true),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 std::string presentation_url("http://fooUrl"); 346 std::string presentation_url("http://fooUrl");
290 GetScreenAvailabilityAndWait( 347 GetScreenAvailabilityAndWait(
291 presentation_url, 348 presentation_url,
292 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, 349 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled,
293 base::Unretained(this)), 350 base::Unretained(this)),
294 false); 351 false);
295 352
296 ExpectListenerDoesNotExist(presentation_url); 353 ExpectListenerDoesNotExist(presentation_url);
297 } 354 }
298 355
356 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) {
357 std::string url1("http://fooUrl");
358 std::string dpu_id("dpuId");
359 EXPECT_CALL(mock_delegate_,
360 SetDefaultPresentationUrl(_, _, Eq(url1), Eq(dpu_id)))
361 .Times(1);
362 service_impl_->SetDefaultPresentationURL(url1, dpu_id);
363 EXPECT_EQ(url1, service_impl_->default_presentation_url_);
364
365 // Now there should be a callback registered with the DPU.
366 GetScreenAvailabilityAndWait(
367 url1,
368 base::Bind(
369 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback,
370 base::Unretained(this), true),
371 true);
372 const auto& contexts = service_impl_->availability_contexts_;
373 auto it = contexts.find(url1);
374 ASSERT_TRUE(it != contexts.end());
375 EXPECT_NE(nullptr, it->second->GetCallback());
376
377 std::string url2("http://barUrl");
378 // Sets different DPU.
379 // Adds listener for url2 and removes listener for url1.
380 // Also, the callback from url1 is transferred to url2.
381 EXPECT_CALL(
382 mock_delegate_,
383 AddScreenAvailabilityListener(_, _, _))
384 .WillOnce(Return(true));
385 EXPECT_CALL(
386 mock_delegate_,
387 RemoveScreenAvailabilityListener(_, _, _))
388 .Times(1);
389 EXPECT_CALL(mock_delegate_,
390 SetDefaultPresentationUrl(_, _, Eq(url2), Eq(dpu_id)))
391 .Times(1);
392 service_impl_->SetDefaultPresentationURL(url2, dpu_id);
393 EXPECT_EQ(url2, service_impl_->default_presentation_url_);
394
395 it = contexts.find(url2);
396 ASSERT_TRUE(it != contexts.end());
397 EXPECT_NE(nullptr, it->second->GetCallback());
398 }
399
400 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) {
401 std::string url("http://fooUrl");
402 std::string dpu_id("dpuId");
403 EXPECT_CALL(mock_delegate_,
404 SetDefaultPresentationUrl(_, _, Eq(url), Eq(dpu_id)))
405 .Times(1);
406 service_impl_->SetDefaultPresentationURL(url, dpu_id);
407 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
408 EXPECT_EQ(url, service_impl_->default_presentation_url_);
409
410 // Same URL as before; no-ops.
411 service_impl_->SetDefaultPresentationURL(url, dpu_id);
412 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_));
413 EXPECT_EQ(url, service_impl_->default_presentation_url_);
414 }
415
416 TEST_F(PresentationServiceImplTest, ClearDefaultPresentationUrl) {
417 std::string url("http://fooUrl");
418 std::string dpu_id("dpuId");
419 EXPECT_CALL(mock_delegate_,
420 SetDefaultPresentationUrl(_, _, Eq(url), Eq(dpu_id)))
421 .Times(1);
422 service_impl_->SetDefaultPresentationURL(url, dpu_id);
423 EXPECT_EQ(url, service_impl_->default_presentation_url_);
424
425 // Now there should be a callback registered with the DPU.
426 GetScreenAvailabilityAndWait(
427 url,
428 base::Bind(
429 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback,
430 base::Unretained(this), true),
431 true);
432
433 const auto& contexts = service_impl_->availability_contexts_;
434 auto it = contexts.find(url);
435 ASSERT_TRUE(it != contexts.end());
436 EXPECT_NE(nullptr, it->second->GetCallback());
437
438 // Clears the default presentation URL. Transfers the listener from url to
439 // "1-UA" mode.
440 EXPECT_CALL(
441 mock_delegate_,
442 AddScreenAvailabilityListener(_, _, _))
443 .WillOnce(Return(true));
444 EXPECT_CALL(
445 mock_delegate_,
446 RemoveScreenAvailabilityListener(_, _, _))
447 .Times(1);
448 EXPECT_CALL(
449 mock_delegate_,
450 SetDefaultPresentationUrl(_, _, Eq(std::string()), Eq(std::string())))
451 .Times(1);
452 service_impl_->SetDefaultPresentationURL(std::string(), std::string());
453 EXPECT_TRUE(service_impl_->default_presentation_url_.empty());
454
455 it = contexts.find(url);
456 ASSERT_TRUE(it == contexts.end());
457 }
458
459 TEST_F(PresentationServiceImplTest, StartSessionSuccess) {
460 std::string presentation_url("http://fooUrl");
461 std::string presentation_id("presentationId");
462 service_ptr_->StartSession(
463 presentation_url,
464 presentation_id,
465 base::Bind(
466 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
467 base::Unretained(this)));
468 base::RunLoop run_loop;
469 base::Callback<void(const PresentationSessionInfo&)> success_cb;
470 EXPECT_CALL(mock_delegate_, StartSession(
471 _, _, Eq(presentation_url), Eq(presentation_id), _, _))
472 .WillOnce(DoAll(
473 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
474 SaveArg<4>(&success_cb)));
475 run_loop.Run();
476 success_cb.Run(PresentationSessionInfo(presentation_url, presentation_id));
477 SaveQuitClosureAndRunLoop();
478 }
479
480 TEST_F(PresentationServiceImplTest, StartSessionError) {
481 std::string presentation_url("http://fooUrl");
482 std::string presentation_id("presentationId");
483 service_ptr_->StartSession(
484 presentation_url,
485 presentation_id,
486 base::Bind(
487 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
488 base::Unretained(this)));
489 base::RunLoop run_loop;
490 base::Callback<void(const PresentationError&)> error_cb;
491 EXPECT_CALL(mock_delegate_, StartSession(
492 _, _, Eq(presentation_url), Eq(presentation_id), _, _))
493 .WillOnce(DoAll(
494 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
495 SaveArg<5>(&error_cb)));
496 run_loop.Run();
497 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message"));
498 SaveQuitClosureAndRunLoop();
499 }
500
501 TEST_F(PresentationServiceImplTest, JoinSessionSuccess) {
502 std::string presentation_url("http://fooUrl");
503 std::string presentation_id("presentationId");
504 service_ptr_->JoinSession(
505 presentation_url,
506 presentation_id,
507 base::Bind(
508 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
509 base::Unretained(this)));
510 base::RunLoop run_loop;
511 base::Callback<void(const PresentationSessionInfo&)> success_cb;
512 EXPECT_CALL(mock_delegate_, JoinSession(
513 _, _, Eq(presentation_url), Eq(presentation_id), _, _))
514 .WillOnce(DoAll(
515 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
516 SaveArg<4>(&success_cb)));
517 run_loop.Run();
518 success_cb.Run(PresentationSessionInfo(presentation_url, presentation_id));
519 SaveQuitClosureAndRunLoop();
520 }
521
522 TEST_F(PresentationServiceImplTest, JoinSessionError) {
523 std::string presentation_url("http://fooUrl");
524 std::string presentation_id("presentationId");
525 service_ptr_->JoinSession(
526 presentation_url,
527 presentation_id,
528 base::Bind(
529 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackError,
530 base::Unretained(this)));
531 base::RunLoop run_loop;
532 base::Callback<void(const PresentationError&)> error_cb;
533 EXPECT_CALL(mock_delegate_, JoinSession(
534 _, _, Eq(presentation_url), Eq(presentation_id), _, _))
535 .WillOnce(DoAll(
536 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
537 SaveArg<5>(&error_cb)));
538 run_loop.Run();
539 error_cb.Run(PresentationError(PRESENTATION_ERROR_UNKNOWN, "Error message"));
540 SaveQuitClosureAndRunLoop();
541 }
542
543 TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
544 std::string presentation_url1("http://fooUrl");
545 std::string presentation_id1("presentationId1");
546 std::string presentation_url2("http://barUrl");
547 std::string presentation_id2("presentationId2");
548 service_ptr_->StartSession(
549 presentation_url1,
550 presentation_id1,
551 base::Bind(
552 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
553 base::Unretained(this)));
554 service_ptr_->StartSession(
555 presentation_url2,
556 presentation_id2,
557 base::Bind(
558 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess,
559 base::Unretained(this)));
560 base::RunLoop run_loop;
561 base::Callback<void(const PresentationSessionInfo&)> success_cb;
562 EXPECT_CALL(mock_delegate_, StartSession(
563 _, _, Eq(presentation_url1), Eq(presentation_id1), _, _))
564 .WillOnce(DoAll(
565 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
566 SaveArg<4>(&success_cb)));
567 run_loop.Run();
568
569 // Running the callback means the first request is done. It should now
570 // move on to the queued request.
571 EXPECT_CALL(mock_delegate_, StartSession(
572 _, _, Eq(presentation_url2), Eq(presentation_id2), _, _))
573 .Times(1);
574 success_cb.Run(PresentationSessionInfo(presentation_url1, presentation_id1));
575 SaveQuitClosureAndRunLoop();
576 }
577
299 } // namespace content 578 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/presentation/presentation_service_impl.cc ('k') | content/browser/presentation/presentation_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698