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

Side by Side Diff: media/mojo/clients/mojo_decryptor_unittest.cc

Issue 2752653002: Change MojoDecryptorService to take a Decryptor (Closed)
Patch Set: Created 3 years, 9 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/test/test_message_loop.h" 13 #include "base/test/test_message_loop.h"
14 #include "media/base/cdm_context.h"
15 #include "media/base/content_decryption_module.h"
16 #include "media/base/decryptor.h" 14 #include "media/base/decryptor.h"
17 #include "media/base/mock_filters.h" 15 #include "media/base/mock_filters.h"
18 #include "media/base/video_frame.h" 16 #include "media/base/video_frame.h"
19 #include "media/mojo/clients/mojo_decryptor.h" 17 #include "media/mojo/clients/mojo_decryptor.h"
20 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" 18 #include "media/mojo/common/mojo_shared_buffer_video_frame.h"
21 #include "media/mojo/interfaces/decryptor.mojom.h" 19 #include "media/mojo/interfaces/decryptor.mojom.h"
22 #include "media/mojo/services/mojo_decryptor_service.h" 20 #include "media/mojo/services/mojo_decryptor_service.h"
23 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
25 23
26 using testing::Invoke; 24 using testing::Invoke;
27 using testing::InSequence; 25 using testing::InSequence;
28 using testing::IsNull; 26 using testing::IsNull;
29 using testing::NotNull; 27 using testing::NotNull;
30 using testing::SaveArg; 28 using testing::SaveArg;
31 using testing::StrictMock; 29 using testing::StrictMock;
32 using testing::_; 30 using testing::_;
33 31
34 namespace media { 32 namespace media {
35 33
36 class MojoDecryptorTest : public ::testing::Test { 34 class MojoDecryptorTest : public ::testing::Test {
37 public: 35 public:
38 MojoDecryptorTest() { 36 MojoDecryptorTest() {
39 decryptor_.reset(new StrictMock<MockDecryptor>()); 37 decryptor_.reset(new StrictMock<MockDecryptor>());
40 38
41 cdm_context_.reset(new StrictMock<MockCdmContext>());
42 EXPECT_CALL(*cdm_context_, GetDecryptor())
43 .WillRepeatedly(Return(decryptor_.get()));
44
45 cdm_ = new StrictMock<MockCdm>(
46 base::Bind(&MojoDecryptorTest::OnSessionMessage,
47 base::Unretained(this)),
48 base::Bind(&MojoDecryptorTest::OnSessionClosed, base::Unretained(this)),
49 base::Bind(&MojoDecryptorTest::OnSessionKeysChange,
50 base::Unretained(this)),
51 base::Bind(&MojoDecryptorTest::OnSessionExpirationUpdate,
52 base::Unretained(this)));
53 EXPECT_CALL(*cdm_.get(), GetCdmContext())
54 .WillRepeatedly(Return(cdm_context_.get()));
55
56 mojom::DecryptorPtr remote_decryptor; 39 mojom::DecryptorPtr remote_decryptor;
57 mojo_decryptor_service_.reset(new MojoDecryptorService( 40 mojo_decryptor_service_.reset(new MojoDecryptorService(
58 cdm_, mojo::MakeRequest(&remote_decryptor), 41 decryptor_.get(), mojo::MakeRequest(&remote_decryptor),
59 base::Bind(&MojoDecryptorTest::OnConnectionClosed, 42 base::Bind(&MojoDecryptorTest::OnConnectionClosed,
60 base::Unretained(this)))); 43 base::Unretained(this))));
61 44
62 mojo_decryptor_.reset(new MojoDecryptor(std::move(remote_decryptor))); 45 mojo_decryptor_.reset(new MojoDecryptor(std::move(remote_decryptor)));
63 } 46 }
64 47
65 ~MojoDecryptorTest() override {} 48 ~MojoDecryptorTest() override {}
66 49
67 void DestroyClient() { 50 void DestroyClient() {
68 EXPECT_CALL(*this, OnConnectionClosed()); 51 EXPECT_CALL(*this, OnConnectionClosed());
(...skipping 24 matching lines...) Expand all
93 void ReturnEOSVideoFrame(const scoped_refptr<DecoderBuffer>& encrypted, 76 void ReturnEOSVideoFrame(const scoped_refptr<DecoderBuffer>& encrypted,
94 const Decryptor::VideoDecodeCB& video_decode_cb) { 77 const Decryptor::VideoDecodeCB& video_decode_cb) {
95 // Simply create and return an End-Of-Stream VideoFrame. 78 // Simply create and return an End-Of-Stream VideoFrame.
96 video_decode_cb.Run(Decryptor::kSuccess, VideoFrame::CreateEOSFrame()); 79 video_decode_cb.Run(Decryptor::kSuccess, VideoFrame::CreateEOSFrame());
97 } 80 }
98 81
99 MOCK_METHOD2(VideoDecoded, 82 MOCK_METHOD2(VideoDecoded,
100 void(Decryptor::Status status, 83 void(Decryptor::Status status,
101 const scoped_refptr<VideoFrame>& frame)); 84 const scoped_refptr<VideoFrame>& frame));
102 MOCK_METHOD0(OnConnectionClosed, void()); 85 MOCK_METHOD0(OnConnectionClosed, void());
103 MOCK_METHOD3(OnSessionMessage,
104 void(const std::string& session_id,
105 ContentDecryptionModule::MessageType message_type,
106 const std::vector<uint8_t>& message));
107 MOCK_METHOD1(OnSessionClosed, void(const std::string& session_id));
108 MOCK_METHOD2(OnSessionExpirationUpdate,
109 void(const std::string& session_id, base::Time new_expiry_time));
110 MOCK_METHOD0(OnFrameDestroyed, void()); 86 MOCK_METHOD0(OnFrameDestroyed, void());
111 87
112 // MOCK methods don't work with move-only types like CdmKeysInfo. Add an extra
113 // OnSessionKeysChangeCalled() function to work around this.
114 MOCK_METHOD2(OnSessionKeysChangeCalled,
115 void(const std::string& session_id,
116 bool has_additional_usable_key));
117 void OnSessionKeysChange(const std::string& session_id,
118 bool has_additional_usable_key,
119 CdmKeysInfo keys_info) {
120 OnSessionKeysChangeCalled(session_id, has_additional_usable_key);
121 }
122
123 protected: 88 protected:
124 // Fixture members. 89 // Fixture members.
125 base::TestMessageLoop message_loop_; 90 base::TestMessageLoop message_loop_;
126 91
127 // The MojoDecryptor that we are testing. 92 // The MojoDecryptor that we are testing.
128 std::unique_ptr<MojoDecryptor> mojo_decryptor_; 93 std::unique_ptr<MojoDecryptor> mojo_decryptor_;
129 94
130 // The matching MojoDecryptorService for |mojo_decryptor_|. 95 // The matching MojoDecryptorService for |mojo_decryptor_|.
131 std::unique_ptr<MojoDecryptorService> mojo_decryptor_service_; 96 std::unique_ptr<MojoDecryptorService> mojo_decryptor_service_;
132 97
133 // Helpers needed by |mojo_decryptor_service_|. 98 // Helpers needed by |mojo_decryptor_service_|.
xhwang 2017/03/14 22:07:19 nit: the decryptor_ is not really a helper here ;)
jrummell 2017/03/14 22:49:40 Done.
134 std::unique_ptr<StrictMock<MockDecryptor>> decryptor_; 99 std::unique_ptr<StrictMock<MockDecryptor>> decryptor_;
135 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_;
136 scoped_refptr<StrictMock<MockCdm>> cdm_;
137 100
138 private: 101 private:
139 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorTest); 102 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorTest);
140 }; 103 };
141 104
142 TEST_F(MojoDecryptorTest, VideoDecodeFreesBuffer) { 105 TEST_F(MojoDecryptorTest, VideoDecodeFreesBuffer) {
143 // Call DecryptAndDecodeVideo(). Once the callback VideoDecoded() completes, 106 // Call DecryptAndDecodeVideo(). Once the callback VideoDecoded() completes,
144 // the frame will be destroyed, and the buffer will be released. 107 // the frame will be destroyed, and the buffer will be released.
145 { 108 {
146 InSequence seq; 109 InSequence seq;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)).Times(0); 200 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)).Times(0);
238 201
239 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(100)); 202 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(100));
240 mojo_decryptor_->DecryptAndDecodeVideo( 203 mojo_decryptor_->DecryptAndDecodeVideo(
241 std::move(buffer), 204 std::move(buffer),
242 base::Bind(&MojoDecryptorTest::VideoDecoded, base::Unretained(this))); 205 base::Bind(&MojoDecryptorTest::VideoDecoded, base::Unretained(this)));
243 base::RunLoop().RunUntilIdle(); 206 base::RunLoop().RunUntilIdle();
244 } 207 }
245 208
246 } // namespace media 209 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/mojo/services/mojo_cdm_service.h » ('j') | media/mojo/services/mojo_cdm_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698