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

Side by Side Diff: chrome/browser/ui/search/instant_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: Format and lint Created 7 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/instant_test_utils.h" 5 #include "chrome/browser/ui/search/instant_test_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); 51 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}");
52 data.search_terms_replacement_key = "strk"; 52 data.search_terms_replacement_key = "strk";
53 53
54 TemplateURL* template_url = new TemplateURL(browser_->profile(), data); 54 TemplateURL* template_url = new TemplateURL(browser_->profile(), data);
55 service->Add(template_url); // Takes ownership of |template_url|. 55 service->Add(template_url); // Takes ownership of |template_url|.
56 service->SetDefaultSearchProvider(template_url); 56 service->SetDefaultSearchProvider(template_url);
57 57
58 InstantService* instant_service = 58 InstantService* instant_service =
59 InstantServiceFactory::GetForProfile(browser_->profile()); 59 InstantServiceFactory::GetForProfile(browser_->profile());
60 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 60 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
61 instant_service->ntp_prerenderer()->ReloadStaleNTP(); 61 instant_service->ntp_prerenderer()->ReloadInstantNTP();
62 } 62 }
63 63
64 void InstantTestBase::SetInstantURL(const std::string& url) { 64 void InstantTestBase::SetInstantURL(const std::string& url) {
65 TemplateURLService* service = 65 TemplateURLService* service =
66 TemplateURLServiceFactory::GetForProfile(browser_->profile()); 66 TemplateURLServiceFactory::GetForProfile(browser_->profile());
67 ui_test_utils::WaitForTemplateURLServiceToLoad(service); 67 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
68 68
69 TemplateURLData data; 69 TemplateURLData data;
70 data.SetURL(url); 70 data.SetURL(url);
71 data.instant_url = url; 71 data.instant_url = url;
(...skipping 11 matching lines...) Expand all
83 // If the omnibox already has focus, just notify Instant. 83 // If the omnibox already has focus, just notify Instant.
84 if (omnibox()->model()->has_focus()) { 84 if (omnibox()->model()->has_focus()) {
85 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, 85 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE,
86 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); 86 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL);
87 } else { 87 } else {
88 browser_->window()->GetLocationBar()->FocusLocation(false); 88 browser_->window()->GetLocationBar()->FocusLocation(false);
89 } 89 }
90 } 90 }
91 91
92 void InstantTestBase::FocusOmniboxAndWaitForInstantNTPSupport() { 92 void InstantTestBase::FocusOmniboxAndWaitForInstantNTPSupport() {
93 FocusOmnibox();
94 WaitForInstantNTPSupport();
95 }
96
97 void InstantTestBase::WaitForInstantNTPSupport() {
93 content::WindowedNotificationObserver ntp_observer( 98 content::WindowedNotificationObserver ntp_observer(
94 chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED, 99 chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
95 content::NotificationService::AllSources()); 100 content::NotificationService::AllSources());
96 FocusOmnibox();
samarth 2013/08/12 19:07:28 Are you sure this doesn't break any tests? You gen
Anuj 2013/08/13 00:18:09 Removed. I was earlier trying to make use of Insta
97 101
98 InstantService* instant_service = 102 InstantService* instant_service =
99 InstantServiceFactory::GetForProfile(browser_->profile()); 103 InstantServiceFactory::GetForProfile(browser_->profile());
100 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 104 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
101 if (!instant_service->ntp_prerenderer()->ntp() || 105 InstantNTP* ntp = instant_service->ntp_prerenderer()->ntp();
102 !instant_service->ntp_prerenderer()->ntp()->supports_instant()) 106 if (!ntp || !ntp->supports_instant())
103 ntp_observer.Wait(); 107 ntp_observer.Wait();
104 } 108 }
105 109
106 void InstantTestBase::SetOmniboxText(const std::string& text) { 110 void InstantTestBase::SetOmniboxText(const std::string& text) {
107 FocusOmnibox(); 111 FocusOmnibox();
108 omnibox()->SetUserText(UTF8ToUTF16(text)); 112 omnibox()->SetUserText(UTF8ToUTF16(text));
109 } 113 }
110 114
111 void InstantTestBase::PressEnterAndWaitForNavigation() { 115 void InstantTestBase::PressEnterAndWaitForNavigation() {
112 content::WindowedNotificationObserver nav_observer( 116 content::WindowedNotificationObserver nav_observer(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); 173 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded);
170 } 174 }
171 175
172 string16 InstantTestBase::GetBlueText() { 176 string16 InstantTestBase::GetBlueText() {
173 size_t start = 0, end = 0; 177 size_t start = 0, end = 0;
174 omnibox()->GetSelectionBounds(&start, &end); 178 omnibox()->GetSelectionBounds(&start, &end);
175 if (start > end) 179 if (start > end)
176 std::swap(start, end); 180 std::swap(start, end);
177 return omnibox()->GetText().substr(start, end - start); 181 return omnibox()->GetText().substr(start, end - start);
178 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698