| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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" |
| 6 #include "media/formats/webm/webm_constants.h" |
| 5 #include "media/formats/webm/webm_content_encodings_client.h" | 7 #include "media/formats/webm/webm_content_encodings_client.h" |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "media/base/mock_media_log.h" | |
| 12 #include "media/formats/webm/webm_constants.h" | |
| 13 #include "media/formats/webm/webm_parser.h" | 8 #include "media/formats/webm/webm_parser.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 10 |
| 17 using ::testing::StrictMock; | |
| 18 | |
| 19 namespace media { | 11 namespace media { |
| 20 | 12 |
| 21 // Matchers for verifying common media log entry strings. | |
| 22 MATCHER(MissingContentEncoding, "") { | |
| 23 return CONTAINS_STRING(arg, "Missing ContentEncoding."); | |
| 24 } | |
| 25 | |
| 26 MATCHER(UnexpectedContentEncodingOrder, "") { | |
| 27 return CONTAINS_STRING(arg, "Unexpected ContentEncodingOrder."); | |
| 28 } | |
| 29 | |
| 30 MATCHER(UnexpectedContentEncodingScope, "") { | |
| 31 return CONTAINS_STRING(arg, "Unexpected ContentEncodingScope."); | |
| 32 } | |
| 33 | |
| 34 MATCHER(ContentCompressionNotSupported, "") { | |
| 35 return CONTAINS_STRING(arg, "ContentCompression not supported."); | |
| 36 } | |
| 37 | |
| 38 MATCHER(MissingContentEncryption, "") { | |
| 39 return CONTAINS_STRING( | |
| 40 arg, | |
| 41 "ContentEncodingType is encryption but ContentEncryption is missing."); | |
| 42 } | |
| 43 | |
| 44 MATCHER_P(UnexpectedContentEncAlgo, algo, "") { | |
| 45 return CONTAINS_STRING( | |
| 46 arg, "Unexpected ContentEncAlgo " + base::IntToString(algo) + "."); | |
| 47 } | |
| 48 | |
| 49 class WebMContentEncodingsClientTest : public testing::Test { | 13 class WebMContentEncodingsClientTest : public testing::Test { |
| 50 public: | 14 public: |
| 51 WebMContentEncodingsClientTest() | 15 WebMContentEncodingsClientTest() |
| 52 : media_log_(new StrictMock<MockMediaLog>()), | 16 : client_(new MediaLog()), parser_(kWebMIdContentEncodings, &client_) {} |
| 53 client_(media_log_), | |
| 54 parser_(kWebMIdContentEncodings, &client_) {} | |
| 55 | 17 |
| 56 void ParseAndExpectToFail(const uint8* buf, int size) { | 18 void ParseAndExpectToFail(const uint8* buf, int size) { |
| 57 int result = parser_.Parse(buf, size); | 19 int result = parser_.Parse(buf, size); |
| 58 EXPECT_EQ(-1, result); | 20 EXPECT_EQ(-1, result); |
| 59 } | 21 } |
| 60 | 22 |
| 61 protected: | 23 protected: |
| 62 scoped_refptr<StrictMock<MockMediaLog>> media_log_; | |
| 63 WebMContentEncodingsClient client_; | 24 WebMContentEncodingsClient client_; |
| 64 WebMListParser parser_; | 25 WebMListParser parser_; |
| 65 }; | 26 }; |
| 66 | 27 |
| 67 TEST_F(WebMContentEncodingsClientTest, EmptyContentEncodings) { | 28 TEST_F(WebMContentEncodingsClientTest, EmptyContentEncodings) { |
| 68 const uint8 kContentEncodings[] = { | 29 const uint8 kContentEncodings[] = { |
| 69 0x6D, 0x80, 0x80, // ContentEncodings (size = 0) | 30 0x6D, 0x80, 0x80, // ContentEncodings (size = 0) |
| 70 }; | 31 }; |
| 71 int size = sizeof(kContentEncodings); | 32 int size = sizeof(kContentEncodings); |
| 72 EXPECT_MEDIA_LOG(MissingContentEncoding()); | |
| 73 ParseAndExpectToFail(kContentEncodings, size); | 33 ParseAndExpectToFail(kContentEncodings, size); |
| 74 } | 34 } |
| 75 | 35 |
| 76 TEST_F(WebMContentEncodingsClientTest, EmptyContentEncoding) { | 36 TEST_F(WebMContentEncodingsClientTest, EmptyContentEncoding) { |
| 77 const uint8 kContentEncodings[] = { | 37 const uint8 kContentEncodings[] = { |
| 78 0x6D, 0x80, 0x83, // ContentEncodings (size = 3) | 38 0x6D, 0x80, 0x83, // ContentEncodings (size = 3) |
| 79 0x63, 0x40, 0x80, // ContentEncoding (size = 0) | 39 0x63, 0x40, 0x80, // ContentEncoding (size = 0) |
| 80 }; | 40 }; |
| 81 int size = sizeof(kContentEncodings); | 41 int size = sizeof(kContentEncodings); |
| 82 ParseAndExpectToFail(kContentEncodings, size); | 42 ParseAndExpectToFail(kContentEncodings, size); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 175 |
| 216 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingOrder) { | 176 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingOrder) { |
| 217 const uint8 kContentEncodings[] = { | 177 const uint8 kContentEncodings[] = { |
| 218 0x6D, 0x80, 0x8E, // ContentEncodings (size = 14) | 178 0x6D, 0x80, 0x8E, // ContentEncodings (size = 14) |
| 219 0x62, 0x40, 0x8B, // ContentEncoding (size = 11) | 179 0x62, 0x40, 0x8B, // ContentEncoding (size = 11) |
| 220 0x50, 0x31, 0x81, 0xEE, // ContentEncodingOrder (size = 1), invalid | 180 0x50, 0x31, 0x81, 0xEE, // ContentEncodingOrder (size = 1), invalid |
| 221 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) | 181 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) |
| 222 0x50, 0x35, 0x80, // ContentEncryption (size = 0) | 182 0x50, 0x35, 0x80, // ContentEncryption (size = 0) |
| 223 }; | 183 }; |
| 224 int size = sizeof(kContentEncodings); | 184 int size = sizeof(kContentEncodings); |
| 225 EXPECT_MEDIA_LOG(UnexpectedContentEncodingOrder()); | |
| 226 ParseAndExpectToFail(kContentEncodings, size); | 185 ParseAndExpectToFail(kContentEncodings, size); |
| 227 } | 186 } |
| 228 | 187 |
| 229 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingScope) { | 188 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingScope) { |
| 230 const uint8 kContentEncodings[] = { | 189 const uint8 kContentEncodings[] = { |
| 231 0x6D, 0x80, 0x8E, // ContentEncodings (size = 14) | 190 0x6D, 0x80, 0x8E, // ContentEncodings (size = 14) |
| 232 0x62, 0x40, 0x8B, // ContentEncoding (size = 11) | 191 0x62, 0x40, 0x8B, // ContentEncoding (size = 11) |
| 233 0x50, 0x32, 0x81, 0xEE, // ContentEncodingScope (size = 1), invalid | 192 0x50, 0x32, 0x81, 0xEE, // ContentEncodingScope (size = 1), invalid |
| 234 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) | 193 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) |
| 235 0x50, 0x35, 0x80, // ContentEncryption (size = 0) | 194 0x50, 0x35, 0x80, // ContentEncryption (size = 0) |
| 236 }; | 195 }; |
| 237 int size = sizeof(kContentEncodings); | 196 int size = sizeof(kContentEncodings); |
| 238 EXPECT_MEDIA_LOG(UnexpectedContentEncodingScope()); | |
| 239 ParseAndExpectToFail(kContentEncodings, size); | 197 ParseAndExpectToFail(kContentEncodings, size); |
| 240 } | 198 } |
| 241 | 199 |
| 242 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingType) { | 200 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingType) { |
| 243 const uint8 kContentEncodings[] = { | 201 const uint8 kContentEncodings[] = { |
| 244 0x6D, 0x80, 0x8E, // ContentEncodings (size = 14) | 202 0x6D, 0x80, 0x8E, // ContentEncodings (size = 14) |
| 245 0x62, 0x40, 0x8B, // ContentEncoding (size = 11) | 203 0x62, 0x40, 0x8B, // ContentEncoding (size = 11) |
| 246 0x50, 0x33, 0x81, 0x00, // ContentEncodingType (size = 1), invalid | 204 0x50, 0x33, 0x81, 0x00, // ContentEncodingType (size = 1), invalid |
| 247 0x50, 0x35, 0x80, // ContentEncryption (size = 0) | 205 0x50, 0x35, 0x80, // ContentEncryption (size = 0) |
| 248 }; | 206 }; |
| 249 int size = sizeof(kContentEncodings); | 207 int size = sizeof(kContentEncodings); |
| 250 EXPECT_MEDIA_LOG(ContentCompressionNotSupported()); | |
| 251 ParseAndExpectToFail(kContentEncodings, size); | 208 ParseAndExpectToFail(kContentEncodings, size); |
| 252 } | 209 } |
| 253 | 210 |
| 254 // ContentEncodingType is encryption but no ContentEncryption present. | 211 // ContentEncodingType is encryption but no ContentEncryption present. |
| 255 TEST_F(WebMContentEncodingsClientTest, MissingContentEncryption) { | 212 TEST_F(WebMContentEncodingsClientTest, MissingContentEncryption) { |
| 256 const uint8 kContentEncodings[] = { | 213 const uint8 kContentEncodings[] = { |
| 257 0x6D, 0x80, 0x87, // ContentEncodings (size = 7) | 214 0x6D, 0x80, 0x87, // ContentEncodings (size = 7) |
| 258 0x62, 0x40, 0x84, // ContentEncoding (size = 4) | 215 0x62, 0x40, 0x84, // ContentEncoding (size = 4) |
| 259 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) | 216 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) |
| 260 // ContentEncryption missing | 217 // ContentEncryption missing |
| 261 }; | 218 }; |
| 262 int size = sizeof(kContentEncodings); | 219 int size = sizeof(kContentEncodings); |
| 263 EXPECT_MEDIA_LOG(MissingContentEncryption()); | |
| 264 ParseAndExpectToFail(kContentEncodings, size); | 220 ParseAndExpectToFail(kContentEncodings, size); |
| 265 } | 221 } |
| 266 | 222 |
| 267 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncAlgo) { | 223 TEST_F(WebMContentEncodingsClientTest, InvalidContentEncAlgo) { |
| 268 const uint8 kContentEncodings[] = { | 224 const uint8 kContentEncodings[] = { |
| 269 0x6D, 0x80, 0x99, // ContentEncodings (size = 25) | 225 0x6D, 0x80, 0x99, // ContentEncodings (size = 25) |
| 270 0x62, 0x40, 0x96, // ContentEncoding (size = 22) | 226 0x62, 0x40, 0x96, // ContentEncoding (size = 22) |
| 271 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) | 227 0x50, 0x33, 0x81, 0x01, // ContentEncodingType (size = 1) |
| 272 0x50, 0x35, 0x8F, // ContentEncryption (size = 15) | 228 0x50, 0x35, 0x8F, // ContentEncryption (size = 15) |
| 273 0x47, 0xE1, 0x81, 0xEE, // ContentEncAlgo (size = 1), invalid | 229 0x47, 0xE1, 0x81, 0xEE, // ContentEncAlgo (size = 1), invalid |
| 274 0x47, 0xE2, 0x88, // ContentEncKeyID (size = 8) | 230 0x47, 0xE2, 0x88, // ContentEncKeyID (size = 8) |
| 275 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, | 231 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
| 276 }; | 232 }; |
| 277 int size = sizeof(kContentEncodings); | 233 int size = sizeof(kContentEncodings); |
| 278 EXPECT_MEDIA_LOG(UnexpectedContentEncAlgo(0xEE)); | |
| 279 ParseAndExpectToFail(kContentEncodings, size); | 234 ParseAndExpectToFail(kContentEncodings, size); |
| 280 } | 235 } |
| 281 | 236 |
| 282 } // namespace media | 237 } // namespace media |
| OLD | NEW |