@Implements(android.webkit.WebView.class) public class ShadowWebView extends ShadowViewGroup
Modifier and Type | Class | Description |
---|---|---|
static class |
ShadowWebView.LoadData |
|
static class |
ShadowWebView.LoadDataWithBaseURL |
ShadowView.WindowIdHelper
attributeSet, realView, scrollToCoordinates
realViewGroup
Constructor | Description |
---|---|
ShadowWebView() |
Modifier and Type | Method | Description |
---|---|---|
protected void |
addJavascriptInterface(Object obj,
String interfaceName) |
|
protected boolean |
canGoBack() |
|
protected boolean |
canGoForward() |
|
protected void |
clearCache(boolean includeDiskFiles) |
|
protected void |
clearFormData() |
|
protected void |
clearHistory() |
|
protected void |
clearView() |
|
protected WebBackForwardList |
copyBackForwardList() |
|
static WebView.HitTestResult |
createHitTestResult(int type,
String extra) |
Creates an instance of
WebView.HitTestResult . |
protected void |
destroy() |
|
boolean |
didClearCacheIncludeDiskFiles() |
|
void |
ensureProviderCreated() |
|
protected void |
evaluateJavascript(String script,
ValueCallback<String> callback) |
|
protected static String |
findAddress(String addr) |
|
int |
getBackgroundColor() |
Returns the
Color int that has been set by setBackgroundColor(int) . |
protected static PackageInfo |
getCurrentWebViewPackage() |
Overrides the system implementation for getting the WebView package.
|
DownloadListener |
getDownloadListener() |
Returns the
DownloadListener set with setDownloadListener(android.webkit.DownloadListener) , if any. |
protected static WebViewFactoryProvider |
getFactory() |
|
protected Bitmap |
getFavicon() |
Gets the favicon for the current page set by
setFavicon(android.graphics.Bitmap) . |
int |
getGoBackInvocations() |
Returns the number of times
android.webkit.WebView#goBack() was invoked. |
int |
getGoForwardInvocations() |
Returns the number of times
android.webkit.WebView#goForward() was invoked. |
protected WebView.HitTestResult |
getHitTestResult() |
|
Object |
getJavascriptInterface(String interfaceName) |
|
Map<String,String> |
getLastAdditionalHttpHeaders() |
|
String |
getLastEvaluatedJavascript() |
|
ShadowWebView.LoadData |
getLastLoadData() |
|
ShadowWebView.LoadDataWithBaseURL |
getLastLoadDataWithBaseURL() |
|
String |
getLastLoadedUrl() |
|
protected String |
getOriginalUrl() |
|
int |
getReloadInvocations() |
Returns the number of times
android.webkit.WebView#reload() was invoked |
protected WebSettings |
getSettings() |
|
protected String |
getTitle() |
|
protected String |
getUrl() |
|
WebChromeClient |
getWebChromeClient() |
|
WebViewClient |
getWebViewClient() |
|
protected void |
goBack() |
|
protected void |
goBackOrForward(int steps) |
|
protected void |
goForward() |
|
protected void |
loadData(String data,
String mimeType,
String encoding) |
|
protected void |
loadDataWithBaseURL(String baseUrl,
String data,
String mimeType,
String encoding,
String historyUrl) |
|
protected void |
loadUrl(String url) |
|
protected void |
loadUrl(String url,
Map<String,String> additionalHttpHeaders) |
Fires a request to load the given
url in WebView. |
protected void |
onPause() |
|
protected void |
onResume() |
|
void |
performNoPageLoadClientCallbacks() |
Performs no callbacks on
WebViewClient and WebChromeClient when any of loadUrl(java.lang.String) , loadData(java.lang.String,java.lang.String,java.lang.String) or loadDataWithBaseURL(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) is called. |
void |
performSuccessfulPageLoadClientCallbacks() |
Performs callbacks on
WebViewClient and WebChromeClient that simulates a
successful page load when any of loadUrl(java.lang.String) , loadData(java.lang.String,java.lang.String,java.lang.String) or loadDataWithBaseURL(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) is called. |
void |
pushEntryToHistory(String url) |
Pushes an entry to the history with the given
url . |
protected void |
reload() |
|
protected void |
removeJavascriptInterface(String name) |
|
static void |
reset() |
|
protected WebBackForwardList |
restoreState(Bundle inState) |
|
protected WebBackForwardList |
saveState(Bundle outState) |
|
protected void |
setBackgroundColor(int backgroundColor) |
Sets the
Color int that should be returned from getBackgroundColor() . |
void |
setCanGoBack(boolean canGoBack) |
Deprecated.
Do not depend on this method as it will be removed in a future update. The
preferered method is to populate a fake web history to use for going back.
|
static void |
setCurrentWebViewPackage(PackageInfo webViewPackageInfo) |
Sets the value to return from
#getCurrentWebviewPackage() . |
protected void |
setDownloadListener(DownloadListener downloadListener) |
|
void |
setFavicon(Bitmap favicon) |
Sets the favicon to return from
getFavicon() . |
void |
setHitTestResult(WebView.HitTestResult hitTestResult) |
Sets the
WebView.HitTestResult that should be returned from getHitTestResult() . |
protected void |
setLayoutParams(ViewGroup.LayoutParams params) |
|
protected void |
setWebChromeClient(WebChromeClient client) |
|
static void |
setWebContentsDebuggingEnabled(boolean enabled) |
|
protected void |
setWebViewClient(WebViewClient client) |
|
boolean |
wasClearCacheCalled() |
|
boolean |
wasClearFormDataCalled() |
|
boolean |
wasClearHistoryCalled() |
|
boolean |
wasClearViewCalled() |
|
boolean |
wasDestroyCalled() |
|
boolean |
wasOnPauseCalled() |
|
boolean |
wasOnResumeCalled() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
__constructor__, addOnAttachStateChangeListener, callOnAttachedToWindow, callOnDetachedFromWindow, checkedPerformClick, clearAnimation, clearWasInvalidated, clickOn, didRequestLayout, draw, dump, dump, dumpAttribute, dumpAttributes, dumpFirstPart, dumpIndent, getGlobalVisibleRect, getLastTouchEvent, getLayerType, getOnAttachStateChangeListeners, getOnClickListener, getOnCreateContextMenuListener, getOnLongClickListener, getOnSystemUiVisibilityChangeListener, getOnTouchListener, getScrollX, getScrollY, getWindowDisplayFrame, getWindowId, getWindowVisibleDisplayFrame, innerText, invalidate, isAttachedToWindow, lastHapticFeedbackPerformed, onLayout, onLayoutWasCalled, onTouchEvent, performHapticFeedback, post, postDelayed, postInvalidateDelayed, removeCallbacks, removeOnAttachStateChangeListener, requestLayout, scrollBy, scrollTo, setAnimation, setDidRequestLayout, setGlobalVisibleRect, setLayerType, setMyParent, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setScrollX, setScrollY, setViewFocus, visualize, wasInvalidated
addView, dump, getDisallowInterceptTouchEvent, getInterceptedTouchEvent, innerText, onInterceptTouchEvent, removedChild, requestDisallowInterceptTouchEvent
@HiddenApi @Implementation protected static WebViewFactoryProvider getFactory()
@HiddenApi @Implementation public void ensureProviderCreated()
@Implementation protected void setLayoutParams(ViewGroup.LayoutParams params)
@Implementation protected void loadUrl(String url)
@Implementation protected void loadUrl(String url, Map<String,String> additionalHttpHeaders)
url
in WebView.
The url
is is not added to the history until pushEntryToHistory(String)
is
called. If you want to simulate a redirect you can pass the redirect URL to pushEntryToHistory(String)
.
@Implementation protected void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)
@Implementation protected void loadData(String data, String mimeType, String encoding)
public void pushEntryToHistory(String url)
url
.
This method can be used after a loadUrl(String)
call to push that navigation into
the history. This matches the prod behaviour of WebView, a navigation is never committed to
history inline and can take an arbitrary amount of time depending on the network connection.
Notice that the given url
does not need to match that of the loadUrl(String)
as URL can be changed e.g. through server-side redirects without WebView being notified by the
time it is committed.
This method can also be used to simulate navigations started by user interaction, as these would still add an entry to the history themselves.
If there are any entries ahead of the current index (for forward navigation) these are removed.
public void performNoPageLoadClientCallbacks()
WebViewClient
and WebChromeClient
when any of loadUrl(java.lang.String)
, loadData(java.lang.String,java.lang.String,java.lang.String)
or loadDataWithBaseURL(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
is called.public void performSuccessfulPageLoadClientCallbacks()
WebViewClient
and WebChromeClient
that simulates a
successful page load when any of loadUrl(java.lang.String)
, loadData(java.lang.String,java.lang.String,java.lang.String)
or loadDataWithBaseURL(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
is called.public String getLastLoadedUrl()
@Implementation protected String getOriginalUrl()
@Implementation protected String getUrl()
@Implementation protected String getTitle()
public Map<String,String> getLastAdditionalHttpHeaders()
@Implementation protected WebSettings getSettings()
@Implementation protected void setWebViewClient(WebViewClient client)
@Implementation protected void setWebChromeClient(WebChromeClient client)
public WebViewClient getWebViewClient()
@Implementation protected void addJavascriptInterface(Object obj, String interfaceName)
@Implementation protected void removeJavascriptInterface(String name)
@Implementation protected void clearCache(boolean includeDiskFiles)
public boolean wasClearCacheCalled()
public boolean didClearCacheIncludeDiskFiles()
@Implementation protected void clearFormData()
public boolean wasClearFormDataCalled()
@Implementation protected void clearHistory()
public boolean wasClearHistoryCalled()
@Implementation protected void reload()
public int getReloadInvocations()
android.webkit.WebView#reload()
was invoked@Implementation protected void clearView()
public boolean wasClearViewCalled()
@Implementation protected void onPause()
public boolean wasOnPauseCalled()
@Implementation protected void onResume()
public boolean wasOnResumeCalled()
@Implementation protected void destroy()
public boolean wasDestroyCalled()
public WebChromeClient getWebChromeClient()
@Implementation protected boolean canGoBack()
@Implementation protected boolean canGoForward()
@Implementation protected void goBack()
@Implementation protected void goForward()
@Implementation protected void goBackOrForward(int steps)
@Implementation protected WebBackForwardList copyBackForwardList()
@Implementation protected static String findAddress(String addr)
@Implementation(minSdk=26) protected static PackageInfo getCurrentWebViewPackage()
Returns null by default, but this can be changed with #setCurrentWebviewPackage()
.
public static void setCurrentWebViewPackage(PackageInfo webViewPackageInfo)
#getCurrentWebviewPackage()
.@Implementation protected Bitmap getFavicon()
setFavicon(android.graphics.Bitmap)
.public void setFavicon(Bitmap favicon)
getFavicon()
.@Implementation(minSdk=19) protected void evaluateJavascript(String script, ValueCallback<String> callback)
public String getLastEvaluatedJavascript()
@Deprecated public void setCanGoBack(boolean canGoBack)
android.webkit.WebView#canGoBack()
canGoBack
- Value to return from android.webkit.WebView#canGoBack()
public int getGoBackInvocations()
android.webkit.WebView#goBack()
was invoked.public int getGoForwardInvocations()
android.webkit.WebView#goForward()
was invoked.public ShadowWebView.LoadData getLastLoadData()
public ShadowWebView.LoadDataWithBaseURL getLastLoadDataWithBaseURL()
@Implementation protected WebBackForwardList saveState(Bundle outState)
@Implementation protected WebBackForwardList restoreState(Bundle inState)
@Implementation protected WebView.HitTestResult getHitTestResult()
public static WebView.HitTestResult createHitTestResult(int type, String extra)
WebView.HitTestResult
.public void setHitTestResult(WebView.HitTestResult hitTestResult)
WebView.HitTestResult
that should be returned from getHitTestResult()
.@Resetter public static void reset()
public static void setWebContentsDebuggingEnabled(boolean enabled)
@Implementation protected void setBackgroundColor(int backgroundColor)
Color
int that should be returned from getBackgroundColor()
.
WebView uses the background color set by the WebView.setBackgroundColor(int)
method to internally tint the background color of
web pages until they are drawn. The way this API works is completely independent of the View.setBackgroundColor(int)
method and it interacts directly with WebView renderers.
Tests can access the set background color using the getBackgroundColor()
method.
public int getBackgroundColor()
Color
int that has been set by setBackgroundColor(int)
.@Implementation protected void setDownloadListener(DownloadListener downloadListener)
public DownloadListener getDownloadListener()
DownloadListener
set with setDownloadListener(android.webkit.DownloadListener)
, if any.