Class ShadowWebView
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
Nested classes/interfaces inherited from class org.robolectric.shadows.ShadowView
ShadowView.WindowIdHelper
-
Field Summary
Fields inherited from class org.robolectric.shadows.ShadowViewGroup
realViewGroup
Fields inherited from class org.robolectric.shadows.ShadowView
attributeSet, realView, scrollToCoordinates, viewReflector
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addJavascriptInterface
(Object obj, String interfaceName) protected boolean
protected boolean
protected void
clearCache
(boolean includeDiskFiles) protected void
protected void
protected void
protected WebBackForwardList
static WebView.HitTestResult
createHitTestResult
(int type, String extra) Creates an instance ofWebView.HitTestResult
.protected WebMessagePort[]
protected void
destroy()
boolean
void
protected void
evaluateJavascript
(String script, ValueCallback<String> callback) protected static String
findAddress
(String addr) int
Returns theColor
int that has been set bysetBackgroundColor(int)
.protected static PackageInfo
Overrides the system implementation for getting the WebView package.Returns theDownloadListener
set withsetDownloadListener(android.webkit.DownloadListener)
, if any.protected static WebViewFactoryProvider
protected Bitmap
Gets the favicon for the current page set bysetFavicon(android.graphics.Bitmap)
.int
Returns the number of timesandroid.webkit.WebView#goBack()
was invoked.int
Returns the number of timesandroid.webkit.WebView#goForward()
was invoked.protected WebView.HitTestResult
getJavascriptInterface
(String interfaceName) Returns the last evaluated Javascript value provided toevaluateJavascript(String, ValueCallback)
or null if the method has not been called.Returns the last callback value provided toevaluateJavascript(String, ValueCallback)
or null if the method has not been called.protected String
int
Returns the number of timesandroid.webkit.WebView#reload()
was invokedprotected WebSettings
protected String
getTitle()
protected String
getUrl()
protected void
goBack()
protected void
goBackOrForward
(int steps) protected void
protected void
protected void
loadDataWithBaseURL
(String baseUrl, String data, String mimeType, String encoding, String historyUrl) protected void
protected void
Fires a request to load the givenurl
in WebView.protected void
onPause()
protected void
onResume()
void
Performs no callbacks onWebViewClient
andWebChromeClient
when any ofloadUrl(java.lang.String)
,loadData(java.lang.String,java.lang.String,java.lang.String)
orloadDataWithBaseURL(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
is called.void
Performs callbacks onWebViewClient
andWebChromeClient
that simulates a successful page load when any ofloadUrl(java.lang.String)
,loadData(java.lang.String,java.lang.String,java.lang.String)
orloadDataWithBaseURL(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 givenurl
.protected void
reload()
protected void
static void
reset()
protected WebBackForwardList
restoreState
(Bundle inState) protected WebBackForwardList
protected void
setBackgroundColor
(int backgroundColor) Sets theColor
int that should be returned fromgetBackgroundColor()
.void
setCanGoBack
(boolean canGoBack) Deprecated.Do not depend on this method as it will be removed in a future update.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 fromgetFavicon()
.void
setHitTestResult
(WebView.HitTestResult hitTestResult) Sets theWebView.HitTestResult
that should be returned fromgetHitTestResult()
.protected void
protected void
setWebChromeClient
(WebChromeClient client) static void
setWebContentsDebuggingEnabled
(boolean enabled) protected void
setWebViewClient
(WebViewClient client) boolean
boolean
boolean
boolean
boolean
boolean
boolean
Methods inherited from class org.robolectric.shadows.ShadowViewGroup
addView, dump, getDisallowInterceptTouchEvent, getInterceptedTouchEvent, innerText, onInterceptTouchEvent, removedChild, requestDisallowInterceptTouchEvent
Methods inherited from class org.robolectric.shadows.ShadowView
__constructor__, __constructor__, addGlobalPerformClickListener, addGlobalPerformLongClickListener, addOnAttachStateChangeListener, addOnLayoutChangeListener, callOnAttachedToWindow, callOnDetachedFromWindow, checkedPerformClick, clearAnimation, clearAnimations, clearWasInvalidated, clickOn, didRequestLayout, draw, dump, dump, dumpAttribute, dumpAttributes, dumpFirstPart, dumpIndent, getAnimations, getGlobalVisibleRect, getLastTouchEvent, getLayerType, getLocationOnScreen, getOnAttachStateChangeListeners, getOnClickListener, getOnCreateContextMenuListener, getOnLayoutChangeListeners, getOnLongClickListener, getOnSystemUiVisibilityChangeListener, getOnTouchListener, getScrollX, getScrollY, getSourceLayoutResId, getWindowDisplayFrame, getWindowId, getWindowVisibleDisplayFrame, initialAwakenScrollBars, innerText, invalidate, isAttachedToWindow, lastHapticFeedbackPerformed, mapRectFromViewToScreenCoords, onLayout, onLayoutWasCalled, onTouchEvent, performClick, performHapticFeedback, performLongClick, post, postDelayed, postInvalidateDelayed, removeCallbacks, removeGlobalPerformClickListener, removeGlobalPerformLongClickListener, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestLayout, scrollBy, scrollTo, setAnimation, setDidRequestLayout, setGlobalVisibleRect, setLayerType, setMyParent, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setScrollX, setScrollY, setViewFocus, useRealGraphics, visualize, wasInvalidated
-
Constructor Details
-
ShadowWebView
public ShadowWebView()
-
-
Method Details
-
getFactory
-
ensureProviderCreated
-
setLayoutParams
-
loadUrl
-
loadUrl
Fires a request to load the givenurl
in WebView.The
url
is is not added to the history untilpushEntryToHistory(String)
is called. If you want to simulate a redirect you can pass the redirect URL topushEntryToHistory(String)
. -
loadDataWithBaseURL
-
loadData
-
pushEntryToHistory
Pushes an entry to the history with the givenurl
.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 givenurl
does not need to match that of theloadUrl(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.
-
performNoPageLoadClientCallbacks
public void performNoPageLoadClientCallbacks()Performs no callbacks onWebViewClient
andWebChromeClient
when any ofloadUrl(java.lang.String)
,loadData(java.lang.String,java.lang.String,java.lang.String)
orloadDataWithBaseURL(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
is called. -
performSuccessfulPageLoadClientCallbacks
public void performSuccessfulPageLoadClientCallbacks()Performs callbacks onWebViewClient
andWebChromeClient
that simulates a successful page load when any ofloadUrl(java.lang.String)
,loadData(java.lang.String,java.lang.String,java.lang.String)
orloadDataWithBaseURL(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
is called. -
getLastLoadedUrl
- Returns:
- the last loaded url
-
getOriginalUrl
-
getUrl
-
getTitle
-
getLastAdditionalHttpHeaders
- Returns:
- the additional Http headers that in the same request with last loaded url
-
getSettings
-
setWebViewClient
-
setWebChromeClient
-
getWebViewClient
-
addJavascriptInterface
-
getJavascriptInterface
-
removeJavascriptInterface
-
createWebMessageChannel
-
getCreatedPorts
-
clearCache
-
wasClearCacheCalled
public boolean wasClearCacheCalled() -
didClearCacheIncludeDiskFiles
public boolean didClearCacheIncludeDiskFiles() -
clearFormData
-
wasClearFormDataCalled
public boolean wasClearFormDataCalled() -
clearHistory
-
wasClearHistoryCalled
public boolean wasClearHistoryCalled() -
reload
-
getReloadInvocations
public int getReloadInvocations()Returns the number of timesandroid.webkit.WebView#reload()
was invoked -
clearView
-
wasClearViewCalled
public boolean wasClearViewCalled() -
onPause
-
wasOnPauseCalled
public boolean wasOnPauseCalled() -
onResume
-
wasOnResumeCalled
public boolean wasOnResumeCalled() -
destroy
-
wasDestroyCalled
public boolean wasDestroyCalled() -
getWebChromeClient
- Returns:
- webChromeClient
-
canGoBack
-
canGoForward
-
goBack
-
goForward
-
goBackOrForward
-
copyBackForwardList
-
findAddress
-
getCurrentWebViewPackage
Overrides the system implementation for getting the WebView package.Returns null by default, but this can be changed with
#setCurrentWebviewPackage()
. -
setCurrentWebViewPackage
Sets the value to return from#getCurrentWebviewPackage()
. -
getFavicon
Gets the favicon for the current page set bysetFavicon(android.graphics.Bitmap)
. -
setFavicon
Sets the favicon to return fromgetFavicon()
. -
evaluateJavascript
@Implementation(minSdk=19) protected void evaluateJavascript(String script, ValueCallback<String> callback) -
getLastEvaluatedJavascript
Returns the last evaluated Javascript value provided toevaluateJavascript(String, ValueCallback)
or null if the method has not been called. -
getLastEvaluatedJavascriptCallback
Returns the last callback value provided toevaluateJavascript(String, ValueCallback)
or null if the method has not been called. -
setCanGoBack
Deprecated.Do not depend on this method as it will be removed in a future update. The preferred method is to populate a fake web history to use for going back.Sets the value to return fromandroid.webkit.WebView#canGoBack()
- Parameters:
canGoBack
- Value to return fromandroid.webkit.WebView#canGoBack()
-
getGoBackInvocations
public int getGoBackInvocations()Returns the number of timesandroid.webkit.WebView#goBack()
was invoked. -
getGoForwardInvocations
public int getGoForwardInvocations()Returns the number of timesandroid.webkit.WebView#goForward()
was invoked. -
getLastLoadData
-
getLastLoadDataWithBaseURL
-
saveState
-
restoreState
-
getHitTestResult
-
createHitTestResult
Creates an instance ofWebView.HitTestResult
. -
setHitTestResult
Sets theWebView.HitTestResult
that should be returned fromgetHitTestResult()
. -
reset
-
setWebContentsDebuggingEnabled
-
setBackgroundColor
Sets theColor
int that should be returned fromgetBackgroundColor()
.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 theView.setBackgroundColor(int)
method and it interacts directly with WebView renderers. Tests can access the set background color using thegetBackgroundColor()
method. -
getBackgroundColor
public int getBackgroundColor()Returns theColor
int that has been set bysetBackgroundColor(int)
. -
setDownloadListener
-
getDownloadListener
Returns theDownloadListener
set withsetDownloadListener(android.webkit.DownloadListener)
, if any.
-