Chromium Code Reviews| 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..4323d52769ae4d9737a6e65abaa5b66adbeec498 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,24 @@ 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() { |
|
Avi (use Gerrit)
2013/01/05 21:57:09
Do I need a special Looper? Right now it all fires
mkosiba (inactive)
2013/01/07 10:42:09
The CallbackHelper should be threadsafe so you don
joth
2013/01/07 19:43:28
This isn't using a 'special' looper though? it is
|
| + @Override |
| + public void handleMessage(Message msg) { |
| + String json = (String)msg.obj; |
| + notifyCalled(json); |
| + } |
| + }); |
| + 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 +120,8 @@ public class TestCallbackHelperContainer { |
| public String getJsonResultAndClear() { |
| assert hasValue(); |
| String result = mJsonResult; |
| - setRequestId(null); |
| + mRequestSent = false; |
| + mJsonResult = null; |
| return result; |
| } |
| @@ -141,21 +153,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(); |
| } |