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