Search in sources :

Example 11 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem in project materialistic by hidroh.

the class BaseListActivityTest method testSelectItemStartActionView.

@Test
public void testSelectItemStartActionView() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.browser", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_external), true).commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
Also used : Intent(android.content.Intent) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 12 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem in project materialistic by hidroh.

the class ItemActivityTest method testVolumeNavigation.

@Test
public void testVolumeNavigation() {
    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();
    activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
    verify(keyDelegate).setScrollable(any(Scrollable.class), any(AppBarLayout.class));
    verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class));
    activity.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP));
    verify(keyDelegate).onKeyUp(anyInt(), any(KeyEvent.class));
    activity.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
    verify(keyDelegate).onKeyLongPress(anyInt(), any(KeyEvent.class));
}
Also used : KeyEvent(android.view.KeyEvent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Intent(android.content.Intent) AppBarLayout(android.support.design.widget.AppBarLayout) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 13 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem in project materialistic by hidroh.

the class BaseListActivityTest method testSelectItemOpenExternal.

@Test
public void testSelectItemOpenExternal() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_external), true).commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
Also used : Intent(android.content.Intent) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 14 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem in project materialistic by hidroh.

the class BaseListActivityTest method testSelectItemOpenWeb.

@Test
public void testSelectItemOpenWeb() {
    activity.onItemSelected(new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    Intent actual = shadowOf(activity).getNextStartedActivity();
    assertEquals(ItemActivity.class.getName(), actual.getComponent().getClassName());
}
Also used : Intent(android.content.Intent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 15 with TestWebItem

use of io.github.hidroh.materialistic.test.TestWebItem in project materialistic by hidroh.

the class BaseListActivityTest method testSelectItemOpenChooser.

@Test
public void testSelectItemOpenChooser() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://news.ycombinator.com/item?id=1")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://news.ycombinator.com/item?id=1")), ShadowResolveInfo.newResolveInfo("label", "com.android.browser", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_external), true).commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://news.ycombinator.com/item?id=1";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_CHOOSER);
}
Also used : Intent(android.content.Intent) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Aggregations

TestWebItem (io.github.hidroh.materialistic.test.TestWebItem)15 Test (org.junit.Test)13 Intent (android.content.Intent)10 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)10 WebItem (io.github.hidroh.materialistic.data.WebItem)6 RobolectricPackageManager (org.robolectric.res.builder.RobolectricPackageManager)3 ConnectivityManager (android.net.ConnectivityManager)2 Bundle (android.os.Bundle)2 KeyEvent (android.view.KeyEvent)2 WebView (android.webkit.WebView)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 TestReadabilityActivity (io.github.hidroh.materialistic.test.TestReadabilityActivity)2 Before (org.junit.Before)2 Config (org.robolectric.annotation.Config)2 ShadowWebView (org.robolectric.shadows.ShadowWebView)2 Account (android.accounts.Account)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 Fragment (android.support.v4.app.Fragment)1 BuildConfig (io.github.hidroh.materialistic.BuildConfig)1 ShadowFloatingActionButton (io.github.hidroh.materialistic.test.shadow.ShadowFloatingActionButton)1