Skip to content

Commit

Permalink
Merge autofill::TestSyncService into syncer::TestSyncService
Browse files Browse the repository at this point in the history
Less duplication == good.
Most of the things in autofill::TestSyncService were already supported,
a few missing ones are added in this CL.

TBRing trivial change in payment_request_browsertest_base.h
TBR=mathp

Bug: 859874
Change-Id: I51c140c86efb95494f84eb38142d54fc32f74b14
Reviewed-on: https://chromium-review.googlesource.com/c/1319592
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605991}
  • Loading branch information
Marc Treib authored and Commit Bot committed Nov 7, 2018
1 parent 1c93093 commit 633949c
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "components/autofill/core/browser/test_event_waiter.h"
#include "components/autofill/core/browser/test_sync_service.h"
#include "components/payments/content/payment_request.h"
#include "components/sync/driver/test_sync_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/web_contents_observer.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
Expand Down Expand Up @@ -269,7 +269,7 @@ class PaymentRequestBrowserTestBase
std::unique_ptr<net::EmbeddedTestServer> https_server_;
// Weak, owned by the PaymentRequest object.
TestChromePaymentRequestDelegate* delegate_;
autofill::TestSyncService sync_service_;
syncer::TestSyncService sync_service_;
sync_preferences::TestingPrefServiceSyncable prefs_;
bool is_incognito_;
bool is_valid_ssl_;
Expand Down
2 changes: 0 additions & 2 deletions components/autofill/core/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@ jumbo_static_library("test_support") {
"test_region_data_loader.h",
"test_strike_database.cc",
"test_strike_database.h",
"test_sync_service.cc",
"test_sync_service.h",
"webdata/autofill_sync_bridge_test_util.cc",
"webdata/autofill_sync_bridge_test_util.h",
"webdata/mock_autofill_webdata_backend.cc",
Expand Down
16 changes: 10 additions & 6 deletions components/autofill/core/browser/autofill_experiments_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include "components/autofill/core/browser/autofill_experiments.h"

#include "base/test/scoped_feature_list.h"
#include "components/autofill/core/browser/test_sync_service.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync/driver/test_sync_service.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace autofill {
Expand All @@ -35,7 +36,7 @@ class AutofillExperimentsTest : public testing::Test {

base::test::ScopedFeatureList scoped_feature_list_;
TestingPrefServiceSimple pref_service_;
TestSyncService sync_service_;
syncer::TestSyncService sync_service_;
};

TEST_F(AutofillExperimentsTest, DenyUpload_FeatureEnabled) {
Expand All @@ -57,26 +58,29 @@ TEST_F(AutofillExperimentsTest, DenyUpload_SyncServiceCannotStart) {

TEST_F(AutofillExperimentsTest, DenyUpload_AuthError) {
scoped_feature_list_.InitAndEnableFeature(features::kAutofillUpstream);
sync_service_.SetInAuthError(true);
sync_service_.SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
EXPECT_FALSE(IsCreditCardUploadEnabled());
}

TEST_F(AutofillExperimentsTest,
DenyUpload_SyncServiceDoesNotHaveAutofillProfilePreferredDataType) {
scoped_feature_list_.InitAndEnableFeature(features::kAutofillUpstream);
sync_service_.SetDataTypes(syncer::ModelTypeSet());
sync_service_.SetPreferredDataTypes(syncer::ModelTypeSet());
sync_service_.SetActiveDataTypes(syncer::ModelTypeSet());
EXPECT_FALSE(IsCreditCardUploadEnabled());
}

TEST_F(AutofillExperimentsTest, DenyUpload_SyncCycleNotComplete) {
scoped_feature_list_.InitAndEnableFeature(features::kAutofillUpstream);
sync_service_.SetSyncCycleComplete(false);
sync_service_.SetLastCycleSnapshot(syncer::SyncCycleSnapshot());
EXPECT_FALSE(IsCreditCardUploadEnabled());
}

TEST_F(AutofillExperimentsTest, DenyUpload_SyncConfigurationNotDone) {
scoped_feature_list_.InitAndEnableFeature(features::kAutofillUpstream);
sync_service_.SetConfigurationDone(false);
sync_service_.SetTransportState(
syncer::SyncService::TransportState::CONFIGURING);
EXPECT_FALSE(IsCreditCardUploadEnabled());
}

Expand Down
4 changes: 2 additions & 2 deletions components/autofill/core/browser/autofill_metrics_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
#include "components/autofill/core/browser/test_autofill_manager.h"
#include "components/autofill/core/browser/test_form_structure.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/browser/test_sync_service.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/test_sync_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/webdata/common/web_data_results.h"
#include "services/metrics/public/cpp/ukm_builders.h"
Expand Down Expand Up @@ -254,7 +254,7 @@ class AutofillMetricsTest : public testing::Test {
base::test::ScopedTaskEnvironment scoped_task_environment_;
ukm::TestAutoSetUkmRecorder test_ukm_recorder_;
MockAutofillClient autofill_client_;
TestSyncService sync_service_;
syncer::TestSyncService sync_service_;
std::unique_ptr<TestAutofillDriver> autofill_driver_;
std::unique_ptr<TestAutofillManager> autofill_manager_;
std::unique_ptr<TestPersonalDataManager> personal_data_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "components/autofill/core/browser/test_credit_card_save_manager.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/browser/test_strike_database.h"
#include "components/autofill/core/browser/test_sync_service.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
Expand All @@ -45,6 +44,7 @@
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/test_sync_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
Expand Down Expand Up @@ -307,7 +307,7 @@ class CreditCardSaveManagerTest : public testing::Test {
std::unique_ptr<TestAutofillManager> autofill_manager_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_;
TestPersonalDataManager personal_data_;
TestSyncService sync_service_;
syncer::TestSyncService sync_service_;
base::test::ScopedFeatureList scoped_feature_list_;
// Ends up getting owned (and destroyed) by TestFormDataImporter:
TestCreditCardSaveManager* credit_card_save_manager_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "components/autofill/core/browser/test_credit_card_save_manager.h"
#include "components/autofill/core/browser/test_local_card_migration_manager.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/browser/test_sync_service.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
Expand All @@ -44,6 +43,7 @@
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/test_sync_service.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
#include "services/metrics/public/cpp/ukm_builders.h"
Expand Down Expand Up @@ -164,7 +164,7 @@ class LocalCardMigrationManagerTest : public testing::Test {
std::unique_ptr<TestAutofillManager> autofill_manager_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_;
TestPersonalDataManager personal_data_;
TestSyncService sync_service_;
syncer::TestSyncService sync_service_;
base::test::ScopedFeatureList scoped_feature_list_;
// Ends up getting owned (and destroyed) by TestFormDataImporter:
TestCreditCardSaveManager* credit_card_save_manager_;
Expand Down
36 changes: 23 additions & 13 deletions components/autofill/core/browser/personal_data_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/test_autofill_profile_validator.h"
#include "components/autofill/core/browser/test_sync_service.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
Expand All @@ -51,9 +50,11 @@
#include "components/os_crypt/os_crypt_mocker.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service_utils.h"
#include "components/sync/driver/test_sync_service.h"
#include "components/version_info/version_info.h"
#include "components/webdata/common/web_data_service_base.h"
#include "components/webdata/common/web_database_service.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -402,7 +403,7 @@ class PersonalDataManagerTestBase {
base::MessageLoopForUI message_loop_;
std::unique_ptr<PrefService> prefs_;
identity::IdentityTestEnvironment identity_test_env_;
TestSyncService sync_service_;
syncer::TestSyncService sync_service_;
scoped_refptr<AutofillWebDataService> profile_database_service_;
scoped_refptr<AutofillWebDataService> account_database_service_;
scoped_refptr<WebDatabaseService> profile_web_database_;
Expand Down Expand Up @@ -5988,7 +5989,8 @@ TEST_F(PersonalDataManagerTest, RemoveExpiredCreditCardsNotUsedSinceTimestamp) {

TEST_F(PersonalDataManagerTest, CreateDataForTest) {
// Disable sync so the data gets created.
sync_service_.SetDataTypes(syncer::ModelTypeSet());
sync_service_.SetPreferredDataTypes(syncer::ModelTypeSet());
sync_service_.SetActiveDataTypes(syncer::ModelTypeSet());

// By default, the creation of test data is disabled.
ResetPersonalDataManager(USER_MODE_NORMAL);
Expand Down Expand Up @@ -6108,12 +6110,14 @@ TEST_F(PersonalDataManagerTest, SyncAuthErrorMasksServerCards) {
SetUpThreeCardTypes();

// Set an auth error and inform the personal data manager.
sync_service_.SetInAuthError(true);
sync_service_.SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
personal_data_->OnStateChanged(&sync_service_);
WaitForOnPersonalDataChanged();

// Remove the auth error to be able to get the server cards.
sync_service_.SetInAuthError(false);
sync_service_.SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::NONE));

// Check that cards were masked and other were untouched.
EXPECT_EQ(3U, personal_data_->GetCreditCards().size());
Expand Down Expand Up @@ -6163,15 +6167,17 @@ TEST_F(PersonalDataManagerTest, OnSyncServiceInitialized_NotActiveSyncService) {
SetUpThreeCardTypes();

// Call OnSyncServiceInitialized with a sync service in auth error.
TestSyncService sync_service;
syncer::TestSyncService sync_service;
sync_service.SetIsAuthenticatedAccountPrimary(
/*is_authenticated_account_primary=*/false);
sync_service.SetInAuthError(true);
sync_service.SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
personal_data_->OnSyncServiceInitialized(&sync_service);
WaitForOnPersonalDataChanged();

// Remove the auth error to be able to get the server cards.
sync_service.SetInAuthError(false);
sync_service.SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::NONE));

// Check that cards were masked and other were untouched.
EXPECT_EQ(3U, personal_data_->GetCreditCards().size());
Expand All @@ -6195,7 +6201,8 @@ TEST_F(PersonalDataManagerTest, SyncAuthErrorHidesServerCards) {
SetUpThreeCardTypes();

// Set a persistent auth error.
sync_service_.SetInAuthError(true);
sync_service_.SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));

// Check that no server cards are available for suggestion, but that the other
// calls to get the credit cards are unaffected.
Expand All @@ -6204,8 +6211,9 @@ TEST_F(PersonalDataManagerTest, SyncAuthErrorHidesServerCards) {
EXPECT_EQ(1U, personal_data_->GetLocalCreditCards().size());
EXPECT_EQ(2U, personal_data_->GetServerCreditCards().size());

// Remove error
sync_service_.SetInAuthError(false);
// Remove error.
sync_service_.SetAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::NONE));

// Check that all cards are available.
EXPECT_EQ(3U, personal_data_->GetCreditCards().size());
Expand Down Expand Up @@ -6452,7 +6460,8 @@ TEST_F(
// Turn off autofill profile sync.
auto model_type_set = sync_service_.GetActiveDataTypes();
model_type_set.Remove(syncer::AUTOFILL_PROFILE);
sync_service_.SetDataTypes(model_type_set);
sync_service_.SetPreferredDataTypes(model_type_set);
sync_service_.SetActiveDataTypes(model_type_set);

// The data should still exist.
ASSERT_EQ(1U, personal_data_->GetProfiles().size());
Expand Down Expand Up @@ -6484,7 +6493,8 @@ TEST_F(
auto model_type_set = sync_service_.GetActiveDataTypes();
model_type_set.Remove(syncer::AUTOFILL_WALLET_DATA);
model_type_set.Remove(syncer::AUTOFILL_WALLET_METADATA);
sync_service_.SetDataTypes(model_type_set);
sync_service_.SetPreferredDataTypes(model_type_set);
sync_service_.SetActiveDataTypes(model_type_set);

// The credit card should still exist.
ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
Expand Down
91 changes: 0 additions & 91 deletions components/autofill/core/browser/test_sync_service.cc

This file was deleted.

Loading

0 comments on commit 633949c

Please sign in to comment.