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 176919) |
+++ content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCallbackHelperContainer.java (working copy) |
@@ -81,6 +81,8 @@ |
} |
public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper { |
+ private volatile Integer mRequestId; |
+ private volatile Integer mId; |
private String mJsonResult; |
/** |
@@ -89,22 +91,14 @@ |
* @param code A JavaScript code to be evaluated. |
*/ |
public void evaluateJavaScript(ContentViewCore contentViewCore, String code) { |
- ContentViewCore.JavaScriptCallback callback = |
- new ContentViewCore.JavaScriptCallback() { |
- @Override |
- public void handleJavaScriptResult(String jsonResult) { |
- notifyCalled(jsonResult); |
- } |
- }; |
- contentViewCore.evaluateJavaScript(code, callback); |
- 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; |
} |
/** |
@@ -115,7 +109,7 @@ |
public String getJsonResultAndClear() { |
assert hasValue(); |
String result = mJsonResult; |
- mJsonResult = null; |
+ setRequestId(null); |
return result; |
} |
@@ -147,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(); |
} |