Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java

Issue 1133883002: [Cronet] Enable persistence mode for Sdch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quic_server_remove_loop
Patch Set: Addressed Misha's comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..9bae947b71bf6d122d0b4c5fb592996d4235887f
--- /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 utilities related to Sdch.
+ */
+@JNINamespace("cronet")
+public final class SdchTestUtil {
+ // Blocks until the native SdchObserver is added or removed.
+ private static final ConditionVariable sAddRemoveBlock = 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;
+
+ public static void registerSdchObserverCallback(
+ long contextAdapter, SdchObserverCallback callback, boolean isLegacyAPI) {
+ assertNull(sCallback);
+ sCallback = callback;
+ nativeAddRemoveSdchObserver(contextAdapter, isLegacyAPI, true /** add */);
+ sAddRemoveBlock.block();
+ sAddRemoveBlock.close();
+ }
+
+ public static void unregisterSdchObserverCallback(
+ long contextAdapter, SdchObserverCallback callback, boolean isLegacyAPI) {
+ assertEquals(sCallback, callback);
+ sCallback = null;
+ nativeAddRemoveSdchObserver(contextAdapter, isLegacyAPI, false /** add */);
+ sAddRemoveBlock.block();
+ sAddRemoveBlock.close();
+ }
+
+ @CalledByNative
+ private static void onDictionaryAdded(String dictionaryURL) {
+ if (sCallback != null) {
+ sCallback.onDictionaryAdded(dictionaryURL);
+ }
+ }
+
+ @CalledByNative
+ private static void onAddRemoveSdchObserverCompleted() {
+ sAddRemoveBlock.open();
+ }
+
+ private static native void nativeAddRemoveSdchObserver(
+ long contextAdapter, boolean isLegacyAPI, boolean add);
+}

Powered by Google App Engine
This is Rietveld 408576698