OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_pro
xy.h" |
| 6 #include "base/run_loop.h" |
| 7 #include "base/test/mock_callback.h" |
| 8 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service.h" |
| 9 #include "chrome/browser/media/router/test_helper.h" |
| 10 #include "chrome/test/base/testing_profile.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 using ::testing::_; |
| 16 using ::testing::InvokeWithoutArgs; |
| 17 using ::testing::Return; |
| 18 |
| 19 namespace media_router { |
| 20 |
| 21 class MockDialMediaSinkService : public DialMediaSinkService { |
| 22 public: |
| 23 MockDialMediaSinkService(const MediaSinkService::OnSinksDiscoveredCallback& |
| 24 sink_discovery_callback, |
| 25 net::URLRequestContextGetter* request_context) |
| 26 : DialMediaSinkService(sink_discovery_callback, request_context) {} |
| 27 ~MockDialMediaSinkService() override {} |
| 28 |
| 29 MOCK_METHOD0(Start, void()); |
| 30 MOCK_METHOD0(Stop, void()); |
| 31 |
| 32 void OnSinksDiscovered() { |
| 33 sink_discovery_callback_.Run(std::vector<MediaSinkInternal>()); |
| 34 } |
| 35 }; |
| 36 |
| 37 class DialMediaSinkServiceProxyTest : public ::testing::Test { |
| 38 public: |
| 39 DialMediaSinkServiceProxyTest() |
| 40 : proxy_(new DialMediaSinkServiceProxy(mock_sink_discovered_cb_.Get(), |
| 41 &profile_)) { |
| 42 std::unique_ptr<MockDialMediaSinkService> mock_dial_media_sink_service = |
| 43 base::MakeUnique<MockDialMediaSinkService>( |
| 44 base::Bind(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread, |
| 45 base::Unretained(proxy_.get())), |
| 46 profile_.GetRequestContext()); |
| 47 mock_service_ = mock_dial_media_sink_service.get(); |
| 48 proxy_->SetDialMediaSinkServiceForTest( |
| 49 std::move(mock_dial_media_sink_service)); |
| 50 } |
| 51 |
| 52 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 53 |
| 54 protected: |
| 55 const content::TestBrowserThreadBundle thread_bundle_; |
| 56 TestingProfile profile_; |
| 57 |
| 58 base::MockCallback<MediaSinkService::OnSinksDiscoveredCallback> |
| 59 mock_sink_discovered_cb_; |
| 60 |
| 61 MockDialMediaSinkService* mock_service_; |
| 62 scoped_refptr<DialMediaSinkServiceProxy> proxy_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxyTest); |
| 65 }; |
| 66 |
| 67 TEST_F(DialMediaSinkServiceProxyTest, TestStart) { |
| 68 EXPECT_CALL(*mock_service_, Start()).WillOnce(InvokeWithoutArgs([]() { |
| 69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 70 })); |
| 71 |
| 72 proxy_->Start(); |
| 73 } |
| 74 |
| 75 TEST_F(DialMediaSinkServiceProxyTest, TestStop) { |
| 76 EXPECT_CALL(*mock_service_, Stop()).WillOnce(InvokeWithoutArgs([]() { |
| 77 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 78 })); |
| 79 |
| 80 proxy_->Stop(); |
| 81 } |
| 82 |
| 83 TEST_F(DialMediaSinkServiceProxyTest, TestOnSinksDiscovered) { |
| 84 EXPECT_CALL(*mock_service_, Start()); |
| 85 EXPECT_CALL(mock_sink_discovered_cb_, Run(_)).Times(1); |
| 86 |
| 87 proxy_->Start(); |
| 88 mock_service_->OnSinksDiscovered(); |
| 89 } |
| 90 |
| 91 } // namespace media_router |
OLD | NEW |