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

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

Issue 11778034: Revert 175489 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/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 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

Powered by Google App Engine
This is Rietveld 408576698