Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / sync / internal_api / sync_rollback_manager_base_unittest.cc
blobfd1c12f849d33d086dca50ac2f7aadd1edfad243
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.
5 #include "sync/internal_api/sync_rollback_manager_base.h"
7 #include "base/bind.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 "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h"
14 namespace syncer {
16 namespace {
18 void OnConfigDone(bool success) {
19 EXPECT_TRUE(success);
22 class SyncTestRollbackManager : public SyncRollbackManagerBase {
23 public:
24 void Init(InitArgs* args) override {
25 SyncRollbackManagerBase::InitInternal(
26 args->database_location,
27 args->internal_components_factory.get(),
28 InternalComponentsFactory::STORAGE_IN_MEMORY,
29 args->unrecoverable_error_handler.Pass(),
30 args->report_unrecoverable_error_function);
34 class SyncRollbackManagerBaseTest : public testing::Test {
35 protected:
36 void SetUp() override {
37 SyncManager::InitArgs args;
38 args.database_location = base::FilePath(base::FilePath::kCurrentDirectory);
39 args.service_url = GURL("https://example.com/");
40 args.internal_components_factory.reset(new TestInternalComponentsFactory(
41 InternalComponentsFactory::Switches(),
42 InternalComponentsFactory::STORAGE_IN_MEMORY,
43 &storage_used_));
44 manager_.Init(&args);
45 EXPECT_EQ(InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used_);
48 SyncTestRollbackManager manager_;
49 base::MessageLoop loop_; // Needed for WeakHandle
50 InternalComponentsFactory::StorageOption storage_used_;
53 TEST_F(SyncRollbackManagerBaseTest, InitTypeOnConfiguration) {
54 EXPECT_TRUE(manager_.InitialSyncEndedTypes().Empty());
56 manager_.ConfigureSyncer(
57 CONFIGURE_REASON_NEW_CLIENT,
58 ModelTypeSet(PREFERENCES, BOOKMARKS),
59 ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), ModelSafeRoutingInfo(),
60 base::Bind(&OnConfigDone, true),
61 base::Bind(&OnConfigDone, false));
63 ReadTransaction trans(FROM_HERE, manager_.GetUserShare());
64 ReadNode pref_root(&trans);
65 EXPECT_EQ(BaseNode::INIT_OK,
66 pref_root.InitTypeRoot(PREFERENCES));
68 ReadNode bookmark_root(&trans);
69 EXPECT_EQ(BaseNode::INIT_OK,
70 bookmark_root.InitTypeRoot(BOOKMARKS));
71 ReadNode bookmark_bar(&trans);
72 EXPECT_EQ(BaseNode::INIT_OK,
73 bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar"));
74 ReadNode bookmark_mobile(&trans);
75 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD,
76 bookmark_mobile.InitByTagLookupForBookmarks("synced_bookmarks"));
77 ReadNode bookmark_other(&trans);
78 EXPECT_EQ(BaseNode::INIT_OK,
79 bookmark_other.InitByTagLookupForBookmarks("other_bookmarks"));
82 } // anonymous namespace
84 } // namespace syncer