| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/guid.h" | 5 #include "base/guid.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } | 241 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } |
| 242 | 242 |
| 243 bool IsSectionInEditState(DialogSection section) { | 243 bool IsSectionInEditState(DialogSection section) { |
| 244 std::map<DialogSection, bool> state = section_editing_state(); | 244 std::map<DialogSection, bool> state = section_editing_state(); |
| 245 return state[section]; | 245 return state[section]; |
| 246 } | 246 } |
| 247 | 247 |
| 248 MOCK_METHOD0(LoadRiskFingerprintData, void()); | 248 MOCK_METHOD0(LoadRiskFingerprintData, void()); |
| 249 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 249 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
| 250 | 250 |
| 251 void SimulateSigninError() { |
| 252 OnWalletSigninError(); |
| 253 } |
| 254 |
| 251 protected: | 255 protected: |
| 252 virtual PersonalDataManager* GetManager() OVERRIDE { | 256 virtual PersonalDataManager* GetManager() OVERRIDE { |
| 253 return &test_manager_; | 257 return &test_manager_; |
| 254 } | 258 } |
| 255 | 259 |
| 256 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 260 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
| 257 return &test_wallet_client_; | 261 return &test_wallet_client_; |
| 258 } | 262 } |
| 259 | 263 |
| 260 virtual bool IsFirstRun() const OVERRIDE { | 264 virtual bool IsFirstRun() const OVERRIDE { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 290 io_thread_(BrowserThread::IO) { | 294 io_thread_(BrowserThread::IO) { |
| 291 file_thread_.Start(); | 295 file_thread_.Start(); |
| 292 file_blocking_thread_.Start(); | 296 file_blocking_thread_.Start(); |
| 293 io_thread_.StartIOThread(); | 297 io_thread_.StartIOThread(); |
| 294 } | 298 } |
| 295 | 299 |
| 296 virtual ~AutofillDialogControllerTest() {} | 300 virtual ~AutofillDialogControllerTest() {} |
| 297 | 301 |
| 298 // testing::Test implementation: | 302 // testing::Test implementation: |
| 299 virtual void SetUp() OVERRIDE { | 303 virtual void SetUp() OVERRIDE { |
| 300 FormData form_data; | |
| 301 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { | |
| 302 FormFieldData field; | |
| 303 field.autocomplete_attribute = kFieldsFromPage[i]; | |
| 304 form_data.fields.push_back(field); | |
| 305 } | |
| 306 | |
| 307 profile()->CreateRequestContext(); | 304 profile()->CreateRequestContext(); |
| 308 test_web_contents_.reset( | 305 test_web_contents_.reset( |
| 309 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 306 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
| 310 | 307 |
| 311 SetUpControllerWithFormData(form_data); | 308 SetUpControllerWithFormData(DefaultFormData()); |
| 312 } | 309 } |
| 313 | 310 |
| 314 virtual void TearDown() OVERRIDE { | 311 virtual void TearDown() OVERRIDE { |
| 315 if (controller_) | 312 if (controller_) |
| 316 controller_->ViewClosed(); | 313 controller_->ViewClosed(); |
| 317 } | 314 } |
| 318 | 315 |
| 319 protected: | 316 protected: |
| 317 FormData DefaultFormData() { |
| 318 FormData form_data; |
| 319 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { |
| 320 FormFieldData field; |
| 321 field.autocomplete_attribute = kFieldsFromPage[i]; |
| 322 form_data.fields.push_back(field); |
| 323 } |
| 324 return form_data; |
| 325 } |
| 326 |
| 320 void SetUpControllerWithFormData(const FormData& form_data) { | 327 void SetUpControllerWithFormData(const FormData& form_data) { |
| 321 if (controller_) | 328 if (controller_) |
| 322 controller_->ViewClosed(); | 329 controller_->ViewClosed(); |
| 323 | 330 |
| 324 base::Callback<void(const FormStructure*, const std::string&)> callback = | 331 base::Callback<void(const FormStructure*, const std::string&)> callback = |
| 325 base::Bind(&AutofillDialogControllerTest::FinishedCallback, | 332 base::Bind(&AutofillDialogControllerTest::FinishedCallback, |
| 326 base::Unretained(this)); | 333 base::Unretained(this)); |
| 327 controller_ = (new testing::NiceMock<TestAutofillDialogController>( | 334 controller_ = (new testing::NiceMock<TestAutofillDialogController>( |
| 328 test_web_contents_.get(), | 335 test_web_contents_.get(), |
| 329 form_data, | 336 form_data, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 void SwitchToAutofill() { | 368 void SwitchToAutofill() { |
| 362 controller_->MenuModelForAccountChooser()->ActivatedAt( | 369 controller_->MenuModelForAccountChooser()->ActivatedAt( |
| 363 TestAccountChooserModel::kAutofillItemId); | 370 TestAccountChooserModel::kAutofillItemId); |
| 364 } | 371 } |
| 365 | 372 |
| 366 void SwitchToWallet() { | 373 void SwitchToWallet() { |
| 367 controller_->MenuModelForAccountChooser()->ActivatedAt( | 374 controller_->MenuModelForAccountChooser()->ActivatedAt( |
| 368 TestAccountChooserModel::kActiveWalletItemId); | 375 TestAccountChooserModel::kActiveWalletItemId); |
| 369 } | 376 } |
| 370 | 377 |
| 378 void SimulateSigninError() { |
| 379 controller_->SimulateSigninError(); |
| 380 } |
| 381 |
| 371 void UseBillingForShipping() { | 382 void UseBillingForShipping() { |
| 372 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); | 383 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(0); |
| 373 } | 384 } |
| 374 | 385 |
| 375 TestAutofillDialogController* controller() { return controller_; } | 386 TestAutofillDialogController* controller() { return controller_; } |
| 376 | 387 |
| 377 TestingProfile* profile() { return &profile_; } | 388 TestingProfile* profile() { return &profile_; } |
| 378 | 389 |
| 379 const FormStructure* form_structure() { return form_structure_; } | 390 const FormStructure* form_structure() { return form_structure_; } |
| 380 | 391 |
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 | 1649 |
| 1639 SwitchToAutofill(); | 1650 SwitchToAutofill(); |
| 1640 | 1651 |
| 1641 controller()->OnCancel(); | 1652 controller()->OnCancel(); |
| 1642 controller()->ViewClosed(); | 1653 controller()->ViewClosed(); |
| 1643 | 1654 |
| 1644 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1655 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| 1645 ::prefs::kAutofillDialogPayWithoutWallet)); | 1656 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1646 } | 1657 } |
| 1647 | 1658 |
| 1659 TEST_F(AutofillDialogControllerTest, SubmitWithSigninErrorDoesntSetPref) { |
| 1660 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| 1661 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1662 |
| 1663 SimulateSigninError(); |
| 1664 FillCreditCardInputs(); |
| 1665 controller()->OnAccept(); |
| 1666 |
| 1667 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| 1668 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1669 } |
| 1670 |
| 1648 TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { | 1671 TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { |
| 1649 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1672 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| 1650 ::prefs::kAutofillDialogPayWithoutWallet)); | 1673 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1651 | 1674 |
| 1652 SwitchToAutofill(); | 1675 SwitchToAutofill(); |
| 1653 | |
| 1654 // We also have to simulate CC inputs to keep the controller happy. | |
| 1655 FillCreditCardInputs(); | 1676 FillCreditCardInputs(); |
| 1656 | |
| 1657 controller()->OnAccept(); | 1677 controller()->OnAccept(); |
| 1658 | 1678 |
| 1659 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( | 1679 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| 1660 ::prefs::kAutofillDialogPayWithoutWallet)); | 1680 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1661 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( | 1681 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| 1662 ::prefs::kAutofillDialogPayWithoutWallet)); | 1682 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1683 |
| 1684 // Try again with a signin error (just leaves the pref alone). |
| 1685 SetUpControllerWithFormData(DefaultFormData()); |
| 1686 |
| 1687 // Setting up the controller again should not change the pref. |
| 1688 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| 1689 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1690 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| 1691 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1692 |
| 1693 SimulateSigninError(); |
| 1694 FillCreditCardInputs(); |
| 1695 controller()->OnAccept(); |
| 1696 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| 1697 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1698 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| 1699 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1700 |
| 1701 // Succesfully choosing wallet does set the pref. |
| 1702 SetUpControllerWithFormData(DefaultFormData()); |
| 1703 |
| 1704 SwitchToWallet(); |
| 1705 controller()->OnAccept(); |
| 1706 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| 1707 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1708 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1709 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1663 } | 1710 } |
| 1664 | 1711 |
| 1665 TEST_F(AutofillDialogControllerTest, HideWalletEmail) { | 1712 TEST_F(AutofillDialogControllerTest, HideWalletEmail) { |
| 1666 SwitchToAutofill(); | 1713 SwitchToAutofill(); |
| 1667 | 1714 |
| 1668 // Email section should be showing when using Autofill. | 1715 // Email section should be showing when using Autofill. |
| 1669 EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL)); | 1716 EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL)); |
| 1670 | 1717 |
| 1671 SwitchToWallet(); | 1718 SwitchToWallet(); |
| 1672 | 1719 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 controller()->OnDidGetWalletItems( | 1863 controller()->OnDidGetWalletItems( |
| 1817 wallet::WalletItems::CreateWalletItems(dict).Pass()); | 1864 wallet::WalletItems::CreateWalletItems(dict).Pass()); |
| 1818 | 1865 |
| 1819 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); | 1866 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
| 1820 // "Same as billing" and "Add address...". | 1867 // "Same as billing" and "Add address...". |
| 1821 EXPECT_EQ( | 1868 EXPECT_EQ( |
| 1822 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 1869 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
| 1823 } | 1870 } |
| 1824 | 1871 |
| 1825 } // namespace autofill | 1872 } // namespace autofill |
| OLD | NEW |