1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.content.Context;
4 import android.webkit.CookieSyncManager;
5 
6 import com.xtremelabs.robolectric.Robolectric;
7 import com.xtremelabs.robolectric.internal.Implementation;
8 import com.xtremelabs.robolectric.internal.Implements;
9 
10 /**
11  * Shadows the {@code android.webkit.CookieSyncManager} class.
12  */
13 @Implements(CookieSyncManager.class)
14 public class ShadowCookieSyncManager {
15 
16     private static CookieSyncManager sRef;
17 
18     private boolean synced = false;
19 
20     @Implementation
createInstance(Context ctx)21     public static synchronized CookieSyncManager createInstance(Context ctx) {
22         if (sRef == null) {
23             sRef = Robolectric.newInstanceOf(CookieSyncManager.class);
24         }
25         return sRef;
26     }
27 
28     @Implementation
getInstance()29     public static CookieSyncManager getInstance() {
30         if (sRef == null) {
31             throw new IllegalStateException("createInstance must be called first");
32         }
33         return sRef;
34     }
35 
36     @Implementation
sync()37     public void sync() {
38         synced = true;
39     }
40 
synced()41     public boolean synced() {
42         return synced;
43     }
44 
reset()45     public void reset() {
46         synced = false;
47     }
48 }
49