OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_util_proxy.h" | 5 #include "base/files/file_util_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 class FileUtilProxyTest : public testing::Test { | 17 class FileUtilProxyTest : public testing::Test { |
18 public: | 18 public: |
19 FileUtilProxyTest() | 19 FileUtilProxyTest() |
20 : file_thread_("FileUtilProxyTestFileThread"), | 20 : file_thread_("FileUtilProxyTestFileThread"), |
21 error_(File::FILE_OK), | 21 error_(File::FILE_OK), |
22 created_(false), | |
23 bytes_written_(-1), | |
24 weak_factory_(this) {} | 22 weak_factory_(this) {} |
25 | 23 |
26 void SetUp() override { | 24 void SetUp() override { |
27 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 25 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
28 ASSERT_TRUE(file_thread_.Start()); | 26 ASSERT_TRUE(file_thread_.Start()); |
29 } | 27 } |
30 | 28 |
31 void DidFinish(File::Error error) { | 29 void DidFinish(File::Error error) { |
32 error_ = error; | 30 error_ = error; |
33 MessageLoop::current()->QuitWhenIdle(); | 31 MessageLoop::current()->QuitWhenIdle(); |
(...skipping 11 matching lines...) Expand all Loading... |
45 return file_thread_.message_loop_proxy().get(); | 43 return file_thread_.message_loop_proxy().get(); |
46 } | 44 } |
47 const FilePath& test_dir_path() const { return dir_.path(); } | 45 const FilePath& test_dir_path() const { return dir_.path(); } |
48 const FilePath test_path() const { return dir_.path().AppendASCII("test"); } | 46 const FilePath test_path() const { return dir_.path().AppendASCII("test"); } |
49 | 47 |
50 MessageLoopForIO message_loop_; | 48 MessageLoopForIO message_loop_; |
51 Thread file_thread_; | 49 Thread file_thread_; |
52 | 50 |
53 ScopedTempDir dir_; | 51 ScopedTempDir dir_; |
54 File::Error error_; | 52 File::Error error_; |
55 bool created_; | |
56 FilePath path_; | 53 FilePath path_; |
57 File::Info file_info_; | 54 File::Info file_info_; |
58 std::vector<char> buffer_; | 55 std::vector<char> buffer_; |
59 int bytes_written_; | |
60 WeakPtrFactory<FileUtilProxyTest> weak_factory_; | 56 WeakPtrFactory<FileUtilProxyTest> weak_factory_; |
61 }; | 57 }; |
62 | 58 |
63 | 59 |
64 TEST_F(FileUtilProxyTest, GetFileInfo_File) { | 60 TEST_F(FileUtilProxyTest, GetFileInfo_File) { |
65 // Setup. | 61 // Setup. |
66 ASSERT_EQ(4, WriteFile(test_path(), "test", 4)); | 62 ASSERT_EQ(4, WriteFile(test_path(), "test", 4)); |
67 File::Info expected_info; | 63 File::Info expected_info; |
68 GetFileInfo(test_path(), &expected_info); | 64 GetFileInfo(test_path(), &expected_info); |
69 | 65 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 122 |
127 // The returned values may only have the seconds precision, so we cast | 123 // The returned values may only have the seconds precision, so we cast |
128 // the double values to int here. | 124 // the double values to int here. |
129 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()), | 125 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()), |
130 static_cast<int>(info.last_modified.ToDoubleT())); | 126 static_cast<int>(info.last_modified.ToDoubleT())); |
131 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()), | 127 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()), |
132 static_cast<int>(info.last_accessed.ToDoubleT())); | 128 static_cast<int>(info.last_accessed.ToDoubleT())); |
133 } | 129 } |
134 | 130 |
135 } // namespace base | 131 } // namespace base |
OLD | NEW |