blob: 427a101900b018faf7c4d2bf4685072ff6b156d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package org.robolectric.shadows;
import android.content.Context;
import android.webkit.WebSettings;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
/**
* Shadow of {@link WebSettings} which returns a dummy user a stub instance rather than the
* User-Agent used by a WebView.
*/
@Implements(value = WebSettings.class)
public class ShadowWebSettings {
private static String defaultUserAgent = "user";
/**
* Returns the default User-Agent used by a WebView. An instance of WebView could use a different
* User-Agent if a call is made to {@link WebSettings#setUserAgentString(String)}.
*
* @param context a Context object used to access application assets
*/
@Implementation
protected static String getDefaultUserAgent(Context context) {
return defaultUserAgent;
}
/**
* Sets the default user agent for the WebView. The value set here is returned from {@link
* #getDefaultUserAgent(Context)}.
*/
public static void setDefaultUserAgent(String defaultUserAgent) {
ShadowWebSettings.defaultUserAgent = defaultUserAgent;
}
@Resetter
public static void reset() {
ShadowWebSettings.defaultUserAgent = "user";
}
}
|