Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: media/mojo/services/media_apptest.cc

Issue 1255083004: media: Mojo interfaces renaming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "media/base/cdm_config.h" 10 #include "media/base/cdm_config.h"
11 #include "media/base/mock_filters.h" 11 #include "media/base/mock_filters.h"
12 #include "media/base/test_helpers.h" 12 #include "media/base/test_helpers.h"
13 #include "media/cdm/key_system_names.h" 13 #include "media/cdm/key_system_names.h"
14 #include "media/mojo/interfaces/content_decryption_module.mojom.h" 14 #include "media/mojo/interfaces/content_decryption_module.mojom.h"
15 #include "media/mojo/interfaces/media_renderer.mojom.h" 15 #include "media/mojo/interfaces/renderer.mojom.h"
16 #include "media/mojo/interfaces/service_factory.mojom.h" 16 #include "media/mojo/interfaces/service_factory.mojom.h"
17 #include "media/mojo/services/media_type_converters.h" 17 #include "media/mojo/services/media_type_converters.h"
18 #include "media/mojo/services/mojo_demuxer_stream_impl.h" 18 #include "media/mojo/services/mojo_demuxer_stream_impl.h"
19 #include "mojo/application/public/cpp/application_connection.h" 19 #include "mojo/application/public/cpp/application_connection.h"
20 #include "mojo/application/public/cpp/application_impl.h" 20 #include "mojo/application/public/cpp/application_impl.h"
21 #include "mojo/application/public/cpp/application_test_base.h" 21 #include "mojo/application/public/cpp/application_test_base.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 23
24 using testing::Exactly; 24 using testing::Exactly;
25 using testing::Invoke; 25 using testing::Invoke;
26 using testing::InvokeWithoutArgs; 26 using testing::InvokeWithoutArgs;
27 using testing::StrictMock; 27 using testing::StrictMock;
28 28
29 namespace media { 29 namespace media {
30 namespace { 30 namespace {
31 31
32 const char kInvalidKeySystem[] = "invalid.key.system"; 32 const char kInvalidKeySystem[] = "invalid.key.system";
33 const char kSecurityOrigin[] = "http://foo.com"; 33 const char kSecurityOrigin[] = "http://foo.com";
34 34
35 class MockMediaRendererClient : public interfaces::MediaRendererClient { 35 class MockRendererClient : public interfaces::RendererClient {
36 public: 36 public:
37 MockMediaRendererClient(){}; 37 MockRendererClient(){};
38 ~MockMediaRendererClient() override{}; 38 ~MockRendererClient() override{};
39 39
40 // interfaces::MediaRendererClient implementation. 40 // interfaces::RendererClient implementation.
41 MOCK_METHOD2(OnTimeUpdate, void(int64_t time_usec, int64_t max_time_usec)); 41 MOCK_METHOD2(OnTimeUpdate, void(int64_t time_usec, int64_t max_time_usec));
42 MOCK_METHOD1(OnBufferingStateChange, void(interfaces::BufferingState state)); 42 MOCK_METHOD1(OnBufferingStateChange, void(interfaces::BufferingState state));
43 MOCK_METHOD0(OnEnded, void()); 43 MOCK_METHOD0(OnEnded, void());
44 MOCK_METHOD0(OnError, void()); 44 MOCK_METHOD0(OnError, void());
45 45
46 private: 46 private:
47 DISALLOW_COPY_AND_ASSIGN(MockMediaRendererClient); 47 DISALLOW_COPY_AND_ASSIGN(MockRendererClient);
48 }; 48 };
49 49
50 class MediaAppTest : public mojo::test::ApplicationTestBase { 50 class MediaAppTest : public mojo::test::ApplicationTestBase {
51 public: 51 public:
52 MediaAppTest() 52 MediaAppTest()
53 : media_renderer_client_binding_(&media_renderer_client_), 53 : renderer_client_binding_(&renderer_client_),
54 video_demuxer_stream_(DemuxerStream::VIDEO) {} 54 video_demuxer_stream_(DemuxerStream::VIDEO) {}
55 ~MediaAppTest() override {} 55 ~MediaAppTest() override {}
56 56
57 void SetUp() override { 57 void SetUp() override {
58 ApplicationTestBase::SetUp(); 58 ApplicationTestBase::SetUp();
59 59
60 mojo::URLRequestPtr request = mojo::URLRequest::New(); 60 mojo::URLRequestPtr request = mojo::URLRequest::New();
61 request->url = "mojo:media"; 61 request->url = "mojo:media";
62 mojo::ApplicationConnection* connection = 62 mojo::ApplicationConnection* connection =
63 application_impl()->ConnectToApplication(request.Pass()); 63 application_impl()->ConnectToApplication(request.Pass());
64 64
65 connection->ConnectToService(&service_factory_); 65 connection->ConnectToService(&service_factory_);
66 service_factory_->CreateCdm(mojo::GetProxy(&cdm_)); 66 service_factory_->CreateCdm(mojo::GetProxy(&cdm_));
67 service_factory_->CreateRenderer(mojo::GetProxy(&media_renderer_)); 67 service_factory_->CreateRenderer(mojo::GetProxy(&renderer_));
68 68
69 run_loop_.reset(new base::RunLoop()); 69 run_loop_.reset(new base::RunLoop());
70 } 70 }
71 71
72 // MOCK_METHOD* doesn't support move only types. Work around this by having 72 // MOCK_METHOD* doesn't support move only types. Work around this by having
73 // an extra method. 73 // an extra method.
74 MOCK_METHOD1(OnCdmInitializedInternal, void(bool result)); 74 MOCK_METHOD1(OnCdmInitializedInternal, void(bool result));
75 void OnCdmInitialized(interfaces::CdmPromiseResultPtr result) { 75 void OnCdmInitialized(interfaces::CdmPromiseResultPtr result) {
76 OnCdmInitializedInternal(result->success); 76 OnCdmInitializedInternal(result->success);
77 } 77 }
78 78
79 void InitializeCdm(const std::string& key_system, bool expected_result) { 79 void InitializeCdm(const std::string& key_system, bool expected_result) {
80 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result)) 80 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result))
81 .Times(Exactly(1)) 81 .Times(Exactly(1))
82 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); 82 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
83 cdm_->Initialize( 83 cdm_->Initialize(
84 key_system, kSecurityOrigin, interfaces::CdmConfig::From(CdmConfig()), 84 key_system, kSecurityOrigin, interfaces::CdmConfig::From(CdmConfig()),
85 1, base::Bind(&MediaAppTest::OnCdmInitialized, base::Unretained(this))); 85 1, base::Bind(&MediaAppTest::OnCdmInitialized, base::Unretained(this)));
86 } 86 }
87 87
88 MOCK_METHOD1(OnRendererInitialized, void(bool)); 88 MOCK_METHOD1(OnRendererInitialized, void(bool));
89 89
90 void InitializeRenderer(const VideoDecoderConfig& video_config, 90 void InitializeRenderer(const VideoDecoderConfig& video_config,
91 bool expected_result) { 91 bool expected_result) {
92 video_demuxer_stream_.set_video_decoder_config(video_config); 92 video_demuxer_stream_.set_video_decoder_config(video_config);
93 93
94 interfaces::DemuxerStreamPtr video_stream; 94 interfaces::DemuxerStreamPtr video_stream;
95 new MojoDemuxerStreamImpl(&video_demuxer_stream_, GetProxy(&video_stream)); 95 new MojoDemuxerStreamImpl(&video_demuxer_stream_, GetProxy(&video_stream));
96 96
97 interfaces::MediaRendererClientPtr client_ptr; 97 interfaces::RendererClientPtr client_ptr;
98 media_renderer_client_binding_.Bind(GetProxy(&client_ptr)); 98 renderer_client_binding_.Bind(GetProxy(&client_ptr));
99 99
100 EXPECT_CALL(*this, OnRendererInitialized(expected_result)) 100 EXPECT_CALL(*this, OnRendererInitialized(expected_result))
101 .Times(Exactly(1)) 101 .Times(Exactly(1))
102 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); 102 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
103 media_renderer_->Initialize(client_ptr.Pass(), nullptr, video_stream.Pass(), 103 renderer_->Initialize(client_ptr.Pass(), nullptr, video_stream.Pass(),
104 base::Bind(&MediaAppTest::OnRendererInitialized, 104 base::Bind(&MediaAppTest::OnRendererInitialized,
105 base::Unretained(this))); 105 base::Unretained(this)));
106 } 106 }
107 107
108 protected: 108 protected:
109 scoped_ptr<base::RunLoop> run_loop_; 109 scoped_ptr<base::RunLoop> run_loop_;
110 110
111 interfaces::ServiceFactoryPtr service_factory_; 111 interfaces::ServiceFactoryPtr service_factory_;
112 interfaces::ContentDecryptionModulePtr cdm_; 112 interfaces::ContentDecryptionModulePtr cdm_;
113 interfaces::MediaRendererPtr media_renderer_; 113 interfaces::RendererPtr renderer_;
114 114
115 StrictMock<MockMediaRendererClient> media_renderer_client_; 115 StrictMock<MockRendererClient> renderer_client_;
116 mojo::Binding<interfaces::MediaRendererClient> media_renderer_client_binding_; 116 mojo::Binding<interfaces::RendererClient> renderer_client_binding_;
117 117
118 StrictMock<MockDemuxerStream> video_demuxer_stream_; 118 StrictMock<MockDemuxerStream> video_demuxer_stream_;
119 119
120 private: 120 private:
121 DISALLOW_COPY_AND_ASSIGN(MediaAppTest); 121 DISALLOW_COPY_AND_ASSIGN(MediaAppTest);
122 }; 122 };
123 123
124 } // namespace 124 } // namespace
125 125
126 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because 126 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because
(...skipping 13 matching lines...) Expand all
140 InitializeRenderer(TestVideoConfig::Normal(), true); 140 InitializeRenderer(TestVideoConfig::Normal(), true);
141 run_loop_->Run(); 141 run_loop_->Run();
142 } 142 }
143 143
144 TEST_F(MediaAppTest, InitializeRenderer_InvalidConfig) { 144 TEST_F(MediaAppTest, InitializeRenderer_InvalidConfig) {
145 InitializeRenderer(TestVideoConfig::Invalid(), false); 145 InitializeRenderer(TestVideoConfig::Invalid(), false);
146 run_loop_->Run(); 146 run_loop_->Run();
147 } 147 }
148 148
149 } // namespace media 149 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698