Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / single_client_wallet_sync_test.cc
blob53081eefb7d3a21b5af7828316326d1c1f065eac
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/sync/test/integration/autofill_helper.h"
10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
11 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
12 #include "chrome/browser/sync/test/integration/sync_test.h"
13 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/field_types.h"
15 #include "components/autofill/core/browser/personal_data_manager.h"
16 #include "sync/internal_api/public/base/model_type.h"
17 #include "sync/test/fake_server/fake_server_entity.h"
18 #include "sync/test/fake_server/unique_client_entity.h"
20 using autofill_helper::GetPersonalDataManager;
21 using sync_integration_test_util::AwaitCommitActivityCompletion;
23 namespace {
25 // Setting the Preferences files contents to this string (before Profile is
26 // created) will bypass the Sync experiment logic for enabling this feature.
27 const char kWalletSyncEnabledPreferencesContents[] =
28 "{\"autofill\": { \"wallet_import_sync_experiment_enabled\": true } }";
30 } // namespace
32 class SingleClientWalletSyncTest : public SyncTest {
33 public:
34 SingleClientWalletSyncTest() : SyncTest(SINGLE_CLIENT) {}
35 ~SingleClientWalletSyncTest() override {}
37 private:
38 DISALLOW_COPY_AND_ASSIGN(SingleClientWalletSyncTest);
41 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, DisabledByDefault) {
42 ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
43 // The type should not be enabled without the experiment enabled.
44 ASSERT_FALSE(GetClient(0)->IsTypePreferred(syncer::AUTOFILL_WALLET_DATA));
47 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, EnabledViaPreference) {
48 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
49 ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
50 // The type should not be enabled without the experiment enabled.
51 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncer::AUTOFILL_WALLET_DATA));
52 // TODO(pvalenzuela): Assert that the local root node for AUTOFILL_WALLET_DATA
53 // exists.
56 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, Download) {
57 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents);
59 std::string id = "wallet entity ID";
60 int expiration_month = 8;
61 int expiration_year = 2087;
62 std::string last_four_digits = "1234";
63 std::string name_on_card = "Patrick Valenzuela";
65 sync_pb::EntitySpecifics specifics;
66 sync_pb::AutofillWalletSpecifics* wallet_specifics =
67 specifics.mutable_autofill_wallet();
68 wallet_specifics->set_type(
69 sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD);
71 sync_pb::WalletMaskedCreditCard* credit_card =
72 wallet_specifics->mutable_masked_card();
73 credit_card->set_id(id);
74 credit_card->set_exp_month(expiration_month);
75 credit_card->set_exp_year(expiration_year);
76 credit_card->set_last_four(last_four_digits);
77 credit_card->set_name_on_card(name_on_card);
78 credit_card->set_status(sync_pb::WalletMaskedCreditCard::VALID);
79 credit_card->set_type(sync_pb::WalletMaskedCreditCard::AMEX);
81 GetFakeServer()->InjectEntity(
82 fake_server::UniqueClientEntity::CreateForInjection(
83 syncer::AUTOFILL_WALLET_DATA,
84 id,
85 specifics));
87 ASSERT_TRUE(SetupSync()) << "SetupSync() failed";
89 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0);
90 ASSERT_TRUE(pdm != nullptr);
91 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards();
92 ASSERT_EQ(1uL, cards.size());
94 autofill::CreditCard* card = cards[0];
95 ASSERT_EQ(autofill::CreditCard::MASKED_SERVER_CARD, card->record_type());
96 ASSERT_EQ(id, card->server_id());
97 ASSERT_EQ(base::UTF8ToUTF16(last_four_digits), card->LastFourDigits());
98 ASSERT_EQ(autofill::kAmericanExpressCard, card->type());
99 ASSERT_EQ(expiration_month, card->expiration_month());
100 ASSERT_EQ(expiration_year, card->expiration_year());
101 ASSERT_EQ(base::UTF8ToUTF16(name_on_card),
102 card->GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME));