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 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 | 1641 |
1631 SwitchToAutofill(); | 1642 SwitchToAutofill(); |
1632 | 1643 |
1633 controller()->OnCancel(); | 1644 controller()->OnCancel(); |
1634 controller()->ViewClosed(); | 1645 controller()->ViewClosed(); |
1635 | 1646 |
1636 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1647 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( |
1637 ::prefs::kAutofillDialogPayWithoutWallet)); | 1648 ::prefs::kAutofillDialogPayWithoutWallet)); |
1638 } | 1649 } |
1639 | 1650 |
| 1651 TEST_F(AutofillDialogControllerTest, SubmitWithSigninErrorDoesntSetPref) { |
| 1652 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| 1653 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1654 |
| 1655 SimulateSigninError(); |
| 1656 FillCreditCardInputs(); |
| 1657 controller()->OnAccept(); |
| 1658 |
| 1659 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( |
| 1660 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1661 } |
| 1662 |
1640 TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { | 1663 TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { |
1641 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1664 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
1642 ::prefs::kAutofillDialogPayWithoutWallet)); | 1665 ::prefs::kAutofillDialogPayWithoutWallet)); |
1643 | 1666 |
1644 SwitchToAutofill(); | 1667 SwitchToAutofill(); |
1645 | |
1646 // We also have to simulate CC inputs to keep the controller happy. | |
1647 FillCreditCardInputs(); | 1668 FillCreditCardInputs(); |
1648 | |
1649 controller()->OnAccept(); | 1669 controller()->OnAccept(); |
1650 | 1670 |
1651 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( | 1671 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
1652 ::prefs::kAutofillDialogPayWithoutWallet)); | 1672 ::prefs::kAutofillDialogPayWithoutWallet)); |
1653 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( | 1673 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
1654 ::prefs::kAutofillDialogPayWithoutWallet)); | 1674 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1675 |
| 1676 // Try again with a signin error (just leaves the pref alone). |
| 1677 SetUpControllerWithFormData(DefaultFormData()); |
| 1678 |
| 1679 // Setting up the controller again should not change the pref. |
| 1680 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| 1681 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1682 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| 1683 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1684 |
| 1685 SimulateSigninError(); |
| 1686 FillCreditCardInputs(); |
| 1687 controller()->OnAccept(); |
| 1688 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| 1689 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1690 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| 1691 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1692 |
| 1693 // Succesfully choosing wallet does set the pref. |
| 1694 SetUpControllerWithFormData(DefaultFormData()); |
| 1695 |
| 1696 SwitchToWallet(); |
| 1697 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 1698 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 1699 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 1700 controller()->OnAccept(); |
| 1701 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
| 1702 |
| 1703 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
| 1704 ::prefs::kAutofillDialogPayWithoutWallet)); |
| 1705 EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1706 ::prefs::kAutofillDialogPayWithoutWallet)); |
1655 } | 1707 } |
1656 | 1708 |
1657 TEST_F(AutofillDialogControllerTest, HideWalletEmail) { | 1709 TEST_F(AutofillDialogControllerTest, HideWalletEmail) { |
1658 SwitchToAutofill(); | 1710 SwitchToAutofill(); |
1659 | 1711 |
1660 // Email section should be showing when using Autofill. | 1712 // Email section should be showing when using Autofill. |
1661 EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL)); | 1713 EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL)); |
1662 | 1714 |
1663 SwitchToWallet(); | 1715 SwitchToWallet(); |
1664 | 1716 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 controller()->OnDidGetWalletItems( | 1860 controller()->OnDidGetWalletItems( |
1809 wallet::WalletItems::CreateWalletItems(dict).Pass()); | 1861 wallet::WalletItems::CreateWalletItems(dict).Pass()); |
1810 | 1862 |
1811 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); | 1863 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
1812 // "Same as billing" and "Add address...". | 1864 // "Same as billing" and "Add address...". |
1813 EXPECT_EQ( | 1865 EXPECT_EQ( |
1814 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 1866 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
1815 } | 1867 } |
1816 | 1868 |
1817 } // namespace autofill | 1869 } // namespace autofill |
OLD | NEW |