Class ShadowWebView


@Implements(android.webkit.WebView.class) public class ShadowWebView extends ShadowViewGroup
  • Constructor Details

    • ShadowWebView

      public ShadowWebView()
  • Method Details

    • 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 given 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).

    • 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 given 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.

    • performNoPageLoadClientCallbacks

      public void performNoPageLoadClientCallbacks()
    • performSuccessfulPageLoadClientCallbacks

      public void performSuccessfulPageLoadClientCallbacks()
    • 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)
    • getJavascriptInterface

      public Object getJavascriptInterface(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 times android.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 by setFavicon(android.graphics.Bitmap).
    • setFavicon

      public void setFavicon(Bitmap favicon)
      Sets the favicon to return from getFavicon().
    • evaluateJavascript

      @Implementation(minSdk=19) protected void evaluateJavascript(String script, ValueCallback<String> callback)
    • getLastEvaluatedJavascript

      public String getLastEvaluatedJavascript()
      Returns the last evaluated Javascript value provided to evaluateJavascript(String, ValueCallback) or null if the method has not been called.
    • getLastEvaluatedJavascriptCallback

      public ValueCallback<String> getLastEvaluatedJavascriptCallback()
      Returns the last callback value provided to evaluateJavascript(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 preferred method is to populate a fake web history to use for going back.
      Sets the value to return from android.webkit.WebView#canGoBack()
      Parameters:
      canGoBack - Value to return from android.webkit.WebView#canGoBack()
    • getGoBackInvocations

      public int getGoBackInvocations()
      Returns the number of times android.webkit.WebView#goBack() was invoked.
    • getGoForwardInvocations

      public int getGoForwardInvocations()
      Returns the number of times android.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 of WebView.HitTestResult.
    • setHitTestResult

      public void setHitTestResult(WebView.HitTestResult hitTestResult)
      Sets the WebView.HitTestResult that should be returned from getHitTestResult().
    • reset

      @Resetter public static void reset()
    • setWebContentsDebuggingEnabled

      @Implementation(minSdk=19) public static void setWebContentsDebuggingEnabled(boolean enabled)
    • setBackgroundColor

      @Implementation protected void setBackgroundColor(int backgroundColor)
      Sets the 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.

    • getBackgroundColor

      public int getBackgroundColor()
      Returns the Color int that has been set by setBackgroundColor(int).
    • setDownloadListener

      @Implementation protected void setDownloadListener(DownloadListener downloadListener)
    • getDownloadListener

      public DownloadListener getDownloadListener()