Search in sources :

Example 51 with WebView

use of android.webkit.WebView in project materialistic by hidroh.

the class WebFragmentLocalTest method testComment.

@Test
public void testComment() {
    TestItem item = new TestItem() {

        @NonNull
        @Override
        public String getType() {
            return COMMENT_TYPE;
        }

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public String getUrl() {
            return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
        }

        @Override
        public String getText() {
            return "comment";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume().visible();
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("comment");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 52 with WebView

use of android.webkit.WebView in project materialistic by hidroh.

the class WebFragmentTest method testAdBlocker.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Test
public void testAdBlocker() {
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    WebViewClient client = shadowOf(webView).getWebViewClient();
    assertNull(client.shouldInterceptRequest(webView, "http://google.com"));
    assertNull(client.shouldInterceptRequest(webView, "http://google.com"));
    assertNotNull(client.shouldInterceptRequest(webView, "http://page2.g.doubleclick.net"));
    assertNotNull(client.shouldInterceptRequest(webView, "http://page2.g.doubleclick.net"));
}
Also used : WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 53 with WebView

use of android.webkit.WebView in project materialistic by hidroh.

the class WebFragmentTest method testProgressChanged.

@Test
public void testProgressChanged() {
    ProgressBar progressBar = (ProgressBar) activity.findViewById(R.id.progress);
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    shadowOf(webView).getWebChromeClient().onProgressChanged(webView, 50);
    assertThat(progressBar).isVisible();
    shadowOf(webView).getWebChromeClient().onProgressChanged(webView, 100);
    assertThat(progressBar).isNotVisible();
}
Also used : WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) ProgressBar(android.widget.ProgressBar) Test(org.junit.Test)

Example 54 with WebView

use of android.webkit.WebView in project materialistic by hidroh.

the class OfflineWebActivityTest method testLoadUrl.

@Test
public void testLoadUrl() {
    activity = controller.withIntent(new Intent().putExtra(OfflineWebActivity.EXTRA_URL, "http://example.com")).create().get();
    assertThat(activity.getTitle()).contains("http://example.com");
    WebView 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");
    // web view title
    assertThat(activity.getTitle()).isNullOrEmpty();
    shadowWebView.getWebChromeClient().onProgressChanged(webView, 50);
    assertThat(progress).isVisible();
    shadowWebView.getWebChromeClient().onProgressChanged(webView, 100);
    assertThat(progress).isNotVisible();
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) ShadowWebView(org.robolectric.shadows.ShadowWebView) WebView(android.webkit.WebView) ShadowNestedScrollView(io.github.hidroh.materialistic.test.shadow.ShadowNestedScrollView) ShadowWebView(org.robolectric.shadows.ShadowWebView) View(android.view.View) WebView(android.webkit.WebView) Test(org.junit.Test)

Example 55 with WebView

use of android.webkit.WebView in project materialistic by hidroh.

the class ReadabilityFragmentTest method testFontMenu.

@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();
}
Also used : WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Test(org.junit.Test)

Aggregations

WebView (android.webkit.WebView)328 WebViewClient (android.webkit.WebViewClient)108 View (android.view.View)82 WebSettings (android.webkit.WebSettings)48 Intent (android.content.Intent)42 SuppressLint (android.annotation.SuppressLint)37 WebChromeClient (android.webkit.WebChromeClient)37 TextView (android.widget.TextView)28 DialogInterface (android.content.DialogInterface)23 LinearLayout (android.widget.LinearLayout)23 ImageView (android.widget.ImageView)22 Bitmap (android.graphics.Bitmap)19 AlertDialog (android.app.AlertDialog)17 Test (org.junit.Test)15 Uri (android.net.Uri)12 Bundle (android.os.Bundle)12 Handler (android.os.Handler)11 WebResourceRequest (android.webkit.WebResourceRequest)11 Drawable (android.graphics.drawable.Drawable)10 Button (android.widget.Button)10