OLD | NEW |
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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "media/base/decoder_buffer.h" | 11 #include "media/base/decoder_buffer.h" |
12 #include "media/base/decrypt_config.h" | 12 #include "media/base/decrypt_config.h" |
13 #include "media/base/mock_filters.h" | 13 #include "media/base/mock_filters.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using ::testing::_; | 17 using ::testing::_; |
18 using ::testing::AtLeast; | 18 using ::testing::AtLeast; |
19 using ::testing::IsNull; | 19 using ::testing::IsNull; |
20 using ::testing::NotNull; | 20 using ::testing::NotNull; |
21 | 21 |
22 using media::DecoderBuffer; | 22 using media::DecoderBuffer; |
23 using media::DecryptConfig; | 23 using media::DecryptConfig; |
24 using media::Decryptor; | 24 using media::Decryptor; |
25 | 25 |
26 namespace webkit_media { | 26 namespace webkit_media { |
27 | 27 |
28 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; | 28 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; |
29 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; | 29 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; |
30 static const uint8 kFakeCheckSum[] = { 0, 0 }; | |
31 static const char kFakeKeySystem[] = "system.key.fake"; | 30 static const char kFakeKeySystem[] = "system.key.fake"; |
32 static const char kFakeSessionId[] = "FakeSessionId"; | 31 static const char kFakeSessionId[] = "FakeSessionId"; |
33 static const uint8 kFakeKey[] = { 0x4b, 0x65, 0x79 }; | 32 static const uint8 kFakeKey[] = { 0x4b, 0x65, 0x79 }; |
34 static const uint8 kEncryptedData[] = { 0x65, 0x6E, 0x63, 0x72, 0x79 }; | 33 static const uint8 kEncryptedData[] = { 0x65, 0x6E, 0x63, 0x72, 0x79 }; |
35 static const uint8 kDecryptedData[] = { 0x64, 0x65, 0x63, 0x72, 0x79 }; | 34 static const uint8 kDecryptedData[] = { 0x64, 0x65, 0x63, 0x72, 0x79 }; |
36 | 35 |
37 // Creates a fake non-empty encrypted buffer. | 36 // Creates a fake non-empty encrypted buffer. |
38 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { | 37 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { |
39 const int encrypted_frame_offset = 1; // This should be non-zero. | 38 const int encrypted_frame_offset = 1; // This should be non-zero. |
40 scoped_refptr<DecoderBuffer> encrypted_buffer = | 39 scoped_refptr<DecoderBuffer> encrypted_buffer = |
41 DecoderBuffer::CopyFrom(kEncryptedData, arraysize(kEncryptedData)); | 40 DecoderBuffer::CopyFrom(kEncryptedData, arraysize(kEncryptedData)); |
42 encrypted_buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>( | 41 encrypted_buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>( |
43 new DecryptConfig( | 42 new DecryptConfig( |
44 std::string(reinterpret_cast<const char*>(kFakeKeyId), | 43 std::string(reinterpret_cast<const char*>(kFakeKeyId), |
45 arraysize(kFakeKeyId)), | 44 arraysize(kFakeKeyId)), |
46 std::string(reinterpret_cast<const char*>(kFakeIv), | 45 std::string(reinterpret_cast<const char*>(kFakeIv), |
47 DecryptConfig::kDecryptionKeySize), | 46 DecryptConfig::kDecryptionKeySize), |
48 std::string(reinterpret_cast<const char*>(kFakeCheckSum), | |
49 arraysize(kFakeCheckSum)), | |
50 encrypted_frame_offset, | 47 encrypted_frame_offset, |
51 std::vector<media::SubsampleEntry>()))); | 48 std::vector<media::SubsampleEntry>()))); |
52 return encrypted_buffer; | 49 return encrypted_buffer; |
53 } | 50 } |
54 | 51 |
55 ACTION_P2(RunDecryptCB, status, buffer) { | 52 ACTION_P2(RunDecryptCB, status, buffer) { |
56 arg1.Run(status, buffer); | 53 arg1.Run(status, buffer); |
57 } | 54 } |
58 | 55 |
59 ACTION_P(ScheduleMessageLoopToStop, message_loop) { | 56 ACTION_P(ScheduleMessageLoopToStop, message_loop) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 EXPECT_CALL(*real_decryptor_, Stop()); | 217 EXPECT_CALL(*real_decryptor_, Stop()); |
221 EXPECT_CALL(*this, BufferDecrypted(Decryptor::kError, null_buffer_)) | 218 EXPECT_CALL(*this, BufferDecrypted(Decryptor::kError, null_buffer_)) |
222 .Times(3); | 219 .Times(3); |
223 proxy_decryptor_.Stop(); | 220 proxy_decryptor_.Stop(); |
224 | 221 |
225 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 222 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
226 message_loop_.Run(); | 223 message_loop_.Run(); |
227 } | 224 } |
228 | 225 |
229 } // namespace webkit_media | 226 } // namespace webkit_media |
OLD | NEW |