OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/test/app/sync_test_util.h" | 5 #import "ios/chrome/test/app/sync_test_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #import "base/mac/bind_objc_block.h" | 11 #import "base/mac/bind_objc_block.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #import "base/test/ios/wait_util.h" | 15 #import "base/test/ios/wait_util.h" |
16 #include "components/autofill/core/browser/personal_data_manager.h" | 16 #include "components/autofill/core/browser/personal_data_manager.h" |
17 #include "components/browser_sync/profile_sync_service.h" | 17 #include "components/browser_sync/profile_sync_service.h" |
18 #include "components/history/core/browser/history_service.h" | 18 #include "components/history/core/browser/history_service.h" |
19 #include "components/keyed_service/core/service_access_type.h" | 19 #include "components/keyed_service/core/service_access_type.h" |
20 #include "components/sync/engine/net/http_bridge_network_resources.h" | 20 #include "components/sync/engine/net/http_bridge_network_resources.h" |
21 #include "components/sync/test/fake_server/entity_builder_factory.h" | 21 #include "components/sync/test/fake_server/entity_builder_factory.h" |
22 #include "components/sync/test/fake_server/fake_server.h" | 22 #include "components/sync/test/fake_server/fake_server.h" |
23 #include "components/sync/test/fake_server/fake_server_network_resources.h" | 23 #include "components/sync/test/fake_server/fake_server_network_resources.h" |
24 #include "components/sync/test/fake_server/fake_server_verifier.h" | 24 #include "components/sync/test/fake_server/fake_server_verifier.h" |
25 #include "components/sync/test/fake_server/sessions_hierarchy.h" | 25 #include "components/sync/test/fake_server/sessions_hierarchy.h" |
26 #include "components/sync/test/fake_server/tombstone_entity.h" | |
27 #include "components/sync/test/fake_server/unique_client_entity.h" | |
28 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 26 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
29 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
30 #include "ios/chrome/browser/history/history_service_factory.h" | 28 #include "ios/chrome/browser/history/history_service_factory.h" |
31 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 29 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
32 #include "ios/chrome/browser/sync/sync_setup_service.h" | 30 #include "ios/chrome/browser/sync/sync_setup_service.h" |
33 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 31 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
34 #import "ios/chrome/test/app/chrome_test_util.h" | 32 #import "ios/chrome/test/app/chrome_test_util.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
36 | 34 |
37 #if !defined(__has_feature) || !__has_feature(objc_arc) | 35 #if !defined(__has_feature) || !__has_feature(objc_arc) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 169 |
172 void InjectAutofillProfileOnFakeSyncServer(std::string guid, | 170 void InjectAutofillProfileOnFakeSyncServer(std::string guid, |
173 std::string full_name) { | 171 std::string full_name) { |
174 DCHECK(gSyncFakeServer); | 172 DCHECK(gSyncFakeServer); |
175 sync_pb::EntitySpecifics entity_specifics; | 173 sync_pb::EntitySpecifics entity_specifics; |
176 sync_pb::AutofillProfileSpecifics* autofill_profile = | 174 sync_pb::AutofillProfileSpecifics* autofill_profile = |
177 entity_specifics.mutable_autofill_profile(); | 175 entity_specifics.mutable_autofill_profile(); |
178 autofill_profile->add_name_full(full_name); | 176 autofill_profile->add_name_full(full_name); |
179 autofill_profile->set_guid(guid); | 177 autofill_profile->set_guid(guid); |
180 | 178 |
181 std::unique_ptr<fake_server::FakeServerEntity> entity = | 179 std::unique_ptr<syncer::LoopbackServerEntity> entity = |
182 fake_server::UniqueClientEntity::CreateForInjection(guid, | 180 syncer::PersistentUniqueClientEntity::CreateFromEntitySpecifics( |
183 entity_specifics); | 181 guid, entity_specifics); |
184 gSyncFakeServer->InjectEntity(std::move(entity)); | 182 gSyncFakeServer->InjectEntity(std::move(entity)); |
185 } | 183 } |
186 | 184 |
187 void DeleteAutofillProfileOnFakeSyncServer(std::string guid) { | 185 void DeleteAutofillProfileOnFakeSyncServer(std::string guid) { |
188 DCHECK(gSyncFakeServer); | 186 DCHECK(gSyncFakeServer); |
189 std::vector<sync_pb::SyncEntity> autofill_profiles = | 187 std::vector<sync_pb::SyncEntity> autofill_profiles = |
190 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::AUTOFILL_PROFILE); | 188 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::AUTOFILL_PROFILE); |
191 std::string entity_id; | 189 std::string entity_id; |
192 for (const sync_pb::SyncEntity& autofill_profile : autofill_profiles) { | 190 for (const sync_pb::SyncEntity& autofill_profile : autofill_profiles) { |
193 if (autofill_profile.specifics().autofill_profile().guid() == guid) { | 191 if (autofill_profile.specifics().autofill_profile().guid() == guid) { |
194 entity_id = autofill_profile.id_string(); | 192 entity_id = autofill_profile.id_string(); |
195 break; | 193 break; |
196 } | 194 } |
197 } | 195 } |
198 // Delete the entity if it exists. | 196 // Delete the entity if it exists. |
199 if (!entity_id.empty()) { | 197 if (!entity_id.empty()) { |
200 std::unique_ptr<fake_server::FakeServerEntity> entity; | 198 std::unique_ptr<syncer::LoopbackServerEntity> entity; |
201 entity = fake_server::TombstoneEntity::Create(entity_id, std::string()); | 199 entity = |
| 200 syncer::PersistentTombstoneEntity::CreateNew(entity_id, std::string()); |
202 gSyncFakeServer->InjectEntity(std::move(entity)); | 201 gSyncFakeServer->InjectEntity(std::move(entity)); |
203 } | 202 } |
204 } | 203 } |
205 | 204 |
206 bool IsAutofillProfilePresent(std::string guid, std::string full_name) { | 205 bool IsAutofillProfilePresent(std::string guid, std::string full_name) { |
207 ios::ChromeBrowserState* browser_state = | 206 ios::ChromeBrowserState* browser_state = |
208 chrome_test_util::GetOriginalBrowserState(); | 207 chrome_test_util::GetOriginalBrowserState(); |
209 autofill::PersonalDataManager* personal_data_manager = | 208 autofill::PersonalDataManager* personal_data_manager = |
210 autofill::PersonalDataManagerFactory::GetForBrowserState(browser_state); | 209 autofill::PersonalDataManagerFactory::GetForBrowserState(browser_state); |
211 autofill::AutofillProfile* autofill_profile = | 210 autofill::AutofillProfile* autofill_profile = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 259 |
261 void InjectTypedURLOnFakeSyncServer(const std::string& url) { | 260 void InjectTypedURLOnFakeSyncServer(const std::string& url) { |
262 DCHECK(gSyncFakeServer); | 261 DCHECK(gSyncFakeServer); |
263 sync_pb::EntitySpecifics entitySpecifics; | 262 sync_pb::EntitySpecifics entitySpecifics; |
264 sync_pb::TypedUrlSpecifics* typedUrl = entitySpecifics.mutable_typed_url(); | 263 sync_pb::TypedUrlSpecifics* typedUrl = entitySpecifics.mutable_typed_url(); |
265 typedUrl->set_url(url); | 264 typedUrl->set_url(url); |
266 typedUrl->set_title(url); | 265 typedUrl->set_title(url); |
267 typedUrl->add_visits(base::Time::Max().ToInternalValue()); | 266 typedUrl->add_visits(base::Time::Max().ToInternalValue()); |
268 typedUrl->add_visit_transitions(sync_pb::SyncEnums::TYPED); | 267 typedUrl->add_visit_transitions(sync_pb::SyncEnums::TYPED); |
269 | 268 |
270 std::unique_ptr<fake_server::FakeServerEntity> entity = | 269 std::unique_ptr<syncer::LoopbackServerEntity> entity = |
271 fake_server::UniqueClientEntity::CreateForInjection(url, entitySpecifics); | 270 syncer::PersistentUniqueClientEntity::CreateFromEntitySpecifics( |
| 271 url, entitySpecifics); |
272 gSyncFakeServer->InjectEntity(std::move(entity)); | 272 gSyncFakeServer->InjectEntity(std::move(entity)); |
273 } | 273 } |
274 | 274 |
275 BOOL IsTypedUrlPresentOnClient(const GURL& url, | 275 BOOL IsTypedUrlPresentOnClient(const GURL& url, |
276 BOOL expect_present, | 276 BOOL expect_present, |
277 NSError** error) { | 277 NSError** error) { |
278 // Call the history service. | 278 // Call the history service. |
279 ios::ChromeBrowserState* browser_state = | 279 ios::ChromeBrowserState* browser_state = |
280 chrome_test_util::GetOriginalBrowserState(); | 280 chrome_test_util::GetOriginalBrowserState(); |
281 history::HistoryService* history_service = | 281 history::HistoryService* history_service = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 std::vector<sync_pb::SyncEntity> typed_urls = | 339 std::vector<sync_pb::SyncEntity> typed_urls = |
340 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::TYPED_URLS); | 340 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::TYPED_URLS); |
341 std::string entity_id; | 341 std::string entity_id; |
342 for (const sync_pb::SyncEntity& typed_url : typed_urls) { | 342 for (const sync_pb::SyncEntity& typed_url : typed_urls) { |
343 if (typed_url.specifics().typed_url().url() == url) { | 343 if (typed_url.specifics().typed_url().url() == url) { |
344 entity_id = typed_url.id_string(); | 344 entity_id = typed_url.id_string(); |
345 break; | 345 break; |
346 } | 346 } |
347 } | 347 } |
348 if (!entity_id.empty()) { | 348 if (!entity_id.empty()) { |
349 std::unique_ptr<fake_server::FakeServerEntity> entity; | 349 std::unique_ptr<syncer::LoopbackServerEntity> entity; |
350 entity = fake_server::TombstoneEntity::Create(entity_id, std::string()); | 350 entity = |
| 351 syncer::PersistentTombstoneEntity::CreateNew(entity_id, std::string()); |
351 gSyncFakeServer->InjectEntity(std::move(entity)); | 352 gSyncFakeServer->InjectEntity(std::move(entity)); |
352 } | 353 } |
353 } | 354 } |
354 | 355 |
355 } // namespace chrome_test_util | 356 } // namespace chrome_test_util |
OLD | NEW |