1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test;
7 import android.test.MoreAsserts;
8 import android.test.suitebuilder.annotation.MediumTest;
9 import android.util.Pair;
10 import android.webkit.ValueCallback;
12 import static org.chromium.android_webview.test.util.CookieUtils.TestValueCallback;
14 import org.chromium.android_webview.AwContents;
15 import org.chromium.android_webview.AwCookieManager;
16 import org.chromium.android_webview.AwSettings;
17 import org.chromium.android_webview.test.util.CookieUtils;
18 import org.chromium.android_webview.test.util.JSUtils;
19 import org.chromium.base.test.util.Feature;
20 import org.chromium.net.test.util.TestWebServer;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Date;
25 import java.util.HashSet;
26 import java.util.List;
28 import java.util.concurrent.Callable;
31 * Tests for the CookieManager.
33 public class CookieManagerTest extends AwTestBase {
35 private AwCookieManager mCookieManager;
36 private TestAwContentsClient mContentsClient;
37 private AwContents mAwContents;
40 protected void setUp() throws Exception {
43 mCookieManager = new AwCookieManager();
44 mContentsClient = new TestAwContentsClient();
45 final AwTestContainerView testContainerView =
46 createAwTestContainerViewOnMainSync(mContentsClient);
47 mAwContents = testContainerView.getAwContents();
48 mAwContents.getSettings().setJavaScriptEnabled(true);
49 assertNotNull(mCookieManager);
51 mCookieManager.setAcceptCookie(true);
52 assertTrue(mCookieManager.acceptCookie());
56 protected void tearDown() throws Exception {
59 } catch (Throwable e) {
60 throw new RuntimeException("Could not clear cookies.");
66 @Feature({"AndroidWebView", "Privacy"})
67 public void testAcceptCookie() throws Throwable {
68 TestWebServer webServer = TestWebServer.start();
70 String path = "/cookie_test.html";
72 "<html><head><title>TEST!</title></head><body>HELLO!</body></html>";
73 String url = webServer.setResponse(path, responseStr, null);
75 mCookieManager.setAcceptCookie(false);
76 assertFalse(mCookieManager.acceptCookie());
78 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
79 setCookieWithJavaScript("test1", "value1");
80 assertNull(mCookieManager.getCookie(url));
82 List<Pair<String, String>> responseHeaders = new ArrayList<Pair<String, String>>();
84 Pair.create("Set-Cookie", "header-test1=header-value1; path=" + path));
85 url = webServer.setResponse(path, responseStr, responseHeaders);
86 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
87 assertNull(mCookieManager.getCookie(url));
89 mCookieManager.setAcceptCookie(true);
90 assertTrue(mCookieManager.acceptCookie());
92 url = webServer.setResponse(path, responseStr, null);
93 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
94 setCookieWithJavaScript("test2", "value2");
96 String cookie = mCookieManager.getCookie(url);
97 assertNotNull(cookie);
98 validateCookies(cookie, "test2");
100 responseHeaders = new ArrayList<Pair<String, String>>();
102 Pair.create("Set-Cookie", "header-test2=header-value2 path=" + path));
103 url = webServer.setResponse(path, responseStr, responseHeaders);
104 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
106 cookie = mCookieManager.getCookie(url);
107 assertNotNull(cookie);
108 validateCookies(cookie, "test2", "header-test2");
110 webServer.shutdown();
114 private void setCookieWithJavaScript(final String name, final String value)
116 JSUtils.executeJavaScriptAndWaitForResult(
118 mContentsClient.getOnEvaluateJavaScriptResultHelper(),
119 "var expirationDate = new Date();"
120 + "expirationDate.setDate(expirationDate.getDate() + 5);"
121 + "document.cookie='" + name + "=" + value
122 + "; expires=' + expirationDate.toUTCString();");
126 @Feature({"AndroidWebView", "Privacy"})
127 public void testRemoveAllCookies() throws Exception {
128 mCookieManager.setCookie("http://www.example.com", "name=test");
129 assertTrue(mCookieManager.hasCookies());
130 mCookieManager.removeAllCookies();
131 assertFalse(mCookieManager.hasCookies());
135 @Feature({"AndroidWebView", "Privacy"})
136 public void testRemoveSessionCookies() throws Exception {
137 final String url = "http://www.example.com";
138 final String sessionCookie = "cookie1=peter";
139 final String normalCookie = "cookie2=sue";
141 mCookieManager.setCookie(url, sessionCookie);
142 mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600));
144 mCookieManager.removeSessionCookies();
146 String allCookies = mCookieManager.getCookie(url);
147 assertFalse(allCookies.contains(sessionCookie));
148 assertTrue(allCookies.contains(normalCookie));
152 @Feature({"AndroidWebView", "Privacy"})
153 public void testSetCookie() throws Throwable {
154 String url = "http://www.example.com";
155 String cookie = "name=test";
156 mCookieManager.setCookie(url, cookie);
157 assertEquals(cookie, mCookieManager.getCookie(url));
161 @Feature({"AndroidWebView", "Privacy"})
162 public void testHasCookie() throws Throwable {
163 assertFalse(mCookieManager.hasCookies());
164 mCookieManager.setCookie("http://www.example.com", "name=test");
165 assertTrue(mCookieManager.hasCookies());
169 @Feature({"AndroidWebView", "Privacy"})
170 public void testSetCookieCallback() throws Throwable {
171 final String url = "http://www.example.com";
172 final String cookie = "name=test";
173 final String brokenUrl = "foo";
175 final TestValueCallback<Boolean> callback = new TestValueCallback<Boolean>();
176 int callCount = callback.getOnReceiveValueHelper().getCallCount();
178 setCookieOnUiThread(url, cookie, callback);
179 callback.getOnReceiveValueHelper().waitForCallback(callCount);
180 assertTrue(callback.getValue());
181 assertEquals(cookie, mCookieManager.getCookie(url));
183 callCount = callback.getOnReceiveValueHelper().getCallCount();
185 setCookieOnUiThread(brokenUrl, cookie, callback);
186 callback.getOnReceiveValueHelper().waitForCallback(callCount);
187 assertFalse(callback.getValue());
188 assertEquals(null, mCookieManager.getCookie(brokenUrl));
192 @Feature({"AndroidWebView", "Privacy"})
193 public void testSetCookieNullCallback() throws Throwable {
194 mCookieManager.setAcceptCookie(true);
195 assertTrue(mCookieManager.acceptCookie());
197 final String url = "http://www.example.com";
198 final String cookie = "name=test";
200 mCookieManager.setCookie(url, cookie, null);
202 poll(new Callable<Boolean>() {
204 public Boolean call() throws Exception {
205 return mCookieManager.hasCookies();
211 @Feature({"AndroidWebView", "Privacy"})
212 public void testRemoveAllCookiesCallback() throws Throwable {
213 TestValueCallback<Boolean> callback = new TestValueCallback<Boolean>();
214 int callCount = callback.getOnReceiveValueHelper().getCallCount();
216 mCookieManager.setCookie("http://www.example.com", "name=test");
218 // When we remove all cookies the first time some cookies are removed.
219 removeAllCookiesOnUiThread(callback);
220 callback.getOnReceiveValueHelper().waitForCallback(callCount);
221 assertTrue(callback.getValue());
222 assertFalse(mCookieManager.hasCookies());
224 callCount = callback.getOnReceiveValueHelper().getCallCount();
226 // The second time none are removed.
227 removeAllCookiesOnUiThread(callback);
228 callback.getOnReceiveValueHelper().waitForCallback(callCount);
229 assertFalse(callback.getValue());
233 @Feature({"AndroidWebView", "Privacy"})
234 public void testRemoveAllCookiesNullCallback() throws Throwable {
235 mCookieManager.setCookie("http://www.example.com", "name=test");
237 mCookieManager.removeAllCookies(null);
239 // Eventually the cookies are removed.
240 poll(new Callable<Boolean>() {
242 public Boolean call() throws Exception {
243 return !mCookieManager.hasCookies();
249 @Feature({"AndroidWebView", "Privacy"})
250 public void testRemoveSessionCookiesCallback() throws Throwable {
251 final String url = "http://www.example.com";
252 final String sessionCookie = "cookie1=peter";
253 final String normalCookie = "cookie2=sue";
255 TestValueCallback<Boolean> callback = new TestValueCallback<Boolean>();
256 int callCount = callback.getOnReceiveValueHelper().getCallCount();
258 mCookieManager.setCookie(url, sessionCookie);
259 mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600));
261 // When there is a session cookie then it is removed.
262 removeSessionCookiesOnUiThread(callback);
263 callback.getOnReceiveValueHelper().waitForCallback(callCount);
264 assertTrue(callback.getValue());
265 String allCookies = mCookieManager.getCookie(url);
266 assertTrue(!allCookies.contains(sessionCookie));
267 assertTrue(allCookies.contains(normalCookie));
269 callCount = callback.getOnReceiveValueHelper().getCallCount();
271 // If there are no session cookies then none are removed.
272 removeSessionCookiesOnUiThread(callback);
273 callback.getOnReceiveValueHelper().waitForCallback(callCount);
274 assertFalse(callback.getValue());
278 @Feature({"AndroidWebView", "Privacy"})
279 public void testRemoveSessionCookiesNullCallback() throws Throwable {
280 final String url = "http://www.example.com";
281 final String sessionCookie = "cookie1=peter";
282 final String normalCookie = "cookie2=sue";
284 mCookieManager.setCookie(url, sessionCookie);
285 mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600));
286 String allCookies = mCookieManager.getCookie(url);
287 assertTrue(allCookies.contains(sessionCookie));
288 assertTrue(allCookies.contains(normalCookie));
290 mCookieManager.removeSessionCookies(null);
292 // Eventually the session cookie is removed.
293 poll(new Callable<Boolean>() {
295 public Boolean call() throws Exception {
296 String c = mCookieManager.getCookie(url);
297 return !c.contains(sessionCookie) && c.contains(normalCookie);
303 @Feature({"AndroidWebView", "Privacy"})
304 public void testExpiredCookiesAreNotSet() throws Exception {
305 final String url = "http://www.example.com";
306 final String cookie = "cookie1=peter";
308 mCookieManager.setCookie(url, makeExpiringCookie(cookie, -1));
309 assertNull(mCookieManager.getCookie(url));
313 @Feature({"AndroidWebView", "Privacy"})
314 public void testCookiesExpire() throws Exception {
315 final String url = "http://www.example.com";
316 final String cookie = "cookie1=peter";
318 mCookieManager.setCookie(url, makeExpiringCookieMs(cookie, 1200));
320 // The cookie exists:
321 assertTrue(mCookieManager.hasCookies());
323 // But eventually expires:
324 poll(new Callable<Boolean>() {
326 public Boolean call() throws Exception {
327 return !mCookieManager.hasCookies();
333 @Feature({"AndroidWebView", "Privacy"})
334 public void testCookieExpiration() throws Exception {
335 final String url = "http://www.example.com";
336 final String sessionCookie = "cookie1=peter";
337 final String longCookie = "cookie2=marc";
339 mCookieManager.setCookie(url, sessionCookie);
340 mCookieManager.setCookie(url, makeExpiringCookie(longCookie, 600));
342 String allCookies = mCookieManager.getCookie(url);
343 assertTrue(allCookies.contains(sessionCookie));
344 assertTrue(allCookies.contains(longCookie));
346 // Removing expired cookies doesn't have an observable effect but since people will still
347 // be calling it for a while it shouldn't break anything either.
348 mCookieManager.removeExpiredCookies();
350 allCookies = mCookieManager.getCookie(url);
351 assertTrue(allCookies.contains(sessionCookie));
352 assertTrue(allCookies.contains(longCookie));
356 @Feature({"AndroidWebView", "Privacy"})
357 public void testThirdPartyCookie() throws Throwable {
358 // In theory we need two servers to test this, one server ('the first party') which returns
359 // a response with a link to a second server ('the third party') at different origin. This
360 // second server attempts to set a cookie which should fail if AcceptThirdPartyCookie() is
362 // Strictly according to the letter of RFC6454 it should be possible to set this situation
363 // up with two TestServers on different ports (these count as having different origins) but
364 // Chrome is not strict about this and does not check the port. Instead we cheat making some
365 // of the urls come from localhost and some from 127.0.0.1 which count (both in theory and
366 // pratice) as having different origins.
367 TestWebServer webServer = TestWebServer.start();
369 // Turn global allow on.
370 mCookieManager.setAcceptCookie(true);
371 assertTrue(mCookieManager.acceptCookie());
373 // When third party cookies are disabled...
374 mAwContents.getSettings().setAcceptThirdPartyCookies(false);
375 assertFalse(mAwContents.getSettings().getAcceptThirdPartyCookies());
377 // ...we can't set third party cookies.
378 // First on the third party server we create a url which tries to set a cookie.
379 String cookieUrl = toThirdPartyUrl(
380 makeCookieUrl(webServer, "/cookie_1.js", "test1", "value1"));
381 // Then we create a url on the first party server which links to the first url.
382 String url = makeScriptLinkUrl(webServer, "/content_1.html", cookieUrl);
383 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
384 assertNull(mCookieManager.getCookie(cookieUrl));
386 // When third party cookies are enabled...
387 mAwContents.getSettings().setAcceptThirdPartyCookies(true);
388 assertTrue(mAwContents.getSettings().getAcceptThirdPartyCookies());
390 // ...we can set third party cookies.
391 cookieUrl = toThirdPartyUrl(
392 makeCookieUrl(webServer, "/cookie_2.js", "test2", "value2"));
393 url = makeScriptLinkUrl(webServer, "/content_2.html", cookieUrl);
394 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
395 waitForCookie(cookieUrl);
396 String cookie = mCookieManager.getCookie(cookieUrl);
397 assertNotNull(cookie);
398 validateCookies(cookie, "test2");
400 webServer.shutdown();
405 * Creates a response on the TestWebServer which attempts to set a cookie when fetched.
406 * @param webServer the webServer on which to create the response
407 * @param path the path component of the url (e.g "/cookie_test.html")
408 * @param key the key of the cookie
409 * @param value the value of the cookie
410 * @return the url which gets the response
412 private String makeCookieUrl(TestWebServer webServer, String path, String key, String value) {
413 String response = "";
414 List<Pair<String, String>> responseHeaders = new ArrayList<Pair<String, String>>();
416 Pair.create("Set-Cookie", key + "=" + value + "; path=" + path));
417 return webServer.setResponse(path, response, responseHeaders);
421 * Creates a response on the TestWebServer which contains a script tag with an external src.
422 * @param webServer the webServer on which to create the response
423 * @param path the path component of the url (e.g "/my_thing_with_script.html")
424 * @param url the url which which should appear as the src of the script tag.
425 * @return the url which gets the response
427 private String makeScriptLinkUrl(TestWebServer webServer, String path, String url) {
428 String responseStr = "<html><head><title>Content!</title></head>"
429 + "<body><script src=" + url + "></script></body></html>";
430 return webServer.setResponse(path, responseStr, null);
434 @Feature({"AndroidWebView", "Privacy"})
435 public void testThirdPartyJavascriptCookie() throws Throwable {
436 TestWebServer webServer = TestWebServer.start();
438 // This test again uses 127.0.0.1/localhost trick to simulate a third party.
439 ThirdPartyCookiesTestHelper thirdParty =
440 new ThirdPartyCookiesTestHelper(webServer);
442 mCookieManager.setAcceptCookie(true);
443 assertTrue(mCookieManager.acceptCookie());
445 // When third party cookies are disabled...
446 thirdParty.getSettings().setAcceptThirdPartyCookies(false);
447 assertFalse(thirdParty.getSettings().getAcceptThirdPartyCookies());
449 // ...we can't set third party cookies.
450 thirdParty.assertThirdPartyIFrameCookieResult("1", false);
452 // When third party cookies are enabled...
453 thirdParty.getSettings().setAcceptThirdPartyCookies(true);
454 assertTrue(thirdParty.getSettings().getAcceptThirdPartyCookies());
456 // ...we can set third party cookies.
457 thirdParty.assertThirdPartyIFrameCookieResult("2", true);
459 webServer.shutdown();
464 @Feature({"AndroidWebView", "Privacy"})
465 public void testThirdPartyCookiesArePerWebview() throws Throwable {
466 TestWebServer webServer = TestWebServer.start();
468 mCookieManager.setAcceptCookie(true);
469 mCookieManager.removeAllCookie();
470 assertTrue(mCookieManager.acceptCookie());
471 assertFalse(mCookieManager.hasCookies());
473 ThirdPartyCookiesTestHelper helperOne = new ThirdPartyCookiesTestHelper(webServer);
474 ThirdPartyCookiesTestHelper helperTwo = new ThirdPartyCookiesTestHelper(webServer);
476 helperOne.getSettings().setAcceptThirdPartyCookies(false);
477 helperTwo.getSettings().setAcceptThirdPartyCookies(false);
478 assertFalse(helperOne.getSettings().getAcceptThirdPartyCookies());
479 assertFalse(helperTwo.getSettings().getAcceptThirdPartyCookies());
480 helperOne.assertThirdPartyIFrameCookieResult("1", false);
481 helperTwo.assertThirdPartyIFrameCookieResult("2", false);
483 helperTwo.getSettings().setAcceptThirdPartyCookies(true);
484 assertFalse(helperOne.getSettings().getAcceptThirdPartyCookies());
485 assertTrue(helperTwo.getSettings().getAcceptThirdPartyCookies());
486 helperOne.assertThirdPartyIFrameCookieResult("3", false);
487 helperTwo.assertThirdPartyIFrameCookieResult("4", true);
489 helperOne.getSettings().setAcceptThirdPartyCookies(true);
490 assertTrue(helperOne.getSettings().getAcceptThirdPartyCookies());
491 assertTrue(helperTwo.getSettings().getAcceptThirdPartyCookies());
492 helperOne.assertThirdPartyIFrameCookieResult("5", true);
493 helperTwo.assertThirdPartyIFrameCookieResult("6", true);
495 helperTwo.getSettings().setAcceptThirdPartyCookies(false);
496 assertTrue(helperOne.getSettings().getAcceptThirdPartyCookies());
497 assertFalse(helperTwo.getSettings().getAcceptThirdPartyCookies());
498 helperOne.assertThirdPartyIFrameCookieResult("7", true);
499 helperTwo.assertThirdPartyIFrameCookieResult("8", false);
501 webServer.shutdown();
506 @Feature({"AndroidWebView", "Privacy"})
507 public void testAcceptFileSchemeCookies() throws Throwable {
508 mCookieManager.setAcceptFileSchemeCookies(true);
509 mAwContents.getSettings().setAllowFileAccess(true);
511 mAwContents.getSettings().setAcceptThirdPartyCookies(true);
512 assertTrue(fileURLCanSetCookie("1"));
513 mAwContents.getSettings().setAcceptThirdPartyCookies(false);
514 assertTrue(fileURLCanSetCookie("2"));
518 @Feature({"AndroidWebView", "Privacy"})
519 public void testRejectFileSchemeCookies() throws Throwable {
520 mCookieManager.setAcceptFileSchemeCookies(false);
521 mAwContents.getSettings().setAllowFileAccess(true);
523 mAwContents.getSettings().setAcceptThirdPartyCookies(true);
524 assertFalse(fileURLCanSetCookie("3"));
525 mAwContents.getSettings().setAcceptThirdPartyCookies(false);
526 assertFalse(fileURLCanSetCookie("4"));
529 private boolean fileURLCanSetCookie(String suffix) throws Throwable {
530 String value = "value" + suffix;
531 String url = "file:///android_asset/cookie_test.html?value=" + value;
532 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
533 String cookie = mCookieManager.getCookie(url);
534 return cookie != null && cookie.contains("test=" + value);
537 class ThirdPartyCookiesTestHelper {
538 protected final AwContents mAwContents;
539 protected final TestAwContentsClient mContentsClient;
540 protected final TestWebServer mWebServer;
542 ThirdPartyCookiesTestHelper(TestWebServer webServer) throws Throwable {
543 mWebServer = webServer;
544 mContentsClient = new TestAwContentsClient();
545 final AwTestContainerView containerView =
546 createAwTestContainerViewOnMainSync(mContentsClient);
547 mAwContents = containerView.getAwContents();
548 mAwContents.getSettings().setJavaScriptEnabled(true);
551 AwContents getAwContents() {
555 AwSettings getSettings() {
556 return mAwContents.getSettings();
559 TestWebServer getWebServer() {
563 void assertThirdPartyIFrameCookieResult(String suffix, boolean expectedResult)
565 String key = "test" + suffix;
566 String value = "value" + suffix;
567 String iframePath = "/iframe_" + suffix + ".html";
568 String pagePath = "/content_" + suffix + ".html";
570 // We create a script which tries to set a cookie on a third party.
571 String cookieUrl = toThirdPartyUrl(
572 makeCookieScriptUrl(getWebServer(), iframePath, key, value));
574 // Then we load it as an iframe.
575 String url = makeIframeUrl(getWebServer(), pagePath, cookieUrl);
576 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
578 if (expectedResult) {
579 String cookie = mCookieManager.getCookie(cookieUrl);
580 assertNotNull(cookie);
581 validateCookies(cookie, key);
583 assertNull(mCookieManager.getCookie(cookieUrl));
586 // Clear the cookies.
588 assertFalse(mCookieManager.hasCookies());
593 * Creates a response on the TestWebServer which attempts to set a cookie when fetched.
594 * @param webServer the webServer on which to create the response
595 * @param path the path component of the url (e.g "/my_thing_with_iframe.html")
596 * @param url the url which which should appear as the src of the iframe.
597 * @return the url which gets the response
599 private String makeIframeUrl(TestWebServer webServer, String path, String url) {
600 String responseStr = "<html><head><title>Content!</title></head>"
601 + "<body><iframe src=" + url + "></iframe></body></html>";
602 return webServer.setResponse(path, responseStr, null);
606 * Creates a response on the TestWebServer with a script that attempts to set a cookie.
607 * @param webServer the webServer on which to create the response
608 * @param path the path component of the url (e.g "/cookie_test.html")
609 * @param key the key of the cookie
610 * @param value the value of the cookie
611 * @return the url which gets the response
613 private String makeCookieScriptUrl(TestWebServer webServer, String path, String key,
615 String response = "<html><head></head><body>"
616 + "<script>document.cookie = \"" + key + "=" + value + "\";</script></body></html>";
617 return webServer.setResponse(path, response, null);
621 * Makes a url look as if it comes from a different host.
622 * @param url the url to fake.
623 * @return the resulting url after faking.
625 private String toThirdPartyUrl(String url) {
626 return url.replace("localhost", "127.0.0.1");
629 private void setCookieOnUiThread(final String url, final String cookie,
630 final ValueCallback<Boolean> callback) throws Throwable {
631 runTestOnUiThread(new Runnable() {
634 mCookieManager.setCookie(url, cookie, callback);
639 private void removeSessionCookiesOnUiThread(final ValueCallback<Boolean> callback)
641 runTestOnUiThread(new Runnable() {
644 mCookieManager.removeSessionCookies(callback);
649 private void removeAllCookiesOnUiThread(final ValueCallback<Boolean> callback)
651 runTestOnUiThread(new Runnable() {
654 mCookieManager.removeAllCookies(callback);
660 * Clears all cookies synchronously.
662 private void clearCookies() throws Throwable {
663 CookieUtils.clearCookies(this, mCookieManager);
666 private void waitForCookie(final String url) throws Exception {
667 poll(new Callable<Boolean>() {
669 public Boolean call() throws Exception {
670 return mCookieManager.getCookie(url) != null;
675 private void validateCookies(String responseCookie, String... expectedCookieNames) {
676 String[] cookies = responseCookie.split(";");
677 Set<String> foundCookieNames = new HashSet<String>();
678 for (String cookie : cookies) {
679 foundCookieNames.add(cookie.substring(0, cookie.indexOf("=")).trim());
681 MoreAsserts.assertEquals(
682 foundCookieNames, new HashSet<String>(Arrays.asList(expectedCookieNames)));
685 private String makeExpiringCookie(String cookie, int secondsTillExpiry) {
686 return makeExpiringCookieMs(cookie, secondsTillExpiry * 1000);
689 @SuppressWarnings("deprecation")
690 private String makeExpiringCookieMs(String cookie, int millisecondsTillExpiry) {
691 Date date = new Date();
692 date.setTime(date.getTime() + millisecondsTillExpiry);
693 return cookie + "; expires=" + date.toGMTString();