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

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

Issue 11883037: Revert 176773 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1384/src/
Patch Set: 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
===================================================================
--- 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();
}

Powered by Google App Engine
This is Rietveld 408576698