Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "content/renderer/presentation/presentation_dispatcher.h" | 10 #include "content/renderer/presentation/presentation_dispatcher.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 // - Screen availability not supported | 42 // - Screen availability not supported |
| 43 // - Default presentation starting | 43 // - Default presentation starting |
| 44 | 44 |
| 45 namespace content { | 45 namespace content { |
| 46 | 46 |
| 47 class MockPresentationAvailabilityObserver | 47 class MockPresentationAvailabilityObserver |
| 48 : public WebPresentationAvailabilityObserver { | 48 : public WebPresentationAvailabilityObserver { |
| 49 public: | 49 public: |
| 50 explicit MockPresentationAvailabilityObserver(const WebVector<WebURL>& urls) | 50 explicit MockPresentationAvailabilityObserver(const WebVector<WebURL>& urls) |
| 51 : urls_(urls) {} | 51 : urls_(urls) {} |
| 52 explicit MockPresentationAvailabilityObserver(const std::vector<GURL>& gurls) | |
|
mark a. foltz
2017/01/13 19:01:16
Do we need both mock constructors?
zhaobin
2017/01/14 01:45:33
Done.
| |
| 53 : urls_(gurls) {} | |
| 52 ~MockPresentationAvailabilityObserver() override {} | 54 ~MockPresentationAvailabilityObserver() override {} |
| 53 | 55 |
| 54 MOCK_METHOD1(availabilityChanged, void(bool is_available)); | 56 MOCK_METHOD1(availabilityChanged, void(bool is_available)); |
| 55 const WebVector<WebURL>& urls() const override { return urls_; } | 57 const WebVector<WebURL>& urls() const override { return urls_; } |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 const WebVector<WebURL> urls_; | 60 const WebVector<WebURL> urls_; |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 class MockPresentationService : public PresentationService { | 63 class MockPresentationService : public PresentationService { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 // *Internal method is to work around lack of support for move-only types in | 100 // *Internal method is to work around lack of support for move-only types in |
| 99 // GMock. | 101 // GMock. |
| 100 void ListenForConnectionMessages( | 102 void ListenForConnectionMessages( |
| 101 PresentationSessionInfoPtr session_info) override { | 103 PresentationSessionInfoPtr session_info) override { |
| 102 ListenForConnectionMessagesInternal(session_info.get()); | 104 ListenForConnectionMessagesInternal(session_info.get()); |
| 103 } | 105 } |
| 104 MOCK_METHOD1(ListenForConnectionMessagesInternal, | 106 MOCK_METHOD1(ListenForConnectionMessagesInternal, |
| 105 void(PresentationSessionInfo* session_info)); | 107 void(PresentationSessionInfo* session_info)); |
| 106 }; | 108 }; |
| 107 | 109 |
| 110 class MockPresentationAvailabilityCallbacks final | |
| 111 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> { | |
| 112 public: | |
| 113 MOCK_METHOD1(onSuccess, void(bool value)); | |
| 114 MOCK_METHOD1(onError, void(const blink::WebPresentationError&)); | |
| 115 }; | |
| 116 | |
| 108 class TestWebPresentationConnectionCallback | 117 class TestWebPresentationConnectionCallback |
| 109 : public WebPresentationConnectionCallback { | 118 : public WebPresentationConnectionCallback { |
| 110 public: | 119 public: |
| 111 TestWebPresentationConnectionCallback(WebURL url, WebString id) | 120 TestWebPresentationConnectionCallback(WebURL url, WebString id) |
| 112 : url_(url), id_(id), callback_called_(false) {} | 121 : url_(url), id_(id), callback_called_(false) {} |
| 113 ~TestWebPresentationConnectionCallback() override { | 122 ~TestWebPresentationConnectionCallback() override { |
| 114 EXPECT_TRUE(callback_called_); | 123 EXPECT_TRUE(callback_called_); |
| 115 } | 124 } |
| 116 | 125 |
| 117 void onSuccess(const WebPresentationSessionInfo& info) override { | 126 void onSuccess(const WebPresentationSessionInfo& info) override { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 mojo::MakeRequest(&presentation_service_)); | 174 mojo::MakeRequest(&presentation_service_)); |
| 166 } | 175 } |
| 167 } | 176 } |
| 168 | 177 |
| 169 MockPresentationService* mock_presentation_service_; | 178 MockPresentationService* mock_presentation_service_; |
| 170 std::unique_ptr<mojo::Binding<PresentationService>> mock_binding_; | 179 std::unique_ptr<mojo::Binding<PresentationService>> mock_binding_; |
| 171 }; | 180 }; |
| 172 | 181 |
| 173 class PresentationDispatcherTest : public ::testing::Test { | 182 class PresentationDispatcherTest : public ::testing::Test { |
| 174 public: | 183 public: |
| 184 enum class URLState { Available, Unavailable, Unsupported }; | |
| 185 | |
| 175 PresentationDispatcherTest() | 186 PresentationDispatcherTest() |
| 176 : gurl1_(GURL("https://www.example.com/1.html")), | 187 : gurl1_(GURL("https://www.example.com/1.html")), |
| 177 gurl2_(GURL("https://www.example.com/2.html")), | 188 gurl2_(GURL("https://www.example.com/2.html")), |
| 178 gurls_({gurl1_, gurl2_}), | 189 gurl3_(GURL("https://www.example.com/3.html")), |
| 190 gurl4_(GURL("https://www.example.com/4.html")), | |
| 191 gurls_({gurl1_, gurl2_, gurl3_, gurl4_}), | |
| 179 url1_(WebURL(gurl1_)), | 192 url1_(WebURL(gurl1_)), |
| 180 url2_(WebURL(gurl2_)), | 193 url2_(WebURL(gurl2_)), |
| 194 url3_(WebURL(gurl3_)), | |
| 195 url4_(WebURL(gurl4_)), | |
| 181 urls_(WebVector<WebURL>(gurls_)), | 196 urls_(WebVector<WebURL>(gurls_)), |
| 182 presentation_id_(WebString::fromUTF8("test-id")), | 197 presentation_id_(WebString::fromUTF8("test-id")), |
| 183 array_buffer_(WebArrayBuffer::create(4, 1)), | 198 array_buffer_(WebArrayBuffer::create(4, 1)), |
| 184 observer_(urls_), | 199 observer_(urls_), |
| 200 mock_observer1_({gurl1_, gurl2_, gurl3_}), | |
| 201 mock_observer2_({gurl2_, gurl3_, gurl4_}), | |
| 202 mock_observer3_({gurl2_, gurl3_}), | |
| 203 mock_observers_({&mock_observer1_, &mock_observer2_, &mock_observer3_}), | |
| 185 dispatcher_(&presentation_service_) {} | 204 dispatcher_(&presentation_service_) {} |
| 205 | |
| 186 ~PresentationDispatcherTest() override {} | 206 ~PresentationDispatcherTest() override {} |
| 187 | 207 |
| 188 void SetUp() override { | 208 void SetUp() override { |
| 189 // Set some test data. | 209 // Set some test data. |
| 190 *array_buffer_data() = 42; | 210 *array_buffer_data() = 42; |
| 191 } | 211 } |
| 192 | 212 |
| 193 uint8_t* array_buffer_data() { | 213 uint8_t* array_buffer_data() { |
| 194 return static_cast<uint8_t*>(array_buffer_.data()); | 214 return static_cast<uint8_t*>(array_buffer_.data()); |
| 195 } | 215 } |
| 196 | 216 |
| 217 void ChangeURLState(const GURL& gurl, URLState state) { | |
|
mark a. foltz
2017/01/13 19:01:15
s|gurl|url|
zhaobin
2017/01/14 01:45:33
Done.
| |
| 218 switch (state) { | |
| 219 case URLState::Available: | |
| 220 dispatcher_.OnScreenAvailabilityUpdated(gurl, true); | |
| 221 break; | |
| 222 case URLState::Unavailable: | |
| 223 dispatcher_.OnScreenAvailabilityUpdated(gurl, false); | |
| 224 break; | |
| 225 case URLState::Unsupported: | |
| 226 dispatcher_.OnScreenAvailabilityNotSupported(gurl); | |
| 227 break; | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 void StartListening(MockPresentationAvailabilityObserver* observer) { | |
| 232 dispatcher_.startListening(observer); | |
|
mark a. foltz
2017/01/13 19:01:16
Since |dispatcher_| is protected, it should be pos
zhaobin
2017/01/14 01:45:33
Done.
| |
| 233 } | |
| 234 | |
| 235 void StopListening(MockPresentationAvailabilityObserver* observer) { | |
| 236 dispatcher_.stopListening(observer); | |
|
mark a. foltz
2017/01/13 19:01:16
Similar comment as StartListening().
zhaobin
2017/01/14 01:45:33
Done.
| |
| 237 } | |
| 238 | |
| 239 void TestGetAvailability( | |
|
mark a. foltz
2017/01/13 19:01:16
Can you document what this is testing? E.g.,
Test
zhaobin
2017/01/14 01:45:33
Done.
| |
| 240 const blink::WebVector<blink::WebURL>& urls, | |
| 241 const std::vector<URLState>& states, | |
| 242 MockPresentationAvailabilityCallbacks* mock_callback) { | |
| 243 for (const auto& url : urls) { | |
| 244 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(GURL(url))) | |
| 245 .Times(1); | |
| 246 } | |
| 247 | |
| 248 base::RunLoop run_loop; | |
| 249 client()->getAvailability(urls, base::WrapUnique(mock_callback)); | |
|
mark a. foltz
2017/01/13 19:01:17
Document that this function takes ownership of |mo
zhaobin
2017/01/14 01:45:33
Done.
| |
| 250 for (size_t i = 0; i < std::min(urls.size(), states.size()); i++) | |
|
mark a. foltz
2017/01/13 19:01:15
Should you require urls.size() == states.size()?
zhaobin
2017/01/14 01:45:33
Done.
| |
| 251 ChangeURLState(urls[i], states[i]); | |
|
mark a. foltz
2017/01/13 19:01:16
Nit: blank line after loop statement
zhaobin
2017/01/14 01:45:33
Done.
| |
| 252 run_loop.RunUntilIdle(); | |
|
mark a. foltz
2017/01/13 19:01:15
It seems like in most cases |mock_callback| will b
zhaobin
2017/01/14 01:45:33
Set in test cases below.
| |
| 253 } | |
| 254 | |
| 255 blink::WebPresentationClient* client() { return &dispatcher_; } | |
| 256 | |
| 197 protected: | 257 protected: |
| 198 const GURL gurl1_; | 258 const GURL gurl1_; |
| 199 const GURL gurl2_; | 259 const GURL gurl2_; |
| 260 const GURL gurl3_; | |
| 261 const GURL gurl4_; | |
| 200 const std::vector<GURL> gurls_; | 262 const std::vector<GURL> gurls_; |
| 201 const WebURL url1_; | 263 const WebURL url1_; |
| 202 const WebURL url2_; | 264 const WebURL url2_; |
| 265 const WebURL url3_; | |
| 266 const WebURL url4_; | |
| 203 const WebVector<WebURL> urls_; | 267 const WebVector<WebURL> urls_; |
| 268 const std::vector<blink::WebVector<blink::WebURL>> urls_set_; | |
|
mark a. foltz
2017/01/13 19:01:16
|urls_| ?
zhaobin
2017/01/14 01:45:33
removed :)
| |
| 204 const WebString presentation_id_; | 269 const WebString presentation_id_; |
| 205 const WebArrayBuffer array_buffer_; | 270 const WebArrayBuffer array_buffer_; |
| 206 MockPresentationAvailabilityObserver observer_; | 271 MockPresentationAvailabilityObserver observer_; |
| 272 MockPresentationAvailabilityObserver mock_observer1_; | |
| 273 MockPresentationAvailabilityObserver mock_observer2_; | |
| 274 MockPresentationAvailabilityObserver mock_observer3_; | |
| 275 std::vector<MockPresentationAvailabilityObserver*> mock_observers_; | |
| 276 | |
| 207 MockPresentationService presentation_service_; | 277 MockPresentationService presentation_service_; |
| 208 TestPresentationDispatcher dispatcher_; | 278 TestPresentationDispatcher dispatcher_; |
| 209 | 279 |
| 210 private: | 280 private: |
| 211 content::TestBrowserThreadBundle thread_bundle_; | 281 content::TestBrowserThreadBundle thread_bundle_; |
| 212 }; | 282 }; |
| 213 | 283 |
| 214 TEST_F(PresentationDispatcherTest, TestStartSession) { | 284 TEST_F(PresentationDispatcherTest, TestStartSession) { |
| 215 base::RunLoop run_loop; | 285 base::RunLoop run_loop; |
| 216 | 286 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 TEST_F(PresentationDispatcherTest, TestTerminateSession) { | 435 TEST_F(PresentationDispatcherTest, TestTerminateSession) { |
| 366 base::RunLoop run_loop; | 436 base::RunLoop run_loop; |
| 367 EXPECT_CALL(presentation_service_, | 437 EXPECT_CALL(presentation_service_, |
| 368 Terminate(gurl1_, presentation_id_.utf8())); | 438 Terminate(gurl1_, presentation_id_.utf8())); |
| 369 dispatcher_.terminateSession(url1_, presentation_id_); | 439 dispatcher_.terminateSession(url1_, presentation_id_); |
| 370 run_loop.RunUntilIdle(); | 440 run_loop.RunUntilIdle(); |
| 371 } | 441 } |
| 372 | 442 |
| 373 TEST_F(PresentationDispatcherTest, TestListenForScreenAvailability) { | 443 TEST_F(PresentationDispatcherTest, TestListenForScreenAvailability) { |
| 374 base::RunLoop run_loop1; | 444 base::RunLoop run_loop1; |
| 375 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl1_)); | 445 for (const auto& gurl : gurls_) |
| 446 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl)); | |
| 376 dispatcher_.getAvailability( | 447 dispatcher_.getAvailability( |
| 377 urls_, base::MakeUnique<WebPresentationAvailabilityCallbacks>()); | 448 urls_, base::MakeUnique<WebPresentationAvailabilityCallbacks>()); |
| 378 dispatcher_.OnScreenAvailabilityUpdated(url1_, true); | 449 dispatcher_.OnScreenAvailabilityUpdated(url1_, true); |
| 379 run_loop1.RunUntilIdle(); | 450 run_loop1.RunUntilIdle(); |
| 380 | 451 |
| 381 base::RunLoop run_loop2; | 452 base::RunLoop run_loop2; |
| 382 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl1_)); | |
| 383 dispatcher_.startListening(&observer_); | 453 dispatcher_.startListening(&observer_); |
| 384 run_loop2.RunUntilIdle(); | 454 run_loop2.RunUntilIdle(); |
| 385 | 455 |
| 386 base::RunLoop run_loop3; | 456 base::RunLoop run_loop3; |
| 387 EXPECT_CALL(observer_, availabilityChanged(false)); | 457 EXPECT_CALL(observer_, availabilityChanged(false)); |
| 388 dispatcher_.OnScreenAvailabilityUpdated(url1_, false); | 458 dispatcher_.OnScreenAvailabilityUpdated(url1_, false); |
| 389 EXPECT_CALL(observer_, availabilityChanged(true)); | 459 EXPECT_CALL(observer_, availabilityChanged(true)); |
| 390 dispatcher_.OnScreenAvailabilityUpdated(url1_, true); | 460 dispatcher_.OnScreenAvailabilityUpdated(url1_, true); |
| 391 EXPECT_CALL(presentation_service_, | 461 for (const auto& gurl : gurls_) { |
| 392 StopListeningForScreenAvailability(gurl1_)); | 462 EXPECT_CALL(presentation_service_, |
| 463 StopListeningForScreenAvailability(gurl)); | |
| 464 } | |
| 393 dispatcher_.stopListening(&observer_); | 465 dispatcher_.stopListening(&observer_); |
| 394 run_loop3.RunUntilIdle(); | 466 run_loop3.RunUntilIdle(); |
| 395 | 467 |
| 396 // After stopListening(), |observer_| should no longer be notified. | 468 // After stopListening(), |observer_| should no longer be notified. |
| 397 base::RunLoop run_loop4; | 469 base::RunLoop run_loop4; |
| 398 EXPECT_CALL(observer_, availabilityChanged(false)).Times(0); | 470 EXPECT_CALL(observer_, availabilityChanged(false)).Times(0); |
| 399 dispatcher_.OnScreenAvailabilityUpdated(url1_, false); | 471 dispatcher_.OnScreenAvailabilityUpdated(url1_, false); |
| 400 run_loop4.RunUntilIdle(); | 472 run_loop4.RunUntilIdle(); |
| 401 } | 473 } |
| 402 | 474 |
| 403 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { | 475 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { |
| 404 base::RunLoop run_loop; | 476 base::RunLoop run_loop; |
| 405 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); | 477 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); |
| 406 dispatcher_.setDefaultPresentationUrls(urls_); | 478 dispatcher_.setDefaultPresentationUrls(urls_); |
| 407 run_loop.RunUntilIdle(); | 479 run_loop.RunUntilIdle(); |
| 408 } | 480 } |
| 409 | 481 |
| 482 TEST_F(PresentationDispatcherTest, GetAvailabilityOneUrlNoAvailabilityChange) { | |
| 483 auto* mock_callback = new MockPresentationAvailabilityCallbacks(); | |
|
mark a. foltz
2017/01/13 19:01:16
You can use a StrictMock<> to verify that mock_cal
zhaobin
2017/01/14 01:45:33
Done.
| |
| 484 blink::WebVector<blink::WebURL> urls(std::vector<GURL>({url1_})); | |
| 485 std::vector<URLState> states; | |
| 486 TestGetAvailability(urls, states, mock_callback); | |
|
mark a. foltz
2017/01/13 19:01:16
Could this just take a vector<GURL> and convert to
zhaobin
2017/01/14 01:45:33
Done.
| |
| 487 } | |
| 488 | |
| 489 TEST_F(PresentationDispatcherTest, GetAvailabilityOneUrlBecomesAvailable) { | |
| 490 auto* mock_callback = new MockPresentationAvailabilityCallbacks(); | |
| 491 EXPECT_CALL(*mock_callback, onSuccess(true)); | |
|
mark a. foltz
2017/01/13 19:01:16
Nit: consistently add a blank line after setting e
zhaobin
2017/01/14 01:45:33
Done.
| |
| 492 blink::WebVector<blink::WebURL> urls(std::vector<GURL>({url1_})); | |
| 493 std::vector<URLState> states = {URLState::Available}; | |
| 494 TestGetAvailability(urls, states, mock_callback); | |
| 495 } | |
| 496 | |
| 497 TEST_F(PresentationDispatcherTest, GetAvailabilityOneUrlBecomesUnavailable) { | |
| 498 auto* mock_callback = new MockPresentationAvailabilityCallbacks(); | |
| 499 EXPECT_CALL(*mock_callback, onSuccess(false)); | |
| 500 | |
| 501 blink::WebVector<blink::WebURL> urls(std::vector<GURL>({url1_})); | |
| 502 std::vector<URLState> states = {URLState::Unavailable}; | |
| 503 TestGetAvailability(urls, states, mock_callback); | |
| 504 } | |
| 505 | |
| 506 TEST_F(PresentationDispatcherTest, GetAvailabilityOneUrlBecomesNotSupported) { | |
| 507 auto* mock_callback = new MockPresentationAvailabilityCallbacks(); | |
| 508 EXPECT_CALL(*mock_callback, onError(_)); | |
| 509 EXPECT_CALL(presentation_service_, | |
| 510 StopListeningForScreenAvailability(gurl1_)); | |
| 511 | |
| 512 blink::WebVector<blink::WebURL> urls(std::vector<GURL>({url1_})); | |
| 513 std::vector<URLState> states = {URLState::Unsupported}; | |
| 514 TestGetAvailability(urls, states, mock_callback); | |
| 515 } | |
| 516 | |
| 517 TEST_F(PresentationDispatcherTest, | |
| 518 GetAvailabilityMultipleUrlsAllBecomesAvailable) { | |
| 519 auto* mock_callback = new MockPresentationAvailabilityCallbacks(); | |
| 520 EXPECT_CALL(*mock_callback, onSuccess(true)).Times(1); | |
| 521 | |
| 522 blink::WebVector<blink::WebURL> urls(std::vector<GURL>({url1_, url2_})); | |
| 523 std::vector<URLState> state_seq = {URLState::Available, URLState::Available}; | |
| 524 TestGetAvailability(urls, state_seq, mock_callback); | |
| 525 } | |
| 526 | |
| 527 TEST_F(PresentationDispatcherTest, | |
| 528 GetAvailabilityMultipleUrlsAllBecomesUnavailable) { | |
| 529 auto* mock_callback = new MockPresentationAvailabilityCallbacks(); | |
| 530 EXPECT_CALL(*mock_callback, onSuccess(false)).Times(1); | |
| 531 | |
| 532 blink::WebVector<blink::WebURL> urls(std::vector<GURL>({url1_, url2_})); | |
| 533 std::vector<URLState> state_seq = {URLState::Unavailable, | |
| 534 URLState::Unavailable}; | |
| 535 TestGetAvailability(urls, state_seq, mock_callback); | |
| 536 } | |
| 537 | |
| 538 TEST_F(PresentationDispatcherTest, | |
| 539 GetAvailabilityMultipleUrlsAllBecomesUnsupported) { | |
| 540 auto* mock_callback = new MockPresentationAvailabilityCallbacks(); | |
| 541 EXPECT_CALL(*mock_callback, onError(_)).Times(1); | |
| 542 EXPECT_CALL(presentation_service_, | |
| 543 StopListeningForScreenAvailability(gurl1_)); | |
| 544 EXPECT_CALL(presentation_service_, | |
| 545 StopListeningForScreenAvailability(gurl2_)); | |
| 546 | |
| 547 blink::WebVector<blink::WebURL> urls(std::vector<GURL>({url1_, url2_})); | |
| 548 std::vector<URLState> state_seq = {URLState::Unsupported, | |
| 549 URLState::Unsupported}; | |
| 550 TestGetAvailability(urls, state_seq, mock_callback); | |
| 551 } | |
| 552 | |
| 553 TEST_F(PresentationDispatcherTest, | |
| 554 GetAvailabilityReturnsDirectlyForAlreadyListeningUrls) { | |
| 555 auto* mock_callback_1 = new MockPresentationAvailabilityCallbacks(); | |
| 556 EXPECT_CALL(*mock_callback_1, onSuccess(false)).Times(1); | |
| 557 | |
| 558 std::vector<URLState> state_seq = {URLState::Unavailable, URLState::Available, | |
| 559 URLState::Unavailable}; | |
| 560 TestGetAvailability(mock_observer1_.urls(), state_seq, mock_callback_1); | |
| 561 | |
| 562 auto* mock_callback_2 = new MockPresentationAvailabilityCallbacks(); | |
| 563 EXPECT_CALL(*mock_callback_2, onSuccess(true)).Times(1); | |
| 564 | |
| 565 base::RunLoop run_loop; | |
| 566 client()->getAvailability(mock_observer3_.urls(), | |
| 567 base::WrapUnique(mock_callback_2)); | |
| 568 run_loop.RunUntilIdle(); | |
| 569 } | |
| 570 | |
| 571 TEST_F(PresentationDispatcherTest, StartListeningListenToEachURLOnce) { | |
| 572 for (const auto& gurl : gurls_) { | |
| 573 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl)) | |
| 574 .Times(1); | |
| 575 } | |
| 576 | |
| 577 base::RunLoop run_loop; | |
| 578 for (auto* mock_observer : mock_observers_) { | |
| 579 client()->getAvailability( | |
| 580 mock_observer->urls(), | |
| 581 base::MakeUnique<WebPresentationAvailabilityCallbacks>()); | |
| 582 StartListening(mock_observer); | |
| 583 } | |
| 584 run_loop.RunUntilIdle(); | |
| 585 } | |
| 586 | |
| 587 TEST_F(PresentationDispatcherTest, StopListeningListenToEachURLOnce) { | |
| 588 for (const auto& gurl : gurls_) { | |
| 589 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl)) | |
| 590 .Times(1); | |
| 591 EXPECT_CALL(presentation_service_, StopListeningForScreenAvailability(gurl)) | |
| 592 .Times(1); | |
| 593 } | |
| 594 | |
| 595 // Set up |availability_set_| and |listening_status_| | |
| 596 base::RunLoop run_loop; | |
| 597 for (auto* mock_observer : mock_observers_) { | |
| 598 client()->getAvailability( | |
| 599 mock_observer->urls(), | |
| 600 base::MakeUnique<WebPresentationAvailabilityCallbacks>()); | |
| 601 } | |
| 602 // Clean up callbacks. | |
| 603 ChangeURLState(gurl2_, URLState::Unavailable); | |
| 604 | |
| 605 for (auto* mock_observer : mock_observers_) | |
| 606 StartListening(mock_observer); | |
| 607 for (auto* mock_observer : mock_observers_) | |
| 608 StopListening(mock_observer); | |
| 609 | |
| 610 run_loop.RunUntilIdle(); | |
| 611 } | |
| 612 | |
| 613 TEST_F(PresentationDispatcherTest, | |
| 614 StopListeningDoesNotStopIfURLListenedByOthers) { | |
| 615 for (const auto& gurl : gurls_) { | |
| 616 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl)) | |
| 617 .Times(1); | |
| 618 } | |
| 619 EXPECT_CALL(presentation_service_, StopListeningForScreenAvailability(gurl1_)) | |
| 620 .Times(1); | |
| 621 EXPECT_CALL(presentation_service_, StopListeningForScreenAvailability(gurl2_)) | |
| 622 .Times(0); | |
| 623 EXPECT_CALL(presentation_service_, StopListeningForScreenAvailability(gurl3_)) | |
| 624 .Times(0); | |
| 625 | |
| 626 // Set up |availability_set_| and |listening_status_| | |
| 627 base::RunLoop run_loop; | |
| 628 for (auto& mock_observer : mock_observers_) { | |
| 629 client()->getAvailability( | |
| 630 mock_observer->urls(), | |
| 631 base::MakeUnique<WebPresentationAvailabilityCallbacks>()); | |
| 632 } | |
| 633 | |
| 634 // Clean up callbacks. | |
| 635 ChangeURLState(gurl2_, URLState::Unavailable); | |
|
mark a. foltz
2017/01/13 19:01:16
Set expectation that mock_observer{1,2}_ will have
zhaobin
2017/01/14 01:45:33
Done.
| |
| 636 | |
| 637 for (auto* mock_observer : mock_observers_) | |
| 638 StartListening(mock_observer); | |
| 639 StopListening(&mock_observer1_); | |
| 640 | |
| 641 run_loop.RunUntilIdle(); | |
| 642 } | |
| 643 | |
| 644 TEST_F(PresentationDispatcherTest, | |
| 645 OnScreenAvailabilityUpdatedInvokesAvailabilityChanged) { | |
| 646 for (const auto& gurl : gurls_) { | |
| 647 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl)) | |
| 648 .Times(1); | |
| 649 } | |
| 650 | |
| 651 EXPECT_CALL(mock_observer1_, availabilityChanged(true)); | |
| 652 | |
| 653 base::RunLoop run_loop; | |
| 654 for (auto* mock_observer : mock_observers_) { | |
| 655 client()->getAvailability( | |
| 656 mock_observer->urls(), | |
| 657 base::MakeUnique<WebPresentationAvailabilityCallbacks>()); | |
| 658 StartListening(mock_observer); | |
| 659 } | |
| 660 | |
| 661 ChangeURLState(gurl1_, URLState::Available); | |
|
mark a. foltz
2017/01/13 19:01:16
Can you change the state to Unavailable and test t
zhaobin
2017/01/14 01:45:33
Done.
| |
| 662 run_loop.RunUntilIdle(); | |
| 663 } | |
| 664 | |
| 665 TEST_F(PresentationDispatcherTest, | |
| 666 OnScreenAvailabilityUpdatedInvokesMultipleAvailabilityChanged) { | |
|
mark a. foltz
2017/01/13 19:01:15
I didn't see any test of availabilityChanged() in
zhaobin
2017/01/14 01:45:33
Done.
| |
| 667 for (const auto& gurl : gurls_) { | |
| 668 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl)) | |
| 669 .Times(1); | |
| 670 } | |
| 671 | |
| 672 base::RunLoop run_loop; | |
| 673 for (auto* mock_observer : mock_observers_) { | |
| 674 EXPECT_CALL(*mock_observer, availabilityChanged(true)); | |
| 675 client()->getAvailability( | |
| 676 mock_observer->urls(), | |
| 677 base::MakeUnique<WebPresentationAvailabilityCallbacks>()); | |
| 678 StartListening(mock_observer); | |
| 679 } | |
| 680 | |
| 681 ChangeURLState(gurl2_, URLState::Available); | |
| 682 run_loop.RunUntilIdle(); | |
| 683 } | |
| 684 | |
| 410 } // namespace content | 685 } // namespace content |
| OLD | NEW |