| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 void InstantTestBase::PressEnterAndWaitForFrameLoad() { | 99 void InstantTestBase::PressEnterAndWaitForFrameLoad() { |
| 100 content::WindowedNotificationObserver nav_observer( | 100 content::WindowedNotificationObserver nav_observer( |
| 101 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 101 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 102 content::NotificationService::AllSources()); | 102 content::NotificationService::AllSources()); |
| 103 browser_->window()->GetLocationBar()->AcceptInput(); | 103 browser_->window()->GetLocationBar()->AcceptInput(); |
| 104 nav_observer.Wait(); | 104 nav_observer.Wait(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool InstantTestBase::GetBoolFromJS(content::WebContents* contents, | 107 bool InstantTestBase::GetBoolFromJS(const content::ToRenderFrameHost& adapter, |
| 108 const std::string& script, | 108 const std::string& script, |
| 109 bool* result) { | 109 bool* result) { |
| 110 return content::ExecuteScriptAndExtractBool( | 110 return content::ExecuteScriptAndExtractBool(adapter, WrapScript(script), |
| 111 contents, WrapScript(script), result); | 111 result); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool InstantTestBase::GetIntFromJS(content::WebContents* contents, | 114 bool InstantTestBase::GetIntFromJS(const content::ToRenderFrameHost& adapter, |
| 115 const std::string& script, | 115 const std::string& script, |
| 116 int* result) { | 116 int* result) { |
| 117 return content::ExecuteScriptAndExtractInt( | 117 return content::ExecuteScriptAndExtractInt(adapter, WrapScript(script), |
| 118 contents, WrapScript(script), result); | 118 result); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool InstantTestBase::GetDoubleFromJS(content::WebContents* contents, | 121 bool InstantTestBase::GetDoubleFromJS(const content::ToRenderFrameHost& adapter, |
| 122 const std::string& script, | 122 const std::string& script, |
| 123 double* result) { | 123 double* result) { |
| 124 return content::ExecuteScriptAndExtractDouble(contents, WrapScript(script), | 124 return content::ExecuteScriptAndExtractDouble(adapter, WrapScript(script), |
| 125 result); | 125 result); |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool InstantTestBase::GetStringFromJS(content::WebContents* contents, | 128 bool InstantTestBase::GetStringFromJS(const content::ToRenderFrameHost& adapter, |
| 129 const std::string& script, | 129 const std::string& script, |
| 130 std::string* result) { | 130 std::string* result) { |
| 131 return content::ExecuteScriptAndExtractString( | 131 return content::ExecuteScriptAndExtractString(adapter, WrapScript(script), |
| 132 contents, WrapScript(script), result); | 132 result); |
| 133 } | 133 } |
| 134 | 134 |
| 135 std::string InstantTestBase::GetOmniboxText() { | 135 std::string InstantTestBase::GetOmniboxText() { |
| 136 return base::UTF16ToUTF8(omnibox()->GetText()); | 136 return base::UTF16ToUTF8(omnibox()->GetText()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool InstantTestBase::LoadImage(content::RenderViewHost* rvh, | 139 bool InstantTestBase::LoadImage(content::RenderViewHost* rvh, |
| 140 const std::string& image, | 140 const std::string& image, |
| 141 bool* loaded) { | 141 bool* loaded) { |
| 142 std::string js_chrome = | 142 std::string js_chrome = |
| 143 "var img = document.createElement('img');" | 143 "var img = document.createElement('img');" |
| 144 "img.onerror = function() { domAutomationController.send(false); };" | 144 "img.onerror = function() { domAutomationController.send(false); };" |
| 145 "img.onload = function() { domAutomationController.send(true); };" | 145 "img.onload = function() { domAutomationController.send(true); };" |
| 146 "img.src = '" + image + "';"; | 146 "img.src = '" + image + "';"; |
| 147 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); | 147 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); |
| 148 } | 148 } |
| OLD | NEW |