summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines/template_url_unittest.cc
diff options
context:
space:
mode:
authoravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-21 09:58:47 +0000
committeravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-21 09:58:47 +0000
commit81c6ef6f1ef71822b08703962f5b260d00f734e2 (patch)
tree8ec1b964b6aa6b08ae586830c3a4b1833a699615 /chrome/browser/search_engines/template_url_unittest.cc
parent6b9540882ccacb7f9a41f84f2e8fb221ec6e1406 (diff)
downloadchromium_src-81c6ef6f1ef71822b08703962f5b260d00f734e2.zip
chromium_src-81c6ef6f1ef71822b08703962f5b260d00f734e2.tar.gz
chromium_src-81c6ef6f1ef71822b08703962f5b260d00f734e2.tar.bz2
Removed restriction for {} so that javascript blocks can be used in the url.
Added unittests for TemplateURLRef::ParseParameter and TemplateURLRef::ParseURL methods. BUG=2238 TEST=Try adding urls with different combinations of {}, they all should work. Review URL: http://codereview.chromium.org/555012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines/template_url_unittest.cc')
-rw-r--r--chrome/browser/search_engines/template_url_unittest.cc71
1 files changed, 70 insertions, 1 deletions
diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc
index 261adf0..fd468cb 100644
--- a/chrome/browser/search_engines/template_url_unittest.cc
+++ b/chrome/browser/search_engines/template_url_unittest.cc
@@ -369,7 +369,6 @@ TEST_F(TemplateURLTest, HostAndSearchTermKey) {
// Single term with extra chars in value should match.
{ L"http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
-
};
TemplateURL t_url;
@@ -411,3 +410,73 @@ TEST_F(TemplateURLTest, Keyword) {
EXPECT_FALSE(t_url.autogenerate_keyword());
EXPECT_EQ(L"foo", t_url.keyword());
}
+
+TEST_F(TemplateURLTest, ParseParameterKnown) {
+ std::wstring parsed_url(L"{searchTerms}");
+ TemplateURLRef url_ref(parsed_url, 0, 0);
+ TemplateURLRef::Replacements replacements;
+ EXPECT_TRUE(url_ref.ParseParameter(0, 12, &parsed_url, &replacements));
+ EXPECT_EQ(std::wstring(), parsed_url);
+ ASSERT_EQ(1U, replacements.size());
+ EXPECT_EQ(0, replacements[0].index);
+ EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
+}
+
+TEST_F(TemplateURLTest, ParseParameterUnknown) {
+ std::wstring parsed_url(L"{}");
+ TemplateURLRef url_ref(parsed_url, 0, 0);
+ TemplateURLRef::Replacements replacements;
+ EXPECT_FALSE(url_ref.ParseParameter(0, 1, &parsed_url, &replacements));
+ EXPECT_EQ(L"{}", parsed_url);
+ EXPECT_TRUE(replacements.empty());
+}
+
+TEST_F(TemplateURLTest, ParseURLEmpty) {
+ TemplateURLRef url_ref(L"", 0, 0);
+ TemplateURLRef::Replacements replacements;
+ bool valid = false;
+ EXPECT_EQ(std::wstring(), url_ref.ParseURL(L"", &replacements, &valid));
+ EXPECT_TRUE(replacements.empty());
+ EXPECT_TRUE(valid);
+}
+
+TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
+ TemplateURLRef url_ref(L"{", 0, 0);
+ TemplateURLRef::Replacements replacements;
+ bool valid = false;
+ EXPECT_EQ(std::wstring(), url_ref.ParseURL(L"{", &replacements, &valid));
+ EXPECT_TRUE(replacements.empty());
+ EXPECT_FALSE(valid);
+}
+
+TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
+ TemplateURLRef url_ref(L"{}", 0, 0);
+ TemplateURLRef::Replacements replacements;
+ bool valid = false;
+ EXPECT_EQ(L"{}", url_ref.ParseURL(L"{}", &replacements, &valid));
+ EXPECT_TRUE(replacements.empty());
+ EXPECT_TRUE(valid);
+}
+
+TEST_F(TemplateURLTest, ParseURLTwoParameters) {
+ TemplateURLRef url_ref(L"{}{{%s}}", 0, 0);
+ TemplateURLRef::Replacements replacements;
+ bool valid = false;
+ EXPECT_EQ(L"{}{}",
+ url_ref.ParseURL(L"{}{{searchTerms}}", &replacements, &valid));
+ ASSERT_EQ(1U, replacements.size());
+ EXPECT_EQ(3, replacements[0].index);
+ EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
+ EXPECT_TRUE(valid);
+}
+
+TEST_F(TemplateURLTest, ParseURLNestedParameter) {
+ TemplateURLRef url_ref(L"{%s", 0, 0);
+ TemplateURLRef::Replacements replacements;
+ bool valid = false;
+ EXPECT_EQ(L"{", url_ref.ParseURL(L"{{searchTerms}", &replacements, &valid));
+ ASSERT_EQ(1U, replacements.size());
+ EXPECT_EQ(1, replacements[0].index);
+ EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type);
+ EXPECT_TRUE(valid);
+}