Bug 1339066 - Don't add a private tab opened while viewing the normal-mode tab strip. r=sebastian, a=lizzard
authorTom Klein <twointofive@gmail.com>
Thu, 16 Feb 2017 07:25:54 -0600
changeset 378691 e5d37ee6a1d0954a6add1c740143b53aa48b00bc
parent 378690 e49433bc9adad6bb7ec4a809d299b19ac9459a35
child 378692 48b049856be44ea59113efa763d8b30e9720cbf9
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1339066
milestone53.0a2
Bug 1339066 - Don't add a private tab opened while viewing the normal-mode tab strip. r=sebastian, a=lizzard MozReview-Commit-ID: AZEZq4boaJW
mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
mobile/android/tests/browser/robocop/robocop.ini
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/TabStripComponent.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/helpers/GeckoClickHelper.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testTabStripPrivacyMode.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
@@ -85,16 +85,20 @@ public class TabStripView extends Recycl
     }
 
     /* package */ void restoreTabs() {
         refreshTabs();
         animateRestoredTabs();
     }
 
     /* package */ void addTab(Tab tab, int position) {
+        if (tab.isPrivate() != isPrivate) {
+            return;
+        }
+
         adapter.addTab(tab, position);
         position = position == -1 ? adapter.getItemCount() - 1 : position;
         if (position == 0 || position == adapter.getItemCount() - 1) {
             // A new first or last tab gets added off screen, so scroll to make it visible.
             scrollToPosition(position);
         }
     }
 
--- a/mobile/android/tests/browser/robocop/robocop.ini
+++ b/mobile/android/tests/browser/robocop/robocop.ini
@@ -102,16 +102,17 @@ skip-if = android_version == "18"
 [src/org/mozilla/gecko/tests/testInputConnection.java]
 [src/org/mozilla/gecko/tests/testJavascriptBridge.java]
 [src/org/mozilla/gecko/tests/testReaderCacheMigration.java]
 [src/org/mozilla/gecko/tests/testReadingListToBookmarksMigration.java]
 [src/org/mozilla/gecko/tests/testNativeCrypto.java]
 [src/org/mozilla/gecko/tests/testReaderModeTitle.java]
 [src/org/mozilla/gecko/tests/testSessionHistory.java]
 [src/org/mozilla/gecko/tests/testStateWhileLoading.java]
+[src/org/mozilla/gecko/tests/testTabStripPrivacyMode.java]
 [src/org/mozilla/gecko/tests/testUnifiedTelemetryClientId.java]
 
 [src/org/mozilla/gecko/tests/testAccessibleCarets.java]
 
 # testStumblerSetting disabled on Android 4.3, bug 1145846
 [src/org/mozilla/gecko/tests/testStumblerSetting.java]
 skip-if = android_version == "18"
 
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/TabStripComponent.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/TabStripComponent.java
@@ -17,16 +17,21 @@ import static org.mozilla.gecko.tests.he
 public class TabStripComponent extends BaseComponent {
     // Using a text id because the layout and therefore the id might be stripped from the (non-tablet) build
     private static final String TAB_STRIP_ID = "tab_strip";
 
     public TabStripComponent(final UITestContext testContext) {
         super(testContext);
     }
 
+    public TabStripComponent assertTabCount(int count) {
+        fAssertEquals("The tab strip tab count is " + count, count, getTabStripView().getAdapter().getItemCount());
+        return this;
+    }
+
     public void switchToTab(int index) {
         // The tab strip is only available on tablets
         DeviceHelper.assertIsTablet();
 
         View tabView = waitForTabView(index);
         fAssertNotNull(String.format("Tab at index %d is not null", index), tabView);
 
         mSolo.clickOnView(tabView);
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/helpers/GeckoClickHelper.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/helpers/GeckoClickHelper.java
@@ -33,16 +33,29 @@ public class GeckoClickHelper {
      */
     public static void openCentralizedLinkInNewTab() {
         openLinkContextMenu();
 
         // Click on "Open Link in New Tab"
         sSolo.clickOnText(StringHelper.get().CONTEXT_MENU_ITEMS_IN_NORMAL_TAB[0]);
     }
 
+    /**
+     * Long press the link and select "Open Link in New Private Tab" from the context menu.
+     *
+     * The link should be positioned at the top of the page, at least 60px high and
+     * aligned to the middle.
+     */
+    public static void openCentralizedLinkInNewPrivateTab() {
+        openLinkContextMenu();
+
+        // Click on "Open Link in New Private Tab"
+        sSolo.clickOnText(StringHelper.get().CONTEXT_MENU_ITEMS_IN_NORMAL_TAB[1]);
+    }
+
     private static void openLinkContextMenu() {
         DisplayMetrics dm = new DisplayMetrics();
         sActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
 
         sSolo.clickLongOnScreen(
                 sDriver.getGeckoLeft() + sDriver.getGeckoWidth() / 2,
                 sDriver.getGeckoTop() + 30 * dm.density
         );
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testTabStripPrivacyMode.java
@@ -0,0 +1,42 @@
+package org.mozilla.gecko.tests;
+
+import org.mozilla.gecko.Actions;
+import org.mozilla.gecko.tests.helpers.DeviceHelper;
+import org.mozilla.gecko.tests.helpers.GeckoClickHelper;
+import org.mozilla.gecko.tests.helpers.GeckoHelper;
+import org.mozilla.gecko.tests.helpers.NavigationHelper;
+import org.mozilla.gecko.tests.helpers.WaitHelper;
+
+/**
+ * Make sure that a private tab opened while the tab strip is in normal mode does not get added to
+ * the tab strip (bug 1339066).
+ */
+public class testTabStripPrivacyMode extends UITest {
+    public void testTabStripPrivacyMode() {
+        if (!DeviceHelper.isTablet()) {
+            return;
+        }
+
+        GeckoHelper.blockForReady();
+
+        final String normalModeUrl = mStringHelper.ROBOCOP_BIG_LINK_URL;
+        NavigationHelper.enterAndLoadUrl(normalModeUrl);
+
+        final Actions.EventExpecter titleExpecter = mActions.expectGlobalEvent(Actions.EventType.UI, "Content:DOMTitleChanged");
+        GeckoClickHelper.openCentralizedLinkInNewPrivateTab();
+
+        titleExpecter.blockForEvent();
+        titleExpecter.unregisterListener();
+        // In the passing version of this test the UI shouldn't change at all in response to the
+        // new private tab, but to prevent a false positive when the private tab does get added to
+        // the tab strip in error, sleep here to make sure the UI has time to update before we
+        // check it.
+        mSolo.sleep(250);
+
+        // Now make sure there's still only one tab in the tab strip, and that it's still the normal
+        // mode tab.
+
+        mTabStrip.assertTabCount(1);
+        mToolbar.assertTitle(normalModeUrl);
+    }
+ }