@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 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 testThirdPartyCookiesArePerWebview() throws Throwable {
    TestWebServer webServer = null;
    try {
      webServer = new TestWebServer(false);
      mCookieManager.setAcceptCookie(true);
      mCookieManager.removeAllCookie();
      assertTrue(mCookieManager.acceptCookie());
      assertFalse(mCookieManager.hasCookies());

      ThirdPartyCookiesTestHelper helperOne = new ThirdPartyCookiesTestHelper(webServer);
      ThirdPartyCookiesTestHelper helperTwo = new ThirdPartyCookiesTestHelper(webServer);

      helperOne.getSettings().setAcceptThirdPartyCookies(false);
      helperTwo.getSettings().setAcceptThirdPartyCookies(false);
      assertFalse(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertFalse(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("1", false);
      helperTwo.assertThirdPartyIFrameCookieResult("2", false);

      helperTwo.getSettings().setAcceptThirdPartyCookies(true);
      assertFalse(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertTrue(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("3", false);
      helperTwo.assertThirdPartyIFrameCookieResult("4", true);

      helperOne.getSettings().setAcceptThirdPartyCookies(true);
      assertTrue(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertTrue(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("5", true);
      helperTwo.assertThirdPartyIFrameCookieResult("6", true);

      helperTwo.getSettings().setAcceptThirdPartyCookies(false);
      assertTrue(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertFalse(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("7", true);
      helperTwo.assertThirdPartyIFrameCookieResult("8", false);
    } finally {
      if (webServer != null) webServer.shutdown();
    }
  }
  @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());
  }