OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 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 "sync/internal_api/sync_backup_manager.h" | |
6 | |
7 #include "sql/connection.h" | |
8 #include "sync/internal_api/public/read_node.h" | |
9 #include "sync/internal_api/public/read_transaction.h" | |
10 #include "sync/internal_api/public/test/test_internal_components_factory.h" | |
11 #include "sync/internal_api/public/write_node.h" | |
12 #include "sync/internal_api/public/write_transaction.h" | |
13 #include "sync/syncable/entry.h" | |
14 #include "sync/test/test_directory_backing_store.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 namespace syncer { | |
18 | |
19 namespace { | |
20 | |
21 void OnConfigDone(bool success) { | |
22 EXPECT_TRUE(success); | |
23 } | |
24 | |
25 class SyncBackupManagerTest : public testing::Test { | |
26 protected: | |
27 virtual void SetUp() OVERRIDE { | |
28 db_.reset(new sql::Connection); | |
29 CHECK(db_->OpenInMemory()); | |
30 } | |
31 | |
32 void InitManager(SyncManager* manager) { | |
33 TestInternalComponentsFactory factory( | |
34 scoped_ptr<syncable::DirectoryBackingStore>( | |
Nicolas Zea
2014/04/15 23:05:51
do you have to create this here? Could you instead
haitaol1
2014/04/16 21:52:36
That's not sufficient because I want to verify dat
| |
35 new syncable::TestDirectoryBackingStore("test", db_.get()))); | |
36 | |
37 manager->Init(base::FilePath("test"), | |
38 MakeWeakHandle(base::WeakPtr<JsEventHandler>()), | |
39 "", 0, true, scoped_ptr<HttpPostProviderFactory>().Pass(), | |
40 std::vector<scoped_refptr<ModelSafeWorker> >(), | |
41 NULL, NULL, SyncCredentials(), "", "", "", &factory, | |
42 NULL, scoped_ptr<UnrecoverableErrorHandler>().Pass(), | |
43 NULL, NULL); | |
44 manager->ConfigureSyncer( | |
45 CONFIGURE_REASON_NEW_CLIENT, | |
46 ModelTypeSet(PREFERENCES), | |
47 ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), | |
48 ModelSafeRoutingInfo(), | |
49 base::Bind(&OnConfigDone, true), | |
50 base::Bind(&OnConfigDone, false)); | |
51 } | |
52 | |
53 void CreateEntry(UserShare* user_share, ModelType type, | |
54 const std::string& client_tag) { | |
55 WriteTransaction trans(FROM_HERE, user_share); | |
56 ReadNode type_root(&trans); | |
57 EXPECT_EQ(BaseNode::INIT_OK, | |
58 type_root.InitByTagLookup(ModelTypeToRootTag(type))); | |
59 | |
60 WriteNode node(&trans); | |
61 EXPECT_EQ(WriteNode::INIT_SUCCESS, | |
62 node.InitUniqueByCreation(type, type_root, client_tag)); | |
63 } | |
64 | |
65 scoped_ptr<sql::Connection> db_; | |
66 base::MessageLoop loop_; // Needed for WeakHandle | |
67 }; | |
68 | |
69 TEST_F(SyncBackupManagerTest, NormalizeAndPersist) { | |
70 scoped_ptr<SyncBackupManager> manager(new SyncBackupManager); | |
71 InitManager(manager.get()); | |
72 | |
73 CreateEntry(manager->GetUserShare(), PREFERENCES, "test"); | |
74 | |
75 { | |
76 // New entry is local and unsynced at first. | |
77 ReadTransaction trans(FROM_HERE, manager->GetUserShare()); | |
78 ReadNode pref(&trans); | |
79 EXPECT_EQ(BaseNode::INIT_OK, | |
80 pref.InitByClientTagLookup(PREFERENCES, "test")); | |
81 EXPECT_FALSE(pref.GetEntry()->GetId().ServerKnows()); | |
82 EXPECT_TRUE(pref.GetEntry()->GetIsUnsynced()); | |
83 } | |
84 | |
85 manager->SaveChanges(); | |
86 | |
87 { | |
88 // New entry has server ID and unsynced bit is cleared after saving. | |
89 ReadTransaction trans(FROM_HERE, manager->GetUserShare()); | |
90 ReadNode pref(&trans); | |
91 EXPECT_EQ(BaseNode::INIT_OK, | |
92 pref.InitByClientTagLookup(PREFERENCES, "test")); | |
93 EXPECT_TRUE(pref.GetEntry()->GetId().ServerKnows()); | |
94 EXPECT_FALSE(pref.GetEntry()->GetIsUnsynced()); | |
95 } | |
96 manager->ShutdownOnSyncThread(); | |
97 | |
98 // Reopen db to verify entry is persisted. | |
99 manager.reset(new SyncBackupManager); | |
100 InitManager(manager.get()); | |
101 { | |
102 ReadTransaction trans(FROM_HERE, manager->GetUserShare()); | |
103 ReadNode pref(&trans); | |
104 EXPECT_EQ(BaseNode::INIT_OK, | |
105 pref.InitByClientTagLookup(PREFERENCES, "test")); | |
106 EXPECT_TRUE(pref.GetEntry()->GetId().ServerKnows()); | |
107 EXPECT_FALSE(pref.GetEntry()->GetIsUnsynced()); | |
108 } | |
109 } | |
110 | |
111 } // anonymous namespace | |
112 | |
113 } // namespace syncer | |
114 | |
OLD | NEW |