Search in sources :

Example 31 with CookieManager

use of android.webkit.CookieManager in project robolectric by robolectric.

the class ShadowCookieManagerTest method shouldGetCookieForHostInDomain.

@Test
public void shouldGetCookieForHostInDomain() {
    CookieManager cookieManager = CookieManager.getInstance();
    String value1 = "my cookie";
    cookieManager.setCookie("foo.com/this%20is%20a%20test", value1);
    assertThat(cookieManager.getCookie(".foo.com")).isEqualTo(value1);
}
Also used : CookieManager(android.webkit.CookieManager) Test(org.junit.Test)

Example 32 with CookieManager

use of android.webkit.CookieManager in project robolectric by robolectric.

the class ShadowCookieManagerTest method shouldGetCookieForHostInDomainDefinedWithProtocol.

@Test
public void shouldGetCookieForHostInDomainDefinedWithProtocol() {
    CookieManager cookieManager = CookieManager.getInstance();
    String value1 = "my cookie";
    cookieManager.setCookie("qutz.com/", value1);
    assertThat(cookieManager.getCookie("http://.qutz.com")).isEqualTo(value1);
}
Also used : CookieManager(android.webkit.CookieManager) Test(org.junit.Test)

Example 33 with CookieManager

use of android.webkit.CookieManager in project robolectric by robolectric.

the class ShadowCookieManagerTest method shouldSetAndGetACookie.

@Test
public void shouldSetAndGetACookie() {
    CookieManager cookieManager = CookieManager.getInstance();
    String url = "http://www.google.com";
    String value = "my cookie";
    cookieManager.setCookie(url, value);
    assertThat(cookieManager.getCookie(url)).isEqualTo(value);
}
Also used : CookieManager(android.webkit.CookieManager) Test(org.junit.Test)

Example 34 with CookieManager

use of android.webkit.CookieManager in project AgentWeb by Justson.

the class AgentWebConfig method syncCookieToWebView.

/**
     * cookie同步
     */
private void syncCookieToWebView(Context context, List<String> cookies, String url) {
    if (CookieSyncManager.getInstance() == null)
        CookieSyncManager.createInstance(context);
    CookieManager cm = CookieManager.getInstance();
    cm.removeAllCookie();
    cm.setAcceptCookie(true);
    if (cookies != null) {
        for (String cookie : cookies) {
            cm.setCookie(url, cookie);
        }
    }
    CookieSyncManager.getInstance().sync();
}
Also used : CookieManager(android.webkit.CookieManager)

Example 35 with CookieManager

use of android.webkit.CookieManager in project Lightning-Browser by anthonycr.

the class WebUtils method clearCookies.

public static void clearCookies(@NonNull Context context) {
    CookieManager c = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        c.removeAllCookies(null);
    } else {
        //noinspection deprecation
        CookieSyncManager.createInstance(context);
        //noinspection deprecation
        c.removeAllCookie();
    }
}
Also used : CookieManager(android.webkit.CookieManager)

Aggregations

CookieManager (android.webkit.CookieManager)37 CookieSyncManager (android.webkit.CookieSyncManager)9 Test (org.junit.Test)7 WebView (android.webkit.WebView)4 SuppressLint (android.annotation.SuppressLint)3 WebSettings (android.webkit.WebSettings)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Editor (android.content.SharedPreferences.Editor)2 Uri (android.net.Uri)2 View (android.view.View)2 WebViewClient (android.webkit.WebViewClient)2 TextView (android.widget.TextView)2 TargetApi (android.annotation.TargetApi)1 ActionBar (android.app.ActionBar)1 AlarmManager (android.app.AlarmManager)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1