| 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 } else { | 108 } |
| 109 else { |
| 109 browser()->window()->GetLocationBar()->FocusLocation(false); | 110 browser()->window()->GetLocationBar()->FocusLocation(false); |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 void FocusOmniboxAndWaitForInstantSupport() { | 114 void FocusOmniboxAndWaitForInstantSupport() { |
| 114 content::WindowedNotificationObserver observer( | 115 content::WindowedNotificationObserver observer( |
| 115 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 116 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 116 content::NotificationService::AllSources()); | 117 content::NotificationService::AllSources()); |
| 117 FocusOmnibox(); | 118 FocusOmnibox(); |
| 118 observer.Wait(); | 119 observer.Wait(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void SetOmniboxText(const std::string& text) { | 122 void SetOmniboxText(const std::string& text) { |
| 122 FocusOmnibox(); | 123 FocusOmnibox(); |
| 123 omnibox()->SetUserText(UTF8ToUTF16(text)); | 124 omnibox()->SetUserText(UTF8ToUTF16(text)); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void SetOmniboxTextAndWaitForInstantToShow(const std::string& text) { | 127 void SetOmniboxTextAndWaitForInstantToShow(const std::string& text) { |
| 127 InstantTestModelObserver observer( | 128 InstantTestModelObserver observer( |
| 128 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); | 129 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); |
| 129 SetOmniboxText(text); | 130 SetOmniboxText(text); |
| 130 observer.WaitUntilDesiredPreviewState(); | 131 observer.WaitUntilDesiredPreviewState(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 std::string WrapScript(const std::string& script) const { | 134 std::wstring WrapScript(const std::string& script) const { |
| 134 return "domAutomationController.send(" + script + ")"; | 135 return UTF8ToWide("domAutomationController.send(" + script + ")"); |
| 135 } | 136 } |
| 136 | 137 |
| 137 bool GetBoolFromJS(content::RenderViewHost* rvh, | 138 bool GetBoolFromJS(content::RenderViewHost* rvh, |
| 138 const std::string& script, | 139 const std::string& script, |
| 139 bool* result) WARN_UNUSED_RESULT { | 140 bool* result) WARN_UNUSED_RESULT { |
| 140 return content::ExecuteJavaScriptAndExtractBool(rvh, "", WrapScript(script), | 141 return content::ExecuteJavaScriptAndExtractBool(rvh, std::wstring(), |
| 141 result); | 142 WrapScript(script), result); |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool GetIntFromJS(content::RenderViewHost* rvh, | 145 bool GetIntFromJS(content::RenderViewHost* rvh, |
| 145 const std::string& script, | 146 const std::string& script, |
| 146 int* result) WARN_UNUSED_RESULT { | 147 int* result) WARN_UNUSED_RESULT { |
| 147 return content::ExecuteJavaScriptAndExtractInt(rvh, "", WrapScript(script), | 148 return content::ExecuteJavaScriptAndExtractInt(rvh, std::wstring(), |
| 148 result); | 149 WrapScript(script), result); |
| 149 } | 150 } |
| 150 | 151 |
| 151 bool GetStringFromJS(content::RenderViewHost* rvh, | 152 bool GetStringFromJS(content::RenderViewHost* rvh, |
| 152 const std::string& script, | 153 const std::string& script, |
| 153 std::string* result) WARN_UNUSED_RESULT { | 154 std::string* result) WARN_UNUSED_RESULT { |
| 154 return content::ExecuteJavaScriptAndExtractString(rvh, "", | 155 return content::ExecuteJavaScriptAndExtractString( |
| 155 WrapScript(script), | 156 rvh, std::wstring(), WrapScript(script), result); |
| 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(), | 173 instant()->GetPreviewContents()->GetRenderViewHost(), std::wstring(), |
| 174 "", | 174 UTF8ToWide(script)); |
| 175 script); | |
| 176 } | 175 } |
| 177 | 176 |
| 178 bool CheckVisibilityIs(content::WebContents* contents, | 177 bool CheckVisibilityIs(content::WebContents* contents, |
| 179 bool expected) WARN_UNUSED_RESULT { | 178 bool expected) WARN_UNUSED_RESULT { |
| 180 bool actual = !expected; // Purposely start with a mis-match. | 179 bool actual = !expected; // Purposely start with a mis-match. |
| 181 // We can only use ASSERT_*() in a method that returns void, hence this | 180 // We can only use ASSERT_*() in a method that returns void, hence this |
| 182 // convoluted check. | 181 // convoluted check. |
| 183 return GetBoolFromJS(contents->GetRenderViewHost(), | 182 return GetBoolFromJS(contents->GetRenderViewHost(), |
| 184 "!document.webkitHidden", &actual) && | 183 "!document.webkitHidden", &actual) && |
| 185 actual == expected; | 184 actual == expected; |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 SetOmniboxTextAndWaitForInstantToShow("q"); | 1084 SetOmniboxTextAndWaitForInstantToShow("q"); |
| 1086 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 1085 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
| 1087 | 1086 |
| 1088 // Kill the instant renderer and wait for instant support again. | 1087 // Kill the instant renderer and wait for instant support again. |
| 1089 KillInstantRenderView(); | 1088 KillInstantRenderView(); |
| 1090 FocusOmniboxAndWaitForInstantSupport(); | 1089 FocusOmniboxAndWaitForInstantSupport(); |
| 1091 | 1090 |
| 1092 SetOmniboxTextAndWaitForInstantToShow("qu"); | 1091 SetOmniboxTextAndWaitForInstantToShow("qu"); |
| 1093 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 1092 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
| 1094 } | 1093 } |
| OLD | NEW |