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

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

Issue 3133022: sync: take two for: "Added classes to enable session sync... (Closed)
Patch Set: Created 10 years, 4 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
« no previous file with comments | « chrome/browser/sessions/tab_restore_service.h ('k') | chrome/browser/sync/engine/syncapi.h » ('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/chrome_thread.h" 14 #include "chrome/browser/chrome_thread.h"
15 #include "chrome/browser/sync/engine/syncapi.h" 15 #include "chrome/browser/sync/engine/syncapi.h"
16 #include "chrome/browser/sync/glue/autofill_model_associator.h" 16 #include "chrome/browser/sync/glue/autofill_model_associator.h"
17 #include "chrome/browser/sync/glue/password_model_associator.h" 17 #include "chrome/browser/sync/glue/password_model_associator.h"
18 #include "chrome/browser/sync/glue/preference_model_associator.h" 18 #include "chrome/browser/sync/glue/preference_model_associator.h"
19 #include "chrome/browser/sync/glue/session_model_associator.h"
19 #include "chrome/browser/sync/glue/typed_url_model_associator.h" 20 #include "chrome/browser/sync/glue/typed_url_model_associator.h"
20 #include "chrome/browser/sync/profile_sync_factory_mock.h" 21 #include "chrome/browser/sync/profile_sync_factory_mock.h"
21 #include "chrome/browser/sync/protocol/sync.pb.h" 22 #include "chrome/browser/sync/protocol/sync.pb.h"
22 #include "chrome/browser/sync/syncable/directory_manager.h" 23 #include "chrome/browser/sync/syncable/directory_manager.h"
23 #include "chrome/browser/sync/syncable/model_type.h" 24 #include "chrome/browser/sync/syncable/model_type.h"
24 #include "chrome/browser/sync/syncable/syncable.h" 25 #include "chrome/browser/sync/syncable/syncable.h"
25 #include "chrome/browser/sync/test_profile_sync_service.h" 26 #include "chrome/browser/sync/test_profile_sync_service.h"
26 #include "chrome/browser/sync/util/cryptographer.h" 27 #include "chrome/browser/sync/util/cryptographer.h"
27 #include "chrome/test/profile_mock.h" 28 #include "chrome/test/profile_mock.h"
28 #include "chrome/test/sync/engine/test_id_factory.h" 29 #include "chrome/test/sync/engine/test_id_factory.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 using browser_sync::TestIdFactory; 32 using browser_sync::TestIdFactory;
32 using sync_api::UserShare; 33 using sync_api::UserShare;
33 using syncable::BASE_VERSION; 34 using syncable::BASE_VERSION;
34 using syncable::CREATE; 35 using syncable::CREATE;
35 using syncable::DirectoryManager; 36 using syncable::DirectoryManager;
36 using syncable::ID;
37 using syncable::IS_DEL; 37 using syncable::IS_DEL;
38 using syncable::IS_DIR; 38 using syncable::IS_DIR;
39 using syncable::IS_UNAPPLIED_UPDATE; 39 using syncable::IS_UNAPPLIED_UPDATE;
40 using syncable::IS_UNSYNCED; 40 using syncable::IS_UNSYNCED;
41 using syncable::ModelType; 41 using syncable::ModelType;
42 using syncable::MutableEntry; 42 using syncable::MutableEntry;
43 using syncable::SERVER_IS_DIR; 43 using syncable::SERVER_IS_DIR;
44 using syncable::SERVER_VERSION; 44 using syncable::SERVER_VERSION;
45 using syncable::SPECIFICS; 45 using syncable::SPECIFICS;
46 using syncable::ScopedDirLookup; 46 using syncable::ScopedDirLookup;
47 using syncable::UNIQUE_SERVER_TAG; 47 using syncable::UNIQUE_SERVER_TAG;
48 using syncable::UNITTEST; 48 using syncable::UNITTEST;
49 using syncable::WriteTransaction; 49 using syncable::WriteTransaction;
50 50
51 class AbstractProfileSyncServiceTest : public testing::Test { 51 class ProfileSyncServiceTestHelper {
52 public: 52 public:
53 AbstractProfileSyncServiceTest() 53 static bool CreateRoot(ModelType model_type, ProfileSyncService* service,
54 : ui_thread_(ChromeThread::UI, &message_loop_) {} 54 TestIdFactory* ids) {
55 55 UserShare* user_share = service->backend()->GetUserShareHandle();
56 bool CreateRoot(ModelType model_type) {
57 UserShare* user_share = service_->backend()->GetUserShareHandle();
58 DirectoryManager* dir_manager = user_share->dir_manager.get(); 56 DirectoryManager* dir_manager = user_share->dir_manager.get();
59 57
60 ScopedDirLookup dir(dir_manager, user_share->authenticated_name); 58 ScopedDirLookup dir(dir_manager, user_share->authenticated_name);
61 if (!dir.good()) 59 if (!dir.good())
62 return false; 60 return false;
63 61
64 std::string tag_name; 62 std::string tag_name;
65 switch (model_type) { 63 switch (model_type) {
66 case syncable::AUTOFILL: 64 case syncable::AUTOFILL:
67 tag_name = browser_sync::kAutofillTag; 65 tag_name = browser_sync::kAutofillTag;
68 break; 66 break;
69 case syncable::PREFERENCES: 67 case syncable::PREFERENCES:
70 tag_name = browser_sync::kPreferencesTag; 68 tag_name = browser_sync::kPreferencesTag;
71 break; 69 break;
72 case syncable::PASSWORDS: 70 case syncable::PASSWORDS:
73 tag_name = browser_sync::kPasswordTag; 71 tag_name = browser_sync::kPasswordTag;
74 break; 72 break;
75 case syncable::NIGORI: 73 case syncable::NIGORI:
76 tag_name = browser_sync::kNigoriTag; 74 tag_name = browser_sync::kNigoriTag;
77 break; 75 break;
78 case syncable::TYPED_URLS: 76 case syncable::TYPED_URLS:
79 tag_name = browser_sync::kTypedUrlTag; 77 tag_name = browser_sync::kTypedUrlTag;
80 break; 78 break;
79 case syncable::SESSIONS:
80 tag_name = browser_sync::kSessionsTag;
81 break;
81 default: 82 default:
82 return false; 83 return false;
83 } 84 }
84 85
85 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 86 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__);
86 MutableEntry node(&wtrans, 87 MutableEntry node(&wtrans,
87 CREATE, 88 CREATE,
88 wtrans.root_id(), 89 wtrans.root_id(),
89 tag_name); 90 tag_name);
90 node.Put(UNIQUE_SERVER_TAG, tag_name); 91 node.Put(UNIQUE_SERVER_TAG, tag_name);
91 node.Put(IS_DIR, true); 92 node.Put(IS_DIR, true);
92 node.Put(SERVER_IS_DIR, false); 93 node.Put(SERVER_IS_DIR, false);
93 node.Put(IS_UNSYNCED, false); 94 node.Put(IS_UNSYNCED, false);
94 node.Put(IS_UNAPPLIED_UPDATE, false); 95 node.Put(IS_UNAPPLIED_UPDATE, false);
95 node.Put(SERVER_VERSION, 20); 96 node.Put(SERVER_VERSION, 20);
96 node.Put(BASE_VERSION, 20); 97 node.Put(BASE_VERSION, 20);
97 node.Put(IS_DEL, false); 98 node.Put(IS_DEL, false);
98 node.Put(ID, ids_.MakeServer(tag_name)); 99 node.Put(syncable::ID, ids->MakeServer(tag_name));
99 sync_pb::EntitySpecifics specifics; 100 sync_pb::EntitySpecifics specifics;
100 syncable::AddDefaultExtensionValue(model_type, &specifics); 101 syncable::AddDefaultExtensionValue(model_type, &specifics);
101 node.Put(SPECIFICS, specifics); 102 node.Put(SPECIFICS, specifics);
102 103
103 return true; 104 return true;
104 } 105 }
106 };
107
108 class AbstractProfileSyncServiceTest : public testing::Test {
109 public:
110 AbstractProfileSyncServiceTest()
111 : ui_thread_(ChromeThread::UI, &message_loop_) {}
112
113 bool CreateRoot(ModelType model_type) {
114 return ProfileSyncServiceTestHelper::CreateRoot(model_type,
115 service_.get(), &ids_);
116 }
105 117
106 protected: 118 protected:
107 119
108 MessageLoopForUI message_loop_; 120 MessageLoopForUI message_loop_;
109 ChromeThread ui_thread_; 121 ChromeThread ui_thread_;
110 ProfileSyncFactoryMock factory_; 122 ProfileSyncFactoryMock factory_;
111 scoped_ptr<TestProfileSyncService> service_; 123 scoped_ptr<TestProfileSyncService> service_;
112 TestIdFactory ids_; 124 TestIdFactory ids_;
113 }; 125 };
114 126
(...skipping 10 matching lines...) Expand all
125 137
126 bool success() { return success_; } 138 bool success() { return success_; }
127 139
128 private: 140 private:
129 AbstractProfileSyncServiceTest* test_; 141 AbstractProfileSyncServiceTest* test_;
130 ModelType model_type_; 142 ModelType model_type_;
131 bool success_; 143 bool success_;
132 }; 144 };
133 145
134 #endif // CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ 146 #endif // CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_
OLDNEW
« no previous file with comments | « chrome/browser/sessions/tab_restore_service.h ('k') | chrome/browser/sync/engine/syncapi.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698