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

Unified Diff: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java

Issue 11788005: Switch Android code to use ExecuteJavascriptInWebFrameCallbackResult. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweaks Created 7 years, 11 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/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java
diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java
index c7079ed0fe7470742d4d5504efdd74217cac7dce..fedc4a5bab71c23ef3314be3f3a57f877e9a36bd 100644
--- a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java
+++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java
@@ -81,8 +81,6 @@ public class TestCallbackHelperContainer {
}
public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper {
- private volatile Integer mRequestId;
- private volatile Integer mId;
private String mJsonResult;
/**
@@ -91,14 +89,22 @@ public class TestCallbackHelperContainer {
* @param code A JavaScript code to be evaluated.
*/
public void evaluateJavaScript(ContentViewCore contentViewCore, String code) {
- setRequestId(contentViewCore.evaluateJavaScript(code));
+ ContentViewCore.JavaScriptCallback callback =
+ new ContentViewCore.JavaScriptCallback() {
+ @Override
+ public void handleJavaScriptResult(String jsonResult) {
+ notifyCalled(jsonResult);
+ }
+ };
+ contentViewCore.evaluateJavaScript(code, callback);
+ mJsonResult = null;
}
/**
* Returns true if the evaluation started by evaluateJavaScript() has completed.
*/
public boolean hasValue() {
- return mId != null;
+ return mJsonResult != null;
}
/**
@@ -109,7 +115,7 @@ public class TestCallbackHelperContainer {
public String getJsonResultAndClear() {
assert hasValue();
String result = mJsonResult;
- setRequestId(null);
+ mJsonResult = null;
return result;
}
@@ -141,21 +147,8 @@ public class TestCallbackHelperContainer {
return hasValue();
}
- private void setRequestId(Integer requestId) {
- mRequestId = requestId;
- mId = null;
- mJsonResult = null;
- }
-
- public void notifyCalled(int id, String jsonResult) {
- if (mRequestId == null) {
- Log.w("TestCallbackHelperContainer",
- "Received JavaScript eval result when request id was not set");
- return;
- }
- if (id != mRequestId.intValue()) return;
- assert mId == null;
- mId = Integer.valueOf(id);
+ public void notifyCalled(String jsonResult) {
+ assert !hasValue();
mJsonResult = jsonResult;
notifyCalled();
}

Powered by Google App Engine
This is Rietveld 408576698