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

Side by Side Diff: sync/syncable/deferred_on_disk_directory_backing_store_unittest.cc

Issue 455023003: Let SyncBackupManager keep backup data in memory until shutdown. Only persist (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ToT 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
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/files/scoped_temp_dir.h"
6 #include "base/stl_util.h"
7 #include "sync/syncable/deferred_on_disk_directory_backing_store.h"
8 #include "sync/syncable/directory.h"
9 #include "sync/syncable/entry_kernel.h"
10 #include "sync/syncable/on_disk_directory_backing_store.h"
11 #include "sync/syncable/syncable_delete_journal.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace syncer {
15 namespace syncable {
16 namespace {
17
18 static const base::FilePath::CharType kSyncDataFolderName[] =
19 FILE_PATH_LITERAL("Sync Data");
20
21 class DeferredOnDiskDirectoryBackingStoreTest : public testing::Test {
22 protected:
23 virtual void SetUp() OVERRIDE {
24 CHECK(temp_dir_.CreateUniqueTempDir());
25 db_path_ = temp_dir_.path().Append(kSyncDataFolderName);
26 }
27
28 virtual void TearDown() OVERRIDE {
29 STLDeleteValues(&handles_map_);
30 }
31
32 base::ScopedTempDir temp_dir_;
33 base::FilePath db_path_;
34 Directory::MetahandlesMap handles_map_;
35 JournalIndex delete_journals_;
36 Directory::KernelLoadInfo kernel_load_info_;
37 };
38
39 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, Load) {
Nicolas Zea 2014/08/13 20:32:05 nit: add comments about what is being tested and w
haitaol1 2014/08/14 01:30:35 Done.
40 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
41 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
42 &kernel_load_info_));
43 EXPECT_TRUE(delete_journals_.empty());
44 ASSERT_EQ(1u, handles_map_.size()); // root node
45 ASSERT_TRUE(handles_map_.count(1));
46 EntryKernel* root = handles_map_[1];
47 EXPECT_TRUE(root->ref(ID).IsRoot());
48 EXPECT_EQ(1, root->ref(META_HANDLE));
49 EXPECT_TRUE(root->ref(IS_DIR));
50 }
51
52 TEST_F(DeferredOnDiskDirectoryBackingStoreTest,
53 DontPersistIfSavingChangesNotCalled) {
54 {
55 // Open and close.
56 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
57 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
58 &kernel_load_info_));
59 }
60
61 EXPECT_FALSE(base::PathExists(db_path_));
62 }
63
64 TEST_F(DeferredOnDiskDirectoryBackingStoreTest,
65 DontPersistWhenSavingNoChanges) {
66 {
67 // Open and close.
68 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
69 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
70 &kernel_load_info_));
71
72 Directory::SaveChangesSnapshot snapshot;
73 store.SaveChanges(snapshot);
74 }
75
76 EXPECT_FALSE(base::PathExists(db_path_));
77 }
78
79 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, PersistWhenSavingValidChanges) {
80 {
81 // Open and close.
82 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
83 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
84 &kernel_load_info_));
85
86 Directory::SaveChangesSnapshot snapshot;
87 EntryKernel* entry = new EntryKernel();
88 entry->put(ID, Id::CreateFromClientString("test_entry"));
89 entry->put(META_HANDLE, 2);
90 entry->mark_dirty(NULL);
91 snapshot.dirty_metas.insert(entry);
92 store.SaveChanges(snapshot);
93 }
94
95 STLDeleteValues(&handles_map_);
96
97 ASSERT_TRUE(base::PathExists(db_path_));
98 OnDiskDirectoryBackingStore read_store("test", db_path_);
99 EXPECT_EQ(OPENED, read_store.Load(&handles_map_, &delete_journals_,
100 &kernel_load_info_));
101 ASSERT_EQ(2u, handles_map_.size());
102 ASSERT_TRUE(handles_map_.count(1)); // root node
103 ASSERT_TRUE(handles_map_.count(2));
104 EntryKernel* entry = handles_map_[2];
105 EXPECT_EQ(Id::CreateFromClientString("test_entry"), entry->ref(ID));
106 }
107
108 } // anonymous
Nicolas Zea 2014/08/13 20:32:05 s/anonymous/namespace
haitaol1 2014/08/14 01:30:34 Done.
109 } // syncable
Nicolas Zea 2014/08/13 20:32:05 s/syncable/namespace syncable
haitaol1 2014/08/14 01:30:34 Done.
110 } // syncer
Nicolas Zea 2014/08/13 20:32:05 here too
haitaol1 2014/08/14 01:30:34 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698