Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: content/browser/fileapi/file_system_operation_runner_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/platform_file.h" 8 #include "base/platform_file.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/public/test/test_file_system_context.h" 10 #include "content/public/test/test_file_system_context.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/browser/fileapi/file_system_context.h" 12 #include "webkit/browser/fileapi/file_system_context.h"
13 #include "webkit/browser/fileapi/file_system_operation_runner.h" 13 #include "webkit/browser/fileapi/file_system_operation_runner.h"
14 14
15 using fileapi::FileSystemContext; 15 using fileapi::FileSystemContext;
16 using fileapi::FileSystemOperationRunner; 16 using fileapi::FileSystemOperationRunner;
17 using fileapi::FileSystemType; 17 using fileapi::FileSystemType;
18 using fileapi::FileSystemURL; 18 using fileapi::FileSystemURL;
19 19
20 namespace content { 20 namespace content {
21 21
22 void GetStatus(bool* done, 22 void GetStatus(bool* done,
23 base::PlatformFileError *status_out, 23 base::File::Error *status_out,
24 base::PlatformFileError status) { 24 base::File::Error status) {
25 ASSERT_FALSE(*done); 25 ASSERT_FALSE(*done);
26 *done = true; 26 *done = true;
27 *status_out = status; 27 *status_out = status;
28 } 28 }
29 29
30 void GetCancelStatus(bool* operation_done, 30 void GetCancelStatus(bool* operation_done,
31 bool* cancel_done, 31 bool* cancel_done,
32 base::PlatformFileError *status_out, 32 base::File::Error *status_out,
33 base::PlatformFileError status) { 33 base::File::Error status) {
34 // Cancel callback must be always called after the operation's callback. 34 // Cancel callback must be always called after the operation's callback.
35 ASSERT_TRUE(*operation_done); 35 ASSERT_TRUE(*operation_done);
36 ASSERT_FALSE(*cancel_done); 36 ASSERT_FALSE(*cancel_done);
37 *cancel_done = true; 37 *cancel_done = true;
38 *status_out = status; 38 *status_out = status;
39 } 39 }
40 40
41 class FileSystemOperationRunnerTest : public testing::Test { 41 class FileSystemOperationRunnerTest : public testing::Test {
42 protected: 42 protected:
43 FileSystemOperationRunnerTest() {} 43 FileSystemOperationRunnerTest() {}
(...skipping 24 matching lines...) Expand all
68 private: 68 private:
69 base::ScopedTempDir base_; 69 base::ScopedTempDir base_;
70 base::MessageLoop message_loop_; 70 base::MessageLoop message_loop_;
71 scoped_refptr<FileSystemContext> file_system_context_; 71 scoped_refptr<FileSystemContext> file_system_context_;
72 72
73 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationRunnerTest); 73 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationRunnerTest);
74 }; 74 };
75 75
76 TEST_F(FileSystemOperationRunnerTest, NotFoundError) { 76 TEST_F(FileSystemOperationRunnerTest, NotFoundError) {
77 bool done = false; 77 bool done = false;
78 base::PlatformFileError status = base::PLATFORM_FILE_ERROR_FAILED; 78 base::File::Error status = base::File::FILE_ERROR_FAILED;
79 79
80 // Regular NOT_FOUND error, which is called asynchronously. 80 // Regular NOT_FOUND error, which is called asynchronously.
81 operation_runner()->Truncate(URL("foo"), 0, 81 operation_runner()->Truncate(URL("foo"), 0,
82 base::Bind(&GetStatus, &done, &status)); 82 base::Bind(&GetStatus, &done, &status));
83 ASSERT_FALSE(done); 83 ASSERT_FALSE(done);
84 base::RunLoop().RunUntilIdle(); 84 base::RunLoop().RunUntilIdle();
85 ASSERT_TRUE(done); 85 ASSERT_TRUE(done);
86 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status); 86 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, status);
87 } 87 }
88 88
89 TEST_F(FileSystemOperationRunnerTest, InvalidURLError) { 89 TEST_F(FileSystemOperationRunnerTest, InvalidURLError) {
90 bool done = false; 90 bool done = false;
91 base::PlatformFileError status = base::PLATFORM_FILE_ERROR_FAILED; 91 base::File::Error status = base::File::FILE_ERROR_FAILED;
92 92
93 // Invalid URL error, which calls DidFinish synchronously. 93 // Invalid URL error, which calls DidFinish synchronously.
94 operation_runner()->Truncate(FileSystemURL(), 0, 94 operation_runner()->Truncate(FileSystemURL(), 0,
95 base::Bind(&GetStatus, &done, &status)); 95 base::Bind(&GetStatus, &done, &status));
96 // The error call back shouldn't be fired synchronously. 96 // The error call back shouldn't be fired synchronously.
97 ASSERT_FALSE(done); 97 ASSERT_FALSE(done);
98 98
99 base::RunLoop().RunUntilIdle(); 99 base::RunLoop().RunUntilIdle();
100 ASSERT_TRUE(done); 100 ASSERT_TRUE(done);
101 ASSERT_EQ(base::PLATFORM_FILE_ERROR_INVALID_URL, status); 101 ASSERT_EQ(base::File::FILE_ERROR_INVALID_URL, status);
102 } 102 }
103 103
104 TEST_F(FileSystemOperationRunnerTest, NotFoundErrorAndCancel) { 104 TEST_F(FileSystemOperationRunnerTest, NotFoundErrorAndCancel) {
105 bool done = false; 105 bool done = false;
106 bool cancel_done = false; 106 bool cancel_done = false;
107 base::PlatformFileError status = base::PLATFORM_FILE_ERROR_FAILED; 107 base::File::Error status = base::File::FILE_ERROR_FAILED;
108 base::PlatformFileError cancel_status = base::PLATFORM_FILE_ERROR_FAILED; 108 base::File::Error cancel_status = base::File::FILE_ERROR_FAILED;
109 109
110 // Call Truncate with non-existent URL, and try to cancel it immediately 110 // Call Truncate with non-existent URL, and try to cancel it immediately
111 // after that (before its callback is fired). 111 // after that (before its callback is fired).
112 FileSystemOperationRunner::OperationID id = 112 FileSystemOperationRunner::OperationID id =
113 operation_runner()->Truncate(URL("foo"), 0, 113 operation_runner()->Truncate(URL("foo"), 0,
114 base::Bind(&GetStatus, &done, &status)); 114 base::Bind(&GetStatus, &done, &status));
115 operation_runner()->Cancel(id, base::Bind(&GetCancelStatus, 115 operation_runner()->Cancel(id, base::Bind(&GetCancelStatus,
116 &done, &cancel_done, 116 &done, &cancel_done,
117 &cancel_status)); 117 &cancel_status));
118 118
119 ASSERT_FALSE(done); 119 ASSERT_FALSE(done);
120 ASSERT_FALSE(cancel_done); 120 ASSERT_FALSE(cancel_done);
121 base::RunLoop().RunUntilIdle(); 121 base::RunLoop().RunUntilIdle();
122 122
123 ASSERT_TRUE(done); 123 ASSERT_TRUE(done);
124 ASSERT_TRUE(cancel_done); 124 ASSERT_TRUE(cancel_done);
125 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status); 125 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, status);
126 ASSERT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, cancel_status); 126 ASSERT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, cancel_status);
127 } 127 }
128 128
129 TEST_F(FileSystemOperationRunnerTest, InvalidURLErrorAndCancel) { 129 TEST_F(FileSystemOperationRunnerTest, InvalidURLErrorAndCancel) {
130 bool done = false; 130 bool done = false;
131 bool cancel_done = false; 131 bool cancel_done = false;
132 base::PlatformFileError status = base::PLATFORM_FILE_ERROR_FAILED; 132 base::File::Error status = base::File::FILE_ERROR_FAILED;
133 base::PlatformFileError cancel_status = base::PLATFORM_FILE_ERROR_FAILED; 133 base::File::Error cancel_status = base::File::FILE_ERROR_FAILED;
134 134
135 // Call Truncate with invalid URL, and try to cancel it immediately 135 // Call Truncate with invalid URL, and try to cancel it immediately
136 // after that (before its callback is fired). 136 // after that (before its callback is fired).
137 FileSystemOperationRunner::OperationID id = 137 FileSystemOperationRunner::OperationID id =
138 operation_runner()->Truncate(FileSystemURL(), 0, 138 operation_runner()->Truncate(FileSystemURL(), 0,
139 base::Bind(&GetStatus, &done, &status)); 139 base::Bind(&GetStatus, &done, &status));
140 operation_runner()->Cancel(id, base::Bind(&GetCancelStatus, 140 operation_runner()->Cancel(id, base::Bind(&GetCancelStatus,
141 &done, &cancel_done, 141 &done, &cancel_done,
142 &cancel_status)); 142 &cancel_status));
143 143
144 ASSERT_FALSE(done); 144 ASSERT_FALSE(done);
145 ASSERT_FALSE(cancel_done); 145 ASSERT_FALSE(cancel_done);
146 base::RunLoop().RunUntilIdle(); 146 base::RunLoop().RunUntilIdle();
147 147
148 ASSERT_TRUE(done); 148 ASSERT_TRUE(done);
149 ASSERT_TRUE(cancel_done); 149 ASSERT_TRUE(cancel_done);
150 ASSERT_EQ(base::PLATFORM_FILE_ERROR_INVALID_URL, status); 150 ASSERT_EQ(base::File::FILE_ERROR_INVALID_URL, status);
151 ASSERT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, cancel_status); 151 ASSERT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, cancel_status);
152 } 152 }
153 153
154 TEST_F(FileSystemOperationRunnerTest, CancelWithInvalidId) { 154 TEST_F(FileSystemOperationRunnerTest, CancelWithInvalidId) {
155 const FileSystemOperationRunner::OperationID kInvalidId = -1; 155 const FileSystemOperationRunner::OperationID kInvalidId = -1;
156 bool done = true; // The operation is not running. 156 bool done = true; // The operation is not running.
157 bool cancel_done = false; 157 bool cancel_done = false;
158 base::PlatformFileError cancel_status = base::PLATFORM_FILE_ERROR_FAILED; 158 base::File::Error cancel_status = base::File::FILE_ERROR_FAILED;
159 operation_runner()->Cancel(kInvalidId, base::Bind(&GetCancelStatus, 159 operation_runner()->Cancel(kInvalidId, base::Bind(&GetCancelStatus,
160 &done, &cancel_done, 160 &done, &cancel_done,
161 &cancel_status)); 161 &cancel_status));
162 162
163 ASSERT_TRUE(cancel_done); 163 ASSERT_TRUE(cancel_done);
164 ASSERT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, cancel_status); 164 ASSERT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, cancel_status);
165 } 165 }
166 166
167 } // namespace content 167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698