Class ShadowWebView
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classNested classes/interfaces inherited from class org.robolectric.shadows.ShadowView
ShadowView.WindowIdHelper -
Field Summary
Fields inherited from class org.robolectric.shadows.ShadowViewGroup
realViewGroupFields inherited from class org.robolectric.shadows.ShadowView
attributeSet, realView, scrollToCoordinates, viewReflector -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddJavascriptInterface(Object obj, String interfaceName) protected booleanprotected booleanprotected voidclearCache(boolean includeDiskFiles) protected voidprotected voidprotected voidprotected WebBackForwardListstatic WebView.HitTestResultcreateHitTestResult(int type, String extra) Creates an instance ofWebView.HitTestResult.protected WebMessagePort[]protected voiddestroy()booleanvoidprotected voidevaluateJavascript(String script, ValueCallback<String> callback) protected static StringfindAddress(String addr) intReturns theColorint that has been set bysetBackgroundColor(int).protected static PackageInfoOverrides the system implementation for getting the WebView package.Returns theDownloadListenerset withsetDownloadListener(android.webkit.DownloadListener), if any.protected static WebViewFactoryProviderprotected BitmapGets the favicon for the current page set bysetFavicon(android.graphics.Bitmap).intReturns the number of timesandroid.webkit.WebView#goBack()was invoked.intReturns the number of timesandroid.webkit.WebView#goForward()was invoked.protected WebView.HitTestResultgetJavascriptInterface(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 StringintReturns the number of timesandroid.webkit.WebView#reload()was invokedprotected WebSettingsprotected StringgetTitle()protected StringgetUrl()protected voidgoBack()protected voidgoBackOrForward(int steps) protected voidprotected voidprotected voidloadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) protected voidprotected voidFires a request to load the givenurlin WebView.protected voidonPause()protected voidonResume()voidPerforms no callbacks onWebViewClientandWebChromeClientwhen 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.voidPerforms callbacks onWebViewClientandWebChromeClientthat 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.voidpushEntryToHistory(String url) Pushes an entry to the history with the givenurl.protected voidreload()protected voidstatic voidreset()protected WebBackForwardListrestoreState(Bundle inState) protected WebBackForwardListprotected voidsetBackgroundColor(int backgroundColor) Sets theColorint that should be returned fromgetBackgroundColor().voidsetCanGoBack(boolean canGoBack) Deprecated.Do not depend on this method as it will be removed in a future update.static voidsetCurrentWebViewPackage(PackageInfo webViewPackageInfo) Sets the value to return from#getCurrentWebviewPackage().protected voidsetDownloadListener(DownloadListener downloadListener) voidsetFavicon(Bitmap favicon) Sets the favicon to return fromgetFavicon().voidsetHitTestResult(WebView.HitTestResult hitTestResult) Sets theWebView.HitTestResultthat should be returned fromgetHitTestResult().protected voidprotected voidsetWebChromeClient(WebChromeClient client) static voidsetWebContentsDebuggingEnabled(boolean enabled) protected voidsetWebViewClient(WebViewClient client) booleanbooleanbooleanbooleanbooleanbooleanbooleanMethods inherited from class org.robolectric.shadows.ShadowViewGroup
addView, dump, getDisallowInterceptTouchEvent, getInterceptedTouchEvent, innerText, onInterceptTouchEvent, removedChild, requestDisallowInterceptTouchEventMethods inherited from class org.robolectric.shadows.ShadowView
__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 givenurlin WebView.The
urlis 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 givenurldoes 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 onWebViewClientandWebChromeClientwhen 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 onWebViewClientandWebChromeClientthat 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
-
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.HitTestResultthat should be returned fromgetHitTestResult(). -
reset
-
setWebContentsDebuggingEnabled
-
setBackgroundColor
Sets theColorint 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 theColorint that has been set bysetBackgroundColor(int). -
setDownloadListener
-
getDownloadListener
Returns theDownloadListenerset withsetDownloadListener(android.webkit.DownloadListener), if any.
-