Chromium Code Reviews| 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..bc0402dac120e911c3af9cbf3e4cc2f02150f0b6 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,12 +15,11 @@ 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 final ConditionVariable mAddBlock = new ConditionVariable(); |
| + private static final int BLOCK_WAIT_TIMEOUT_SEC = 20; |
|
xunjieli
2017/02/21 20:11:34
nit: static before non-static fields.
kapishnikov
2017/02/21 20:30:55
Done.
|
| /** |
| * Constructor. |
| @@ -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); |
| } |