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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 AutofillDialogControllerTest() | 331 AutofillDialogControllerTest() |
332 : form_structure_(NULL) { | 332 : form_structure_(NULL) { |
333 } | 333 } |
334 | 334 |
335 // testing::Test implementation: | 335 // testing::Test implementation: |
336 virtual void SetUp() OVERRIDE { | 336 virtual void SetUp() OVERRIDE { |
337 profile()->CreateRequestContext(); | 337 profile()->CreateRequestContext(); |
338 test_web_contents_.reset( | 338 test_web_contents_.reset( |
339 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 339 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
340 | 340 |
| 341 // Don't get stuck on the first run wallet interstitial. |
| 342 profile()->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, |
| 343 true); |
| 344 |
341 SetUpControllerWithFormData(DefaultFormData()); | 345 SetUpControllerWithFormData(DefaultFormData()); |
342 } | 346 } |
343 | 347 |
344 virtual void TearDown() OVERRIDE { | 348 virtual void TearDown() OVERRIDE { |
345 if (controller_.get()) | 349 if (controller_.get()) |
346 controller_->ViewClosed(); | 350 controller_->ViewClosed(); |
347 } | 351 } |
348 | 352 |
349 protected: | 353 protected: |
350 FormData DefaultFormData() { | 354 FormData DefaultFormData() { |
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 EXPECT_EQ(1U, NotificationsOfType( | 1631 EXPECT_EQ(1U, NotificationsOfType( |
1628 DialogNotification::REQUIRED_ACTION).size()); | 1632 DialogNotification::REQUIRED_ACTION).size()); |
1629 } | 1633 } |
1630 | 1634 |
1631 // Test Wallet banners are show in the right situations. These banners explain | 1635 // Test Wallet banners are show in the right situations. These banners explain |
1632 // where Chrome got the user's data (i.e. "Got details from Wallet") or promote | 1636 // where Chrome got the user's data (i.e. "Got details from Wallet") or promote |
1633 // saving details into Wallet (i.e. "[x] Save details to Wallet"). | 1637 // saving details into Wallet (i.e. "[x] Save details to Wallet"). |
1634 TEST_F(AutofillDialogControllerTest, WalletBanners) { | 1638 TEST_F(AutofillDialogControllerTest, WalletBanners) { |
1635 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1639 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1636 command_line->AppendSwitch(switches::kWalletServiceUseProd); | 1640 command_line->AppendSwitch(switches::kWalletServiceUseProd); |
1637 PrefService* prefs = controller()->profile()->GetPrefs(); | 1641 PrefService* prefs = profile()->GetPrefs(); |
1638 ASSERT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet)); | 1642 |
| 1643 // Simulate first run. |
| 1644 prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, false); |
| 1645 SetUpControllerWithFormData(DefaultFormData()); |
1639 | 1646 |
1640 EXPECT_EQ(0U, NotificationsOfType( | 1647 EXPECT_EQ(0U, NotificationsOfType( |
1641 DialogNotification::EXPLANATORY_MESSAGE).size()); | 1648 DialogNotification::EXPLANATORY_MESSAGE).size()); |
1642 EXPECT_EQ(0U, NotificationsOfType( | 1649 EXPECT_EQ(0U, NotificationsOfType( |
1643 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); | 1650 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); |
1644 | 1651 |
1645 // Sign in a user with a completed account. | 1652 // Sign in a user with a completed account. |
1646 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 1653 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
1647 | 1654 |
1648 // Full account; should show "Details from Wallet" message. | 1655 // Full account; should show "Details from Wallet" message. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 DialogNotification::AUTOCHECKOUT_SUCCESS).size()); | 1743 DialogNotification::AUTOCHECKOUT_SUCCESS).size()); |
1737 EXPECT_EQ(1U, NotificationsOfType( | 1744 EXPECT_EQ(1U, NotificationsOfType( |
1738 DialogNotification::AUTOCHECKOUT_ERROR).size()); | 1745 DialogNotification::AUTOCHECKOUT_ERROR).size()); |
1739 } | 1746 } |
1740 | 1747 |
1741 TEST_F(AutofillDialogControllerTest, OnAutocheckoutSuccess) { | 1748 TEST_F(AutofillDialogControllerTest, OnAutocheckoutSuccess) { |
1742 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1749 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1743 command_line->AppendSwitch(switches::kWalletServiceUseProd); | 1750 command_line->AppendSwitch(switches::kWalletServiceUseProd); |
1744 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); | 1751 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); |
1745 | 1752 |
| 1753 // Simulate first run. |
| 1754 profile()->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, |
| 1755 false); |
| 1756 SetUpControllerWithFormData(DefaultFormData()); |
| 1757 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); |
| 1758 |
1746 // Sign in a user with a completed account. | 1759 // Sign in a user with a completed account. |
1747 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 1760 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
1748 | 1761 |
1749 // Full account; should show "Details from Wallet" message. | 1762 // Full account; should show "Details from Wallet" message. |
1750 EXPECT_EQ(1U, NotificationsOfType( | 1763 EXPECT_EQ(1U, NotificationsOfType( |
1751 DialogNotification::EXPLANATORY_MESSAGE).size()); | 1764 DialogNotification::EXPLANATORY_MESSAGE).size()); |
1752 EXPECT_EQ(0U, NotificationsOfType( | 1765 EXPECT_EQ(0U, NotificationsOfType( |
1753 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); | 1766 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); |
1754 | 1767 |
1755 AcceptAndLoadFakeFingerprint(); | 1768 AcceptAndLoadFakeFingerprint(); |
1756 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | 1769 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
| 1770 controller()->OverlayButtonPressed(); |
1757 | 1771 |
1758 EXPECT_EQ(0U, NotificationsOfType( | 1772 EXPECT_EQ(0U, NotificationsOfType( |
1759 DialogNotification::EXPLANATORY_MESSAGE).size()); | 1773 DialogNotification::EXPLANATORY_MESSAGE).size()); |
1760 | 1774 |
1761 controller()->OnAutocheckoutSuccess(); | 1775 controller()->OnAutocheckoutSuccess(); |
1762 | 1776 |
1763 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1777 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1764 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1778 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1765 EXPECT_EQ(1U, NotificationsOfType( | 1779 EXPECT_EQ(1U, NotificationsOfType( |
1766 DialogNotification::AUTOCHECKOUT_SUCCESS).size()); | 1780 DialogNotification::AUTOCHECKOUT_SUCCESS).size()); |
(...skipping 21 matching lines...) Expand all Loading... |
1788 ::prefs::kAutofillDialogPayWithoutWallet)); | 1802 ::prefs::kAutofillDialogPayWithoutWallet)); |
1789 | 1803 |
1790 SimulateSigninError(); | 1804 SimulateSigninError(); |
1791 FillCreditCardInputs(); | 1805 FillCreditCardInputs(); |
1792 controller()->OnAccept(); | 1806 controller()->OnAccept(); |
1793 | 1807 |
1794 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1808 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( |
1795 ::prefs::kAutofillDialogPayWithoutWallet)); | 1809 ::prefs::kAutofillDialogPayWithoutWallet)); |
1796 } | 1810 } |
1797 | 1811 |
| 1812 // Tests that there's an overlay shown while waiting for full wallet items, |
| 1813 // and on first run an additional expository wallet overlay shown after full |
| 1814 // wallet items are returned. |
| 1815 // TODO(estade): enable on other platforms when overlays are supported there. |
| 1816 #if defined(TOOLKIT_VIEWS) |
| 1817 TEST_F(AutofillDialogControllerTest, WalletFirstRun) { |
| 1818 // Simulate first run. |
| 1819 PrefService* prefs = profile()->GetPrefs(); |
| 1820 prefs->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, false); |
| 1821 SetUpControllerWithFormData(DefaultFormData()); |
| 1822 |
| 1823 SwitchToWallet(); |
| 1824 EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); |
| 1825 |
| 1826 SubmitWithWalletItems(CompleteAndValidWalletItems()); |
| 1827 EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty()); |
| 1828 |
| 1829 EXPECT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet)); |
| 1830 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
| 1831 EXPECT_FALSE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet)); |
| 1832 EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty()); |
| 1833 EXPECT_FALSE(form_structure()); |
| 1834 |
| 1835 controller()->OverlayButtonPressed(); |
| 1836 EXPECT_TRUE(prefs->GetBoolean(::prefs::kAutofillDialogHasPaidWithWallet)); |
| 1837 EXPECT_TRUE(form_structure()); |
| 1838 } |
| 1839 #endif |
| 1840 |
| 1841 // On second run, the second overlay doesn't show. |
| 1842 TEST_F(AutofillDialogControllerTest, WalletSecondRun) { |
| 1843 SwitchToWallet(); |
| 1844 EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); |
| 1845 |
| 1846 SubmitWithWalletItems(CompleteAndValidWalletItems()); |
| 1847 EXPECT_FALSE(controller()->GetDialogOverlay().image.IsEmpty()); |
| 1848 |
| 1849 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| 1850 ::prefs::kAutofillDialogHasPaidWithWallet)); |
| 1851 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
| 1852 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( |
| 1853 ::prefs::kAutofillDialogHasPaidWithWallet)); |
| 1854 EXPECT_TRUE(form_structure()); |
| 1855 } |
| 1856 |
1798 TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { | 1857 TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { |
1799 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1858 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
1800 ::prefs::kAutofillDialogPayWithoutWallet)); | 1859 ::prefs::kAutofillDialogPayWithoutWallet)); |
1801 | 1860 |
1802 SwitchToAutofill(); | 1861 SwitchToAutofill(); |
1803 FillCreditCardInputs(); | 1862 FillCreditCardInputs(); |
1804 controller()->OnAccept(); | 1863 controller()->OnAccept(); |
1805 | 1864 |
1806 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( | 1865 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath( |
1807 ::prefs::kAutofillDialogPayWithoutWallet)); | 1866 ::prefs::kAutofillDialogPayWithoutWallet)); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2163 controller()->CurrentAutocheckoutSteps()[1].type()); | 2222 controller()->CurrentAutocheckoutSteps()[1].type()); |
2164 EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED, | 2223 EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED, |
2165 controller()->CurrentAutocheckoutSteps()[1].status()); | 2224 controller()->CurrentAutocheckoutSteps()[1].status()); |
2166 EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING, | 2225 EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING, |
2167 controller()->CurrentAutocheckoutSteps()[2].type()); | 2226 controller()->CurrentAutocheckoutSteps()[2].type()); |
2168 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, | 2227 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, |
2169 controller()->CurrentAutocheckoutSteps()[2].status()); | 2228 controller()->CurrentAutocheckoutSteps()[2].status()); |
2170 } | 2229 } |
2171 | 2230 |
2172 } // namespace autofill | 2231 } // namespace autofill |
OLD | NEW |