michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: import org.mozilla.gecko.tests.helpers.GeckoHelper; michael@0: import org.mozilla.gecko.tests.helpers.NavigationHelper; michael@0: michael@0: public class testHomeBanner extends UITest { michael@0: michael@0: private static final String TEST_URL = "chrome://roboextender/content/robocop_home_banner.html"; michael@0: private static final String TEXT = "The quick brown fox jumps over the lazy dog."; michael@0: michael@0: public void testHomeBanner() { michael@0: GeckoHelper.blockForReady(); michael@0: michael@0: // Make sure the banner is not visible to start. michael@0: mAboutHome.assertVisible() michael@0: .assertBannerNotVisible(); michael@0: michael@0: // These test methods depend on being run in this order. michael@0: addBannerTest(); michael@0: michael@0: // Make sure the banner hides when the user starts interacting with the url bar. michael@0: hideOnToolbarFocusTest(); michael@0: michael@0: // TODO: API doesn't actually support this but it used to work due to how the banner was michael@0: // part of TopSitesPanel's lifecycle michael@0: // removeBannerTest(); michael@0: michael@0: // Make sure to test dismissing the banner after everything else, since dismissing michael@0: // the banner will prevent it from showing up again. michael@0: dismissBannerTest(); michael@0: } michael@0: michael@0: /** michael@0: * Adds a banner message, verifies that it appears when it should, and verifies that michael@0: * onshown/onclick handlers are called in JS. michael@0: * michael@0: * Note: This test does not remove the message after it is done. michael@0: */ michael@0: private void addBannerTest() { michael@0: // Load about:home and make sure the onshown handler is called. michael@0: Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageShown"); michael@0: addBannerMessage(); michael@0: NavigationHelper.enterAndLoadUrl("about:home"); michael@0: eventExpecter.blockForEvent(); michael@0: michael@0: // Verify that the banner is visible with the correct text. michael@0: mAboutHome.assertBannerText(TEXT); michael@0: michael@0: // Test to make sure the onclick handler is called. michael@0: eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageClicked"); michael@0: mAboutHome.clickOnBanner(); michael@0: eventExpecter.blockForEvent(); michael@0: michael@0: // Verify that the banner isn't visible after navigating away from about:home. michael@0: NavigationHelper.enterAndLoadUrl("about:firefox"); michael@0: michael@0: mAboutHome.assertBannerNotVisible(); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Removes a banner message, and verifies that it no longer appears on about:home. michael@0: * michael@0: * Note: This test expects for a message to have been added before it runs. michael@0: */ michael@0: private void removeBannerTest() { michael@0: removeBannerMessage(); michael@0: michael@0: // Verify that the banner no longer appears. michael@0: NavigationHelper.enterAndLoadUrl("about:home"); michael@0: mAboutHome.assertVisible() michael@0: .assertBannerNotVisible(); michael@0: } michael@0: michael@0: /** michael@0: * Adds a banner message, verifies that its ondismiss handler is called in JS, michael@0: * and verifies that the banner is no longer shown after it is dismissed. michael@0: * michael@0: * Note: This test does not remove the message after it is done. michael@0: */ michael@0: private void dismissBannerTest() { michael@0: // Add back the banner message to test the dismiss functionality. michael@0: addBannerMessage(); michael@0: michael@0: NavigationHelper.enterAndLoadUrl("about:home"); michael@0: mAboutHome.assertVisible(); michael@0: michael@0: // Test to make sure the ondismiss handler is called when the close button is clicked. michael@0: final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageDismissed"); michael@0: mAboutHome.dismissBanner(); michael@0: eventExpecter.blockForEvent(); michael@0: michael@0: mAboutHome.assertBannerNotVisible(); michael@0: } michael@0: michael@0: private void hideOnToolbarFocusTest() { michael@0: NavigationHelper.enterAndLoadUrl("about:home"); michael@0: mAboutHome.assertVisible() michael@0: .assertBannerVisible(); michael@0: michael@0: mToolbar.enterEditingMode(); michael@0: mAboutHome.assertBannerNotVisible(); michael@0: michael@0: mToolbar.dismissEditingMode(); michael@0: mAboutHome.assertBannerVisible(); michael@0: } michael@0: michael@0: /** michael@0: * Loads the roboextender page to add a message to the banner. michael@0: */ michael@0: private void addBannerMessage() { michael@0: final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageAdded"); michael@0: NavigationHelper.enterAndLoadUrl(TEST_URL + "#addMessage"); michael@0: eventExpecter.blockForEvent(); michael@0: } michael@0: michael@0: /** michael@0: * Loads the roboextender page to remove the message from the banner. michael@0: */ michael@0: private void removeBannerMessage() { michael@0: final Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageRemoved"); michael@0: NavigationHelper.enterAndLoadUrl(TEST_URL + "#removeMessage"); michael@0: eventExpecter.blockForEvent(); michael@0: } michael@0: }