Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/CookieManagerTest.java

Issue 1786243003: Rename pollForCriteria to pollForTestThreadCriteria. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and update MediaRouterIntegrationTest.java Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.test.MoreAsserts; 7 import android.test.MoreAsserts;
8 import android.test.suitebuilder.annotation.MediumTest; 8 import android.test.suitebuilder.annotation.MediumTest;
9 import android.util.Pair; 9 import android.util.Pair;
10 import android.webkit.ValueCallback; 10 import android.webkit.ValueCallback;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 @Feature({"AndroidWebView", "Privacy"}) 192 @Feature({"AndroidWebView", "Privacy"})
193 public void testSetCookieNullCallback() throws Throwable { 193 public void testSetCookieNullCallback() throws Throwable {
194 mCookieManager.setAcceptCookie(true); 194 mCookieManager.setAcceptCookie(true);
195 assertTrue(mCookieManager.acceptCookie()); 195 assertTrue(mCookieManager.acceptCookie());
196 196
197 final String url = "http://www.example.com"; 197 final String url = "http://www.example.com";
198 final String cookie = "name=test"; 198 final String cookie = "name=test";
199 199
200 mCookieManager.setCookie(url, cookie, null); 200 mCookieManager.setCookie(url, cookie, null);
201 201
202 poll(new Callable<Boolean>() { 202 pollInstrumentationThread(new Callable<Boolean>() {
203 @Override 203 @Override
204 public Boolean call() throws Exception { 204 public Boolean call() throws Exception {
205 return mCookieManager.hasCookies(); 205 return mCookieManager.hasCookies();
206 } 206 }
207 }); 207 });
208 } 208 }
209 209
210 @MediumTest 210 @MediumTest
211 @Feature({"AndroidWebView", "Privacy"}) 211 @Feature({"AndroidWebView", "Privacy"})
212 public void testRemoveAllCookiesCallback() throws Throwable { 212 public void testRemoveAllCookiesCallback() throws Throwable {
(...skipping 17 matching lines...) Expand all
230 } 230 }
231 231
232 @MediumTest 232 @MediumTest
233 @Feature({"AndroidWebView", "Privacy"}) 233 @Feature({"AndroidWebView", "Privacy"})
234 public void testRemoveAllCookiesNullCallback() throws Throwable { 234 public void testRemoveAllCookiesNullCallback() throws Throwable {
235 mCookieManager.setCookie("http://www.example.com", "name=test"); 235 mCookieManager.setCookie("http://www.example.com", "name=test");
236 236
237 mCookieManager.removeAllCookies(null); 237 mCookieManager.removeAllCookies(null);
238 238
239 // Eventually the cookies are removed. 239 // Eventually the cookies are removed.
240 poll(new Callable<Boolean>() { 240 pollInstrumentationThread(new Callable<Boolean>() {
241 @Override 241 @Override
242 public Boolean call() throws Exception { 242 public Boolean call() throws Exception {
243 return !mCookieManager.hasCookies(); 243 return !mCookieManager.hasCookies();
244 } 244 }
245 }); 245 });
246 } 246 }
247 247
248 @MediumTest 248 @MediumTest
249 @Feature({"AndroidWebView", "Privacy"}) 249 @Feature({"AndroidWebView", "Privacy"})
250 public void testRemoveSessionCookiesCallback() throws Throwable { 250 public void testRemoveSessionCookiesCallback() throws Throwable {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 mCookieManager.setCookie(url, sessionCookie); 284 mCookieManager.setCookie(url, sessionCookie);
285 mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600)); 285 mCookieManager.setCookie(url, makeExpiringCookie(normalCookie, 600));
286 String allCookies = mCookieManager.getCookie(url); 286 String allCookies = mCookieManager.getCookie(url);
287 assertTrue(allCookies.contains(sessionCookie)); 287 assertTrue(allCookies.contains(sessionCookie));
288 assertTrue(allCookies.contains(normalCookie)); 288 assertTrue(allCookies.contains(normalCookie));
289 289
290 mCookieManager.removeSessionCookies(null); 290 mCookieManager.removeSessionCookies(null);
291 291
292 // Eventually the session cookie is removed. 292 // Eventually the session cookie is removed.
293 poll(new Callable<Boolean>() { 293 pollInstrumentationThread(new Callable<Boolean>() {
294 @Override 294 @Override
295 public Boolean call() throws Exception { 295 public Boolean call() throws Exception {
296 String c = mCookieManager.getCookie(url); 296 String c = mCookieManager.getCookie(url);
297 return !c.contains(sessionCookie) && c.contains(normalCookie); 297 return !c.contains(sessionCookie) && c.contains(normalCookie);
298 } 298 }
299 }); 299 });
300 } 300 }
301 301
302 @MediumTest 302 @MediumTest
303 @Feature({"AndroidWebView", "Privacy"}) 303 @Feature({"AndroidWebView", "Privacy"})
(...skipping 10 matching lines...) Expand all
314 public void testCookiesExpire() throws Exception { 314 public void testCookiesExpire() throws Exception {
315 final String url = "http://www.example.com"; 315 final String url = "http://www.example.com";
316 final String cookie = "cookie1=peter"; 316 final String cookie = "cookie1=peter";
317 317
318 mCookieManager.setCookie(url, makeExpiringCookieMs(cookie, 1200)); 318 mCookieManager.setCookie(url, makeExpiringCookieMs(cookie, 1200));
319 319
320 // The cookie exists: 320 // The cookie exists:
321 assertTrue(mCookieManager.hasCookies()); 321 assertTrue(mCookieManager.hasCookies());
322 322
323 // But eventually expires: 323 // But eventually expires:
324 poll(new Callable<Boolean>() { 324 pollInstrumentationThread(new Callable<Boolean>() {
325 @Override 325 @Override
326 public Boolean call() throws Exception { 326 public Boolean call() throws Exception {
327 return !mCookieManager.hasCookies(); 327 return !mCookieManager.hasCookies();
328 } 328 }
329 }); 329 });
330 } 330 }
331 331
332 @MediumTest 332 @MediumTest
333 @Feature({"AndroidWebView", "Privacy"}) 333 @Feature({"AndroidWebView", "Privacy"})
334 public void testCookieExpiration() throws Exception { 334 public void testCookieExpiration() throws Exception {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 } 657 }
658 658
659 /** 659 /**
660 * Clears all cookies synchronously. 660 * Clears all cookies synchronously.
661 */ 661 */
662 private void clearCookies() throws Throwable { 662 private void clearCookies() throws Throwable {
663 CookieUtils.clearCookies(this, mCookieManager); 663 CookieUtils.clearCookies(this, mCookieManager);
664 } 664 }
665 665
666 private void waitForCookie(final String url) throws Exception { 666 private void waitForCookie(final String url) throws Exception {
667 poll(new Callable<Boolean>() { 667 pollInstrumentationThread(new Callable<Boolean>() {
668 @Override 668 @Override
669 public Boolean call() throws Exception { 669 public Boolean call() throws Exception {
670 return mCookieManager.getCookie(url) != null; 670 return mCookieManager.getCookie(url) != null;
671 } 671 }
672 }); 672 });
673 } 673 }
674 674
675 private void validateCookies(String responseCookie, String... expectedCookie Names) { 675 private void validateCookies(String responseCookie, String... expectedCookie Names) {
676 String[] cookies = responseCookie.split(";"); 676 String[] cookies = responseCookie.split(";");
677 Set<String> foundCookieNames = new HashSet<String>(); 677 Set<String> foundCookieNames = new HashSet<String>();
678 for (String cookie : cookies) { 678 for (String cookie : cookies) {
679 foundCookieNames.add(cookie.substring(0, cookie.indexOf("=")).trim() ); 679 foundCookieNames.add(cookie.substring(0, cookie.indexOf("=")).trim() );
680 } 680 }
681 MoreAsserts.assertEquals( 681 MoreAsserts.assertEquals(
682 foundCookieNames, new HashSet<String>(Arrays.asList(expectedCook ieNames))); 682 foundCookieNames, new HashSet<String>(Arrays.asList(expectedCook ieNames)));
683 } 683 }
684 684
685 private String makeExpiringCookie(String cookie, int secondsTillExpiry) { 685 private String makeExpiringCookie(String cookie, int secondsTillExpiry) {
686 return makeExpiringCookieMs(cookie, secondsTillExpiry * 1000); 686 return makeExpiringCookieMs(cookie, secondsTillExpiry * 1000);
687 } 687 }
688 688
689 @SuppressWarnings("deprecation") 689 @SuppressWarnings("deprecation")
690 private String makeExpiringCookieMs(String cookie, int millisecondsTillExpir y) { 690 private String makeExpiringCookieMs(String cookie, int millisecondsTillExpir y) {
691 Date date = new Date(); 691 Date date = new Date();
692 date.setTime(date.getTime() + millisecondsTillExpiry); 692 date.setTime(date.getTime() + millisecondsTillExpiry);
693 return cookie + "; expires=" + date.toGMTString(); 693 return cookie + "; expires=" + date.toGMTString();
694 } 694 }
695 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698