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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/open_file_operation_unittest.cc

Issue 23816002: drive: Stop using resource ID to access local metadata in OpenFileOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new Created 7 years, 2 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
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/open_file_operation.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/chromeos/drive/file_system/open_file_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 EXPECT_EQ(FILE_ERROR_OK, error); 52 EXPECT_EQ(FILE_ERROR_OK, error);
53 ASSERT_TRUE(base::PathExists(file_path)); 53 ASSERT_TRUE(base::PathExists(file_path));
54 int64 local_file_size; 54 int64 local_file_size;
55 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); 55 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size));
56 EXPECT_EQ(file_size, local_file_size); 56 EXPECT_EQ(file_size, local_file_size);
57 57
58 ASSERT_FALSE(close_callback.is_null()); 58 ASSERT_FALSE(close_callback.is_null());
59 close_callback.Run(); 59 close_callback.Run();
60 EXPECT_EQ( 60 EXPECT_EQ(
61 1U, 61 1U,
62 observer()->upload_needed_local_ids().count(src_entry.resource_id())); 62 observer()->upload_needed_local_ids().count(src_entry.local_id()));
63 } 63 }
64 64
65 TEST_F(OpenFileOperationTest, OpenNonExistingFile) { 65 TEST_F(OpenFileOperationTest, OpenNonExistingFile) {
66 const base::FilePath file_in_root( 66 const base::FilePath file_in_root(
67 FILE_PATH_LITERAL("drive/root/not-exist.txt")); 67 FILE_PATH_LITERAL("drive/root/not-exist.txt"));
68 68
69 FileError error = FILE_ERROR_FAILED; 69 FileError error = FILE_ERROR_FAILED;
70 base::FilePath file_path; 70 base::FilePath file_path;
71 base::Closure close_callback; 71 base::Closure close_callback;
72 operation_->OpenFile( 72 operation_->OpenFile(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); 120 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName()));
121 121
122 EXPECT_EQ(FILE_ERROR_OK, error); 122 EXPECT_EQ(FILE_ERROR_OK, error);
123 ASSERT_TRUE(base::PathExists(file_path)); 123 ASSERT_TRUE(base::PathExists(file_path));
124 int64 local_file_size; 124 int64 local_file_size;
125 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); 125 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size));
126 EXPECT_EQ(0, local_file_size); // Should be an empty file. 126 EXPECT_EQ(0, local_file_size); // Should be an empty file.
127 127
128 ASSERT_FALSE(close_callback.is_null()); 128 ASSERT_FALSE(close_callback.is_null());
129 close_callback.Run(); 129 close_callback.Run();
130 // Here we don't know about the resource id, so just make sure 130 EXPECT_EQ(
131 // OnCacheFileUploadNeededByOperation is called actually. 131 1U,
132 EXPECT_EQ(1U, observer()->upload_needed_local_ids().size()); 132 observer()->upload_needed_local_ids().count(GetLocalId(file_in_root)));
133 } 133 }
134 134
135 TEST_F(OpenFileOperationTest, OpenOrCreateExistingFile) { 135 TEST_F(OpenFileOperationTest, OpenOrCreateExistingFile) {
136 const base::FilePath file_in_root( 136 const base::FilePath file_in_root(
137 FILE_PATH_LITERAL("drive/root/File 1.txt")); 137 FILE_PATH_LITERAL("drive/root/File 1.txt"));
138 ResourceEntry src_entry; 138 ResourceEntry src_entry;
139 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); 139 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry));
140 const int64 file_size = src_entry.file_info().size(); 140 const int64 file_size = src_entry.file_info().size();
141 141
142 FileError error = FILE_ERROR_FAILED; 142 FileError error = FILE_ERROR_FAILED;
(...skipping 14 matching lines...) Expand all
157 EXPECT_EQ(FILE_ERROR_OK, error); 157 EXPECT_EQ(FILE_ERROR_OK, error);
158 ASSERT_TRUE(base::PathExists(file_path)); 158 ASSERT_TRUE(base::PathExists(file_path));
159 int64 local_file_size; 159 int64 local_file_size;
160 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); 160 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size));
161 EXPECT_EQ(file_size, local_file_size); 161 EXPECT_EQ(file_size, local_file_size);
162 162
163 ASSERT_FALSE(close_callback.is_null()); 163 ASSERT_FALSE(close_callback.is_null());
164 close_callback.Run(); 164 close_callback.Run();
165 EXPECT_EQ( 165 EXPECT_EQ(
166 1U, 166 1U,
167 observer()->upload_needed_local_ids().count(src_entry.resource_id())); 167 observer()->upload_needed_local_ids().count(src_entry.local_id()));
168 168
169 bool success = false; 169 bool success = false;
170 FileCacheEntry cache_entry; 170 FileCacheEntry cache_entry;
171 cache()->GetCacheEntryOnUIThread( 171 cache()->GetCacheEntryOnUIThread(
172 src_entry.resource_id(), 172 src_entry.local_id(),
173 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); 173 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry));
174 test_util::RunBlockingPoolTask(); 174 test_util::RunBlockingPoolTask();
175 EXPECT_TRUE(success); 175 EXPECT_TRUE(success);
176 EXPECT_TRUE(cache_entry.is_present()); 176 EXPECT_TRUE(cache_entry.is_present());
177 EXPECT_TRUE(cache_entry.is_dirty()); 177 EXPECT_TRUE(cache_entry.is_dirty());
178 } 178 }
179 179
180 TEST_F(OpenFileOperationTest, OpenOrCreateNonExistingFile) { 180 TEST_F(OpenFileOperationTest, OpenOrCreateNonExistingFile) {
181 const base::FilePath file_in_root( 181 const base::FilePath file_in_root(
182 FILE_PATH_LITERAL("drive/root/not-exist.txt")); 182 FILE_PATH_LITERAL("drive/root/not-exist.txt"));
(...skipping 10 matching lines...) Expand all
193 test_util::RunBlockingPoolTask(); 193 test_util::RunBlockingPoolTask();
194 194
195 EXPECT_EQ(FILE_ERROR_OK, error); 195 EXPECT_EQ(FILE_ERROR_OK, error);
196 ASSERT_TRUE(base::PathExists(file_path)); 196 ASSERT_TRUE(base::PathExists(file_path));
197 int64 local_file_size; 197 int64 local_file_size;
198 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); 198 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size));
199 EXPECT_EQ(0, local_file_size); // Should be an empty file. 199 EXPECT_EQ(0, local_file_size); // Should be an empty file.
200 200
201 ASSERT_FALSE(close_callback.is_null()); 201 ASSERT_FALSE(close_callback.is_null());
202 close_callback.Run(); 202 close_callback.Run();
203 // Here we don't know about the resource id, so just make sure 203 EXPECT_EQ(
204 // OnCacheFileUploadNeededByOperation is called actually. 204 1U,
205 EXPECT_EQ(1U, observer()->upload_needed_local_ids().size()); 205 observer()->upload_needed_local_ids().count(GetLocalId(file_in_root)));
206 } 206 }
207 207
208 TEST_F(OpenFileOperationTest, OpenFileTwice) { 208 TEST_F(OpenFileOperationTest, OpenFileTwice) {
209 const base::FilePath file_in_root( 209 const base::FilePath file_in_root(
210 FILE_PATH_LITERAL("drive/root/File 1.txt")); 210 FILE_PATH_LITERAL("drive/root/File 1.txt"));
211 ResourceEntry src_entry; 211 ResourceEntry src_entry;
212 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); 212 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry));
213 const int64 file_size = src_entry.file_info().size(); 213 const int64 file_size = src_entry.file_info().size();
214 214
215 FileError error = FILE_ERROR_FAILED; 215 FileError error = FILE_ERROR_FAILED;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 252
253 // There still remains a client opening the file, so it shouldn't be 253 // There still remains a client opening the file, so it shouldn't be
254 // uploaded yet. 254 // uploaded yet.
255 EXPECT_TRUE(observer()->upload_needed_local_ids().empty()); 255 EXPECT_TRUE(observer()->upload_needed_local_ids().empty());
256 256
257 close_callback2.Run(); 257 close_callback2.Run();
258 258
259 // Here, all the clients close the file, so it should be uploaded then. 259 // Here, all the clients close the file, so it should be uploaded then.
260 EXPECT_EQ( 260 EXPECT_EQ(
261 1U, 261 1U,
262 observer()->upload_needed_local_ids().count(src_entry.resource_id())); 262 observer()->upload_needed_local_ids().count(src_entry.local_id()));
263 } 263 }
264 264
265 } // namespace file_system 265 } // namespace file_system
266 } // namespace drive 266 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/open_file_operation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698