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

Side by Side Diff: webkit/fileapi/syncable/local_file_change_tracker_unittest.cc

Issue 10966003: Add LocalFileChangeTracker database to record non-synced dirty files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 (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 "webkit/fileapi/syncable/local_file_change_tracker.h" 5 #include "webkit/fileapi/syncable/local_file_change_tracker.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "base/scoped_temp_dir.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/fileapi/syncable/local_file_change_tracker.h" 13 #include "webkit/fileapi/syncable/local_file_change_tracker.h"
13 #include "webkit/fileapi/syncable/local_file_sync_status.h" 14 #include "webkit/fileapi/syncable/local_file_sync_status.h"
14 15
15 namespace fileapi { 16 namespace fileapi {
16 17
17 namespace { 18 namespace {
18 19
19 // Test URLs (no parent/child relationships, as we test such cases 20 // Test URLs (no parent/child relationships, as we test such cases
20 // mainly in LocalFileSyncStatusTest). 21 // mainly in LocalFileSyncStatusTest).
21 const char kURL0[] = "filesystem:http://foo.com/test/dir a/file"; 22 const char kURL0[] = "filesystem:http://foo.com/test/dir a/file";
22 const char kURL1[] = "filesystem:http://foo.com/test/dir b"; 23 const char kURL1[] = "filesystem:http://foo.com/test/dir b";
23 const char kURL2[] = "filesystem:http://foo.com/test/foo.txt"; 24 const char kURL2[] = "filesystem:http://foo.com/test/foo.txt";
24 const char kURL3[] = "filesystem:http://foo.com/test/bar"; 25 const char kURL3[] = "filesystem:http://foo.com/test/bar";
25 const char kURL4[] = "filesystem:http://foo.com/temporary/dir a"; 26 const char kURL4[] = "filesystem:http://foo.com/temporary/dir a";
26 27
27 FileSystemURL URL(const char* spec) { 28 FileSystemURL URL(const char* spec) {
28 return FileSystemURL(GURL(spec)); 29 return FileSystemURL(GURL(spec));
29 } 30 }
30 31
31 } // namespace 32 } // namespace
32 33
33 class LocalFileChangeTrackerTest : public testing::Test { 34 class LocalFileChangeTrackerTest : public testing::Test {
34 public: 35 public:
35 LocalFileChangeTrackerTest() 36 LocalFileChangeTrackerTest()
36 : sync_status_(new LocalFileSyncStatus), 37 : sync_status_(new LocalFileSyncStatus) {
37 change_tracker_(new LocalFileChangeTracker( 38 EXPECT_TRUE(data_dir_.CreateUniqueTempDir());
38 sync_status_.get(), base::MessageLoopProxy::current())) {} 39 change_tracker_.reset(new LocalFileChangeTracker(
40 sync_status_.get(),
41 data_dir_.path(),
42 base::MessageLoopProxy::current()));
tzik 2012/09/20 05:24:50 Could you move them into SetUp()?
nhiroki 2012/09/20 09:30:33 Done.
43 }
39 44
40 protected: 45 protected:
41 LocalFileSyncStatus* sync_status() const { 46 LocalFileSyncStatus* sync_status() const {
42 return sync_status_.get(); 47 return sync_status_.get();
43 } 48 }
44 49
45 LocalFileChangeTracker* change_tracker() const { 50 LocalFileChangeTracker* change_tracker() const {
46 return change_tracker_.get(); 51 return change_tracker_.get();
47 } 52 }
48 53
(...skipping 17 matching lines...) Expand all
66 change_tracker()->FinalizeSyncForURL(url); 71 change_tracker()->FinalizeSyncForURL(url);
67 EXPECT_TRUE(sync_status()->IsWritable(url)); 72 EXPECT_TRUE(sync_status()->IsWritable(url));
68 73
69 // See if the changes for URL are reset. 74 // See if the changes for URL are reset.
70 ASSERT_TRUE(sync_status()->TryDisableWriting(url)); 75 ASSERT_TRUE(sync_status()->TryDisableWriting(url));
71 change_tracker()->GetChangesForURL(url, &changes); 76 change_tracker()->GetChangesForURL(url, &changes);
72 EXPECT_TRUE(changes.empty()); 77 EXPECT_TRUE(changes.empty());
73 } 78 }
74 79
75 private: 80 private:
81 ScopedTempDir data_dir_;
76 MessageLoop message_loop_; 82 MessageLoop message_loop_;
77 scoped_ptr<LocalFileSyncStatus> sync_status_; 83 scoped_ptr<LocalFileSyncStatus> sync_status_;
78 scoped_ptr<LocalFileChangeTracker> change_tracker_; 84 scoped_ptr<LocalFileChangeTracker> change_tracker_;
79 }; 85 };
80 86
81 TEST_F(LocalFileChangeTrackerTest, GetChanges) { 87 TEST_F(LocalFileChangeTrackerTest, GetChanges) {
82 change_tracker()->OnCreateFile(URL(kURL0)); 88 change_tracker()->OnCreateFile(URL(kURL0));
83 change_tracker()->OnRemoveFile(URL(kURL0)); // Offset the create. 89 change_tracker()->OnRemoveFile(URL(kURL0)); // Offset the create.
84 change_tracker()->OnRemoveDirectory(URL(kURL1)); 90 change_tracker()->OnRemoveDirectory(URL(kURL1));
85 change_tracker()->OnCreateDirectory(URL(kURL2)); 91 change_tracker()->OnCreateDirectory(URL(kURL2));
(...skipping 22 matching lines...) Expand all
108 FileChange::FILE_TYPE_DIRECTORY)); 114 FileChange::FILE_TYPE_DIRECTORY));
109 VerifyChange(URL(kURL3), 115 VerifyChange(URL(kURL3),
110 FileChange(FileChange::FILE_CHANGE_DELETE, 116 FileChange(FileChange::FILE_CHANGE_DELETE,
111 FileChange::FILE_TYPE_FILE)); 117 FileChange::FILE_TYPE_FILE));
112 VerifyChange(URL(kURL4), 118 VerifyChange(URL(kURL4),
113 FileChange(FileChange::FILE_CHANGE_UPDATE, 119 FileChange(FileChange::FILE_CHANGE_UPDATE,
114 FileChange::FILE_TYPE_FILE)); 120 FileChange::FILE_TYPE_FILE));
115 } 121 }
116 122
117 } // namespace fileapi 123 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698