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

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/util/CookieUtils.java

Issue 273873003: Adds Asynchronous APIs to CookieManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed bad comment and indent. Created 6 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: android_webview/javatests/src/org/chromium/android_webview/test/util/CookieUtils.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/util/CookieUtils.java b/android_webview/javatests/src/org/chromium/android_webview/test/util/CookieUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..15484f7467f794457ea3a6b7d5d2615d70a46945
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/util/CookieUtils.java
@@ -0,0 +1,84 @@
+// Copyright 2014 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.android_webview.test.util;
+
+import android.webkit.ValueCallback;
+
+import junit.framework.Assert;
+
+import org.chromium.android_webview.AwCookieManager;
+import org.chromium.android_webview.test.AwTestBase;
+import org.chromium.content.browser.test.util.CallbackHelper;
+
+/**
+ * Useful functions for testing the CookieManager.
+ */
+public class CookieUtils {
+ private CookieUtils() {
+ }
+
+
+ /**
+ * A CallbackHelper for use with setCookie/removeXXXCookie.
+ */
+ public static class TestValueCallback<T> implements ValueCallback<T> {
+ /**
+ * We only have one intresting method on ValueCallback: onReceiveValue.
+ */
+ public static class OnReceiveValueHelper<T> extends CallbackHelper {
+ private T mValue;
+
+ public T getValue() {
+ assert getCallCount() > 0;
+ return mValue;
+ }
+
+ public void notifyCalled(T value) {
+ mValue = value;
+ notifyCalled();
+ }
+ }
+
+ private OnReceiveValueHelper<T> mOnReceiveValueHelper;
+
+ public TestValueCallback() {
+ mOnReceiveValueHelper = new OnReceiveValueHelper<T>();
+ }
+
+ public OnReceiveValueHelper getOnReceiveValueHelper() {
+ return mOnReceiveValueHelper;
+ }
+
+ @Override
+ public void onReceiveValue(T value) {
+ mOnReceiveValueHelper.notifyCalled(value);
+ }
+
+ public T getValue() {
+ return mOnReceiveValueHelper.getValue();
+ }
+ }
+
+ /**
+ * Clear all cookies from the CookieManager synchronously then assert they are gone.
+ * @param cookieManager the CookieManager on which to remove cookies.
+ * @param timeoutMs the timeout in milliseconds for waiting for the callback to complete.
+ */
+ public static void clearCookies(AwTestBase awTestBase, final AwCookieManager cookieManager)
+ throws Throwable {
+
+ final TestValueCallback<Boolean> callback = new TestValueCallback<Boolean>();
+ int callCount = callback.getOnReceiveValueHelper().getCallCount();
+
+ awTestBase.runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ cookieManager.removeAllCookies(callback);
+ }
+ });
+ callback.getOnReceiveValueHelper().waitForCallback(callCount);
+ Assert.assertFalse(cookieManager.hasCookies());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698