| OLD | NEW |
| 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 "chrome/browser/media/router/presentation_media_sinks_observer.h" | 5 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "chrome/browser/media/router/media_source_helper.h" | 10 #include "chrome/browser/media/router/media_source_helper.h" |
| 11 #include "chrome/browser/media/router/mock_media_router.h" | 11 #include "chrome/browser/media/router/mock_media_router.h" |
| 12 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | 12 #include "chrome/browser/media/router/mock_screen_availability_listener.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "content/public/browser/presentation_screen_availability_listener.h" | 14 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 | 16 |
| 17 using testing::_; | 17 using testing::_; |
| 18 using testing::Mock; | 18 using testing::Mock; |
| 19 using testing::Return; | 19 using testing::Return; |
| 20 | 20 |
| 21 namespace media_router { | 21 namespace media_router { |
| 22 | 22 |
| 23 namespace { |
| 24 constexpr char kOrigin[] = "https://google.com"; |
| 25 } // namespace |
| 26 |
| 23 class PresentationMediaSinksObserverTest : public ::testing::Test { | 27 class PresentationMediaSinksObserverTest : public ::testing::Test { |
| 24 public: | 28 public: |
| 25 PresentationMediaSinksObserverTest() | 29 PresentationMediaSinksObserverTest() |
| 26 : listener_(GURL("http://example.com/presentation.html")) {} | 30 : listener_(GURL("http://example.com/presentation.html")) {} |
| 27 ~PresentationMediaSinksObserverTest() override {} | 31 ~PresentationMediaSinksObserverTest() override {} |
| 28 | 32 |
| 29 void SetUp() override { | 33 void SetUp() override { |
| 30 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true)); | 34 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true)); |
| 31 observer_.reset(new PresentationMediaSinksObserver( | 35 observer_.reset(new PresentationMediaSinksObserver( |
| 32 &router_, &listener_, MediaSourceForPresentationUrl( | 36 &router_, &listener_, MediaSourceForPresentationUrl( |
| 33 GURL("http://example.com/presentation.html")), | 37 GURL("http://example.com/presentation.html")), |
| 34 GURL("https://google.com"))); | 38 url::Origin(GURL(kOrigin)))); |
| 35 EXPECT_TRUE(observer_->Init()); | 39 EXPECT_TRUE(observer_->Init()); |
| 36 } | 40 } |
| 37 | 41 |
| 38 void TearDown() override { | 42 void TearDown() override { |
| 39 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)); | 43 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)); |
| 40 observer_.reset(); | 44 observer_.reset(); |
| 41 } | 45 } |
| 42 | 46 |
| 43 MockMediaRouter router_; | 47 MockMediaRouter router_; |
| 44 MockScreenAvailabilityListener listener_; | 48 MockScreenAvailabilityListener listener_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 observer_->OnSinksReceived(result); | 87 observer_->OnSinksReceived(result); |
| 84 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_)); | 88 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_)); |
| 85 | 89 |
| 86 // |listener_| should get result since it changed to false. | 90 // |listener_| should get result since it changed to false. |
| 87 EXPECT_CALL(listener_, OnScreenAvailabilityChanged(false)).Times(1); | 91 EXPECT_CALL(listener_, OnScreenAvailabilityChanged(false)).Times(1); |
| 88 observer_->OnSinksReceived(std::vector<MediaSink>()); | 92 observer_->OnSinksReceived(std::vector<MediaSink>()); |
| 89 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_)); | 93 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_)); |
| 90 } | 94 } |
| 91 | 95 |
| 92 } // namespace media_router | 96 } // namespace media_router |
| OLD | NEW |