mobile/android/base/tests/testHomeBanner.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 package org.mozilla.gecko.tests;
     3 import org.mozilla.gecko.Actions;
     4 import org.mozilla.gecko.tests.helpers.GeckoHelper;
     5 import org.mozilla.gecko.tests.helpers.NavigationHelper;
     7 public class testHomeBanner extends UITest {
     9     private static final String TEST_URL = "chrome://roboextender/content/robocop_home_banner.html";
    10     private static final String TEXT = "The quick brown fox jumps over the lazy dog.";
    12     public void testHomeBanner() {
    13         GeckoHelper.blockForReady();
    15         // Make sure the banner is not visible to start.
    16         mAboutHome.assertVisible()
    17                   .assertBannerNotVisible();
    19         // These test methods depend on being run in this order.
    20         addBannerTest();
    22         // Make sure the banner hides when the user starts interacting with the url bar.
    23         hideOnToolbarFocusTest();
    25         // TODO: API doesn't actually support this but it used to work due to how the banner was
    26         // part of TopSitesPanel's lifecycle
    27         // removeBannerTest();
    29         // Make sure to test dismissing the banner after everything else, since dismissing
    30         // the banner will prevent it from showing up again.
    31         dismissBannerTest();
    32     }
    34     /**
    35      * Adds a banner message, verifies that it appears when it should, and verifies that
    36      * onshown/onclick handlers are called in JS.
    37      *
    38      * Note: This test does not remove the message after it is done.
    39      */
    40     private void addBannerTest() {
    41         // Load about:home and make sure the onshown handler is called.
    42         Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageShown");
    43         addBannerMessage();
    44         NavigationHelper.enterAndLoadUrl("about:home");
    45         eventExpecter.blockForEvent();
    47         // Verify that the banner is visible with the correct text.
    48         mAboutHome.assertBannerText(TEXT);
    50         // Test to make sure the onclick handler is called.
    51         eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageClicked");
    52         mAboutHome.clickOnBanner();
    53         eventExpecter.blockForEvent();
    55         // Verify that the banner isn't visible after navigating away from about:home.
    56         NavigationHelper.enterAndLoadUrl("about:firefox");
    58         mAboutHome.assertBannerNotVisible();
    59     }
    62     /**
    63      * Removes a banner message, and verifies that it no longer appears on about:home.
    64      *
    65      * Note: This test expects for a message to have been added before it runs.
    66      */
    67     private void removeBannerTest() {
    68         removeBannerMessage();
    70         // Verify that the banner no longer appears.
    71         NavigationHelper.enterAndLoadUrl("about:home");
    72         mAboutHome.assertVisible()
    73                   .assertBannerNotVisible();
    74     }
    76     /**
    77      * Adds a banner message, verifies that its ondismiss handler is called in JS,
    78      * and verifies that the banner is no longer shown after it is dismissed.
    79      *
    80      * Note: This test does not remove the message after it is done.
    81      */
    82     private void dismissBannerTest() {
    83         // Add back the banner message to test the dismiss functionality.
    84         addBannerMessage();
    86         NavigationHelper.enterAndLoadUrl("about:home");
    87         mAboutHome.assertVisible();
    89         // Test to make sure the ondismiss handler is called when the close button is clicked.
    90         final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageDismissed");
    91         mAboutHome.dismissBanner();
    92         eventExpecter.blockForEvent();
    94         mAboutHome.assertBannerNotVisible();
    95     }
    97     private void hideOnToolbarFocusTest() {
    98         NavigationHelper.enterAndLoadUrl("about:home");
    99         mAboutHome.assertVisible()
   100                   .assertBannerVisible();
   102         mToolbar.enterEditingMode();
   103         mAboutHome.assertBannerNotVisible();
   105         mToolbar.dismissEditingMode();
   106         mAboutHome.assertBannerVisible();
   107     }
   109     /**
   110      * Loads the roboextender page to add a message to the banner.
   111      */
   112     private void addBannerMessage() {
   113         final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageAdded");
   114         NavigationHelper.enterAndLoadUrl(TEST_URL + "#addMessage");
   115         eventExpecter.blockForEvent();
   116     }
   118     /**
   119      * Loads the roboextender page to remove the message from the banner.
   120      */
   121     private void removeBannerMessage() {
   122         final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageRemoved");
   123         NavigationHelper.enterAndLoadUrl(TEST_URL + "#removeMessage");
   124         eventExpecter.blockForEvent();
   125     }
   126 }

mercurial