mobile/android/base/tests/testHomeBanner.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testHomeBanner.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.mozilla.gecko.Actions;
     1.7 +import org.mozilla.gecko.tests.helpers.GeckoHelper;
     1.8 +import org.mozilla.gecko.tests.helpers.NavigationHelper;
     1.9 +
    1.10 +public class testHomeBanner extends UITest {
    1.11 +
    1.12 +    private static final String TEST_URL = "chrome://roboextender/content/robocop_home_banner.html";
    1.13 +    private static final String TEXT = "The quick brown fox jumps over the lazy dog.";
    1.14 +
    1.15 +    public void testHomeBanner() {
    1.16 +        GeckoHelper.blockForReady();
    1.17 +
    1.18 +        // Make sure the banner is not visible to start.
    1.19 +        mAboutHome.assertVisible()
    1.20 +                  .assertBannerNotVisible();
    1.21 +
    1.22 +        // These test methods depend on being run in this order.
    1.23 +        addBannerTest();
    1.24 +
    1.25 +        // Make sure the banner hides when the user starts interacting with the url bar.
    1.26 +        hideOnToolbarFocusTest();
    1.27 +
    1.28 +        // TODO: API doesn't actually support this but it used to work due to how the banner was
    1.29 +        // part of TopSitesPanel's lifecycle
    1.30 +        // removeBannerTest();
    1.31 +
    1.32 +        // Make sure to test dismissing the banner after everything else, since dismissing
    1.33 +        // the banner will prevent it from showing up again.
    1.34 +        dismissBannerTest();
    1.35 +    }
    1.36 +
    1.37 +    /**
    1.38 +     * Adds a banner message, verifies that it appears when it should, and verifies that
    1.39 +     * onshown/onclick handlers are called in JS.
    1.40 +     *
    1.41 +     * Note: This test does not remove the message after it is done.
    1.42 +     */
    1.43 +    private void addBannerTest() {
    1.44 +        // Load about:home and make sure the onshown handler is called.
    1.45 +        Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageShown");
    1.46 +        addBannerMessage();
    1.47 +        NavigationHelper.enterAndLoadUrl("about:home");
    1.48 +        eventExpecter.blockForEvent();
    1.49 +
    1.50 +        // Verify that the banner is visible with the correct text.
    1.51 +        mAboutHome.assertBannerText(TEXT);
    1.52 +
    1.53 +        // Test to make sure the onclick handler is called.
    1.54 +        eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageClicked");
    1.55 +        mAboutHome.clickOnBanner();
    1.56 +        eventExpecter.blockForEvent();
    1.57 +
    1.58 +        // Verify that the banner isn't visible after navigating away from about:home.
    1.59 +        NavigationHelper.enterAndLoadUrl("about:firefox");
    1.60 +
    1.61 +        mAboutHome.assertBannerNotVisible();
    1.62 +    }
    1.63 +
    1.64 +
    1.65 +    /**
    1.66 +     * Removes a banner message, and verifies that it no longer appears on about:home.
    1.67 +     *
    1.68 +     * Note: This test expects for a message to have been added before it runs.
    1.69 +     */
    1.70 +    private void removeBannerTest() {
    1.71 +        removeBannerMessage();
    1.72 +
    1.73 +        // Verify that the banner no longer appears.
    1.74 +        NavigationHelper.enterAndLoadUrl("about:home");
    1.75 +        mAboutHome.assertVisible()
    1.76 +                  .assertBannerNotVisible();
    1.77 +    }
    1.78 +
    1.79 +    /**
    1.80 +     * Adds a banner message, verifies that its ondismiss handler is called in JS,
    1.81 +     * and verifies that the banner is no longer shown after it is dismissed.
    1.82 +     *
    1.83 +     * Note: This test does not remove the message after it is done.
    1.84 +     */
    1.85 +    private void dismissBannerTest() {
    1.86 +        // Add back the banner message to test the dismiss functionality.
    1.87 +        addBannerMessage();
    1.88 +
    1.89 +        NavigationHelper.enterAndLoadUrl("about:home");
    1.90 +        mAboutHome.assertVisible();
    1.91 +
    1.92 +        // Test to make sure the ondismiss handler is called when the close button is clicked.
    1.93 +        final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageDismissed");
    1.94 +        mAboutHome.dismissBanner();
    1.95 +        eventExpecter.blockForEvent();
    1.96 +
    1.97 +        mAboutHome.assertBannerNotVisible();
    1.98 +    }
    1.99 +
   1.100 +    private void hideOnToolbarFocusTest() {
   1.101 +        NavigationHelper.enterAndLoadUrl("about:home");
   1.102 +        mAboutHome.assertVisible()
   1.103 +                  .assertBannerVisible();
   1.104 +
   1.105 +        mToolbar.enterEditingMode();
   1.106 +        mAboutHome.assertBannerNotVisible();
   1.107 +
   1.108 +        mToolbar.dismissEditingMode();
   1.109 +        mAboutHome.assertBannerVisible();
   1.110 +    }
   1.111 +
   1.112 +    /**
   1.113 +     * Loads the roboextender page to add a message to the banner.
   1.114 +     */
   1.115 +    private void addBannerMessage() {
   1.116 +        final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageAdded");
   1.117 +        NavigationHelper.enterAndLoadUrl(TEST_URL + "#addMessage");
   1.118 +        eventExpecter.blockForEvent();
   1.119 +    }
   1.120 +
   1.121 +    /**
   1.122 +     * Loads the roboextender page to remove the message from the banner.
   1.123 +     */
   1.124 +    private void removeBannerMessage() {
   1.125 +        final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageRemoved");
   1.126 +        NavigationHelper.enterAndLoadUrl(TEST_URL + "#removeMessage");
   1.127 +        eventExpecter.blockForEvent();
   1.128 +    }
   1.129 +}

mercurial