Search in sources :

Example 1 with ShadowWebView

use of org.robolectric.shadows.ShadowWebView in project materialistic by hidroh.

the class WebFragmentLocalTest method testMenu.

@Test
public void testMenu() {
    TestWebItem item = new TestWebItem() {

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

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

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

        @Override
        public String getDisplayedTitle() {
            return "Ask HN";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume().visible();
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    listener.getValue().onResponse(new TestItem() {

        @Override
        public String getText() {
            return "text";
        }
    });
    Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName());
    assertTrue(fragment.hasOptionsMenu());
    fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options));
    assertNotNull(ShadowDialog.getLatestDialog());
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf").apply();
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("text").contains("DroidSans.ttf");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) Fragment(android.support.v4.app.Fragment) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 2 with ShadowWebView

use of org.robolectric.shadows.ShadowWebView 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 3 with ShadowWebView

use of org.robolectric.shadows.ShadowWebView 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 4 with ShadowWebView

use of org.robolectric.shadows.ShadowWebView in project materialistic by hidroh.

the class WebFragmentLocalTest method testStory.

@Test
public void testStory() {
    TestWebItem item = new TestWebItem() {

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

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

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

        @Override
        public String getDisplayedTitle() {
            return "Ask HN";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume().visible();
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    listener.getValue().onResponse(new TestItem() {

        @Override
        public String getText() {
            return "text";
        }
    });
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("text");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Aggregations

Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 Test (org.junit.Test)4 ShadowWebView (org.robolectric.shadows.ShadowWebView)4 TestItem (io.github.hidroh.materialistic.test.TestItem)3 TestWebItem (io.github.hidroh.materialistic.test.TestWebItem)2 Fragment (android.support.v4.app.Fragment)1 View (android.view.View)1 ShadowNestedScrollView (io.github.hidroh.materialistic.test.shadow.ShadowNestedScrollView)1 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)1