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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 observer.WaitUntilDesiredPreviewState(); | 130 observer.WaitUntilDesiredPreviewState(); |
131 } | 131 } |
132 | 132 |
133 std::string WrapScript(const std::string& script) const { | 133 std::string WrapScript(const std::string& script) const { |
134 return "domAutomationController.send(" + script + ")"; | 134 return "domAutomationController.send(" + script + ")"; |
135 } | 135 } |
136 | 136 |
137 bool GetBoolFromJS(content::RenderViewHost* rvh, | 137 bool GetBoolFromJS(content::RenderViewHost* rvh, |
138 const std::string& script, | 138 const std::string& script, |
139 bool* result) WARN_UNUSED_RESULT { | 139 bool* result) WARN_UNUSED_RESULT { |
140 return content::ExecuteJavaScriptAndExtractBool(rvh, "", WrapScript(script), | 140 return content::ExecuteScriptAndExtractBool(rvh, WrapScript(script), |
141 result); | 141 result); |
142 } | 142 } |
143 | 143 |
144 bool GetIntFromJS(content::RenderViewHost* rvh, | 144 bool GetIntFromJS(content::RenderViewHost* rvh, |
145 const std::string& script, | 145 const std::string& script, |
146 int* result) WARN_UNUSED_RESULT { | 146 int* result) WARN_UNUSED_RESULT { |
147 return content::ExecuteJavaScriptAndExtractInt(rvh, "", WrapScript(script), | 147 return content::ExecuteScriptAndExtractInt(rvh, WrapScript(script), result); |
148 result); | |
149 } | 148 } |
150 | 149 |
151 bool GetStringFromJS(content::RenderViewHost* rvh, | 150 bool GetStringFromJS(content::RenderViewHost* rvh, |
152 const std::string& script, | 151 const std::string& script, |
153 std::string* result) WARN_UNUSED_RESULT { | 152 std::string* result) WARN_UNUSED_RESULT { |
154 return content::ExecuteJavaScriptAndExtractString(rvh, "", | 153 return content::ExecuteScriptAndExtractString(rvh, WrapScript(script), |
155 WrapScript(script), | 154 result); |
156 result); | |
157 } | 155 } |
158 | 156 |
159 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { | 157 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { |
160 content::RenderViewHost* rvh = contents->GetRenderViewHost(); | 158 content::RenderViewHost* rvh = contents->GetRenderViewHost(); |
161 return GetIntFromJS(rvh, "onvisibilitycalls", &onvisibilitycalls_) && | 159 return GetIntFromJS(rvh, "onvisibilitycalls", &onvisibilitycalls_) && |
162 GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && | 160 GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && |
163 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && | 161 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && |
164 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && | 162 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && |
165 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && | 163 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && |
166 GetStringFromJS(rvh, "value", &value_) && | 164 GetStringFromJS(rvh, "value", &value_) && |
167 GetBoolFromJS(rvh, "verbatim", &verbatim_) && | 165 GetBoolFromJS(rvh, "verbatim", &verbatim_) && |
168 GetIntFromJS(rvh, "height", &height_); | 166 GetIntFromJS(rvh, "height", &height_); |
169 } | 167 } |
170 | 168 |
171 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT { | 169 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT { |
172 return content::ExecuteJavaScript( | 170 return content::ExecuteScript( |
173 instant()->GetPreviewContents()->GetRenderViewHost(), | 171 instant()->GetPreviewContents()->GetRenderViewHost(), script); |
174 "", | |
175 script); | |
176 } | 172 } |
177 | 173 |
178 bool CheckVisibilityIs(content::WebContents* contents, | 174 bool CheckVisibilityIs(content::WebContents* contents, |
179 bool expected) WARN_UNUSED_RESULT { | 175 bool expected) WARN_UNUSED_RESULT { |
180 bool actual = !expected; // Purposely start with a mis-match. | 176 bool actual = !expected; // Purposely start with a mis-match. |
181 // We can only use ASSERT_*() in a method that returns void, hence this | 177 // We can only use ASSERT_*() in a method that returns void, hence this |
182 // convoluted check. | 178 // convoluted check. |
183 return GetBoolFromJS(contents->GetRenderViewHost(), | 179 return GetBoolFromJS(contents->GetRenderViewHost(), |
184 "!document.webkitHidden", &actual) && | 180 "!document.webkitHidden", &actual) && |
185 actual == expected; | 181 actual == expected; |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 SetOmniboxTextAndWaitForInstantToShow("q"); | 1081 SetOmniboxTextAndWaitForInstantToShow("q"); |
1086 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 1082 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
1087 | 1083 |
1088 // Kill the instant renderer and wait for instant support again. | 1084 // Kill the instant renderer and wait for instant support again. |
1089 KillInstantRenderView(); | 1085 KillInstantRenderView(); |
1090 FocusOmniboxAndWaitForInstantSupport(); | 1086 FocusOmniboxAndWaitForInstantSupport(); |
1091 | 1087 |
1092 SetOmniboxTextAndWaitForInstantToShow("qu"); | 1088 SetOmniboxTextAndWaitForInstantToShow("qu"); |
1093 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 1089 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
1094 } | 1090 } |
OLD | NEW |