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

Side by Side Diff: chrome/browser/instant/instant_test_utils.cc

Issue 11896113: Add chrome-search: access from Instant overlay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Yet another rebase Created 7 years, 9 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 | Annotate | Revision Log
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/instant/instant_test_utils.h" 5 #include "chrome/browser/instant/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 "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/omnibox/omnibox_view.h"
13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/interactive_test_utils.h" 16 #include "chrome/test/base/interactive_test_utils.h"
14 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/result_codes.h" 21 #include "content/public/common/result_codes.h"
18 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
19 23
20 namespace { 24 namespace {
21 25
22 std::string WrapScript(const std::string& script) { 26 std::string WrapScript(const std::string& script) {
23 return "domAutomationController.send(" + script + ")"; 27 return "domAutomationController.send(" + script + ")";
24 } 28 }
(...skipping 19 matching lines...) Expand all
44 } 48 }
45 49
46 void InstantTestModelObserver::OverlayStateChanged( 50 void InstantTestModelObserver::OverlayStateChanged(
47 const InstantOverlayModel& model) { 51 const InstantOverlayModel& model) {
48 if (model.mode().mode == desired_mode_type_) 52 if (model.mode().mode == desired_mode_type_)
49 run_loop_.Quit(); 53 run_loop_.Quit();
50 } 54 }
51 55
52 // InstantTestBase ----------------------------------------------------------- 56 // InstantTestBase -----------------------------------------------------------
53 57
54 void InstantTestBase::SetupInstant() { 58 void InstantTestBase::SetupInstant(Browser* browser) {
59 browser_ = browser;
55 TemplateURLService* service = 60 TemplateURLService* service =
56 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 61 TemplateURLServiceFactory::GetForProfile(browser_->profile());
57 ui_test_utils::WaitForTemplateURLServiceToLoad(service); 62 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
58 63
59 TemplateURLData data; 64 TemplateURLData data;
60 // Necessary to use exact URL for both the main URL and the alternate URL for 65 // Necessary to use exact URL for both the main URL and the alternate URL for
61 // search term extraction to work in InstantExtended. 66 // search term extraction to work in InstantExtended.
62 data.SetURL(instant_url_.spec() + "q={searchTerms}"); 67 data.SetURL(instant_url_.spec() + "q={searchTerms}");
63 data.instant_url = instant_url_.spec(); 68 data.instant_url = instant_url_.spec();
64 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); 69 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}");
65 data.search_terms_replacement_key = "strk"; 70 data.search_terms_replacement_key = "strk";
66 71
67 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); 72 TemplateURL* template_url = new TemplateURL(browser_->profile(), data);
68 service->Add(template_url); // Takes ownership of |template_url|. 73 service->Add(template_url); // Takes ownership of |template_url|.
69 service->SetDefaultSearchProvider(template_url); 74 service->SetDefaultSearchProvider(template_url);
70 75
71 browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); 76 browser_->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true);
72 77
73 // TODO(shishir): Fix this ugly hack. 78 // TODO(shishir): Fix this ugly hack.
74 instant()->SetInstantEnabled(false, true); 79 instant()->SetInstantEnabled(false, true);
75 instant()->SetInstantEnabled(true, false); 80 instant()->SetInstantEnabled(true, false);
76 } 81 }
77 82
83 void InstantTestBase::Init(const GURL& instant_url) {
84 instant_url_ = instant_url;
85 }
86
78 void InstantTestBase::KillInstantRenderView() { 87 void InstantTestBase::KillInstantRenderView() {
79 base::KillProcess( 88 base::KillProcess(
80 instant()->GetOverlayContents()->GetRenderProcessHost()->GetHandle(), 89 instant()->GetOverlayContents()->GetRenderProcessHost()->GetHandle(),
81 content::RESULT_CODE_KILLED, 90 content::RESULT_CODE_KILLED,
82 false); 91 false);
83 } 92 }
84 93
85 void InstantTestBase::FocusOmnibox() { 94 void InstantTestBase::FocusOmnibox() {
86 // If the omnibox already has focus, just notify Instant. 95 // If the omnibox already has focus, just notify Instant.
87 if (omnibox()->model()->has_focus()) { 96 if (omnibox()->model()->has_focus()) {
88 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, 97 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE,
89 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); 98 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL);
90 } else { 99 } else {
91 browser()->window()->GetLocationBar()->FocusLocation(false); 100 browser_->window()->GetLocationBar()->FocusLocation(false);
92 } 101 }
93 } 102 }
94 103
104 void InstantTestBase::FocusOmniboxAndWaitForInstantSupport() {
105 content::WindowedNotificationObserver observer(
106 chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED,
107 content::NotificationService::AllSources());
108 FocusOmnibox();
109 observer.Wait();
110 }
111
112 void InstantTestBase::FocusOmniboxAndWaitForInstantExtendedSupport() {
113 content::WindowedNotificationObserver ntp_observer(
114 chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
115 content::NotificationService::AllSources());
116 content::WindowedNotificationObserver overlay_observer(
117 chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED,
118 content::NotificationService::AllSources());
119 FocusOmnibox();
120 ntp_observer.Wait();
121 overlay_observer.Wait();
122 }
123
95 void InstantTestBase::SetOmniboxText(const std::string& text) { 124 void InstantTestBase::SetOmniboxText(const std::string& text) {
96 FocusOmnibox(); 125 FocusOmnibox();
97 omnibox()->SetUserText(UTF8ToUTF16(text)); 126 omnibox()->SetUserText(UTF8ToUTF16(text));
98 } 127 }
99 128
100 void InstantTestBase::SetOmniboxTextAndWaitForOverlayToShow( 129 void InstantTestBase::SetOmniboxTextAndWaitForOverlayToShow(
101 const std::string& text) { 130 const std::string& text) {
102 InstantTestModelObserver observer( 131 InstantTestModelObserver observer(
103 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); 132 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS);
104 SetOmniboxText(text); 133 SetOmniboxText(text);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 actual == expected; 168 actual == expected;
140 } 169 }
141 170
142 bool InstantTestBase::HasUserInputInProgress() { 171 bool InstantTestBase::HasUserInputInProgress() {
143 return omnibox()->model()->user_input_in_progress_; 172 return omnibox()->model()->user_input_in_progress_;
144 } 173 }
145 174
146 bool InstantTestBase::HasTemporaryText() { 175 bool InstantTestBase::HasTemporaryText() {
147 return omnibox()->model()->has_temporary_text_; 176 return omnibox()->model()->has_temporary_text_;
148 } 177 }
178
179 bool InstantTestBase::LoadImage(content::RenderViewHost* rvh,
180 const std::string& image,
181 bool* loaded) {
182 std::string js_chrome =
183 "var img = document.createElement('img');"
184 "img.onerror = function() { domAutomationController.send(false); };"
185 "img.onload = function() { domAutomationController.send(true); };"
186 "img.src = '" + image + "';";
187 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded);
188 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_test_utils.h ('k') | chrome/browser/net/chrome_url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698