Commit 4c8c125e authored by Bernhard Bauer's avatar Bernhard Bauer Committed by Commit Bot

Add unit test for <Alias> tag in OSDD files.

Bug: 728558
Change-Id: Ie0d82eba52ecbd0ba397c6b28f8a5bb33050a67b
Reviewed-on: https://chromium-review.googlesource.com/570024
Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487457}
parent 7f92a72e
...@@ -95,27 +95,26 @@ void TemplateURLParserTest::ParseFile( ...@@ -95,27 +95,26 @@ void TemplateURLParserTest::ParseFile(
contents.length(), filter); contents.length(), filter);
} }
// Actual tests --------------------------------------------------------------- // Actual tests ---------------------------------------------------------------
TEST_F(TemplateURLParserTest, FailOnBogusURL) { TEST_F(TemplateURLParserTest, FailOnBogusURL) {
ASSERT_NO_FATAL_FAILURE(ParseFile("bogus.xml", NULL)); ASSERT_NO_FATAL_FAILURE(ParseFile("bogus.xml", nullptr));
EXPECT_FALSE(template_url_.get()); EXPECT_FALSE(template_url_);
} }
TEST_F(TemplateURLParserTest, PassOnHTTPS) { TEST_F(TemplateURLParserTest, PassOnHTTPS) {
ASSERT_NO_FATAL_FAILURE(ParseFile("https.xml", NULL)); ASSERT_NO_FATAL_FAILURE(ParseFile("https.xml", nullptr));
EXPECT_TRUE(template_url_.get()); EXPECT_TRUE(template_url_);
} }
TEST_F(TemplateURLParserTest, FailOnPost) { TEST_F(TemplateURLParserTest, FailOnPost) {
ASSERT_NO_FATAL_FAILURE(ParseFile("post.xml", NULL)); ASSERT_NO_FATAL_FAILURE(ParseFile("post.xml", nullptr));
EXPECT_FALSE(template_url_.get()); EXPECT_FALSE(template_url_);
} }
TEST_F(TemplateURLParserTest, TestDictionary) { TEST_F(TemplateURLParserTest, TestDictionary) {
ASSERT_NO_FATAL_FAILURE(ParseFile("dictionary.xml", NULL)); ASSERT_NO_FATAL_FAILURE(ParseFile("dictionary.xml", nullptr));
ASSERT_TRUE(template_url_.get()); ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Dictionary.com"), template_url_->short_name()); EXPECT_EQ(ASCIIToUTF16("Dictionary.com"), template_url_->short_name());
EXPECT_EQ(GURL("http://cache.lexico.com/g/d/favicon.ico"), EXPECT_EQ(GURL("http://cache.lexico.com/g/d/favicon.ico"),
template_url_->favicon_url()); template_url_->favicon_url());
...@@ -125,8 +124,8 @@ TEST_F(TemplateURLParserTest, TestDictionary) { ...@@ -125,8 +124,8 @@ TEST_F(TemplateURLParserTest, TestDictionary) {
} }
TEST_F(TemplateURLParserTest, TestMSDN) { TEST_F(TemplateURLParserTest, TestMSDN) {
ASSERT_NO_FATAL_FAILURE(ParseFile("msdn.xml", NULL)); ASSERT_NO_FATAL_FAILURE(ParseFile("msdn.xml", nullptr));
ASSERT_TRUE(template_url_.get()); ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Search \" MSDN"), template_url_->short_name()); EXPECT_EQ(ASCIIToUTF16("Search \" MSDN"), template_url_->short_name());
EXPECT_EQ(GURL("http://search.msdn.microsoft.com/search/favicon.ico"), EXPECT_EQ(GURL("http://search.msdn.microsoft.com/search/favicon.ico"),
template_url_->favicon_url()); template_url_->favicon_url());
...@@ -137,8 +136,8 @@ TEST_F(TemplateURLParserTest, TestMSDN) { ...@@ -137,8 +136,8 @@ TEST_F(TemplateURLParserTest, TestMSDN) {
} }
TEST_F(TemplateURLParserTest, TestWikipedia) { TEST_F(TemplateURLParserTest, TestWikipedia) {
ASSERT_NO_FATAL_FAILURE(ParseFile("wikipedia.xml", NULL)); ASSERT_NO_FATAL_FAILURE(ParseFile("wikipedia.xml", nullptr));
ASSERT_TRUE(template_url_.get()); ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Wikipedia (English)"), template_url_->short_name()); EXPECT_EQ(ASCIIToUTF16("Wikipedia (English)"), template_url_->short_name());
EXPECT_EQ(GURL("http://en.wikipedia.org/favicon.ico"), EXPECT_EQ(GURL("http://en.wikipedia.org/favicon.ico"),
template_url_->favicon_url()); template_url_->favicon_url());
...@@ -157,7 +156,7 @@ TEST_F(TemplateURLParserTest, TestWikipedia) { ...@@ -157,7 +156,7 @@ TEST_F(TemplateURLParserTest, TestWikipedia) {
} }
TEST_F(TemplateURLParserTest, NoCrashOnEmptyAttributes) { TEST_F(TemplateURLParserTest, NoCrashOnEmptyAttributes) {
ASSERT_NO_FATAL_FAILURE(ParseFile("url_with_no_attributes.xml", NULL)); ASSERT_NO_FATAL_FAILURE(ParseFile("url_with_no_attributes.xml", nullptr));
} }
TEST_F(TemplateURLParserTest, TestFirefoxEbay) { TEST_F(TemplateURLParserTest, TestFirefoxEbay) {
...@@ -165,7 +164,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxEbay) { ...@@ -165,7 +164,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxEbay) {
// (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Parameter/1.0) // (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Parameter/1.0)
ParamFilterImpl filter("ebay", "ebay"); ParamFilterImpl filter("ebay", "ebay");
ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_ebay.xml", &filter)); ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_ebay.xml", &filter));
ASSERT_TRUE(template_url_.get()); ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("eBay"), template_url_->short_name()); EXPECT_EQ(ASCIIToUTF16("eBay"), template_url_->short_name());
EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData())); EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData()));
EXPECT_EQ("http://search.ebay.com/search/search.dll?query={searchTerms}&" EXPECT_EQ("http://search.ebay.com/search/search.dll?query={searchTerms}&"
...@@ -182,7 +181,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxWebster) { ...@@ -182,7 +181,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxWebster) {
// This XML file uses a namespace. // This XML file uses a namespace.
ParamFilterImpl filter(std::string(), "Mozilla"); ParamFilterImpl filter(std::string(), "Mozilla");
ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_webster.xml", &filter)); ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_webster.xml", &filter));
ASSERT_TRUE(template_url_.get()); ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Webster"), template_url_->short_name()); EXPECT_EQ(ASCIIToUTF16("Webster"), template_url_->short_name());
EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData())); EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData()));
EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}",
...@@ -197,7 +196,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { ...@@ -197,7 +196,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxYahoo) {
// This XML file uses a namespace. // This XML file uses a namespace.
ParamFilterImpl filter(std::string(), "Mozilla"); ParamFilterImpl filter(std::string(), "Mozilla");
ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_yahoo.xml", &filter)); ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_yahoo.xml", &filter));
ASSERT_TRUE(template_url_.get()); ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name());
EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData())); EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData()));
EXPECT_EQ("http://ff.search.yahoo.com/gossip?" EXPECT_EQ("http://ff.search.yahoo.com/gossip?"
...@@ -217,7 +216,7 @@ TEST_F(TemplateURLParserTest, TestPostSuggestion) { ...@@ -217,7 +216,7 @@ TEST_F(TemplateURLParserTest, TestPostSuggestion) {
// This XML file uses a namespace. // This XML file uses a namespace.
ParamFilterImpl filter(std::string(), "Mozilla"); ParamFilterImpl filter(std::string(), "Mozilla");
ASSERT_NO_FATAL_FAILURE(ParseFile("post_suggestion.xml", &filter)); ASSERT_NO_FATAL_FAILURE(ParseFile("post_suggestion.xml", &filter));
ASSERT_TRUE(template_url_.get()); ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name());
EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData())); EXPECT_TRUE(template_url_->url_ref().SupportsReplacement(SearchTermsData()));
EXPECT_TRUE(template_url_->suggestions_url().empty()); EXPECT_TRUE(template_url_->suggestions_url().empty());
...@@ -228,3 +227,24 @@ TEST_F(TemplateURLParserTest, TestPostSuggestion) { ...@@ -228,3 +227,24 @@ TEST_F(TemplateURLParserTest, TestPostSuggestion) {
EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"),
template_url_->favicon_url()); template_url_->favicon_url());
} }
// <Alias> tags are parsed and used as keyword for the template URL.
TEST_F(TemplateURLParserTest, TestKeyword) {
ASSERT_NO_FATAL_FAILURE(ParseFile("keyword.xml", nullptr));
ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Example"), template_url_->short_name());
EXPECT_EQ("https://www.example.com/search?q={searchTerms}",
template_url_->url());
EXPECT_EQ(ASCIIToUTF16("moose"), template_url_->keyword());
}
// Empty <Alias> tags are ignored and the default keyword is used instead
// (because empty keywords are not allowed).
TEST_F(TemplateURLParserTest, TestEmptyKeyword) {
ASSERT_NO_FATAL_FAILURE(ParseFile("empty_keyword.xml", nullptr));
ASSERT_TRUE(template_url_);
EXPECT_EQ(ASCIIToUTF16("Example"), template_url_->short_name());
EXPECT_EQ("https://www.example.com/search?q={searchTerms}",
template_url_->url());
EXPECT_EQ(ASCIIToUTF16("example.com"), template_url_->keyword());
}
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Example</ShortName>
<Description>Example Search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" method="get" template="https://www.example.com/search?q={searchTerms}"/>
<Alias/>
</SearchPlugin>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Example</ShortName>
<Description>Example Search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" method="get" template="https://www.example.com/search?q={searchTerms}"/>
<Alias>MoOsE</Alias>
</SearchPlugin>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment