Class ShadowWebView
- java.lang.Object
-
- org.robolectric.shadows.ShadowView
-
- org.robolectric.shadows.ShadowViewGroup
-
- org.robolectric.shadows.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.ShadowViewGroup
realViewGroup
-
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, clearWasInvalidated, clickOn, didRequestLayout, draw, dump, dump, dumpAttribute, dumpAttributes, dumpFirstPart, dumpIndent, 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
-
-
-
-
Method Detail
-
getFactory
@HiddenApi @Implementation protected static WebViewFactoryProvider getFactory()
-
ensureProviderCreated
@HiddenApi @Implementation public void ensureProviderCreated()
-
setLayoutParams
@Implementation protected void setLayoutParams(ViewGroup.LayoutParams params)
-
loadUrl
@Implementation protected void loadUrl(String url)
-
loadUrl
@Implementation protected void loadUrl(String url, Map<String,String> additionalHttpHeaders)
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
@Implementation protected void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)
-
loadData
@Implementation protected void loadData(String data, String mimeType, String encoding)
-
pushEntryToHistory
public void pushEntryToHistory(String url)
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
public String getLastLoadedUrl()
- Returns:
- the last loaded url
-
getOriginalUrl
@Implementation protected String getOriginalUrl()
-
getUrl
@Implementation protected String getUrl()
-
getTitle
@Implementation protected String getTitle()
-
getLastAdditionalHttpHeaders
public Map<String,String> getLastAdditionalHttpHeaders()
- Returns:
- the additional Http headers that in the same request with last loaded url
-
getSettings
@Implementation protected WebSettings getSettings()
-
setWebViewClient
@Implementation protected void setWebViewClient(WebViewClient client)
-
setWebChromeClient
@Implementation protected void setWebChromeClient(WebChromeClient client)
-
getWebViewClient
@Implementation(minSdk=26) public WebViewClient getWebViewClient()
-
addJavascriptInterface
@Implementation protected void addJavascriptInterface(Object obj, String interfaceName)
-
removeJavascriptInterface
@Implementation protected void removeJavascriptInterface(String name)
-
createWebMessageChannel
@Implementation(minSdk=23) protected WebMessagePort[] createWebMessageChannel()
-
getCreatedPorts
public List<RoboWebMessagePort[]> getCreatedPorts()
-
clearCache
@Implementation protected void clearCache(boolean includeDiskFiles)
-
wasClearCacheCalled
public boolean wasClearCacheCalled()
-
didClearCacheIncludeDiskFiles
public boolean didClearCacheIncludeDiskFiles()
-
clearFormData
@Implementation protected void clearFormData()
-
wasClearFormDataCalled
public boolean wasClearFormDataCalled()
-
clearHistory
@Implementation protected void clearHistory()
-
wasClearHistoryCalled
public boolean wasClearHistoryCalled()
-
reload
@Implementation protected void reload()
-
getReloadInvocations
public int getReloadInvocations()
Returns the number of timesandroid.webkit.WebView#reload()
was invoked
-
clearView
@Implementation protected void clearView()
-
wasClearViewCalled
public boolean wasClearViewCalled()
-
onPause
@Implementation protected void onPause()
-
wasOnPauseCalled
public boolean wasOnPauseCalled()
-
onResume
@Implementation protected void onResume()
-
wasOnResumeCalled
public boolean wasOnResumeCalled()
-
destroy
@Implementation protected void destroy()
-
wasDestroyCalled
public boolean wasDestroyCalled()
-
getWebChromeClient
@Implementation(minSdk=26) public WebChromeClient getWebChromeClient()
- Returns:
- webChromeClient
-
canGoBack
@Implementation protected boolean canGoBack()
-
canGoForward
@Implementation protected boolean canGoForward()
-
goBack
@Implementation protected void goBack()
-
goForward
@Implementation protected void goForward()
-
goBackOrForward
@Implementation protected void goBackOrForward(int steps)
-
copyBackForwardList
@Implementation protected WebBackForwardList copyBackForwardList()
-
findAddress
@Implementation protected static String findAddress(String addr)
-
getCurrentWebViewPackage
@Implementation(minSdk=26) protected static PackageInfo getCurrentWebViewPackage()
Overrides the system implementation for getting the WebView package.Returns null by default, but this can be changed with
#setCurrentWebviewPackage()
.
-
setCurrentWebViewPackage
public static void setCurrentWebViewPackage(PackageInfo webViewPackageInfo)
Sets the value to return from#getCurrentWebviewPackage()
.
-
getFavicon
@Implementation protected Bitmap getFavicon()
Gets the favicon for the current page set bysetFavicon(android.graphics.Bitmap)
.
-
setFavicon
public void setFavicon(Bitmap favicon)
Sets the favicon to return fromgetFavicon()
.
-
evaluateJavascript
@Implementation(minSdk=19) protected void evaluateJavascript(String script, ValueCallback<String> callback)
-
getLastEvaluatedJavascript
public String getLastEvaluatedJavascript()
Returns the last evaluated Javascript value provided toevaluateJavascript(String, ValueCallback)
or null if the method has not been called.
-
getLastEvaluatedJavascriptCallback
public ValueCallback<String> getLastEvaluatedJavascriptCallback()
Returns the last callback value provided toevaluateJavascript(String, ValueCallback)
or null if the method has not been called.
-
setCanGoBack
@Deprecated public 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.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
public ShadowWebView.LoadData getLastLoadData()
-
getLastLoadDataWithBaseURL
public ShadowWebView.LoadDataWithBaseURL getLastLoadDataWithBaseURL()
-
saveState
@Implementation protected WebBackForwardList saveState(Bundle outState)
-
restoreState
@Implementation protected WebBackForwardList restoreState(Bundle inState)
-
getHitTestResult
@Implementation protected WebView.HitTestResult getHitTestResult()
-
createHitTestResult
public static WebView.HitTestResult createHitTestResult(int type, String extra)
Creates an instance ofWebView.HitTestResult
.
-
setHitTestResult
public void setHitTestResult(WebView.HitTestResult hitTestResult)
Sets theWebView.HitTestResult
that should be returned fromgetHitTestResult()
.
-
reset
@Resetter public static void reset()
-
setWebContentsDebuggingEnabled
@Implementation(minSdk=19) public static void setWebContentsDebuggingEnabled(boolean enabled)
-
setBackgroundColor
@Implementation protected void setBackgroundColor(int backgroundColor)
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
@Implementation protected void setDownloadListener(DownloadListener downloadListener)
-
getDownloadListener
public DownloadListener getDownloadListener()
Returns theDownloadListener
set withsetDownloadListener(android.webkit.DownloadListener)
, if any.
-
-