| 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" |
| 26 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 28 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
| 27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 29 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 28 #include "ios/chrome/browser/history/history_service_factory.h" | 30 #include "ios/chrome/browser/history/history_service_factory.h" |
| 29 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 31 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
| 30 #include "ios/chrome/browser/sync/sync_setup_service.h" | 32 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 31 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 33 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 32 #import "ios/chrome/test/app/chrome_test_util.h" | 34 #import "ios/chrome/test/app/chrome_test_util.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 167 |
| 166 void InjectAutofillProfileOnFakeSyncServer(std::string guid, | 168 void InjectAutofillProfileOnFakeSyncServer(std::string guid, |
| 167 std::string full_name) { | 169 std::string full_name) { |
| 168 DCHECK(gSyncFakeServer); | 170 DCHECK(gSyncFakeServer); |
| 169 sync_pb::EntitySpecifics entity_specifics; | 171 sync_pb::EntitySpecifics entity_specifics; |
| 170 sync_pb::AutofillProfileSpecifics* autofill_profile = | 172 sync_pb::AutofillProfileSpecifics* autofill_profile = |
| 171 entity_specifics.mutable_autofill_profile(); | 173 entity_specifics.mutable_autofill_profile(); |
| 172 autofill_profile->add_name_full(full_name); | 174 autofill_profile->add_name_full(full_name); |
| 173 autofill_profile->set_guid(guid); | 175 autofill_profile->set_guid(guid); |
| 174 | 176 |
| 175 std::unique_ptr<syncer::LoopbackServerEntity> entity = | 177 std::unique_ptr<fake_server::FakeServerEntity> entity = |
| 176 syncer::PersistentUniqueClientEntity::CreateFromEntitySpecifics( | 178 fake_server::UniqueClientEntity::CreateForInjection(guid, |
| 177 guid, entity_specifics); | 179 entity_specifics); |
| 178 gSyncFakeServer->InjectEntity(std::move(entity)); | 180 gSyncFakeServer->InjectEntity(std::move(entity)); |
| 179 } | 181 } |
| 180 | 182 |
| 181 void DeleteAutofillProfileOnFakeSyncServer(std::string guid) { | 183 void DeleteAutofillProfileOnFakeSyncServer(std::string guid) { |
| 182 DCHECK(gSyncFakeServer); | 184 DCHECK(gSyncFakeServer); |
| 183 std::vector<sync_pb::SyncEntity> autofill_profiles = | 185 std::vector<sync_pb::SyncEntity> autofill_profiles = |
| 184 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::AUTOFILL_PROFILE); | 186 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::AUTOFILL_PROFILE); |
| 185 std::string entity_id; | 187 std::string entity_id; |
| 186 for (const sync_pb::SyncEntity& autofill_profile : autofill_profiles) { | 188 for (const sync_pb::SyncEntity& autofill_profile : autofill_profiles) { |
| 187 if (autofill_profile.specifics().autofill_profile().guid() == guid) { | 189 if (autofill_profile.specifics().autofill_profile().guid() == guid) { |
| 188 entity_id = autofill_profile.id_string(); | 190 entity_id = autofill_profile.id_string(); |
| 189 break; | 191 break; |
| 190 } | 192 } |
| 191 } | 193 } |
| 192 // Delete the entity if it exists. | 194 // Delete the entity if it exists. |
| 193 if (!entity_id.empty()) { | 195 if (!entity_id.empty()) { |
| 194 std::unique_ptr<syncer::LoopbackServerEntity> entity; | 196 std::unique_ptr<fake_server::FakeServerEntity> entity; |
| 195 entity = | 197 entity = fake_server::TombstoneEntity::Create(entity_id, std::string()); |
| 196 syncer::PersistentTombstoneEntity::CreateNew(entity_id, std::string()); | |
| 197 gSyncFakeServer->InjectEntity(std::move(entity)); | 198 gSyncFakeServer->InjectEntity(std::move(entity)); |
| 198 } | 199 } |
| 199 } | 200 } |
| 200 | 201 |
| 201 bool IsAutofillProfilePresent(std::string guid, std::string full_name) { | 202 bool IsAutofillProfilePresent(std::string guid, std::string full_name) { |
| 202 ios::ChromeBrowserState* browser_state = | 203 ios::ChromeBrowserState* browser_state = |
| 203 chrome_test_util::GetOriginalBrowserState(); | 204 chrome_test_util::GetOriginalBrowserState(); |
| 204 autofill::PersonalDataManager* personal_data_manager = | 205 autofill::PersonalDataManager* personal_data_manager = |
| 205 autofill::PersonalDataManagerFactory::GetForBrowserState(browser_state); | 206 autofill::PersonalDataManagerFactory::GetForBrowserState(browser_state); |
| 206 autofill::AutofillProfile* autofill_profile = | 207 autofill::AutofillProfile* autofill_profile = |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 256 |
| 256 void InjectTypedURLOnFakeSyncServer(const std::string& url) { | 257 void InjectTypedURLOnFakeSyncServer(const std::string& url) { |
| 257 DCHECK(gSyncFakeServer); | 258 DCHECK(gSyncFakeServer); |
| 258 sync_pb::EntitySpecifics entitySpecifics; | 259 sync_pb::EntitySpecifics entitySpecifics; |
| 259 sync_pb::TypedUrlSpecifics* typedUrl = entitySpecifics.mutable_typed_url(); | 260 sync_pb::TypedUrlSpecifics* typedUrl = entitySpecifics.mutable_typed_url(); |
| 260 typedUrl->set_url(url); | 261 typedUrl->set_url(url); |
| 261 typedUrl->set_title(url); | 262 typedUrl->set_title(url); |
| 262 typedUrl->add_visits(base::Time::Max().ToInternalValue()); | 263 typedUrl->add_visits(base::Time::Max().ToInternalValue()); |
| 263 typedUrl->add_visit_transitions(sync_pb::SyncEnums::TYPED); | 264 typedUrl->add_visit_transitions(sync_pb::SyncEnums::TYPED); |
| 264 | 265 |
| 265 std::unique_ptr<syncer::LoopbackServerEntity> entity = | 266 std::unique_ptr<fake_server::FakeServerEntity> entity = |
| 266 syncer::PersistentUniqueClientEntity::CreateFromEntitySpecifics( | 267 fake_server::UniqueClientEntity::CreateForInjection(url, entitySpecifics); |
| 267 url, entitySpecifics); | |
| 268 gSyncFakeServer->InjectEntity(std::move(entity)); | 268 gSyncFakeServer->InjectEntity(std::move(entity)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 BOOL IsTypedUrlPresentOnClient(const GURL& url, | 271 BOOL IsTypedUrlPresentOnClient(const GURL& url, |
| 272 BOOL expect_present, | 272 BOOL expect_present, |
| 273 NSError** error) { | 273 NSError** error) { |
| 274 // Call the history service. | 274 // Call the history service. |
| 275 ios::ChromeBrowserState* browser_state = | 275 ios::ChromeBrowserState* browser_state = |
| 276 chrome_test_util::GetOriginalBrowserState(); | 276 chrome_test_util::GetOriginalBrowserState(); |
| 277 history::HistoryService* history_service = | 277 history::HistoryService* history_service = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 std::vector<sync_pb::SyncEntity> typed_urls = | 335 std::vector<sync_pb::SyncEntity> typed_urls = |
| 336 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::TYPED_URLS); | 336 gSyncFakeServer->GetSyncEntitiesByModelType(syncer::TYPED_URLS); |
| 337 std::string entity_id; | 337 std::string entity_id; |
| 338 for (const sync_pb::SyncEntity& typed_url : typed_urls) { | 338 for (const sync_pb::SyncEntity& typed_url : typed_urls) { |
| 339 if (typed_url.specifics().typed_url().url() == url) { | 339 if (typed_url.specifics().typed_url().url() == url) { |
| 340 entity_id = typed_url.id_string(); | 340 entity_id = typed_url.id_string(); |
| 341 break; | 341 break; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 if (!entity_id.empty()) { | 344 if (!entity_id.empty()) { |
| 345 std::unique_ptr<syncer::LoopbackServerEntity> entity; | 345 std::unique_ptr<fake_server::FakeServerEntity> entity; |
| 346 entity = | 346 entity = fake_server::TombstoneEntity::Create(entity_id, std::string()); |
| 347 syncer::PersistentTombstoneEntity::CreateNew(entity_id, std::string()); | |
| 348 gSyncFakeServer->InjectEntity(std::move(entity)); | 347 gSyncFakeServer->InjectEntity(std::move(entity)); |
| 349 } | 348 } |
| 350 } | 349 } |
| 351 | 350 |
| 352 } // namespace chrome_test_util | 351 } // namespace chrome_test_util |
| OLD | NEW |