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 #ifndef CONTENT_TEST_IMAGE_DECODER_TEST_H_
6 #define CONTENT_TEST_IMAGE_DECODER_TEST_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace blink
{ class WebImageDecoder
; }
19 // Decodes a handful of image files and compares their MD5 sums to the stored
20 // sums on disk. To recalculate the MD5 sums, uncomment the CALCULATE_MD5_SUMS
21 // #define in the .cc file.
23 // The image files and corresponding MD5 sums live in the directory
24 // chrome/test/data/*_decoder (where "*" is the format being tested).
26 // Note: The MD5 sums calculated in this test by little- and big-endian systems
27 // will differ, since no endianness correction is done. If we start compiling
28 // for big endian machines this should be fixed.
30 enum ImageDecoderTestFileSelection
{
36 // Returns the path the decoded data is saved at.
37 base::FilePath
GetMD5SumPath(const base::FilePath
& path
);
39 class ImageDecoderTest
: public testing::Test
{
41 explicit ImageDecoderTest(const std::string
& format
) : format_(format
) { }
44 void SetUp() override
;
46 // Returns the vector of image files for testing.
47 std::vector
<base::FilePath
> GetImageFiles() const;
49 // Returns true if the image is bogus and should not be successfully decoded.
50 bool ShouldImageFail(const base::FilePath
& path
) const;
52 // Tests if decoder decodes image at image_path with underlying frame at
53 // index desired_frame_index. The md5_sum_path is needed if the test is not
54 // asked to generate one, i.e. if #define CALCULATE_MD5_SUMS is not set.
55 void TestWebKitImageDecoder(const base::FilePath
& image_path
,
56 const base::FilePath
& md5_sum_path
,
57 int desired_frame_index
) const;
59 // Verifies each of the test image files is decoded correctly and matches the
60 // expected state. |file_selection| and |threshold| can be used to select
61 // files to test based on file size.
62 // If just the MD5 sum is wanted, this skips chunking.
63 void TestDecoding(ImageDecoderTestFileSelection file_selection
,
64 const int64 threshold
);
67 TestDecoding(TEST_ALL
, 0);
70 // Creates WebKit API's decoder.
71 virtual blink::WebImageDecoder
* CreateWebKitImageDecoder() const = 0;
73 // The format to be decoded, like "bmp" or "ico".
77 const base::FilePath
& data_dir() const { return data_dir_
; }
80 // Path to the test files.
81 base::FilePath data_dir_
;
83 DISALLOW_COPY_AND_ASSIGN(ImageDecoderTest
);
86 #endif // CONTENT_TEST_IMAGE_DECODER_TEST_H_