Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / common / gpu / media / h264_parser_unittest.cc
blobd52bb5122094f519f409cd453af2245393092326
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
3 // found in the LICENSE file.
5 #include "testing/gtest/include/gtest/gtest.h"
7 #include "base/command_line.h"
8 #include "base/files/memory_mapped_file.h"
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "content/common/gpu/media/h264_parser.h"
13 using content::H264Parser;
14 using content::H264NALU;
16 const base::FilePath::CharType* test_stream_filename =
17 FILE_PATH_LITERAL("content/common/gpu/testdata/test-25fps.h264");
18 // Number of NALUs in the stream to be parsed.
19 int num_nalus = 759;
21 TEST(H264ParserTest, StreamFileParsing) {
22 base::FilePath fp(test_stream_filename);
23 base::MemoryMappedFile stream;
24 CHECK(stream.Initialize(fp)) << "Couldn't open stream file: "
25 << test_stream_filename;
26 DVLOG(1) << "Parsing file: " << test_stream_filename;
28 H264Parser parser;
29 parser.SetStream(stream.data(), stream.length());
31 // Parse until the end of stream/unsupported stream/error in stream is found.
32 int num_parsed_nalus = 0;
33 while (true) {
34 content::H264SliceHeader shdr;
35 content::H264SEIMessage sei_msg;
36 H264NALU nalu;
37 H264Parser::Result res = parser.AdvanceToNextNALU(&nalu);
38 if (res == H264Parser::kEOStream) {
39 DVLOG(1) << "Number of successfully parsed NALUs before EOS: "
40 << num_parsed_nalus;
41 ASSERT_EQ(num_nalus, num_parsed_nalus);
42 return;
44 ASSERT_EQ(res, H264Parser::kOk);
46 ++num_parsed_nalus;
48 int id;
49 switch (nalu.nal_unit_type) {
50 case H264NALU::kIDRSlice:
51 case H264NALU::kNonIDRSlice:
52 ASSERT_EQ(parser.ParseSliceHeader(nalu, &shdr), H264Parser::kOk);
53 break;
55 case H264NALU::kSPS:
56 ASSERT_EQ(parser.ParseSPS(&id), H264Parser::kOk);
57 break;
59 case H264NALU::kPPS:
60 ASSERT_EQ(parser.ParsePPS(&id), H264Parser::kOk);
61 break;
63 case H264NALU::kSEIMessage:
64 ASSERT_EQ(parser.ParseSEI(&sei_msg), H264Parser::kOk);
65 break;
67 default:
68 // Skip unsupported NALU.
69 DVLOG(4) << "Skipping unsupported NALU";
70 break;
75 int main(int argc, char **argv) {
76 ::testing::InitGoogleTest(&argc, argv);
77 CommandLine::Init(argc, argv);
79 const CommandLine::SwitchMap& switches =
80 CommandLine::ForCurrentProcess()->GetSwitches();
81 for (CommandLine::SwitchMap::const_iterator it = switches.begin();
82 it != switches.end(); ++it) {
83 if (it->first == "test_stream") {
84 test_stream_filename = it->second.c_str();
85 } else if (it->first == "num_nalus") {
86 CHECK(base::StringToInt(it->second, &num_nalus));
87 } else {
88 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
92 return RUN_ALL_TESTS();