Commit 9dd1930a authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Updates TabSwitcherTransitionTest to work with the tab grid.

Modifies the test to use the TabSwitcherMode enum instead of checking
IsIPadIdiom().  Adds some EG matchers for various elements of the tab grid.

BUG=825431
TEST=None

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I29de41c895696627f37cc26b0c7853ab068f1834
Reviewed-on: https://chromium-review.googlesource.com/988273
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547435}
parent c88fd9da
...@@ -105,6 +105,27 @@ source_set("unit_tests") { ...@@ -105,6 +105,27 @@ source_set("unit_tests") {
] ]
} }
source_set("egtest_support") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"tab_grid_egtest_util.h",
"tab_grid_egtest_util.mm",
]
deps = [
":tab_grid_ui",
"//base",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/tools_menu/public",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/testing:ios_test_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ui/base",
]
}
source_set("eg_tests") { source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_EGTEST_UTIL_H_
#define IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_EGTEST_UTIL_H_
@protocol GREYMatcher;
namespace chrome_test_util {
// Returns the GREYMatcher for the button that opens the tab grid.
id<GREYMatcher> TabGridOpenButton();
// Returns the GREYMatcher for the button that closes the tab grid.
id<GREYMatcher> TabGridDoneButton();
// Returns the GREYMatcher for the button that creates new non incognito tabs
// from within the tab grid.
id<GREYMatcher> TabGridNewTabButton();
// Returns the GREYMatcher for the button that creates new incognito tabs from
// within the tab grid.
id<GREYMatcher> TabGridNewIncognitoTabButton();
// Returns the GREYMatcher for the button to go to the non incognito panel in
// the tab grid.
id<GREYMatcher> TabGridOpenTabsPanelButton();
// Returns the GREYMatcher for the button to go to the incognito panel in
// the tab grid.
id<GREYMatcher> TabGridIncognitoTabsPanelButton();
// Returns the GREYMatcher for the button to go to the other devices panel in
// the tab grid.
id<GREYMatcher> TabGridOtherDevicesPanelButton();
} // namespace chrome_test_util
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_EGTEST_UTIL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/tab_grid/tab_grid_egtest_util.h"
#import <EarlGrey/EarlGrey.h>
#import "ios/chrome/browser/ui/tab_grid/tab_grid_constants.h"
#import "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace chrome_test_util {
id<GREYMatcher> TabGridOpenButton() {
return ButtonWithAccessibilityLabelId(IDS_IOS_TAB_STRIP_ENTER_TAB_SWITCHER);
}
id<GREYMatcher> TabGridDoneButton() {
return grey_allOf(grey_accessibilityID(kTabGridDoneButtonIdentifier),
grey_sufficientlyVisible(), nil);
}
id<GREYMatcher> TabGridNewTabButton() {
return grey_allOf(
ButtonWithAccessibilityLabelId(IDS_IOS_TAB_GRID_CREATE_NEW_TAB),
grey_sufficientlyVisible(), nil);
}
id<GREYMatcher> TabGridNewIncognitoTabButton() {
return grey_allOf(
ButtonWithAccessibilityLabelId(IDS_IOS_TAB_GRID_CREATE_NEW_INCOGNITO_TAB),
grey_sufficientlyVisible(), nil);
}
id<GREYMatcher> TabGridOpenTabsPanelButton() {
return grey_accessibilityID(kTabGridRegularTabsPageButtonIdentifier);
}
id<GREYMatcher> TabGridIncognitoTabsPanelButton() {
return grey_accessibilityID(kTabGridIncognitoTabsPageButtonIdentifier);
}
id<GREYMatcher> TabGridOtherDevicesPanelButton() {
return grey_accessibilityID(kTabGridRemoteTabsPageButtonIdentifier);
}
} // namespace chrome_test_util
...@@ -205,6 +205,7 @@ source_set("eg_tests") { ...@@ -205,6 +205,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/authentication:eg_test_support", "//ios/chrome/browser/ui/authentication:eg_test_support",
"//ios/chrome/browser/ui/tab_grid:egtest_support",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin:test_support", "//ios/public/provider/chrome/browser/signin:test_support",
......
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "ios/chrome/app/main_controller.h" #import "ios/chrome/app/main_controller.h"
#import "ios/chrome/browser/tabs/tab_model.h" #import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_egtest_util.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_egtest_util.h" #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_egtest_util.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_mode.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h"
#import "ios/chrome/browser/ui/ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h" #import "ios/chrome/test/app/tab_test_util.h"
...@@ -29,6 +30,12 @@ ...@@ -29,6 +30,12 @@
#endif #endif
using chrome_test_util::ButtonWithAccessibilityLabelId; using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::TabGridDoneButton;
using chrome_test_util::TabGridIncognitoTabsPanelButton;
using chrome_test_util::TabGridNewIncognitoTabButton;
using chrome_test_util::TabGridNewTabButton;
using chrome_test_util::TabGridOpenButton;
using chrome_test_util::TabGridOpenTabsPanelButton;
using chrome_test_util::TabletTabSwitcherCloseButton; using chrome_test_util::TabletTabSwitcherCloseButton;
using chrome_test_util::TabletTabSwitcherIncognitoTabsPanelButton; using chrome_test_util::TabletTabSwitcherIncognitoTabsPanelButton;
using chrome_test_util::TabletTabSwitcherNewIncognitoTabButton; using chrome_test_util::TabletTabSwitcherNewIncognitoTabButton;
...@@ -48,10 +55,16 @@ TabModel* GetNormalTabModel() { ...@@ -48,10 +55,16 @@ TabModel* GetNormalTabModel() {
// and tablet. // and tablet.
void ShowTabSwitcher() { void ShowTabSwitcher() {
id<GREYMatcher> matcher = nil; id<GREYMatcher> matcher = nil;
if (IsIPadIdiom()) { switch (GetTabSwitcherMode()) {
matcher = TabletTabSwitcherOpenButton(); case TabSwitcherMode::STACK:
} else { matcher = chrome_test_util::ShowTabsButton();
matcher = chrome_test_util::ShowTabsButton(); break;
case TabSwitcherMode::TABLET_SWITCHER:
matcher = TabletTabSwitcherOpenButton();
break;
case TabSwitcherMode::GRID:
matcher = TabGridOpenButton();
break;
} }
DCHECK(matcher); DCHECK(matcher);
...@@ -76,10 +89,16 @@ void ShowTabSwitcher() { ...@@ -76,10 +89,16 @@ void ShowTabSwitcher() {
// and tablet. // and tablet.
void ShowTabViewController() { void ShowTabViewController() {
id<GREYMatcher> matcher = nil; id<GREYMatcher> matcher = nil;
if (IsIPadIdiom()) { switch (GetTabSwitcherMode()) {
matcher = TabletTabSwitcherCloseButton(); case TabSwitcherMode::STACK:
} else { matcher = chrome_test_util::ShowTabsButton();
matcher = chrome_test_util::ShowTabsButton(); break;
case TabSwitcherMode::TABLET_SWITCHER:
matcher = TabletTabSwitcherCloseButton();
break;
case TabSwitcherMode::GRID:
matcher = TabGridDoneButton();
break;
} }
DCHECK(matcher); DCHECK(matcher);
...@@ -88,23 +107,35 @@ void ShowTabViewController() { ...@@ -88,23 +107,35 @@ void ShowTabViewController() {
// Selects and focuses the tab with the given |title|. // Selects and focuses the tab with the given |title|.
void SelectTab(NSString* title) { void SelectTab(NSString* title) {
if (IsIPadIdiom()) { switch (GetTabSwitcherMode()) {
// The UILabel containing the tab's title is not tappable, but its parent case TabSwitcherMode::STACK:
// TabSwitcherLocalSessionCell is. // In the stack view, tapping on the title UILabel will select the tab.
[[EarlGrey [[EarlGrey
selectElementWithMatcher:grey_allOf( selectElementWithMatcher:grey_allOf(
grey_kindOfClass( grey_accessibilityLabel(title),
[TabSwitcherLocalSessionCell class]), grey_accessibilityTrait(
grey_descendant(grey_text(title)), UIAccessibilityTraitStaticText),
grey_sufficientlyVisible(), nil)] nil)] performAction:grey_tap()];
performAction:grey_tap()]; break;
} else { case TabSwitcherMode::TABLET_SWITCHER:
// On phone, tapping on the title UILabel will select the tab. // In the tablet tab switcher, the UILabel containing the tab's title is
[[EarlGrey // not tappable, but its parent TabSwitcherLocalSessionCell is.
selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(title), [[EarlGrey
grey_accessibilityTrait( selectElementWithMatcher:grey_allOf(
UIAccessibilityTraitStaticText), grey_kindOfClass(
nil)] performAction:grey_tap()]; [TabSwitcherLocalSessionCell class]),
grey_descendant(grey_text(title)),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
break;
case TabSwitcherMode::GRID:
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityLabel(title),
grey_accessibilityTrait(
UIAccessibilityTraitStaticText),
nil)] performAction:grey_tap()];
break;
} }
} }
...@@ -234,24 +265,30 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -234,24 +265,30 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Enter the switcher and open a new tab using the new tab button. // Enter the switcher and open a new tab using the new tab button.
ShowTabSwitcher(); ShowTabSwitcher();
if (IsIPadIdiom()) { id<GREYMatcher> matcher = nil;
[[EarlGrey selectElementWithMatcher:TabletTabSwitcherNewTabButton()] switch (GetTabSwitcherMode()) {
performAction:grey_tap()]; case TabSwitcherMode::STACK:
} else { matcher = ButtonWithAccessibilityLabelId(IDS_IOS_TOOLS_MENU_NEW_TAB);
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId( break;
IDS_IOS_TOOLS_MENU_NEW_TAB)] case TabSwitcherMode::TABLET_SWITCHER:
performAction:grey_tap()]; matcher = TabletTabSwitcherNewTabButton();
break;
case TabSwitcherMode::GRID:
matcher = TabGridNewTabButton();
break;
} }
DCHECK(matcher);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
// Load a URL in this newly-created tab and verify that the tab is visible. // Load a URL in this newly-created tab and verify that the tab is visible.
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab1_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab1_title]];
[ChromeEarlGrey [ChromeEarlGrey
waitForWebViewContainingText:base::SysNSStringToUTF8(tab1_title)]; waitForWebViewContainingText:base::SysNSStringToUTF8(tab1_title)];
if (!IsIPadIdiom()) { if (GetTabSwitcherMode() == TabSwitcherMode::STACK) {
// On phone, enter the switcher again and open a new tab using the tools // When the stack view is in use, enter the switcher again and open a new
// menu. This does not apply on tablet because there is no tools menu // tab using the tools menu. This does not apply for other switcher modes
// in the switcher. // because they do not show a tools menu in the switcher.
ShowTabSwitcher(); ShowTabSwitcher();
[ChromeEarlGreyUI openNewTab]; [ChromeEarlGreyUI openNewTab];
...@@ -275,26 +312,31 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -275,26 +312,31 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Enter the switcher and open a new incognito tab using the new tab button. // Enter the switcher and open a new incognito tab using the new tab button.
ShowTabSwitcher(); ShowTabSwitcher();
if (IsIPadIdiom()) { id<GREYMatcher> matcher = nil;
[[EarlGrey switch (GetTabSwitcherMode()) {
selectElementWithMatcher:TabletTabSwitcherNewIncognitoTabButton()] case TabSwitcherMode::STACK:
performAction:grey_tap()]; matcher =
} else { ButtonWithAccessibilityLabelId(IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB);
[[EarlGrey break;
selectElementWithMatcher:ButtonWithAccessibilityLabelId( case TabSwitcherMode::TABLET_SWITCHER:
IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)] matcher = TabletTabSwitcherNewIncognitoTabButton();
performAction:grey_tap()]; break;
case TabSwitcherMode::GRID:
matcher = TabGridNewIncognitoTabButton();
break;
} }
DCHECK(matcher);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
// Load a URL in this newly-created tab and verify that the tab is visible. // Load a URL in this newly-created tab and verify that the tab is visible.
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab1_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab1_title]];
[ChromeEarlGrey [ChromeEarlGrey
waitForWebViewContainingText:base::SysNSStringToUTF8(tab1_title)]; waitForWebViewContainingText:base::SysNSStringToUTF8(tab1_title)];
if (!IsIPadIdiom()) { if (GetTabSwitcherMode() == TabSwitcherMode::STACK) {
// On phone, enter the switcher again and open a new incognito tab using the // When the stack view is in use, enter the switcher again and open a new
// tools menu. This does not apply on tablet because there is no tools menu // incognito tab using the tools menu. This does not apply for other
// in the switcher. // switcher modes because they do not show a tools menu in the switcher.
ShowTabSwitcher(); ShowTabSwitcher();
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
...@@ -313,15 +355,24 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -313,15 +355,24 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Go from normal mode to incognito mode. // Go from normal mode to incognito mode.
ShowTabSwitcher(); ShowTabSwitcher();
if (IsIPadIdiom()) { switch (GetTabSwitcherMode()) {
[[EarlGrey case TabSwitcherMode::STACK:
selectElementWithMatcher:TabletTabSwitcherIncognitoTabsPanelButton()] [ChromeEarlGreyUI openNewIncognitoTab];
performAction:grey_tap()]; break;
[[EarlGrey case TabSwitcherMode::TABLET_SWITCHER:
selectElementWithMatcher:TabletTabSwitcherNewIncognitoTabButton()] [[EarlGrey
performAction:grey_tap()]; selectElementWithMatcher:TabletTabSwitcherIncognitoTabsPanelButton()]
} else { performAction:grey_tap()];
[ChromeEarlGreyUI openNewIncognitoTab]; [[EarlGrey
selectElementWithMatcher:TabletTabSwitcherNewIncognitoTabButton()]
performAction:grey_tap()];
break;
case TabSwitcherMode::GRID:
[[EarlGrey selectElementWithMatcher:TabGridIncognitoTabsPanelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:TabGridNewIncognitoTabButton()]
performAction:grey_tap()];
break;
} }
// Load a URL in this newly-created tab and verify that the tab is visible. // Load a URL in this newly-created tab and verify that the tab is visible.
...@@ -331,13 +382,23 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -331,13 +382,23 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Go from incognito mode to normal mode. // Go from incognito mode to normal mode.
ShowTabSwitcher(); ShowTabSwitcher();
if (IsIPadIdiom()) { switch (GetTabSwitcherMode()) {
[[EarlGrey selectElementWithMatcher:TabletTabSwitcherOpenTabsPanelButton()] case TabSwitcherMode::STACK:
performAction:grey_tap()]; [ChromeEarlGreyUI openNewTab];
[[EarlGrey selectElementWithMatcher:TabletTabSwitcherNewTabButton()] break;
performAction:grey_tap()]; case TabSwitcherMode::TABLET_SWITCHER:
} else { [[EarlGrey
[ChromeEarlGreyUI openNewTab]; selectElementWithMatcher:TabletTabSwitcherOpenTabsPanelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:TabletTabSwitcherNewTabButton()]
performAction:grey_tap()];
break;
case TabSwitcherMode::GRID:
[[EarlGrey selectElementWithMatcher:TabGridOpenTabsPanelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:TabGridNewTabButton()]
performAction:grey_tap()];
break;
} }
// Load a URL in this newly-created tab and verify that the tab is visible. // Load a URL in this newly-created tab and verify that the tab is visible.
...@@ -410,39 +471,60 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -410,39 +471,60 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey loadURL:[self makeURLForTitle:incognito_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:incognito_title]];
ShowTabSwitcher(); ShowTabSwitcher();
if (IsIPadIdiom()) { switch (GetTabSwitcherMode()) {
// On tablet, switch to the normal panel and select the one tab that is case TabSwitcherMode::STACK:
// there. // In the stack view, get to the normal card stack by swiping right on the
[[EarlGrey selectElementWithMatcher:TabletTabSwitcherOpenTabsPanelButton()] // current incognito card.
performAction:grey_tap()]; [[EarlGrey
} else { selectElementWithMatcher:grey_allOf(
// On phone, get to the normal card stack by swiping right on the current grey_accessibilityLabel(incognito_title),
// incognito card. grey_accessibilityTrait(
[[EarlGrey UIAccessibilityTraitStaticText),
selectElementWithMatcher:grey_allOf( nil)]
grey_accessibilityLabel(incognito_title), performAction:grey_swipeFastInDirection(kGREYDirectionRight)];
grey_accessibilityTrait( break;
UIAccessibilityTraitStaticText), case TabSwitcherMode::TABLET_SWITCHER:
nil)] // In the tablet tab switcher, switch to the normal panel and select the
performAction:grey_swipeFastInDirection(kGREYDirectionRight)]; // one tab that is there.
[[EarlGrey
selectElementWithMatcher:TabletTabSwitcherOpenTabsPanelButton()]
performAction:grey_tap()];
break;
case TabSwitcherMode::GRID:
// In the tab grid, switch to the normal panel and select the one tab that
// is there.
[[EarlGrey selectElementWithMatcher:TabGridOpenTabsPanelButton()]
performAction:grey_tap()];
break;
} }
SelectTab(normal_title); SelectTab(normal_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebViewContainingText:base::SysNSStringToUTF8(normal_title)]; waitForWebViewContainingText:base::SysNSStringToUTF8(normal_title)];
ShowTabSwitcher(); ShowTabSwitcher();
if (IsIPadIdiom()) { switch (GetTabSwitcherMode()) {
// On tablet, switch to the incognito panel and select the one tab that is case TabSwitcherMode::STACK:
// there. // In the stack view, get to the incognito card stack by tapping on the
[[EarlGrey // partially-visible incognito card. It will need to be tapped a second
selectElementWithMatcher:TabletTabSwitcherIncognitoTabsPanelButton()] // time to actually select it.
performAction:grey_tap()]; SelectTab(incognito_title);
} else { break;
// On phone, get to the incognito card stack by tapping on the case TabSwitcherMode::TABLET_SWITCHER:
// partially-visible incognito card. It will need to be tapped a second // In the tablet tab switcher, switch to the incognito panel and select
// time to actually select it. // the one tab that is there.
SelectTab(incognito_title); [[EarlGrey
selectElementWithMatcher:TabletTabSwitcherIncognitoTabsPanelButton()]
performAction:grey_tap()];
break;
case TabSwitcherMode::GRID:
// In the tab grid, switch to the incognito panel and select the one tab
// that is there.
[[EarlGrey selectElementWithMatcher:TabGridIncognitoTabsPanelButton()]
performAction:grey_tap()];
break;
} }
SelectTab(incognito_title); SelectTab(incognito_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebViewContainingText:base::SysNSStringToUTF8(incognito_title)]; waitForWebViewContainingText:base::SysNSStringToUTF8(incognito_title)];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment