@Implementation protected void loadUrl(String url) { loadUrl(url, null); }
public void ensureProviderCreated() { final ClassLoader classLoader = getClass().getClassLoader(); Class<?> webViewProviderClass = getClassNamed("android.webkit.WebViewProvider"); Field mProvider; try {
@Test public void testFontMenu() { verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture()); callback.getValue().onResponse("<div>content</div>"); PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf") .apply(); WebView webView = (WebView) activity.findViewById(R.id.web_view); shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank"); assertThat(shadowOf(webView).getLastLoadDataWithBaseURL().data).contains("DroidSans.ttf"); assertEquals("DroidSans.ttf", Preferences.Theme.getReadabilityTypeface(activity)); controller.pause().stop().destroy(); }
@Test public void testBackPressed() { WebView webView = activity.findViewById(R.id.web_view); shadowOf(webView).getWebViewClient().onPageFinished(webView, "http://example.com"); shadowOf(webView).setCanGoBack(true); assertTrue(activity.fragment.onBackPressed()); shadowOf(webView).setCanGoBack(false); assertFalse(activity.fragment.onBackPressed()); }
@Test public void testWebToggle() { fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_readability)); WebView webView = (WebView) activity.findViewById(R.id.web_view); shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank"); assertThat(shadowOf(webView).getLastLoadedUrl()).isEqualTo("http://example.com/article.html"); }
@Test public void testLoadUrl() { controller = Robolectric.buildActivity(OfflineWebActivity.class, new Intent() .putExtra(OfflineWebActivity.EXTRA_URL, "http://example.com")); activity = controller .create() .get(); assertThat(activity.getTitle()).contains("http://example.com"); WebView webView = activity.findViewById(R.id.web_view); View progress = activity.findViewById(R.id.progress); ShadowWebView shadowWebView = shadowOf(webView); assertThat(shadowWebView.getLastLoadedUrl()) .contains("http://example.com"); shadowWebView.getWebViewClient().onPageFinished(webView, "http://example.com"); assertThat(activity.getTitle()).isNullOrEmpty(); // web view title shadowWebView.getWebChromeClient().onProgressChanged(webView, 50); assertThat(progress).isVisible(); shadowWebView.getWebChromeClient().onProgressChanged(webView, 100); assertThat(progress).isNotVisible(); }
@Test public void testLoadUrl() throws Exception { String url = "http://www.taobao.com"; view.loadUrl(url); WebViewClient client = shadow.getWebViewClient(); client.onPageStarted(webView,url,null); client.onPageFinished(webView,url); WebChromeClient chromeClient = shadow.getWebChromeClient(); chromeClient.onProgressChanged(webView,10); chromeClient.onProgressChanged(webView,100); chromeClient.onReceivedTitle(webView,"test"); }
@Test public void shouldRecordWebChromeClient() { WebChromeClient webChromeClient = new WebChromeClient(); assertThat(shadowOf(webView).getWebChromeClient()).isNull(); webView.setWebChromeClient(webChromeClient); assertThat(shadowOf(webView).getWebChromeClient()).isSameAs(webChromeClient); }
@Test public void shouldRecordWebViewClient() { WebViewClient webViewClient = new WebViewClient(); assertThat(shadowOf(webView).getWebViewClient()).isNull(); webView.setWebViewClient(webViewClient); assertThat(shadowOf(webView).getWebViewClient()).isSameAs(webViewClient); }
@Test public void shouldRecordLastLoadDataWithBaseURL() throws Exception { webView.loadDataWithBaseURL("base/url", "<html><body><h1>Hi</h1></body></html>", "text/html", "utf-8", "history/url"); ShadowWebView.LoadDataWithBaseURL lastLoadData = shadowOf(webView).getLastLoadDataWithBaseURL(); assertThat(lastLoadData.baseUrl).isEqualTo("base/url"); assertThat(lastLoadData.data).isEqualTo("<html><body><h1>Hi</h1></body></html>"); assertThat(lastLoadData.mimeType).isEqualTo("text/html"); assertThat(lastLoadData.encoding).isEqualTo("utf-8"); assertThat(lastLoadData.historyUrl).isEqualTo("history/url"); }
@Implementation protected void goBack() { if (canGoBack()) { goBackInvocations++; // TODO: Delete this when setCanGoBack is deleted, since this creates two different behavior // paths. if (canGoBackIsSet) { return; } history.remove(0); if (!history.isEmpty()) { originalUrl = history.get(0); } } }
@Override public void evaluateJavascript(String script, ValueCallback<String> callback) { super.evaluateJavascript(script, callback); Clog.d(TestUtil.testLogTag, "ShadowCustomClickThroughWebView evaluateJavascript: " + script); if (script.contains("createVastPlayerWithContent")) { Clog.d(TestUtil.testLogTag, "evaluateJavascript createVastPlayerWithContent"); if (!simulateVideoError) { this.getWebViewClient().shouldOverrideUrlLoading(webView, "video://{\"event\":\"adReady\",\"params\":{\"creativeUrl\":\"http://vcdn.adnxs.com/p/creative-video/05/64/6d/99/05646d99.webm\",\"duration\":96000}}"); } else { this.getWebViewClient().shouldOverrideUrlLoading(webView, "video://{\"event\":\"video-error\",\"params\":{}}"); } if (simulateDelayedVideoError) { new Handler().postDelayed(new Runnable() { @Override public void run() { getWebViewClient().shouldOverrideUrlLoading(webView, "video://{\"event\":\"video-error\",\"params\":{}}"); } }, 1000); } if (simulateVideoAdClick) { new Handler().postDelayed(new Runnable() { @Override public void run() { getWebViewClient().shouldOverrideUrlLoading(webView, "www.appnexus.com"); } }, 2000); } } }
assertThat(shadowNotification.getMax()).isEqualTo(104); // self + 2 kids + readability + web shadowOf(adapter.syncDelegate.mWebView).getWebChromeClient() .onProgressChanged(adapter.syncDelegate.mWebView, 100);
@Test public void testParseFailed() { assertThat(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_font_options)).isNotVisible(); assertThat((View) activity.findViewById(R.id.progress)).isVisible(); verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture()); callback.getValue().onResponse(null); reset(readabilityClient); assertThat(ShadowToast.getTextOfLatestToast()) .contains(activity.getString(R.string.readability_failed)); WebView webView = (WebView) activity.findViewById(R.id.web_view); shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank"); assertThat(ShadowWebView.getLastGlobalLoadedUrl()) .contains("http://example.com/article.html"); assertThat(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_font_options)).isNotVisible(); controller.pause().stop().destroy(); }
@Test public void LoadReceipt() { activityController.start(); activityController.resume(); Activity activity = (Activity)activityController.get(); WebView receiptView = (WebView)activity.findViewById(R.id.imageView); ShadowWebView.LoadDataWithBaseURL loadedData = shadowOf(receiptView).getLastLoadDataWithBaseURL(); assertEquals("", loadedData.baseUrl); assertEquals("text/html", loadedData.mimeType); assertEquals("utf-8", loadedData.encoding); assertNull(loadedData.historyUrl); assertTrue(loadedData.data.contains("src=\"file://receipt\"")); } }
@Implementation protected void goBack() { if (canGoBack()) { goBackInvocations++; // TODO: Delete this when setCanGoBack is deleted, since this creates two different behavior // paths. if (canGoBackIsSet) { return; } history.remove(0); if (!history.isEmpty()) { originalUrl = history.get(0); } } }
@Override public void evaluateJavascript(String script, ValueCallback<String> callback) { super.evaluateJavascript(script, callback); Clog.d(TestUtil.testLogTag, "ShadowCustomWebView evaluateJavascript"); if (script.contains("createVastPlayerWithContent")) { Clog.d(TestUtil.testLogTag, "evaluateJavascript createVastPlayerWithContent"); if (!simulateVideoError) { this.getWebViewClient().shouldOverrideUrlLoading(webView, "video://{\"event\":\"adReady\",\"params\":{\"creativeUrl\":\"http://vcdn.adnxs.com/p/creative-video/05/64/6d/99/05646d99.webm\",\"duration\":96000}}"); } else { this.getWebViewClient().shouldOverrideUrlLoading(webView, "video://{\"event\":\"video-error\",\"params\":{}}"); } if (simulateDelayedVideoError) { new Handler().postDelayed(new Runnable() { @Override public void run() { getWebViewClient().shouldOverrideUrlLoading(webView, "video://{\"event\":\"video-error\",\"params\":{}}"); } }, 1000); } } }
@Override public void loadUrl(String url) { super.loadUrl(url); lastGlobalLoadedUrl = url; }
@Test public void testParseAndBind() { assertThat((View) activity.findViewById(R.id.progress)).isVisible(); verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture()); callback.getValue().onResponse("<div>content</div>"); WebView webView = (WebView) activity.findViewById(R.id.web_view); shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank"); assertThat(shadowOf(webView).getLastLoadDataWithBaseURL().data).contains("content"); shadowOf(activity).recreate(); webView = (WebView) activity.findViewById(R.id.web_view); shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank"); assertThat(shadowOf(webView).getLastLoadDataWithBaseURL().data).contains("content"); controller.pause().stop().destroy(); }
@HiddenApi @Implementation public void ensureProviderCreated() { final ClassLoader classLoader = getClass().getClassLoader(); Class<?> webViewProviderClass = getClassNamed("android.webkit.WebViewProvider"); Field mProvider; try {