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_imp l.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 MockDialMediaSinkServiceImpl : public DialMediaSinkServiceImpl { | |
22 public: | |
23 MockDialMediaSinkServiceImpl( | |
24 const MediaSinkService::OnSinksDiscoveredCallback& | |
25 sink_discovery_callback, | |
26 net::URLRequestContextGetter* request_context) | |
27 : DialMediaSinkServiceImpl(sink_discovery_callback, request_context) {} | |
28 ~MockDialMediaSinkServiceImpl() override {} | |
29 | |
30 MOCK_METHOD0(Start, void()); | |
31 MOCK_METHOD0(Stop, void()); | |
32 | |
33 void OnSinksDiscovered() { | |
34 sink_discovery_callback_.Run(std::vector<MediaSinkInternal>()); | |
35 } | |
36 }; | |
37 | |
38 class DialMediaSinkServiceProxyTest : public ::testing::Test { | |
39 public: | |
40 DialMediaSinkServiceProxyTest() | |
41 : proxy_(new DialMediaSinkServiceProxy(mock_sink_discovered_cb_.Get(), | |
42 &profile_)) { | |
43 std::unique_ptr<MockDialMediaSinkServiceImpl> mock_dial_media_sink_service = | |
44 base::MakeUnique<MockDialMediaSinkServiceImpl>( | |
45 base::Bind(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread, | |
46 base::Unretained(proxy_.get())), | |
47 profile_.GetRequestContext()); | |
48 mock_service_ = mock_dial_media_sink_service.get(); | |
49 proxy_->SetDialMediaSinkServiceForTest( | |
50 std::move(mock_dial_media_sink_service)); | |
51 } | |
52 | |
53 void TearDown() override { base::RunLoop().RunUntilIdle(); } | |
54 | |
55 protected: | |
56 const content::TestBrowserThreadBundle thread_bundle_; | |
Kevin M
2017/05/24 00:52:55
nit: Why is this const?
zhaobin
2017/05/24 17:45:52
Done.
| |
57 TestingProfile profile_; | |
58 | |
59 base::MockCallback<MediaSinkService::OnSinksDiscoveredCallback> | |
60 mock_sink_discovered_cb_; | |
61 | |
62 MockDialMediaSinkServiceImpl* mock_service_; | |
63 scoped_refptr<DialMediaSinkServiceProxy> proxy_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxyTest); | |
66 }; | |
67 | |
68 TEST_F(DialMediaSinkServiceProxyTest, TestStart) { | |
69 EXPECT_CALL(*mock_service_, Start()).WillOnce(InvokeWithoutArgs([]() { | |
70 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
71 })); | |
72 | |
73 proxy_->Start(); | |
74 } | |
75 | |
76 TEST_F(DialMediaSinkServiceProxyTest, TestStop) { | |
77 EXPECT_CALL(*mock_service_, Stop()).WillOnce(InvokeWithoutArgs([]() { | |
78 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
Kevin M
2017/05/24 00:52:55
Nit: use GTest macros in test cases, they are more
zhaobin
2017/05/24 17:45:51
Done.
| |
79 })); | |
80 | |
81 proxy_->Stop(); | |
82 } | |
83 | |
84 TEST_F(DialMediaSinkServiceProxyTest, TestOnSinksDiscovered) { | |
85 EXPECT_CALL(*mock_service_, Start()); | |
86 EXPECT_CALL(mock_sink_discovered_cb_, Run(_)).Times(1); | |
87 | |
88 proxy_->Start(); | |
89 mock_service_->OnSinksDiscovered(); | |
90 } | |
91 | |
92 } // namespace media_router | |
OLD | NEW |