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

Side by Side Diff: chrome/browser/search/instant_unittest_base.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: Fixed InstantNTPPrerendererTest Created 7 years, 3 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/search/instant_unittest_base.h ('k') | chrome/browser/ui/OWNERS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 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 "chrome/browser/search/instant_unittest_base.h"
6 #include <string>
7
8 #include "base/basictypes.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/google/google_url_tracker.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search/instant_service.h"
13 #include "chrome/browser/search/instant_service_factory.h"
14 #include "chrome/browser/search/search.h"
15 #include "chrome/browser/search_engines/search_terms_data.h"
16 #include "chrome/browser/search_engines/template_url.h"
17 #include "chrome/browser/search_engines/template_url_service.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h"
19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/browser_with_test_window_test.h"
21 #include "chrome/test/base/testing_pref_service_syncable.h"
22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/notification_source.h"
26
27 void InstantUnitTestBase::SetUp() {
28 chrome::EnableInstantExtendedAPIForTesting();
29 BrowserWithTestWindowTest::SetUp();
30
31 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
32 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
33 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile());
34 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_);
35
36 UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/");
37 TestingPrefServiceSyncable* pref_service = profile()->GetTestingPrefService();
38 pref_service->SetUserPref(prefs::kLastPromptedGoogleURL,
39 new base::StringValue("https://www.google.com/"));
40 SetDefaultSearchProvider("{google:baseURL}");
41 instant_service_ = InstantServiceFactory::GetForProfile(profile());
42 }
43
44 void InstantUnitTestBase::TearDown() {
45 UIThreadSearchTermsData::SetGoogleBaseURL("");
46 BrowserWithTestWindowTest::TearDown();
47 }
48
49 void InstantUnitTestBase::SetDefaultSearchProvider(
50 const std::string& base_url) {
51 TemplateURLData data;
52 data.SetURL(base_url + "url?bar={searchTerms}");
53 data.instant_url = base_url + "instant?"
54 "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk";
55 data.alternate_urls.push_back(base_url + "alt#quux={searchTerms}");
56 data.search_terms_replacement_key = "strk";
57
58 TemplateURL* template_url = new TemplateURL(profile(), data);
59 // Takes ownership of |template_url|.
60 template_url_service_->Add(template_url);
61 template_url_service_->SetDefaultSearchProvider(template_url);
62 }
63
64 void InstantUnitTestBase::NotifyGoogleBaseURLUpdate(
65 const std::string& new_google_base_url) {
66 // GoogleURLTracker is not created in tests.
67 // (See GoogleURLTrackerFactory::ServiceIsNULLWhileTesting())
68 // For determining google:baseURL for NTP, the following is used:
69 // UIThreadSearchTermsData::GoogleBaseURLValue()
70 // For simulating test behavior, this is overridden below.
71 UIThreadSearchTermsData::SetGoogleBaseURL(new_google_base_url);
72 GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"),
73 GURL(new_google_base_url));
74 content::NotificationService::current()->Notify(
75 chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
76 content::Source<Profile>(profile()->GetOriginalProfile()),
77 content::Details<GoogleURLTracker::UpdatedDetails>(&details));
78 }
79
80
81 bool InstantUnitTestBase::IsInstantServiceObserver(
82 InstantServiceObserver* observer) {
83 return instant_service_->observers_.HasObserver(observer);
84 }
85
OLDNEW
« no previous file with comments | « chrome/browser/search/instant_unittest_base.h ('k') | chrome/browser/ui/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698