mobile/android/base/tests/testAddonManager.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testAddonManager.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.json.JSONObject;
     1.7 +import org.mozilla.gecko.Actions;
     1.8 +
     1.9 +import android.util.DisplayMetrics;
    1.10 +
    1.11 +public class testAddonManager extends PixelTest  {
    1.12 +    /* This test will check the behavior of the Addons Manager:
    1.13 +    First the test will open the Addons Manager from the Menu and then close it
    1.14 +    Then the test will open the Addons Manager by visiting about:addons
    1.15 +    The test will tap/click on the addons.mozilla.org icon to open the AMO page in a new tab
    1.16 +    With the Addons Manager open the test will verify that when it is opened again from the menu no new tab will be opened*/
    1.17 +
    1.18 +    public void testAddonManager() {
    1.19 +        Actions.EventExpecter tabEventExpecter;
    1.20 +        Actions.EventExpecter contentEventExpecter;
    1.21 +        String url = "about:addons";
    1.22 +
    1.23 +        blockForGeckoReady();
    1.24 +
    1.25 +        // Use the menu to open the Addon Manger
    1.26 +        selectMenuItem("Add-ons");
    1.27 +
    1.28 +        // Set up listeners to catch the page load we're about to do
    1.29 +        tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
    1.30 +        contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
    1.31 +
    1.32 +        // Wait for the new tab and page to load
    1.33 +        tabEventExpecter.blockForEvent();
    1.34 +        contentEventExpecter.blockForEvent();
    1.35 +
    1.36 +        tabEventExpecter.unregisterListener();
    1.37 +        contentEventExpecter.unregisterListener();
    1.38 +
    1.39 +        // Verify the url
    1.40 +        verifyPageTitle("Add-ons");
    1.41 +
    1.42 +        // Close the Add-on Manager
    1.43 +        mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    1.44 +
    1.45 +        // Load the about:addons page and verify it was loaded
    1.46 +        loadAndPaint(url);
    1.47 +        verifyPageTitle("Add-ons");
    1.48 +
    1.49 +        // Change the AMO URL so we do not try to navigate to a live webpage
    1.50 +        JSONObject jsonPref = new JSONObject();
    1.51 +        try {
    1.52 +            jsonPref.put("name", "extensions.getAddons.browseAddons");
    1.53 +            jsonPref.put("type", "string");
    1.54 +            jsonPref.put("value", getAbsoluteUrl("/robocop/robocop_blank_01.html"));
    1.55 +            setPreferenceAndWaitForChange(jsonPref);
    1.56 +
    1.57 +        } catch (Exception ex) { 
    1.58 +            mAsserter.ok(false, "exception in testAddonManager", ex.toString());
    1.59 +        }
    1.60 +
    1.61 +        // Load AMO page by clicking the AMO icon
    1.62 +        DisplayMetrics dm = new DisplayMetrics();
    1.63 +        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
    1.64 +
    1.65 +        /* Setup the tap to top value + 25px and right value - 25px.
    1.66 +        Since the AMO icon is 50x50px this values should set the tap
    1.67 +        in the middle of the icon */
    1.68 +        float top = mDriver.getGeckoTop() + 25 * dm.density;;
    1.69 +        float right = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() - 25 * dm.density;;
    1.70 +
    1.71 +        // Setup wait for tab to spawn and load
    1.72 +        tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
    1.73 +        contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
    1.74 +
    1.75 +        // Tap on the AMO icon
    1.76 +        mSolo.clickOnScreen(right, top);
    1.77 +
    1.78 +        // Wait for the new tab and page to load
    1.79 +        tabEventExpecter.blockForEvent();
    1.80 +        contentEventExpecter.blockForEvent();
    1.81 +
    1.82 +        tabEventExpecter.unregisterListener();
    1.83 +        contentEventExpecter.unregisterListener();
    1.84 +
    1.85 +        // Verify tab count has increased
    1.86 +        verifyTabCount(2);
    1.87 +
    1.88 +        // Verify the page was opened
    1.89 +        verifyPageTitle("Browser Blank Page 01");
    1.90 +
    1.91 +        // Addons Manager is not opened 2 separate times when opened from the menu
    1.92 +        selectMenuItem("Add-ons");        
    1.93 +
    1.94 +        // Verify tab count not increased
    1.95 +        verifyTabCount(2);
    1.96 +    }
    1.97 +}

mercurial