@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testRemoveSessionCookiesCallback() throws Throwable { final String url = "http://www.example.com"; final String sessionCookie = "cookie1=peter"; final String normalCookie = "cookie2=sue"; TestValueCallback<Boolean> callback = new TestValueCallback<Boolean>(); int callCount = callback.getOnReceiveValueHelper().getCallCount(); mCookieManager.setCookie(url, sessionCookie); mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600)); // When there is a session cookie then it is removed. removeSessionCookiesOnUiThread(callback); callback.getOnReceiveValueHelper().waitForCallback(callCount); assertTrue(callback.getValue()); String allCookies = mCookieManager.getCookie(url); assertTrue(!allCookies.contains(sessionCookie)); assertTrue(allCookies.contains(normalCookie)); callCount = callback.getOnReceiveValueHelper().getCallCount(); // If there are no session cookies then none are removed. removeSessionCookiesOnUiThread(callback); callback.getOnReceiveValueHelper().waitForCallback(callCount); assertFalse(callback.getValue()); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testRemoveSessionCookiesNullCallback() throws Throwable { final String url = "http://www.example.com"; final String sessionCookie = "cookie1=peter"; final String normalCookie = "cookie2=sue"; mCookieManager.setCookie(url, sessionCookie); mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600)); String allCookies = mCookieManager.getCookie(url); assertTrue(allCookies.contains(sessionCookie)); assertTrue(allCookies.contains(normalCookie)); mCookieManager.removeSessionCookies(null); // Eventually the session cookie is removed. poll( new Callable<Boolean>() { @Override public Boolean call() throws Exception { String c = mCookieManager.getCookie(url); return !c.contains(sessionCookie) && c.contains(normalCookie); } }); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testHasCookie() throws Throwable { assertFalse(mCookieManager.hasCookies()); mCookieManager.setCookie("http://www.example.com", "name=test"); assertTrue(mCookieManager.hasCookies()); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testRemoveSessionCookies() throws Exception { final String url = "http://www.example.com"; final String sessionCookie = "cookie1=peter"; final String normalCookie = "cookie2=sue"; mCookieManager.setCookie(url, sessionCookie); mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600)); mCookieManager.removeSessionCookies(); String allCookies = mCookieManager.getCookie(url); assertFalse(allCookies.contains(sessionCookie)); assertTrue(allCookies.contains(normalCookie)); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testSetCookie() throws Throwable { String url = "http://www.example.com"; String cookie = "name=test"; mCookieManager.setCookie(url, cookie); assertEquals(cookie, mCookieManager.getCookie(url)); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testRemoveAllCookies() throws Exception { mCookieManager.setCookie("http://www.example.com", "name=test"); assertTrue(mCookieManager.hasCookies()); mCookieManager.removeAllCookies(); assertFalse(mCookieManager.hasCookies()); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testExpiredCookiesAreNotSet() throws Exception { final String url = "http://www.example.com"; final String cookie = "cookie1=peter"; mCookieManager.setCookie(url, makeExpiringCookie(cookie, -1)); assertNull(mCookieManager.getCookie(url)); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testCookieExpiration() throws Exception { final String url = "http://www.example.com"; final String sessionCookie = "cookie1=peter"; final String longCookie = "cookie2=marc"; mCookieManager.setCookie(url, sessionCookie); mCookieManager.setCookie(url, makeExpiringCookie(longCookie, 600)); String allCookies = mCookieManager.getCookie(url); assertTrue(allCookies.contains(sessionCookie)); assertTrue(allCookies.contains(longCookie)); // Removing expired cookies doesn't have an observable effect but since people will still // be calling it for a while it shouldn't break anything either. mCookieManager.removeExpiredCookies(); allCookies = mCookieManager.getCookie(url); assertTrue(allCookies.contains(sessionCookie)); assertTrue(allCookies.contains(longCookie)); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testRemoveAllCookiesNullCallback() throws Throwable { mCookieManager.setCookie("http://www.example.com", "name=test"); mCookieManager.removeAllCookies(null); // Eventually the cookies are removed. poll( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return !mCookieManager.hasCookies(); } }); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testSetCookieNullCallback() throws Throwable { mCookieManager.setAcceptCookie(true); assertTrue(mCookieManager.acceptCookie()); final String url = "http://www.example.com"; final String cookie = "name=test"; mCookieManager.setCookie(url, cookie, null); poll( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return mCookieManager.hasCookies(); } }); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testCookiesExpire() throws Exception { final String url = "http://www.example.com"; final String cookie = "cookie1=peter"; mCookieManager.setCookie(url, makeExpiringCookieMs(cookie, 1200)); // The cookie exists: assertTrue(mCookieManager.hasCookies()); // But eventually expires: poll( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return !mCookieManager.hasCookies(); } }); }
@MediumTest @Feature({"AndroidWebView", "Privacy"}) public void testRemoveAllCookiesCallback() throws Throwable { TestValueCallback<Boolean> callback = new TestValueCallback<Boolean>(); int callCount = callback.getOnReceiveValueHelper().getCallCount(); mCookieManager.setCookie("http://www.example.com", "name=test"); // When we remove all cookies the first time some cookies are removed. removeAllCookiesOnUiThread(callback); callback.getOnReceiveValueHelper().waitForCallback(callCount); assertTrue(callback.getValue()); assertFalse(mCookieManager.hasCookies()); callCount = callback.getOnReceiveValueHelper().getCallCount(); // The second time none are removed. removeAllCookiesOnUiThread(callback); callback.getOnReceiveValueHelper().waitForCallback(callCount); assertFalse(callback.getValue()); }