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"
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"
17 void OnConfigDone(bool success
) {
21 class SyncRollbackManagerBaseTest
: public testing::Test
{
23 virtual void SetUp() OVERRIDE
{
24 TestInternalComponentsFactory
factory(InternalComponentsFactory::Switches(),
26 manager_
.Init(base::FilePath(base::FilePath::kCurrentDirectory
),
27 MakeWeakHandle(base::WeakPtr
<JsEventHandler
>()),
28 "", 0, true, scoped_ptr
<HttpPostProviderFactory
>().Pass(),
29 std::vector
<scoped_refptr
<ModelSafeWorker
> >(),
30 NULL
, NULL
, SyncCredentials(), "", "", "", &factory
,
31 NULL
, scoped_ptr
<UnrecoverableErrorHandler
>().Pass(),
35 SyncRollbackManagerBase manager_
;
36 base::MessageLoop loop_
; // Needed for WeakHandle
39 TEST_F(SyncRollbackManagerBaseTest
, InitTypeOnConfiguration
) {
40 EXPECT_TRUE(manager_
.InitialSyncEndedTypes().Empty());
42 manager_
.ConfigureSyncer(
43 CONFIGURE_REASON_NEW_CLIENT
,
44 ModelTypeSet(PREFERENCES
, BOOKMARKS
),
45 ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), ModelSafeRoutingInfo(),
46 base::Bind(&OnConfigDone
, true),
47 base::Bind(&OnConfigDone
, false));
49 ReadTransaction
trans(FROM_HERE
, manager_
.GetUserShare());
50 ReadNode
pref_root(&trans
);
51 EXPECT_EQ(BaseNode::INIT_OK
,
52 pref_root
.InitTypeRoot(PREFERENCES
));
54 ReadNode
bookmark_root(&trans
);
55 EXPECT_EQ(BaseNode::INIT_OK
,
56 bookmark_root
.InitTypeRoot(BOOKMARKS
));
57 ReadNode
bookmark_bar(&trans
);
58 EXPECT_EQ(BaseNode::INIT_OK
,
59 bookmark_bar
.InitByTagLookupForBookmarks("bookmark_bar"));
60 ReadNode
bookmark_mobile(&trans
);
61 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD
,
62 bookmark_mobile
.InitByTagLookupForBookmarks("synced_bookmarks"));
63 ReadNode
bookmark_other(&trans
);
64 EXPECT_EQ(BaseNode::INIT_OK
,
65 bookmark_other
.InitByTagLookupForBookmarks("other_bookmarks"));
68 } // anonymous namespace