• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_rollback_manager_base.h"
6 
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 
13 namespace syncer {
14 
15 namespace {
16 
OnConfigDone(bool success)17 void OnConfigDone(bool success) {
18   EXPECT_TRUE(success);
19 }
20 
21 class SyncTestRollbackManager : public SyncRollbackManagerBase {
22  public:
Init(const base::FilePath & database_location,const WeakHandle<JsEventHandler> & event_handler,const std::string & sync_server_and_path,int sync_server_port,bool use_ssl,scoped_ptr<HttpPostProviderFactory> post_factory,const std::vector<scoped_refptr<ModelSafeWorker>> & workers,ExtensionsActivity * extensions_activity,ChangeDelegate * change_delegate,const SyncCredentials & credentials,const std::string & invalidator_client_id,const std::string & restored_key_for_bootstrapping,const std::string & restored_keystore_key_for_bootstrapping,InternalComponentsFactory * internal_components_factory,Encryptor * encryptor,scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,ReportUnrecoverableErrorFunction report_unrecoverable_error_function,CancelationSignal * cancelation_signal)23   virtual void Init(
24       const base::FilePath& database_location,
25       const WeakHandle<JsEventHandler>& event_handler,
26       const std::string& sync_server_and_path,
27       int sync_server_port,
28       bool use_ssl,
29       scoped_ptr<HttpPostProviderFactory> post_factory,
30       const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
31       ExtensionsActivity* extensions_activity,
32       ChangeDelegate* change_delegate,
33       const SyncCredentials& credentials,
34       const std::string& invalidator_client_id,
35       const std::string& restored_key_for_bootstrapping,
36       const std::string& restored_keystore_key_for_bootstrapping,
37       InternalComponentsFactory* internal_components_factory,
38       Encryptor* encryptor,
39       scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
40       ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
41       CancelationSignal* cancelation_signal) OVERRIDE {
42     SyncRollbackManagerBase::InitInternal(database_location,
43                                           internal_components_factory,
44                                           unrecoverable_error_handler.Pass(),
45                                           report_unrecoverable_error_function);
46   }
47 };
48 
49 class SyncRollbackManagerBaseTest : public testing::Test {
50  protected:
SetUp()51   virtual void SetUp() OVERRIDE {
52     TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(),
53                                           STORAGE_IN_MEMORY);
54     manager_.Init(base::FilePath(base::FilePath::kCurrentDirectory),
55                   MakeWeakHandle(base::WeakPtr<JsEventHandler>()),
56                   "", 0, true, scoped_ptr<HttpPostProviderFactory>().Pass(),
57                   std::vector<scoped_refptr<ModelSafeWorker> >(),
58                   NULL, NULL, SyncCredentials(), "", "", "", &factory,
59                   NULL, scoped_ptr<UnrecoverableErrorHandler>().Pass(),
60                   NULL, NULL);
61   }
62 
63   SyncTestRollbackManager manager_;
64   base::MessageLoop loop_;    // Needed for WeakHandle
65 };
66 
TEST_F(SyncRollbackManagerBaseTest,InitTypeOnConfiguration)67 TEST_F(SyncRollbackManagerBaseTest, InitTypeOnConfiguration) {
68   EXPECT_TRUE(manager_.InitialSyncEndedTypes().Empty());
69 
70   manager_.ConfigureSyncer(
71       CONFIGURE_REASON_NEW_CLIENT,
72       ModelTypeSet(PREFERENCES, BOOKMARKS),
73       ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), ModelSafeRoutingInfo(),
74       base::Bind(&OnConfigDone, true),
75       base::Bind(&OnConfigDone, false));
76 
77   ReadTransaction trans(FROM_HERE, manager_.GetUserShare());
78   ReadNode pref_root(&trans);
79   EXPECT_EQ(BaseNode::INIT_OK,
80             pref_root.InitTypeRoot(PREFERENCES));
81 
82   ReadNode bookmark_root(&trans);
83   EXPECT_EQ(BaseNode::INIT_OK,
84             bookmark_root.InitTypeRoot(BOOKMARKS));
85   ReadNode bookmark_bar(&trans);
86   EXPECT_EQ(BaseNode::INIT_OK,
87             bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar"));
88   ReadNode bookmark_mobile(&trans);
89   EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD,
90             bookmark_mobile.InitByTagLookupForBookmarks("synced_bookmarks"));
91   ReadNode bookmark_other(&trans);
92   EXPECT_EQ(BaseNode::INIT_OK,
93             bookmark_other.InitByTagLookupForBookmarks("other_bookmarks"));
94 }
95 
96 }  // anonymous namespace
97 
98 }  // namespace syncer
99