| Index: components/cronet/android/test/src/org/chromium/net/SdchObserver.java
|
| diff --git a/components/cronet/android/test/src/org/chromium/net/SdchObserver.java b/components/cronet/android/test/src/org/chromium/net/SdchObserver.java
|
| index 8e8fe127baab8542b42cf87bff6798284d80d1b4..2028c09040c7b3170ade5627ea3dd9974c8058ec 100644
|
| --- a/components/cronet/android/test/src/org/chromium/net/SdchObserver.java
|
| +++ b/components/cronet/android/test/src/org/chromium/net/SdchObserver.java
|
| @@ -6,6 +6,8 @@ package org.chromium.net;
|
|
|
| import android.os.ConditionVariable;
|
|
|
| +import junit.framework.Assert;
|
| +
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
|
|
| @@ -13,11 +15,10 @@ import org.chromium.base.annotations.JNINamespace;
|
| * Class to watch for Sdch dictionary events. The native implementation
|
| * unregisters itself when an event happens. Therefore, an instance of this
|
| * class is only able to receive a notification of the earliest event.
|
| - * Currently, implemented events include {@link #onDictionaryAdded}.
|
| */
|
| @JNINamespace("cronet")
|
| public class SdchObserver {
|
| - protected boolean mDictionaryAlreadyPresent = false;
|
| + private static final int BLOCK_WAIT_TIMEOUT_SEC = 20;
|
| private final ConditionVariable mAddBlock = new ConditionVariable();
|
|
|
| /**
|
| @@ -27,29 +28,39 @@ public class SdchObserver {
|
| */
|
| public SdchObserver(String targetUrl, long contextAdapter) {
|
| nativeAddSdchObserver(targetUrl, contextAdapter);
|
| - mAddBlock.block();
|
| - mAddBlock.close();
|
| }
|
|
|
| /**
|
| * Called when a dictionary is added to the SdchManager for the target url.
|
| - * Override this method if caller would like to get notified.
|
| */
|
| @CalledByNative
|
| - public void onDictionaryAdded() {
|
| - // Left blank;
|
| + protected void onDictionaryAdded() {
|
| + mAddBlock.open();
|
| }
|
|
|
| + /**
|
| + * Called after the observer has been registered.
|
| + */
|
| @CalledByNative
|
| - private void onAddSdchObserverCompleted() {
|
| - mAddBlock.open();
|
| + protected void onAddSdchObserverCompleted() {
|
| + // Left blank;
|
| }
|
|
|
| + /**
|
| + * Called if the dictionary was added before the observer registration.
|
| + */
|
| @CalledByNative
|
| - private void onDictionarySetAlreadyPresent() {
|
| - mDictionaryAlreadyPresent = true;
|
| + protected void onDictionarySetAlreadyPresent() {
|
| mAddBlock.open();
|
| }
|
|
|
| + public void waitForDictionaryAdded() {
|
| + boolean success = mAddBlock.block(BLOCK_WAIT_TIMEOUT_SEC * 1000);
|
| + if (!success) {
|
| + Assert.fail("Timeout: the dictionary hasn't been added after waiting for "
|
| + + BLOCK_WAIT_TIMEOUT_SEC + " seconds");
|
| + }
|
| + }
|
| +
|
| private native void nativeAddSdchObserver(String targetUrl, long contextAdapter);
|
| }
|
|
|