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