Bug 960359: (4/4) Update HomeBanner test for new implementation. r=margaret
authorJosh Dover <gerfuls@gmail.com>
Thu, 20 Feb 2014 16:12:04 -0800
changeset 170389 56d5e91fe13e23f216167efb7b2a962aaf151d7e
parent 170388 a6905ad185fa5f8c19a0da32af6da5af3477b5e4
child 170390 38c32cf0123b3a8fac20b9308b913384397a3f99
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersmargaret
bugs960359
milestone30.0a1
Bug 960359: (4/4) Update HomeBanner test for new implementation. r=margaret
mobile/android/base/tests/BaseTest.java
mobile/android/base/tests/components/AboutHomeComponent.java
mobile/android/base/tests/testHomeBanner.java
--- a/mobile/android/base/tests/BaseTest.java
+++ b/mobile/android/base/tests/BaseTest.java
@@ -478,22 +478,22 @@ abstract class BaseTest extends Activity
                 mSolo.clickOnText("(^More$|^Tools$)");
             }
             waitForText(itemName);
             mSolo.clickOnText(itemName);
         }
     }
 
     public final void verifyHomePagerHidden() {
-        final View homePagerView = mSolo.getView(R.id.home_pager);
+        final View homePagerContainer = mSolo.getView(R.id.home_pager_container);
 
         boolean rc = waitForCondition(new Condition() {
             @Override
             public boolean isSatisfied() {
-                return homePagerView.getVisibility() != View.VISIBLE;
+                return homePagerContainer.getVisibility() != View.VISIBLE;
             }
         }, MAX_WAIT_HOME_PAGER_HIDDEN_MS);
 
         if (!rc) {
             mAsserter.ok(rc, "Verify HomePager is hidden", "HomePager is hidden");
         }
     }
 
--- a/mobile/android/base/tests/components/AboutHomeComponent.java
+++ b/mobile/android/base/tests/components/AboutHomeComponent.java
@@ -54,16 +54,20 @@ public class AboutHomeComponent extends 
     // The percentage of the panel to swipe between 0 and 1. This value was set through
     // testing: 0.55f was tested on try and fails on armv6 devices.
     private static final float SWIPE_PERCENTAGE = 0.70f;
 
     public AboutHomeComponent(final UITestContext testContext) {
         super(testContext);
     }
 
+    private View getHomePagerContainer() {
+        return mSolo.getView(R.id.home_pager_container);
+    }
+
     private ViewPager getHomePagerView() {
         return (ViewPager) mSolo.getView(R.id.home_pager);
     }
 
     private View getHomeBannerView() {
         return mSolo.getView(R.id.home_banner);
     }
 
@@ -72,36 +76,42 @@ public class AboutHomeComponent extends 
 
         final int expectedPanelIndex = getPanelIndexForDevice(expectedPanel.ordinal());
         assertEquals("The current HomePager panel is " + expectedPanel,
                      expectedPanelIndex, getHomePagerView().getCurrentItem());
         return this;
     }
 
     public AboutHomeComponent assertNotVisible() {
-        assertFalse("The HomePager is not visible",
-                    getHomePagerView().getVisibility() == View.VISIBLE);
+        assertTrue("The HomePager is not visible",
+                    getHomePagerContainer().getVisibility() != View.VISIBLE ||
+                    getHomePagerView().getVisibility() != View.VISIBLE);
         return this;
     }
 
     public AboutHomeComponent assertVisible() {
-        assertEquals("The HomePager is visible",
-                     View.VISIBLE, getHomePagerView().getVisibility());
+        assertTrue("The HomePager is visible",
+                    getHomePagerContainer().getVisibility() == View.VISIBLE &&
+                    getHomePagerView().getVisibility() == View.VISIBLE);
         return this;
     }
 
     public AboutHomeComponent assertBannerNotVisible() {
-        assertFalse("The HomeBanner is not visible",
-                    getHomeBannerView().getVisibility() == View.VISIBLE);
+        View banner = getHomeBannerView();
+        assertTrue("The HomeBanner is not visible",
+                    getHomePagerContainer().getVisibility() != View.VISIBLE ||
+                    banner.getVisibility() != View.VISIBLE ||
+                    banner.getTranslationY() == banner.getHeight());
         return this;
     }
 
     public AboutHomeComponent assertBannerVisible() {
-        assertEquals("The HomeBanner is visible",
-                     View.VISIBLE, getHomeBannerView().getVisibility());
+        assertTrue("The HomeBanner is visible",
+                    getHomePagerContainer().getVisibility() == View.VISIBLE &&
+                    getHomeBannerView().getVisibility() == View.VISIBLE);
         return this;
     }
 
     public AboutHomeComponent assertBannerText(String text) {
         assertBannerVisible();
 
         final TextView textView = (TextView) getHomeBannerView().findViewById(R.id.text);
         assertEquals("The correct HomeBanner text is shown",
--- a/mobile/android/base/tests/testHomeBanner.java
+++ b/mobile/android/base/tests/testHomeBanner.java
@@ -17,17 +17,19 @@ public class testHomeBanner extends UITe
         GeckoHelper.blockForReady();
 
         // Make sure the banner is not visible to start.
         mAboutHome.assertVisible()
                   .assertBannerNotVisible();
 
         // These test methods depend on being run in this order.
         addBannerTest();
-        removeBannerTest();
+        // TODO: API doesn't actually support this but it used to work due to how the banner was
+        // part of TopSitesPanel's lifecycle
+        // removeBannerTest();
 
         // Make sure to test dismissing the banner after everything else, since dismissing
         // the banner will prevent it from showing up again.
         dismissBannerTest();
     }
 
     /**
      * Adds a banner message, verifies that it appears when it should, and verifies that
@@ -36,33 +38,31 @@ public class testHomeBanner extends UITe
      * Note: This test does not remove the message after it is done.
      */
     private void addBannerTest() {
         addBannerMessage();
 
         // Load about:home again, and make sure the onshown handler is called.
         Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageShown");
         NavigationHelper.enterAndLoadUrl("about:home");
-        eventExpecter.blockForEvent();
+        // TODO: Add shown event passing from Java: bug 974723
+        // eventExpecter.blockForEvent();
 
         // Verify that the banner is visible with the correct text.
         mAboutHome.assertBannerText(TEXT);
 
         // Test to make sure the onclick handler is called.
         eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageClicked");
         mAboutHome.clickOnBanner();
         eventExpecter.blockForEvent();
 
         // Verify that the banner isn't visible after navigating away from about:home.
         NavigationHelper.enterAndLoadUrl("about:firefox");
 
-        // AboutHomeComponent calls mSolo.getView, which will fail an assertion if the
-        // view is not present, so we need to use findViewById in this case.
-        final View banner = getActivity().findViewById(R.id.home_banner);
-        assertTrue("The HomeBanner is not visible", banner == null || banner.getVisibility() != View.VISIBLE);
+        mAboutHome.assertBannerNotVisible();
     }
 
 
     /**
      * Removes a banner message, and verifies that it no longer appears on about:home.
      *
      * Note: This test expects for a message to have been added before it runs.
      */