Chromium Code Reviews| Index: content/public/test/browser_test_utils.cc |
| diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc |
| index 214b2fd61d678cca452e21f5e3fcde487f0bc5a8..d2600bbf3164da979295d2f8b9134621aa118819 100644 |
| --- a/content/public/test/browser_test_utils.cc |
| +++ b/content/public/test/browser_test_utils.cc |
| @@ -163,6 +163,43 @@ bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, |
| return true; |
| } |
| +// Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. |
| +bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
| + const int world_id, |
| + const std::string& original_script, |
| + scoped_ptr<base::Value>* result) |
| + WARN_UNUSED_RESULT; |
|
nasko
2015/09/02 21:59:40
Why not just add this on the method itself? Why do
mdjones
2015/09/03 01:38:29
The compiler throws an error if that attribute is
|
| + |
| +bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
| + const int world_id, |
| + const std::string& original_script, |
| + scoped_ptr<base::Value>* result) { |
| + std::string script = |
| + "window.domAutomationController.setAutomationId(0);" + original_script; |
| + DOMOperationObserver dom_op_observer(render_frame_host->GetRenderViewHost()); |
| + render_frame_host->ExecuteJavaScriptInIsolatedWorld( |
| + base::UTF8ToUTF16(script), |
| + content::RenderFrameHost::JavaScriptResultCallback(), world_id); |
| + std::string json; |
| + if (!dom_op_observer.WaitAndGetResponse(&json)) { |
| + DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; |
| + return false; |
| + } |
| + |
| + // Nothing more to do for callers that ignore the returned JS value. |
| + if (!result) |
| + return true; |
| + |
| + base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); |
| + *result = reader.ReadToValue(json); |
| + if (!*result) { |
| + DLOG(ERROR) << reader.GetErrorMessage(); |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, |
| ui::KeyboardCode key_code, |
| int native_key_code, |
| @@ -585,6 +622,22 @@ bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, |
| return value->GetAsBoolean(result); |
| } |
| +bool ExecuteScriptInIsolatedWorldAndExtractBool( |
| + const ToRenderFrameHost& adapter, |
| + const int world_id, |
| + const std::string& script, |
| + bool* result) { |
| + DCHECK(result); |
| + scoped_ptr<base::Value> value; |
| + if (!ExecuteScriptInIsolatedWorldHelper(adapter.render_frame_host(), world_id, |
| + script, &value) || |
| + !value.get()) { |
| + return false; |
| + } |
| + |
| + return value->GetAsBoolean(result); |
| +} |
| + |
| bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, |
| const std::string& script, |
| std::string* result) { |