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

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: new approach with Messages Created 7 years, 12 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..292d637fb5d49671c35d118bc8b0f650edd7f7f7 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
@@ -5,6 +5,8 @@
package org.chromium.content.browser.test.util;
+import android.os.Handler;
+import android.os.Message;
import android.util.Log;
import org.chromium.content.browser.ContentView;
@@ -81,8 +83,7 @@ public class TestCallbackHelperContainer {
}
public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper {
- private volatile Integer mRequestId;
- private volatile Integer mId;
+ private boolean mRequestSent;
private String mJsonResult;
/**
@@ -91,14 +92,23 @@ public class TestCallbackHelperContainer {
* @param code A JavaScript code to be evaluated.
*/
public void evaluateJavaScript(ContentViewCore contentViewCore, String code) {
- setRequestId(contentViewCore.evaluateJavaScript(code));
+ assert !mRequestSent;
+ Message message = Message.obtain(new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ notifyCalled(msg.obj);
joth 2013/01/05 00:54:42 will need to cast: notifyCalled((String) msg.obj);
Avi (use Gerrit) 2013/01/05 01:03:34 Already fixed in my local copy.
+ }
+ });
+ contentViewCore.evaluateJavaScript(code, message);
+ mRequestSent = true;
+ mJsonResult = null;
}
/**
* Returns true if the evaluation started by evaluateJavaScript() has completed.
*/
public boolean hasValue() {
- return mId != null;
+ return mJsonResult != null;
}
/**
@@ -109,7 +119,8 @@ public class TestCallbackHelperContainer {
public String getJsonResultAndClear() {
assert hasValue();
String result = mJsonResult;
- setRequestId(null);
+ mRequestSent = false;
+ mJsonResult = null;
return result;
}
@@ -141,21 +152,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