Bug 777719 - Addons Manager test modified according to review. r=jmaher.
authoradrian.tamas@softvision.ro
Tue, 02 Oct 2012 18:24:38 +0300
changeset 109071 f6d4ab10d670cd3f146a54d2f0f4d9b04ed4913f
parent 109070 809b60046c5bfa16347921d7f3d87669c0f9f558
child 109072 2622aa008fe922164d65f72c814a82035c6c5dc3
push id15830
push userjmaher@mozilla.com
push dateWed, 03 Oct 2012 15:08:06 +0000
treeherdermozilla-inbound@2622aa008fe9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs777719
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 777719 - Addons Manager test modified according to review. r=jmaher.
mobile/android/base/tests/BaseTest.java.in
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/testAddonManager.java.in
old mode 100644
new mode 100755
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -300,9 +300,37 @@ abstract class BaseTest extends Activity
         }
         return true;
     }
 
     public InputStream getAsset(String filename) throws IOException {
         AssetManager assets = getInstrumentation().getContext().getAssets();
         return assets.open(filename);
     }
+
+    public final void selectMenuItem(String menuItemName) {
+        //build the item name ready to be used
+        String itemName = "^" + menuItemName + "$";
+        mActions.sendSpecialKey(Actions.SpecialKey.MENU);
+
+        // Look for the 'More' menu if this device/OS uses it
+        if (mSolo.waitForText("^More$")) {
+            mSolo.clickOnText("^More$");
+        }
+
+        mSolo.waitForText(itemName);
+        mSolo.clickOnText(itemName);
+    }
+
+    public final void verifyPageTitle(String title) {
+	Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
+        mAsserter.isnot(awesomebar, null, "Got the awesomebar");
+        assertMatches(awesomebar.getText(), title, "Page title match");
+    }
+
+    public final void verifyTabCount(int expectedTabCount) {
+        Activity activity = getActivity();
+        Element tabCount = mDriver.findElement(activity, "tabs_count");
+        String tabCountText = tabCount.getText();
+        int tabCountInt = Integer.parseInt(tabCountText);
+        mAsserter.is(tabCountInt, expectedTabCount, "The correct number of tabs are opened");
+    }
 }
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -15,16 +15,17 @@
 [testAboutPage]
 # [testWebContentContextMenu] # see bug 785577
 [testPasswordProvider]
 [testPasswordEncrypt]
 [testFormHistory]
 [testBrowserProvider]
 [testSearchSuggestions]
 [testThumbnails]
+[testAddonManager]
 # [testPermissions] # see bug 757475
 # [testJarReader] # see bug 738890
 
 # Used for Talos, please don't use in mochitest
 #[testPan]
 #[testCheck]
 #[testCheck2]
 #[testCheck3]
new file mode 100755
--- /dev/null
+++ b/mobile/android/base/tests/testAddonManager.java.in
@@ -0,0 +1,87 @@
+#filter substitution
+package @ANDROID_PACKAGE_NAME@.tests;
+
+import @ANDROID_PACKAGE_NAME@.*;
+import android.app.Activity;
+import android.view.MenuItem;
+import android.widget.TextView;
+import android.widget.TabHost;
+import android.content.ContentResolver;
+import android.app.Instrumentation;
+import android.util.DisplayMetrics;
+
+public class testAddonManager extends PixelTest  {
+    Actions.EventExpecter tabEventExpecter;
+    Actions.EventExpecter contentEventExpecter;
+    String url = "about:addons";
+
+    @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() {
+        mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
+
+        // 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();
+
+        // 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");
+
+        // 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();
+
+        // Verify tab count has increased
+        verifyTabCount(2);
+
+        // Verify the page was opened
+        verifyPageTitle("Add-ons for Android");
+
+        // Addons Manager is not opened 2 separate times when opened from the menu
+        selectMenuItem("Add-ons");        
+        contentEventExpecter.blockForEvent();
+
+        // Verify tab count not increased
+        verifyTabCount(2);
+    }
+}