void () { URL url; try { url = new URL(TEST_URL); } catch (MalformedURLException e) { e.printStackTrace(); fail("Unexpected exception"); return; } String urlToQuery = url.getProtocol() + "://" + url.getHost(); JBCefCookie cookie = new JBCefCookie( "MY_COOKIE", "MY_VALUE", url.getHost(), "/", false, false); JBCefBrowser browser = new JBCefBrowser(TEST_URL); CountDownLatch loadStartedLatch = new CountDownLatch(1); browser.getJBCefClient().addLoadHandler(new CefLoadHandlerAdapter() { @Override public void onLoadStart(CefBrowser browser, CefFrame frame, CefRequest.TransitionType transitionType) { System.out.println("onLoadStart"); loadStartedLatch.countDown(); } }, browser.getCefBrowser()); JBCefCookieManager manager = JBCefBrowserBase.getGlobalJBCefCookieManager(); /* * SET (before load) */ System.out.println("Test setCookie()..."); Future<Boolean> result = manager.setCookie(urlToQuery, cookie); JBCefTestHelper.showAsync(browser, JBCefCookieManagerTest.class.getSimpleName()); testFuture(result, Function.identity()); assertTrue(loadStartedLatch.getCount() > 0); // assure the cookie had been set before the site loading has started System.out.println("...done"); // wait for the loading to start try { assertTrue(loadStartedLatch.await(5, TimeUnit.SECONDS)); } catch (InterruptedException e) { e.printStackTrace(); fail("Unexpected exception"); } /* * GET */ System.out.println("Test getCookie()..."); Future<List<JBCefCookie>> result2 = manager.getCookies(urlToQuery, false); assertTrue(testFuture(result2, futureResult -> futureResult.contains(cookie))); System.out.println("...done"); /* * DELETE */ System.out.println("Test deleteCookies()..."); Future<Boolean> result3 = manager.deleteCookies(urlToQuery, cookie.getName()); assertTrue(testFuture(result3, Function.identity())); System.out.println("...done"); /* * GET (to tineout) */ System.out.println("Test getCookie() to timeout..."); Future<List<JBCefCookie>> result4 = manager.getCookies(urlToQuery, false); assertTrue(testFuture(result4, null)); System.out.println("...done"); Disposer.dispose(browser); }