| 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 29 matching lines...) Expand all Loading... |
| 40 // - Messages received | 40 // - Messages received |
| 41 // - Discarding queued messages when the frame navigates | 41 // - Discarding queued messages when the frame navigates |
| 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(WebURL url) : url_(url) {} | 50 explicit MockPresentationAvailabilityObserver(const WebVector<WebURL>& urls) |
| 51 : urls_(urls) {} |
| 51 ~MockPresentationAvailabilityObserver() override {} | 52 ~MockPresentationAvailabilityObserver() override {} |
| 52 | 53 |
| 53 MOCK_METHOD1(availabilityChanged, void(bool is_available)); | 54 MOCK_METHOD1(availabilityChanged, void(bool is_available)); |
| 54 const WebURL url() const override { return url_; } | 55 const WebVector<WebURL>& urls() const override { return urls_; } |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 const WebURL url_; | 58 const WebVector<WebURL> urls_; |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 class MockPresentationService : public PresentationService { | 61 class MockPresentationService : public PresentationService { |
| 61 public: | 62 public: |
| 62 void SetClient(PresentationServiceClientPtr client) override {} | 63 void SetClient(PresentationServiceClientPtr client) override {} |
| 63 MOCK_METHOD1(SetDefaultPresentationUrls, | 64 MOCK_METHOD1(SetDefaultPresentationUrls, |
| 64 void(const std::vector<GURL>& presentation_urls)); | 65 void(const std::vector<GURL>& presentation_urls)); |
| 65 MOCK_METHOD1(ListenForScreenAvailability, void(const GURL& availability_url)); | 66 MOCK_METHOD1(ListenForScreenAvailability, void(const GURL& availability_url)); |
| 66 MOCK_METHOD1(StopListeningForScreenAvailability, | 67 MOCK_METHOD1(StopListeningForScreenAvailability, |
| 67 void(const GURL& availability_url)); | 68 void(const GURL& availability_url)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 public: | 174 public: |
| 174 PresentationDispatcherTest() | 175 PresentationDispatcherTest() |
| 175 : gurl1_(GURL("https://www.example.com/1.html")), | 176 : gurl1_(GURL("https://www.example.com/1.html")), |
| 176 gurl2_(GURL("https://www.example.com/2.html")), | 177 gurl2_(GURL("https://www.example.com/2.html")), |
| 177 gurls_({gurl1_, gurl2_}), | 178 gurls_({gurl1_, gurl2_}), |
| 178 url1_(WebURL(gurl1_)), | 179 url1_(WebURL(gurl1_)), |
| 179 url2_(WebURL(gurl2_)), | 180 url2_(WebURL(gurl2_)), |
| 180 urls_(WebVector<WebURL>(gurls_)), | 181 urls_(WebVector<WebURL>(gurls_)), |
| 181 presentation_id_(WebString::fromUTF8("test-id")), | 182 presentation_id_(WebString::fromUTF8("test-id")), |
| 182 array_buffer_(WebArrayBuffer::create(4, 1)), | 183 array_buffer_(WebArrayBuffer::create(4, 1)), |
| 183 observer_(url1_), | 184 observer_(urls_), |
| 184 dispatcher_(&presentation_service_) {} | 185 dispatcher_(&presentation_service_) {} |
| 185 ~PresentationDispatcherTest() override {} | 186 ~PresentationDispatcherTest() override {} |
| 186 | 187 |
| 187 void SetUp() override { | 188 void SetUp() override { |
| 188 // Set some test data. | 189 // Set some test data. |
| 189 *array_buffer_data() = 42; | 190 *array_buffer_data() = 42; |
| 190 } | 191 } |
| 191 | 192 |
| 192 uint8_t* array_buffer_data() { | 193 uint8_t* array_buffer_data() { |
| 193 return static_cast<uint8_t*>(array_buffer_.data()); | 194 return static_cast<uint8_t*>(array_buffer_.data()); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 EXPECT_CALL(presentation_service_, | 367 EXPECT_CALL(presentation_service_, |
| 367 Terminate(gurl1_, presentation_id_.utf8())); | 368 Terminate(gurl1_, presentation_id_.utf8())); |
| 368 dispatcher_.terminateSession(url1_, presentation_id_); | 369 dispatcher_.terminateSession(url1_, presentation_id_); |
| 369 run_loop.RunUntilIdle(); | 370 run_loop.RunUntilIdle(); |
| 370 } | 371 } |
| 371 | 372 |
| 372 TEST_F(PresentationDispatcherTest, TestListenForScreenAvailability) { | 373 TEST_F(PresentationDispatcherTest, TestListenForScreenAvailability) { |
| 373 base::RunLoop run_loop1; | 374 base::RunLoop run_loop1; |
| 374 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl1_)); | 375 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl1_)); |
| 375 dispatcher_.getAvailability( | 376 dispatcher_.getAvailability( |
| 376 url1_, base::MakeUnique<WebPresentationAvailabilityCallbacks>()); | 377 urls_, base::MakeUnique<WebPresentationAvailabilityCallbacks>()); |
| 377 dispatcher_.OnScreenAvailabilityUpdated(url1_, true); | 378 dispatcher_.OnScreenAvailabilityUpdated(url1_, true); |
| 378 run_loop1.RunUntilIdle(); | 379 run_loop1.RunUntilIdle(); |
| 379 | 380 |
| 380 base::RunLoop run_loop2; | 381 base::RunLoop run_loop2; |
| 381 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl1_)); | 382 EXPECT_CALL(presentation_service_, ListenForScreenAvailability(gurl1_)); |
| 382 dispatcher_.startListening(&observer_); | 383 dispatcher_.startListening(&observer_); |
| 383 run_loop2.RunUntilIdle(); | 384 run_loop2.RunUntilIdle(); |
| 384 | 385 |
| 385 base::RunLoop run_loop3; | 386 base::RunLoop run_loop3; |
| 386 EXPECT_CALL(observer_, availabilityChanged(false)); | 387 EXPECT_CALL(observer_, availabilityChanged(false)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 400 } | 401 } |
| 401 | 402 |
| 402 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { | 403 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { |
| 403 base::RunLoop run_loop; | 404 base::RunLoop run_loop; |
| 404 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); | 405 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); |
| 405 dispatcher_.setDefaultPresentationUrls(urls_); | 406 dispatcher_.setDefaultPresentationUrls(urls_); |
| 406 run_loop.RunUntilIdle(); | 407 run_loop.RunUntilIdle(); |
| 407 } | 408 } |
| 408 | 409 |
| 409 } // namespace content | 410 } // namespace content |
| OLD | NEW |