Class ShadowWebView
@Implements(android.webkit.WebView.class) public class ShadowWebView extends ShadowViewGroup
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShadowWebView.LoadData
static class
ShadowWebView.LoadDataWithBaseURL
Nested classes/interfaces inherited from class org.robolectric.shadows.ShadowView
ShadowView.WindowIdHelper
-
Field Summary
Fields inherited from class org.robolectric.shadows.ShadowView
attributeSet, realView, scrollToCoordinates, viewReflector
-
Constructor Summary
Constructors Constructor Description ShadowWebView()
-
Method Summary
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, 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 preferered 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.
-