autofill_dialog_controller_unittest.cc revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <map> 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/bind.h" 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/command_line.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/guid.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 119ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/run_loop.h" 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/strings/string_number_conversions.h" 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 16ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/tuple.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_view.h" 19ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" 20ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h" 21ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_view.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h" 23ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "chrome/common/render_messages.h" 24ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "chrome/test/base/chrome_render_view_host_test_harness.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/testing_profile.h" 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/full_wallet.h" 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/instrument.h" 297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "components/autofill/content/browser/wallet/mock_wallet_client.h" 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_address.h" 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_service_url.h" 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_test_util.h" 33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_common_test.h" 34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_metrics.h" 35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/test_personal_data_manager.h" 367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/autofill_switches.h" 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/form_data.h" 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/web_contents.h" 39ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "content/public/test/mock_render_process_host.h" 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h" 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN) 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/win/scoped_ole_initializer.h" 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using testing::_; 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace autofill { 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kFakeEmail[] = "user@example.com"; 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; 55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)const char kEditedBillingAddress[] = "123 edited billing address"; 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char* kFieldsFromPage[] = 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "email", 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "cc-name", 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "cc-number", 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "cc-exp-month", 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "cc-exp-year", 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "cc-csc", 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "billing name", 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "billing address-line1", 65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "billing locality", 66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "billing region", 67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "billing postal-code", 68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "billing country", 69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "billing tel", 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "shipping name", 71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "shipping address-line1", 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "shipping locality", 73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "shipping region", 74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "shipping postal-code", 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "shipping country", 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "shipping tel", 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) }; 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kSettingsOrigin[] = "Chrome settings"; 797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberAmex[] = "376200000000002"; 807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberVisa[] = "4111111111111111"; 817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberMaster[] = "5555555555554444"; 827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberDiscover[] = "6011111111111117"; 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberIncomplete[] = "4111111111"; 847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Credit card number fails Luhn check. 857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const char kTestCCNumberInvalid[] = "4111111111111112"; 867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void SetOutputValue(const DetailInputs& inputs, 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DetailOutputMap* outputs, 903240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch ServerFieldType type, 91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const base::string16& value) { 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) for (size_t i = 0; i < inputs.size(); ++i) { 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const DetailInput& input = inputs[i]; 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) (*outputs)[&input] = input.type == type ? 95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) value : 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) input.initial_value; 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochscoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { 101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<wallet::WalletItems> items = wallet::GetTestWalletItems(); 102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch items->AddInstrument(wallet::GetTestMaskedInstrument()); 103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch items->AddAddress(wallet::GetTestShippingAddress()); 104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return items.Pass(); 105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)scoped_ptr<wallet::FullWallet> CreateFullWallet(const char* required_action) { 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::DictionaryValue dict; 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<base::ListValue> list(new base::ListValue()); 110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) list->AppendString(required_action); 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) dict.Set("required_action", list.release()); 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return wallet::FullWallet::CreateFullWallet(dict); 11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)scoped_ptr<risk::Fingerprint> GetFakeFingerprint() { 11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint()); 11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Add some data to the proto, else the encoded content is empty. 11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) fingerprint->mutable_machine_characteristics()->mutable_screen_size()-> 11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) set_width(1024); 12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return fingerprint.Pass(); 12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestAutofillDialogView : public AutofillDialogView { 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TestAutofillDialogView() : updates_started_(0) {} 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TestAutofillDialogView() {} 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void Show() OVERRIDE {} 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void Hide() OVERRIDE {} 1303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdatesStarted() OVERRIDE { 1323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) updates_started_++; 1333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdatesFinished() OVERRIDE { 1363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) updates_started_--; 1373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_GE(updates_started_, 0); 1383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdateNotificationArea() OVERRIDE { 1413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_GE(updates_started_, 1); 1423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdateAccountChooser() OVERRIDE { 1453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_GE(updates_started_, 1); 1463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdateButtonStrip() OVERRIDE { 1493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_GE(updates_started_, 1); 1503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdateDetailArea() OVERRIDE { 1533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_GE(updates_started_, 1); 1543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdateAutocheckoutStepsArea() OVERRIDE { 1573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_GE(updates_started_, 1); 1583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void UpdateSection(DialogSection section) OVERRIDE { 1613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_GE(updates_started_, 1); 1623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void FillSection(DialogSection section, 165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInput& originating_input) OVERRIDE {}; 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void GetUserInput(DialogSection section, DetailOutputMap* output) 167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OVERRIDE { 168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) *output = outputs_[section]; 169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual TestableAutofillDialogView* GetTestableView() OVERRIDE { 1717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return NULL; 1727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual string16 GetCvc() OVERRIDE { return string16(); } 175424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual bool HitTestInput(const DetailInput& input, 176424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const gfx::Point& screen_point) OVERRIDE { 177424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return false; 178424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool SaveDetailsLocally() OVERRIDE { return true; } 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual const content::NavigationController* ShowSignIn() OVERRIDE { 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return NULL; 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void HideSignIn() OVERRIDE {} 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void UpdateProgressBar(double value) OVERRIDE {} 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MOCK_METHOD0(ModelChanged, void()); 1877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MOCK_METHOD0(UpdateForErrors, void()); 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} 19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void SetUserInput(DialogSection section, const DetailOutputMap& map) { 192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) outputs_[section] = map; 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::map<DialogSection, DetailOutputMap> outputs_; 197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int updates_started_; 1993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Bring over command-ids from AccountChooserModel. 204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestAccountChooserModel : public AccountChooserModel { 205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TestAccountChooserModel(AccountChooserModelDelegate* delegate, 207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) PrefService* prefs, 208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const AutofillMetrics& metric_logger) 209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) : AccountChooserModel(delegate, prefs, metric_logger, 210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {} 211c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~TestAccountChooserModel() {} 212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) using AccountChooserModel::kActiveWalletItemId; 214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) using AccountChooserModel::kAutofillItemId; 215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel); 218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 220c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class TestAutofillDialogController 221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) : public AutofillDialogControllerImpl, 222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public base::SupportsWeakPtr<TestAutofillDialogController> { 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestAutofillDialogController( 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* contents, 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const FormData& form_structure, 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& source_url, 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const AutofillMetrics& metric_logger, 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const DialogType dialog_type, 230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const base::Callback<void(const FormStructure*, 231ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const std::string&)>& callback, 232ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch MockNewCreditCardBubbleController* mock_new_card_bubble_controller) 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : AutofillDialogControllerImpl(contents, 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) form_structure, 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) source_url, 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) dialog_type, 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback), 238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) metric_logger_(metric_logger), 2397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch mock_wallet_client_( 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Profile::FromBrowserContext(contents->GetBrowserContext())-> 241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetRequestContext(), this), 242ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch dialog_type_(dialog_type), 243ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch mock_new_card_bubble_controller_(mock_new_card_bubble_controller) {} 244ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TestAutofillDialogController() {} 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual AutofillDialogView* CreateView() OVERRIDE { 248c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return new testing::NiceMock<TestAutofillDialogView>(); 249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 251c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void Init(content::BrowserContext* browser_context) { 252c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) test_manager_.Init(browser_context); 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestAutofillDialogView* GetView() { 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return static_cast<TestAutofillDialogView*>(view()); 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestPersonalDataManager* GetTestingManager() { 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return &test_manager_; 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch wallet::MockWalletClient* GetTestingWalletClient() { 2647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return &mock_wallet_client_; 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 267c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const GURL& open_tab_url() { return open_tab_url_; } 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 26990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual DialogType GetDialogType() const OVERRIDE { 27090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return dialog_type_; 27190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 27390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } 27490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 275868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void SimulateSigninError() { 276868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) OnWalletSigninError(); 27790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 279ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch bool AutocheckoutIsRunning() const { 280ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch return AUTOCHECKOUT_IN_PROGRESS == autocheckout_state(); 281ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch } 282ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 28390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MOCK_METHOD0(LoadRiskFingerprintData, void()); 28490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; 285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) using AutofillDialogControllerImpl::IsEditingExistingData; 28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual PersonalDataManager* GetManager() OVERRIDE { 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return &test_manager_; 2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual wallet::WalletClient* GetWalletClient() OVERRIDE { 2937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return &mock_wallet_client_; 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OpenTabWithUrl(const GURL& url) OVERRIDE { 297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) open_tab_url_ = url; 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 300eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Whether the information input in this dialog will be securely transmitted 301eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // to the requesting site. 302eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual bool TransmissionWillBeSecure() const OVERRIDE { 303eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return true; 304eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 305eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 306ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch virtual void ShowNewCreditCardBubble( 307ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch scoped_ptr<CreditCard> new_card, 308ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch scoped_ptr<AutofillProfile> billing_profile) OVERRIDE { 309ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch mock_new_card_bubble_controller_->Show(new_card.Pass(), 310ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch billing_profile.Pass()); 311ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 312ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // To specify our own metric logger. 315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return metric_logger_; 317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const AutofillMetrics& metric_logger_; 3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestPersonalDataManager test_manager_; 3217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_; 322c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GURL open_tab_url_; 32390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DialogType dialog_type_; 324ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch MockNewCreditCardBubbleController* mock_new_card_bubble_controller_; 3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 329ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass TestGeneratedCreditCardBubbleController : 330ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch public GeneratedCreditCardBubbleController { 3317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public: 332ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch explicit TestGeneratedCreditCardBubbleController( 3337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch content::WebContents* contents) 334ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch : GeneratedCreditCardBubbleController(contents) { 3357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch contents->SetUserData(UserDataKey(), this); 336a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) CHECK_EQ(contents->GetUserData(UserDataKey()), this); 3377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 338a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 339ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch virtual ~TestGeneratedCreditCardBubbleController() {} 3407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 341ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch MOCK_METHOD2(SetupAndShow, void(const base::string16& backing_card_name, 342ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const base::string16& fronting_card_name)); 3437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 344868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected: 345ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch virtual base::WeakPtr<GeneratedCreditCardBubbleView> CreateBubble() OVERRIDE { 346ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return TestGeneratedCreditCardBubbleView::Create(GetWeakPtr()); 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual bool CanShow() const OVERRIDE { 3507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return true; 3517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 3527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 3537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private: 354ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch DISALLOW_COPY_AND_ASSIGN(TestGeneratedCreditCardBubbleController); 3557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}; 3567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 357ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness { 3587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch protected: 3597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch AutofillDialogControllerTest(): form_structure_(NULL) {} 3607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // testing::Test implementation: 3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUp() OVERRIDE { 363ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ChromeRenderViewHostTestHarness::SetUp(); 364ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch Reset(); 36590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 36690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 36790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void TearDown() OVERRIDE { 3687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (controller_) 36990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->ViewClosed(); 370ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ChromeRenderViewHostTestHarness::TearDown(); 371ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch } 372ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 373ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch void Reset() { 374ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch if (controller_) 375ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch controller_->ViewClosed(); 376ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 377ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch test_generated_bubble_controller_ = 378ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch new testing::NiceMock<TestGeneratedCreditCardBubbleController>( 379ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch web_contents()); 380ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch mock_new_card_bubble_controller_.reset( 381ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch new MockNewCreditCardBubbleController); 382ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 383ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Don't get stuck on the first run wallet interstitial. 384ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch profile()->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, 385ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch true); 386ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 387ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SetUpControllerWithFormData(DefaultFormData()); 38890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 38990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 390868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FormData DefaultFormData() { 391868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FormData form_data; 392868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { 393868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FormFieldData field; 394868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) field.autocomplete_attribute = kFieldsFromPage[i]; 395868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) form_data.fields.push_back(field); 396868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 397868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return form_data; 398868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 399868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 40090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void SetUpControllerWithFormData(const FormData& form_data) { 4017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (controller_) 40290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->ViewClosed(); 40390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Callback<void(const FormStructure*, const std::string&)> callback = 405c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Bind(&AutofillDialogControllerTest::FinishedCallback, 406c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Unretained(this)); 40790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_ = (new testing::NiceMock<TestAutofillDialogController>( 408ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch web_contents(), 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) form_data, 4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL(), 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) metric_logger_, 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DIALOG_TYPE_REQUEST_AUTOCOMPLETE, 413ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch callback, 414ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch mock_new_card_bubble_controller_.get()))->AsWeakPtr(); 415c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller_->Init(profile()); 4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller_->Show(); 417c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller_->OnUserNameFetchSuccess(kFakeEmail); 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 420c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void FillCreditCardInputs() { 421c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DetailOutputMap cc_outputs; 422c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInputs& cc_inputs = 423c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_CC); 424c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < cc_inputs.size(); ++i) { 4257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NUMBER ? 4267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11"); 427c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 428c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); 429c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 430c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 431c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::vector<DialogNotification> NotificationsOfType( 432c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DialogNotification::Type type) { 433c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::vector<DialogNotification> right_type; 434c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::vector<DialogNotification>& notifications = 435c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->CurrentNotifications(); 436c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < notifications.size(); ++i) { 437c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (notifications[i].type() == type) 438c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) right_type.push_back(notifications[i]); 439c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 440c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return right_type; 441c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 442c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void SwitchToAutofill() { 444c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller_->MenuModelForAccountChooser()->ActivatedAt( 445c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TestAccountChooserModel::kAutofillItemId); 446c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 447c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 448c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void SwitchToWallet() { 449c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller_->MenuModelForAccountChooser()->ActivatedAt( 450c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TestAccountChooserModel::kActiveWalletItemId); 451c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 452c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 453868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void SimulateSigninError() { 454868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller_->SimulateSigninError(); 455868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 456868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 45790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void UseBillingForShipping() { 45890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); 45990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 46090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void ValidateCCNumber(DialogSection section, 4627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::string& cc_number, 4637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool should_pass) { 4647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DetailOutputMap outputs; 4657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const DetailInputs& inputs = 4667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->RequestedFieldsForSection(section); 4677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 468a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_NUMBER, 469a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASCIIToUTF16(cc_number)); 4707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidityData validity_data = 4717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_FINAL); 4727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_EQ(should_pass ? 0U : 1U, validity_data.count(CREDIT_CARD_NUMBER)); 4737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 4747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 475eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void SubmitWithWalletItems(scoped_ptr<wallet::WalletItems> wallet_items) { 476eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(wallet_items.Pass()); 477eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 478eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 479eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 480eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void AcceptAndLoadFakeFingerprint() { 481eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnAccept(); 482eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); 483eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 484eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 485ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch bool ReadSetVisuallyDeemphasizedIpc() { 486ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(1U, process()->sink().message_count()); 487ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch uint32 kMsgID = ChromeViewMsg_SetVisuallyDeemphasized::ID; 488ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch const IPC::Message* message = 489ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch process()->sink().GetFirstMessageMatching(kMsgID); 490ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_TRUE(message); 491ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch Tuple1<bool> payload; 492ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ChromeViewMsg_SetVisuallyDeemphasized::Read(message, &payload); 493ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch process()->sink().ClearMessages(); 494ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch return payload.a; 495ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch } 4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 497ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch TestAutofillDialogController* controller() { return controller_.get(); } 4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 499c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const FormStructure* form_structure() { return form_structure_; } 500c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 501ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { 502ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return test_generated_bubble_controller_; 503ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 504ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 505ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { 506ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return mock_new_card_bubble_controller_.get(); 5077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 5087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 510c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void FinishedCallback(const FormStructure* form_structure, 511c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& google_transaction_id) { 512c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) form_structure_ = form_structure; 513868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (controller()->GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) 514868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(controller()->AutocheckoutIsRunning()); 515c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 516c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 517c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN) 518c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // http://crbug.com/227221 519c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::ScopedOleInitializer ole_initializer_; 520c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 521c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The controller owns itself. 523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::WeakPtr<TestAutofillDialogController> controller_; 5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Must outlive the controller. 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AutofillMetrics metric_logger_; 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Returned when the dialog closes successfully. 529c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const FormStructure* form_structure_; 5307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 5317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Used to monitor if the Autofill credit card bubble is shown. Owned by 532ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // |web_contents()|. 533ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch TestGeneratedCreditCardBubbleController* test_generated_bubble_controller_; 534ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 535ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Used to record when new card bubbles would show. Created in |Reset()|. 536ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch scoped_ptr<MockNewCreditCardBubbleController> 537ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch mock_new_card_bubble_controller_; 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This test makes sure nothing falls over when fields are being validity- 5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// checked. 5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ValidityCheck) { 545868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 546868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogSection section = static_cast<DialogSection>(i); 5472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const DetailInputs& shipping_inputs = 5482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->RequestedFieldsForSection(section); 5492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (DetailInputs::const_iterator iter = shipping_inputs.begin(); 5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter != shipping_inputs.end(); ++iter) { 5517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputValidityMessage(section, iter->type, string16()); 5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 55690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Test for phone number validation. 55790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) { 55890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct DetailOutputMap from existing data. 55990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SwitchToAutofill(); 56090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 56190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 56290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 56390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 564868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (size_t i = 0; i < 2; ++i) { 5653240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch ServerFieldType phone = i == 0 ? PHONE_HOME_WHOLE_NUMBER : 5663240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch PHONE_BILLING_WHOLE_NUMBER; 5673240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch ServerFieldType address = i == 0 ? ADDRESS_HOME_COUNTRY : 5683240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch ADDRESS_BILLING_COUNTRY; 569868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogSection section = i == 0 ? SECTION_SHIPPING : SECTION_BILLING; 57090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 571868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->EditClickedForSection(section); 57290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 573868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DetailOutputMap outputs; 574868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const DetailInputs& inputs = 575868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->RequestedFieldsForSection(section); 576868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Make sure country is United States. 577a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, address, ASCIIToUTF16("United States")); 578868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 579868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Existing data should have no errors. 580868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ValidityData validity_data = 5817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_FINAL); 582868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(phone)); 583868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 584868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Input an empty phone number with VALIDATE_FINAL. 585a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue( inputs, &outputs, phone, base::string16()); 5867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 5877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_FINAL); 588868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(phone)); 589868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 590868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Input an empty phone number with VALIDATE_EDIT. 5917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 5927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_EDIT); 593868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(phone)); 594868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 595868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Input an invalid phone number. 596a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("ABC")); 5977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 5987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_EDIT); 599868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(phone)); 600868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 601868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Input a local phone number. 602a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("2155546699")); 6037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 6047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_EDIT); 605868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(phone)); 606868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 607868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Input an invalid local phone number. 608a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("215554669")); 6097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 6107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_EDIT); 611868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(phone)); 612868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 613868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Input an international phone number. 614a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, phone, ASCIIToUTF16("+33 892 70 12 39")); 6157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 6167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_EDIT); 617868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(phone)); 618868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 619868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Input an invalid international phone number. 620a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, phone, 621a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASCIIToUTF16("+112333 892 70 12 39")); 6227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 6237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(section, outputs, VALIDATE_EDIT); 624868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(phone)); 625868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 62690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 62790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 628a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) { 629a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DetailOutputMap outputs; 630a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const DetailInputs& inputs = 631a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_CC_BILLING); 632a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 633a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ui::ComboboxModel* exp_year_model = 634a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR); 635a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ui::ComboboxModel* exp_month_model = 636a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH); 637a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 638a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::string16 default_year_value = 639a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) exp_year_model->GetItemAt(exp_year_model->GetDefaultIndex()); 640a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 641a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::string16 other_year_value = 642a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) exp_year_model->GetItemAt(exp_year_model->GetItemCount() - 1); 643a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::string16 other_month_value = 644a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) exp_month_model->GetItemAt(exp_month_model->GetItemCount() - 1); 645a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 646a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, 647a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) default_year_value); 648a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 649a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Expiration default values "validate" with VALIDATE_EDIT. 650a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ValidityData validity_data = 651a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT); 652a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 653a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 654a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 655a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Expiration date with default month "validates" with VALIDATE_EDIT. 656a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, 657a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) other_year_value); 658a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 659a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) validity_data = 660a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT); 661a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 662a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 663a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 664a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Expiration date with default year "validates" with VALIDATE_EDIT. 665a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_MONTH, other_month_value); 666a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 667a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) validity_data = 668a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT); 669a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 670a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 671a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 672a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Expiration default values fail with VALIDATE_FINAL. 673a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, 674a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) default_year_value); 675a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 676a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) validity_data = 677a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_FINAL); 678a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 679a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 680a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 681a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Expiration date with default month fails with VALIDATE_FINAL. 682a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, 683a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) &outputs, 684a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) CREDIT_CARD_EXP_4_DIGIT_YEAR, 685a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) other_year_value); 686a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 687a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) validity_data = 688a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_FINAL); 689a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 690a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 691a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 692a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Expiration date with default year fails with VALIDATE_FINAL. 693a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_MONTH, other_month_value); 694a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 695a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) validity_data = 696a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_FINAL); 697a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 698a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 699a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 700a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 7017dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, BillingNameValidation) { 70290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct DetailOutputMap from AutofillProfile data. 70390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SwitchToAutofill(); 70490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 70590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DetailOutputMap outputs; 70690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const DetailInputs& inputs = 7077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->RequestedFieldsForSection(SECTION_BILLING); 70890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input an empty billing name with VALIDATE_FINAL. 710a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, NAME_BILLING_FULL, base::string16()); 71190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ValidityData validity_data = 7127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->InputsAreValid(SECTION_BILLING, outputs, VALIDATE_FINAL); 713a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(NAME_BILLING_FULL)); 71490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input an empty billing name with VALIDATE_EDIT. 71690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->InputsAreValid(SECTION_BILLING, outputs, VALIDATE_EDIT); 718a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL)); 71990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input a non-empty billing name. 721a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, NAME_BILLING_FULL, ASCIIToUTF16("Bob")); 72290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->InputsAreValid(SECTION_BILLING, outputs, VALIDATE_FINAL); 724a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL)); 72590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 72690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Switch to Wallet which only considers names with with at least two names to 72790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // be valid. 72890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SwitchToWallet(); 72990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 73090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Setup some wallet state. 73190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 73290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 73390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 73490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DetailOutputMap wallet_outputs; 73590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const DetailInputs& wallet_inputs = 73690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_CC_BILLING); 73790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input an empty billing name with VALIDATE_FINAL. Data source should not 73990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // change this behavior. 740a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL, 741a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::string16()); 74290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid( 7447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL); 745a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(NAME_BILLING_FULL)); 74690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input an empty billing name with VALIDATE_EDIT. Data source should not 74890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // change this behavior. 74990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid( 7517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SECTION_CC_BILLING, wallet_outputs, VALIDATE_EDIT); 752a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL)); 75390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input a one name billing name. Wallet does not currently support this. 755a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL, 756a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASCIIToUTF16("Bob")); 75790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid( 7597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL); 760a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(NAME_BILLING_FULL)); 76190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input a two name billing name. 763a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL, 764a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASCIIToUTF16("Bob Barker")); 76590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid( 7677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL); 768a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL)); 76990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input a more than two name billing name. 771a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(wallet_inputs, &wallet_outputs, NAME_BILLING_FULL, 772a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASCIIToUTF16("John Jacob Jingleheimer Schmidt")); 77390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid( 7757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL); 776a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL)); 77790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Input a billing name with lots of crazy whitespace. 779a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue( 780a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) wallet_inputs, &wallet_outputs, NAME_BILLING_FULL, 781a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASCIIToUTF16(" \\n\\r John \\n Jacob Jingleheimer \\t Schmidt ")); 78290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) validity_data = 7837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid( 7847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SECTION_CC_BILLING, wallet_outputs, VALIDATE_FINAL); 785a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(NAME_BILLING_FULL)); 78690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 78790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) { 7897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Construct DetailOutputMap from AutofillProfile data. 7907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SwitchToAutofill(); 7917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Should accept AMEX, Visa, Master and Discover. 7937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC, kTestCCNumberVisa, true); 7947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC, kTestCCNumberMaster, true); 7957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC, kTestCCNumberDiscover, true); 7967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC, kTestCCNumberAmex, true); 7977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC, kTestCCNumberIncomplete, false); 7997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC, kTestCCNumberInvalid, false); 8007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Switch to Wallet which will not accept AMEX. 8027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SwitchToWallet(); 8037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Setup some wallet state. 8057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 8067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Should accept Visa, Master and Discover, but not AMEX. 8087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberVisa, true); 8097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberMaster, true); 8107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberDiscover, true); 8117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberAmex, false); 8137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberIncomplete, false); 8147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberInvalid, false); 8157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 8167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfiles) { 8182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::MenuModel* shipping_model = 8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING); 8202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Since the PersonalDataManager is empty, this should only have the 821c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // "use billing", "add new" and "manage" menu items. 82290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(shipping_model); 823c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(3, shipping_model->GetItemCount()); 824c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // On the other hand, the other models should be NULL when there's no 825c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // suggestion. 826c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 827c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); 828c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL)); 8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 83090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3); 8312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Empty profiles are ignored. 833c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile empty_profile(base::GenerateGUID(), kSettingsOrigin); 8342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 8352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&empty_profile); 8362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 83790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(shipping_model); 838c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(3, shipping_model->GetItemCount()); 839c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL)); 8402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 84190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // An otherwise full but unverified profile should be ignored. 842c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile full_profile(test::GetFullProfile()); 84390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) full_profile.set_origin("https://www.example.com"); 8442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 8462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 84790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(shipping_model); 84890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(3, shipping_model->GetItemCount()); 84990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL)); 85090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 85190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // A full, verified profile should be picked up. 85290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile verified_profile(test::GetVerifiedProfile()); 85390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 85490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 85590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 85690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(shipping_model); 857c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(4, shipping_model->GetItemCount()); 858c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL)); 8592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 86190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Makes sure that the choice of which Autofill profile to use for each section 86290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// is sticky. 86390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) { 86490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetFullProfile()); 86590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) full_profile.set_origin(kSettingsOrigin); 86690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 86790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile2(test::GetFullProfile2()); 86890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) full_profile2.set_origin(kSettingsOrigin); 86990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile2); 87090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 87190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Until a selection has been made, the default shipping suggestion is the 87290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // first one (after "use billing"). 87390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SuggestionsMenuModel* shipping_model = static_cast<SuggestionsMenuModel*>( 87490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING)); 87590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(1, shipping_model->checked_item()); 87690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 87790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) for (int i = 2; i >= 0; --i) { 87890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_model = static_cast<SuggestionsMenuModel*>( 87990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING)); 88090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_model->ExecuteCommand(i, 0); 88190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FillCreditCardInputs(); 88290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 88390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 884ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch Reset(); 88590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 88690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile2); 88790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_model = static_cast<SuggestionsMenuModel*>( 88890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING)); 88990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(i, shipping_model->checked_item()); 89090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 89190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 89290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Try again, but don't add the default profile to the PDM. The dialog 89390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // should fall back to the first profile. 89490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_model->ExecuteCommand(2, 0); 89590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FillCreditCardInputs(); 89690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 897ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch Reset(); 89890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 89990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_model = static_cast<SuggestionsMenuModel*>( 90090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING)); 90190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(1, shipping_model->checked_item()); 90290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 90390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { 9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 906c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::MenuModel* email_model = 907c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->MenuModelForSection(SECTION_EMAIL); 908c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(email_model); 9092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set up some variant data. 91190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 9122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<string16> names; 9132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) names.push_back(ASCIIToUTF16("John Doe")); 9142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) names.push_back(ASCIIToUTF16("Jane Doe")); 9152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); 916c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); 9172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); 9182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<string16> emails; 9192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) emails.push_back(kEmail1); 9202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) emails.push_back(kEmail2); 9212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); 9222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Respect variants for the email address field only. 9242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 9252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::MenuModel* shipping_model = 9262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING); 927c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(4, shipping_model->GetItemCount()); 928c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) email_model = controller()->MenuModelForSection(SECTION_EMAIL); 929c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_TRUE(!!email_model); 930c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(4, email_model->GetItemCount()); 9312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 93290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The first one is the default. 93390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SuggestionsMenuModel* email_suggestions = static_cast<SuggestionsMenuModel*>( 93490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_EMAIL)); 93590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0, email_suggestions->checked_item()); 93690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) email_model->ActivatedAt(0); 938c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kEmail1, 939c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch controller()->SuggestionStateForSection(SECTION_EMAIL). 940c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch vertically_compact_text); 9412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) email_model->ActivatedAt(1); 942c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kEmail2, 943c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch controller()->SuggestionStateForSection(SECTION_EMAIL). 944c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch vertically_compact_text); 9452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->EditClickedForSection(SECTION_EMAIL); 9472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const DetailInputs& inputs = 9482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_EMAIL); 949c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kEmail2, inputs[0].initial_value); 95090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 95190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The choice of variant is persisted across runs of the dialog. 95290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) email_model->ActivatedAt(0); 95390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) email_model->ActivatedAt(1); 95490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FillCreditCardInputs(); 95590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 95690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 957ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch Reset(); 95890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 95990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) email_suggestions = static_cast<SuggestionsMenuModel*>( 96090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_EMAIL)); 96190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(1, email_suggestions->checked_item()); 96290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 96390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 964eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, SuggestValidEmail) { 9657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AutofillProfile profile(test::GetVerifiedProfile()); 9667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const string16 kValidEmail = ASCIIToUTF16(kFakeEmail); 9677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) profile.SetRawInfo(EMAIL_ADDRESS, kValidEmail); 9687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&profile); 9697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 9707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(0); 9717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_EQ(kValidEmail, 972c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch controller()->SuggestionStateForSection(SECTION_EMAIL). 973c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch vertically_compact_text); 9747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 9757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 976eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidEmail) { 9777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AutofillProfile profile(test::GetVerifiedProfile()); 9787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(".!#$%&'*+/=?^_`-@-..")); 9797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&profile); 980eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(static_cast<ui::MenuModel*>(NULL), 981eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->MenuModelForSection(SECTION_EMAIL)); 982eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 9837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 984eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromIncompleteProfile) { 985eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile(test::GetVerifiedProfile()); 986eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail)); 987eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profile.SetRawInfo(ADDRESS_HOME_STATE, base::string16()); 988eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->GetTestingManager()->AddTestingProfile(&profile); 989eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(static_cast<ui::MenuModel*>(NULL), 990eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->MenuModelForSection(SECTION_EMAIL)); 991eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 992eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 993eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestEmailFromInvalidProfile) { 994eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile(test::GetVerifiedProfile()); 995eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(kFakeEmail)); 996eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C")); 997eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->GetTestingManager()->AddTestingProfile(&profile); 998eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(static_cast<ui::MenuModel*>(NULL), 999eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->MenuModelForSection(SECTION_EMAIL)); 1000eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 1001eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1002eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, SuggestValidAddress) { 1003eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile full_profile(test::GetVerifiedProfile()); 1004eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch full_profile.set_origin(kSettingsOrigin); 1005eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1006eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ( 1007eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 1008eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 1009eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1010eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DoNotSuggestInvalidAddress) { 1011eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile full_profile(test::GetVerifiedProfile()); 1012eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch full_profile.set_origin(kSettingsOrigin); 1013eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch full_profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("C")); 1014eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1015eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ( 1016eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 10177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 10187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 101990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillCreditCards) { 102090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Since the PersonalDataManager is empty, this should only have the 102190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // default menu items. 102290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 102390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 102490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3); 102590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 102690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Empty cards are ignored. 102790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard empty_card(base::GenerateGUID(), kSettingsOrigin); 102890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) empty_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John Doe")); 102990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingCreditCard(&empty_card); 103090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 103190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 103290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // An otherwise full but unverified card should be ignored. 103390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard full_card(test::GetCreditCard()); 103490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) full_card.set_origin("https://www.example.com"); 103590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingCreditCard(&full_card); 103690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 103790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 103890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // A full, verified card should be picked up. 103990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard verified_card(test::GetCreditCard()); 104090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) verified_card.set_origin(kSettingsOrigin); 104190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingCreditCard(&verified_card); 104290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ui::MenuModel* credit_card_model = 104390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_CC); 104490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(credit_card_model); 104590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(3, credit_card_model->GetItemCount()); 10462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 10472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1048b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test selecting a shipping address different from billing as address. 1049b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) { 105090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 105190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile2(test::GetVerifiedProfile2()); 105290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard credit_card(test::GetVerifiedCreditCard()); 1053b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1054b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile2); 1055b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1056b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ui::MenuModel* shipping_model = 1057b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING); 1058b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) shipping_model->ActivatedAt(2); 1059b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1060b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->OnAccept(); 1061868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_EQ(20U, form_structure()->field_count()); 10623240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch EXPECT_EQ(ADDRESS_HOME_STATE, 1063bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(9)->Type().GetStorableType()); 1064bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); 1065bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_HOME_STATE, 1066bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(16)->Type().GetStorableType()); 1067bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); 1068868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 billing_state = form_structure()->field(9)->value; 1069868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 shipping_state = form_structure()->field(16)->value; 1070868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(billing_state.empty()); 1071868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(shipping_state.empty()); 1072868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_NE(billing_state, shipping_state); 1073868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1074bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(CREDIT_CARD_NAME, 1075bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(1)->Type().GetStorableType()); 1076868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 cc_name = form_structure()->field(1)->value; 1077bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType()); 1078bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); 1079868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 billing_name = form_structure()->field(6)->value; 1080bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType()); 1081bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); 1082868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 shipping_name = form_structure()->field(13)->value; 1083868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1084868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(cc_name.empty()); 1085868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(billing_name.empty()); 1086868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(shipping_name.empty()); 1087868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Billing name should always be the same as cardholder name. 10887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_EQ(cc_name, billing_name); 1089868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_NE(cc_name, shipping_name); 1090b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 1091b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1092b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test selecting UseBillingForShipping. 1093b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) { 109490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 109590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile2(test::GetVerifiedProfile2()); 109690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard credit_card(test::GetVerifiedCreditCard()); 1097b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1098b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile2); 1099b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1100b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1101b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Test after setting use billing for shipping. 110290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) UseBillingForShipping(); 1103b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1104b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->OnAccept(); 1105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_EQ(20U, form_structure()->field_count()); 11063240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch EXPECT_EQ(ADDRESS_HOME_STATE, 1107bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(9)->Type().GetStorableType()); 1108bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); 1109bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_HOME_STATE, 1110bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(16)->Type().GetStorableType()); 1111bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); 1112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 billing_state = form_structure()->field(9)->value; 1113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 shipping_state = form_structure()->field(16)->value; 1114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(billing_state.empty()); 1115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(shipping_state.empty()); 1116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(billing_state, shipping_state); 1117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 11183240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch EXPECT_EQ(CREDIT_CARD_NAME, 1119bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(1)->Type().GetStorableType()); 1120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 cc_name = form_structure()->field(1)->value; 1121bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType()); 1122bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group()); 1123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 billing_name = form_structure()->field(6)->value; 1124bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType()); 1125bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(NAME, form_structure()->field(13)->Type().group()); 1126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) string16 shipping_name = form_structure()->field(13)->value; 1127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(cc_name.empty()); 1129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(billing_name.empty()); 1130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(shipping_name.empty()); 1131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(cc_name, billing_name); 1132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(cc_name, shipping_name); 1133b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 1134b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 113590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that shipping and billing telephone fields are supported, and filled 113690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// in by their respective profiles. http://crbug.com/244515 1137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { 113890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FormFieldData shipping_tel; 113990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_tel.autocomplete_attribute = "shipping tel"; 114090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FormFieldData billing_tel; 114190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) billing_tel.autocomplete_attribute = "billing tel"; 114290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 114390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FormData form_data; 114490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) form_data.fields.push_back(shipping_tel); 114590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) form_data.fields.push_back(billing_tel); 114690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetUpControllerWithFormData(form_data); 114790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 114890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The profile that will be chosen for the shipping section. 114990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile shipping_profile(test::GetVerifiedProfile()); 115090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The profile that will be chosen for the billing section. 115190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile billing_profile(test::GetVerifiedProfile2()); 115290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard credit_card(test::GetVerifiedCreditCard()); 115390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); 115490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&billing_profile); 115590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 115690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ui::MenuModel* billing_model = 115790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_BILLING); 115890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) billing_model->ActivatedAt(1); 115990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 116090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 116190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_EQ(2U, form_structure()->field_count()); 11623240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 1163bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(0)->Type().GetStorableType()); 1164bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(PHONE_HOME, form_structure()->field(0)->Type().group()); 1165bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 1166bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(1)->Type().GetStorableType()); 1167bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(PHONE_BILLING, form_structure()->field(1)->Type().group()); 116890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), 116990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) form_structure()->field(0)->value); 1170424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_EQ(billing_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), 117190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) form_structure()->field(1)->value); 117290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_NE(form_structure()->field(1)->value, 117390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) form_structure()->field(0)->value); 117490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 117590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { 11772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 11782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AcceptLegalDocuments(_, _, _)).Times(1); 11792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 11802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetFullWallet(_)).Times(1); 118190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); 11822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems(); 11842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); 11852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnAccept(); 118790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidAcceptLegalDocuments(); 118890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); 11892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Makes sure the default object IDs are respected. 1192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { 1193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 1195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 1196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 11982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); 1200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); 1201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); 1202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestShippingAddress()); 1203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); 1204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // "add", "manage", and 4 suggestions. 1207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(6, 1208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); 1209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> 1210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IsItemCheckedAt(2)); 1211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_FALSE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); 1212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // "use billing", "add", "manage", and 5 suggestions. 1213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(8, 1214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 1215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->MenuModelForSection(SECTION_SHIPPING)-> 1216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IsItemCheckedAt(4)); 1217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_FALSE(controller()->IsEditingExistingData(SECTION_SHIPPING)); 121890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 121990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 122090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that invalid and AMEX default instruments are ignored. 122190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SelectInstrument) { 122290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 122390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Tests if default instrument is invalid, then, the first valid instrument is 122490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // selected instead of the default instrument. 122590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 122690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 122790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid()); 122890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 122990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 123090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 123190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // 4 suggestions and "add", "manage". 123290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(6, 123390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); 123490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> 123590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IsItemCheckedAt(0)); 123690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 123790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Tests if default instrument is AMEX, then, the first valid instrument is 123890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // selected instead of the default instrument. 123990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items = wallet::GetTestWalletItems(); 124090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 124190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 124290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex()); 124390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 124490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 124590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 124690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // 4 suggestions and "add", "manage". 124790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(6, 124890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); 124990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> 125090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IsItemCheckedAt(0)); 125190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 125290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Tests if only have AMEX and invalid instrument, then "add" is selected. 125390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items = wallet::GetTestWalletItems(); 125490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid()); 125590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex()); 125690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 125790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 125890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // 2 suggestions and "add", "manage". 125990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(4, 126090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); 126190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // "add" 126290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> 126390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IsItemCheckedAt(2)); 1264c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1265c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1266c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveAddress) { 12672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 12682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1269ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::IsNull(), 1270ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch testing::NotNull(), 1271ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 12722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 12742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 12752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 127690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // If there is no shipping address in wallet, it will default to 127790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // "same-as-billing" instead of "add-new-item". "same-as-billing" is covered 127890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // by the following tests. The last item in the menu is "add-new-item". 127990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ui::MenuModel* shipping_model = 128090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING); 128190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_model->ActivatedAt(shipping_model->GetItemCount() - 1); 1282eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 12832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrument) { 12862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 12872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1288ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::NotNull(), 1289ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch testing::IsNull(), 1290ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 12912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 12932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestShippingAddress()); 1294eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(wallet_items.Pass()); 12952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 129790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) { 129890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 129990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1300ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::NotNull(), 1301ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch testing::IsNull(), 1302ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 130390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 130490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 130590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestShippingAddress()); 130690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid()); 1307eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(wallet_items.Pass()); 130890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 130990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 13102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { 13112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1312ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::NotNull(), 1313ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch testing::NotNull(), 1314ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 13152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 1317eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 13182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1320ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochMATCHER(IsUpdatingExistingData, "updating existing Wallet data") { 1321ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch return !arg->object_id().empty(); 1322ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch} 1323ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 1324a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Tests that editing an address (in wallet mode0 and submitting the dialog 1325a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// should update the existing address on the server via WalletClient. 1326a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateAddress) { 1327a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1328ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::IsNull(), 1329ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch IsUpdatingExistingData(), 1330ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 1331a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1332eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 1333a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1334a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->EditClickedForSection(SECTION_SHIPPING); 1335eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 1336a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 1337a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1338a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Tests that editing an instrument (CC + address) in wallet mode updates an 1339a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// existing instrument on the server via WalletClient. 1340a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateInstrument) { 1341ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_CALL(*controller()->GetTestingWalletClient(), 1342ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(IsUpdatingExistingData(), 1343ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch testing::IsNull(), 1344ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 1345ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 1346eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 1347a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1348a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->EditClickedForSection(SECTION_CC_BILLING); 1349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 1350a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 1351a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1352a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that a user is able to edit their instrument and add a new address in 1353a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// the same submission. 1354a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpdateInstrumentSaveAddress) { 1355a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1356ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(IsUpdatingExistingData(), 1357ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch testing::NotNull(), 1358ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 1359a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1360a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1361a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1362a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1363a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1364a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->EditClickedForSection(SECTION_CC_BILLING); 1365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 1366a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 1367a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1368a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that saving a new instrument and editing an address works. 1369a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentUpdateAddress) { 1370a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1371ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::NotNull(), 1372ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch IsUpdatingExistingData(), 1373ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 1374a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1375a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1376a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestShippingAddress()); 137790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1378a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1379a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1380a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->EditClickedForSection(SECTION_SHIPPING); 1381eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 1382a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 1383a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1384a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)MATCHER(UsesLocalBillingAddress, "uses the local billing address") { 1385ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch return arg->address_line_1() == ASCIIToUTF16(kEditedBillingAddress); 1386a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 1387a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 138890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that when using billing address for shipping, and there is no exact 138990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// matched shipping address, then a shipping address should be added. 139090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingForShipping) { 139190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1392ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::IsNull(), 1393ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch testing::NotNull(), 1394ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 139590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1396eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 139790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Select "Same as billing" in the address menu. 139890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) UseBillingForShipping(); 139990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1400eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 140190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 140290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 140390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that when using billing address for shipping, and there is an exact 140490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// matched shipping address, then a shipping address should not be added. 140590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) { 140690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1407ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(_, _, _)).Times(0); 140890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 140990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 141090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument = 141190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet::GetTestMaskedInstrument(); 141290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Copy billing address as shipping address, and assign an id to it. 141390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::Address> shipping_address( 141490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) new wallet::Address(instrument->address())); 141590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping_address->set_object_id("shipping_address_id"); 141690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddAddress(shipping_address.Pass()); 141790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(instrument.Pass()); 141890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestShippingAddress()); 141990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 142090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 142190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Select "Same as billing" in the address menu. 142290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) UseBillingForShipping(); 142390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1424eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 142590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 142690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1427a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Test that the local view contents is used when saving a new instrument and 1428a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// the user has selected "Same as billing". 1429a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) { 1430a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1431a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1432a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1433a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1434a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->EditClickedForSection(SECTION_CC_BILLING); 1435a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->OnAccept(); 1436a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1437a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DetailOutputMap outputs; 1438a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const DetailInputs& inputs = 1439a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_CC_BILLING); 1440a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) for (size_t i = 0; i < inputs.size(); ++i) { 1441a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const DetailInput& input = inputs[i]; 1442a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) outputs[&input] = input.type == ADDRESS_BILLING_LINE1 ? 1443a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) ASCIIToUTF16(kEditedBillingAddress) : input.initial_value; 1444a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 1445a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); 1446a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1447a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1448ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(testing::NotNull(), 1449ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch UsesLocalBillingAddress(), 1450ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch _)).Times(1); 1451eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 1452a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 1453a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1454c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, CancelNoSave) { 1455c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1456ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SaveToWalletMock(_, _, _)).Times(0); 14572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 14592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 14612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller()->OnCancel(); 14622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 14632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1464c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Checks that clicking the Manage menu item opens a new tab with a different 1465c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// URL for Wallet and Autofill. 1466c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ManageItem) { 146790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 1468c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) full_profile.set_origin(kSettingsOrigin); 1469c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 1470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1471c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 1472c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 147390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SuggestionsMenuModel* shipping = static_cast<SuggestionsMenuModel*>( 1474c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->MenuModelForSection(SECTION_SHIPPING)); 147590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shipping->ExecuteCommand(shipping->GetItemCount() - 1, 0); 1476c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GURL autofill_manage_url = controller()->open_tab_url(); 1477c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ("chrome", autofill_manage_url.scheme()); 1478c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1479c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToWallet(); 148090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 148190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 148290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1483c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 148490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->SuggestionItemSelected(shipping, shipping->GetItemCount() - 1); 148590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) GURL wallet_manage_addresses_url = controller()->open_tab_url(); 148690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("https", wallet_manage_addresses_url.scheme()); 148790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 148890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SuggestionsMenuModel* billing = static_cast<SuggestionsMenuModel*>( 148990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->MenuModelForSection(SECTION_CC_BILLING)); 149090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->SuggestionItemSelected(billing, billing->GetItemCount() - 1); 149190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) GURL wallet_manage_instruments_url = controller()->open_tab_url(); 149290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("https", wallet_manage_instruments_url.scheme()); 149390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 149490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_NE(autofill_manage_url, wallet_manage_instruments_url); 149590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_NE(wallet_manage_instruments_url, wallet_manage_addresses_url); 1496c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1497c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 14983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, EditClicked) { 1499c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 1500c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 150190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 1502c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const string16 kEmail = ASCIIToUTF16("first@johndoe.com"); 1503c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail); 1504c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1505c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1506c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::MenuModel* email_model = 1507c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->MenuModelForSection(SECTION_EMAIL); 1508c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(3, email_model->GetItemCount()); 1509c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1510c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // When unedited, the initial_value should be empty. 1511c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) email_model->ActivatedAt(0); 1512c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInputs& inputs0 = 1513c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_EMAIL); 1514c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(string16(), inputs0[0].initial_value); 1515c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kEmail, 1516c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch controller()->SuggestionStateForSection(SECTION_EMAIL). 1517c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch vertically_compact_text); 1518c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1519c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // When edited, the initial_value should contain the value. 1520c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->EditClickedForSection(SECTION_EMAIL); 1521c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInputs& inputs1 = 1522c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_EMAIL); 1523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kEmail, inputs1[0].initial_value); 1524c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch EXPECT_FALSE(controller()->SuggestionStateForSection(SECTION_EMAIL).visible); 1525c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1526c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1527c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that editing an autofill profile and then submitting works. 1528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, EditAutofillProfile) { 1529c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 1530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1531ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); 1532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 153390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 1534ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch CreditCard credit_card(test::GetVerifiedCreditCard()); 1535c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1536ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1537c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->EditClickedForSection(SECTION_SHIPPING); 1538c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1539c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DetailOutputMap outputs; 1540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInputs& inputs = 1541c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_SHIPPING); 1542c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < inputs.size(); ++i) { 1543c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInput& input = inputs[i]; 1544c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) outputs[&input] = input.type == NAME_FULL ? ASCIIToUTF16("Edited Name") : 1545c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) input.initial_value; 1546c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1547c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs); 1548c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1549c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // We also have to simulate CC inputs to keep the controller happy. 1550c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FillCreditCardInputs(); 1551c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1552c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnAccept(); 1553c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const AutofillProfile& edited_profile = 1554c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->imported_profile(); 1555c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1556c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < inputs.size(); ++i) { 1557c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInput& input = inputs[i]; 1558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(input.type == NAME_FULL ? ASCIIToUTF16("Edited Name") : 1559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) input.initial_value, 15603240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch edited_profile.GetInfo(AutofillType(input.type), "en-US")); 1561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that adding an autofill profile and then submitting works. 1565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AddAutofillProfile) { 1566ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch SwitchToAutofill(); 15677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); 1568c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 156990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 15707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch CreditCard credit_card(test::GetVerifiedCreditCard()); 1571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 15727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 1573c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::MenuModel* model = controller()->MenuModelForSection(SECTION_BILLING); 1575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Activate the "Add billing address" menu item. 1576c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) model->ActivatedAt(model->GetItemCount() - 2); 1577c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1578c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Fill in the inputs from the profile. 1579c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DetailOutputMap outputs; 1580c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInputs& inputs = 1581c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_BILLING); 158290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile2(test::GetVerifiedProfile2()); 1583c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < inputs.size(); ++i) { 1584c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInput& input = inputs[i]; 15853240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch outputs[&input] = full_profile2.GetInfo(AutofillType(input.type), "en-US"); 1586c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1587c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetView()->SetUserInput(SECTION_BILLING, outputs); 1588c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1589c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnAccept(); 1590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const AutofillProfile& added_profile = 1591c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->imported_profile(); 1592c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInputs& shipping_inputs = 1594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_SHIPPING); 1595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < shipping_inputs.size(); ++i) { 1596c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DetailInput& input = shipping_inputs[i]; 15973240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch EXPECT_EQ(full_profile2.GetInfo(AutofillType(input.type), "en-US"), 15983240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch added_profile.GetInfo(AutofillType(input.type), "en-US")); 1599c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 160090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 160190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Also, the currently selected email address should get added to the new 160290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // profile. 16033240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch string16 original_email = 16043240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch full_profile.GetInfo(AutofillType(EMAIL_ADDRESS), "en-US"); 160590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(original_email.empty()); 160690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(original_email, 16073240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch added_profile.GetInfo(AutofillType(EMAIL_ADDRESS), "en-US")); 160890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 160990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 161090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Makes sure that a newly added email address gets added to an existing profile 161190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// (as opposed to creating its own profile). http://crbug.com/240926 161290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AddEmail) { 1613ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch SwitchToAutofill(); 1614ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); 161590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 161690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 1617ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch CreditCard credit_card(test::GetVerifiedCreditCard()); 161890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1619ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 162090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 162190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ui::MenuModel* model = controller()->MenuModelForSection(SECTION_EMAIL); 162290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(model); 162390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Activate the "Add email address" menu item. 162490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) model->ActivatedAt(model->GetItemCount() - 2); 162590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 162690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Fill in the inputs from the profile. 162790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DetailOutputMap outputs; 162890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const DetailInputs& inputs = 162990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_EMAIL); 163090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const DetailInput& input = inputs[0]; 163190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) string16 new_email = ASCIIToUTF16("addemailtest@example.com"); 163290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) outputs[&input] = new_email; 163390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->GetView()->SetUserInput(SECTION_EMAIL, outputs); 163490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 163590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FillCreditCardInputs(); 163690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 163790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<base::string16> email_values; 16383240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch full_profile.GetMultiInfo( 16393240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch AutofillType(EMAIL_ADDRESS), "en-US", &email_values); 164090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_EQ(2U, email_values.size()); 164190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(new_email, email_values[1]); 1642c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1643c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1644c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, VerifyCvv) { 1645c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1646c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetFullWallet(_)).Times(1); 1647c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1648ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch AuthenticateInstrument(_, _)).Times(1); 1649c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1650eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 1651c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1652c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); 1653c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); 1654c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); 1655c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 16567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1657c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1658c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SuggestionState suggestion_state = 1659c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->SuggestionStateForSection(SECTION_CC_BILLING); 1660c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(suggestion_state.extra_text.empty()); 1661c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1662868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv")); 1663c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1664c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE( 1665c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); 1666c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); 1667c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); 1668c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1669c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) suggestion_state = 1670c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->SuggestionStateForSection(SECTION_CC_BILLING); 1671c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(suggestion_state.extra_text.empty()); 1672c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); 1673c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1674c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1675c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1676c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1677c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnAccept(); 1678c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1679c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1680c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { 1681c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1682c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetFullWallet(_)).Times(1); 1683c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1684eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 1685c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1686c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 16877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1688c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1689c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); 1690c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1691c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1692c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1693c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1694c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1695c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(dbeam): disallow changing accounts instead and remove this test. 1696c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) { 1697c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1698c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetFullWallet(_)).Times(1); 1699c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1700eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 1701c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1702c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 17037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1704c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1705c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToWallet(); 1706c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 1707c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1708c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1709c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1710c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1711c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1712c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { 1713c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1714c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetFullWallet(_)).Times(1); 1715c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1716eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 1717868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv")); 1718c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1719c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1720c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1721c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1722c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); 1723c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1724c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1725c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1726c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1727c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1728c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(dbeam): disallow changing accounts instead and remove this test. 1729c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { 1730c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 1731c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetFullWallet(_)).Times(1); 1732c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1733eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 1734868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetFullWallet(CreateFullWallet("verify_cvv")); 1735c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1736c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1737c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1738c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1739c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToWallet(); 1740c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 1741c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1742c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1743c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1744c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1745c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1746a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Simulates receiving an INVALID_FORM_FIELD required action while processing a 1747a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// |WalletClientDelegate::OnDid{Save,Update}*()| call. This can happen if Online 1748a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Wallet's server validation differs from Chrome's local validation. 17497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletServerSideValidation) { 1750a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1751a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1752a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1753a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) controller()->OnAccept(); 1754a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1755a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) std::vector<wallet::RequiredAction> required_actions; 1756a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) required_actions.push_back(wallet::INVALID_FORM_FIELD); 17577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 17587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::vector<wallet::FormFieldError> form_errors; 17597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) form_errors.push_back( 17607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) wallet::FormFieldError(wallet::FormFieldError::INVALID_POSTAL_CODE, 17617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) wallet::FormFieldError::SHIPPING_ADDRESS)); 17627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 17637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1); 1764ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch controller()->OnDidSaveToWallet(std::string(), 1765ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch std::string(), 1766ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch required_actions, 1767ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch form_errors); 17687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 17697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 17707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Simulates receiving unrecoverable Wallet server validation errors. 17717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletServerSideValidationUnrecoverable) { 17727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 17737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 17747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 17757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->OnAccept(); 17767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 17777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::vector<wallet::RequiredAction> required_actions; 17787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) required_actions.push_back(wallet::INVALID_FORM_FIELD); 17797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 17807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::vector<wallet::FormFieldError> form_errors; 17817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) form_errors.push_back( 17827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) wallet::FormFieldError(wallet::FormFieldError::UNKNOWN_ERROR, 17837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) wallet::FormFieldError::UNKNOWN_LOCATION)); 17847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1785ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch controller()->OnDidSaveToWallet(std::string(), 1786ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch std::string(), 1787ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch required_actions, 1788ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch form_errors); 1789a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1790a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 1791a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DialogNotification::REQUIRED_ACTION).size()); 1792a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 1793a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1794868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Test Wallet banners are show in the right situations. These banners explain 1795868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// where Chrome got the user's data (i.e. "Got details from Wallet") or promote 1796868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// saving details into Wallet (i.e. "[x] Save details to Wallet"). 1797868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletBanners) { 1798eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CommandLine* command_line = CommandLine::ForCurrentProcess(); 1799eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line->AppendSwitch(switches::kWalletServiceUseProd); 18007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch PrefService* prefs = profile()->GetPrefs(); 18017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 18027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Simulate first run. 18037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, false); 18047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SetUpControllerWithFormData(DefaultFormData()); 1805868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1806868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1807868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1808868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1809868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1810868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1811868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Sign in a user with a completed account. 1812eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 1813c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1814868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Full account; should show "Details from Wallet" message. 1815c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 1816c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1817868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1818868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1819c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1820868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Full account; no "[x] Save details in Wallet" option should show. 1821c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 1822868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1823868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1824868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1825868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1826c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1827868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SetUpControllerWithFormData(DefaultFormData()); 1828868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |controller()| has already been initialized. Test that should not take 1829868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // effect until the next call of |SetUpControllerWithFormData()|. 1830868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, true); 1831c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1832868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Sign in a user with a incomplete account. 1833eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1834c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1835c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1836c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1837868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Partial account; no "Details from Wallet" message should show, but a 1838868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // "[x] Save details in Wallet" should. 1839868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1840868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1841868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 1842868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1843c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1844868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Once the usage confirmation banner is shown once, it keeps showing even if 1845868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // the user switches to Autofill data. 1846c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 1847868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1848868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1849868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 1850868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1851c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1852868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // A Wallet error should kill any Wallet promos. 1853868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); 1854c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1855868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 1856868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_ERROR).size()); 1857868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1858868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1859868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1860868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1861c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1862868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SetUpControllerWithFormData(DefaultFormData()); 1863868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |controller()| is error free and thinks the user has already paid w/Wallet. 1864c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1865868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // User has already paid with wallet. Don't show promos. 1866868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1867868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1868868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1869868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1870868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1871eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 1872c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1873868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1874868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1875868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1876868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1877868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1878868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) wallet_items = wallet::GetTestWalletItems(); 1879868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1880868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 1881868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1882868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SwitchToAutofill(); 1883868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1884868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::EXPLANATORY_MESSAGE).size()); 1885868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 1886868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1887c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1888c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 188990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, OnAutocheckoutError) { 189090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SwitchToAutofill(); 189190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); 189290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 189390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // We also have to simulate CC inputs to keep the controller happy. 189490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) FillCreditCardInputs(); 189590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 189690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 1897ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); 189890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAutocheckoutError(); 189990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1900ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_FALSE(controller()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL); 1901ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 190290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 190390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DialogNotification::AUTOCHECKOUT_SUCCESS).size()); 190490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 190590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DialogNotification::AUTOCHECKOUT_ERROR).size()); 1906ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 1907ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch controller()->ViewClosed(); 1908ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc()); 190990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 191090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 191190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, OnAutocheckoutSuccess) { 1912eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CommandLine* command_line = CommandLine::ForCurrentProcess(); 1913eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line->AppendSwitch(switches::kWalletServiceUseProd); 191490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); 191590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Simulate first run. 19177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch profile()->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, 19187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch false); 19197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SetUpControllerWithFormData(DefaultFormData()); 19207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); 19217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1922eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Sign in a user with a completed account. 1923eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 1924eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1925eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Full account; should show "Details from Wallet" message. 1926eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(1U, NotificationsOfType( 1927eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DialogNotification::EXPLANATORY_MESSAGE).size()); 1928eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(0U, NotificationsOfType( 1929eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DialogNotification::WALLET_USAGE_CONFIRMATION).size()); 1930eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1931eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AcceptAndLoadFakeFingerprint(); 1932ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); 1933eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 19347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); 1935eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1936eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(0U, NotificationsOfType( 1937eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DialogNotification::EXPLANATORY_MESSAGE).size()); 193890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 193990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAutocheckoutSuccess(); 19407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); 194190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1942ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_FALSE(controller()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL); 1943ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 194490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 194590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DialogNotification::AUTOCHECKOUT_SUCCESS).size()); 194690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 194790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DialogNotification::AUTOCHECKOUT_ERROR).size()); 1948eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(0U, NotificationsOfType( 1949eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DialogNotification::EXPLANATORY_MESSAGE).size()); 19507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( 19517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ::prefs::kAutofillDialogHasPaidWithWallet)); 1952ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 1953ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch controller()->ViewClosed(); 1954ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc()); 195590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 195690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1957c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ViewCancelDoesntSetPref) { 1958c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( 1959c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 1960c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1961c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 1962c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1963c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnCancel(); 1964c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->ViewClosed(); 1965c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1966c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( 1967c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 1968c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1969c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1970868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, SubmitWithSigninErrorDoesntSetPref) { 1971868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( 1972868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 1973868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1974868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SimulateSigninError(); 1975868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FillCreditCardInputs(); 1976868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnAccept(); 1977868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1978868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( 1979868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 1980868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 1981868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 19827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Tests that there's an overlay shown while waiting for full wallet items, 19837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// and on first run an additional expository wallet overlay shown after full 19847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// wallet items are returned. 19857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// TODO(estade): enable on other platforms when overlays are supported there. 19867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#if defined(TOOLKIT_VIEWS) 19877dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, WalletFirstRun) { 19887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Simulate first run. 19897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch PrefService* prefs = profile()->GetPrefs(); 19907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, false); 19917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SetUpControllerWithFormData(DefaultFormData()); 19927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 19937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SwitchToWallet(); 19947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); 19957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 19967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 19977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty()); 19987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 19997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet)); 20007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 20017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet)); 20027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty()); 20037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(form_structure()); 20047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 20057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->OverlayButtonPressed(); 20067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet)); 20077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(form_structure()); 20087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 20097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif 20107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 20117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// On second run, the second overlay doesn't show. 20127dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, WalletSecondRun) { 20137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SwitchToWallet(); 20147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); 20157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 20167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 20177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty()); 20187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 20197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( 20207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ::prefs::kAutofillDialogHasPaidWithWallet)); 20217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 20227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( 20237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ::prefs::kAutofillDialogHasPaidWithWallet)); 20247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(form_structure()); 20257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 20267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2027c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { 2028c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( 2029c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2030c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2031c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 2032868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FillCreditCardInputs(); 2033868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnAccept(); 2034c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2035868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( 2036868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2037868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( 2038868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2039868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2040868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Try again with a signin error (just leaves the pref alone). 2041868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SetUpControllerWithFormData(DefaultFormData()); 2042868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2043868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Setting up the controller again should not change the pref. 2044868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( 2045868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2046868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( 2047868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2048868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2049868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SimulateSigninError(); 2050c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FillCreditCardInputs(); 2051868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnAccept(); 2052868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( 2053868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2054868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( 2055868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2056868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2057868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Succesfully choosing wallet does set the pref. 2058868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SetUpControllerWithFormData(DefaultFormData()); 2059c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2060868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SwitchToWallet(); 2061868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 2062868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 2063868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 2064c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnAccept(); 2065868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2066c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2067c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( 2068c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2069868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( 2070c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ::prefs::kAutofillDialogPayWithoutWallet)); 2071c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 2072c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2073c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, HideWalletEmail) { 2074c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToAutofill(); 2075c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2076c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Email section should be showing when using Autofill. 2077c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL)); 2078c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2079c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SwitchToWallet(); 2080c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2081c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Setup some wallet state, submit, and get a full wallet to end the flow. 2082eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<wallet::WalletItems> wallet_items = CompleteAndValidWalletItems(); 2083c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2084c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Filling |form_structure()| depends on the current username and wallet items 2085c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // being fetched. Until both of these have occurred, the user should not be 2086c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // able to click Submit if using Wallet. The username fetch happened earlier. 2087c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 2088c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 2089c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 2090c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2091c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Email section should be hidden when using Wallet. 2092c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); 2093c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2094c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnAccept(); 2095c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2096c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2097c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) size_t i = 0; 2098c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (; i < form_structure()->field_count(); ++i) { 2099bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch if (form_structure()->field(i)->Type().GetStorableType() == EMAIL_ADDRESS) { 2100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(ASCIIToUTF16(kFakeEmail), form_structure()->field(i)->value); 2101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) break; 2102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 2103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 2104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_LT(i, form_structure()->field_count()); 2105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 2106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2107b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Test if autofill types of returned form structure are correct for billing 2108b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// entries. 2109b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, AutofillTypes) { 21107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 2111b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->OnAccept(); 2112b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_EQ(20U, form_structure()->field_count()); 2114bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(EMAIL_ADDRESS, 2115bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(0)->Type().GetStorableType()); 21163240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch EXPECT_EQ(CREDIT_CARD_NUMBER, 2117bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(2)->Type().GetStorableType()); 2118bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_HOME_STATE, 2119bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(9)->Type().GetStorableType()); 2120bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group()); 21213240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch EXPECT_EQ(ADDRESS_HOME_STATE, 2122bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch form_structure()->field(16)->Type().GetStorableType()); 2123bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group()); 2124b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 2125b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 2126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, SaveDetailsInChrome) { 2127ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch SwitchToAutofill(); 2128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); 2129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 213090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 2131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 2132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 213390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard card(test::GetVerifiedCreditCard()); 2134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->GetTestingManager()->AddTestingCreditCard(&card); 2135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 2136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->EditClickedForSection(SECTION_EMAIL); 2138c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 2139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 21403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(0); 2141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 2142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 2144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 2145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 21463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->ForceIncognito(true); 2147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 2148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 2149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 215090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Tests that user is prompted when using instrument with minimal address. 215190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) { 2152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // A minimal address being selected should trigger error validation in the 2153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // view. Called once for each incomplete suggestion. 2154eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1); 2155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 215690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 215790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentWithIdAndAddress( 215890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) "id", wallet::GetTestMinimalAddress())); 215990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::Address> address(wallet::GetTestShippingAddress()); 216090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) address->set_is_complete_address(false); 216190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddAddress(address.Pass()); 216290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 216390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 216490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Assert that dialog's SECTION_CC_BILLING section is in edit mode. 2165868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); 216690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Shipping section should be in edit mode because of 216790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // is_minimal_shipping_address. 2168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_TRUE(controller()->IsEditingExistingData(SECTION_SHIPPING)); 216990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 217090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 217190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) { 217290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); 217390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 217490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 217590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); 217690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 217790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 217890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 217990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 218090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) { 218190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); 218290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 218390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 218490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); 218590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 218690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 218790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) testing::Mock::VerifyAndClear(controller()); 218890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); 218990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 219090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnAccept(); 219190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 219290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Simulate a risk load and verify |GetRiskData()| matches the encoded value. 219390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidAcceptLegalDocuments(); 219490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); 219590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData()); 219690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 219790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 219890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(AutofillDialogControllerTest, NoManageMenuItemForNewWalletUsers) { 219990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Make sure the menu model item is created for a returning Wallet user. 220090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 220190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 220290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet_items->AddAddress(wallet::GetTestShippingAddress()); 220390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 220490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 220590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)); 220690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // "Same as billing", "123 address", "Add address...", and "Manage addresses". 220790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ( 220890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 220990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 221090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Make sure the menu model item is not created for new Wallet users. 221190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::DictionaryValue dict; 221290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<base::ListValue> required_actions(new base::ListValue); 221390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) required_actions->AppendString("setup_wallet"); 221490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) dict.Set("required_action", required_actions.release()); 221590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller()->OnDidGetWalletItems( 221690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) wallet::WalletItems::CreateWalletItems(dict).Pass()); 221790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 221890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); 221990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // "Same as billing" and "Add address...". 222090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ( 222190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 222290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 222390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2224868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHidden) { 2225868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SwitchToAutofill(); 2226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2227868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FormFieldData email_field; 2228868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) email_field.autocomplete_attribute = "email"; 2229868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FormFieldData cc_field; 2230868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) cc_field.autocomplete_attribute = "cc-number"; 2231868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FormFieldData billing_field; 2232868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) billing_field.autocomplete_attribute = "billing region"; 2233868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FormData form_data; 2235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) form_data.fields.push_back(email_field); 2236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) form_data.fields.push_back(cc_field); 2237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) form_data.fields.push_back(billing_field); 2238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AutofillProfile full_profile(test::GetVerifiedProfile()); 2240868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->GetTestingManager()->AddTestingProfile(&full_profile); 2241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SetUpControllerWithFormData(form_data); 2242868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); 2243868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2244868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FillCreditCardInputs(); 2245868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnAccept(); 2246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(form_structure()); 2247868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 2248868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2249a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHiddenForWallet) { 2250a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SwitchToWallet(); 2251a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2252a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) FormFieldData email_field; 2253a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) email_field.autocomplete_attribute = "email"; 2254a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) FormFieldData cc_field; 2255a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) cc_field.autocomplete_attribute = "cc-number"; 2256a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) FormFieldData billing_field; 2257a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) billing_field.autocomplete_attribute = "billing region"; 2258a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2259a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) FormData form_data; 2260a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) form_data.fields.push_back(email_field); 2261a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) form_data.fields.push_back(cc_field); 2262a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) form_data.fields.push_back(billing_field); 2263a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2264a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetUpControllerWithFormData(form_data); 2265a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); 2266a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_FALSE(controller()->IsShippingAddressRequired()); 2267a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2268a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 2269a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) GetFullWallet(_)).Times(1); 2270a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 2271a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 2272a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SubmitWithWalletItems(wallet_items.Pass()); 2273a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->OnDidGetFullWallet(wallet::GetTestFullWalletInstrumentOnly()); 2274a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(form_structure()); 2275a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 2276a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2277868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, NotProdNotification) { 2278868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // To make IsPayingWithWallet() true. 2279868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 2280868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2281868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CommandLine* command_line = CommandLine::ForCurrentProcess(); 2282868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_FALSE(command_line->HasSwitch(switches::kWalletServiceUseProd)); 2283868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE( 2284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty()); 2285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) command_line->AppendSwitch(switches::kWalletServiceUseProd); 2287868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE( 2288868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty()); 2289868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 2290868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2291868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Ensure Wallet instruments marked expired by the server are shown as invalid. 2292868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, WalletExpiredCard) { 2293868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 2294868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); 2295868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetWalletItems(wallet_items.Pass()); 2296868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2297868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING)); 2298868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 22993240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // Use |SetOutputValue()| to put the right ServerFieldTypes into the map. 2300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const DetailInputs& inputs = 2301868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->RequestedFieldsForSection(SECTION_CC_BILLING); 2302868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DetailOutputMap outputs; 2303a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, COMPANY_NAME, ASCIIToUTF16("Bluth Company")); 2304868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2305868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ValidityData validity_data = 23067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT); 2307868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 2308868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 2309868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2310868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Make the local input year differ from the instrument. 2311a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_4_DIGIT_YEAR, 2312a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASCIIToUTF16("3002")); 2313868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 23147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 23157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT); 2316868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 2317868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 2318868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2319868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Make the local input month differ from the instrument. 2320a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SetOutputValue(inputs, &outputs, CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06")); 2321868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 23227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) validity_data = 23237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller()->InputsAreValid(SECTION_CC_BILLING, outputs, VALIDATE_EDIT); 2324868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_MONTH)); 2325868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 2326868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 2327868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2328868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, ChooseAnotherInstrumentOrAddress) { 2329eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 2330868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2331868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 2332868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::REQUIRED_ACTION).size()); 2333868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_CALL(*controller()->GetTestingWalletClient(), 2334868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GetWalletItems(_)).Times(1); 2335868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnDidGetFullWallet( 2336868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CreateFullWallet("choose_another_instrument_or_address")); 2337868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(1U, NotificationsOfType( 2338868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::REQUIRED_ACTION).size()); 2339eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 2340868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2341868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) controller()->OnAccept(); 2342868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(0U, NotificationsOfType( 2343868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DialogNotification::REQUIRED_ACTION).size()); 2344868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 2345868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2346eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Make sure detailed steps for Autocheckout are added 2347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// and updated correctly. 2348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillDialogControllerTest, DetailedSteps) { 2349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_CALL(*controller()->GetTestingWalletClient(), 23507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch GetFullWallet(_)).Times(1); 2351eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2352eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); 2353eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2354eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Add steps as would normally be done by the AutocheckoutManager. 2355eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING); 2356eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY); 2357eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_BILLING); 2358eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2359eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 2360eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 2361eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallet_items->AddAddress(wallet::GetTestShippingAddress()); 2362eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidGetWalletItems(wallet_items.Pass()); 2363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Initiate flow - should add proxy card step since the user is using wallet 2364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // data. 2365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnAccept(); 2366ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); 2367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); 2368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2369eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SuggestionState suggestion_state = 2370eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->SuggestionStateForSection(SECTION_CC_BILLING); 2371eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(suggestion_state.extra_text.empty()); 2372eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2373eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // There should be four steps total, with the first being the card generation 2374eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // step added by the dialog controller. 2375eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(4U, controller()->CurrentAutocheckoutSteps().size()); 2376eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_PROXY_CARD, 2377eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[0].type()); 2378eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED, 2379eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[0].status()); 2380eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2381eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Simulate a wallet error. This should remove the card generation step from 2382eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // the flow, as we will have to proceed with local data. 2383eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); 2384eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2385eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile shipping_profile(test::GetVerifiedProfile()); 2386eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile billing_profile(test::GetVerifiedProfile2()); 2387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreditCard credit_card(test::GetVerifiedCreditCard()); 2388eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); 2389eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->GetTestingManager()->AddTestingProfile(&billing_profile); 2390eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 2391eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui::MenuModel* billing_model = 2392eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->MenuModelForSection(SECTION_BILLING); 2393eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch billing_model->ActivatedAt(1); 2394eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2395eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Re-initiate flow. 2396eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->OnAccept(); 2397ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); 2398eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2399eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // All steps should be initially unstarted. 2400eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size()); 2401eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING, 2402eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[0].type()); 2403eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, 2404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[0].status()); 2405eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY, 2406eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[1].type()); 2407eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, 2408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[1].status()); 2409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING, 2410eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[2].type()); 2411eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, 2412eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[2].status()); 2413eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2414eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Update steps in the same manner that we would expect to see from the 2415eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // AutocheckoutManager while progressing through a flow. 2416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING, 2417eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AUTOCHECKOUT_STEP_STARTED); 2418eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING, 2419eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AUTOCHECKOUT_STEP_COMPLETED); 2420eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY, 2421eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AUTOCHECKOUT_STEP_STARTED); 2422eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2423eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Verify that the steps were appropriately updated. 2424eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size()); 2425eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING, 2426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[0].type()); 2427eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_COMPLETED, 2428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[0].status()); 2429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY, 2430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[1].type()); 2431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED, 2432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[1].status()); 2433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING, 2434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[2].type()); 2435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, 2436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller()->CurrentAutocheckoutSteps()[2].status()); 2437ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 2438ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch controller()->ViewClosed(); 2439ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc()); 2440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 2441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 24427dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, NewCardBubbleShown) { 2443ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(0); 24447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 24457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SwitchToAutofill(); 24467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch FillCreditCardInputs(); 24477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->OnAccept(); 24487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->ViewClosed(); 2449ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 2450ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_EQ(1, mock_new_card_bubble_controller()->bubbles_shown()); 24517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 24527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 24537dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(AutofillDialogControllerTest, GeneratedCardBubbleShown) { 2454ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(1); 24557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 24567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch SubmitWithWalletItems(CompleteAndValidWalletItems()); 24577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 24587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch controller()->ViewClosed(); 2459ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 2460ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown()); 24617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 24627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 246358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben MurdochTEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { 246458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // Switch into Wallet mode and initialize some Wallet data. 246558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch SwitchToWallet(); 246658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch 246758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 246858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 246958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 247058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); 247158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddAddress(wallet::GetTestShippingAddress()); 247258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch controller()->OnDidGetWalletItems(wallet_items.Pass()); 247358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch 247458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // Initially, the default entries should be selected. 247558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ui::MenuModel* cc_billing_model = 247658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch controller()->MenuModelForSection(SECTION_CC_BILLING); 247758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ui::MenuModel* shipping_model = 247858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch controller()->MenuModelForSection(SECTION_SHIPPING); 247958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // "add", "manage", and 2 suggestions. 248058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ASSERT_EQ(4, cc_billing_model->GetItemCount()); 248158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0)); 248258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // "use billing", "add", "manage", and 2 suggestions. 248358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ASSERT_EQ(5, shipping_model->GetItemCount()); 248458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch EXPECT_TRUE(shipping_model->IsItemCheckedAt(2)); 248558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch 248658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // Select entries other than the defaults. 248758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch cc_billing_model->ActivatedAt(1); 248858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch shipping_model->ActivatedAt(1); 248958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // "add", "manage", and 2 suggestions. 249058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ASSERT_EQ(4, cc_billing_model->GetItemCount()); 249158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); 249258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // "use billing", "add", "manage", and 2 suggestions. 249358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ASSERT_EQ(5, shipping_model->GetItemCount()); 249458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch EXPECT_TRUE(shipping_model-> IsItemCheckedAt(1)); 249558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch 249658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // Simulate switching away from the tab and back. This should issue a request 249758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // for wallet items. 249858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); 249958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch controller()->TabActivated(); 250058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch 250158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // Simulate a response that includes different items. 250258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items = wallet::GetTestWalletItems(); 250358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); 250458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 250558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 250658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); 250758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch controller()->OnDidGetWalletItems(wallet_items.Pass()); 250858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch 250958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // The previously selected entries should still be selected. 251058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // "add", "manage", and 3 suggestions. 251158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ASSERT_EQ(5, cc_billing_model->GetItemCount()); 251258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(2)); 251358e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // "use billing", "add", "manage", and 1 suggestion. 251458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch ASSERT_EQ(4, shipping_model->GetItemCount()); 251558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); 251658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch} 251758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch 2518558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochTEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) { 2519558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch SwitchToWallet(); 2520558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 2521558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); 2522558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(1); 2523558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); 2524558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 2525558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); 2526558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch controller()->TabActivated(); 2527558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 2528558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 2529558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 2530558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); 2531558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch EXPECT_EQ( 2532558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 2533558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} 2534558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 2535a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleNotShown) { 2536ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(0); 2537a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2538a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) SubmitWithWalletItems(CompleteAndValidWalletItems()); 2539a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); 2540a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2541a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->OnAutocheckoutError(); 2542a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) controller()->ViewClosed(); 2543ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 2544ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown()); 2545a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 2546a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 25472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace autofill 2548