Update Flash minimum secure versions.
[chromium-blink-merge.git] / chrome / utility / media_galleries / image_metadata_extractor_unittest.cc
blobfaba6a6598cd10f97cc49efc68444019fe85d2cf
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 "base/bind.h"
6 #include "base/files/file_path.h"
7 #include "base/path_service.h"
8 #include "base/run_loop.h"
9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/utility/media_galleries/image_metadata_extractor.h"
11 #include "media/filters/file_data_source.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace metadata {
16 void QuitLoop(base::RunLoop* loop, bool* output, bool success) {
17 loop->Quit();
18 *output = success;
21 base::FilePath GetTestDataFilePath(const std::string& filename) {
22 base::FilePath path;
23 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
24 path = path.AppendASCII("extensions").AppendASCII("api_test")
25 .AppendASCII("wallpaper").AppendASCII(filename);
26 return path;
29 scoped_ptr<ImageMetadataExtractor> GetExtractor(
30 const std::string& filename,
31 bool expected_result) {
32 EXPECT_TRUE(ImageMetadataExtractor::InitializeLibraryForTesting());
34 media::FileDataSource source;
35 base::FilePath test_path;
37 EXPECT_TRUE(source.Initialize(GetTestDataFilePath(filename)));
39 scoped_ptr<ImageMetadataExtractor> extractor(new ImageMetadataExtractor);
41 base::RunLoop loop;
42 bool extracted = false;
43 extractor->Extract(&source, base::Bind(&QuitLoop, &loop, &extracted));
44 EXPECT_EQ(expected_result, extracted);
46 return extractor.Pass();
49 TEST(ImageMetadataExtractorTest, JPGFile) {
50 scoped_ptr<ImageMetadataExtractor> extractor =
51 GetExtractor("test.jpg", true);
53 EXPECT_EQ(5616, extractor->width());
54 EXPECT_EQ(3744, extractor->height());
55 EXPECT_EQ(0, extractor->rotation());
56 EXPECT_EQ(300.0, extractor->x_resolution());
57 EXPECT_EQ(300.0, extractor->y_resolution());
58 EXPECT_EQ("2012:03:01 17:06:07", extractor->date());
59 EXPECT_EQ("Canon", extractor->camera_make());
60 EXPECT_EQ("Canon EOS 5D Mark II", extractor->camera_model());
61 EXPECT_EQ(0.01, extractor->exposure_time_sec());
62 EXPECT_FALSE(extractor->flash_fired());
63 EXPECT_EQ(3.2, extractor->f_number());
64 EXPECT_EQ(100, extractor->focal_length_mm());
65 EXPECT_EQ(1600, extractor->iso_equivalent());
68 TEST(ImageMetadataExtractorTest, PNGFile) {
69 GetExtractor("test.png", false);
72 TEST(ImageMetadataExtractorTest, NonImageFile) {
73 GetExtractor("test.js", false);
76 } // namespace metadata