Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 6 | 6 |
| 7 import android.support.test.filters.MediumTest; | 7 import android.support.test.filters.MediumTest; |
| 8 import android.test.MoreAsserts; | 8 import android.test.MoreAsserts; |
| 9 import android.util.Pair; | 9 import android.util.Pair; |
| 10 import android.webkit.ValueCallback; | 10 import android.webkit.ValueCallback; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 cookie = mCookieManager.getCookie(url); | 107 cookie = mCookieManager.getCookie(url); |
| 108 assertNotNull(cookie); | 108 assertNotNull(cookie); |
| 109 validateCookies(cookie, "test2", "header-test2"); | 109 validateCookies(cookie, "test2", "header-test2"); |
| 110 } finally { | 110 } finally { |
| 111 webServer.shutdown(); | 111 webServer.shutdown(); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 private void setCookieWithJavaScript(final String name, final String value) | 115 private void setCookieWithJavaScript(final String name, final String value) |
| 116 throws Throwable { | 116 throws Throwable { |
| 117 JSUtils.executeJavaScriptAndWaitForResult( | 117 JSUtils.executeJavaScriptAndWaitForResult(getInstrumentation(), mAwConte nts, |
| 118 this, mAwContents, | |
| 119 mContentsClient.getOnEvaluateJavaScriptResultHelper(), | 118 mContentsClient.getOnEvaluateJavaScriptResultHelper(), |
| 120 "var expirationDate = new Date();" | 119 "var expirationDate = new Date();" |
| 121 + "expirationDate.setDate(expirationDate.getDate() + 5);" | 120 + "expirationDate.setDate(expirationDate.getDate() + 5); " |
| 122 + "document.cookie='" + name + "=" + value | 121 + "document.cookie='" + name + "=" + value |
| 123 + "; expires=' + expirationDate.toUTCString();"); | 122 + "; expires=' + expirationDate.toUTCString();"); |
| 124 } | 123 } |
| 125 | 124 |
| 126 @MediumTest | 125 @MediumTest |
| 127 @Feature({"AndroidWebView", "Privacy"}) | 126 @Feature({"AndroidWebView", "Privacy"}) |
| 128 public void testRemoveAllCookies() throws Exception { | 127 public void testRemoveAllCookies() throws Exception { |
| 129 mCookieManager.setCookie("http://www.example.com", "name=test"); | 128 mCookieManager.setCookie("http://www.example.com", "name=test"); |
| 130 assertTrue(mCookieManager.hasCookies()); | 129 assertTrue(mCookieManager.hasCookies()); |
| 131 mCookieManager.removeAllCookies(); | 130 mCookieManager.removeAllCookies(); |
| 132 assertFalse(mCookieManager.hasCookies()); | 131 assertFalse(mCookieManager.hasCookies()); |
| 133 } | 132 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 mCookieManager.removeExpiredCookies(); | 358 mCookieManager.removeExpiredCookies(); |
| 360 | 359 |
| 361 allCookies = mCookieManager.getCookie(url); | 360 allCookies = mCookieManager.getCookie(url); |
| 362 assertTrue(allCookies.contains(sessionCookie)); | 361 assertTrue(allCookies.contains(sessionCookie)); |
| 363 assertTrue(allCookies.contains(longCookie)); | 362 assertTrue(allCookies.contains(longCookie)); |
| 364 } | 363 } |
| 365 | 364 |
| 366 @MediumTest | 365 @MediumTest |
| 367 @Feature({"AndroidWebView", "Privacy"}) | 366 @Feature({"AndroidWebView", "Privacy"}) |
| 368 public void testThirdPartyCookie() throws Throwable { | 367 public void testThirdPartyCookie() throws Throwable { |
| 369 // In theory we need two servers to test this, one server ('the first pa rty') which returns | 368 // In theory we need two servers to test getInstrumentation(), one serve r ('the first |
|
boliu
2017/07/20 21:22:47
wrong thing to sed over :p
the real yoland
2017/07/27 00:29:47
lol, yup
| |
| 370 // a response with a link to a second server ('the third party') at diff erent origin. This | 369 // party') which returns a response with a link to a second server ('the third party') at |
| 371 // second server attempts to set a cookie which should fail if AcceptThi rdPartyCookie() is | 370 // different origin. This second server attempts to set a cookie which s hould fail if |
| 372 // false. | 371 // AcceptThirdPartyCookie() is false. Strictly according to the letter o f RFC6454 it should |
| 373 // Strictly according to the letter of RFC6454 it should be possible to set this situation | 372 // be possible to set this situation up with two TestServers on differen t ports (these count |
| 374 // up with two TestServers on different ports (these count as having dif ferent origins) but | 373 // as having different origins) but Chrome is not strict about this and does not check the |
| 375 // Chrome is not strict about this and does not check the port. Instead we cheat making some | 374 // port. Instead we cheat making some of the urls come from localhost an d some from |
| 376 // of the urls come from localhost and some from 127.0.0.1 which count ( both in theory and | 375 // 127.0.0.1 which count (both in theory and pratice) as having differen t origins. |
| 377 // pratice) as having different origins. | |
| 378 TestWebServer webServer = TestWebServer.start(); | 376 TestWebServer webServer = TestWebServer.start(); |
| 379 try { | 377 try { |
| 380 // Turn global allow on. | 378 // Turn global allow on. |
| 381 mCookieManager.setAcceptCookie(true); | 379 mCookieManager.setAcceptCookie(true); |
| 382 assertTrue(mCookieManager.acceptCookie()); | 380 assertTrue(mCookieManager.acceptCookie()); |
| 383 | 381 |
| 384 // When third party cookies are disabled... | 382 // When third party cookies are disabled... |
| 385 mAwContents.getSettings().setAcceptThirdPartyCookies(false); | 383 mAwContents.getSettings().setAcceptThirdPartyCookies(false); |
| 386 assertFalse(mAwContents.getSettings().getAcceptThirdPartyCookies()); | 384 assertFalse(mAwContents.getSettings().getAcceptThirdPartyCookies()); |
| 387 | 385 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 return makeExpiringCookieMs(cookie, secondsTillExpiry * 1000); | 774 return makeExpiringCookieMs(cookie, secondsTillExpiry * 1000); |
| 777 } | 775 } |
| 778 | 776 |
| 779 @SuppressWarnings("deprecation") | 777 @SuppressWarnings("deprecation") |
| 780 private String makeExpiringCookieMs(String cookie, int millisecondsTillExpir y) { | 778 private String makeExpiringCookieMs(String cookie, int millisecondsTillExpir y) { |
| 781 Date date = new Date(); | 779 Date date = new Date(); |
| 782 date.setTime(date.getTime() + millisecondsTillExpiry); | 780 date.setTime(date.getTime() + millisecondsTillExpiry); |
| 783 return cookie + "; expires=" + date.toGMTString(); | 781 return cookie + "; expires=" + date.toGMTString(); |
| 784 } | 782 } |
| 785 } | 783 } |
| OLD | NEW |