Bug 1417255 - Test when PAW badge should be hidden. r?maliu draft
authorNevin Chen <cnevinchen@gmail.com>
Sun, 07 Jan 2018 13:46:11 +0800
changeset 717055 7c27f4df258dfc9199785b0e124d53c0f1fde136
parent 717054 bc54ec4001e5cf1776417abb8286e4a7aef39257
child 745134 fde17d9fcbf36e651d5baeca78d2d2b4fbf75a39
push id94544
push userbmo:cnevinchen@gmail.com
push dateMon, 08 Jan 2018 05:17:15 +0000
reviewersmaliu
bugs1417255
milestone59.0a1
Bug 1417255 - Test when PAW badge should be hidden. r?maliu MozReview-Commit-ID: AxzNswWSxFr
mobile/android/app/src/androidTest/java/org/mozilla/gecko/PwaBadgeTest.java
mobile/android/app/src/espresso/assets/pwa_test_site/badge_hide.html
--- a/mobile/android/app/src/androidTest/java/org/mozilla/gecko/PwaBadgeTest.java
+++ b/mobile/android/app/src/androidTest/java/org/mozilla/gecko/PwaBadgeTest.java
@@ -12,16 +12,17 @@ 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.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;
@@ -29,50 +30,67 @@ import static org.mozilla.gecko.toolbar.
 
 @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";
 
     @Rule
     public ActivityTestRule<BrowserApp> activityRule = new ActivityTestRule(BrowserApp.class);
     private CountingIdlingResource countingResource;
     private String url = null;
 
     @Before
     public void setup() {
         countingResource = new CountingIdlingResource("PWA");
 
-        url = adjustUrl(PAGE_BADGE_DISPLAY);
         // 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 shouldShowBadge() {
-        // Enter url
+    public void testPwaBadgeDisplay() {
+        // 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());
 
         activityRule.getActivity().setIdlingResource(countingResource);
         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)));
 
+
+        // Should hide PWA badge
+        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.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());
+
+
     }
 
     @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());
 
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/espresso/assets/pwa_test_site/badge_hide.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <title> test pwa</title>
+</head>
+<body>
+TEST
+</body>
+</html>
+