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

Unified Diff: chrome/browser/search/search_test_utils.cc

Issue 20388003: Reload Instant NTP and Instant-process tabs on search url change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added ui and unit tests Created 7 years, 5 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
Index: chrome/browser/search/search_test_utils.cc
diff --git a/chrome/browser/search/search_test_utils.cc b/chrome/browser/search/search_test_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c63ab9fbb931a1c23b1af0a53df8c08aa1238cb3
--- /dev/null
+++ b/chrome/browser/search/search_test_utils.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/search/search_test_utils.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/test/base/ui_test_utils.h"
+
+namespace search_test_utils {
samarth 2013/08/02 21:51:15 In general, I'm all for sharing code. But given ho
Anuj 2013/08/09 07:22:00 I have introduced instant_unittest_base. The Insta
+
+void SetSearchProvider(Profile* profile) {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile);
+ ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
+ TemplateURLData data;
+ data.SetURL("http://foo.com/url?bar={searchTerms}");
+ data.instant_url =
+ "http://foo.com/instant?"
+ "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk";
+ data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
+ data.search_terms_replacement_key = "strk";
+
+ TemplateURL* template_url = new TemplateURL(profile, data);
+ // Takes ownership of |template_url|.
+ template_url_service->Add(template_url);
+ template_url_service->SetDefaultSearchProvider(template_url);
+}
+
+// Build an Instant URL with or without a valid search terms replacement key
+// as per |has_search_term_replacement_key|. Set that URL as the instant URL
+// for the default search provider.
+void SetDefaultInstantTemplateUrl(Profile* profile,
+ bool has_search_term_replacement_key) {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile);
+ ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
+
+ static const char kInstantURLWithStrk[] =
+ "http://foo.com/instant?foo=foo#foo=foo&strk";
+ static const char kInstantURLNoStrk[] =
+ "http://foo.com/instant?foo=foo#foo=foo";
+
+ TemplateURLData data;
+ data.short_name = ASCIIToUTF16("instafoo");
+ data.SetURL("http://foo.com/url?bar={searchTerms}");
+ data.suggestions_url = "http://foo.com/url?sug={searchTerms}";
+ data.instant_url = (has_search_term_replacement_key ? kInstantURLWithStrk
+ : kInstantURLNoStrk);
+ data.search_terms_replacement_key = "strk";
+
+ TemplateURL* template_url = new TemplateURL(profile, data);
+ // Takes ownership of |template_url|.
+ template_url_service->Add(template_url);
+ template_url_service->SetDefaultSearchProvider(template_url);
+}
+} // namespace search_test_utils

Powered by Google App Engine
This is Rietveld 408576698