OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/content_settings/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
6 #include "chrome/browser/history/history_service_factory.h" | 6 #include "chrome/browser/history/history_service_factory.h" |
7 #include "chrome/browser/instant/instant_loader.h" | 7 #include "chrome/browser/instant/instant_loader.h" |
8 #include "chrome/browser/instant/instant_model_observer.h" | 8 #include "chrome/browser/instant/instant_model_observer.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 instant()->GetPreviewContents()->GetRenderProcessHost()->GetHandle(), | 98 instant()->GetPreviewContents()->GetRenderProcessHost()->GetHandle(), |
99 content::RESULT_CODE_KILLED, | 99 content::RESULT_CODE_KILLED, |
100 false); | 100 false); |
101 } | 101 } |
102 | 102 |
103 void FocusOmnibox() { | 103 void FocusOmnibox() { |
104 // If the omnibox already has focus, just notify Instant. | 104 // If the omnibox already has focus, just notify Instant. |
105 if (omnibox()->model()->has_focus()) { | 105 if (omnibox()->model()->has_focus()) { |
106 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, | 106 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, |
107 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); | 107 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); |
108 } | 108 } else { |
109 else { | |
110 browser()->window()->GetLocationBar()->FocusLocation(false); | 109 browser()->window()->GetLocationBar()->FocusLocation(false); |
111 } | 110 } |
112 } | 111 } |
113 | 112 |
114 void FocusOmniboxAndWaitForInstantSupport() { | 113 void FocusOmniboxAndWaitForInstantSupport() { |
115 content::WindowedNotificationObserver observer( | 114 content::WindowedNotificationObserver observer( |
116 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 115 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
117 content::NotificationService::AllSources()); | 116 content::NotificationService::AllSources()); |
118 FocusOmnibox(); | 117 FocusOmnibox(); |
119 observer.Wait(); | 118 observer.Wait(); |
120 } | 119 } |
121 | 120 |
122 void SetOmniboxText(const std::string& text) { | 121 void SetOmniboxText(const std::string& text) { |
123 FocusOmnibox(); | 122 FocusOmnibox(); |
124 omnibox()->SetUserText(UTF8ToUTF16(text)); | 123 omnibox()->SetUserText(UTF8ToUTF16(text)); |
125 } | 124 } |
126 | 125 |
127 void SetOmniboxTextAndWaitForInstantToShow(const std::string& text) { | 126 void SetOmniboxTextAndWaitForInstantToShow(const std::string& text) { |
128 InstantTestModelObserver observer( | 127 InstantTestModelObserver observer( |
129 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); | 128 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); |
130 SetOmniboxText(text); | 129 SetOmniboxText(text); |
131 observer.WaitUntilDesiredPreviewState(); | 130 observer.WaitUntilDesiredPreviewState(); |
132 } | 131 } |
133 | 132 |
134 std::wstring WrapScript(const std::string& script) const { | 133 std::string WrapScript(const std::string& script) const { |
135 return UTF8ToWide("domAutomationController.send(" + script + ")"); | 134 return "domAutomationController.send(" + script + ")"; |
136 } | 135 } |
137 | 136 |
138 bool GetBoolFromJS(content::RenderViewHost* rvh, | 137 bool GetBoolFromJS(content::RenderViewHost* rvh, |
139 const std::string& script, | 138 const std::string& script, |
140 bool* result) WARN_UNUSED_RESULT { | 139 bool* result) WARN_UNUSED_RESULT { |
141 return content::ExecuteJavaScriptAndExtractBool(rvh, std::wstring(), | 140 return content::ExecuteJavaScriptAndExtractBool(rvh, "", WrapScript(script), |
142 WrapScript(script), result); | 141 result); |
143 } | 142 } |
144 | 143 |
145 bool GetIntFromJS(content::RenderViewHost* rvh, | 144 bool GetIntFromJS(content::RenderViewHost* rvh, |
146 const std::string& script, | 145 const std::string& script, |
147 int* result) WARN_UNUSED_RESULT { | 146 int* result) WARN_UNUSED_RESULT { |
148 return content::ExecuteJavaScriptAndExtractInt(rvh, std::wstring(), | 147 return content::ExecuteJavaScriptAndExtractInt(rvh, "", WrapScript(script), |
149 WrapScript(script), result); | 148 result); |
150 } | 149 } |
151 | 150 |
152 bool GetStringFromJS(content::RenderViewHost* rvh, | 151 bool GetStringFromJS(content::RenderViewHost* rvh, |
153 const std::string& script, | 152 const std::string& script, |
154 std::string* result) WARN_UNUSED_RESULT { | 153 std::string* result) WARN_UNUSED_RESULT { |
155 return content::ExecuteJavaScriptAndExtractString( | 154 return content::ExecuteJavaScriptAndExtractString(rvh, "", |
156 rvh, std::wstring(), WrapScript(script), result); | 155 WrapScript(script), |
| 156 result); |
157 } | 157 } |
158 | 158 |
159 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { | 159 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { |
160 content::RenderViewHost* rvh = contents->GetRenderViewHost(); | 160 content::RenderViewHost* rvh = contents->GetRenderViewHost(); |
161 return GetIntFromJS(rvh, "onvisibilitycalls", &onvisibilitycalls_) && | 161 return GetIntFromJS(rvh, "onvisibilitycalls", &onvisibilitycalls_) && |
162 GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && | 162 GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && |
163 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && | 163 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && |
164 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && | 164 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && |
165 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && | 165 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && |
166 GetStringFromJS(rvh, "value", &value_) && | 166 GetStringFromJS(rvh, "value", &value_) && |
167 GetBoolFromJS(rvh, "verbatim", &verbatim_) && | 167 GetBoolFromJS(rvh, "verbatim", &verbatim_) && |
168 GetIntFromJS(rvh, "height", &height_); | 168 GetIntFromJS(rvh, "height", &height_); |
169 } | 169 } |
170 | 170 |
171 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT { | 171 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT { |
172 return content::ExecuteJavaScript( | 172 return content::ExecuteJavaScript( |
173 instant()->GetPreviewContents()->GetRenderViewHost(), std::wstring(), | 173 instant()->GetPreviewContents()->GetRenderViewHost(), |
174 UTF8ToWide(script)); | 174 "", |
| 175 script); |
175 } | 176 } |
176 | 177 |
177 bool CheckVisibilityIs(content::WebContents* contents, | 178 bool CheckVisibilityIs(content::WebContents* contents, |
178 bool expected) WARN_UNUSED_RESULT { | 179 bool expected) WARN_UNUSED_RESULT { |
179 bool actual = !expected; // Purposely start with a mis-match. | 180 bool actual = !expected; // Purposely start with a mis-match. |
180 // We can only use ASSERT_*() in a method that returns void, hence this | 181 // We can only use ASSERT_*() in a method that returns void, hence this |
181 // convoluted check. | 182 // convoluted check. |
182 return GetBoolFromJS(contents->GetRenderViewHost(), | 183 return GetBoolFromJS(contents->GetRenderViewHost(), |
183 "!document.webkitHidden", &actual) && | 184 "!document.webkitHidden", &actual) && |
184 actual == expected; | 185 actual == expected; |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 SetOmniboxTextAndWaitForInstantToShow("q"); | 1085 SetOmniboxTextAndWaitForInstantToShow("q"); |
1085 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 1086 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
1086 | 1087 |
1087 // Kill the instant renderer and wait for instant support again. | 1088 // Kill the instant renderer and wait for instant support again. |
1088 KillInstantRenderView(); | 1089 KillInstantRenderView(); |
1089 FocusOmniboxAndWaitForInstantSupport(); | 1090 FocusOmniboxAndWaitForInstantSupport(); |
1090 | 1091 |
1091 SetOmniboxTextAndWaitForInstantToShow("qu"); | 1092 SetOmniboxTextAndWaitForInstantToShow("qu"); |
1092 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 1093 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
1093 } | 1094 } |
OLD | NEW |