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