AirshipWebViewClient extends WebViewClient { @Override @CallSuper public void onPageFinished(@Nullable final WebView view, final @Nullable String url) { if (view == null) { return; } if (!isAllowed(url)) { Logger.debug("AirshipWebViewClient - %s is not an allowed URL. Airship Javascript interface will not be accessible.", url); return; } JavaScriptEnvironment.Builder environment = extendJavascriptEnvironment(JavaScriptEnvironment.newBuilder(), view); Cancelable cancelable = nativeBridge.loadJavaScriptEnvironment( view.getContext(), environment.build(), new WebViewJavaScriptExecutor(view)); pendingNativeBridgeLoads.put(view, cancelable); } AirshipWebViewClient();  AirshipWebViewClient(@NonNull ActionRunRequestFactory requestFactory); @VisibleForTesting  AirshipWebViewClient(@NonNull NativeBridge nativeBridge); void setActionCompletionCallback(@Nullable ActionCompletionCallback actionCompletionCallback); @CallSuper @Override boolean shouldOverrideUrlLoading(@NonNull WebView webView, @Nullable String url); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void setFaviconEnabled(boolean enabled); @CallSuper @Override @Nullable WebResourceResponse shouldInterceptRequest(@NonNull WebView webView, @NonNull String url); @CallSuper @Override @SuppressLint("NewApi") @Nullable WebResourceResponse shouldInterceptRequest(@NonNull WebView webView, @NonNull WebResourceRequest request); @CallSuper @Override void onLoadResource(@NonNull WebView webView, @Nullable String url); @Override @CallSuper void onPageFinished(@Nullable final WebView view, final @Nullable String url); @CallSuper @Override void onPageStarted(@NonNull WebView view, @Nullable String url, @Nullable Bitmap favicon); @CallSuper @Override void onReceivedHttpAuthRequest(@NonNull WebView view, @NonNull HttpAuthHandler handler, @Nullable String host,
                                          @Nullable String realm); void addAuthRequestCredentials(@NonNull String expectedAuthHost, @Nullable String username, @Nullable String password); void removeAuthRequestCredentials(@NonNull String expectedAuthHost);  }
@Test @SuppressLint("NewApi") public void testOnPageFinished() { client.onPageFinished(webView, webViewUrl); ArgumentCaptor<JavaScriptExecutor> argument = ArgumentCaptor.forClass(JavaScriptExecutor.class); verify(nativeBridge).loadJavaScriptEnvironment( any(Context.class), any(JavaScriptEnvironment.class), argument.capture()); argument.getValue().executeJavaScript("test"); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { verify(webView).loadUrl("javascript:test"); } else { verify(webView).evaluateJavascript("test", null); } }
@Test @SuppressLint("NewApi") public void testOnPageFinishedNotAllowed() { webViewUrl = "http: client.onPageFinished(webView, webViewUrl); verifyZeroInteractions(nativeBridge); }