Search in sources :

Example 1 with ShadowWebView

use of io.github.hidroh.materialistic.test.shadow.ShadowWebView in project materialistic by hidroh.

the class WebFragmentTest method testRefresh.

@Test
public void testRefresh() {
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    ShadowWebView.lastGlobalLoadedUrl = null;
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(activity.findViewById(R.id.web_view));
    shadowWebView.setProgress(20);
    activity.findViewById(R.id.button_refresh).performClick();
    assertThat(ShadowWebView.getLastGlobalLoadedUrl()).isNullOrEmpty();
    shadowWebView.setProgress(100);
    activity.findViewById(R.id.button_refresh).performClick();
    assertThat(ShadowWebView.getLastGlobalLoadedUrl()).isEqualTo(ShadowWebView.RELOADED);
}
Also used : ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Intent(android.content.Intent) Test(org.junit.Test)

Example 2 with ShadowWebView

use of io.github.hidroh.materialistic.test.shadow.ShadowWebView in project materialistic by hidroh.

the class WebFragmentTest method testWebControls.

@SuppressLint("NewApi")
@Test
public void testWebControls() {
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(activity.findViewById(R.id.web_view));
    activity.findViewById(R.id.button_more).performClick();
    shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_in));
    assertThat(shadowWebView.getZoomDegree()).isEqualTo(1);
    activity.findViewById(R.id.button_more).performClick();
    shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_out));
    assertThat(shadowWebView.getZoomDegree()).isEqualTo(0);
    activity.findViewById(R.id.button_forward).performClick();
    assertThat(shadowWebView.getPageIndex()).isEqualTo(1);
    activity.findViewById(R.id.button_back).performClick();
    assertThat(shadowWebView.getPageIndex()).isEqualTo(0);
}
Also used : ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Intent(android.content.Intent) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 3 with ShadowWebView

use of io.github.hidroh.materialistic.test.shadow.ShadowWebView in project materialistic by hidroh.

the class WebFragmentTest method testDownloadPDF.

@Test
public void testDownloadPDF() {
    ResolveInfo resolverInfo = new ResolveInfo();
    resolverInfo.activityInfo = new ActivityInfo();
    resolverInfo.activityInfo.applicationInfo = new ApplicationInfo();
    resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName();
    resolverInfo.activityInfo.name = ListActivity.class.getName();
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com/file.pdf")), resolverInfo);
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(webView);
    shadowWebView.getDownloadListener().onDownloadStart("http://example.com/file.pdf", "", "", "", 0l);
    assertThat(activity.findViewById(R.id.empty)).isVisible();
    activity.findViewById(R.id.download_button).performClick();
    assertNotNull(shadowOf(activity).getNextStartedActivity());
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Test(org.junit.Test)

Example 4 with ShadowWebView

use of io.github.hidroh.materialistic.test.shadow.ShadowWebView in project materialistic by hidroh.

the class WebFragmentTest method testFullScroll.

@Test
public void testFullScroll() {
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(activity.findViewById(R.id.web_view));
    WebFragment fragment = (WebFragment) activity.getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName());
    fragment.scrollToTop();
    assertEquals(0, shadowWebView.getScrollY());
    fragment.scrollToNext();
    assertEquals(1, shadowWebView.getScrollY());
    fragment.scrollToPrevious();
    assertEquals(0, shadowWebView.getScrollY());
}
Also used : ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Intent(android.content.Intent) Test(org.junit.Test)

Example 5 with ShadowWebView

use of io.github.hidroh.materialistic.test.shadow.ShadowWebView in project materialistic by hidroh.

the class WebFragmentTest method testSearch.

@Test
public void testSearch() {
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    activity.findViewById(R.id.button_find).performClick();
    ViewSwitcher controlSwitcher = (ViewSwitcher) activity.findViewById(R.id.control_switcher);
    assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(1);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(activity.findViewById(R.id.web_view));
    // no query
    EditText editText = (EditText) activity.findViewById(R.id.edittext);
    shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null);
    assertThat(activity.findViewById(R.id.button_next)).isDisabled();
    // with results
    shadowWebView.setFindCount(1);
    editText.setText("abc");
    shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null);
    assertThat(activity.findViewById(R.id.button_next)).isEnabled();
    activity.findViewById(R.id.button_next).performClick();
    assertThat(shadowWebView.getFindIndex()).isEqualTo(1);
    activity.findViewById(R.id.button_clear).performClick();
    assertThat(editText).isEmpty();
    assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(0);
    // with no results
    shadowWebView.setFindCount(0);
    editText.setText("abc");
    shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null);
    assertThat(activity.findViewById(R.id.button_next)).isDisabled();
    assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.no_matches));
}
Also used : EditText(android.widget.EditText) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Intent(android.content.Intent) ViewSwitcher(android.widget.ViewSwitcher) Test(org.junit.Test)

Aggregations

Intent (android.content.Intent)5 ShadowWebView (io.github.hidroh.materialistic.test.shadow.ShadowWebView)5 Test (org.junit.Test)5 SuppressLint (android.annotation.SuppressLint)1 ActivityInfo (android.content.pm.ActivityInfo)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 WebView (android.webkit.WebView)1 EditText (android.widget.EditText)1 ViewSwitcher (android.widget.ViewSwitcher)1 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)1 RobolectricPackageManager (org.robolectric.res.builder.RobolectricPackageManager)1