Fix initial focus finding, ignore div nodes, and resolve aria-label name calculation.
[chromium-blink-merge.git] / media / filters / jpeg_parser_unittest.cc
blobf2ae889a4a33bd90b14a16740bfe570747fa90d8
1 // Copyright 2015 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 "base/at_exit.h"
6 #include "base/files/memory_mapped_file.h"
7 #include "base/path_service.h"
8 #include "media/base/test_data_util.h"
9 #include "media/filters/jpeg_parser.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace media {
14 TEST(JpegParserTest, Parsing) {
15 base::FilePath data_dir;
16 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir));
18 // This sample frame is captured from Chromebook Pixel
19 base::FilePath file_path = data_dir.AppendASCII("media")
20 .AppendASCII("test")
21 .AppendASCII("data")
22 .AppendASCII("pixel-1280x720.jpg");
24 base::MemoryMappedFile stream;
25 ASSERT_TRUE(stream.Initialize(file_path))
26 << "Couldn't open stream file: " << file_path.MaybeAsASCII();
28 JpegParseResult result;
29 ASSERT_TRUE(ParseJpegPicture(stream.data(), stream.length(), &result));
31 // Verify selected fields
33 // SOF fields
34 EXPECT_EQ(1280, result.frame_header.visible_width);
35 EXPECT_EQ(720, result.frame_header.visible_height);
36 EXPECT_EQ(1280, result.frame_header.coded_width);
37 EXPECT_EQ(720, result.frame_header.coded_height);
38 EXPECT_EQ(3, result.frame_header.num_components);
39 EXPECT_EQ(1, result.frame_header.components[0].id);
40 EXPECT_EQ(2, result.frame_header.components[0].horizontal_sampling_factor);
41 EXPECT_EQ(1, result.frame_header.components[0].vertical_sampling_factor);
42 EXPECT_EQ(0, result.frame_header.components[0].quantization_table_selector);
43 EXPECT_EQ(2, result.frame_header.components[1].id);
44 EXPECT_EQ(1, result.frame_header.components[1].horizontal_sampling_factor);
45 EXPECT_EQ(1, result.frame_header.components[1].vertical_sampling_factor);
46 EXPECT_EQ(1, result.frame_header.components[1].quantization_table_selector);
47 EXPECT_EQ(3, result.frame_header.components[2].id);
48 EXPECT_EQ(1, result.frame_header.components[2].horizontal_sampling_factor);
49 EXPECT_EQ(1, result.frame_header.components[2].vertical_sampling_factor);
50 EXPECT_EQ(1, result.frame_header.components[2].quantization_table_selector);
52 // DRI fields
53 EXPECT_EQ(0, result.restart_interval);
55 // DQT fields
56 EXPECT_TRUE(result.q_table[0].valid);
57 EXPECT_TRUE(result.q_table[1].valid);
58 EXPECT_FALSE(result.q_table[2].valid);
59 EXPECT_FALSE(result.q_table[3].valid);
61 // DHT fields (no DHT marker)
62 EXPECT_FALSE(result.dc_table[0].valid);
63 EXPECT_FALSE(result.ac_table[0].valid);
64 EXPECT_FALSE(result.dc_table[1].valid);
65 EXPECT_FALSE(result.ac_table[1].valid);
67 // SOS fields
68 EXPECT_EQ(3, result.scan.num_components);
69 EXPECT_EQ(1, result.scan.components[0].component_selector);
70 EXPECT_EQ(0, result.scan.components[0].dc_selector);
71 EXPECT_EQ(0, result.scan.components[0].ac_selector);
72 EXPECT_EQ(2, result.scan.components[1].component_selector);
73 EXPECT_EQ(1, result.scan.components[1].dc_selector);
74 EXPECT_EQ(1, result.scan.components[1].ac_selector);
75 EXPECT_EQ(3, result.scan.components[2].component_selector);
76 EXPECT_EQ(1, result.scan.components[2].dc_selector);
77 EXPECT_EQ(1, result.scan.components[2].ac_selector);
78 EXPECT_EQ(121150u, result.data_size);
81 TEST(JpegParserTest, CodedSizeNotEqualVisibleSize) {
82 base::FilePath data_dir;
83 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir));
85 base::FilePath file_path = data_dir.AppendASCII("media")
86 .AppendASCII("test")
87 .AppendASCII("data")
88 .AppendASCII("blank-1x1.jpg");
90 base::MemoryMappedFile stream;
91 ASSERT_TRUE(stream.Initialize(file_path))
92 << "Couldn't open stream file: " << file_path.MaybeAsASCII();
94 JpegParseResult result;
95 ASSERT_TRUE(ParseJpegPicture(stream.data(), stream.length(), &result));
97 EXPECT_EQ(1, result.frame_header.visible_width);
98 EXPECT_EQ(1, result.frame_header.visible_height);
99 // The sampling factor of the given image is 2:2, so coded size is 16x16
100 EXPECT_EQ(16, result.frame_header.coded_width);
101 EXPECT_EQ(16, result.frame_header.coded_height);
102 EXPECT_EQ(2, result.frame_header.components[0].horizontal_sampling_factor);
103 EXPECT_EQ(2, result.frame_header.components[0].vertical_sampling_factor);
106 TEST(JpegParserTest, ParsingFail) {
107 const uint8_t data[] = {0, 1, 2, 3}; // not jpeg
108 JpegParseResult result;
109 ASSERT_FALSE(ParseJpegPicture(data, sizeof(data), &result));
112 } // namespace media