@Test public void testOnDownloadProgress() { final String torrentFile = "file"; final int progress = 42; LocalBroadcaster localBroadcaster = new LocalBroadcaster(RuntimeEnvironment.application); localBroadcaster.onDownloadProgress(torrentFile, progress); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application); ShadowLocalBroadcastManager shadowLocalBroadcastManager = Shadows.shadowOf(localBroadcastManager); List<Intent> broadcastIntents = shadowLocalBroadcastManager.getSentBroadcastIntents(); assertThat(broadcastIntents.size()).isEqualTo(1); Intent referenceBroadcast = new DownloadProgressBroadcast() .setTorrentFile(torrentFile) .setProgress(progress) .createIntent(); assertThat(broadcastIntents.get(0).equals(referenceBroadcast)).isTrue(); }
@Test public void testOnDownloadEnd() { final String torrentFile = "file"; final int downloadState = 42; LocalBroadcaster localBroadcaster = new LocalBroadcaster(RuntimeEnvironment.application); localBroadcaster.onDownloadEnd(torrentFile, downloadState); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application); ShadowLocalBroadcastManager shadowLocalBroadcastManager = Shadows.shadowOf(localBroadcastManager); List<Intent> broadcastIntents = shadowLocalBroadcastManager.getSentBroadcastIntents(); assertThat(broadcastIntents.size()).isEqualTo(1); Intent referenceBroadcast = new DownloadEndBroadcast() .setTorrentFile(torrentFile) .setDownloadState(downloadState) .createIntent(); assertThat(broadcastIntents.get(0).equals(referenceBroadcast)).isTrue(); }
@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); }
@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()); }
@Test public void testFullscreenBackPressed() { Intent intent = new Intent(); WebItem webItem = new TestWebItem() { @Override public String getUrl() { return "http://example.com"; } @Override public String getId() { return "1"; } }; intent.putExtra(ItemActivity.EXTRA_ITEM, webItem); controller.withIntent(intent).create().start().resume().visible(); ShadowLocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); activity.onBackPressed(); assertThat(activity).isNotFinishing(); activity.onBackPressed(); assertThat(activity).isFinishing(); }
@Test public void testRegisterGCMStartsBroadcastManagerAndIntentService() throws ManifestValidator.InvalidManifestException { registration.registerGCM(context, "senderId", registrationListener); Intent expectedIntent = new Intent(context, GCMRegistrationIntentService.class); Intent startedIntent = shadowOf(RuntimeEnvironment.application).getNextStartedService(); assertThat(startedIntent.getComponent(), equalTo(expectedIntent.getComponent())); Bundle extras = startedIntent.getExtras(); assertEquals("senderId", extras.getString("gcm_defaultSenderId")); ShadowLocalBroadcastManager localBroadcastManager = (ShadowLocalBroadcastManager) Shadow.extract(LocalBroadcastManager.getInstance(context)); List<ShadowLocalBroadcastManager.Wrapper> receivers = localBroadcastManager.getRegisteredBroadcastReceivers(); assertEquals(1, receivers.size()); }
private void sendLocalProgressBroadcast(String torrentFile, int progress) { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application); ShadowLocalBroadcastManager shadowLocalBroadcastManager = Shadows.shadowOf(localBroadcastManager); shadowLocalBroadcastManager.sendBroadcast( new DownloadProgressBroadcast() .setTorrentFile(torrentFile) .setProgress(progress) .createIntent()); }
private void sendLocalEndBroadcast(String torrentFile, int downloadState) { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application); ShadowLocalBroadcastManager shadowLocalBroadcastManager = Shadows.shadowOf(localBroadcastManager); shadowLocalBroadcastManager.sendBroadcast( new DownloadEndBroadcast() .setTorrentFile(torrentFile) .setDownloadState(downloadState) .createIntent()); }
@Test public void testOnDownloadStart() { final String torrentFile = "file"; LocalBroadcaster localBroadcaster = new LocalBroadcaster(RuntimeEnvironment.application); localBroadcaster.onDownloadStart(torrentFile); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application); ShadowLocalBroadcastManager shadowLocalBroadcastManager = Shadows.shadowOf(localBroadcastManager); List<Intent> broadcastIntents = shadowLocalBroadcastManager.getSentBroadcastIntents(); assertThat(broadcastIntents.size()).isEqualTo(1); // TODO not needed, compare to DownloadProgressBroadcast assertThat(broadcastIntents.get(0).getAction()).isEqualTo(BitTorrentIntentConstants.ACTION_BROADCAST_PROGRESS); assertThat(broadcastIntents.get(0).getStringExtra(BitTorrentIntentConstants.EXTRA_TORRENT_FILE)).isEqualToIgnoringCase(torrentFile); assertThat(broadcastIntents.get(0).getIntExtra(BitTorrentIntentConstants.EXTRA_DOWNLOAD_PROGRESS, -1)).isEqualTo(0); }
@SuppressLint("NewApi") @Test public void testFullscreenMenu() { verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture()); callback.getValue().onResponse("<div>content</div>"); ShadowLocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); activity.findViewById(R.id.button_more).performClick(); shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_font_options)); assertThat(fragment.getFragmentManager()) .hasFragmentWithTag(PopupSettingsFragment.class.getName()); }
@Test public void testFullscreen() { ShadowLocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); assertThat((View) activity.findViewById(R.id.control_switcher)).isVisible(); shadowOf(activity).recreate(); assertThat((View) activity.findViewById(R.id.control_switcher)).isVisible(); activity.findViewById(R.id.button_exit).performClick(); assertThat((View) activity.findViewById(R.id.control_switcher)).isNotVisible(); }
@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((View) activity.findViewById(R.id.button_next)).isDisabled(); // with results shadowWebView.setFindCount(1); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) 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((View) activity.findViewById(R.id.button_next)).isDisabled(); assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.no_matches)); }
@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); }
@Config(shadows = {ShadowFloatingActionButton.class}) @Test public void testFullscreen() { Intent intent = new Intent(); WebItem webItem = new TestWebItem() { @Override public String getUrl() { return "http://example.com"; } @Override public String getId() { return "1"; } }; intent.putExtra(ItemActivity.EXTRA_ITEM, webItem); controller.withIntent(intent).create().start().resume().visible(); ShadowFloatingActionButton shadowFab = (ShadowFloatingActionButton) ShadowExtractor .extract(activity.findViewById(R.id.reply_button)); assertTrue(shadowFab.isVisible()); ShadowLocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); assertFalse(shadowFab.isVisible()); ShadowLocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, false)); assertTrue(shadowFab.isVisible()); }