Chromium Code Reviews| 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..e6f155adc531b472f015c69d0b6aafb44d47963f |
| --- /dev/null |
| +++ b/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java |
| @@ -0,0 +1,68 @@ |
| +// 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; |
| + |
| +/** |
| + * Test untilities lated to Sdch. |
|
mef
2015/05/19 21:39:44
nit: typos.
xunjieli
2015/05/20 15:50:41
Done. So many typos :( not sure whether my mind wa
|
| + */ |
| +@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 { |
|
mef
2015/05/19 21:39:44
nit: should it be interface OnDictionaryAddedListe
xunjieli
2015/05/20 15:50:41
You are right. If it's an interface, it should be
|
| + /** |
| + * 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( |
|
mef
2015/05/19 21:39:44
addDictionaryAddedListener?
xunjieli
2015/05/20 15:50:41
Done.
|
| + long contextAdapter, SdchObserver observer, boolean isLegacyAPI) { |
| + assertNull(sObserver); |
| + sObserver = observer; |
| + nativeAddRemoveSdchObserver(contextAdapter, isLegacyAPI, true /** add */); |
| + sAddRemoveBlock.block(); |
| + sAddRemoveBlock.close(); |
| + } |
| + |
| + public static void removeSdchObserver( |
|
mef
2015/05/19 21:39:44
removeDictionaryAddedListener?
xunjieli
2015/05/20 15:50:41
Done.
|
| + 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() { |
|
mef
2015/05/19 21:39:44
maybe call it 'onAddRemoveSdchObserverCompleted'?
xunjieli
2015/05/20 15:50:41
Done.
|
| + sAddRemoveBlock.open(); |
| + } |
| + |
| + private static native void nativeAddRemoveSdchObserver( |
| + long contextAdapter, boolean isLegacyAPI, boolean add); |
| +} |