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);
}
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);
}
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());
}
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());
}
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));
}
Aggregations