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/file_util_proxy.h" | 5 #include "base/file_util_proxy.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 ASSERT_TRUE(file_thread_.Start()); | 33 ASSERT_TRUE(file_thread_.Start()); |
34 } | 34 } |
35 | 35 |
36 virtual void TearDown() OVERRIDE { | 36 virtual void TearDown() OVERRIDE { |
37 if (file_ != kInvalidPlatformFileValue) | 37 if (file_ != kInvalidPlatformFileValue) |
38 ClosePlatformFile(file_); | 38 ClosePlatformFile(file_); |
39 } | 39 } |
40 | 40 |
41 void DidFinish(PlatformFileError error) { | 41 void DidFinish(PlatformFileError error) { |
42 error_ = error; | 42 error_ = error; |
43 MessageLoop::current()->Quit(); | 43 MessageLoop::current()->QuitWhenIdle(); |
44 } | 44 } |
45 | 45 |
46 void DidCreateOrOpen(PlatformFileError error, | 46 void DidCreateOrOpen(PlatformFileError error, |
47 PassPlatformFile file, | 47 PassPlatformFile file, |
48 bool created) { | 48 bool created) { |
49 error_ = error; | 49 error_ = error; |
50 file_ = file.ReleaseValue(); | 50 file_ = file.ReleaseValue(); |
51 created_ = created; | 51 created_ = created; |
52 MessageLoop::current()->Quit(); | 52 MessageLoop::current()->QuitWhenIdle(); |
53 } | 53 } |
54 | 54 |
55 void DidCreateTemporary(PlatformFileError error, | 55 void DidCreateTemporary(PlatformFileError error, |
56 PassPlatformFile file, | 56 PassPlatformFile file, |
57 const FilePath& path) { | 57 const FilePath& path) { |
58 error_ = error; | 58 error_ = error; |
59 file_ = file.ReleaseValue(); | 59 file_ = file.ReleaseValue(); |
60 path_ = path; | 60 path_ = path; |
61 MessageLoop::current()->Quit(); | 61 MessageLoop::current()->QuitWhenIdle(); |
62 } | 62 } |
63 | 63 |
64 void DidGetFileInfo(PlatformFileError error, | 64 void DidGetFileInfo(PlatformFileError error, |
65 const PlatformFileInfo& file_info) { | 65 const PlatformFileInfo& file_info) { |
66 error_ = error; | 66 error_ = error; |
67 file_info_ = file_info; | 67 file_info_ = file_info; |
68 MessageLoop::current()->Quit(); | 68 MessageLoop::current()->QuitWhenIdle(); |
69 } | 69 } |
70 | 70 |
71 void DidRead(PlatformFileError error, | 71 void DidRead(PlatformFileError error, |
72 const char* data, | 72 const char* data, |
73 int bytes_read) { | 73 int bytes_read) { |
74 error_ = error; | 74 error_ = error; |
75 buffer_.resize(bytes_read); | 75 buffer_.resize(bytes_read); |
76 memcpy(&buffer_[0], data, bytes_read); | 76 memcpy(&buffer_[0], data, bytes_read); |
77 MessageLoop::current()->Quit(); | 77 MessageLoop::current()->QuitWhenIdle(); |
78 } | 78 } |
79 | 79 |
80 void DidWrite(PlatformFileError error, | 80 void DidWrite(PlatformFileError error, |
81 int bytes_written) { | 81 int bytes_written) { |
82 error_ = error; | 82 error_ = error; |
83 bytes_written_ = bytes_written; | 83 bytes_written_ = bytes_written; |
84 MessageLoop::current()->Quit(); | 84 MessageLoop::current()->QuitWhenIdle(); |
85 } | 85 } |
86 | 86 |
87 protected: | 87 protected: |
88 PlatformFile GetTestPlatformFile(int flags) { | 88 PlatformFile GetTestPlatformFile(int flags) { |
89 if (file_ != kInvalidPlatformFileValue) | 89 if (file_ != kInvalidPlatformFileValue) |
90 return file_; | 90 return file_; |
91 bool created; | 91 bool created; |
92 PlatformFileError error; | 92 PlatformFileError error; |
93 file_ = CreatePlatformFile(test_path(), flags, &created, &error); | 93 file_ = CreatePlatformFile(test_path(), flags, &created, &error); |
94 EXPECT_EQ(PLATFORM_FILE_OK, error); | 94 EXPECT_EQ(PLATFORM_FILE_OK, error); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 char buffer[53]; | 401 char buffer[53]; |
402 EXPECT_EQ(53, file_util::ReadFile(test_path(), buffer, 53)); | 402 EXPECT_EQ(53, file_util::ReadFile(test_path(), buffer, 53)); |
403 int i = 0; | 403 int i = 0; |
404 for (; i < 10; ++i) | 404 for (; i < 10; ++i) |
405 EXPECT_EQ(kTestData[i], buffer[i]); | 405 EXPECT_EQ(kTestData[i], buffer[i]); |
406 for (; i < 53; ++i) | 406 for (; i < 53; ++i) |
407 EXPECT_EQ(0, buffer[i]); | 407 EXPECT_EQ(0, buffer[i]); |
408 } | 408 } |
409 | 409 |
410 } // namespace base | 410 } // namespace base |
OLD | NEW |