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

Side by Side Diff: webkit/media/crypto/proxy_decryptor_unittest.cc

Issue 11144036: Update Decryptor interface to support audio decoding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove leftover unretained Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « webkit/media/crypto/proxy_decryptor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/media/crypto/proxy_decryptor.h" 5 #include "webkit/media/crypto/proxy_decryptor.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 std::string(reinterpret_cast<const char*>(kFakeKeyId), 46 std::string(reinterpret_cast<const char*>(kFakeKeyId),
47 arraysize(kFakeKeyId)), 47 arraysize(kFakeKeyId)),
48 std::string(reinterpret_cast<const char*>(kFakeIv), 48 std::string(reinterpret_cast<const char*>(kFakeIv),
49 DecryptConfig::kDecryptionKeySize), 49 DecryptConfig::kDecryptionKeySize),
50 encrypted_frame_offset, 50 encrypted_frame_offset,
51 std::vector<media::SubsampleEntry>()))); 51 std::vector<media::SubsampleEntry>())));
52 return encrypted_buffer; 52 return encrypted_buffer;
53 } 53 }
54 54
55 ACTION_P2(RunDecryptCB, status, buffer) { 55 ACTION_P2(RunDecryptCB, status, buffer) {
56 arg1.Run(status, buffer); 56 arg2.Run(status, buffer);
57 } 57 }
58 58
59 ACTION_P3(ResetAndRunDecryptCB, decrypt_cb, status, buffer) { 59 ACTION_P3(ResetAndRunDecryptCB, decrypt_cb, status, buffer) {
60 base::ResetAndReturn(decrypt_cb).Run(status, buffer); 60 base::ResetAndReturn(decrypt_cb).Run(status, buffer);
61 } 61 }
62 62
63 ACTION_P(ScheduleMessageLoopToStop, message_loop) { 63 ACTION_P(ScheduleMessageLoopToStop, message_loop) {
64 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 64 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
65 } 65 }
66 66
67 // Tests the interaction between external Decryptor calls and concrete Decryptor 67 // Tests the interaction between external Decryptor calls and concrete Decryptor
68 // implementations. This test is not interested in any specific Decryptor 68 // implementations. This test is not interested in any specific Decryptor
69 // implementation. A MockDecryptor is used here to serve this purpose. 69 // implementation. A MockDecryptor is used here to serve this purpose.
70 class ProxyDecryptorTest : public testing::Test { 70 class ProxyDecryptorTest : public testing::Test {
71 public: 71 public:
72 ProxyDecryptorTest() 72 ProxyDecryptorTest()
73 : proxy_decryptor_(message_loop_.message_loop_proxy(), 73 : proxy_decryptor_(message_loop_.message_loop_proxy(),
74 &client_, NULL, NULL), 74 &client_, NULL, NULL),
75 real_decryptor_(new media::MockDecryptor()), 75 real_decryptor_(new media::MockDecryptor()),
76 scoped_real_decryptor_(real_decryptor_), 76 scoped_real_decryptor_(real_decryptor_),
77 stream_type_(media::Decryptor::kVideo),
77 decrypt_cb_(base::Bind(&ProxyDecryptorTest::DeliverBuffer, 78 decrypt_cb_(base::Bind(&ProxyDecryptorTest::DeliverBuffer,
78 base::Unretained(this))), 79 base::Unretained(this))),
79 encrypted_buffer_(CreateFakeEncryptedBuffer()), 80 encrypted_buffer_(CreateFakeEncryptedBuffer()),
80 decrypted_buffer_(DecoderBuffer::CopyFrom(kDecryptedData, 81 decrypted_buffer_(DecoderBuffer::CopyFrom(kDecryptedData,
81 arraysize(kDecryptedData))), 82 arraysize(kDecryptedData))),
82 null_buffer_(scoped_refptr<DecoderBuffer>()) { 83 null_buffer_(scoped_refptr<DecoderBuffer>()) {
83 } 84 }
84 85
85 // Instead of calling ProxyDecryptor::GenerateKeyRequest() here to create a 86 // Instead of calling ProxyDecryptor::GenerateKeyRequest() here to create a
86 // real Decryptor, inject a MockDecryptor for testing purpose. 87 // real Decryptor, inject a MockDecryptor for testing purpose.
(...skipping 28 matching lines...) Expand all
115 // mock decryptor. 116 // mock decryptor.
116 media::MockDecryptor* real_decryptor_; 117 media::MockDecryptor* real_decryptor_;
117 118
118 // Scoped pointer that takes ownership of |real_decryptor_|. When 119 // Scoped pointer that takes ownership of |real_decryptor_|. When
119 // GenerateKeyRequest() is called, the ownership of |real_decryptor_| is 120 // GenerateKeyRequest() is called, the ownership of |real_decryptor_| is
120 // passed from |scoped_real_decryptor_| to |proxy_decryptor_|. We need this 121 // passed from |scoped_real_decryptor_| to |proxy_decryptor_|. We need this
121 // to manage life time of |real_decryptor_| because not all tests call 122 // to manage life time of |real_decryptor_| because not all tests call
122 // GenerateKeyRequest(). 123 // GenerateKeyRequest().
123 scoped_ptr<Decryptor> scoped_real_decryptor_; 124 scoped_ptr<Decryptor> scoped_real_decryptor_;
124 125
126 media::Decryptor::StreamType stream_type_;
127
125 Decryptor::DecryptCB decrypt_cb_; 128 Decryptor::DecryptCB decrypt_cb_;
126 129
127 scoped_refptr<DecoderBuffer> encrypted_buffer_; 130 scoped_refptr<DecoderBuffer> encrypted_buffer_;
128 scoped_refptr<DecoderBuffer> decrypted_buffer_; 131 scoped_refptr<DecoderBuffer> decrypted_buffer_;
129 scoped_refptr<DecoderBuffer> null_buffer_; 132 scoped_refptr<DecoderBuffer> null_buffer_;
130 133
131 private: 134 private:
132 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptorTest); 135 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptorTest);
133 }; 136 };
134 137
135 // Tests a typical use case: GKR(), AddKey() and Decrypt() succeeds. 138 // Tests a typical use case: GKR(), AddKey() and Decrypt() succeeds.
136 TEST_F(ProxyDecryptorTest, NormalDecryption_Success) { 139 TEST_F(ProxyDecryptorTest, NormalDecryption_Success) {
137 GenerateKeyRequest(); 140 GenerateKeyRequest();
138 AddKey(); 141 AddKey();
139 142
140 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 143 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
141 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_)); 144 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_));
142 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_)); 145 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_));
143 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 146 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
144 } 147 }
145 148
146 // Tests the case where Decrypt() fails. 149 // Tests the case where Decrypt() fails.
147 TEST_F(ProxyDecryptorTest, NormalDecryption_Error) { 150 TEST_F(ProxyDecryptorTest, NormalDecryption_Error) {
148 GenerateKeyRequest(); 151 GenerateKeyRequest();
149 AddKey(); 152 AddKey();
150 153
151 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 154 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
152 .WillOnce(RunDecryptCB(Decryptor::kError, null_buffer_)); 155 .WillOnce(RunDecryptCB(Decryptor::kError, null_buffer_));
153 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kError, IsNull())); 156 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kError, IsNull()));
154 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 157 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
155 } 158 }
156 159
157 // Tests the case where no key is available for decryption. 160 // Tests the case where no key is available for decryption.
158 TEST_F(ProxyDecryptorTest, NormalDecryption_NoKey) { 161 TEST_F(ProxyDecryptorTest, NormalDecryption_NoKey) {
159 GenerateKeyRequest(); 162 GenerateKeyRequest();
160 163
161 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 164 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
162 .WillOnce(RunDecryptCB(Decryptor::kNoKey, null_buffer_)); 165 .WillOnce(RunDecryptCB(Decryptor::kNoKey, null_buffer_));
163 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId))); 166 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId)));
164 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 167 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
165 168
166 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_)); 169 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_));
167 proxy_decryptor_.CancelDecrypt(); 170 proxy_decryptor_.CancelDecrypt(stream_type_);
168 } 171 }
169 172
170 // Tests the case where Decrypt() is called after the right key is added. 173 // Tests the case where Decrypt() is called after the right key is added.
171 TEST_F(ProxyDecryptorTest, DecryptBeforeAddKey) { 174 TEST_F(ProxyDecryptorTest, DecryptBeforeAddKey) {
172 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId))); 175 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId)));
173 GenerateKeyRequest(); 176 GenerateKeyRequest();
174 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 177 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
175 .WillOnce(RunDecryptCB(Decryptor::kNoKey, null_buffer_)); 178 .WillOnce(RunDecryptCB(Decryptor::kNoKey, null_buffer_));
176 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 179 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
177 180
178 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 181 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
179 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_)); 182 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_));
180 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_)) 183 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_))
181 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 184 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
182 AddKey(); 185 AddKey();
183 186
184 message_loop_.Run(); 187 message_loop_.Run();
185 } 188 }
186 189
187 // Tests the case where Decrypt() is called before GKR() and the right key is 190 // Tests the case where Decrypt() is called before GKR() and the right key is
188 // added. 191 // added.
189 TEST_F(ProxyDecryptorTest, DecryptBeforeGenerateKeyRequest) { 192 TEST_F(ProxyDecryptorTest, DecryptBeforeGenerateKeyRequest) {
190 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId))); 193 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId)));
191 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 194 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
192 195
193 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 196 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
194 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_)); 197 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_));
195 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_)) 198 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_))
196 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 199 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
197 GenerateKeyRequest(); 200 GenerateKeyRequest();
198 AddKey(); 201 AddKey();
199 202
200 message_loop_.Run(); 203 message_loop_.Run();
201 } 204 }
202 205
203 // Tests the case where multiple AddKey() is called to add some irrelevant keys 206 // Tests the case where multiple AddKey() is called to add some irrelevant keys
204 // before the real key that can decrypt |encrypted_buffer_| is added. 207 // before the real key that can decrypt |encrypted_buffer_| is added.
205 TEST_F(ProxyDecryptorTest, MultipleAddKeys) { 208 TEST_F(ProxyDecryptorTest, MultipleAddKeys) {
206 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId))) 209 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId)))
207 .Times(AtLeast(1)); 210 .Times(AtLeast(1));
208 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 211 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
209 212
210 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 213 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
211 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, null_buffer_)); 214 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, null_buffer_));
212 GenerateKeyRequest(); 215 GenerateKeyRequest();
213 const int number_of_irrelevant_addkey = 5; 216 const int number_of_irrelevant_addkey = 5;
214 for (int i = 0; i < number_of_irrelevant_addkey; ++i) 217 for (int i = 0; i < number_of_irrelevant_addkey; ++i)
215 AddKey(); // Some irrelevant keys are added. 218 AddKey(); // Some irrelevant keys are added.
216 219
217 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 220 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
218 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_)); 221 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_));
219 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_)) 222 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_))
220 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 223 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
221 AddKey(); // Correct key added. 224 AddKey(); // Correct key added.
222 225
223 message_loop_.Run(); 226 message_loop_.Run();
224 } 227 }
225 228
226 // Test the case where a new key is added before the |real_decryptor_| returns 229 // Test the case where a new key is added before the |real_decryptor_| returns
227 // kNoKey. The exact call sequence is: 230 // kNoKey. The exact call sequence is:
228 // 1, Decrypt an encrypted buffer. 231 // 1, Decrypt an encrypted buffer.
229 // 2, The correct key is added. 232 // 2, The correct key is added.
230 // 3, The previously decrypt call returned kNoKey. 233 // 3, The previously decrypt call returned kNoKey.
231 // In this case, the ProxyDecryptor is smart enough to try the decryption again 234 // In this case, the ProxyDecryptor is smart enough to try the decryption again
232 // and get the buffer decrypted! 235 // and get the buffer decrypted!
233 TEST_F(ProxyDecryptorTest, AddKeyAfterDecryptButBeforeNoKeyReturned) { 236 TEST_F(ProxyDecryptorTest, AddKeyAfterDecryptButBeforeNoKeyReturned) {
234 Decryptor::DecryptCB decrypt_cb; 237 Decryptor::DecryptCB decrypt_cb;
235 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 238 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
236 .WillOnce(SaveArg<1>(&decrypt_cb)); 239 .WillOnce(SaveArg<2>(&decrypt_cb));
237 240
238 GenerateKeyRequest(); 241 GenerateKeyRequest();
239 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 242 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
240 EXPECT_FALSE(decrypt_cb.is_null()); 243 EXPECT_FALSE(decrypt_cb.is_null());
241 244
242 AddKey(); 245 AddKey();
243 246
244 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 247 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
245 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_)); 248 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_));
246 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_)) 249 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_))
247 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 250 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
248 base::ResetAndReturn(&decrypt_cb).Run(Decryptor::kNoKey, null_buffer_); 251 base::ResetAndReturn(&decrypt_cb).Run(Decryptor::kNoKey, null_buffer_);
249 252
250 message_loop_.Run(); 253 message_loop_.Run();
251 } 254 }
252 255
253 // Test the case where we cancel the pending decryption callback even before 256 // Test the case where we cancel the pending decryption callback even before
254 // GenerateKeyRequest is called. In this case, the decryptor was not even 257 // GenerateKeyRequest is called. In this case, the decryptor was not even
255 // created! 258 // created!
256 TEST_F(ProxyDecryptorTest, CancelDecryptWithoutGenerateKeyRequestCalled) { 259 TEST_F(ProxyDecryptorTest, CancelDecryptWithoutGenerateKeyRequestCalled) {
257 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId))) 260 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId)))
258 .Times(AtLeast(1)); 261 .Times(AtLeast(1));
259 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 262 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
260 263
261 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_)) 264 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_))
262 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 265 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
263 proxy_decryptor_.CancelDecrypt(); 266 proxy_decryptor_.CancelDecrypt(stream_type_);
264 267
265 message_loop_.Run(); 268 message_loop_.Run();
266 } 269 }
267 270
268 // Test the case where we cancel the pending decryption callback when it's 271 // Test the case where we cancel the pending decryption callback when it's
269 // stored in the ProxyDecryptor. 272 // stored in the ProxyDecryptor.
270 TEST_F(ProxyDecryptorTest, CancelDecryptWhenDecryptPendingInProxyDecryptor) { 273 TEST_F(ProxyDecryptorTest, CancelDecryptWhenDecryptPendingInProxyDecryptor) {
271 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId))) 274 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId)))
272 .Times(AtLeast(1)); 275 .Times(AtLeast(1));
273 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 276 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
274 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, null_buffer_)); 277 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, null_buffer_));
275 GenerateKeyRequest(); 278 GenerateKeyRequest();
276 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 279 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
277 280
278 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_)) 281 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_))
279 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 282 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
280 proxy_decryptor_.CancelDecrypt(); 283 proxy_decryptor_.CancelDecrypt(stream_type_);
281 284
282 message_loop_.Run(); 285 message_loop_.Run();
283 } 286 }
284 287
285 // Test the case where we cancel the pending decryption callback when it's 288 // Test the case where we cancel the pending decryption callback when it's
286 // pending at the |real_decryptor_|. 289 // pending at the |real_decryptor_|.
287 TEST_F(ProxyDecryptorTest, CancelDecryptWhenDecryptPendingInRealDecryptor) { 290 TEST_F(ProxyDecryptorTest, CancelDecryptWhenDecryptPendingInRealDecryptor) {
288 Decryptor::DecryptCB decrypt_cb; 291 Decryptor::DecryptCB decrypt_cb;
289 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 292 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
290 .WillOnce(SaveArg<1>(&decrypt_cb)); 293 .WillOnce(SaveArg<2>(&decrypt_cb));
291 GenerateKeyRequest(); 294 GenerateKeyRequest();
292 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 295 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
293 EXPECT_FALSE(decrypt_cb.is_null()); 296 EXPECT_FALSE(decrypt_cb.is_null());
294 297
295 // Even though the real decryptor returns kError, DeliverBuffer() should 298 // Even though the real decryptor returns kError, DeliverBuffer() should
296 // still be called with kSuccess and NULL because we are canceling the 299 // still be called with kSuccess and NULL because we are canceling the
297 // decryption. 300 // decryption.
298 EXPECT_CALL(*real_decryptor_, CancelDecrypt()) 301 EXPECT_CALL(*real_decryptor_, CancelDecrypt(stream_type_))
299 .WillOnce(ResetAndRunDecryptCB(&decrypt_cb, 302 .WillOnce(ResetAndRunDecryptCB(&decrypt_cb,
300 Decryptor::kError, null_buffer_)); 303 Decryptor::kError, null_buffer_));
301 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_)) 304 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_))
302 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 305 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
303 proxy_decryptor_.CancelDecrypt(); 306 proxy_decryptor_.CancelDecrypt(stream_type_);
304 307
305 message_loop_.Run(); 308 message_loop_.Run();
306 } 309 }
307 310
308 // Test the case where we try to decrypt again after the previous decrypt was 311 // Test the case where we try to decrypt again after the previous decrypt was
309 // canceled. 312 // canceled.
310 TEST_F(ProxyDecryptorTest, DecryptAfterCancelDecrypt) { 313 TEST_F(ProxyDecryptorTest, DecryptAfterCancelDecrypt) {
311 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId))) 314 EXPECT_CALL(client_, NeedKeyMock("", "", NotNull(), arraysize(kFakeKeyId)))
312 .Times(AtLeast(1)); 315 .Times(AtLeast(1));
313 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 316 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
314 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, null_buffer_)); 317 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, null_buffer_));
315 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 318 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
316 GenerateKeyRequest(); 319 GenerateKeyRequest();
317 320
318 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_)); 321 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, null_buffer_));
319 proxy_decryptor_.CancelDecrypt(); 322 proxy_decryptor_.CancelDecrypt(stream_type_);
320 323
321 AddKey(); 324 AddKey();
322 325
323 EXPECT_CALL(*real_decryptor_, Decrypt(encrypted_buffer_, _)) 326 EXPECT_CALL(*real_decryptor_, Decrypt(stream_type_, encrypted_buffer_, _))
324 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_)); 327 .WillOnce(RunDecryptCB(Decryptor::kSuccess, decrypted_buffer_));
325 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_)) 328 EXPECT_CALL(*this, DeliverBuffer(Decryptor::kSuccess, decrypted_buffer_))
326 .WillOnce(ScheduleMessageLoopToStop(&message_loop_)); 329 .WillOnce(ScheduleMessageLoopToStop(&message_loop_));
327 proxy_decryptor_.Decrypt(encrypted_buffer_, decrypt_cb_); 330 proxy_decryptor_.Decrypt(stream_type_, encrypted_buffer_, decrypt_cb_);
328 331
329 message_loop_.Run(); 332 message_loop_.Run();
330 } 333 }
331 334
332 } // namespace webkit_media 335 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/crypto/proxy_decryptor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698