Index: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java |
=================================================================== |
--- content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java (revision 175490) |
+++ content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java (working copy) |
@@ -5,8 +5,6 @@ |
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; |
@@ -83,7 +81,8 @@ |
} |
public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper { |
- private boolean mRequestSent; |
+ private volatile Integer mRequestId; |
+ private volatile Integer mId; |
private String mJsonResult; |
/** |
@@ -92,24 +91,14 @@ |
* @param code A JavaScript code to be evaluated. |
*/ |
public void evaluateJavaScript(ContentViewCore contentViewCore, String code) { |
- assert !mRequestSent; |
- Message message = Message.obtain(new Handler() { |
- @Override |
- public void handleMessage(Message msg) { |
- String json = (String)msg.obj; |
- notifyCalled(json); |
- } |
- }); |
- contentViewCore.evaluateJavaScript(code, message); |
- mRequestSent = true; |
- mJsonResult = null; |
+ setRequestId(contentViewCore.evaluateJavaScript(code)); |
} |
/** |
* Returns true if the evaluation started by evaluateJavaScript() has completed. |
*/ |
public boolean hasValue() { |
- return mJsonResult != null; |
+ return mId != null; |
} |
/** |
@@ -120,8 +109,7 @@ |
public String getJsonResultAndClear() { |
assert hasValue(); |
String result = mJsonResult; |
- mRequestSent = false; |
- mJsonResult = null; |
+ setRequestId(null); |
return result; |
} |
@@ -153,8 +141,21 @@ |
return hasValue(); |
} |
- public void notifyCalled(String jsonResult) { |
- assert !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); |
mJsonResult = jsonResult; |
notifyCalled(); |
} |
Property changes on: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java |
___________________________________________________________________ |
Deleted: svn:mergeinfo |