Add some instrumentation for jank in URLRequest::Start.
[chromium-blink-merge.git] / media / formats / mpeg / mpeg1_audio_stream_parser_unittest.cc
blobb247acb42cf3bc88bf369914919affe0b2343326
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
3 // found in the LICENSE file.
5 #include "media/base/test_data_util.h"
6 #include "media/formats/common/stream_parser_test_base.h"
7 #include "media/formats/mpeg/mpeg1_audio_stream_parser.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
12 class MPEG1AudioStreamParserTest
13 : public StreamParserTestBase, public testing::Test {
14 public:
15 MPEG1AudioStreamParserTest()
16 : StreamParserTestBase(make_scoped_ptr(new MPEG1AudioStreamParser())) {}
19 // Test parsing with small prime sized chunks to smoke out "power of
20 // 2" field size assumptions.
21 TEST_F(MPEG1AudioStreamParserTest, UnalignedAppend) {
22 const std::string expected =
23 "NewSegment"
24 "{ 0K }"
25 "{ 0K }"
26 "{ 0K }"
27 "{ 0K }"
28 "{ 0K }"
29 "{ 0K }"
30 "{ 0K }"
31 "EndOfSegment"
32 "NewSegment"
33 "{ 0K }"
34 "{ 0K }"
35 "{ 0K }"
36 "EndOfSegment"
37 "NewSegment"
38 "{ 0K }"
39 "{ 0K }"
40 "EndOfSegment";
41 EXPECT_EQ(expected, ParseFile("sfx.mp3", 17));
42 EXPECT_GT(last_audio_config().codec_delay(), 0);
45 // Test parsing with a larger piece size to verify that multiple buffers
46 // are passed to |new_buffer_cb_|.
47 TEST_F(MPEG1AudioStreamParserTest, UnalignedAppend512) {
48 const std::string expected =
49 "NewSegment"
50 "{ 0K 26K 52K 78K }"
51 "EndOfSegment"
52 "NewSegment"
53 "{ 0K 26K 52K }"
54 "{ 0K 26K 52K 78K }"
55 "{ 0K }"
56 "EndOfSegment";
57 EXPECT_EQ(expected, ParseFile("sfx.mp3", 512));
58 EXPECT_GT(last_audio_config().codec_delay(), 0);
61 TEST_F(MPEG1AudioStreamParserTest, MetadataParsing) {
62 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("sfx.mp3");
63 const uint8_t* buffer_ptr = buffer->data();
65 // The first 32 bytes of sfx.mp3 are an ID3 tag, so no segments should be
66 // extracted after appending those bytes.
67 const int kId3TagSize = 32;
68 EXPECT_EQ("", ParseData(buffer_ptr, kId3TagSize));
69 EXPECT_FALSE(last_audio_config().IsValidConfig());
70 buffer_ptr += kId3TagSize;
72 // The next 417 bytes are a Xing frame; with the identifier 21 bytes into
73 // the frame. Appending less than 21 bytes, should result in no segments
74 // nor an AudioDecoderConfig being created.
75 const int kXingTagPosition = 21;
76 EXPECT_EQ("", ParseData(buffer_ptr, kXingTagPosition));
77 EXPECT_FALSE(last_audio_config().IsValidConfig());
78 buffer_ptr += kXingTagPosition;
80 // Appending the rests of the Xing frame should result in no segments, but
81 // should generate a valid AudioDecoderConfig.
82 const int kXingRemainingSize = 417 - kXingTagPosition;
83 EXPECT_EQ("", ParseData(buffer_ptr, kXingRemainingSize));
84 EXPECT_TRUE(last_audio_config().IsValidConfig());
85 buffer_ptr += kXingRemainingSize;
87 // Append the first real frame and ensure we get a segment.
88 const int kFirstRealFrameSize = 182;
89 EXPECT_EQ("NewSegment{ 0K }EndOfSegment",
90 ParseData(buffer_ptr, kFirstRealFrameSize));
91 EXPECT_TRUE(last_audio_config().IsValidConfig());
94 } // namespace media