autofill_dialog_controller_unittest.cc revision c2db58bd994c04d98e4ee2cd7565b71548655fe3
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <map>
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/bind.h"
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/command_line.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/guid.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
119ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/run_loop.h"
147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/strings/string_number_conversions.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
16ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/tuple.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
19ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h"
20ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h"
21ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_view.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h"
23ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "chrome/common/render_messages.h"
24ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "chrome/test/base/chrome_render_view_host_test_harness.h"
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/testing_profile.h"
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/full_wallet.h"
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/instrument.h"
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "components/autofill/content/browser/wallet/mock_wallet_client.h"
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_address.h"
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_service_url.h"
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_test_util.h"
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_common_test.h"
34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_metrics.h"
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/test_personal_data_manager.h"
367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/autofill_switches.h"
377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/form_data.h"
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/web_contents.h"
39ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "content/public/test/mock_render_process_host.h"
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN)
44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/win/scoped_ole_initializer.h"
45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using testing::_;
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace autofill {
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kFakeEmail[] = "user@example.com";
5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char kFakeFingerprintEncoded[] = "CgVaAwiACA==";
55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)const char kEditedBillingAddress[] = "123 edited billing address";
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char* kFieldsFromPage[] =
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    { "email",
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-name",
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-number",
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-exp-month",
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-exp-year",
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-csc",
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing name",
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing address-line1",
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing locality",
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing region",
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing postal-code",
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing country",
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing tel",
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping name",
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping address-line1",
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping locality",
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping region",
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping postal-code",
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping country",
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping tel",
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    };
78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kSettingsOrigin[] = "Chrome settings";
797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberAmex[] = "376200000000002";
807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberVisa[] = "4111111111111111";
817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberMaster[] = "5555555555554444";
827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberDiscover[] = "6011111111111117";
837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberIncomplete[] = "4111111111";
847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Credit card number fails Luhn check.
857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberInvalid[] = "4111111111111112";
867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void SetOutputValue(const DetailInputs& inputs,
8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    DetailOutputMap* outputs,
903240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch                    ServerFieldType type,
91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                    const base::string16& value) {
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const DetailInput& input = inputs[i];
9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    (*outputs)[&input] = input.type == type ?
95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)        value :
9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        input.initial_value;
9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochscoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() {
101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> items = wallet::GetTestWalletItems();
102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  items->AddInstrument(wallet::GetTestMaskedInstrument());
103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  items->AddAddress(wallet::GetTestShippingAddress());
104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return items.Pass();
105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)scoped_ptr<wallet::FullWallet> CreateFullWallet(const char* required_action) {
10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::DictionaryValue dict;
10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<base::ListValue> list(new base::ListValue());
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  list->AppendString(required_action);
11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  dict.Set("required_action", list.release());
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return wallet::FullWallet::CreateFullWallet(dict);
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)scoped_ptr<risk::Fingerprint> GetFakeFingerprint() {
11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint());
11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Add some data to the proto, else the encoded content is empty.
11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  fingerprint->mutable_machine_characteristics()->mutable_screen_size()->
11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      set_width(1024);
12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return fingerprint.Pass();
12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestAutofillDialogView : public AutofillDialogView {
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestAutofillDialogView() {}
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TestAutofillDialogView() {}
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Show() OVERRIDE {}
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Hide() OVERRIDE {}
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateNotificationArea() OVERRIDE {}
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateAccountChooser() OVERRIDE {}
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateButtonStrip() OVERRIDE {}
133b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void UpdateDetailArea() OVERRIDE {}
134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void UpdateAutocheckoutStepsArea() OVERRIDE {}
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateSection(DialogSection section) OVERRIDE {}
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void FillSection(DialogSection section,
137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                           const DetailInput& originating_input) OVERRIDE {};
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void GetUserInput(DialogSection section, DetailOutputMap* output)
139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      OVERRIDE {
140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    *output = outputs_[section];
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual TestableAutofillDialogView* GetTestableView() OVERRIDE {
1437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return NULL;
1447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual string16 GetCvc() OVERRIDE { return string16(); }
147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool SaveDetailsLocally() OVERRIDE { return true; }
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const content::NavigationController* ShowSignIn() OVERRIDE {
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return NULL;
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void HideSignIn() OVERRIDE {}
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateProgressBar(double value) OVERRIDE {}
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD0(ModelChanged, void());
1557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  MOCK_METHOD0(UpdateForErrors, void());
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {}
15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SetUserInput(DialogSection section, const DetailOutputMap& map) {
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    outputs_[section] = map;
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::map<DialogSection, DetailOutputMap> outputs_;
165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView);
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Bring over command-ids from AccountChooserModel.
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestAccountChooserModel : public AccountChooserModel {
171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public:
172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestAccountChooserModel(AccountChooserModelDelegate* delegate,
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          PrefService* prefs,
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          const AutofillMetrics& metric_logger)
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      : AccountChooserModel(delegate, prefs, metric_logger,
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {}
177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual ~TestAccountChooserModel() {}
178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  using AccountChooserModel::kActiveWalletItemId;
180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  using AccountChooserModel::kAutofillItemId;
181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private:
183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel);
184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestAutofillDialogController
187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : public AutofillDialogControllerImpl,
188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      public base::SupportsWeakPtr<TestAutofillDialogController> {
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestAutofillDialogController(
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content::WebContents* contents,
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const FormData& form_structure,
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const GURL& source_url,
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const AutofillMetrics& metric_logger,
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const DialogType dialog_type,
196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const base::Callback<void(const FormStructure*,
197ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                const std::string&)>& callback,
198ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      MockNewCreditCardBubbleController* mock_new_card_bubble_controller)
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : AutofillDialogControllerImpl(contents,
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     form_structure,
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     source_url,
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     dialog_type,
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     callback),
204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        metric_logger_(metric_logger),
2057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch        mock_wallet_client_(
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            Profile::FromBrowserContext(contents->GetBrowserContext())->
207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                GetRequestContext(), this),
208ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        dialog_type_(dialog_type),
209ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        mock_new_card_bubble_controller_(mock_new_card_bubble_controller) {}
210ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TestAutofillDialogController() {}
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual AutofillDialogView* CreateView() OVERRIDE {
214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return new testing::NiceMock<TestAutofillDialogView>();
215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void Init(content::BrowserContext* browser_context) {
218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    test_manager_.Init(browser_context);
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestAutofillDialogView* GetView() {
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return static_cast<TestAutofillDialogView*>(view());
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestPersonalDataManager* GetTestingManager() {
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return &test_manager_;
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  wallet::MockWalletClient* GetTestingWalletClient() {
2307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return &mock_wallet_client_;
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const GURL& open_tab_url() { return open_tab_url_; }
2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
23590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual DialogType GetDialogType() const OVERRIDE {
23690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return dialog_type_;
23790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
23890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; }
24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SimulateSigninError() {
242868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    OnWalletSigninError();
24390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
24490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
245ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool AutocheckoutIsRunning() const {
246ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return AUTOCHECKOUT_IN_PROGRESS == autocheckout_state();
247ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
248ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
24990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  MOCK_METHOD0(LoadRiskFingerprintData, void());
25090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
251868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  using AutofillDialogControllerImpl::IsEditingExistingData;
25290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual PersonalDataManager* GetManager() OVERRIDE {
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return &test_manager_;
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
2597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return &mock_wallet_client_;
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void OpenTabWithUrl(const GURL& url) OVERRIDE {
263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    open_tab_url_ = url;
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Whether the information input in this dialog will be securely transmitted
267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // to the requesting site.
268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool TransmissionWillBeSecure() const OVERRIDE {
269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return true;
270eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
271eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
272ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual void ShowNewCreditCardBubble(
273ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      scoped_ptr<CreditCard> new_card,
274ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      scoped_ptr<AutofillProfile> billing_profile) OVERRIDE {
275ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    mock_new_card_bubble_controller_->Show(new_card.Pass(),
276ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                           billing_profile.Pass());
277ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
278ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // To specify our own metric logger.
281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
282c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return metric_logger_;
283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const AutofillMetrics& metric_logger_;
2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestPersonalDataManager test_manager_;
2877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_;
288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL open_tab_url_;
28990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DialogType dialog_type_;
290ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  MockNewCreditCardBubbleController* mock_new_card_bubble_controller_;
2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
295ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass TestGeneratedCreditCardBubbleController :
296ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    public GeneratedCreditCardBubbleController {
2977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public:
298ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  explicit TestGeneratedCreditCardBubbleController(
2997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      content::WebContents* contents)
300ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      : GeneratedCreditCardBubbleController(contents) {
3017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    contents->SetUserData(UserDataKey(), this);
302a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    CHECK_EQ(contents->GetUserData(UserDataKey()), this);
3037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
304a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
305ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual ~TestGeneratedCreditCardBubbleController() {}
3067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
307ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  MOCK_METHOD2(SetupAndShow, void(const base::string16& backing_card_name,
308ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                  const base::string16& fronting_card_name));
3097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
310868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected:
311ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual base::WeakPtr<GeneratedCreditCardBubbleView> CreateBubble() OVERRIDE {
312ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    return TestGeneratedCreditCardBubbleView::Create(GetWeakPtr());
3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual bool CanShow() const OVERRIDE {
3167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return true;
3177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
3187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
3197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private:
320ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  DISALLOW_COPY_AND_ASSIGN(TestGeneratedCreditCardBubbleController);
3217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch};
3227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
323ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness {
3247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch protected:
3257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  AutofillDialogControllerTest(): form_structure_(NULL) {}
3267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // testing::Test implementation:
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUp() OVERRIDE {
329ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    ChromeRenderViewHostTestHarness::SetUp();
330ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    Reset();
33190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
33290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
33390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void TearDown() OVERRIDE {
3347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    if (controller_)
33590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller_->ViewClosed();
336ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    ChromeRenderViewHostTestHarness::TearDown();
337ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
338ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
339ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void Reset() {
340ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    if (controller_)
341ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      controller_->ViewClosed();
342ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
343ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    test_generated_bubble_controller_ =
344ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        new testing::NiceMock<TestGeneratedCreditCardBubbleController>(
345ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            web_contents());
346ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    mock_new_card_bubble_controller_.reset(
347ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        new MockNewCreditCardBubbleController);
348ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
349ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // Don't get stuck on the first run wallet interstitial.
350ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    profile()->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet,
351ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                      true);
352ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
353ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    SetUpControllerWithFormData(DefaultFormData());
35490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
35590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
356868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormData DefaultFormData() {
357868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    FormData form_data;
358868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) {
359868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      FormFieldData field;
360868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      field.autocomplete_attribute = kFieldsFromPage[i];
361868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      form_data.fields.push_back(field);
362868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    }
363868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return form_data;
364868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
365868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
36690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void SetUpControllerWithFormData(const FormData& form_data) {
3677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    if (controller_)
36890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller_->ViewClosed();
36990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
370c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    base::Callback<void(const FormStructure*, const std::string&)> callback =
371c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        base::Bind(&AutofillDialogControllerTest::FinishedCallback,
372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                   base::Unretained(this));
37390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller_ = (new testing::NiceMock<TestAutofillDialogController>(
374ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        web_contents(),
3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        form_data,
3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        GURL(),
3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        metric_logger_,
3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
379ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        callback,
380ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        mock_new_card_bubble_controller_.get()))->AsWeakPtr();
381c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->Init(profile());
3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    controller_->Show();
383c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->OnUserNameFetchSuccess(kFakeEmail);
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
386c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void FillCreditCardInputs() {
387c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    DetailOutputMap cc_outputs;
388c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInputs& cc_inputs =
389c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        controller()->RequestedFieldsForSection(SECTION_CC);
390c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    for (size_t i = 0; i < cc_inputs.size(); ++i) {
3917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NUMBER ?
3927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch          ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11");
393c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
394c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs);
395c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
396c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
397c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::vector<DialogNotification> NotificationsOfType(
398c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      DialogNotification::Type type) {
399c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    std::vector<DialogNotification> right_type;
400c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const std::vector<DialogNotification>& notifications =
401c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        controller()->CurrentNotifications();
402c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    for (size_t i = 0; i < notifications.size(); ++i) {
403c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      if (notifications[i].type() == type)
404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        right_type.push_back(notifications[i]);
405c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
406c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return right_type;
407c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
408c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
409c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SwitchToAutofill() {
410c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->MenuModelForAccountChooser()->ActivatedAt(
411c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        TestAccountChooserModel::kAutofillItemId);
412c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
413c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
414c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SwitchToWallet() {
415c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->MenuModelForAccountChooser()->ActivatedAt(
416c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        TestAccountChooserModel::kActiveWalletItemId);
417c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
418c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
419868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SimulateSigninError() {
420868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    controller_->SimulateSigninError();
421868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
422868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
42390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void UseBillingForShipping() {
42490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0);
42590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
42690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void ValidateCCNumber(DialogSection section,
4287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                        const std::string& cc_number,
4297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                        bool should_pass) {
4307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DetailOutputMap outputs;
4317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const DetailInputs& inputs =
4327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->RequestedFieldsForSection(section);
4337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
434a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue(inputs, &outputs, CREDIT_CARD_NUMBER,
435a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                   ASCIIToUTF16(cc_number));
4367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    ValidityData validity_data =
4377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
4387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    EXPECT_EQ(should_pass ? 0U : 1U, validity_data.count(CREDIT_CARD_NUMBER));
4397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
4407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void SubmitWithWalletItems(scoped_ptr<wallet::WalletItems> wallet_items) {
442eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    controller()->OnDidGetWalletItems(wallet_items.Pass());
443eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    AcceptAndLoadFakeFingerprint();
444eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
445eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
446eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void AcceptAndLoadFakeFingerprint() {
447eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    controller()->OnAccept();
448eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
449eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
450eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
451ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool ReadSetVisuallyDeemphasizedIpc() {
452ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    EXPECT_EQ(1U, process()->sink().message_count());
453ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    uint32 kMsgID = ChromeViewMsg_SetVisuallyDeemphasized::ID;
454ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    const IPC::Message* message =
455ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        process()->sink().GetFirstMessageMatching(kMsgID);
456ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    EXPECT_TRUE(message);
457ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    Tuple1<bool> payload;
458ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    ChromeViewMsg_SetVisuallyDeemphasized::Read(message, &payload);
459ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    process()->sink().ClearMessages();
460ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return payload.a;
461ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
463ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  TestAutofillDialogController* controller() { return controller_.get(); }
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
465c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const FormStructure* form_structure() { return form_structure_; }
466c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
467ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() {
468ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    return test_generated_bubble_controller_;
469ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
470ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
471ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() {
472ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    return mock_new_card_bubble_controller_.get();
4737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
4747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
476c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void FinishedCallback(const FormStructure* form_structure,
477c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                        const std::string& google_transaction_id) {
478c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    form_structure_ = form_structure;
479868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if (controller()->GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT)
480868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      EXPECT_TRUE(controller()->AutocheckoutIsRunning());
481c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
482c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
483c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN)
484c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   // http://crbug.com/227221
485c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   ui::ScopedOleInitializer ole_initializer_;
486c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
487c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The controller owns itself.
489c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::WeakPtr<TestAutofillDialogController> controller_;
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Must outlive the controller.
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AutofillMetrics metric_logger_;
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
494c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returned when the dialog closes successfully.
495c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const FormStructure* form_structure_;
4967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Used to monitor if the Autofill credit card bubble is shown. Owned by
498ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // |web_contents()|.
499ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  TestGeneratedCreditCardBubbleController* test_generated_bubble_controller_;
500ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
501ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Used to record when new card bubbles would show. Created in |Reset()|.
502ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  scoped_ptr<MockNewCreditCardBubbleController>
503ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      mock_new_card_bubble_controller_;
5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This test makes sure nothing falls over when fields are being validity-
5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// checked.
5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ValidityCheck) {
511868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
512868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DialogSection section = static_cast<DialogSection>(i);
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const DetailInputs& shipping_inputs =
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        controller()->RequestedFieldsForSection(section);
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (DetailInputs::const_iterator iter = shipping_inputs.begin();
5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         iter != shipping_inputs.end(); ++iter) {
5177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputValidityMessage(section, iter->type, string16());
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Test for phone number validation.
52390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) {
52490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Construct DetailOutputMap from existing data.
52590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToAutofill();
52690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
52790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
52890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
52990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
530868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (size_t i = 0; i < 2; ++i) {
5313240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    ServerFieldType phone = i == 0 ? PHONE_HOME_WHOLE_NUMBER :
5323240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch                                     PHONE_BILLING_WHOLE_NUMBER;
5333240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    ServerFieldType address = i == 0 ? ADDRESS_HOME_COUNTRY :
5343240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch                                       ADDRESS_BILLING_COUNTRY;
535868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DialogSection section = i == 0 ? SECTION_SHIPPING : SECTION_BILLING;
53690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
537868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    controller()->EditClickedForSection(section);
53890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
539868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DetailOutputMap outputs;
540868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const DetailInputs& inputs =
541868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        controller()->RequestedFieldsForSection(section);
542868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Make sure country is United States.
543a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue(inputs, &outputs, address, ASCIIToUTF16("United States"));
544868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
545868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Existing data should have no errors.
546868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ValidityData validity_data =
5477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
548868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
549868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
550868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an empty phone number with VALIDATE_FINAL.
551a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue( inputs, &outputs, phone, base::string16());
5527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
554868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
555868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
556868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an empty phone number with VALIDATE_EDIT.
5577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
559868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
560868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
561868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an invalid phone number.
562a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("ABC"));
5637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
565868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
566868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
567868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input a local phone number.
568a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("2155546699"));
5697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
571868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
572868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
573868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an invalid local phone number.
574a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("215554669"));
5757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
577868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
578868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
579868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an international phone number.
580a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("+33 892 70 12 39"));
5817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
583868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
584868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
585868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an invalid international phone number.
586a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone,
587a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                   ASCIIToUTF16("+112333 892 70 12 39"));
5887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
590868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
591868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
59290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
59390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
594a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) {
595a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  DetailOutputMap outputs;
596a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  const DetailInputs& inputs =
597a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
598a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
599a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ui::ComboboxModel* exp_year_model =
600a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR);
601a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ui::ComboboxModel* exp_month_model =
602a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH);
603a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
604a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::string16 default_year_value =
605a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      exp_year_model->GetItemAt(exp_year_model->GetDefaultIndex());
606a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
607a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::string16 other_year_value =
608a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      exp_year_model->GetItemAt(exp_year_model->GetItemCount() - 1);
609a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::string16 other_month_value =
610a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      exp_month_model->GetItemAt(exp_month_model->GetItemCount() - 1);
611a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
612a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR,
613a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 default_year_value);
614a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
615a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Expiration default values "validate" with VALIDATE_EDIT.
616a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ValidityData validity_data =
617a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
618a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
619a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
620a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
621a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Expiration date with default month "validates" with VALIDATE_EDIT.
622a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR,
623a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 other_year_value);
624a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
625a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  validity_data =
626a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
627a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
628a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
629a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
630a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Expiration date with default year "validates" with VALIDATE_EDIT.
631a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_MONTH, other_month_value);
632a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
633a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  validity_data =
634a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
635a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
636a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
637a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
638a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Expiration default values fail with VALIDATE_FINAL.
639a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR,
640a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 default_year_value);
641a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
642a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  validity_data =
643a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_FINAL);
644a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
645a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_MONTH));
646a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
647a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Expiration date with default month fails with VALIDATE_FINAL.
648a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs,
649a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 &outputs,
650a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 CREDIT_CARD_EXP_4_DIGIT_YEAR,
651a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 other_year_value);
652a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
653a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  validity_data =
654a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_FINAL);
655a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
656a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_MONTH));
657a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
658a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Expiration date with default year fails with VALIDATE_FINAL.
659a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_MONTH, other_month_value);
660a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
661a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  validity_data =
662a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_FINAL);
663a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
664a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
665a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
666a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
6677dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, BillingNameValidation) {
66890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Construct DetailOutputMap from AutofillProfile data.
66990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToAutofill();
67090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
67190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DetailOutputMap outputs;
67290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInputs& inputs =
6737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      controller()->RequestedFieldsForSection(SECTION_BILLING);
67490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input an empty billing name with VALIDATE_FINAL.
676a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, NAME_BILLING_FULL, base::string16());
67790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ValidityData validity_data =
6787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      controller()->InputsAreValid(SECTION_BILLING, outputs, VALIDATE_FINAL);
679a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(NAME_BILLING_FULL));
68090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input an empty billing name with VALIDATE_EDIT.
68290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      controller()->InputsAreValid(SECTION_BILLING, outputs, VALIDATE_EDIT);
684a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL));
68590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input a non-empty billing name.
687a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, NAME_BILLING_FULL, ASCIIToUTF16("Bob"));
68890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      controller()->InputsAreValid(SECTION_BILLING, outputs, VALIDATE_FINAL);
690a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL));
69190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
69290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Switch to Wallet which only considers names with with at least two names to
69390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // be valid.
69490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToWallet();
69590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
69690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Setup some wallet state.
69790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
69890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
69990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
70090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DetailOutputMap wallet_outputs;
70190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInputs& wallet_inputs =
70290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
70390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input an empty billing name with VALIDATE_FINAL. Data source should not
70590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // change this behavior.
706a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL,
707a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 base::string16());
70890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
7097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
7107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
711a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(NAME_BILLING_FULL));
71290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input an empty billing name with VALIDATE_EDIT. Data source should not
71490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // change this behavior.
71590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
7167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
7177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_EDIT);
718a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL));
71990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input a one name billing name. Wallet does not currently support this.
721a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL,
722a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 ASCIIToUTF16("Bob"));
72390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
7247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
7257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
726a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(NAME_BILLING_FULL));
72790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input a two name billing name.
729a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL,
730a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 ASCIIToUTF16("Bob Barker"));
73190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
7327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
7337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
734a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL));
73590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input a more than two name billing name.
737a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL,
738a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 ASCIIToUTF16("John Jacob Jingleheimer Schmidt"));
73990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
7407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
7417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
742a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL));
74390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Input a billing name with lots of crazy whitespace.
745a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(
746a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      wallet_inputs, &wallet_outputs, NAME_BILLING_FULL,
747a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      ASCIIToUTF16("     \\n\\r John \\n  Jacob Jingleheimer \\t Schmidt  "));
74890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
7497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
7507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
751a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL));
75290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
75390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) {
7557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Construct DetailOutputMap from AutofillProfile data.
7567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  SwitchToAutofill();
7577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Should accept AMEX, Visa, Master and Discover.
7597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberVisa, true);
7607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberMaster, true);
7617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberDiscover, true);
7627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberAmex, true);
7637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberIncomplete, false);
7657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberInvalid, false);
7667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Switch to Wallet which will not accept AMEX.
7687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  SwitchToWallet();
7697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Setup some wallet state.
7717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
7727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Should accept Visa, Master and Discover, but not AMEX.
7747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberVisa, true);
7757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberMaster, true);
7767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberDiscover, true);
7777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberAmex, false);
7797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberIncomplete, false);
7807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberInvalid, false);
7817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
7827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfiles) {
7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ui::MenuModel* shipping_model =
7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
7862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Since the PersonalDataManager is empty, this should only have the
787c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "use billing", "add new" and "manage" menu items.
78890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
789c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(3, shipping_model->GetItemCount());
790c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // On the other hand, the other models should be NULL when there's no
791c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // suggestion.
792c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
793c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
794c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
79690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3);
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Empty profiles are ignored.
799c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AutofillProfile empty_profile(base::GenerateGUID(), kSettingsOrigin);
8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe"));
8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&empty_profile);
8022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
80390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
804c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(3, shipping_model->GetItemCount());
805c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
80790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // An otherwise full but unverified profile should be ignored.
808c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AutofillProfile full_profile(test::GetFullProfile());
80990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_profile.set_origin("https://www.example.com");
8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
81390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
81490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(3, shipping_model->GetItemCount());
81590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
81690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
81790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // A full, verified profile should be picked up.
81890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile verified_profile(test::GetVerifiedProfile());
81990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
82090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
82190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
82290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
823c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(4, shipping_model->GetItemCount());
824c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL));
8252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Makes sure that the choice of which Autofill profile to use for each section
82890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// is sticky.
82990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) {
83090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetFullProfile());
83190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_profile.set_origin(kSettingsOrigin);
83290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
83390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetFullProfile2());
83490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_profile2.set_origin(kSettingsOrigin);
83590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
83690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
83790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Until a selection has been made, the default shipping suggestion is the
83890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // first one (after "use billing").
83990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* shipping_model = static_cast<SuggestionsMenuModel*>(
84090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING));
84190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1, shipping_model->checked_item());
84290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
84390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for (int i = 2; i >= 0; --i) {
84490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    shipping_model = static_cast<SuggestionsMenuModel*>(
84590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        controller()->MenuModelForSection(SECTION_SHIPPING));
84690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    shipping_model->ExecuteCommand(i, 0);
84790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    FillCreditCardInputs();
84890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->OnAccept();
84990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
850ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    Reset();
85190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->GetTestingManager()->AddTestingProfile(&full_profile);
85290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
85390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    shipping_model = static_cast<SuggestionsMenuModel*>(
85490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        controller()->MenuModelForSection(SECTION_SHIPPING));
85590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    EXPECT_EQ(i, shipping_model->checked_item());
85690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
85790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
85890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Try again, but don't add the default profile to the PDM. The dialog
85990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // should fall back to the first profile.
86090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model->ExecuteCommand(2, 0);
86190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
86290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
863ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  Reset();
86490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
86590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model = static_cast<SuggestionsMenuModel*>(
86690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING));
86790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1, shipping_model->checked_item());
86890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
86990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) {
8712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
872c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ui::MenuModel* email_model =
873c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL);
874c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(email_model);
8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Set up some variant data.
87790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> names;
8792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  names.push_back(ASCIIToUTF16("John Doe"));
8802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  names.push_back(ASCIIToUTF16("Jane Doe"));
8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names);
882c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const string16 kEmail1 = ASCIIToUTF16(kFakeEmail);
8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const string16 kEmail2 = ASCIIToUTF16("admin@example.com");
8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> emails;
8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  emails.push_back(kEmail1);
8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  emails.push_back(kEmail2);
8872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails);
8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Respect variants for the email address field only.
8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ui::MenuModel* shipping_model =
8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
893c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(4, shipping_model->GetItemCount());
894c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  email_model = controller()->MenuModelForSection(SECTION_EMAIL);
895c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(!!email_model);
896c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(4, email_model->GetItemCount());
8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
89890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The first one is the default.
89990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* email_suggestions = static_cast<SuggestionsMenuModel*>(
90090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL));
90190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0, email_suggestions->checked_item());
90290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  email_model->ActivatedAt(0);
904c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail1,
905c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch            controller()->SuggestionStateForSection(SECTION_EMAIL).
906c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch                vertically_compact_text);
9072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  email_model->ActivatedAt(1);
908c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail2,
909c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch            controller()->SuggestionStateForSection(SECTION_EMAIL).
910c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch                vertically_compact_text);
9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_EMAIL);
9132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const DetailInputs& inputs =
9142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
915c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail2, inputs[0].initial_value);
91690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
91790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The choice of variant is persisted across runs of the dialog.
91890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  email_model->ActivatedAt(0);
91990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  email_model->ActivatedAt(1);
92090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
92190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
92290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
923ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  Reset();
92490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
92590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  email_suggestions = static_cast<SuggestionsMenuModel*>(
92690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL));
92790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1, email_suggestions->checked_item());
92890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
92990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
930eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, SuggestValidEmail) {
9317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  AutofillProfile profile(test::GetVerifiedProfile());
9327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  const string16 kValidEmail = ASCIIToUTF16(kFakeEmail);
9337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  profile.SetRawInfo(EMAIL_ADDRESS, kValidEmail);
9347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&profile);
9357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
9367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(0);
9377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_EQ(kValidEmail,
938c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch            controller()->SuggestionStateForSection(SECTION_EMAIL).
939c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch                vertically_compact_text);
9407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
9417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
942eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidEmail) {
9437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  AutofillProfile profile(test::GetVerifiedProfile());
9447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(".!#$%&'*+/=?^_`-@-.."));
9457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&profile);
946eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
947eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->MenuModelForSection(SECTION_EMAIL));
948eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
9497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
950eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromIncompleteProfile) {
951eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile profile(test::GetVerifiedProfile());
952eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail));
953eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(ADDRESS_HOME_STATE, base::string16());
954eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&profile);
955eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
956eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->MenuModelForSection(SECTION_EMAIL));
957eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
958eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
959eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromInvalidProfile) {
960eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile profile(test::GetVerifiedProfile());
961eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail));
962eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C"));
963eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&profile);
964eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
965eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->MenuModelForSection(SECTION_EMAIL));
966eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
967eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
968eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, SuggestValidAddress) {
969eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile full_profile(test::GetVerifiedProfile());
970eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  full_profile.set_origin(kSettingsOrigin);
971eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
972eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(
973eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
974eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
975eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
976eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidAddress) {
977eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile full_profile(test::GetVerifiedProfile());
978eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  full_profile.set_origin(kSettingsOrigin);
979eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  full_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C"));
980eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
981eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(
982eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
9837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
9847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
98590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillCreditCards) {
98690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Since the PersonalDataManager is empty, this should only have the
98790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // default menu items.
98890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
98990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
99090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3);
99190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
99290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Empty cards are ignored.
99390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard empty_card(base::GenerateGUID(), kSettingsOrigin);
99490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  empty_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John Doe"));
99590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&empty_card);
99690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
99790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
99890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // An otherwise full but unverified card should be ignored.
99990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard full_card(test::GetCreditCard());
100090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_card.set_origin("https://www.example.com");
100190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&full_card);
100290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
100390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
100490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // A full, verified card should be picked up.
100590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard verified_card(test::GetCreditCard());
100690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  verified_card.set_origin(kSettingsOrigin);
100790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&verified_card);
100890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* credit_card_model =
100990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC);
101090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(credit_card_model);
101190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(3, credit_card_model->GetItemCount());
10122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1014b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test selecting a shipping address different from billing as address.
1015b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) {
101690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
101790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetVerifiedProfile2());
101890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard credit_card(test::GetVerifiedCreditCard());
1019b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1020b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
1021b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1022b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ui::MenuModel* shipping_model =
1023b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
1024b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  shipping_model->ActivatedAt(2);
1025b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1026b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnAccept();
1027868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_EQ(20U, form_structure()->field_count());
10283240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  EXPECT_EQ(ADDRESS_HOME_STATE,
1029bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(9)->Type().GetStorableType());
1030bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
1031bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_HOME_STATE,
1032bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(16)->Type().GetStorableType());
1033bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
1034868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_state = form_structure()->field(9)->value;
1035868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_state = form_structure()->field(16)->value;
1036868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_state.empty());
1037868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_state.empty());
1038868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_NE(billing_state, shipping_state);
1039868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1040bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(CREDIT_CARD_NAME,
1041bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(1)->Type().GetStorableType());
1042868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 cc_name = form_structure()->field(1)->value;
1043bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
1044bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
1045868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_name = form_structure()->field(6)->value;
1046bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
1047bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
1048868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_name = form_structure()->field(13)->value;
1049868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1050868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(cc_name.empty());
1051868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_name.empty());
1052868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_name.empty());
1053868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Billing name should always be the same as cardholder name.
10547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(cc_name, billing_name);
1055868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_NE(cc_name, shipping_name);
1056b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
1057b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1058b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test selecting UseBillingForShipping.
1059b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) {
106090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
106190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetVerifiedProfile2());
106290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard credit_card(test::GetVerifiedCreditCard());
1063b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1064b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
1065b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1066b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1067b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Test after setting use billing for shipping.
106890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UseBillingForShipping();
1069b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1070b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnAccept();
1071868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_EQ(20U, form_structure()->field_count());
10723240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  EXPECT_EQ(ADDRESS_HOME_STATE,
1073bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(9)->Type().GetStorableType());
1074bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
1075bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_HOME_STATE,
1076bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(16)->Type().GetStorableType());
1077bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
1078868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_state = form_structure()->field(9)->value;
1079868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_state = form_structure()->field(16)->value;
1080868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_state.empty());
1081868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_state.empty());
1082868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(billing_state, shipping_state);
1083868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10843240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  EXPECT_EQ(CREDIT_CARD_NAME,
1085bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(1)->Type().GetStorableType());
1086868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 cc_name = form_structure()->field(1)->value;
1087bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
1088bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
1089868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_name = form_structure()->field(6)->value;
1090bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
1091bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
1092868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_name = form_structure()->field(13)->value;
1093868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1094868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(cc_name.empty());
1095868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_name.empty());
1096868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_name.empty());
1097868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(cc_name, billing_name);
1098868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(cc_name, shipping_name);
1099b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
1100b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
110190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that shipping and billing telephone fields are supported, and filled
110290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// in by their respective profiles. http://crbug.com/244515
1103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) {
110490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FormFieldData shipping_tel;
110590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_tel.autocomplete_attribute = "shipping tel";
110690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FormFieldData billing_tel;
110790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  billing_tel.autocomplete_attribute = "billing tel";
110890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
110990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FormData form_data;
111090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  form_data.fields.push_back(shipping_tel);
111190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  form_data.fields.push_back(billing_tel);
111290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetUpControllerWithFormData(form_data);
111390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
111490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The profile that will be chosen for the shipping section.
111590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile shipping_profile(test::GetVerifiedProfile());
111690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The profile that will be chosen for the billing section.
111790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile billing_profile(test::GetVerifiedProfile2());
111890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard credit_card(test::GetVerifiedCreditCard());
111990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&shipping_profile);
112090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&billing_profile);
112190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
112290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* billing_model =
112390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_BILLING);
112490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  billing_model->ActivatedAt(1);
112590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
112690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
112790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_EQ(2U, form_structure()->field_count());
11283240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1129bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(0)->Type().GetStorableType());
1130bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(PHONE_HOME, form_structure()->field(0)->Type().group());
1131bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1132bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(1)->Type().GetStorableType());
1133bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(PHONE_BILLING, form_structure()->field(1)->Type().group());
113490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER),
113590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            form_structure()->field(0)->value);
1136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(billing_profile.GetRawInfo(PHONE_BILLING_WHOLE_NUMBER),
113790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            form_structure()->field(1)->value);
113890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_NE(form_structure()->field(1)->value,
113990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            form_structure()->field(0)->value);
114090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
114190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
11422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
11432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
11442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              AcceptLegalDocuments(_, _, _)).Times(1);
11452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
11462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              GetFullWallet(_)).Times(1);
114790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
11482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems();
11502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
11512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
115390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidAcceptLegalDocuments();
115490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
11552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Makes sure the default object IDs are respected.
1158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletDefaultItems) {
1159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
1161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
1162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
11642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
1169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "add", "manage", and 4 suggestions.
1173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(6,
1174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
1175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
1176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      IsItemCheckedAt(2));
1177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(controller()->IsEditingExistingData(SECTION_CC_BILLING));
1178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "use billing", "add", "manage", and 5 suggestions.
1179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(8,
1180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
1181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_SHIPPING)->
1182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      IsItemCheckedAt(4));
1183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(controller()->IsEditingExistingData(SECTION_SHIPPING));
118490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
118590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
118690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that invalid and AMEX default instruments are ignored.
118790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SelectInstrument) {
118890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
118990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Tests if default instrument is invalid, then, the first valid instrument is
119090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // selected instead of the default instrument.
119190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
119290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
119390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid());
119490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
119590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
119690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
119790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // 4 suggestions and "add", "manage".
119890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(6,
119990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
120090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
120190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      IsItemCheckedAt(0));
120290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
120390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Tests if default instrument is AMEX, then, the first valid instrument is
120490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // selected instead of the default instrument.
120590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items = wallet::GetTestWalletItems();
120690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
120790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
120890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex());
120990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
121090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
121190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
121290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // 4 suggestions and "add", "manage".
121390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(6,
121490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
121590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
121690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      IsItemCheckedAt(0));
121790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
121890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Tests if only have AMEX and invalid instrument, then "add" is selected.
121990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items = wallet::GetTestWalletItems();
122090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid());
122190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex());
122290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
122390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
122490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // 2 suggestions and "add", "manage".
122590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(4,
122690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
122790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "add"
122890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
122990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      IsItemCheckedAt(2));
1230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveAddress) {
12332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
12342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1235ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::IsNull(),
1236ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               testing::NotNull(),
1237ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
12382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
12402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
12412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
124290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // If there is no shipping address in wallet, it will default to
124390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "same-as-billing" instead of "add-new-item". "same-as-billing" is covered
124490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // by the following tests. The last item in the menu is "add-new-item".
124590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* shipping_model =
124690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
124790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model->ActivatedAt(shipping_model->GetItemCount() - 1);
1248eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
12492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrument) {
12522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
12532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1254ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::NotNull(),
1255ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               testing::IsNull(),
1256ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
12572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
12592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
1260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(wallet_items.Pass());
12612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
126390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) {
126490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
126590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1266ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::NotNull(),
1267ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               testing::IsNull(),
1268ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
126990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
127090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
127190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
127290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid());
1273eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(wallet_items.Pass());
127490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
127590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
12762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) {
12772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1278ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::NotNull(),
1279ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               testing::NotNull(),
1280ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
12812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
1283eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
12842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1286ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochMATCHER(IsUpdatingExistingData, "updating existing Wallet data") {
1287ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  return !arg->object_id().empty();
1288ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
1289ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1290a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Tests that editing an address (in wallet mode0 and submitting the dialog
1291a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// should update the existing address on the server via WalletClient.
1292a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateAddress) {
1293a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1294ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::IsNull(),
1295ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               IsUpdatingExistingData(),
1296ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
1297a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1298eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1299a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1300a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_SHIPPING);
1301eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1302a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1303a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1304a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Tests that editing an instrument (CC + address) in wallet mode updates an
1305a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// existing instrument on the server via WalletClient.
1306a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateInstrument) {
1307ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1308ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(IsUpdatingExistingData(),
1309ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               testing::IsNull(),
1310ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
1311ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1312eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1313a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1314a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_CC_BILLING);
1315eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1316a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1317a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1318a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that a user is able to edit their instrument and add a new address in
1319a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// the same submission.
1320a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateInstrumentSaveAddress) {
1321a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1322ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(IsUpdatingExistingData(),
1323ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               testing::NotNull(),
1324ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
1325a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1326a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1327a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1328a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1329a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1330a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_CC_BILLING);
1331eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1332a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1333a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1334a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that saving a new instrument and editing an address works.
1335a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentUpdateAddress) {
1336a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1337ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::NotNull(),
1338ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               IsUpdatingExistingData(),
1339ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
1340a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1341a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1342a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
134390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1344a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1345a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1346a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_SHIPPING);
1347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1348a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1349a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1350a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)MATCHER(UsesLocalBillingAddress, "uses the local billing address") {
1351ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  return arg->address_line_1() == ASCIIToUTF16(kEditedBillingAddress);
1352a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1353a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
135490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that when using billing address for shipping, and there is no exact
135590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// matched shipping address, then a shipping address should be added.
135690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingForShipping) {
135790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1358ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::IsNull(),
1359ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               testing::NotNull(),
1360ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
136190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1362eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
136390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Select "Same as billing" in the address menu.
136490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UseBillingForShipping();
136590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
136790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
136890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
136990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that when using billing address for shipping, and there is an exact
137090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// matched shipping address, then a shipping address should not be added.
137190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) {
137290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1373ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(_, _, _)).Times(0);
137490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
137590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
137690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument =
137790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      wallet::GetTestMaskedInstrument();
137890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Copy billing address as shipping address, and assign an id to it.
137990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::Address> shipping_address(
138090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      new wallet::Address(instrument->address()));
138190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_address->set_object_id("shipping_address_id");
138290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(shipping_address.Pass());
138390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(instrument.Pass());
138490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
138590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
138690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
138790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Select "Same as billing" in the address menu.
138890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UseBillingForShipping();
138990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1390eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
139190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
139290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1393a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that the local view contents is used when saving a new instrument and
1394a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// the user has selected "Same as billing".
1395a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) {
1396a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1397a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1398a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1399a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1400a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_CC_BILLING);
1401a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnAccept();
1402a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1403a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DetailOutputMap outputs;
1404a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const DetailInputs& inputs =
1405a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
1406a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1407a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const DetailInput& input = inputs[i];
1408a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    outputs[&input] = input.type == ADDRESS_BILLING_LINE1 ?
1409a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        ASCIIToUTF16(kEditedBillingAddress) : input.initial_value;
1410a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1411a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs);
1412a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1413a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1414ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(testing::NotNull(),
1415ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               UsesLocalBillingAddress(),
1416ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                               _)).Times(1);
1417eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1418a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1419a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1420c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, CancelNoSave) {
1421c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1422ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              SaveToWalletMock(_, _, _)).Times(0);
14232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
14242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
14252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
14262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
14272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnCancel();
14282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
14292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1430c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Checks that clicking the Manage menu item opens a new tab with a different
1431c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// URL for Wallet and Autofill.
1432c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ManageItem) {
143390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1434c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  full_profile.set_origin(kSettingsOrigin);
1435c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
1436c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1437c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1438c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
143990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* shipping = static_cast<SuggestionsMenuModel*>(
1440c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING));
144190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping->ExecuteCommand(shipping->GetItemCount() - 1, 0);
1442c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL autofill_manage_url = controller()->open_tab_url();
1443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("chrome", autofill_manage_url.scheme());
1444c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1445c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
144690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
144790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
144890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1449c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
145090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->SuggestionItemSelected(shipping, shipping->GetItemCount() - 1);
145190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GURL wallet_manage_addresses_url = controller()->open_tab_url();
145290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ("https", wallet_manage_addresses_url.scheme());
145390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
145490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* billing = static_cast<SuggestionsMenuModel*>(
145590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING));
145690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->SuggestionItemSelected(billing, billing->GetItemCount() - 1);
145790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GURL wallet_manage_instruments_url = controller()->open_tab_url();
145890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ("https", wallet_manage_instruments_url.scheme());
145990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
146090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_NE(autofill_manage_url, wallet_manage_instruments_url);
146190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_NE(wallet_manage_instruments_url, wallet_manage_addresses_url);
1462c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1463c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1464c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, EditClickedCancelled) {
1465c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
1466c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
146790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1468c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const string16 kEmail = ASCIIToUTF16("first@johndoe.com");
1469c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail);
1470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1471c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1472c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ui::MenuModel* email_model =
1473c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL);
1474c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(3, email_model->GetItemCount());
1475c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1476c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // When unedited, the initial_value should be empty.
1477c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  email_model->ActivatedAt(0);
1478c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs0 =
1479c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
1480c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(string16(), inputs0[0].initial_value);
1481c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail,
1482c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch            controller()->SuggestionStateForSection(SECTION_EMAIL).
1483c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch                vertically_compact_text);
1484c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1485c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // When edited, the initial_value should contain the value.
1486c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_EMAIL);
1487c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs1 =
1488c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
1489c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail, inputs1[0].initial_value);
1490c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  EXPECT_FALSE(controller()->SuggestionStateForSection(SECTION_EMAIL).visible);
1491c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1492c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // When edit is cancelled, the initial_value should be empty.
1493c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditCancelledForSection(SECTION_EMAIL);
1494c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs2 =
1495c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
1496c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail,
1497c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch            controller()->SuggestionStateForSection(SECTION_EMAIL).
1498c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch                vertically_compact_text);
1499c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(string16(), inputs2[0].initial_value);
1500c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1501c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1502c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that editing an autofill profile and then submitting works.
1503c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, EditAutofillProfile) {
1504c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1505c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1506ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
1507c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
150890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1509ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  CreditCard credit_card(test::GetVerifiedCreditCard());
1510c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1511ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1512c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_SHIPPING);
1513c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1514c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DetailOutputMap outputs;
1515c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs =
1516c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_SHIPPING);
1517c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1518c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = inputs[i];
1519c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    outputs[&input] = input.type == NAME_FULL ? ASCIIToUTF16("Edited Name") :
1520c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                input.initial_value;
1521c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1522c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs);
1523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1524c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // We also have to simulate CC inputs to keep the controller happy.
1525c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  FillCreditCardInputs();
1526c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1527c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const AutofillProfile& edited_profile =
1529c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->GetTestingManager()->imported_profile();
1530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1531c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = inputs[i];
1533c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    EXPECT_EQ(input.type == NAME_FULL ? ASCIIToUTF16("Edited Name") :
1534c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                        input.initial_value,
15353240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch              edited_profile.GetInfo(AutofillType(input.type), "en-US"));
1536c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1537c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1538c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1539c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that adding an autofill profile and then submitting works.
1540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AddAutofillProfile) {
1541ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  SwitchToAutofill();
15427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
1543c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
154490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
15457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CreditCard credit_card(test::GetVerifiedCreditCard());
1546c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
15477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1548c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1549c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING);
1550c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Activate the "Add billing address" menu item.
1551c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  model->ActivatedAt(model->GetItemCount() - 2);
1552c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1553c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Fill in the inputs from the profile.
1554c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DetailOutputMap outputs;
1555c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs =
1556c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_BILLING);
155790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetVerifiedProfile2());
1558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = inputs[i];
15603240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    outputs[&input] = full_profile2.GetInfo(AutofillType(input.type), "en-US");
1561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_BILLING, outputs);
1563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const AutofillProfile& added_profile =
1566c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->GetTestingManager()->imported_profile();
1567c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1568c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& shipping_inputs =
1569c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_SHIPPING);
1570c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < shipping_inputs.size(); ++i) {
1571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = shipping_inputs[i];
15723240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    EXPECT_EQ(full_profile2.GetInfo(AutofillType(input.type), "en-US"),
15733240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch              added_profile.GetInfo(AutofillType(input.type), "en-US"));
1574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
157590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
157690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Also, the currently selected email address should get added to the new
157790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // profile.
15783240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  string16 original_email =
15793240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch      full_profile.GetInfo(AutofillType(EMAIL_ADDRESS), "en-US");
158090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(original_email.empty());
158190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(original_email,
15823240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch            added_profile.GetInfo(AutofillType(EMAIL_ADDRESS), "en-US"));
158390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
158490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
158590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Makes sure that a newly added email address gets added to an existing profile
158690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// (as opposed to creating its own profile). http://crbug.com/240926
158790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AddEmail) {
1588ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  SwitchToAutofill();
1589ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
159090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
159190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1592ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  CreditCard credit_card(test::GetVerifiedCreditCard());
159390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1594ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
159590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
159690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* model = controller()->MenuModelForSection(SECTION_EMAIL);
159790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(model);
159890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Activate the "Add email address" menu item.
159990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  model->ActivatedAt(model->GetItemCount() - 2);
160090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
160190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Fill in the inputs from the profile.
160290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DetailOutputMap outputs;
160390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInputs& inputs =
160490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
160590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInput& input = inputs[0];
160690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  string16 new_email = ASCIIToUTF16("addemailtest@example.com");
160790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  outputs[&input] = new_email;
160890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_EMAIL, outputs);
160990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
161090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
161190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
161290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::vector<base::string16> email_values;
16133240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  full_profile.GetMultiInfo(
16143240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch      AutofillType(EMAIL_ADDRESS), "en-US", &email_values);
161590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_EQ(2U, email_values.size());
161690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(new_email, email_values[1]);
1617c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1618c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1619c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, VerifyCvv) {
1620c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1621c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1622c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1623ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch              AuthenticateInstrument(_, _)).Times(1);
1624c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1625eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1626c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1627c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty());
1628c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING));
1629c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
1630c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
16317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1632c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1633c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SuggestionState suggestion_state =
1634c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->SuggestionStateForSection(SECTION_CC_BILLING);
1635c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(suggestion_state.extra_text.empty());
1636c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1637868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv"));
1638c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1639c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(
1640c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty());
1641c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
1642c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
1643c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1644c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  suggestion_state =
1645c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->SuggestionStateForSection(SECTION_CC_BILLING);
1646c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(suggestion_state.extra_text.empty());
1647c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING));
1648c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1649c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1650c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1651c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1652c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1653c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1654c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1655c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) {
1656c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1657c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1658c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1659eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1660c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1661c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
16627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1663c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1664c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
1665c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1666c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1667c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1668c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1669c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1670c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(dbeam): disallow changing accounts instead and remove this test.
1671c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) {
1672c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1673c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1674c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1675eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1676c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1677c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
16787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1679c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1680c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
1681c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1682c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1683c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1684c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1685c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1686c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1687c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) {
1688c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1689c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1690c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1691eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1692868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv"));
1693c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1694c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1695c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1696c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1697c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
1698c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1699c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1700c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1701c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1702c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1703c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(dbeam): disallow changing accounts instead and remove this test.
1704c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) {
1705c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1706c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1707c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1708eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1709868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv"));
1710c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1711c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1712c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1713c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1714c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
1715c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1716c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1717c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1718c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1719c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1720c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1721a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Simulates receiving an INVALID_FORM_FIELD required action while processing a
1722a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// |WalletClientDelegate::OnDid{Save,Update}*()| call. This can happen if Online
1723a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Wallet's server validation differs from Chrome's local validation.
17247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletServerSideValidation) {
1725a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1726a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1727a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1728a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnAccept();
1729a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1730a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::vector<wallet::RequiredAction> required_actions;
1731a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  required_actions.push_back(wallet::INVALID_FORM_FIELD);
17327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
17337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::vector<wallet::FormFieldError> form_errors;
17347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  form_errors.push_back(
17357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      wallet::FormFieldError(wallet::FormFieldError::INVALID_POSTAL_CODE,
17367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                             wallet::FormFieldError::SHIPPING_ADDRESS));
17377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
17387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1);
1739ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  controller()->OnDidSaveToWallet(std::string(),
1740ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                  std::string(),
1741ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                  required_actions,
1742ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                  form_errors);
17437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
17447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
17457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Simulates receiving unrecoverable Wallet server validation errors.
17467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletServerSideValidationUnrecoverable) {
17477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
17487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
17497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
17507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnAccept();
17517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
17527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::vector<wallet::RequiredAction> required_actions;
17537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  required_actions.push_back(wallet::INVALID_FORM_FIELD);
17547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
17557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::vector<wallet::FormFieldError> form_errors;
17567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  form_errors.push_back(
17577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      wallet::FormFieldError(wallet::FormFieldError::UNKNOWN_ERROR,
17587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                             wallet::FormFieldError::UNKNOWN_LOCATION));
17597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1760ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  controller()->OnDidSaveToWallet(std::string(),
1761ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                  std::string(),
1762ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                  required_actions,
1763ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                  form_errors);
1764a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1765a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1766a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
1767a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1768a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1769868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Test Wallet banners are show in the right situations. These banners explain
1770868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// where Chrome got the user's data (i.e. "Got details from Wallet") or promote
1771868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// saving details into Wallet (i.e. "[x] Save details to Wallet").
1772868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletBanners) {
1773eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CommandLine* command_line = CommandLine::ForCurrentProcess();
1774eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  command_line->AppendSwitch(switches::kWalletServiceUseProd);
17757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PrefService* prefs = profile()->GetPrefs();
17767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
17777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Simulate first run.
17787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, false);
17797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SetUpControllerWithFormData(DefaultFormData());
1780868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1781868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1782868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1783868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1784868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1785868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1786868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Sign in a user with a completed account.
1787eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1788c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1789868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Full account; should show "Details from Wallet" message.
1790c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1791c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1792868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1793868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1794c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1795868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Full account; no "[x] Save details in Wallet" option should show.
1796c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1797868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1798868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1799868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1800868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1801c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1802868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
1803868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // |controller()| has already been initialized. Test that should not take
1804868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // effect until the next call of |SetUpControllerWithFormData()|.
1805868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, true);
1806c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1807868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Sign in a user with a incomplete account.
1808eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1809c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1810c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1811c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1812868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Partial account; no "Details from Wallet" message should show, but a
1813868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // "[x] Save details in Wallet" should.
1814868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1815868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1816868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1817868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1818c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1819868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Once the usage confirmation banner is shown once, it keeps showing even if
1820868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // the user switches to Autofill data.
1821c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1822868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1823868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1824868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1825868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1826c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1827868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // A Wallet error should kill any Wallet promos.
1828868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
1829c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1830868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1831868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_ERROR).size());
1832868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1833868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1834868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1835868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1836c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1837868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
1838868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // |controller()| is error free and thinks the user has already paid w/Wallet.
1839c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1840868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // User has already paid with wallet. Don't show promos.
1841868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1842868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1843868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1844868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1845868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1846eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1847c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1848868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1849868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1850868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1851868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1852868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1853868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items = wallet::GetTestWalletItems();
1854868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1855868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1856868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1857868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SwitchToAutofill();
1858868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1859868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1860868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1861868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1862c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1863c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
186490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, OnAutocheckoutError) {
186590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToAutofill();
186690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
186790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
186890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // We also have to simulate CC inputs to keep the controller happy.
186990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
187090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
187190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
1872ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc());
187390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAutocheckoutError();
187490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1875ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_FALSE(controller()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL);
1876ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
187790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
187890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_SUCCESS).size());
187990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
188090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_ERROR).size());
1881ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1882ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  controller()->ViewClosed();
1883ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc());
188490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
188590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
188690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, OnAutocheckoutSuccess) {
1887eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CommandLine* command_line = CommandLine::ForCurrentProcess();
1888eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  command_line->AppendSwitch(switches::kWalletServiceUseProd);
188990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
189090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
18917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Simulate first run.
18927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  profile()->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet,
18937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                    false);
18947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SetUpControllerWithFormData(DefaultFormData());
18957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
18967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1897eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Sign in a user with a completed account.
1898eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1899eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1900eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Full account; should show "Details from Wallet" message.
1901eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(1U, NotificationsOfType(
1902eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::EXPLANATORY_MESSAGE).size());
1903eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0U, NotificationsOfType(
1904eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1905eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1906eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1907ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc());
1908eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
19097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty());
1910eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1911eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0U, NotificationsOfType(
1912eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::EXPLANATORY_MESSAGE).size());
191390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
191490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAutocheckoutSuccess();
19157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty());
191690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1917ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_FALSE(controller()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL);
1918ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
191990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
192090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_SUCCESS).size());
192190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
192290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_ERROR).size());
1923eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0U, NotificationsOfType(
1924eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::EXPLANATORY_MESSAGE).size());
19257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
19267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      ::prefs::kAutofillDialogHasPaidWithWallet));
1927ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1928ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  controller()->ViewClosed();
1929ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc());
193090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
193190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1932c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ViewCancelDoesntSetPref) {
1933c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath(
1934c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1935c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1936c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1937c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1938c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnCancel();
1939c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->ViewClosed();
1940c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1941c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath(
1942c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1943c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1944c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1945868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, SubmitWithSigninErrorDoesntSetPref) {
1946868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath(
1947868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1948868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1949868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SimulateSigninError();
1950868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FillCreditCardInputs();
1951868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
1952868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1953868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath(
1954868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1955868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
1956868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
19577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Tests that there's an overlay shown while waiting for full wallet items,
19587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// and on first run an additional expository wallet overlay shown after full
19597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// wallet items are returned.
19607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// TODO(estade): enable on other platforms when overlays are supported there.
19617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#if defined(TOOLKIT_VIEWS)
19627dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, WalletFirstRun) {
19637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Simulate first run.
19647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PrefService* prefs = profile()->GetPrefs();
19657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, false);
19667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SetUpControllerWithFormData(DefaultFormData());
19677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
19687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SwitchToWallet();
19697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty());
19707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
19717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
19727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty());
19737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
19747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet));
19757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
19767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet));
19777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty());
19787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(form_structure());
19797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
19807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->OverlayButtonPressed();
19817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet));
19827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(form_structure());
19837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
19847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif
19857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
19867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// On second run, the second overlay doesn't show.
19877dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, WalletSecondRun) {
19887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SwitchToWallet();
19897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty());
19907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
19917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
19927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty());
19937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
19947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
19957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      ::prefs::kAutofillDialogHasPaidWithWallet));
19967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
19977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
19987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      ::prefs::kAutofillDialogHasPaidWithWallet));
19997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(form_structure());
20007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
20017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2002c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) {
2003c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath(
2004c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2005c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2006c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
2007868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FillCreditCardInputs();
2008868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
2009c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2010868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
2011868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2012868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
2013868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2014868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2015868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Try again with a signin error (just leaves the pref alone).
2016868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
2017868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2018868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Setting up the controller again should not change the pref.
2019868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
2020868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2021868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
2022868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2023868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2024868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SimulateSigninError();
2025c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  FillCreditCardInputs();
2026868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
2027868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
2028868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2029868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
2030868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2031868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2032868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Succesfully choosing wallet does set the pref.
2033868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
2034c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2035868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SwitchToWallet();
2036868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
2037868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
2038868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
2039c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
2040868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2041c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2042c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
2043c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2044868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(
2045c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
2046c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
2047c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2048c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, HideWalletEmail) {
2049c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
2050c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2051c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Email section should be showing when using Autofill.
2052c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL));
2053c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2054c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
2055c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2056c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Setup some wallet state, submit, and get a full wallet to end the flow.
2057eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems();
2058c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2059c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Filling |form_structure()| depends on the current username and wallet items
2060c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // being fetched. Until both of these have occurred, the user should not be
2061c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // able to click Submit if using Wallet. The username fetch happened earlier.
2062c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2063c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
2064c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2065c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2066c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Email section should be hidden when using Wallet.
2067c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL));
2068c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2069c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
2070c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2071c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2072c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  size_t i = 0;
2073c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (; i < form_structure()->field_count(); ++i) {
2074bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch    if (form_structure()->field(i)->Type().GetStorableType() == EMAIL_ADDRESS) {
2075c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value);
2076c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      break;
2077c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
2078c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
2079c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_LT(i, form_structure()->field_count());
2080c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
2081c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2082b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test if autofill types of returned form structure are correct for billing
2083b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// entries.
2084b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillTypes) {
20857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2086b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnAccept();
2087b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2088868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_EQ(20U, form_structure()->field_count());
2089bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(EMAIL_ADDRESS,
2090bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(0)->Type().GetStorableType());
20913240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  EXPECT_EQ(CREDIT_CARD_NUMBER,
2092bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(2)->Type().GetStorableType());
2093bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_HOME_STATE,
2094bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(9)->Type().GetStorableType());
2095bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
20963240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  EXPECT_EQ(ADDRESS_HOME_STATE,
2097bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch            form_structure()->field(16)->Type().GetStorableType());
2098bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
2099b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
2100b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
2101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) {
2102ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  SwitchToAutofill();
2103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
2104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
210590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
2106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
2107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
210890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard card(test::GetVerifiedCreditCard());
2109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&card);
2110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
2111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_EMAIL);
2113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
2114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditCancelledForSection(SECTION_EMAIL);
2116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
2117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
2119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
2120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  profile()->set_incognito(true);
2122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
2123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
2124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
212590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that user is prompted when using instrument with minimal address.
212690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) {
2127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // A minimal address being selected should trigger error validation in the
2128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // view. Called once for each incomplete suggestion.
2129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1);
2130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
213190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
213290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentWithIdAndAddress(
213390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      "id", wallet::GetTestMinimalAddress()));
213490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::Address> address(wallet::GetTestShippingAddress());
213590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  address->set_is_complete_address(false);
213690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(address.Pass());
213790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
213890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
213990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Assert that dialog's SECTION_CC_BILLING section is in edit mode.
2140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING));
214190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Shipping section should be in edit mode because of
214290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // is_minimal_shipping_address.
2143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_TRUE(controller()->IsEditingExistingData(SECTION_SHIPPING));
214490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
214590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
214690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) {
214790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
214890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
214990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
215090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
215190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
215290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
215390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
215490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
215590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) {
215690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
215790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
215890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
215990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
216090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
216190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
216290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  testing::Mock::VerifyAndClear(controller());
216390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
216490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
216590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
216690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
216790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Simulate a risk load and verify |GetRiskData()| matches the encoded value.
216890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidAcceptLegalDocuments();
216990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
217090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData());
217190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
217290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
217390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, NoManageMenuItemForNewWalletUsers) {
217490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Make sure the menu model item is created for a returning Wallet user.
217590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
217690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
217790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
217890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
217990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
218090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING));
218190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "Same as billing", "123 address", "Add address...", and "Manage addresses".
218290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(
218390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
218490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
218590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Make sure the menu model item is not created for new Wallet users.
218690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::DictionaryValue dict;
218790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<base::ListValue> required_actions(new base::ListValue);
218890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  required_actions->AppendString("setup_wallet");
218990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  dict.Set("required_action", required_actions.release());
219090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(
219190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      wallet::WalletItems::CreateWalletItems(dict).Pass());
219290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
219390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING));
219490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "Same as billing" and "Add address...".
219590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(
219690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
219790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
219890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHidden) {
2200868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SwitchToAutofill();
2201868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2202868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormFieldData email_field;
2203868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  email_field.autocomplete_attribute = "email";
2204868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormFieldData cc_field;
2205868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  cc_field.autocomplete_attribute = "cc-number";
2206868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormFieldData billing_field;
2207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  billing_field.autocomplete_attribute = "billing region";
2208868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2209868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormData form_data;
2210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  form_data.fields.push_back(email_field);
2211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  form_data.fields.push_back(cc_field);
2212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  form_data.fields.push_back(billing_field);
2213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
2215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
2216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(form_data);
2217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
2218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FillCreditCardInputs();
2220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
2221868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(form_structure());
2222868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2224a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHiddenForWallet) {
2225a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SwitchToWallet();
2226a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2227a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  FormFieldData email_field;
2228a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  email_field.autocomplete_attribute = "email";
2229a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  FormFieldData cc_field;
2230a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  cc_field.autocomplete_attribute = "cc-number";
2231a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  FormFieldData billing_field;
2232a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  billing_field.autocomplete_attribute = "billing region";
2233a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2234a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  FormData form_data;
2235a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  form_data.fields.push_back(email_field);
2236a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  form_data.fields.push_back(cc_field);
2237a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  form_data.fields.push_back(billing_field);
2238a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2239a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetUpControllerWithFormData(form_data);
2240a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
2241a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_FALSE(controller()->IsShippingAddressRequired());
2242a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2243a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
2244a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)              GetFullWallet(_)).Times(1);
2245a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
2246a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
2247a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SubmitWithWalletItems(wallet_items.Pass());
2248a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWalletInstrumentOnly());
2249a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_TRUE(form_structure());
2250a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
2251a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2252868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, NotProdNotification) {
2253868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // To make IsPayingWithWallet() true.
2254868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
2255868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2256868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
2257868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(command_line->HasSwitch(switches::kWalletServiceUseProd));
2258868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(
2259868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty());
2260868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2261868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  command_line->AppendSwitch(switches::kWalletServiceUseProd);
2262868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
2263868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty());
2264868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2265868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2266868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Ensure Wallet instruments marked expired by the server are shown as invalid.
2267868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletExpiredCard) {
2268868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
2269868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired());
2270868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
2271868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2272868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING));
2273868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
22743240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  // Use |SetOutputValue()| to put the right ServerFieldTypes into the map.
2275868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const DetailInputs& inputs =
2276868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
2277868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DetailOutputMap outputs;
2278a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, COMPANY_NAME, ASCIIToUTF16("Bluth Company"));
2279868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2280868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ValidityData validity_data =
22817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
2282868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_MONTH));
2283868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
2284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Make the local input year differ from the instrument.
2286a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR,
2287a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                 ASCIIToUTF16("3002"));
2288868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
22897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  validity_data =
22907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
2291868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
2292868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
2293868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2294868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Make the local input month differ from the instrument.
2295a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06"));
2296868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
22977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  validity_data =
22987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
2299868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
2300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
2301868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2302868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2303868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChooseAnotherInstrumentOrAddress) {
2304eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
2305868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2306868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
2307868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
2308868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
2309868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)              GetWalletItems(_)).Times(1);
2310868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(
2311868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      CreateFullWallet("choose_another_instrument_or_address"));
2312868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
2313868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
2314eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2315868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2316868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
2317868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
2318868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
2319868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2320868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2321eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Make sure detailed steps for Autocheckout are added
2322eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// and updated correctly.
2323eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DetailedSteps) {
2324eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_CALL(*controller()->GetTestingWalletClient(),
23257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch              GetFullWallet(_)).Times(1);
2326eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2327eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
2328eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2329eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Add steps as would normally be done by the AutocheckoutManager.
2330eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING);
2331eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY);
2332eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_BILLING);
2333eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2334eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
2335eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
2336eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  wallet_items->AddAddress(wallet::GetTestShippingAddress());
2337eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(wallet_items.Pass());
2338eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Initiate flow - should add proxy card step since the user is using wallet
2339eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // data.
2340eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnAccept();
2341ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc());
2342eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
2343eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2344eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SuggestionState suggestion_state =
2345eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      controller()->SuggestionStateForSection(SECTION_CC_BILLING);
2346eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_TRUE(suggestion_state.extra_text.empty());
2347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // There should be four steps total, with the first being the card generation
2349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // step added by the dialog controller.
2350eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(4U, controller()->CurrentAutocheckoutSteps().size());
2351eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_PROXY_CARD,
2352eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].type());
2353eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED,
2354eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].status());
2355eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2356eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Simulate a wallet error. This should remove the card generation step from
2357eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // the flow, as we will have to proceed with local data.
2358eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
2359eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2360eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile shipping_profile(test::GetVerifiedProfile());
2361eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile billing_profile(test::GetVerifiedProfile2());
2362eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CreditCard credit_card(test::GetVerifiedCreditCard());
2363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&shipping_profile);
2364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&billing_profile);
2365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
2366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ui::MenuModel* billing_model =
2367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      controller()->MenuModelForSection(SECTION_BILLING);
2368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  billing_model->ActivatedAt(1);
2369eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2370eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Re-initiate flow.
2371eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnAccept();
2372ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc());
2373eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2374eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // All steps should be initially unstarted.
2375eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size());
2376eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING,
2377eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].type());
2378eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2379eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].status());
2380eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY,
2381eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].type());
2382eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2383eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].status());
2384eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING,
2385eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].type());
2386eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].status());
2388eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2389eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Update steps in the same manner that we would expect to see from the
2390eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // AutocheckoutManager while progressing through a flow.
2391eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING,
2392eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                       AUTOCHECKOUT_STEP_STARTED);
2393eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING,
2394eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                       AUTOCHECKOUT_STEP_COMPLETED);
2395eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY,
2396eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                       AUTOCHECKOUT_STEP_STARTED);
2397eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2398eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Verify that the steps were appropriately updated.
2399eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size());
2400eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING,
2401eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].type());
2402eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_COMPLETED,
2403eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].status());
2404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY,
2405eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].type());
2406eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED,
2407eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].status());
2408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING,
2409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].type());
2410eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2411eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].status());
2412ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
2413ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  controller()->ViewClosed();
2414ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc());
2415eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
2416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
24177dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, NewCardBubbleShown) {
2418ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(0);
24197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
24207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SwitchToAutofill();
24217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  FillCreditCardInputs();
24227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->OnAccept();
24237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->ViewClosed();
2424ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
2425ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, mock_new_card_bubble_controller()->bubbles_shown());
24267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
24277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
24287dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, GeneratedCardBubbleShown) {
2429ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(1);
24307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
24317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
24327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
24337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  controller()->ViewClosed();
2434ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
2435ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown());
24367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
24377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
243858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben MurdochTEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) {
243958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // Switch into Wallet mode and initialize some Wallet data.
244058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  SwitchToWallet();
244158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch
244258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
244358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
244458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
244558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
244658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddAddress(wallet::GetTestShippingAddress());
244758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  controller()->OnDidGetWalletItems(wallet_items.Pass());
244858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch
244958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // Initially, the default entries should be selected.
245058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ui::MenuModel* cc_billing_model =
245158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch      controller()->MenuModelForSection(SECTION_CC_BILLING);
245258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ui::MenuModel* shipping_model =
245358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch      controller()->MenuModelForSection(SECTION_SHIPPING);
245458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // "add", "manage", and 2 suggestions.
245558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ASSERT_EQ(4, cc_billing_model->GetItemCount());
245658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0));
245758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // "use billing", "add", "manage", and 2 suggestions.
245858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ASSERT_EQ(5, shipping_model->GetItemCount());
245958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  EXPECT_TRUE(shipping_model->IsItemCheckedAt(2));
246058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch
246158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // Select entries other than the defaults.
246258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  cc_billing_model->ActivatedAt(1);
246358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  shipping_model->ActivatedAt(1);
246458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // "add", "manage", and 2 suggestions.
246558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ASSERT_EQ(4, cc_billing_model->GetItemCount());
246658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1));
246758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // "use billing", "add", "manage", and 2 suggestions.
246858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ASSERT_EQ(5, shipping_model->GetItemCount());
246958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  EXPECT_TRUE(shipping_model-> IsItemCheckedAt(1));
247058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch
247158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // Simulate switching away from the tab and back.  This should issue a request
247258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // for wallet items.
247358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_));
247458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  controller()->TabActivated();
247558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch
247658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // Simulate a response that includes different items.
247758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items = wallet::GetTestWalletItems();
247858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired());
247958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
248058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
248158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
248258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  controller()->OnDidGetWalletItems(wallet_items.Pass());
248358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch
248458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // The previously selected entries should still be selected.
248558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // "add", "manage", and 3 suggestions.
248658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ASSERT_EQ(5, cc_billing_model->GetItemCount());
248758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(2));
248858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  // "use billing", "add", "manage", and 1 suggestion.
248958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  ASSERT_EQ(4, shipping_model->GetItemCount());
249058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch  EXPECT_TRUE(shipping_model->IsItemCheckedAt(1));
249158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch}
249258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch
2493558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochTEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) {
2494558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  SwitchToWallet();
2495558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
2496558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2497558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(1);
2498558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1);
2499558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
2500558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_));
2501558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  controller()->TabActivated();
2502558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
2503558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
2504558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
2505558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING));
2506558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(
2507558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch      3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
2508558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch}
2509558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
2510a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleNotShown) {
2511ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(0);
2512a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2513a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  SubmitWithWalletItems(CompleteAndValidWalletItems());
2514a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
2515a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2516a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  controller()->OnAutocheckoutError();
2517a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  controller()->ViewClosed();
2518ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
2519ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown());
2520a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
2521a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
25222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace autofill
2523