Bug 1022801 - Don't visit support.mozilla.org in testBookmarksPanel. r=mcomella, a=test-only
authorGeoff Brown <gbrown@mozilla.com>
Wed, 11 Jun 2014 19:41:10 -0600
changeset 208078 8415553664fdb087817d28de7d33b8e6dd203980
parent 208077 e59ad1a713fa997cb69501360f5860987a4a463e
child 208079 e161f3e3b3325bcb29dfc9eb8d9faf27765f1d5b
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, test-only
bugs1022801
milestone32.0a2
Bug 1022801 - Don't visit support.mozilla.org in testBookmarksPanel. r=mcomella, a=test-only
mobile/android/base/Tabs.java
mobile/android/base/tests/BaseTest.java
mobile/android/base/tests/testBookmarksPanel.java
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -286,30 +286,32 @@ public class Tabs implements GeckoEventL
         return tab != null && tab == mSelectedTab;
     }
 
     public boolean isSelectedTabId(int tabId) {
         final Tab selected = mSelectedTab;
         return selected != null && selected.getId() == tabId;
     }
 
+    @RobocopTarget
     public synchronized Tab getTab(int id) {
         if (id == -1)
             return null;
 
         if (mTabs.size() == 0)
             return null;
 
         if (!mTabs.containsKey(id))
            return null;
 
         return mTabs.get(id);
     }
 
     /** Close tab and then select the default next tab */
+    @RobocopTarget
     public synchronized void closeTab(Tab tab) {
         closeTab(tab, getNextTab(tab));
     }
 
     public synchronized void closeTab(Tab tab, Tab nextTab) {
         closeTab(tab, nextTab, false);
     }
 
--- a/mobile/android/base/tests/BaseTest.java
+++ b/mobile/android/base/tests/BaseTest.java
@@ -20,16 +20,17 @@ import org.mozilla.gecko.Element;
 import org.mozilla.gecko.FennecNativeActions;
 import org.mozilla.gecko.FennecNativeDriver;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.GeckoThread.LaunchState;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.RobocopUtils;
+import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 
 import android.app.Activity;
 import android.content.ContentValues;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.content.res.AssetManager;
 import android.database.Cursor;
@@ -231,16 +232,22 @@ abstract class BaseTest extends BaseRobo
         try {
             Tabs.getInstance().loadUrl(url);
         } catch (Exception e) {
             mAsserter.dumpLog("Exception in loadUrl", e);
             throw new RuntimeException(e);
         }
     }
 
+    protected final void closeTab(int tabId) {
+        Tabs tabs = Tabs.getInstance();
+        Tab tab = tabs.getTab(tabId);
+        tabs.closeTab(tab);
+    }
+
     public final void verifyUrl(String url) {
         final EditText urlEditText = (EditText) mSolo.getView(R.id.url_edit_text);
         String urlBarText = null;
         if (urlEditText != null) {
             // wait for a short time for the expected text, in case there is a delay
             // in updating the view
             waitForCondition(new VerifyTextViewText(urlEditText, url), VERIFY_URL_TIMEOUT);
             urlBarText = urlEditText.getText().toString();
--- a/mobile/android/base/tests/testBookmarksPanel.java
+++ b/mobile/android/base/tests/testBookmarksPanel.java
@@ -1,17 +1,20 @@
 package org.mozilla.gecko.tests;
 
+import org.json.JSONException;
+import org.json.JSONObject;
 import org.mozilla.gecko.Actions;
 import org.mozilla.gecko.Element;
 import org.mozilla.gecko.R;
 
 public class testBookmarksPanel extends AboutHomeTest {
     public void testBookmarksPanel() {
         final String BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
+        JSONObject data = null;
 
         // Add a mobile bookmark
         mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE, BOOKMARK_URL);
 
         openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
 
         // Check that the default bookmarks are displayed
         for (String url : StringHelper.DEFAULT_BOOKMARKS_URLS) {
@@ -26,27 +29,51 @@ public class testBookmarksPanel extends 
             mAsserter.ok(mSolo.searchText(contextMenuOption), "Checking that the context menu option is present", contextMenuOption + " is present");
         }
 
         // Test that "Open in New Tab" works
         final Element tabCount = mDriver.findElement(getActivity(), R.id.tabs_counter);
         final int tabCountInt = Integer.parseInt(tabCount.getText());
         Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
         mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0]);
-        tabEventExpecter.blockForEvent();
+        try {
+            data = new JSONObject(tabEventExpecter.blockForEventData());
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception getting event data", e.toString());
+        }
         tabEventExpecter.unregisterListener();
         mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
+        // extra check here on the Tab:Added message to be sure the right tab opened
+        int tabID = 0;
+        try {
+            mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
+            tabID = data.getInt("tabID");
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception accessing event data", e.toString());
+        }
+        // close tab so about:firefox can be selected again
+        closeTab(tabID);
 
         // Test that "Open in Private Tab" works
-        openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[1]);
+        openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]);
         tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
         mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[1]);
-        tabEventExpecter.blockForEvent();
+        try {
+            data = new JSONObject(tabEventExpecter.blockForEventData());
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception getting event data", e.toString());
+        }
         tabEventExpecter.unregisterListener();
         mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
+        // extra check here on the Tab:Added message to be sure the right tab opened, again
+        try {
+            mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception accessing event data", e.toString());
+        }
 
         // Test that "Edit" works
         String[] editedBookmarkValues = new String[] { "New bookmark title", "www.NewBookmark.url", "newBookmarkKeyword" };
         editBookmark(BOOKMARK_URL, editedBookmarkValues);
         checkBookmarkEdit(editedBookmarkValues[1], editedBookmarkValues);
 
         // Test that "Remove" works
         openBookmarkContextMenu(editedBookmarkValues[1]);