Bug 1339066 - Don't add a private tab opened while viewing the normal-mode tab strip. r=sebastian

MozReview-Commit-ID: AZEZq4boaJW

--HG--
extra : rebase_source : de6fad976ce5227af441a0c6386e36658bfe83c8
This commit is contained in:
Tom Klein 2017-02-16 07:25:54 -06:00
parent 806e31d5b2
commit 4f68f40cfe
5 changed files with 65 additions and 0 deletions

View File

@ -90,6 +90,10 @@ public class TabStripView extends RecyclerView {
}
/* 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) {

View File

@ -106,6 +106,7 @@ skip-if = android_version == "18"
[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]

View File

@ -22,6 +22,11 @@ public class TabStripComponent extends BaseComponent {
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 File

@ -38,6 +38,19 @@ public class GeckoClickHelper {
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);

View File

@ -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);
}
}