| Index: chrome/browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc
|
| diff --git a/chrome/browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc
|
| index 3a06980f7df60b56c74db2a552332851d5f070fc..404536b741f9e2567687c2cd26d1035b3a3f06a8 100644
|
| --- a/chrome/browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc
|
| +++ b/chrome/browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/compiler_specific.h"
|
| +#include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/strings/string16.h"
|
| @@ -12,6 +13,9 @@
|
| #include "chrome/browser/ui/autofill/test_autofill_credit_card_bubble.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "components/autofill/core/browser/autofill_common_test.h"
|
| +#include "components/autofill/core/browser/autofill_profile.h"
|
| +#include "components/autofill/core/browser/credit_card.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/page_transition_types.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| @@ -33,8 +37,12 @@ base::string16 BackingCard() {
|
| base::string16 FrontingCard() {
|
| return ASCIIToUTF16("Mastercard - 5888");
|
| }
|
| -base::string16 NewCard() {
|
| - return ASCIIToUTF16("Discover - 7582");
|
| +scoped_ptr<CreditCard> NewCard() {
|
| + return scoped_ptr<CreditCard>(new CreditCard(test::GetVerifiedCreditCard()));
|
| +}
|
| +scoped_ptr<AutofillProfile> BillingProfile() {
|
| + return scoped_ptr<AutofillProfile>(
|
| + new AutofillProfile(test::GetVerifiedProfile()));
|
| }
|
|
|
| base::string16 RangeOfString(const base::string16& string,
|
| @@ -106,16 +114,16 @@ class AutofillCreditCardBubbleControllerTest : public testing::Test {
|
| return content::WebContentsTester::For(test_web_contents_.get());
|
| }
|
|
|
| - void ShowGeneratedCardUI() {
|
| + void ShowGeneratedCardBubble() {
|
| ASSERT_TRUE(controller()->IsInstalled());
|
| - TestAutofillCreditCardBubbleController::ShowGeneratedCardUI(
|
| + TestAutofillCreditCardBubbleController::ShowGeneratedCardBubble(
|
| test_web_contents_.get(), BackingCard(), FrontingCard());
|
| }
|
|
|
| void ShowNewCardSavedBubble() {
|
| - EXPECT_TRUE(controller()->IsInstalled());
|
| + ASSERT_TRUE(controller()->IsInstalled());
|
| TestAutofillCreditCardBubbleController::ShowNewCardSavedBubble(
|
| - test_web_contents_.get(), NewCard());
|
| + test_web_contents_.get(), NewCard(), BillingProfile());
|
| }
|
|
|
| void Navigate() {
|
| @@ -146,63 +154,92 @@ class AutofillCreditCardBubbleControllerTest : public testing::Test {
|
| TEST_F(AutofillCreditCardBubbleControllerTest, ShouldShowGeneratedCardBubble) {
|
| ASSERT_EQ(0, GeneratedCardBubbleTimesShown());
|
|
|
| - ShowGeneratedCardUI();
|
| + ShowGeneratedCardBubble();
|
| EXPECT_EQ(1, GeneratedCardBubbleTimesShown());
|
| EXPECT_TRUE(controller()->GetTestingBubble()->showing());
|
|
|
| - ShowGeneratedCardUI();
|
| - ShowGeneratedCardUI();
|
| - ShowGeneratedCardUI();
|
| - ShowGeneratedCardUI();
|
| + ShowGeneratedCardBubble();
|
| + ShowGeneratedCardBubble();
|
| + ShowGeneratedCardBubble();
|
| + ShowGeneratedCardBubble();
|
| EXPECT_EQ(5, GeneratedCardBubbleTimesShown());
|
| EXPECT_TRUE(controller()->GetTestingBubble()->showing());
|
|
|
| - ShowGeneratedCardUI();
|
| + ShowGeneratedCardBubble();
|
| EXPECT_EQ(5, GeneratedCardBubbleTimesShown());
|
| EXPECT_FALSE(controller()->GetTestingBubble());
|
| }
|
|
|
| -TEST_F(AutofillCreditCardBubbleControllerTest, BubbleText) {
|
| - ShowGeneratedCardUI();
|
| - base::string16 generated_text = controller()->BubbleText();
|
| +TEST_F(AutofillCreditCardBubbleControllerTest, TitleText) {
|
| + ShowGeneratedCardBubble();
|
| + EXPECT_FALSE(controller()->TitleText().empty());
|
| +
|
| + ShowNewCardSavedBubble();
|
| + EXPECT_TRUE(controller()->TitleText().empty());
|
| +}
|
| +
|
| +TEST_F(AutofillCreditCardBubbleControllerTest, HeaderText) {
|
| + ShowGeneratedCardBubble();
|
| + base::string16 generated_text = controller()->HeaderText();
|
| EXPECT_NE(generated_text.find(BackingCard()), base::string16::npos);
|
| EXPECT_NE(generated_text.find(FrontingCard()), base::string16::npos);
|
| - EXPECT_EQ(generated_text.find(NewCard()), base::string16::npos);
|
|
|
| ShowNewCardSavedBubble();
|
| - base::string16 new_text = controller()->BubbleText();
|
| - EXPECT_NE(new_text, generated_text);
|
| + base::string16 new_text = controller()->HeaderText();
|
| EXPECT_EQ(new_text.find(BackingCard()), base::string16::npos);
|
| EXPECT_EQ(new_text.find(FrontingCard()), base::string16::npos);
|
| - EXPECT_NE(new_text.find(NewCard()), base::string16::npos);
|
|
|
| - ShowGeneratedCardUI();
|
| - EXPECT_EQ(generated_text, controller()->BubbleText());
|
| + ShowGeneratedCardBubble();
|
| + EXPECT_EQ(generated_text, controller()->HeaderText());
|
|
|
| ShowNewCardSavedBubble();
|
| - EXPECT_EQ(new_text, controller()->BubbleText());
|
| + EXPECT_EQ(new_text, controller()->HeaderText());
|
| }
|
|
|
| -TEST_F(AutofillCreditCardBubbleControllerTest, BubbleTextRanges) {
|
| - ShowGeneratedCardUI();
|
| - base::string16 text = controller()->BubbleText();
|
| - std::vector<ui::Range> ranges = controller()->BubbleTextRanges();
|
| +TEST_F(AutofillCreditCardBubbleControllerTest, HeaderTextRanges) {
|
| + ShowGeneratedCardBubble();
|
| + const base::string16& header_text = controller()->HeaderText();
|
| + const std::vector<TextRange>& ranges = controller()->HeaderTextRanges();
|
| +
|
| + ASSERT_EQ(ranges.size(), 3U);
|
| +
|
| + EXPECT_EQ(BackingCard(), RangeOfString(header_text, ranges[0].range));
|
| + EXPECT_FALSE(ranges[0].is_link);
|
| +
|
| + EXPECT_EQ(FrontingCard(), RangeOfString(header_text, ranges[1].range));
|
| + EXPECT_FALSE(ranges[1].is_link);
|
|
|
| - ASSERT_EQ(ranges.size(), 2U);
|
| - EXPECT_EQ(BackingCard(), RangeOfString(text, ranges[0]));
|
| - EXPECT_EQ(FrontingCard(), RangeOfString(text, ranges[1]));
|
| + EXPECT_TRUE(ranges[2].is_link);
|
|
|
| ShowNewCardSavedBubble();
|
| - text = controller()->BubbleText();
|
| - ranges = controller()->BubbleTextRanges();
|
| + EXPECT_TRUE(controller()->HeaderTextRanges().empty());
|
| +}
|
| +
|
| +TEST_F(AutofillCreditCardBubbleControllerTest, AnchorIcon) {
|
| + ShowGeneratedCardBubble();
|
| + EXPECT_FALSE(controller()->AnchorIcon().IsEmpty());
|
| +
|
| + ShowNewCardSavedBubble();
|
| + EXPECT_TRUE(controller()->AnchorIcon().IsEmpty());
|
| +}
|
| +
|
| +TEST_F(AutofillCreditCardBubbleControllerTest, AnchorToSettingsMenu) {
|
| + ShowGeneratedCardBubble();
|
| + EXPECT_FALSE(controller()->AnchorToSettingsMenu());
|
| + controller()->GetTestingBubble()->Hide();
|
| + EXPECT_TRUE(controller());
|
|
|
| - ASSERT_EQ(ranges.size(), 1U);
|
| - EXPECT_EQ(NewCard(), RangeOfString(text, ranges[0]));
|
| + // Because the new card bubble has no anchor to re-show itself, its controller
|
| + // should be destroyed when the bubble pops.
|
| + ShowNewCardSavedBubble();
|
| + EXPECT_TRUE(controller()->AnchorToSettingsMenu());
|
| + controller()->GetTestingBubble()->Hide();
|
| + EXPECT_FALSE(controller());
|
| }
|
|
|
| TEST_F(AutofillCreditCardBubbleControllerTest, HideOnNavigate) {
|
| EXPECT_FALSE(controller()->GetTestingBubble());
|
| - ShowGeneratedCardUI();
|
| + ShowGeneratedCardBubble();
|
| EXPECT_TRUE(controller()->GetTestingBubble()->showing());
|
|
|
| Navigate();
|
| @@ -220,7 +257,7 @@ TEST_F(AutofillCreditCardBubbleControllerTest, HideOnNavigate) {
|
|
|
| TEST_F(AutofillCreditCardBubbleControllerTest, StayOnRedirect) {
|
| EXPECT_FALSE(controller()->GetTestingBubble());
|
| - ShowGeneratedCardUI();
|
| + ShowGeneratedCardBubble();
|
| EXPECT_TRUE(controller()->GetTestingBubble()->showing());
|
|
|
| Redirect();
|
|
|