Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Unified Diff: components/search_engines/template_url_unittest.cc

Issue 2659353002: Fix TemplateUrl::MatchesData comparison of search_terms_replacement_key (reland) (Closed)
Patch Set: Fixed deps Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/search_engines/template_url_unittest.cc
diff --git a/components/search_engines/template_url_unittest.cc b/components/search_engines/template_url_unittest.cc
index 47630f348925dd2bb0dcf7e096f5724ea6f76dd3..170807f17f36a74c46898a97e6b742699efa7c60 100644
--- a/components/search_engines/template_url_unittest.cc
+++ b/components/search_engines/template_url_unittest.cc
@@ -10,12 +10,14 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/google/core/browser/google_util.h"
#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/metrics/proto/omnibox_input_type.pb.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/testing_search_terms_data.h"
+#include "net/base/url_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16;
@@ -1868,3 +1870,43 @@ TEST_F(TemplateURLTest, InvalidateCachedValues) {
search_terms_data_.set_google_base_url("http://www.google.com/");
}
+
+// search_terms_replacement_key param of TemplateURLData with value of
+// "{google:instantExtendedEnabledKey}" is replaced inside TemplateUrl
+// constructor so must be handled specially inside MatchesData.
+// Test that TemplateURL object created with such param matches correctly its
+// TemplateURLData.
+TEST_F(TemplateURLTest, MatchesData) {
+ TemplateURLData data;
+ data.search_terms_replacement_key =
+ google_util::kGoogleInstantExtendedEnabledKeyFull;
+ TemplateURL url(data);
+ EXPECT_NE(google_util::kGoogleInstantExtendedEnabledKeyFull,
+ url.search_terms_replacement_key());
+ EXPECT_TRUE(TemplateURL::MatchesData(&url, &data, search_terms_data_));
+}
+
+// Test for correct replacement of GoogleInstantExtendedEnabledKey param.
+TEST_F(TemplateURLTest, GoogleInstantExtendedEnabledReplacement) {
+ TemplateURLData data;
+ data.SetURL(std::string("https://www.google.com?") +
+ google_util::kGoogleInstantExtendedEnabledKeyFull +
+ "&q={searchTerms}");
+ data.SetShortName(ASCIIToUTF16("Google"));
+ data.SetKeyword(ASCIIToUTF16("google.com"));
+ data.search_terms_replacement_key =
+ google_util::kGoogleInstantExtendedEnabledKeyFull;
+ TemplateURL turl(data);
+ EXPECT_TRUE(TemplateURL::MatchesData(&turl, &data, search_terms_data_));
+ // Expect that replacement of search_terms_replacement_key in TemplateURL
+ // constructor is correct.
+ EXPECT_EQ(google_util::kInstantExtendedAPIParam,
+ turl.search_terms_replacement_key());
+ // Expect that replacement of {google:instantExtendedEnabledKey} in search url
+ // is correct.
+ GURL search_generated = turl.GenerateSearchURL(search_terms_data_);
+ EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated));
+ net::QueryIterator it(search_generated);
+ ASSERT_FALSE(it.IsAtEnd());
+ EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey());
+}
« no previous file with comments | « components/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698