| Index: chrome/browser/ui/autofill/save_card_bubble_controller_impl_unittest.cc
|
| diff --git a/chrome/browser/ui/autofill/save_card_bubble_controller_impl_unittest.cc b/chrome/browser/ui/autofill/save_card_bubble_controller_impl_unittest.cc
|
| index 2fa5eae3f6e78d4e7470d94074416fe0036d34b8..5efd48d92c09896afc4874d5e97e32e8fc4345e1 100644
|
| --- a/chrome/browser/ui/autofill/save_card_bubble_controller_impl_unittest.cc
|
| +++ b/chrome/browser/ui/autofill/save_card_bubble_controller_impl_unittest.cc
|
| @@ -26,9 +26,6 @@ using testing::ElementsAre;
|
|
|
| namespace autofill {
|
|
|
| -typedef SaveCardBubbleController::LegalMessageLine LegalMessageLine;
|
| -typedef SaveCardBubbleController::LegalMessageLines LegalMessageLines;
|
| -
|
| class TestSaveCardBubbleControllerImpl : public SaveCardBubbleControllerImpl {
|
| public:
|
| static void CreateForTesting(content::WebContents* web_contents) {
|
| @@ -76,34 +73,6 @@ class SaveCardBubbleControllerImplTest : public BrowserWithTestWindowTest {
|
| std::move(legal_message));
|
| }
|
|
|
| - // Returns true if lines are the same.
|
| - bool CompareLegalMessageLines(const LegalMessageLine& a,
|
| - const LegalMessageLine& b) {
|
| - if (a.text != b.text)
|
| - return false;
|
| - if (a.links.size() != b.links.size())
|
| - return false;
|
| - for (size_t i = 0; i < a.links.size(); ++i) {
|
| - if (a.links[i].range != b.links[i].range)
|
| - return false;
|
| - if (a.links[i].url != b.links[i].url)
|
| - return false;
|
| - }
|
| - return true;
|
| - }
|
| -
|
| - // Returns true if messages are the same.
|
| - bool CompareLegalMessages(const LegalMessageLines& a,
|
| - const LegalMessageLines& b) {
|
| - if (a.size() != b.size())
|
| - return false;
|
| - for (size_t i = 0; i < a.size(); ++i) {
|
| - if (!CompareLegalMessageLines(a[i], b[i]))
|
| - return false;
|
| - }
|
| - return true;
|
| - }
|
| -
|
| void ShowLocalBubble() {
|
| controller()->ShowBubbleForLocalSave(base::Bind(&SaveCardCallback));
|
| }
|
| @@ -154,303 +123,6 @@ class SaveCardBubbleControllerImplTest : public BrowserWithTestWindowTest {
|
| DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImplTest);
|
| };
|
|
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_NoParameters) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"This is the entire message.\""
|
| - " } ]"
|
| - "}");
|
| -
|
| - LegalMessageLine expected_line;
|
| - expected_line.text = base::ASCIIToUTF16("This is the entire message.");
|
| - LegalMessageLines expected = {expected_line};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_SingleParameter) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"Panda {0}.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bears are fuzzy\","
|
| - " \"url\": \"http://www.example.com\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| -
|
| - LegalMessageLine expected_line;
|
| - expected_line.text = base::ASCIIToUTF16("Panda bears are fuzzy.");
|
| - expected_line.links = {
|
| - {{6, 21}, GURL("http://www.example.com")},
|
| - };
|
| - LegalMessageLines expected = {expected_line};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_MissingUrl) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"Panda {0}.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bear\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| - // Legal message is invalid so GetLegalMessageLines() should return no lines.
|
| - EXPECT_TRUE(CompareLegalMessages(LegalMessageLines(),
|
| - controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_MissingDisplayText) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"Panda {0}.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"url\": \"http://www.example.com\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| - // Legal message is invalid so GetLegalMessageLines() should return no lines.
|
| - EXPECT_TRUE(CompareLegalMessages(LegalMessageLines(),
|
| - controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_EscapeCharacters) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"Panda '{'{0}'}' '{1}' don't $1.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bears\","
|
| - " \"url\": \"http://www.example.com\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| -
|
| - LegalMessageLine expected_line;
|
| - expected_line.text = base::ASCIIToUTF16("Panda {bears} {1} don't $1.");
|
| - expected_line.links = {
|
| - {{7, 12}, GURL("http://www.example.com")},
|
| - };
|
| - LegalMessageLines expected = {expected_line};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_ConsecutiveDollarSigns) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"$$\""
|
| - " } ]"
|
| - "}");
|
| -
|
| - // Consecutive dollar signs do not expand correctly (see comment in
|
| - // ReplaceTemplatePlaceholders() in save_card_bubble_controller_impl.cc).
|
| - // If this is fixed and this test starts to fail, please update the
|
| - // "Caveats" section of the SaveCardBubbleControllerImpl::SetLegalMessage()
|
| - // header file comment.
|
| - LegalMessageLine expected_line;
|
| - expected_line.text = base::ASCIIToUTF16("$$$");
|
| -
|
| - LegalMessageLines expected = {expected_line};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_DollarAndParenthesis) {
|
| - // "${" does not expand correctly (see comment in
|
| - // ReplaceTemplatePlaceholders() in save_card_bubble_controller_impl.cc).
|
| - // If this is fixed and this test starts to fail, please update the
|
| - // "Caveats" section of the SaveCardBubbleControllerImpl::SetLegalMessage()
|
| - // header file comment.
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"${0}\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bears\","
|
| - " \"url\": \"http://www.example.com\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| - // Legal message is invalid so GetLegalMessageLines() should return no lines.
|
| - EXPECT_TRUE(CompareLegalMessages(LegalMessageLines(),
|
| - controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_MultipleParameters) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"Panda {0} like {2} eat {1}.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bears\","
|
| - " \"url\": \"http://www.example.com/0\""
|
| - " }, {"
|
| - " \"display_text\": \"bamboo\","
|
| - " \"url\": \"http://www.example.com/1\""
|
| - " }, {"
|
| - " \"display_text\": \"to\","
|
| - " \"url\": \"http://www.example.com/2\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| -
|
| - LegalMessageLine expected_line;
|
| - expected_line.text = base::ASCIIToUTF16("Panda bears like to eat bamboo.");
|
| - expected_line.links = {
|
| - {{6, 11}, GURL("http://www.example.com/0")},
|
| - {{24, 30}, GURL("http://www.example.com/1")},
|
| - {{17, 19}, GURL("http://www.example.com/2")},
|
| - };
|
| - LegalMessageLines expected = {expected_line};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_MultipleLineElements) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"Panda {0}\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bears\","
|
| - " \"url\": \"http://www.example.com/line_0_param_0\""
|
| - " } ]"
|
| - " }, {"
|
| - " \"template\": \"like {1} eat {0}.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bamboo\","
|
| - " \"url\": \"http://www.example.com/line_1_param_0\""
|
| - " }, {"
|
| - " \"display_text\": \"to\","
|
| - " \"url\": \"http://www.example.com/line_1_param_1\""
|
| - " } ]"
|
| - " }, {"
|
| - " \"template\": \"The {0}.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"end\","
|
| - " \"url\": \"http://www.example.com/line_2_param_0\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| -
|
| - // Line 0.
|
| - LegalMessageLine expected_line_0;
|
| - expected_line_0.text = base::ASCIIToUTF16("Panda bears");
|
| - expected_line_0.links = {
|
| - {{6, 11}, GURL("http://www.example.com/line_0_param_0")},
|
| - };
|
| -
|
| - // Line 1.
|
| - LegalMessageLine expected_line_1;
|
| - expected_line_1.text = base::ASCIIToUTF16("like to eat bamboo.");
|
| - expected_line_1.links = {
|
| - {{12, 18}, GURL("http://www.example.com/line_1_param_0")},
|
| - {{5, 7}, GURL("http://www.example.com/line_1_param_1")},
|
| - };
|
| -
|
| - // Line 2.
|
| - LegalMessageLine expected_line_2;
|
| - expected_line_2.text = base::ASCIIToUTF16("The end.");
|
| - expected_line_2.links = {
|
| - {{4, 7}, GURL("http://www.example.com/line_2_param_0")},
|
| - };
|
| -
|
| - LegalMessageLines expected = {expected_line_0, expected_line_1,
|
| - expected_line_2};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_EmbeddedNewlines) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"Panda {0}\nlike {2} eat {1}.\nThe {3}.\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"bears\","
|
| - " \"url\": \"http://www.example.com/0\""
|
| - " }, {"
|
| - " \"display_text\": \"bamboo\","
|
| - " \"url\": \"http://www.example.com/1\""
|
| - " }, {"
|
| - " \"display_text\": \"to\","
|
| - " \"url\": \"http://www.example.com/2\""
|
| - " }, {"
|
| - " \"display_text\": \"end\","
|
| - " \"url\": \"http://www.example.com/3\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| -
|
| - LegalMessageLine expected_line;
|
| - expected_line.text =
|
| - base::ASCIIToUTF16("Panda bears\nlike to eat bamboo.\nThe end.");
|
| - expected_line.links = {
|
| - {{6, 11}, GURL("http://www.example.com/0")},
|
| - {{24, 30}, GURL("http://www.example.com/1")},
|
| - {{17, 19}, GURL("http://www.example.com/2")},
|
| - {{36, 39}, GURL("http://www.example.com/3")},
|
| - };
|
| - LegalMessageLines expected = {expected_line};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| -TEST_F(SaveCardBubbleControllerImplTest, LegalMessage_MaximumPlaceholders) {
|
| - SetLegalMessage(
|
| - "{"
|
| - " \"line\" : [ {"
|
| - " \"template\": \"a{0} b{1} c{2} d{3} e{4} f{5} g{6}\","
|
| - " \"template_parameter\": [ {"
|
| - " \"display_text\": \"A\","
|
| - " \"url\": \"http://www.example.com/0\""
|
| - " }, {"
|
| - " \"display_text\": \"B\","
|
| - " \"url\": \"http://www.example.com/1\""
|
| - " }, {"
|
| - " \"display_text\": \"C\","
|
| - " \"url\": \"http://www.example.com/2\""
|
| - " }, {"
|
| - " \"display_text\": \"D\","
|
| - " \"url\": \"http://www.example.com/3\""
|
| - " }, {"
|
| - " \"display_text\": \"E\","
|
| - " \"url\": \"http://www.example.com/4\""
|
| - " }, {"
|
| - " \"display_text\": \"F\","
|
| - " \"url\": \"http://www.example.com/5\""
|
| - " }, {"
|
| - " \"display_text\": \"G\","
|
| - " \"url\": \"http://www.example.com/6\""
|
| - " } ]"
|
| - " } ]"
|
| - "}");
|
| -
|
| - LegalMessageLine expected_line;
|
| - expected_line.text = base::ASCIIToUTF16("aA bB cC dD eE fF gG");
|
| - expected_line.links = {
|
| - {{1, 2}, GURL("http://www.example.com/0")},
|
| - {{4, 5}, GURL("http://www.example.com/1")},
|
| - {{7, 8}, GURL("http://www.example.com/2")},
|
| - {{10, 11}, GURL("http://www.example.com/3")},
|
| - {{13, 14}, GURL("http://www.example.com/4")},
|
| - {{16, 17}, GURL("http://www.example.com/5")},
|
| - {{19, 20}, GURL("http://www.example.com/6")},
|
| - };
|
| - LegalMessageLines expected = {expected_line};
|
| - EXPECT_TRUE(
|
| - CompareLegalMessages(expected, controller()->GetLegalMessageLines()));
|
| -}
|
| -
|
| TEST_F(SaveCardBubbleControllerImplTest, Metrics_Local_FirstShow_ShowBubble) {
|
| base::HistogramTester histogram_tester;
|
| ShowLocalBubble();
|
|
|