michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.json.JSONObject; michael@0: import org.mozilla.gecko.Actions; michael@0: michael@0: import android.util.DisplayMetrics; michael@0: michael@0: public class testAddonManager extends PixelTest { michael@0: /* This test will check the behavior of the Addons Manager: michael@0: First the test will open the Addons Manager from the Menu and then close it michael@0: Then the test will open the Addons Manager by visiting about:addons michael@0: The test will tap/click on the addons.mozilla.org icon to open the AMO page in a new tab michael@0: With the Addons Manager open the test will verify that when it is opened again from the menu no new tab will be opened*/ michael@0: michael@0: public void testAddonManager() { michael@0: Actions.EventExpecter tabEventExpecter; michael@0: Actions.EventExpecter contentEventExpecter; michael@0: String url = "about:addons"; michael@0: michael@0: blockForGeckoReady(); michael@0: michael@0: // Use the menu to open the Addon Manger michael@0: selectMenuItem("Add-ons"); michael@0: michael@0: // Set up listeners to catch the page load we're about to do michael@0: tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); michael@0: contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded"); michael@0: michael@0: // Wait for the new tab and page to load michael@0: tabEventExpecter.blockForEvent(); michael@0: contentEventExpecter.blockForEvent(); michael@0: michael@0: tabEventExpecter.unregisterListener(); michael@0: contentEventExpecter.unregisterListener(); michael@0: michael@0: // Verify the url michael@0: verifyPageTitle("Add-ons"); michael@0: michael@0: // Close the Add-on Manager michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: michael@0: // Load the about:addons page and verify it was loaded michael@0: loadAndPaint(url); michael@0: verifyPageTitle("Add-ons"); michael@0: michael@0: // Change the AMO URL so we do not try to navigate to a live webpage michael@0: JSONObject jsonPref = new JSONObject(); michael@0: try { michael@0: jsonPref.put("name", "extensions.getAddons.browseAddons"); michael@0: jsonPref.put("type", "string"); michael@0: jsonPref.put("value", getAbsoluteUrl("/robocop/robocop_blank_01.html")); michael@0: setPreferenceAndWaitForChange(jsonPref); michael@0: michael@0: } catch (Exception ex) { michael@0: mAsserter.ok(false, "exception in testAddonManager", ex.toString()); michael@0: } michael@0: michael@0: // Load AMO page by clicking the AMO icon michael@0: DisplayMetrics dm = new DisplayMetrics(); michael@0: getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); michael@0: michael@0: /* Setup the tap to top value + 25px and right value - 25px. michael@0: Since the AMO icon is 50x50px this values should set the tap michael@0: in the middle of the icon */ michael@0: float top = mDriver.getGeckoTop() + 25 * dm.density;; michael@0: float right = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() - 25 * dm.density;; michael@0: michael@0: // Setup wait for tab to spawn and load michael@0: tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); michael@0: contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded"); michael@0: michael@0: // Tap on the AMO icon michael@0: mSolo.clickOnScreen(right, top); michael@0: michael@0: // Wait for the new tab and page to load michael@0: tabEventExpecter.blockForEvent(); michael@0: contentEventExpecter.blockForEvent(); michael@0: michael@0: tabEventExpecter.unregisterListener(); michael@0: contentEventExpecter.unregisterListener(); michael@0: michael@0: // Verify tab count has increased michael@0: verifyTabCount(2); michael@0: michael@0: // Verify the page was opened michael@0: verifyPageTitle("Browser Blank Page 01"); michael@0: michael@0: // Addons Manager is not opened 2 separate times when opened from the menu michael@0: selectMenuItem("Add-ons"); michael@0: michael@0: // Verify tab count not increased michael@0: verifyTabCount(2); michael@0: } michael@0: }