From 3fb4e96b0deb719658a8b86adce5d6b5ea8c9f42 Mon Sep 17 00:00:00 2001 From: Salvador Martinez Date: Fri, 29 Jul 2016 09:50:56 -0700 Subject: [PATCH] Tests for launch support on default feature Includes some espresso tests to ensure that the proper tab is selected when you attempt to launch settings. Bug: 30233920 Change-Id: I171293114bd84b064b333091fcf2394d44debed5 (cherry picked from commit d1ef20beaa3c69e038860fd610f076892d428da2) --- tests/app/Android.mk | 5 + tests/app/AndroidManifest.xml | 4 +- .../dashboard/TabSelectionOnLaunchTest.java | 108 ++++++++++++++++++ tests/unit/Android.mk | 5 +- 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 tests/app/src/com/android/settings/dashboard/TabSelectionOnLaunchTest.java diff --git a/tests/app/Android.mk b/tests/app/Android.mk index bb31539d4ad..cd1338438db 100644 --- a/tests/app/Android.mk +++ b/tests/app/Android.mk @@ -7,6 +7,11 @@ LOCAL_CERTIFICATE := platform LOCAL_JAVA_LIBRARIES := android.test.runner bouncycastle +LOCAL_STATIC_JAVA_LIBRARIES := \ + android-support-test \ + mockito-target \ + espresso-core + # Include all test java files. LOCAL_SRC_FILES := $(call all-java-files-under, src) diff --git a/tests/app/AndroidManifest.xml b/tests/app/AndroidManifest.xml index 2ef96cfcc64..1c507004ebe 100644 --- a/tests/app/AndroidManifest.xml +++ b/tests/app/AndroidManifest.xml @@ -51,9 +51,9 @@ - + android:label="Settings Test Cases"> mActivityRule = + new ActivityTestRule<>(Settings.class, true, false); + + private final int FLAG_RESTART = Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK; + private final String ARG_SELECT_SUPPORT_TAB = "SUPPORT"; + private final String ARG_SELECT_FAKE_TAB = "NOT_SUPPORT"; + + @Test + /* cold start for settings app with correct flags and extra always selects support tab */ + public void test_ColdStartWithCorrectArgsCorrectFlags_SupportSelected() { + launchSettingsWithFlags(ARG_SELECT_SUPPORT_TAB, FLAG_RESTART); + verifySupportSelected(); + } + + @Test + /* cold start with correct flags and wrong extra defaults to all tab */ + public void test_ColdStartWithWrongExtra_DoesNotSelectSupport() { + launchSettingsWithFlags(ARG_SELECT_FAKE_TAB, FLAG_RESTART); + verifySupportNotSelected(); + } + + @Test + /* warm start from elsewhere in settings with wrong flags does not select support */ + public void test_WarmStartSummarySelectedCorrectExtraWrongFlags_DoesNotSelectSupport() { + InstrumentationRegistry.getContext(). + startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS)); + launchSettingsNoFlags(ARG_SELECT_SUPPORT_TAB); + verifySupportNotSelected(); + } + + @Test + /* warm start from elsewhere in settings with with wrong flags & extra does not select support*/ + public void test_WarmStartSummarySelectedWrongExtraWrongFlags_DoesNotSelectSupport() { + InstrumentationRegistry.getContext(). + startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS)); + launchSettingsNoFlags(ARG_SELECT_FAKE_TAB); + verifySupportNotSelected(); + } + + @Test + /* settings does not crash on null string */ + public void test_DoesNotCrashOnNullExtra_DoesNotSelectSupport() { + launchSettingsWithFlags(null, FLAG_RESTART); + verifySupportNotSelected(); + } + + private void verifySupportNotSelected() { + onView(withText(mActivityRule.getActivity().getApplicationContext(). + getString(com.android.settings.R.string.page_tab_title_support))). + check(matches(not(isSelected()))); + } + + private void verifySupportSelected() { + onView(withText(mActivityRule.getActivity().getApplicationContext(). + getString(com.android.settings.R.string.page_tab_title_support))). + check(matches(isSelected())); + } + + private void launchSettingsWithFlags(String extra, int flags) { + Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS); + intent.setFlags(flags); + intent.putExtra(DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB, extra); + mActivityRule.launchActivity(intent); + } + + private void launchSettingsNoFlags(String extra) { + Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS); + intent.putExtra(DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB, extra); + mActivityRule.launchActivity(intent); + } +} \ No newline at end of file diff --git a/tests/unit/Android.mk b/tests/unit/Android.mk index 3ba4606e6e3..5b20173bbbc 100644 --- a/tests/unit/Android.mk +++ b/tests/unit/Android.mk @@ -7,7 +7,10 @@ LOCAL_CERTIFICATE := platform LOCAL_JAVA_LIBRARIES := android.test.runner -LOCAL_STATIC_JAVA_LIBRARIES := android-support-test mockito-target +LOCAL_STATIC_JAVA_LIBRARIES := \ + android-support-test \ + mockito-target \ + espresso-core # Include all test java files. LOCAL_SRC_FILES := $(call all-java-files-under, src)