Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/sync/abstract_profile_sync_service_test.h

Issue 6375007: [Sync] Refactored ProfileSyncService and remove its backend() function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/sync/abstract_profile_sync_service_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ 5 #ifndef CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_
6 #define CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ 6 #define CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/task.h" 13 #include "base/task.h"
14 #include "chrome/browser/browser_thread.h" 14 #include "chrome/browser/browser_thread.h"
15 #include "chrome/browser/net/gaia/token_service.h" 15 #include "chrome/browser/net/gaia/token_service.h"
16 #include "chrome/browser/sync/engine/syncapi.h"
17 #include "chrome/browser/sync/glue/autofill_model_associator.h"
18 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
19 #include "chrome/browser/sync/glue/password_model_associator.h"
20 #include "chrome/browser/sync/glue/preference_model_associator.h"
21 #include "chrome/browser/sync/glue/session_model_associator.h"
22 #include "chrome/browser/sync/glue/typed_url_model_associator.h"
23 #include "chrome/browser/sync/profile_sync_factory_mock.h" 16 #include "chrome/browser/sync/profile_sync_factory_mock.h"
24 #include "chrome/browser/sync/protocol/sync.pb.h"
25 #include "chrome/browser/sync/syncable/directory_manager.h"
26 #include "chrome/browser/sync/syncable/model_type.h" 17 #include "chrome/browser/sync/syncable/model_type.h"
27 #include "chrome/browser/sync/syncable/syncable.h"
28 #include "chrome/browser/sync/test_profile_sync_service.h"
29 #include "chrome/browser/sync/util/cryptographer.h"
30 #include "chrome/test/profile_mock.h"
31 #include "chrome/test/sync/engine/test_id_factory.h"
32 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
33 19
34 using browser_sync::TestIdFactory; 20 class ProfileSyncService;
35 using sync_api::UserShare; 21 class TestProfileSyncService;
36 using syncable::BASE_VERSION; 22
37 using syncable::CREATE; 23 namespace browser_sync {
38 using syncable::DirectoryManager; 24 class TestIdFactory;
39 using syncable::IS_DEL; 25 } // namespace browser_sync
40 using syncable::IS_DIR; 26
41 using syncable::IS_UNAPPLIED_UPDATE; 27 namespace sync_api {
42 using syncable::IS_UNSYNCED; 28 struct UserShare;
43 using syncable::ModelType; 29 } // namespace sync_api
44 using syncable::MutableEntry;
45 using syncable::SERVER_IS_DIR;
46 using syncable::SERVER_VERSION;
47 using syncable::SPECIFICS;
48 using syncable::ScopedDirLookup;
49 using syncable::UNIQUE_SERVER_TAG;
50 using syncable::UNITTEST;
51 using syncable::WriteTransaction;
52 30
53 class ProfileSyncServiceTestHelper { 31 class ProfileSyncServiceTestHelper {
54 public: 32 public:
55 static const std::string GetTagForType(ModelType model_type) { 33 static const std::string GetTagForType(syncable::ModelType model_type);
56 switch (model_type) {
57 case syncable::AUTOFILL:
58 return browser_sync::kAutofillTag;
59 case syncable::AUTOFILL_PROFILE:
60 return browser_sync::kAutofillProfileTag;
61 case syncable::PREFERENCES:
62 return browser_sync::kPreferencesTag;
63 case syncable::PASSWORDS:
64 return browser_sync::kPasswordTag;
65 case syncable::NIGORI:
66 return browser_sync::kNigoriTag;
67 case syncable::TYPED_URLS:
68 return browser_sync::kTypedUrlTag;
69 case syncable::SESSIONS:
70 return browser_sync::kSessionsTag;
71 case syncable::BOOKMARKS:
72 return "google_chrome_bookmarks";
73 default:
74 NOTREACHED();
75 }
76 return std::string();
77 }
78 34
79 static bool CreateRoot(ModelType model_type, ProfileSyncService* service, 35 static bool CreateRoot(syncable::ModelType model_type,
80 TestIdFactory* ids) { 36 sync_api::UserShare* service,
81 UserShare* user_share = service->backend()->GetUserShareHandle(); 37 browser_sync::TestIdFactory* ids);
82 DirectoryManager* dir_manager = user_share->dir_manager.get();
83
84 ScopedDirLookup dir(dir_manager, user_share->name);
85 if (!dir.good())
86 return false;
87
88 std::string tag_name = GetTagForType(model_type);
89
90 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__);
91 MutableEntry node(&wtrans,
92 CREATE,
93 wtrans.root_id(),
94 tag_name);
95 node.Put(UNIQUE_SERVER_TAG, tag_name);
96 node.Put(IS_DIR, true);
97 node.Put(SERVER_IS_DIR, false);
98 node.Put(IS_UNSYNCED, false);
99 node.Put(IS_UNAPPLIED_UPDATE, false);
100 node.Put(SERVER_VERSION, 20);
101 node.Put(BASE_VERSION, 20);
102 node.Put(IS_DEL, false);
103 node.Put(syncable::ID, ids->MakeServer(tag_name));
104 sync_pb::EntitySpecifics specifics;
105 syncable::AddDefaultExtensionValue(model_type, &specifics);
106 node.Put(SPECIFICS, specifics);
107
108 return true;
109 }
110 }; 38 };
111 39
112 class AbstractProfileSyncServiceTest : public testing::Test { 40 class AbstractProfileSyncServiceTest : public testing::Test {
113 public: 41 public:
114 AbstractProfileSyncServiceTest() 42 AbstractProfileSyncServiceTest();
115 : ui_thread_(BrowserThread::UI, &message_loop_) {}
116 43
117 bool CreateRoot(ModelType model_type) { 44 bool CreateRoot(syncable::ModelType model_type);
118 return ProfileSyncServiceTestHelper::CreateRoot(model_type,
119 service_.get(),
120 service_->id_factory());
121 }
122 45
123 protected: 46 protected:
124
125 MessageLoopForUI message_loop_; 47 MessageLoopForUI message_loop_;
126 BrowserThread ui_thread_; 48 BrowserThread ui_thread_;
127 ProfileSyncFactoryMock factory_; 49 ProfileSyncFactoryMock factory_;
128 TokenService token_service_; 50 TokenService token_service_;
129 scoped_ptr<TestProfileSyncService> service_; 51 scoped_ptr<TestProfileSyncService> service_;
130 }; 52 };
131 53
132 class CreateRootTask : public Task { 54 class CreateRootTask : public Task {
133 public: 55 public:
134 CreateRootTask(AbstractProfileSyncServiceTest* test, ModelType model_type) 56 CreateRootTask(AbstractProfileSyncServiceTest* test,
135 : test_(test), model_type_(model_type), success_(false) { 57 syncable::ModelType model_type);
136 }
137 58
138 virtual ~CreateRootTask() {} 59 virtual ~CreateRootTask();
139 virtual void Run() { 60 virtual void Run();
140 success_ = test_->CreateRoot(model_type_);
141 }
142 61
143 bool success() { return success_; } 62 bool success();
144 63
145 private: 64 private:
146 AbstractProfileSyncServiceTest* test_; 65 AbstractProfileSyncServiceTest* test_;
147 ModelType model_type_; 66 syncable::ModelType model_type_;
148 bool success_; 67 bool success_;
149 }; 68 };
150 69
151 #endif // CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ 70 #endif // CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/abstract_profile_sync_service_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698