1 // Copyright 2013 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.content.Context;
8 import android.test.suitebuilder.annotation.MediumTest;
10 import org.chromium.android_webview.AwBrowserProcess;
11 import org.chromium.android_webview.AwContents;
12 import org.chromium.android_webview.AwCookieManager;
13 import org.chromium.android_webview.test.util.CommonResources;
14 import org.chromium.base.test.util.Feature;
15 import org.chromium.content.app.ContentMain;
16 import org.chromium.net.test.util.TestWebServer;
19 * Test for the CookieManager in the case where it's used before Chromium is started.
21 public class CookieManagerStartupTest extends AwTestBase {
23 private AwCookieManager mCookieManager;
24 private TestAwContentsClient mContentsClient;
25 private AwContents mAwContents;
28 protected void setUp() throws Exception {
31 mCookieManager = new AwCookieManager();
32 assertNotNull(mCookieManager);
34 ContentMain.initApplicationContext(getActivity().getApplicationContext());
38 protected boolean needsBrowserProcessStarted() {
42 private void startChromium() throws Exception {
43 final Context context = getActivity();
44 getInstrumentation().runOnMainSync(new Runnable() {
47 AwBrowserProcess.start(context);
51 mContentsClient = new TestAwContentsClient();
52 final AwTestContainerView testContainerView =
53 createAwTestContainerViewOnMainSync(mContentsClient);
54 mAwContents = testContainerView.getAwContents();
55 mAwContents.getSettings().setJavaScriptEnabled(true);
59 @Feature({"AndroidWebView"})
60 public void testStartup() throws Throwable {
61 TestWebServer webServer = null;
63 webServer = new TestWebServer(false);
64 String path = "/cookie_test.html";
65 String url = webServer.setResponse(path, CommonResources.ABOUT_HTML, null);
67 mCookieManager.setAcceptCookie(true);
68 mCookieManager.removeAllCookie();
69 assertTrue(mCookieManager.acceptCookie());
70 assertFalse(mCookieManager.hasCookies());
71 mCookieManager.setCookie(url, "count=41");
74 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
75 executeJavaScriptAndWaitForResult(
78 "var c=document.cookie.split('=');document.cookie=c[0]+'='+(1+(+c[1]));");
80 assertEquals("count=42", mCookieManager.getCookie(url));
82 if (webServer != null) webServer.shutdown();