autofill_dialog_controller_unittest.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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"
11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/message_loop.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/run_loop.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/testing_profile.h"
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/full_wallet.h"
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/instrument.h"
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_address.h"
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_client.h"
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_service_url.h"
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_test_util.h"
26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_common_test.h"
27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_metrics.h"
28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/test_personal_data_manager.h"
297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/autofill_switches.h"
307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/form_data.h"
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/web_contents.h"
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/public/test/test_browser_thread_bundle.h"
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/web_contents_tester.h"
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN)
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/win/scoped_ole_initializer.h"
39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using testing::_;
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace autofill {
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kFakeEmail[] = "user@example.com";
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char kFakeFingerprintEncoded[] = "CgVaAwiACA==";
49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)const char kEditedBillingAddress[] = "123 edited billing address";
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char* kFieldsFromPage[] =
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    { "email",
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-name",
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-number",
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-exp-month",
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-exp-year",
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "cc-csc",
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing name",
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing address-line1",
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing locality",
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing region",
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing postal-code",
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing country",
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "billing tel",
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping name",
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping address-line1",
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping locality",
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping region",
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping postal-code",
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping country",
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "shipping tel",
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    };
72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kSettingsOrigin[] = "Chrome settings";
737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberAmex[] = "376200000000002";
747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberVisa[] = "4111111111111111";
757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberMaster[] = "5555555555554444";
767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberDiscover[] = "6011111111111117";
777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberIncomplete[] = "4111111111";
787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Credit card number fails Luhn check.
797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberInvalid[] = "4111111111111112";
807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void SetOutputValue(const DetailInputs& inputs,
8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    DetailOutputMap* outputs,
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    AutofillFieldType type,
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    const std::string& value) {
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const DetailInput& input = inputs[i];
8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    (*outputs)[&input] = input.type == type ?
8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        ASCIIToUTF16(value) :
9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        input.initial_value;
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochscoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() {
95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> items = wallet::GetTestWalletItems();
96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  items->AddInstrument(wallet::GetTestMaskedInstrument());
97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  items->AddAddress(wallet::GetTestShippingAddress());
98eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return items.Pass();
99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)scoped_ptr<wallet::FullWallet> CreateFullWallet(const char* required_action) {
10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::DictionaryValue dict;
10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<base::ListValue> list(new base::ListValue());
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  list->AppendString(required_action);
10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  dict.Set("required_action", list.release());
10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return wallet::FullWallet::CreateFullWallet(dict);
10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)scoped_ptr<risk::Fingerprint> GetFakeFingerprint() {
11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint());
11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Add some data to the proto, else the encoded content is empty.
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  fingerprint->mutable_machine_characteristics()->mutable_screen_size()->
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      set_width(1024);
11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return fingerprint.Pass();
11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestAutofillDialogView : public AutofillDialogView {
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestAutofillDialogView() {}
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TestAutofillDialogView() {}
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Show() OVERRIDE {}
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Hide() OVERRIDE {}
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateNotificationArea() OVERRIDE {}
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateAccountChooser() OVERRIDE {}
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateButtonStrip() OVERRIDE {}
127b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void UpdateDetailArea() OVERRIDE {}
128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void UpdateAutocheckoutStepsArea() OVERRIDE {}
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateSection(DialogSection section) OVERRIDE {}
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void FillSection(DialogSection section,
131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                           const DetailInput& originating_input) OVERRIDE {};
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void GetUserInput(DialogSection section, DetailOutputMap* output)
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      OVERRIDE {
134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    *output = outputs_[section];
135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual string16 GetCvc() OVERRIDE { return string16(); }
138c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool SaveDetailsLocally() OVERRIDE { return true; }
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const content::NavigationController* ShowSignIn() OVERRIDE {
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return NULL;
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void HideSignIn() OVERRIDE {}
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateProgressBar(double value) OVERRIDE {}
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD0(ModelChanged, void());
1467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  MOCK_METHOD0(UpdateForErrors, void());
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
14890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {}
14990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
150c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SetUserInput(DialogSection section, const DetailOutputMap& map) {
151c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    outputs_[section] = map;
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::map<DialogSection, DetailOutputMap> outputs_;
156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView);
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestWalletClient : public wallet::WalletClient {
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestWalletClient(net::URLRequestContextGetter* context,
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                   wallet::WalletClientDelegate* delegate)
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : wallet::WalletClient(context, delegate) {}
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TestWalletClient() {}
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD3(AcceptLegalDocuments,
168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      void(const std::vector<wallet::WalletItems::LegalDocument*>& documents,
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const std::string& google_transaction_id,
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const GURL& source_url));
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  MOCK_METHOD3(AuthenticateInstrument,
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      void(const std::string& instrument_id,
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)           const std::string& card_verification_number,
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)           const std::string& obfuscated_gaia_id));
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD1(GetFullWallet,
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      void(const wallet::WalletClient::FullWalletRequest& request));
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  MOCK_METHOD1(GetWalletItems, void(const GURL& source_url));
181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD2(SaveAddress,
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      void(const wallet::Address& address, const GURL& source_url));
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD3(SaveInstrument,
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      void(const wallet::Instrument& instrument,
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const std::string& obfuscated_gaia_id,
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const GURL& source_url));
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD4(SaveInstrumentAndAddress,
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      void(const wallet::Instrument& instrument,
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const wallet::Address& address,
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const std::string& obfuscated_gaia_id,
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           const GURL& source_url));
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
196a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  MOCK_METHOD2(UpdateAddress,
197a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      void(const wallet::Address& address, const GURL& source_url));
198a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
199a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void UpdateInstrument(
200a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      const wallet::WalletClient::UpdateInstrumentRequest& update_request,
201a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      scoped_ptr<wallet::Address> billing_address) {
202a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    updated_billing_address_ = billing_address.Pass();
203a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
204a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
205a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const wallet::Address* updated_billing_address() {
206a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return updated_billing_address_.get();
207a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
208a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
210a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::Address> updated_billing_address_;
211a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestWalletClient);
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Bring over command-ids from AccountChooserModel.
216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestAccountChooserModel : public AccountChooserModel {
217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public:
218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestAccountChooserModel(AccountChooserModelDelegate* delegate,
219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          PrefService* prefs,
220c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          const AutofillMetrics& metric_logger)
221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      : AccountChooserModel(delegate, prefs, metric_logger,
222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {}
223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual ~TestAccountChooserModel() {}
224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  using AccountChooserModel::kActiveWalletItemId;
226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  using AccountChooserModel::kAutofillItemId;
227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
228c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private:
229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel);
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestAutofillDialogController
233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : public AutofillDialogControllerImpl,
234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      public base::SupportsWeakPtr<TestAutofillDialogController> {
2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestAutofillDialogController(
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content::WebContents* contents,
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const FormData& form_structure,
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const GURL& source_url,
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const AutofillMetrics& metric_logger,
2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const DialogType dialog_type,
242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const base::Callback<void(const FormStructure*,
243c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                const std::string&)>& callback)
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : AutofillDialogControllerImpl(contents,
2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     form_structure,
2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     source_url,
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     dialog_type,
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     callback),
249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        metric_logger_(metric_logger),
250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        test_wallet_client_(
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            Profile::FromBrowserContext(contents->GetBrowserContext())->
252c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                GetRequestContext(), this),
25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        dialog_type_(dialog_type) {}
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TestAutofillDialogController() {}
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual AutofillDialogView* CreateView() OVERRIDE {
257c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return new testing::NiceMock<TestAutofillDialogView>();
258c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
259c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void Init(content::BrowserContext* browser_context) {
261c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    test_manager_.Init(browser_context);
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestAutofillDialogView* GetView() {
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return static_cast<TestAutofillDialogView*>(view());
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestPersonalDataManager* GetTestingManager() {
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return &test_manager_;
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestWalletClient* GetTestingWalletClient() {
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return &test_wallet_client_;
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const GURL& open_tab_url() { return open_tab_url_; }
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual DialogType GetDialogType() const OVERRIDE {
27990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return dialog_type_;
28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
28190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
28290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; }
28390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SimulateSigninError() {
285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    OnWalletSigninError();
28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
28790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
28890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  MOCK_METHOD0(LoadRiskFingerprintData, void());
28990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
290868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  using AutofillDialogControllerImpl::IsEditingExistingData;
29190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual PersonalDataManager* GetManager() OVERRIDE {
2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return &test_manager_;
2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return &test_wallet_client_;
2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
301c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void OpenTabWithUrl(const GURL& url) OVERRIDE {
302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    open_tab_url_ = url;
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
305eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Whether the information input in this dialog will be securely transmitted
306eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // to the requesting site.
307eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool TransmissionWillBeSecure() const OVERRIDE {
308eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return true;
309eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
310eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // To specify our own metric logger.
313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return metric_logger_;
315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const AutofillMetrics& metric_logger_;
3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestPersonalDataManager test_manager_;
319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  testing::NiceMock<TestWalletClient> test_wallet_client_;
320c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL open_tab_url_;
32190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DialogType dialog_type_;
3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AutofillDialogControllerTest : public testing::Test {
327868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected:
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AutofillDialogControllerTest()
329868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    : form_structure_(NULL) {
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // testing::Test implementation:
3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUp() OVERRIDE {
3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    profile()->CreateRequestContext();
3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    test_web_contents_.reset(
3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        content::WebContentsTester::CreateTestWebContents(profile(), NULL));
3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
338868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetUpControllerWithFormData(DefaultFormData());
33990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
34090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
34190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void TearDown() OVERRIDE {
342868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if (controller_.get())
34390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller_->ViewClosed();
34490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
34590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
34690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) protected:
347868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormData DefaultFormData() {
348868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    FormData form_data;
349868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) {
350868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      FormFieldData field;
351868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      field.autocomplete_attribute = kFieldsFromPage[i];
352868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      form_data.fields.push_back(field);
353868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    }
354868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return form_data;
355868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
356868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
35790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void SetUpControllerWithFormData(const FormData& form_data) {
358868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if (controller_.get())
35990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller_->ViewClosed();
36090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    base::Callback<void(const FormStructure*, const std::string&)> callback =
362c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        base::Bind(&AutofillDialogControllerTest::FinishedCallback,
363c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                   base::Unretained(this));
36490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller_ = (new testing::NiceMock<TestAutofillDialogController>(
3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        test_web_contents_.get(),
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        form_data,
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        GURL(),
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        metric_logger_,
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
370c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        callback))->AsWeakPtr();
371c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->Init(profile());
3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    controller_->Show();
373c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->OnUserNameFetchSuccess(kFakeEmail);
3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
376c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void FillCreditCardInputs() {
377c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    DetailOutputMap cc_outputs;
378c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInputs& cc_inputs =
379c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        controller()->RequestedFieldsForSection(SECTION_CC);
380c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    for (size_t i = 0; i < cc_inputs.size(); ++i) {
381c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11");
382c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
383c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs);
384c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
385c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
386c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::vector<DialogNotification> NotificationsOfType(
387c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      DialogNotification::Type type) {
388c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    std::vector<DialogNotification> right_type;
389c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const std::vector<DialogNotification>& notifications =
390c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        controller()->CurrentNotifications();
391c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    for (size_t i = 0; i < notifications.size(); ++i) {
392c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      if (notifications[i].type() == type)
393c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        right_type.push_back(notifications[i]);
394c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
395c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return right_type;
396c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
397c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
398c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SwitchToAutofill() {
399c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->MenuModelForAccountChooser()->ActivatedAt(
400c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        TestAccountChooserModel::kAutofillItemId);
401c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
402c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
403c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SwitchToWallet() {
404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    controller_->MenuModelForAccountChooser()->ActivatedAt(
405c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        TestAccountChooserModel::kActiveWalletItemId);
406c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
407c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
408868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SimulateSigninError() {
409868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    controller_->SimulateSigninError();
410868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
411868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
41290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void UseBillingForShipping() {
41390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0);
41490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
41590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void ValidateCCNumber(DialogSection section,
4177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                        const std::string& cc_number,
4187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                        bool should_pass) {
4197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DetailOutputMap outputs;
4207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    const DetailInputs& inputs =
4217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->RequestedFieldsForSection(section);
4227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    SetOutputValue(inputs, &outputs, CREDIT_CARD_NUMBER, cc_number);
4247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    ValidityData validity_data =
4257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
4267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    EXPECT_EQ(should_pass ? 0U : 1U, validity_data.count(CREDIT_CARD_NUMBER));
4277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
4287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void SubmitWithWalletItems(scoped_ptr<wallet::WalletItems> wallet_items) {
430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    controller()->OnDidGetWalletItems(wallet_items.Pass());
431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    AcceptAndLoadFakeFingerprint();
432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void AcceptAndLoadFakeFingerprint() {
435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    controller()->OnAccept();
436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
438eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
439868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TestAutofillDialogController* controller() { return controller_.get(); }
4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestingProfile* profile() { return &profile_; }
4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const FormStructure* form_structure() { return form_structure_; }
444c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
446c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void FinishedCallback(const FormStructure* form_structure,
447c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                        const std::string& google_transaction_id) {
448c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    form_structure_ = form_structure;
449868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if (controller()->GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT)
450868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      EXPECT_TRUE(controller()->AutocheckoutIsRunning());
451c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
452c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
453868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Must be first member to ensure TestBrowserThreads outlive other objects.
454868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  content::TestBrowserThreadBundle thread_bundle_;
455868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
456c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN)
457c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   // http://crbug.com/227221
458c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   ui::ScopedOleInitializer ole_initializer_;
459c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
460c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestingProfile profile_;
4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The controller owns itself.
464c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::WeakPtr<TestAutofillDialogController> controller_;
4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<content::WebContents> test_web_contents_;
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Must outlive the controller.
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AutofillMetrics metric_logger_;
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
471c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returned when the dialog closes successfully.
472c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const FormStructure* form_structure_;
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This test makes sure nothing falls over when fields are being validity-
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// checked.
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ValidityCheck) {
480868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
481868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DialogSection section = static_cast<DialogSection>(i);
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const DetailInputs& shipping_inputs =
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        controller()->RequestedFieldsForSection(section);
4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (DetailInputs::const_iterator iter = shipping_inputs.begin();
4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         iter != shipping_inputs.end(); ++iter) {
4867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputValidityMessage(section, iter->type, string16());
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
49190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Test for phone number validation.
49290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) {
49390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Construct DetailOutputMap from existing data.
49490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToAutofill();
49590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
49690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
49790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
49890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
499868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (size_t i = 0; i < 2; ++i) {
500868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    AutofillFieldType phone = i == 0 ? PHONE_HOME_WHOLE_NUMBER :
501868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                       PHONE_BILLING_WHOLE_NUMBER;
502868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    AutofillFieldType address = i == 0 ? ADDRESS_HOME_COUNTRY :
503868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         ADDRESS_BILLING_COUNTRY;
504868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DialogSection section = i == 0 ? SECTION_SHIPPING : SECTION_BILLING;
50590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
506868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    controller()->EditClickedForSection(section);
50790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
508868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DetailOutputMap outputs;
509868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const DetailInputs& inputs =
510868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        controller()->RequestedFieldsForSection(section);
511868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Make sure country is United States.
512868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetOutputValue(inputs, &outputs, address, "United States");
513868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
514868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Existing data should have no errors.
515868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ValidityData validity_data =
5167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
517868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
518868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
519868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an empty phone number with VALIDATE_FINAL.
520868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetOutputValue( inputs, &outputs, phone, "");
5217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_FINAL);
523868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
524868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
525868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an empty phone number with VALIDATE_EDIT.
5267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
528868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
529868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
530868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an invalid phone number.
531868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, "ABC");
5327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
534868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
535868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
536868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input a local phone number.
537868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, "2155546699");
5387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
540868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
541868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
542868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an invalid local phone number.
543868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, "215554669");
5447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
546868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
547868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
548868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an international phone number.
549868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, "+33 892 70 12 39");
5507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
552868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(0U, validity_data.count(phone));
553868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
554868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Input an invalid international phone number.
555868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetOutputValue(inputs, &outputs, phone, "+112333 892 70 12 39");
5567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    validity_data =
5577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        controller()->InputsAreValid(section, outputs, VALIDATE_EDIT);
558868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_EQ(1U, validity_data.count(phone));
559868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
56090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
56190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
56290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, CardHolderNameValidation) {
56390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Construct DetailOutputMap from AutofillProfile data.
56490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToAutofill();
56590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
56690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DetailOutputMap outputs;
56790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInputs& inputs =
56890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC);
56990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
57090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input an empty card holder name with VALIDATE_FINAL.
57190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_NAME, "");
57290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ValidityData validity_data =
5737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC, outputs, VALIDATE_FINAL);
57490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
57590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
57690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input an empty card holder name with VALIDATE_EDIT.
57790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
5787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC, outputs, VALIDATE_EDIT);
57990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
58090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
58190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input a non-empty card holder name.
58290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_NAME, "Bob");
58390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
5847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC, outputs, VALIDATE_FINAL);
58590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
58690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
58790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Switch to Wallet which only considers names with with at least two names to
58890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // be valid.
58990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToWallet();
59090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
59190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Setup some wallet state.
59290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
59390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
59490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
59590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DetailOutputMap wallet_outputs;
59690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInputs& wallet_inputs =
59790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
59890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
59990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input an empty card holder name with VALIDATE_FINAL. Data source should not
60090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // change this behavior.
60190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME, "");
60290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
6047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
60590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
60690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
60790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input an empty card holder name with VALIDATE_EDIT. Data source should not
60890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // change this behavior.
60990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
6117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_EDIT);
61290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
61390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
61490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input a one name card holder name. Wallet does not currently support this.
61590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME, "Bob");
61690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
6187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
61990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
62090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
62190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input a two name card holder name.
62290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
62390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                 "Bob Barker");
62490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
6267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
62790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
62890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
62990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input a more than two name card holder name.
63090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
63190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                 "John Jacob Jingleheimer Schmidt");
63290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
6347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
63590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
63690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
63790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Input a card holder name with lots of crazy whitespace.
63890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
63990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                 "     \\n\\r John \\n  Jacob Jingleheimer \\t Schmidt  ");
64090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  validity_data =
6417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(
6427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL);
64390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
64490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
64590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) {
6477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Construct DetailOutputMap from AutofillProfile data.
6487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  SwitchToAutofill();
6497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Should accept AMEX, Visa, Master and Discover.
6517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberVisa, true);
6527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberMaster, true);
6537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberDiscover, true);
6547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberAmex, true);
6557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberIncomplete, false);
6577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC, kTestCCNumberInvalid, false);
6587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Switch to Wallet which will not accept AMEX.
6607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  SwitchToWallet();
6617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Setup some wallet state.
6637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
6647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Should accept Visa, Master and Discover, but not AMEX.
6667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberVisa, true);
6677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberMaster, true);
6687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberDiscover, true);
6697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberAmex, false);
6717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberIncomplete, false);
6727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberInvalid, false);
6737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
6747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfiles) {
6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ui::MenuModel* shipping_model =
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Since the PersonalDataManager is empty, this should only have the
679c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "use billing", "add new" and "manage" menu items.
68090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
681c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(3, shipping_model->GetItemCount());
682c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // On the other hand, the other models should be NULL when there's no
683c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // suggestion.
684c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
685c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
686c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
68890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3);
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Empty profiles are ignored.
691c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AutofillProfile empty_profile(base::GenerateGUID(), kSettingsOrigin);
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe"));
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&empty_profile);
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
69590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
696c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(3, shipping_model->GetItemCount());
697c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
69990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // An otherwise full but unverified profile should be ignored.
700c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AutofillProfile full_profile(test::GetFullProfile());
70190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_profile.set_origin("https://www.example.com");
7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
70590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
70690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(3, shipping_model->GetItemCount());
70790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL));
70890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
70990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // A full, verified profile should be picked up.
71090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile verified_profile(test::GetVerifiedProfile());
71190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
71290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
71390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
71490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(shipping_model);
715c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(4, shipping_model->GetItemCount());
716c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL));
7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
71990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Makes sure that the choice of which Autofill profile to use for each section
72090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// is sticky.
72190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) {
72290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetFullProfile());
72390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_profile.set_origin(kSettingsOrigin);
72490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
72590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetFullProfile2());
72690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_profile2.set_origin(kSettingsOrigin);
72790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
72890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
72990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Until a selection has been made, the default shipping suggestion is the
73090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // first one (after "use billing").
73190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* shipping_model = static_cast<SuggestionsMenuModel*>(
73290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING));
73390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1, shipping_model->checked_item());
73490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
73590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for (int i = 2; i >= 0; --i) {
73690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    shipping_model = static_cast<SuggestionsMenuModel*>(
73790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        controller()->MenuModelForSection(SECTION_SHIPPING));
73890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    shipping_model->ExecuteCommand(i, 0);
73990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    FillCreditCardInputs();
74090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->OnAccept();
74190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
74290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    TearDown();
74390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    SetUp();
74490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->GetTestingManager()->AddTestingProfile(&full_profile);
74590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
74690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    shipping_model = static_cast<SuggestionsMenuModel*>(
74790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        controller()->MenuModelForSection(SECTION_SHIPPING));
74890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    EXPECT_EQ(i, shipping_model->checked_item());
74990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
75090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
75190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Try again, but don't add the default profile to the PDM. The dialog
75290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // should fall back to the first profile.
75390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model->ExecuteCommand(2, 0);
75490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
75590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
75690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  TearDown();
75790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetUp();
75890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
75990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model = static_cast<SuggestionsMenuModel*>(
76090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING));
76190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1, shipping_model->checked_item());
76290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
76390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) {
7652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
766c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ui::MenuModel* email_model =
767c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL);
768c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(email_model);
7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Set up some variant data.
77190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> names;
7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  names.push_back(ASCIIToUTF16("John Doe"));
7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  names.push_back(ASCIIToUTF16("Jane Doe"));
7752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names);
776c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const string16 kEmail1 = ASCIIToUTF16(kFakeEmail);
7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const string16 kEmail2 = ASCIIToUTF16("admin@example.com");
7782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> emails;
7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  emails.push_back(kEmail1);
7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  emails.push_back(kEmail2);
7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails);
7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Respect variants for the email address field only.
7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ui::MenuModel* shipping_model =
7862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
787c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(4, shipping_model->GetItemCount());
788c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  email_model = controller()->MenuModelForSection(SECTION_EMAIL);
789c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(!!email_model);
790c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(4, email_model->GetItemCount());
7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
79290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The first one is the default.
79390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* email_suggestions = static_cast<SuggestionsMenuModel*>(
79490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL));
79590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0, email_suggestions->checked_item());
79690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  email_model->ActivatedAt(0);
798c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail1,
799c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            controller()->SuggestionStateForSection(SECTION_EMAIL).text);
8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  email_model->ActivatedAt(1);
801c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail2,
802c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            controller()->SuggestionStateForSection(SECTION_EMAIL).text);
8032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_EMAIL);
8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const DetailInputs& inputs =
8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
807c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail2, inputs[0].initial_value);
80890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
80990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The choice of variant is persisted across runs of the dialog.
81090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  email_model->ActivatedAt(0);
81190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  email_model->ActivatedAt(1);
81290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
81390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
81490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
81590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  TearDown();
81690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetUp();
81790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
81890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  email_suggestions = static_cast<SuggestionsMenuModel*>(
81990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL));
82090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1, email_suggestions->checked_item());
82190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
82290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
823eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, SuggestValidEmail) {
8247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  AutofillProfile profile(test::GetVerifiedProfile());
8257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  const string16 kValidEmail = ASCIIToUTF16(kFakeEmail);
8267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  profile.SetRawInfo(EMAIL_ADDRESS, kValidEmail);
8277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&profile);
8287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
8297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(0);
8307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_EQ(kValidEmail,
8317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            controller()->SuggestionStateForSection(SECTION_EMAIL).text);
8327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
8337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
834eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidEmail) {
8357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  AutofillProfile profile(test::GetVerifiedProfile());
8367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(".!#$%&'*+/=?^_`-@-.."));
8377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&profile);
838eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
839eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->MenuModelForSection(SECTION_EMAIL));
840eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
8417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
842eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromIncompleteProfile) {
843eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile profile(test::GetVerifiedProfile());
844eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail));
845eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(ADDRESS_HOME_STATE, base::string16());
846eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&profile);
847eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
848eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->MenuModelForSection(SECTION_EMAIL));
849eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
850eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
851eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromInvalidProfile) {
852eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile profile(test::GetVerifiedProfile());
853eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail));
854eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C"));
855eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&profile);
856eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(static_cast<ui::MenuModel*>(NULL),
857eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->MenuModelForSection(SECTION_EMAIL));
858eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
859eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
860eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, SuggestValidAddress) {
861eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile full_profile(test::GetVerifiedProfile());
862eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  full_profile.set_origin(kSettingsOrigin);
863eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
864eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(
865eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
866eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
867eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
868eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidAddress) {
869eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile full_profile(test::GetVerifiedProfile());
870eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  full_profile.set_origin(kSettingsOrigin);
871eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  full_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C"));
872eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
873eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(
874eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
8757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
8767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
87790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillCreditCards) {
87890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Since the PersonalDataManager is empty, this should only have the
87990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // default menu items.
88090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
88190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
88290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3);
88390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
88490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Empty cards are ignored.
88590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard empty_card(base::GenerateGUID(), kSettingsOrigin);
88690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  empty_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John Doe"));
88790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&empty_card);
88890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
88990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
89090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // An otherwise full but unverified card should be ignored.
89190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard full_card(test::GetCreditCard());
89290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_card.set_origin("https://www.example.com");
89390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&full_card);
89490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
89590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
89690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // A full, verified card should be picked up.
89790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard verified_card(test::GetCreditCard());
89890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  verified_card.set_origin(kSettingsOrigin);
89990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&verified_card);
90090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* credit_card_model =
90190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC);
90290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(credit_card_model);
90390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(3, credit_card_model->GetItemCount());
9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
906b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test selecting a shipping address different from billing as address.
907b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) {
90890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
90990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetVerifiedProfile2());
91090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard credit_card(test::GetVerifiedCreditCard());
911b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
912b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
913b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
914b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ui::MenuModel* shipping_model =
915b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
916b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  shipping_model->ActivatedAt(2);
917b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
918b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnAccept();
919868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_EQ(20U, form_structure()->field_count());
920868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(9)->type());
921868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(16)->type());
922868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_state = form_structure()->field(9)->value;
923868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_state = form_structure()->field(16)->value;
924868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_state.empty());
925868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_state.empty());
926868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_NE(billing_state, shipping_state);
927868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
928868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(CREDIT_CARD_NAME, form_structure()->field(1)->type());
929868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 cc_name = form_structure()->field(1)->value;
930868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(NAME_FULL, form_structure()->field(6)->type());
931868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_name = form_structure()->field(6)->value;
932868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(NAME_FULL, form_structure()->field(13)->type());
933868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_name = form_structure()->field(13)->value;
934868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
935868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(cc_name.empty());
936868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_name.empty());
937868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_name.empty());
938868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Billing name should always be the same as cardholder name.
939868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // TODO(estade): this currently fails. http://crbug.com/246417
940868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // EXPECT_EQ(cc_name, billing_name);
941868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_NE(cc_name, shipping_name);
942b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
943b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
944b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test selecting UseBillingForShipping.
945b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) {
94690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
94790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetVerifiedProfile2());
94890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard credit_card(test::GetVerifiedCreditCard());
949b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
950b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
951b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
952b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
953b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Test after setting use billing for shipping.
95490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UseBillingForShipping();
955b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
956b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnAccept();
957868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_EQ(20U, form_structure()->field_count());
958868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(9)->type());
959868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(16)->type());
960868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_state = form_structure()->field(9)->value;
961868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_state = form_structure()->field(16)->value;
962868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_state.empty());
963868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_state.empty());
964868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(billing_state, shipping_state);
965868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
966868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(CREDIT_CARD_NAME, form_structure()->field(1)->type());
967868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 cc_name = form_structure()->field(1)->value;
968868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(NAME_FULL, form_structure()->field(6)->type());
969868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 billing_name = form_structure()->field(6)->value;
970868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(NAME_FULL, form_structure()->field(13)->type());
971868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 shipping_name = form_structure()->field(13)->value;
972868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
973868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(cc_name.empty());
974868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(billing_name.empty());
975868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(shipping_name.empty());
976868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(cc_name, billing_name);
977868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(cc_name, shipping_name);
978b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
979b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
98090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that shipping and billing telephone fields are supported, and filled
98190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// in by their respective profiles. http://crbug.com/244515
982868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) {
98390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FormFieldData shipping_tel;
98490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_tel.autocomplete_attribute = "shipping tel";
98590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FormFieldData billing_tel;
98690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  billing_tel.autocomplete_attribute = "billing tel";
98790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
98890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FormData form_data;
98990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  form_data.fields.push_back(shipping_tel);
99090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  form_data.fields.push_back(billing_tel);
99190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SetUpControllerWithFormData(form_data);
99290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
99390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The profile that will be chosen for the shipping section.
99490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile shipping_profile(test::GetVerifiedProfile());
99590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The profile that will be chosen for the billing section.
99690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile billing_profile(test::GetVerifiedProfile2());
99790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard credit_card(test::GetVerifiedCreditCard());
99890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&shipping_profile);
99990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&billing_profile);
100090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
100190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* billing_model =
100290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_BILLING);
100390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  billing_model->ActivatedAt(1);
100490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
100590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
100690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_EQ(2U, form_structure()->field_count());
100790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, form_structure()->field(0)->type());
1008868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(PHONE_BILLING_WHOLE_NUMBER, form_structure()->field(1)->type());
100990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER),
101090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            form_structure()->field(0)->value);
1011868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(billing_profile.GetRawInfo(PHONE_BILLING_WHOLE_NUMBER),
101290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            form_structure()->field(1)->value);
101390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_NE(form_structure()->field(1)->value,
101490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            form_structure()->field(0)->value);
101590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
101690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
10172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
10182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
10192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              AcceptLegalDocuments(_, _, _)).Times(1);
10202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
10212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              GetFullWallet(_)).Times(1);
102290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
10232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1024eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems();
10252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
10262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1027c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
102890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidAcceptLegalDocuments();
102990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
10302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1032c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Makes sure the default object IDs are respected.
1033c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletDefaultItems) {
1034c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1035c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
1036c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
1037c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1038c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
10392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1040c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1041c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1042c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1043c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
1044c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
1045c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1046c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1047c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "add", "manage", and 4 suggestions.
1048c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(6,
1049c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
1050c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
1051c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      IsItemCheckedAt(2));
1052868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(controller()->IsEditingExistingData(SECTION_CC_BILLING));
1053c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "use billing", "add", "manage", and 5 suggestions.
1054c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(8,
1055c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
1056c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_SHIPPING)->
1057c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      IsItemCheckedAt(4));
1058868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(controller()->IsEditingExistingData(SECTION_SHIPPING));
105990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
106090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
106190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that invalid and AMEX default instruments are ignored.
106290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SelectInstrument) {
106390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
106490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Tests if default instrument is invalid, then, the first valid instrument is
106590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // selected instead of the default instrument.
106690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
106790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
106890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid());
106990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
107090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
107190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
107290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // 4 suggestions and "add", "manage".
107390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(6,
107490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
107590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
107690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      IsItemCheckedAt(0));
107790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
107890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Tests if default instrument is AMEX, then, the first valid instrument is
107990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // selected instead of the default instrument.
108090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items = wallet::GetTestWalletItems();
108190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
108290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
108390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex());
108490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
108590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
108690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
108790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // 4 suggestions and "add", "manage".
108890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(6,
108990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
109090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
109190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      IsItemCheckedAt(0));
109290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
109390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Tests if only have AMEX and invalid instrument, then "add" is selected.
109490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items = wallet::GetTestWalletItems();
109590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid());
109690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex());
109790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
109890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
109990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // 2 suggestions and "add", "manage".
110090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(4,
110190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
110290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "add"
110390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)->
110490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      IsItemCheckedAt(2));
1105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveAddress) {
11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
11092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
11102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              SaveAddress(_, _)).Times(1);
11112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
11132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
11142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
111590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // If there is no shipping address in wallet, it will default to
111690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "same-as-billing" instead of "add-new-item". "same-as-billing" is covered
111790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // by the following tests. The last item in the menu is "add-new-item".
111890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* shipping_model =
111990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING);
112090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_model->ActivatedAt(shipping_model->GetItemCount() - 1);
1121eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
11222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrument) {
11252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
11262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
11272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              SaveInstrument(_, _, _)).Times(1);
11282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
11302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
1131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(wallet_items.Pass());
11322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
113490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) {
113590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
113690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
113790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)              SaveInstrument(_, _, _)).Times(1);
113890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
113990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
114090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
114190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid());
1142eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(wallet_items.Pass());
114390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
114490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
11452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) {
11462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
11472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              SaveInstrumentAndAddress(_, _, _, _)).Times(1);
11482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
1150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
11512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1153a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Tests that editing an address (in wallet mode0 and submitting the dialog
1154a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// should update the existing address on the server via WalletClient.
1155a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateAddress) {
1156a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1157a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)              UpdateAddress(_, _)).Times(1);
1158a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1160a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1161a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_SHIPPING);
1162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1163a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1164a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1165a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Tests that editing an instrument (CC + address) in wallet mode updates an
1166a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// existing instrument on the server via WalletClient.
1167a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateInstrument) {
1168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1169a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1170a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_CC_BILLING);
1171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1172a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1173a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_TRUE(
1174a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      controller()->GetTestingWalletClient()->updated_billing_address());
1175a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1176a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1177a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that a user is able to edit their instrument and add a new address in
1178a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// the same submission.
1179a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateInstrumentSaveAddress) {
1180a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1181a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)              SaveAddress(_, _)).Times(1);
1182a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1183a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1184a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1185a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1186a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1187a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_CC_BILLING);
1188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1189a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1190a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_TRUE(
1191a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      controller()->GetTestingWalletClient()->updated_billing_address());
1192a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1193a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1194a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that saving a new instrument and editing an address works.
1195a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentUpdateAddress) {
1196a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1197a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)              SaveInstrument(_, _, _)).Times(1);
1198a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1199a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)              UpdateAddress(_, _)).Times(1);
1200a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1201a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1202a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
120390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1204a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1205a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1206a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_SHIPPING);
1207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1208a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1209a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1210a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)MATCHER(UsesLocalBillingAddress, "uses the local billing address") {
1211a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return arg.address_line_1() == ASCIIToUTF16(kEditedBillingAddress);
1212a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1213a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
121490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that when using billing address for shipping, and there is no exact
121590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// matched shipping address, then a shipping address should be added.
121690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingForShipping) {
121790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
121890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)              SaveAddress(_, _)).Times(1);
121990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
122190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Select "Same as billing" in the address menu.
122290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UseBillingForShipping();
122390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
122590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
122690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
122790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that when using billing address for shipping, and there is an exact
122890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// matched shipping address, then a shipping address should not be added.
122990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) {
123090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
123190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)              SaveAddress(_, _)).Times(0);
123290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
123390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
123490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument =
123590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      wallet::GetTestMaskedInstrument();
123690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Copy billing address as shipping address, and assign an id to it.
123790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::Address> shipping_address(
123890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      new wallet::Address(instrument->address()));
123990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping_address->set_object_id("shipping_address_id");
124090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(shipping_address.Pass());
124190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(instrument.Pass());
124290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
124390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
124490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
124590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Select "Same as billing" in the address menu.
124690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UseBillingForShipping();
124790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1248eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
124990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
125090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
125190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that adding new instrument and also using billing address for shipping,
125290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// then a shipping address should not be added.
125390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingForShippingNewInstrument) {
125490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
125590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)              SaveInstrumentAndAddress(_, _, _, _)).Times(1);
125690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
125790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
125890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
125990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
126090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
126190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Select "Same as billing" in the address menu.
126290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UseBillingForShipping();
126390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
126590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
126690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1267a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that the local view contents is used when saving a new instrument and
1268a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// the user has selected "Same as billing".
1269a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) {
1270a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1271a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1272a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1273a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1274a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_CC_BILLING);
1275a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnAccept();
1276a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1277a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DetailOutputMap outputs;
1278a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const DetailInputs& inputs =
1279a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
1280a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1281a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const DetailInput& input = inputs[i];
1282a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    outputs[&input] = input.type == ADDRESS_BILLING_LINE1 ?
1283a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        ASCIIToUTF16(kEditedBillingAddress) : input.initial_value;
1284a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1285a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs);
1286a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1287a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1288a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)              SaveAddress(UsesLocalBillingAddress(), _)).Times(1);
1289eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1290a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1291a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_TRUE(
1292a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      controller()->GetTestingWalletClient()->updated_billing_address());
1293a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1294a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, CancelNoSave) {
1296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              SaveInstrumentAndAddress(_, _, _, _)).Times(0);
12982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
13002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
13022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  controller()->OnCancel();
13032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
13042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1305c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Checks that clicking the Manage menu item opens a new tab with a different
1306c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// URL for Wallet and Autofill.
1307c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ManageItem) {
130890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1309c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  full_profile.set_origin(kSettingsOrigin);
1310c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
1311c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
131490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* shipping = static_cast<SuggestionsMenuModel*>(
1315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_SHIPPING));
131690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  shipping->ExecuteCommand(shipping->GetItemCount() - 1, 0);
1317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL autofill_manage_url = controller()->open_tab_url();
1318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("chrome", autofill_manage_url.scheme());
1319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1320c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
132190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
132290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
132390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1324c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
132590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->SuggestionItemSelected(shipping, shipping->GetItemCount() - 1);
132690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GURL wallet_manage_addresses_url = controller()->open_tab_url();
132790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ("https", wallet_manage_addresses_url.scheme());
132890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
132990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SuggestionsMenuModel* billing = static_cast<SuggestionsMenuModel*>(
133090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_CC_BILLING));
133190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->SuggestionItemSelected(billing, billing->GetItemCount() - 1);
133290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GURL wallet_manage_instruments_url = controller()->open_tab_url();
133390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ("https", wallet_manage_instruments_url.scheme());
133490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
133590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_NE(autofill_manage_url, wallet_manage_instruments_url);
133690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_NE(wallet_manage_instruments_url, wallet_manage_addresses_url);
1337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1338c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1339c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, EditClickedCancelled) {
1340c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
1341c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
134290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const string16 kEmail = ASCIIToUTF16("first@johndoe.com");
1344c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail);
1345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ui::MenuModel* email_model =
1348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->MenuModelForSection(SECTION_EMAIL);
1349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(3, email_model->GetItemCount());
1350c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1351c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // When unedited, the initial_value should be empty.
1352c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  email_model->ActivatedAt(0);
1353c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs0 =
1354c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
1355c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(string16(), inputs0[0].initial_value);
1356c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail,
1357c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            controller()->SuggestionStateForSection(SECTION_EMAIL).text);
1358c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1359c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // When edited, the initial_value should contain the value.
1360c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_EMAIL);
1361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs1 =
1362c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
1363c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail, inputs1[0].initial_value);
1364c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(string16(),
1365c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            controller()->SuggestionStateForSection(SECTION_EMAIL).text);
1366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1367c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // When edit is cancelled, the initial_value should be empty.
1368c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditCancelledForSection(SECTION_EMAIL);
1369c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs2 =
1370c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
1371c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(kEmail,
1372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            controller()->SuggestionStateForSection(SECTION_EMAIL).text);
1373c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(string16(), inputs2[0].initial_value);
1374c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1375c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1376c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that editing an autofill profile and then submitting works.
1377c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, EditAutofillProfile) {
1378c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1379c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1380c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
1381c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
138290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1383c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1384c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_SHIPPING);
1385c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1386c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DetailOutputMap outputs;
1387c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs =
1388c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_SHIPPING);
1389c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1390c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = inputs[i];
1391c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    outputs[&input] = input.type == NAME_FULL ? ASCIIToUTF16("Edited Name") :
1392c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                input.initial_value;
1393c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1394c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs);
1395c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1396c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // We also have to simulate CC inputs to keep the controller happy.
1397c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  FillCreditCardInputs();
1398c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1399c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1400c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const AutofillProfile& edited_profile =
1401c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->GetTestingManager()->imported_profile();
1402c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1403c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = inputs[i];
1405c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    EXPECT_EQ(input.type == NAME_FULL ? ASCIIToUTF16("Edited Name") :
1406c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                        input.initial_value,
1407c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              edited_profile.GetInfo(input.type, "en-US"));
1408c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1409c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1410c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1411c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that adding an autofill profile and then submitting works.
1412c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AddAutofillProfile) {
1413c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
1414c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
141590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1416c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1417c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1418c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING);
1419c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Activate the "Add billing address" menu item.
1420c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  model->ActivatedAt(model->GetItemCount() - 2);
1421c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1422c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Fill in the inputs from the profile.
1423c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DetailOutputMap outputs;
1424c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& inputs =
1425c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_BILLING);
142690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile2(test::GetVerifiedProfile2());
1427c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < inputs.size(); ++i) {
1428c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = inputs[i];
1429c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    outputs[&input] = full_profile2.GetInfo(input.type, "en-US");
1430c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1431c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_BILLING, outputs);
1432c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1433c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Fill in some CC info. The name field will be used to fill in the billing
1434c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // address name in the newly minted AutofillProfile.
1435c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DetailOutputMap cc_outputs;
1436c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& cc_inputs =
1437c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC);
1438c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < cc_inputs.size(); ++i) {
1439c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NAME ?
1440c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        ASCIIToUTF16("Bill Money") : ASCIIToUTF16("111");
1441c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1442c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs);
1443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1444c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1445c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const AutofillProfile& added_profile =
1446c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->GetTestingManager()->imported_profile();
1447c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1448c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const DetailInputs& shipping_inputs =
1449c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_SHIPPING);
1450c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < shipping_inputs.size(); ++i) {
1451c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const DetailInput& input = shipping_inputs[i];
1452c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    string16 expected = input.type == NAME_FULL ?
1453c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        ASCIIToUTF16("Bill Money") :
1454c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        full_profile2.GetInfo(input.type, "en-US");
1455c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    EXPECT_EQ(expected, added_profile.GetInfo(input.type, "en-US"));
1456c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
145790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
145890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Also, the currently selected email address should get added to the new
145990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // profile.
146090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  string16 original_email = full_profile.GetInfo(EMAIL_ADDRESS, "en-US");
146190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(original_email.empty());
146290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(original_email,
146390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            added_profile.GetInfo(EMAIL_ADDRESS, "en-US"));
146490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
146590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
146690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Makes sure that a newly added email address gets added to an existing profile
146790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// (as opposed to creating its own profile). http://crbug.com/240926
146890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AddEmail) {
146990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
147090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
147190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
147290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
147390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
147490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::MenuModel* model = controller()->MenuModelForSection(SECTION_EMAIL);
147590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_TRUE(model);
147690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Activate the "Add email address" menu item.
147790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  model->ActivatedAt(model->GetItemCount() - 2);
147890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
147990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Fill in the inputs from the profile.
148090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DetailOutputMap outputs;
148190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInputs& inputs =
148290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_EMAIL);
148390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const DetailInput& input = inputs[0];
148490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  string16 new_email = ASCIIToUTF16("addemailtest@example.com");
148590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  outputs[&input] = new_email;
148690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->GetView()->SetUserInput(SECTION_EMAIL, outputs);
148790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
148890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
148990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
149090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::vector<base::string16> email_values;
149190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  full_profile.GetMultiInfo(EMAIL_ADDRESS, "en-US", &email_values);
149290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ASSERT_EQ(2U, email_values.size());
149390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(new_email, email_values[1]);
1494c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1495c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1496c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, VerifyCvv) {
1497c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1498c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1499c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1500c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              AuthenticateInstrument(_, _, _)).Times(1);
1501c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1502eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1503c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1504c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty());
1505c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING));
1506c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
1507c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
15087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1509c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1510c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SuggestionState suggestion_state =
1511c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->SuggestionStateForSection(SECTION_CC_BILLING);
1512c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(suggestion_state.extra_text.empty());
1513c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1514868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv"));
1515c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1516c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(
1517c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty());
1518c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
1519c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
1520c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1521c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  suggestion_state =
1522c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      controller()->SuggestionStateForSection(SECTION_CC_BILLING);
1523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(suggestion_state.extra_text.empty());
1524c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING));
1525c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1526c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1527c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1529c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1531c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) {
1533c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1534c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1535c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1536eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1537c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1538c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
15397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1541c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
1542c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1543c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1544c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1545c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1546c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1547c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(dbeam): disallow changing accounts instead and remove this test.
1548c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) {
1549c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1550c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1551c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1552eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1553c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1554c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
15557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1556c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1557c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
1558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1560c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) {
1565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1566c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1567c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1568eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1569868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv"));
1570c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1572c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1573c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
1575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1576c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1577c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1578c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1579c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1580c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(dbeam): disallow changing accounts instead and remove this test.
1581c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) {
1582c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
1583c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              GetFullWallet(_)).Times(1);
1584c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1585eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
1586868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv"));
1587c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1588c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1589c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1591c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
1592c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1596c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1597c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1598a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Simulates receiving an INVALID_FORM_FIELD required action while processing a
1599a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// |WalletClientDelegate::OnDid{Save,Update}*()| call. This can happen if Online
1600a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Wallet's server validation differs from Chrome's local validation.
16017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletServerSideValidation) {
1602a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1603a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1604a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1605a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  controller()->OnAccept();
1606a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1607a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::vector<wallet::RequiredAction> required_actions;
1608a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  required_actions.push_back(wallet::INVALID_FORM_FIELD);
16097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
16107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::vector<wallet::FormFieldError> form_errors;
16117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  form_errors.push_back(
16127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      wallet::FormFieldError(wallet::FormFieldError::INVALID_POSTAL_CODE,
16137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                             wallet::FormFieldError::SHIPPING_ADDRESS));
16147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
16157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1);
16167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnDidSaveAddress(std::string(), required_actions, form_errors);
16177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
16187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
16197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Simulates receiving unrecoverable Wallet server validation errors.
16207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletServerSideValidationUnrecoverable) {
16217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
16227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
16237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
16247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnAccept();
16257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
16267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::vector<wallet::RequiredAction> required_actions;
16277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  required_actions.push_back(wallet::INVALID_FORM_FIELD);
16287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
16297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::vector<wallet::FormFieldError> form_errors;
16307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  form_errors.push_back(
16317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      wallet::FormFieldError(wallet::FormFieldError::UNKNOWN_ERROR,
16327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                             wallet::FormFieldError::UNKNOWN_LOCATION));
16337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
16347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  controller()->OnDidSaveAddress(std::string(), required_actions, form_errors);
1635a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1636a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1637a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
1638a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1639a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1640868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Test Wallet banners are show in the right situations. These banners explain
1641868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// where Chrome got the user's data (i.e. "Got details from Wallet") or promote
1642868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// saving details into Wallet (i.e. "[x] Save details to Wallet").
1643868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletBanners) {
1644eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CommandLine* command_line = CommandLine::ForCurrentProcess();
1645eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  command_line->AppendSwitch(switches::kWalletServiceUseProd);
1646868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PrefService* prefs = controller()->profile()->GetPrefs();
1647868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet));
1648868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1649868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1650868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1651868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1652868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1653868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1654868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Sign in a user with a completed account.
1655eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1656c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1657868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Full account; should show "Details from Wallet" message.
1658c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1659c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1660868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1661868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1662c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1663868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Full account; no "[x] Save details in Wallet" option should show.
1664c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1665868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1666868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1667868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1668868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1669c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1670868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
1671868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // |controller()| has already been initialized. Test that should not take
1672868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // effect until the next call of |SetUpControllerWithFormData()|.
1673868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, true);
1674c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1675868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Sign in a user with a incomplete account.
1676eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1677c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1678c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1679c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1680868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Partial account; no "Details from Wallet" message should show, but a
1681868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // "[x] Save details in Wallet" should.
1682868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1683868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1684868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1685868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1686c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1687868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Once the usage confirmation banner is shown once, it keeps showing even if
1688868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // the user switches to Autofill data.
1689c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1690868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1691868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1692868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1693868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1694c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1695868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // A Wallet error should kill any Wallet promos.
1696868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
1697c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1698868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
1699868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_ERROR).size());
1700868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1701868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1702868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1703868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1704c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1705868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
1706868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // |controller()| is error free and thinks the user has already paid w/Wallet.
1707c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1708868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // User has already paid with wallet. Don't show promos.
1709868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1710868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1711868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1712868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1713868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1714eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1715c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1716868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1717868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1718868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1719868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1720868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1721868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items = wallet::GetTestWalletItems();
1722868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1723868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1724868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1725868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SwitchToAutofill();
1726868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1727868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::EXPLANATORY_MESSAGE).size());
1728868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
1729868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1730c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1731c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
173290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, OnAutocheckoutError) {
173390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SwitchToAutofill();
173490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
173590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
173690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // We also have to simulate CC inputs to keep the controller happy.
173790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FillCreditCardInputs();
173890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
173990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
174090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAutocheckoutError();
174190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
174290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
174390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
174490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
174590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_SUCCESS).size());
174690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
174790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_ERROR).size());
174890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
174990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
175090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, OnAutocheckoutSuccess) {
1751eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CommandLine* command_line = CommandLine::ForCurrentProcess();
1752eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  command_line->AppendSwitch(switches::kWalletServiceUseProd);
175390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
175490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1755eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Sign in a user with a completed account.
1756eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
1757eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1758eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Full account; should show "Details from Wallet" message.
1759eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(1U, NotificationsOfType(
1760eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::EXPLANATORY_MESSAGE).size());
1761eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0U, NotificationsOfType(
1762eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::WALLET_USAGE_CONFIRMATION).size());
1763eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1764eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AcceptAndLoadFakeFingerprint();
1765eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
1766eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1767eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0U, NotificationsOfType(
1768eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::EXPLANATORY_MESSAGE).size());
176990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
177090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAutocheckoutSuccess();
177190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
177290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
177390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
177490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
177590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_SUCCESS).size());
177690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
177790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      DialogNotification::AUTOCHECKOUT_ERROR).size());
1778eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0U, NotificationsOfType(
1779eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      DialogNotification::EXPLANATORY_MESSAGE).size());
178090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
178190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1782c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ViewCancelDoesntSetPref) {
1783c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath(
1784c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1785c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1786c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1787c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1788c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnCancel();
1789c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->ViewClosed();
1790c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1791c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath(
1792c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1793c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1794c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1795868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, SubmitWithSigninErrorDoesntSetPref) {
1796868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath(
1797868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1798868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1799868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SimulateSigninError();
1800868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FillCreditCardInputs();
1801868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
1802868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1803868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath(
1804868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1805868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
1806868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1807c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) {
1808c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath(
1809c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1810c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1811c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1812868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FillCreditCardInputs();
1813868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
1814c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1815868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
1816868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1817868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
1818868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1819868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1820868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Try again with a signin error (just leaves the pref alone).
1821868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
1822868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1823868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Setting up the controller again should not change the pref.
1824868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
1825868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1826868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
1827868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1828868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1829868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SimulateSigninError();
1830c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  FillCreditCardInputs();
1831868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
1832868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
1833868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1834868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(
1835868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1836868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1837868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Succesfully choosing wallet does set the pref.
1838868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(DefaultFormData());
1839c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1840868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SwitchToWallet();
1841868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1842868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1843868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1844c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1845868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
1846c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1847c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(
1848c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1849868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(
1850c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ::prefs::kAutofillDialogPayWithoutWallet));
1851c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1852c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1853c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, HideWalletEmail) {
1854c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToAutofill();
1855c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1856c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Email section should be showing when using Autofill.
1857c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL));
1858c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1859c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SwitchToWallet();
1860c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1861c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Setup some wallet state, submit, and get a full wallet to end the flow.
1862eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems();
1863c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1864c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Filling |form_structure()| depends on the current username and wallet items
1865c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // being fetched. Until both of these have occurred, the user should not be
1866c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // able to click Submit if using Wallet. The username fetch happened earlier.
1867c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1868c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
1869c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1870c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1871c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Email section should be hidden when using Wallet.
1872c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL));
1873c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1874c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnAccept();
1875c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
1876c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1877c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  size_t i = 0;
1878c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (; i < form_structure()->field_count(); ++i) {
1879c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (form_structure()->field(i)->type() == EMAIL_ADDRESS) {
1880c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value);
1881c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      break;
1882c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
1883c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1884c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_LT(i, form_structure()->field_count());
1885c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1886c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1887b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test if autofill types of returned form structure are correct for billing
1888b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// entries.
1889b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillTypes) {
1890b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
1891b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnAccept();
1892b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
1893868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_EQ(20U, form_structure()->field_count());
1894b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EXPECT_EQ(EMAIL_ADDRESS, form_structure()->field(0)->type());
1895868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure()->field(2)->type());
1896868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(9)->type());
1897868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(16)->type());
1898b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
1899b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1900c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) {
1901c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
1902c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
190390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
1904c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1905c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
190690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CreditCard card(test::GetVerifiedCreditCard());
1907c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->GetTestingManager()->AddTestingCreditCard(&card);
1908c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1909c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1910c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditClickedForSection(SECTION_EMAIL);
1911c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
1912c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1913c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->EditCancelledForSection(SECTION_EMAIL);
1914c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1915c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1916c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
1917c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
1918c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1919c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  profile()->set_incognito(true);
1920c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1921c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1922c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
192390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that user is prompted when using instrument with minimal address.
192490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) {
1925eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // A minimal address being selected should trigger error validation in the
1926eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // view. Called once for each incomplete suggestion.
1927eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1);
1928eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
192990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
193090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentWithIdAndAddress(
193190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      "id", wallet::GetTestMinimalAddress()));
193290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::Address> address(wallet::GetTestShippingAddress());
193390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  address->set_is_complete_address(false);
193490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(address.Pass());
193590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
193690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
193790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Assert that dialog's SECTION_CC_BILLING section is in edit mode.
1938868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING));
193990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Shipping section should be in edit mode because of
194090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // is_minimal_shipping_address.
1941868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_TRUE(controller()->IsEditingExistingData(SECTION_SHIPPING));
194290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
194390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
194490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) {
194590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
194690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
194790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
194890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
194990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
195090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
195190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
195290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
195390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) {
195490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
195590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
195690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
195790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
195890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
195990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
196090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  testing::Mock::VerifyAndClear(controller());
196190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
196290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
196390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnAccept();
196490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
196590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Simulate a risk load and verify |GetRiskData()| matches the encoded value.
196690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidAcceptLegalDocuments();
196790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
196890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData());
196990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
197090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
197190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, NoManageMenuItemForNewWalletUsers) {
197290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Make sure the menu model item is created for a returning Wallet user.
197390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
197490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
197590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  wallet_items->AddAddress(wallet::GetTestShippingAddress());
197690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
197790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
197890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING));
197990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "Same as billing", "123 address", "Add address...", and "Manage addresses".
198090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(
198190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
198290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
198390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Make sure the menu model item is not created for new Wallet users.
198490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::DictionaryValue dict;
198590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<base::ListValue> required_actions(new base::ListValue);
198690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  required_actions->AppendString("setup_wallet");
198790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  dict.Set("required_action", required_actions.release());
198890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  controller()->OnDidGetWalletItems(
198990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      wallet::WalletItems::CreateWalletItems(dict).Pass());
199090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
199190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING));
199290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // "Same as billing" and "Add address...".
199390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(
199490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
199590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
199690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1997868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHidden) {
1998868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SwitchToAutofill();
1999868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2000868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormFieldData email_field;
2001868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  email_field.autocomplete_attribute = "email";
2002868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormFieldData cc_field;
2003868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  cc_field.autocomplete_attribute = "cc-number";
2004868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormFieldData billing_field;
2005868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  billing_field.autocomplete_attribute = "billing region";
2006868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2007868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FormData form_data;
2008868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  form_data.fields.push_back(email_field);
2009868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  form_data.fields.push_back(cc_field);
2010868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  form_data.fields.push_back(billing_field);
2011868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2012868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AutofillProfile full_profile(test::GetVerifiedProfile());
2013868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->GetTestingManager()->AddTestingProfile(&full_profile);
2014868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetUpControllerWithFormData(form_data);
2015868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
2016868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2017868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FillCreditCardInputs();
2018868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
2019868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(form_structure());
2020868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2021868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2022868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, NotProdNotification) {
2023868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // To make IsPayingWithWallet() true.
2024868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
2025868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2026868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
2027868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ASSERT_FALSE(command_line->HasSwitch(switches::kWalletServiceUseProd));
2028868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(
2029868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty());
2030868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2031868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  command_line->AppendSwitch(switches::kWalletServiceUseProd);
2032868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
2033868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty());
2034868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2035868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2036868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Ensure Wallet instruments marked expired by the server are shown as invalid.
2037868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletExpiredCard) {
2038868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
2039868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired());
2040868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetWalletItems(wallet_items.Pass());
2041868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2042868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING));
2043868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2044868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Use |SetOutputValue()| to put the right AutofillFieldTypes into the map.
2045868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const DetailInputs& inputs =
2046868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
2047868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DetailOutputMap outputs;
2048868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetOutputValue(inputs, &outputs, COMPANY_NAME, "Bluth Company");
2049868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2050868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ValidityData validity_data =
20517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
2052868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_MONTH));
2053868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
2054868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2055868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Make the local input year differ from the instrument.
2056868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, "3002");
2057868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
20587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  validity_data =
20597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
2060868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
2061868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
2062868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2063868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Make the local input month differ from the instrument.
2064868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_MONTH, "06");
2065868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
20667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  validity_data =
20677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT);
2068868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH));
2069868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
2070868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2071868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2072868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChooseAnotherInstrumentOrAddress) {
2073eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SubmitWithWalletItems(CompleteAndValidWalletItems());
2074868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2075868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
2076868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
2077868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_CALL(*controller()->GetTestingWalletClient(),
2078868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)              GetWalletItems(_)).Times(1);
2079868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnDidGetFullWallet(
2080868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      CreateFullWallet("choose_another_instrument_or_address"));
2081868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1U, NotificationsOfType(
2082868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
2083eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2084868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2085868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  controller()->OnAccept();
2086868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0U, NotificationsOfType(
2087868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      DialogNotification::REQUIRED_ACTION).size());
2088868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
2089868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2090eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Make sure detailed steps for Autocheckout are added
2091eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// and updated correctly.
2092eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DetailedSteps) {
2093eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_CALL(*controller()->GetTestingWalletClient(),
2094eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            GetFullWallet(_)).Times(1);
2095eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2096eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
2097eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2098eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Add steps as would normally be done by the AutocheckoutManager.
2099eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING);
2100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY);
2101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_BILLING);
2102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
2104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
2105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  wallet_items->AddAddress(wallet::GetTestShippingAddress());
2106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidGetWalletItems(wallet_items.Pass());
2107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Initiate flow - should add proxy card step since the user is using wallet
2108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // data.
2109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnAccept();
2110eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
2111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2112eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SuggestionState suggestion_state =
2113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      controller()->SuggestionStateForSection(SECTION_CC_BILLING);
2114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_TRUE(suggestion_state.extra_text.empty());
2115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // There should be four steps total, with the first being the card generation
2117eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // step added by the dialog controller.
2118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(4U, controller()->CurrentAutocheckoutSteps().size());
2119eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_PROXY_CARD,
2120eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].type());
2121eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED,
2122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].status());
2123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Simulate a wallet error. This should remove the card generation step from
2125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // the flow, as we will have to proceed with local data.
2126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
2127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile shipping_profile(test::GetVerifiedProfile());
2129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  AutofillProfile billing_profile(test::GetVerifiedProfile2());
2130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CreditCard credit_card(test::GetVerifiedCreditCard());
2131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&shipping_profile);
2132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingProfile(&billing_profile);
2133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
2134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ui::MenuModel* billing_model =
2135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      controller()->MenuModelForSection(SECTION_BILLING);
2136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  billing_model->ActivatedAt(1);
2137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Re-initiate flow.
2139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->OnAccept();
2140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2141eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // All steps should be initially unstarted.
2142eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size());
2143eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING,
2144eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].type());
2145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].status());
2147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY,
2148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].type());
2149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].status());
2151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING,
2152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].type());
2153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2154eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].status());
2155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Update steps in the same manner that we would expect to see from the
2157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // AutocheckoutManager while progressing through a flow.
2158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING,
2159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                       AUTOCHECKOUT_STEP_STARTED);
2160eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING,
2161eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                       AUTOCHECKOUT_STEP_COMPLETED);
2162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY,
2163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                       AUTOCHECKOUT_STEP_STARTED);
2164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Verify that the steps were appropriately updated.
2166eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size());
2167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING,
2168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].type());
2169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_COMPLETED,
2170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[0].status());
2171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY,
2172eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].type());
2173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED,
2174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[1].status());
2175eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING,
2176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].type());
2177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            controller()->CurrentAutocheckoutSteps()[2].status());
2179eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
2180eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
21812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace autofill
2182