Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Unified Diff: content/browser/web_contents/web_contents_android.cc

Issue 1123783002: Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_android.cc
diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc
index 33296c100ab1fde8f60151aee7c38d474b1afd0a..8fd5c506a2dfb263920e9538108c22af5985d837 100644
--- a/content/browser/web_contents/web_contents_android.cc
+++ b/content/browser/web_contents/web_contents_android.cc
@@ -440,6 +440,39 @@ void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env,
ConvertJavaStringToUTF16(env, script), js_callback);
}
+void WebContentsAndroid::EvaluateJavaScriptForTests(JNIEnv* env,
+ jobject obj,
+ jstring script,
+ jobject callback) {
+ RenderViewHost* rvh = web_contents_->GetRenderViewHost();
+ DCHECK(rvh);
+
+ if (!rvh->IsRenderViewLive()) {
+ if (!static_cast<WebContentsImpl*>(web_contents_)->
+ CreateRenderViewForInitialEmptyDocument()) {
+ LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScriptForTests";
+ return;
+ }
+ }
+
+ if (!callback) {
+ // No callback requested.
+ web_contents_->GetMainFrame()->ExecuteJavaScriptForTests(
+ ConvertJavaStringToUTF16(env, script));
+ return;
+ }
+
+ // Secure the Java callback in a scoped object and give ownership of it to the
+ // base::Callback.
+ ScopedJavaGlobalRef<jobject> j_callback;
+ j_callback.Reset(env, callback);
+ RenderFrameHost::JavaScriptResultCallback js_callback =
+ base::Bind(&JavaScriptResultCallback, j_callback);
+
+ web_contents_->GetMainFrame()->ExecuteJavaScriptForTests(
+ ConvertJavaStringToUTF16(env, script), js_callback);
+}
+
void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env,
jobject jobj,
jint level,

Powered by Google App Engine
This is Rietveld 408576698