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

Side by Side Diff: chrome/browser/sync_file_system/local/syncable_file_operation_runner_unittest.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" 14 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
15 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" 15 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
16 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" 16 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
17 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" 17 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h"
18 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 18 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
19 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h " 19 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h "
20 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h " 20 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h "
21 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 21 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
22 #include "content/public/test/mock_blob_url_request_context.h" 22 #include "content/public/test/mock_blob_url_request_context.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 23 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" 25 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
26 #include "third_party/leveldatabase/src/include/leveldb/env.h" 26 #include "third_party/leveldatabase/src/include/leveldb/env.h"
27 #include "webkit/browser/fileapi/file_system_context.h" 27 #include "storage/browser/fileapi/file_system_context.h"
28 #include "webkit/browser/fileapi/file_system_operation_runner.h" 28 #include "storage/browser/fileapi/file_system_operation_runner.h"
29 29
30 using fileapi::FileSystemOperation; 30 using storage::FileSystemOperation;
31 using fileapi::FileSystemURL; 31 using storage::FileSystemURL;
32 using content::MockBlobURLRequestContext; 32 using content::MockBlobURLRequestContext;
33 using content::ScopedTextBlob; 33 using content::ScopedTextBlob;
34 using base::File; 34 using base::File;
35 35
36 namespace sync_file_system { 36 namespace sync_file_system {
37 37
38 namespace { 38 namespace {
39 const std::string kParent = "foo"; 39 const std::string kParent = "foo";
40 const std::string kFile = "foo/file"; 40 const std::string kFile = "foo/file";
41 const std::string kDir = "foo/dir"; 41 const std::string kDir = "foo/dir";
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 EXPECT_EQ(File::FILE_OK, file_system_.CreateDirectory(URL(kDir))); 242 EXPECT_EQ(File::FILE_OK, file_system_.CreateDirectory(URL(kDir)));
243 EXPECT_EQ(File::FILE_OK, file_system_.CreateFile(URL(kChild))); 243 EXPECT_EQ(File::FILE_OK, file_system_.CreateFile(URL(kChild)));
244 244
245 // Start syncing the kParent directory. 245 // Start syncing the kParent directory.
246 sync_status()->StartSyncing(URL(kParent)); 246 sync_status()->StartSyncing(URL(kParent));
247 247
248 // Copying kDir to other directory should succeed, while moving would fail 248 // Copying kDir to other directory should succeed, while moving would fail
249 // (since the source directory is in syncing). 249 // (since the source directory is in syncing).
250 ResetCallbackStatus(); 250 ResetCallbackStatus();
251 file_system_.operation_runner()->Copy( 251 file_system_.operation_runner()->Copy(
252 URL(kDir), URL("dest-copy"), 252 URL(kDir),
253 fileapi::FileSystemOperation::OPTION_NONE, 253 URL("dest-copy"),
254 fileapi::FileSystemOperationRunner::CopyProgressCallback(), 254 storage::FileSystemOperation::OPTION_NONE,
255 storage::FileSystemOperationRunner::CopyProgressCallback(),
255 ExpectStatus(FROM_HERE, File::FILE_OK)); 256 ExpectStatus(FROM_HERE, File::FILE_OK));
256 file_system_.operation_runner()->Move( 257 file_system_.operation_runner()->Move(
257 URL(kDir), URL("dest-move"), 258 URL(kDir),
258 fileapi::FileSystemOperation::OPTION_NONE, 259 URL("dest-move"),
260 storage::FileSystemOperation::OPTION_NONE,
259 ExpectStatus(FROM_HERE, File::FILE_OK)); 261 ExpectStatus(FROM_HERE, File::FILE_OK));
260 base::MessageLoop::current()->RunUntilIdle(); 262 base::MessageLoop::current()->RunUntilIdle();
261 EXPECT_EQ(1, callback_count_); 263 EXPECT_EQ(1, callback_count_);
262 264
263 // Only "dest-copy1" should exist. 265 // Only "dest-copy1" should exist.
264 EXPECT_EQ(File::FILE_OK, 266 EXPECT_EQ(File::FILE_OK,
265 file_system_.DirectoryExists(URL("dest-copy"))); 267 file_system_.DirectoryExists(URL("dest-copy")));
266 EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, 268 EXPECT_EQ(File::FILE_ERROR_NOT_FOUND,
267 file_system_.DirectoryExists(URL("dest-move"))); 269 file_system_.DirectoryExists(URL("dest-move")));
268 270
269 // Start syncing the "dest-copy2" directory. 271 // Start syncing the "dest-copy2" directory.
270 sync_status()->StartSyncing(URL("dest-copy2")); 272 sync_status()->StartSyncing(URL("dest-copy2"));
271 273
272 // Now the destination is also locked copying kDir should be queued. 274 // Now the destination is also locked copying kDir should be queued.
273 ResetCallbackStatus(); 275 ResetCallbackStatus();
274 file_system_.operation_runner()->Copy( 276 file_system_.operation_runner()->Copy(
275 URL(kDir), URL("dest-copy2"), 277 URL(kDir),
276 fileapi::FileSystemOperation::OPTION_NONE, 278 URL("dest-copy2"),
277 fileapi::FileSystemOperationRunner::CopyProgressCallback(), 279 storage::FileSystemOperation::OPTION_NONE,
280 storage::FileSystemOperationRunner::CopyProgressCallback(),
278 ExpectStatus(FROM_HERE, File::FILE_OK)); 281 ExpectStatus(FROM_HERE, File::FILE_OK));
279 base::MessageLoop::current()->RunUntilIdle(); 282 base::MessageLoop::current()->RunUntilIdle();
280 EXPECT_EQ(0, callback_count_); 283 EXPECT_EQ(0, callback_count_);
281 284
282 // Finish syncing the "dest-copy2" directory to unlock Copy. 285 // Finish syncing the "dest-copy2" directory to unlock Copy.
283 sync_status()->EndSyncing(URL("dest-copy2")); 286 sync_status()->EndSyncing(URL("dest-copy2"));
284 ResetCallbackStatus(); 287 ResetCallbackStatus();
285 base::MessageLoop::current()->RunUntilIdle(); 288 base::MessageLoop::current()->RunUntilIdle();
286 EXPECT_EQ(1, callback_count_); 289 EXPECT_EQ(1, callback_count_);
287 290
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 TEST_F(SyncableFileOperationRunnerTest, Cancel) { 392 TEST_F(SyncableFileOperationRunnerTest, Cancel) {
390 // Prepare a file. 393 // Prepare a file.
391 file_system_.operation_runner()->CreateFile( 394 file_system_.operation_runner()->CreateFile(
392 URL(kFile), false /* exclusive */, 395 URL(kFile), false /* exclusive */,
393 ExpectStatus(FROM_HERE, File::FILE_OK)); 396 ExpectStatus(FROM_HERE, File::FILE_OK));
394 base::MessageLoop::current()->RunUntilIdle(); 397 base::MessageLoop::current()->RunUntilIdle();
395 EXPECT_EQ(1, callback_count_); 398 EXPECT_EQ(1, callback_count_);
396 399
397 // Run Truncate and immediately cancel. This shouldn't crash. 400 // Run Truncate and immediately cancel. This shouldn't crash.
398 ResetCallbackStatus(); 401 ResetCallbackStatus();
399 fileapi::FileSystemOperationRunner::OperationID id = 402 storage::FileSystemOperationRunner::OperationID id =
400 file_system_.operation_runner()->Truncate( 403 file_system_.operation_runner()->Truncate(
401 URL(kFile), 10, 404 URL(kFile), 10, ExpectStatus(FROM_HERE, File::FILE_OK));
402 ExpectStatus(FROM_HERE, File::FILE_OK));
403 file_system_.operation_runner()->Cancel( 405 file_system_.operation_runner()->Cancel(
404 id, ExpectStatus(FROM_HERE, File::FILE_ERROR_INVALID_OPERATION)); 406 id, ExpectStatus(FROM_HERE, File::FILE_ERROR_INVALID_OPERATION));
405 base::MessageLoop::current()->RunUntilIdle(); 407 base::MessageLoop::current()->RunUntilIdle();
406 EXPECT_EQ(2, callback_count_); 408 EXPECT_EQ(2, callback_count_);
407 } 409 }
408 410
409 } // namespace sync_file_system 411 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698