Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | package org.mozilla.gecko.tests; |
michael@0 | 2 | |
michael@0 | 3 | import org.json.JSONObject; |
michael@0 | 4 | import org.mozilla.gecko.Actions; |
michael@0 | 5 | |
michael@0 | 6 | import android.util.DisplayMetrics; |
michael@0 | 7 | |
michael@0 | 8 | public class testAddonManager extends PixelTest { |
michael@0 | 9 | /* This test will check the behavior of the Addons Manager: |
michael@0 | 10 | First the test will open the Addons Manager from the Menu and then close it |
michael@0 | 11 | Then the test will open the Addons Manager by visiting about:addons |
michael@0 | 12 | The test will tap/click on the addons.mozilla.org icon to open the AMO page in a new tab |
michael@0 | 13 | 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 | 14 | |
michael@0 | 15 | public void testAddonManager() { |
michael@0 | 16 | Actions.EventExpecter tabEventExpecter; |
michael@0 | 17 | Actions.EventExpecter contentEventExpecter; |
michael@0 | 18 | String url = "about:addons"; |
michael@0 | 19 | |
michael@0 | 20 | blockForGeckoReady(); |
michael@0 | 21 | |
michael@0 | 22 | // Use the menu to open the Addon Manger |
michael@0 | 23 | selectMenuItem("Add-ons"); |
michael@0 | 24 | |
michael@0 | 25 | // Set up listeners to catch the page load we're about to do |
michael@0 | 26 | tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); |
michael@0 | 27 | contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded"); |
michael@0 | 28 | |
michael@0 | 29 | // Wait for the new tab and page to load |
michael@0 | 30 | tabEventExpecter.blockForEvent(); |
michael@0 | 31 | contentEventExpecter.blockForEvent(); |
michael@0 | 32 | |
michael@0 | 33 | tabEventExpecter.unregisterListener(); |
michael@0 | 34 | contentEventExpecter.unregisterListener(); |
michael@0 | 35 | |
michael@0 | 36 | // Verify the url |
michael@0 | 37 | verifyPageTitle("Add-ons"); |
michael@0 | 38 | |
michael@0 | 39 | // Close the Add-on Manager |
michael@0 | 40 | mActions.sendSpecialKey(Actions.SpecialKey.BACK); |
michael@0 | 41 | |
michael@0 | 42 | // Load the about:addons page and verify it was loaded |
michael@0 | 43 | loadAndPaint(url); |
michael@0 | 44 | verifyPageTitle("Add-ons"); |
michael@0 | 45 | |
michael@0 | 46 | // Change the AMO URL so we do not try to navigate to a live webpage |
michael@0 | 47 | JSONObject jsonPref = new JSONObject(); |
michael@0 | 48 | try { |
michael@0 | 49 | jsonPref.put("name", "extensions.getAddons.browseAddons"); |
michael@0 | 50 | jsonPref.put("type", "string"); |
michael@0 | 51 | jsonPref.put("value", getAbsoluteUrl("/robocop/robocop_blank_01.html")); |
michael@0 | 52 | setPreferenceAndWaitForChange(jsonPref); |
michael@0 | 53 | |
michael@0 | 54 | } catch (Exception ex) { |
michael@0 | 55 | mAsserter.ok(false, "exception in testAddonManager", ex.toString()); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | // Load AMO page by clicking the AMO icon |
michael@0 | 59 | DisplayMetrics dm = new DisplayMetrics(); |
michael@0 | 60 | getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); |
michael@0 | 61 | |
michael@0 | 62 | /* Setup the tap to top value + 25px and right value - 25px. |
michael@0 | 63 | Since the AMO icon is 50x50px this values should set the tap |
michael@0 | 64 | in the middle of the icon */ |
michael@0 | 65 | float top = mDriver.getGeckoTop() + 25 * dm.density;; |
michael@0 | 66 | float right = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() - 25 * dm.density;; |
michael@0 | 67 | |
michael@0 | 68 | // Setup wait for tab to spawn and load |
michael@0 | 69 | tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); |
michael@0 | 70 | contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded"); |
michael@0 | 71 | |
michael@0 | 72 | // Tap on the AMO icon |
michael@0 | 73 | mSolo.clickOnScreen(right, top); |
michael@0 | 74 | |
michael@0 | 75 | // Wait for the new tab and page to load |
michael@0 | 76 | tabEventExpecter.blockForEvent(); |
michael@0 | 77 | contentEventExpecter.blockForEvent(); |
michael@0 | 78 | |
michael@0 | 79 | tabEventExpecter.unregisterListener(); |
michael@0 | 80 | contentEventExpecter.unregisterListener(); |
michael@0 | 81 | |
michael@0 | 82 | // Verify tab count has increased |
michael@0 | 83 | verifyTabCount(2); |
michael@0 | 84 | |
michael@0 | 85 | // Verify the page was opened |
michael@0 | 86 | verifyPageTitle("Browser Blank Page 01"); |
michael@0 | 87 | |
michael@0 | 88 | // Addons Manager is not opened 2 separate times when opened from the menu |
michael@0 | 89 | selectMenuItem("Add-ons"); |
michael@0 | 90 | |
michael@0 | 91 | // Verify tab count not increased |
michael@0 | 92 | verifyTabCount(2); |
michael@0 | 93 | } |
michael@0 | 94 | } |