Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/logging.h" | |
| 6 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "chrome/browser/search/search_test_utils.h" | |
| 8 #include "chrome/browser/search_engines/template_url.h" | |
| 9 #include "chrome/browser/search_engines/template_url_service.h" | |
| 10 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 11 #include "chrome/test/base/ui_test_utils.h" | |
| 12 | |
| 13 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
| |
| 14 | |
| 15 void SetSearchProvider(Profile* profile) { | |
| 16 TemplateURLService* template_url_service = | |
| 17 TemplateURLServiceFactory::GetForProfile(profile); | |
| 18 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); | |
| 19 TemplateURLData data; | |
| 20 data.SetURL("http://foo.com/url?bar={searchTerms}"); | |
| 21 data.instant_url = | |
| 22 "http://foo.com/instant?" | |
| 23 "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk"; | |
| 24 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); | |
| 25 data.search_terms_replacement_key = "strk"; | |
| 26 | |
| 27 TemplateURL* template_url = new TemplateURL(profile, data); | |
| 28 // Takes ownership of |template_url|. | |
| 29 template_url_service->Add(template_url); | |
| 30 template_url_service->SetDefaultSearchProvider(template_url); | |
| 31 } | |
| 32 | |
| 33 // Build an Instant URL with or without a valid search terms replacement key | |
| 34 // as per |has_search_term_replacement_key|. Set that URL as the instant URL | |
| 35 // for the default search provider. | |
| 36 void SetDefaultInstantTemplateUrl(Profile* profile, | |
| 37 bool has_search_term_replacement_key) { | |
| 38 TemplateURLService* template_url_service = | |
| 39 TemplateURLServiceFactory::GetForProfile(profile); | |
| 40 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); | |
| 41 | |
| 42 static const char kInstantURLWithStrk[] = | |
| 43 "http://foo.com/instant?foo=foo#foo=foo&strk"; | |
| 44 static const char kInstantURLNoStrk[] = | |
| 45 "http://foo.com/instant?foo=foo#foo=foo"; | |
| 46 | |
| 47 TemplateURLData data; | |
| 48 data.short_name = ASCIIToUTF16("instafoo"); | |
| 49 data.SetURL("http://foo.com/url?bar={searchTerms}"); | |
| 50 data.suggestions_url = "http://foo.com/url?sug={searchTerms}"; | |
| 51 data.instant_url = (has_search_term_replacement_key ? kInstantURLWithStrk | |
| 52 : kInstantURLNoStrk); | |
| 53 data.search_terms_replacement_key = "strk"; | |
| 54 | |
| 55 TemplateURL* template_url = new TemplateURL(profile, data); | |
| 56 // Takes ownership of |template_url|. | |
| 57 template_url_service->Add(template_url); | |
| 58 template_url_service->SetDefaultSearchProvider(template_url); | |
| 59 } | |
| 60 } // namespace search_test_utils | |
| OLD | NEW |