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

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: Rebase 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..0bb2ce89d249d123d82cd8fe08778b3858203b02
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/util/CookieUtils.java
@@ -0,0 +1,50 @@
+// 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 java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * Useful functions for testing the CookieManager.
+ */
+public class CookieUtils {
+ private CookieUtils() {
+ }
+
+ /**
+ * 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 Semaphore s = new Semaphore(0);
mkosiba (inactive) 2014/05/13 09:37:17 nit: could use CallbackHelper for this.
hjd_google 2014/05/15 10:52:07 Done.
+ final ValueCallback<Integer> callback = new ValueCallback<Integer>() {
+ @Override
+ public void onReceiveValue(Integer n) {
+ s.release();
+ }
+ };
+
+ awTestBase.runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ cookieManager.removeAllCookies(callback);
+ }
+ });
+
+ Assert.assertTrue(s.tryAcquire(awTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
+ Assert.assertFalse(cookieManager.hasCookies());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698