| Index: sync/internal_api/sync_backup_manager_unittest.cc
|
| diff --git a/sync/internal_api/sync_backup_manager_unittest.cc b/sync/internal_api/sync_backup_manager_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d4989cfb6b6a419f9680fa3c6b3344c2bd2e8927
|
| --- /dev/null
|
| +++ b/sync/internal_api/sync_backup_manager_unittest.cc
|
| @@ -0,0 +1,113 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "sync/internal_api/sync_backup_manager.h"
|
| +
|
| +#include "sql/connection.h"
|
| +#include "sync/internal_api/public/read_node.h"
|
| +#include "sync/internal_api/public/read_transaction.h"
|
| +#include "sync/internal_api/public/test/test_internal_components_factory.h"
|
| +#include "sync/internal_api/public/write_node.h"
|
| +#include "sync/internal_api/public/write_transaction.h"
|
| +#include "sync/syncable/entry.h"
|
| +#include "sync/test/test_directory_backing_store.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace syncer {
|
| +
|
| +class SyncBackupManagerTest : public testing::Test {
|
| + public:
|
| + virtual void SetUp() OVERRIDE {
|
| + db_.reset(new sql::Connection);
|
| + CHECK(db_->OpenInMemory());
|
| + }
|
| +
|
| + void OnConfigDone(bool success) {
|
| + EXPECT_TRUE(success);
|
| + }
|
| +
|
| + protected:
|
| + void InitManager(SyncManager* manager) {
|
| + TestInternalComponentsFactory factory(
|
| + scoped_ptr<syncable::DirectoryBackingStore>(
|
| + new syncable::TestDirectoryBackingStore("test", db_.get())));
|
| +
|
| + manager->Init(base::FilePath("test"),
|
| + MakeWeakHandle(base::WeakPtr<JsEventHandler>()),
|
| + "", 0, true, scoped_ptr<HttpPostProviderFactory>().Pass(),
|
| + std::vector<scoped_refptr<ModelSafeWorker> >(),
|
| + NULL, NULL, SyncCredentials(), "", "", "", &factory,
|
| + NULL, scoped_ptr<UnrecoverableErrorHandler>().Pass(),
|
| + NULL, NULL);
|
| + manager->ConfigureSyncer(
|
| + CONFIGURE_REASON_NEW_CLIENT,
|
| + ModelTypeSet(PREFERENCES),
|
| + ModelTypeSet(), ModelTypeSet(), ModelTypeSet(),
|
| + ModelSafeRoutingInfo(),
|
| + base::Bind(&SyncBackupManagerTest::OnConfigDone,
|
| + base::Unretained(this), true),
|
| + base::Bind(&SyncBackupManagerTest::OnConfigDone,
|
| + base::Unretained(this), false));
|
| + }
|
| +
|
| + void CreateEntry(UserShare* user_share, ModelType type,
|
| + const std::string& client_tag) {
|
| + WriteTransaction trans(FROM_HERE, user_share);
|
| + ReadNode type_root(&trans);
|
| + EXPECT_EQ(BaseNode::INIT_OK,
|
| + type_root.InitByTagLookup(ModelTypeToRootTag(type)));
|
| +
|
| + WriteNode node(&trans);
|
| + EXPECT_EQ(WriteNode::INIT_SUCCESS,
|
| + node.InitUniqueByCreation(type, type_root, client_tag));
|
| + }
|
| +
|
| + scoped_ptr<sql::Connection> db_;
|
| + base::MessageLoop loop_; // Needed for WeakHandle
|
| +};
|
| +
|
| +TEST_F(SyncBackupManagerTest, NormalizeAndPersist) {
|
| + scoped_ptr<SyncBackupManager> manager(new SyncBackupManager);
|
| + InitManager(manager.get());
|
| +
|
| + CreateEntry(manager->GetUserShare(), PREFERENCES, "test");
|
| +
|
| + {
|
| + // New entry is local and unsynced at first.
|
| + ReadTransaction trans(FROM_HERE, manager->GetUserShare());
|
| + ReadNode pref(&trans);
|
| + EXPECT_EQ(BaseNode::INIT_OK,
|
| + pref.InitByClientTagLookup(PREFERENCES, "test"));
|
| + EXPECT_FALSE(pref.GetEntry()->GetId().ServerKnows());
|
| + EXPECT_TRUE(pref.GetEntry()->GetIsUnsynced());
|
| + }
|
| +
|
| + manager->SaveChanges();
|
| +
|
| + {
|
| + // New entry has server ID and unsynced bit is cleared after saving.
|
| + ReadTransaction trans(FROM_HERE, manager->GetUserShare());
|
| + ReadNode pref(&trans);
|
| + EXPECT_EQ(BaseNode::INIT_OK,
|
| + pref.InitByClientTagLookup(PREFERENCES, "test"));
|
| + EXPECT_TRUE(pref.GetEntry()->GetId().ServerKnows());
|
| + EXPECT_FALSE(pref.GetEntry()->GetIsUnsynced());
|
| + }
|
| + manager->ShutdownOnSyncThread();
|
| +
|
| + // Reopen db to verify entry is persisted.
|
| + manager.reset(new SyncBackupManager);
|
| + InitManager(manager.get());
|
| + {
|
| + ReadTransaction trans(FROM_HERE, manager->GetUserShare());
|
| + ReadNode pref(&trans);
|
| + EXPECT_EQ(BaseNode::INIT_OK,
|
| + pref.InitByClientTagLookup(PREFERENCES, "test"));
|
| + EXPECT_TRUE(pref.GetEntry()->GetId().ServerKnows());
|
| + EXPECT_FALSE(pref.GetEntry()->GetIsUnsynced());
|
| + }
|
| +}
|
| +
|
| +} // namespace syncer
|
| +
|
|
|