mobile/android/base/tests/testHomeBanner.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial