OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "base/files/file.h" |
5 #include "base/logging.h" | 6 #include "base/logging.h" |
6 #include "build/build_config.h" | 7 #include "build/build_config.h" |
7 #include "media/base/media_file_checker.h" | 8 #include "media/base/media_file_checker.h" |
8 #include "media/base/test_data_util.h" | 9 #include "media/base/test_data_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace media { | 12 namespace media { |
12 | 13 |
13 static void RunMediaFileChecker(const std::string& filename, bool expectation) { | 14 static void RunMediaFileChecker(const std::string& filename, bool expectation) { |
14 base::PlatformFileError error; | 15 base::File file(GetTestDataFilePath(filename), |
15 base::PlatformFile file = base::CreatePlatformFile( | 16 base::File::FLAG_OPEN | base::File::FLAG_READ); |
16 GetTestDataFilePath(filename), | 17 ASSERT_TRUE(file.IsValid()); |
17 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | |
18 NULL, | |
19 &error); | |
20 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | |
21 | 18 |
22 MediaFileChecker checker(file); | 19 MediaFileChecker checker(file.Pass()); |
23 const base::TimeDelta check_time = base::TimeDelta::FromMilliseconds(100); | 20 const base::TimeDelta check_time = base::TimeDelta::FromMilliseconds(100); |
24 bool result = checker.Start(check_time); | 21 bool result = checker.Start(check_time); |
25 EXPECT_EQ(expectation, result); | 22 EXPECT_EQ(expectation, result); |
26 | |
27 base::ClosePlatformFile(file); | |
28 } | 23 } |
29 | 24 |
30 TEST(MediaFileCheckerTest, InvalidFile) { | 25 TEST(MediaFileCheckerTest, InvalidFile) { |
31 RunMediaFileChecker("ten_byte_file", false); | 26 RunMediaFileChecker("ten_byte_file", false); |
32 } | 27 } |
33 | 28 |
34 TEST(MediaFileCheckerTest, Video) { | 29 TEST(MediaFileCheckerTest, Video) { |
35 RunMediaFileChecker("bear.ogv", true); | 30 RunMediaFileChecker("bear.ogv", true); |
36 } | 31 } |
37 | 32 |
38 TEST(MediaFileCheckerTest, Audio) { | 33 TEST(MediaFileCheckerTest, Audio) { |
39 RunMediaFileChecker("sfx.ogg", true); | 34 RunMediaFileChecker("sfx.ogg", true); |
40 } | 35 } |
41 | 36 |
42 #if defined(USE_PROPRIETARY_CODECS) | 37 #if defined(USE_PROPRIETARY_CODECS) |
43 TEST(MediaFileCheckerTest, MP3) { | 38 TEST(MediaFileCheckerTest, MP3) { |
44 RunMediaFileChecker("sfx.mp3", true); | 39 RunMediaFileChecker("sfx.mp3", true); |
45 } | 40 } |
46 #endif | 41 #endif |
47 | 42 |
48 } // namespace media | 43 } // namespace media |
OLD | NEW |