Bug 1417255 - Add test when PAW badge should be displayed or hidden. r?maliu
MozReview-Commit-ID: CZFym4atKV5
--- a/mobile/android/app/src/androidTest/java/org/mozilla/gecko/PwaBadgeTest.java
+++ b/mobile/android/app/src/androidTest/java/org/mozilla/gecko/PwaBadgeTest.java
@@ -1,31 +1,110 @@
package org.mozilla.gecko;
import android.support.annotation.Keep;
+import android.support.test.espresso.IdlingRegistry;
+import android.support.test.espresso.idling.CountingIdlingResource;
+import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.action.ViewActions.click;
+import static android.support.test.espresso.action.ViewActions.pressImeActionButton;
+import static android.support.test.espresso.action.ViewActions.replaceText;
+import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static android.support.test.espresso.matcher.ViewMatchers.withParent;
+import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.is;
+import static org.mozilla.gecko.toolbar.PageActionLayout.PageAction.UUID_PAGE_ACTION_PWA;
@EspressoOnly
@Keep
@RunWith(AndroidJUnit4.class)
public class PwaBadgeTest {
+ private static final String PAGE_WEB = "https://pwa.rocks";
+ private static final String PAGE_BADGE_DISPLAY = "badge_display.html";
+ private static final String PAGE_BADGE_HIDE = "badge_hide.html";
+ private static final String IDLE_RESOURCE_PWA = "IDLE_RESOURCE_PWA";
@Rule
public ActivityTestRule<BrowserApp> activityRule = new ActivityTestRule<>(BrowserApp.class);
+ private CountingIdlingResource countingResource;
+ private String url = null;
+
+ @Before
+ public void setup() {
+ countingResource = new CountingIdlingResource("IDLE_RESOURCE_PWA");
+
+ // To prove that the test fails, omit this call:
+ IdlingRegistry.getInstance().register(countingResource);
+ }
+
+ private String adjustUrl(String path) {
+ return "resource://android/assets/pwa_test_site/" + path;
+
+ }
+
@Test
- public void simpleTest() {
+ public void shouldHidePwaBadge() {
+ url = adjustUrl(PAGE_BADGE_HIDE);
+
+ onView(withId(R.id.url_bar_title_scroll_view)).perform(click());
+ onView(withId(R.id.url_edit_text)).perform(click(), replaceText(url), pressImeActionButton());
- onView(withId(R.id.url_bar_title_scroll_view)).check(matches(isDisplayed()));
+ onView(withId(R.id.page_action_layout)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
+
+ onView(allOf(
+ withParent(withId(R.id.page_action_layout)),
+ withTagValue(is((Object) UUID_PAGE_ACTION_PWA))))
+ .check(doesNotExist());
+
}
+ @Test
+ public void shouldDisplayPwaBadge() {
+ // Should display PWA badge
+ url = adjustUrl(PAGE_BADGE_DISPLAY);
+
+ onView(withId(R.id.url_bar_title_scroll_view)).perform(click());
+ onView(withId(R.id.url_edit_text)).perform(click(), replaceText(url), pressImeActionButton());
+
+ countingResource.increment();
+ activityRule.getActivity().setPwaBadgeListener(new BrowserApp.PwaBadgeListener() {
+ @Override
+ public void onPwaBadgeChange() {
+ countingResource.decrement();
+ }
+ });
+ onView(withId(R.id.page_action_layout)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
+
+ onView(allOf(
+ withParent(withId(R.id.page_action_layout)),
+ withTagValue(is((Object) UUID_PAGE_ACTION_PWA))))
+ .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
+
+
+ }
+
+ @After
+ public void tearDown() {
+ onView(withId(R.id.counter_box)).perform(click());
+ onView(withId(R.id.tabs_menu)).perform(click());
+ onView(withText(R.string.close_all_tabs)).perform(click());
+
+ IdlingRegistry.getInstance().unregister(countingResource);
+
+ }
}