| Index: components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
|
| diff --git a/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java b/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0559dbedfd4b1e4b8d0a096a042949afe4562470
|
| --- /dev/null
|
| +++ b/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
|
| @@ -0,0 +1,67 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.net;
|
| +
|
| +import android.os.ConditionVariable;
|
| +
|
| +import static junit.framework.Assert.assertNull;
|
| +
|
| +import org.chromium.base.CalledByNative;
|
| +import org.chromium.base.JNINamespace;
|
| +
|
| +/**
|
| + * Test utilities related to Sdch.
|
| + */
|
| +@JNINamespace("cronet")
|
| +public final class SdchTestUtil {
|
| + // Blocks until the native SdchObserver is added.
|
| + private static final ConditionVariable sAddBlock = new ConditionVariable();
|
| +
|
| + /**
|
| + * Abstract class to listen for callbacks of the native SdchObserver.
|
| + */
|
| + public abstract static class SdchObserverCallback {
|
| + /**
|
| + * Called when a dictionary is added to the SdchManager.
|
| + * @param url the url of the dictionary added.
|
| + */
|
| + public abstract void onDictionaryAdded(String url);
|
| + }
|
| +
|
| + private static SdchObserverCallback sCallback;
|
| + private static boolean sRegisterSdchObserverSucceeded = false;
|
| +
|
| + /**
|
| + * Returns whether the native SdchObserver has been registered. The native
|
| + * SdchObserver will not be registered when dictionaries for the
|
| + * {@code targetUrl} are already loaded, for example.
|
| + */
|
| + public static boolean registerSdchObserverCallback(String targetUrl, long contextAdapter,
|
| + SdchObserverCallback callback, boolean isLegacyAPI) {
|
| + assertNull(sCallback);
|
| + sCallback = callback;
|
| + nativeAddSdchObserver(targetUrl, contextAdapter, isLegacyAPI);
|
| + sAddBlock.block();
|
| + sAddBlock.close();
|
| + return sRegisterSdchObserverSucceeded;
|
| + }
|
| +
|
| + @CalledByNative
|
| + private static void onDictionaryAdded(String dictionaryURL) {
|
| + if (sCallback != null) {
|
| + sCallback.onDictionaryAdded(dictionaryURL);
|
| + sCallback = null;
|
| + }
|
| + }
|
| +
|
| + @CalledByNative
|
| + private static void onAddSdchObserverCompleted(boolean succeeded) {
|
| + sRegisterSdchObserverSucceeded = succeeded;
|
| + sAddBlock.open();
|
| + }
|
| +
|
| + private static native void nativeAddSdchObserver(
|
| + String targetUrl, long contextAdapter, boolean isLegacyAPI);
|
| +}
|
|
|