Chromium Code Reviews| 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()); |
| + } |
| +} |