| 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..66d8625318cebd77c2d62c91cc25f4a7acaf1332
|
| --- /dev/null
|
| +++ b/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
|
| @@ -0,0 +1,69 @@
|
| +// 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.assertEquals;
|
| +import static junit.framework.Assert.assertNull;
|
| +
|
| +import org.chromium.base.CalledByNative;
|
| +import org.chromium.base.JNINamespace;
|
| +
|
| +/**
|
| + * Wrapper class to start an in-process native test server, and get URLs
|
| + * needed to talk to it.
|
| + */
|
| +@JNINamespace("cronet")
|
| +public final class SdchTestUtil {
|
| + // Blocks until Sdch observer is added or removed.
|
| + private static final ConditionVariable sAddRemoveBlock = new ConditionVariable();
|
| +
|
| + /**
|
| + * SdchObserver interface.
|
| + */
|
| + public static interface SdchObserver {
|
| + /**
|
| + * Called when a dictionary is added to the SdchManager.
|
| + * @param url the url of the dictionary added.
|
| + */
|
| + public void onDictionaryAdded(String url);
|
| + }
|
| +
|
| + private static SdchObserver sObserver;
|
| +
|
| + public static void addSdchObserver(
|
| + long contextAdapter, SdchObserver observer, boolean isLegacyAPI) {
|
| + assertNull(sObserver);
|
| + sObserver = observer;
|
| + nativeAddRemoveSdchObserver(contextAdapter, isLegacyAPI, true /** add */);
|
| + sAddRemoveBlock.block();
|
| + sAddRemoveBlock.close();
|
| + }
|
| +
|
| + public static void removeSdchObserver(
|
| + long contextAdapter, SdchObserver observer, boolean isLegacyAPI) {
|
| + assertEquals(sObserver, observer);
|
| + sObserver = null;
|
| + nativeAddRemoveSdchObserver(contextAdapter, isLegacyAPI, false /** add */);
|
| + sAddRemoveBlock.block();
|
| + sAddRemoveBlock.close();
|
| + }
|
| +
|
| + @CalledByNative
|
| + private static void onDictionaryAdded(String dictionaryURL) {
|
| + if (sObserver != null) {
|
| + sObserver.onDictionaryAdded(dictionaryURL);
|
| + }
|
| + }
|
| +
|
| + @CalledByNative
|
| + private static void onAddRemoveSdchObserver() {
|
| + sAddRemoveBlock.open();
|
| + }
|
| +
|
| + private static native void nativeAddRemoveSdchObserver(
|
| + long contextAdapter, boolean isLegacyAPI, boolean add);
|
| +}
|
|
|