2012-10-02 08:24:38 -07:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
|
2013-01-04 12:11:57 -08:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2012-10-02 08:24:38 -07:00
|
|
|
public class testAddonManager extends PixelTest {
|
|
|
|
@Override
|
|
|
|
protected int getTestType() {
|
|
|
|
return TEST_MOCHITEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This test will check the behavior of the Addons Manager:
|
|
|
|
First the test will open the Addons Manager from the Menu and then close it
|
|
|
|
Then the test will open the Addons Manager by visiting about:addons
|
|
|
|
The test will tap/click on the addons.mozilla.org icon to open the AMO page in a new tab
|
|
|
|
With the Addons Manager open the test will verify that when it is opened again from the menu no new tab will be opened*/
|
|
|
|
|
|
|
|
public void testAddonManager() {
|
2013-04-18 20:18:09 -07:00
|
|
|
Actions.EventExpecter tabEventExpecter;
|
|
|
|
Actions.EventExpecter contentEventExpecter;
|
|
|
|
String url = "about:addons";
|
|
|
|
|
2012-10-25 12:37:39 -07:00
|
|
|
blockForGeckoReady();
|
2012-10-02 08:24:38 -07:00
|
|
|
|
|
|
|
// Use the menu to open the Addon Manger
|
|
|
|
selectMenuItem("Add-ons");
|
|
|
|
|
|
|
|
// Set up listeners to catch the page load we're about to do
|
|
|
|
tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
|
|
|
|
contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
|
|
|
|
|
|
|
// Wait for the new tab and page to load
|
|
|
|
tabEventExpecter.blockForEvent();
|
|
|
|
contentEventExpecter.blockForEvent();
|
|
|
|
|
2013-04-18 20:18:09 -07:00
|
|
|
tabEventExpecter.unregisterListener();
|
|
|
|
contentEventExpecter.unregisterListener();
|
|
|
|
|
2012-10-02 08:24:38 -07:00
|
|
|
// Verify the url
|
|
|
|
verifyPageTitle("Add-ons");
|
|
|
|
|
|
|
|
// Close the Add-on Manager
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
|
|
|
|
|
|
|
// Load the about:addons page and verify it was loaded
|
|
|
|
loadAndPaint(url);
|
|
|
|
verifyPageTitle("Add-ons");
|
|
|
|
|
2013-01-04 12:11:57 -08:00
|
|
|
// Change the AMO URL so we do not try to navigate to a live webpage
|
|
|
|
JSONObject jsonPref = new JSONObject();
|
|
|
|
try {
|
|
|
|
jsonPref.put("name", "extensions.getAddons.browseAddons");
|
|
|
|
jsonPref.put("type", "string");
|
|
|
|
jsonPref.put("value", getAbsoluteUrl("/robocop/robocop_blank_01.html"));
|
|
|
|
mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
|
|
|
|
|
|
|
|
// Wait for confirmation of the pref change before proceeding with the test.
|
|
|
|
JSONArray getPrefData = new JSONArray();
|
|
|
|
getPrefData.put("extensions.getAddons.browseAddons");
|
|
|
|
JSONObject message = new JSONObject();
|
|
|
|
message.put("requestId", "testAddonManager");
|
|
|
|
message.put("preferences", getPrefData);
|
2013-02-24 07:55:45 -08:00
|
|
|
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
|
2013-01-04 12:11:57 -08:00
|
|
|
mActions.sendGeckoEvent("Preferences:Get", message.toString());
|
2013-02-24 07:55:45 -08:00
|
|
|
|
|
|
|
JSONObject data = null;
|
|
|
|
String requestId = "";
|
|
|
|
|
|
|
|
// Wait until we get the correct "Preferences:Data" event
|
|
|
|
while (!requestId.equals("testAddonManager")) {
|
|
|
|
data = new JSONObject(eventExpecter.blockForEventData());
|
|
|
|
requestId = data.getString("requestId");
|
|
|
|
}
|
2013-04-18 20:18:09 -07:00
|
|
|
eventExpecter.unregisterListener();
|
2013-02-24 07:55:45 -08:00
|
|
|
|
2013-01-04 12:11:57 -08:00
|
|
|
} catch (Exception ex) {
|
|
|
|
mAsserter.ok(false, "exception in testAddonManager", ex.toString());
|
|
|
|
}
|
|
|
|
|
2012-10-02 08:24:38 -07:00
|
|
|
// Load AMO page by clicking the AMO icon
|
|
|
|
DisplayMetrics dm = new DisplayMetrics();
|
|
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
|
|
|
|
|
|
/* Setup the tap to top value + 25px and right value - 25px.
|
|
|
|
Since the AMO icon is 50x50px this values should set the tap
|
|
|
|
in the middle of the icon */
|
|
|
|
float top = mDriver.getGeckoTop() + 25 * dm.density;;
|
|
|
|
float right = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() - 25 * dm.density;;
|
|
|
|
|
|
|
|
// Setup wait for tab to spawn and load
|
|
|
|
tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
|
|
|
|
contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
|
|
|
|
|
|
|
// Tap on the AMO icon
|
|
|
|
mSolo.clickOnScreen(right, top);
|
|
|
|
|
|
|
|
// Wait for the new tab and page to load
|
|
|
|
tabEventExpecter.blockForEvent();
|
|
|
|
contentEventExpecter.blockForEvent();
|
|
|
|
|
2013-04-18 20:18:09 -07:00
|
|
|
tabEventExpecter.unregisterListener();
|
|
|
|
contentEventExpecter.unregisterListener();
|
|
|
|
|
2012-10-02 08:24:38 -07:00
|
|
|
// Verify tab count has increased
|
|
|
|
verifyTabCount(2);
|
|
|
|
|
|
|
|
// Verify the page was opened
|
2013-01-04 12:11:57 -08:00
|
|
|
verifyPageTitle("Browser Blank Page 01");
|
2012-10-02 08:24:38 -07:00
|
|
|
|
|
|
|
// Addons Manager is not opened 2 separate times when opened from the menu
|
|
|
|
selectMenuItem("Add-ons");
|
|
|
|
|
|
|
|
// Verify tab count not increased
|
|
|
|
verifyTabCount(2);
|
|
|
|
}
|
|
|
|
}
|