Commit 4a8424da authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Fixes TabUsageRecorderTest when the UIRefresh flag is enabled.

Updates the egtest utils to support the new TabGrid.  Adds a temporary
workaround for a TabGrid bug.

BUG=818732,836312

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I66efdbcfce9318a7245463cb2cf7d4f0592ed5de
Reviewed-on: https://chromium-review.googlesource.com/1026411
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553547}
parent 61f756c9
...@@ -220,9 +220,16 @@ source_set("test_support") { ...@@ -220,9 +220,16 @@ source_set("test_support") {
] ]
deps = [ deps = [
"//base", "//base",
"//ios/chrome/app:app_internal",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/tab_grid:egtest_support",
"//ios/chrome/browser/ui/tab_switcher:egtest_support",
"//ios/chrome/browser/ui/tab_switcher:modes",
"//ios/chrome/browser/ui/tools_menu/public", "//ios/chrome/browser/ui/tools_menu/public",
"//ios/chrome/browser/web_state_list",
"//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/testing:ios_test_support", "//ios/testing:ios_test_support",
......
...@@ -83,12 +83,6 @@ void Wait(id<GREYMatcher> matcher, NSString* name) { ...@@ -83,12 +83,6 @@ void Wait(id<GREYMatcher> matcher, NSString* name) {
@"Waiting for matcher %@ failed.", name); @"Waiting for matcher %@ failed.", name);
} }
// Wait until |matcher| is accessible (not nil) and tap on it.
void WaitAndTap(id<GREYMatcher> matcher, NSString* name) {
Wait(matcher, name);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
}
// Creates a new main tab and load |url|. Wait until |word| is visible on the // Creates a new main tab and load |url|. Wait until |word| is visible on the
// page. // page.
void NewMainTabWithURL(const GURL& url, const std::string& word) { void NewMainTabWithURL(const GURL& url, const std::string& word) {
...@@ -112,19 +106,6 @@ void OpenTwoTabs() { ...@@ -112,19 +106,6 @@ void OpenTwoTabs() {
NewMainTabWithURL(url2, kURL2FirstWord); NewMainTabWithURL(url2, kURL2FirstWord);
} }
// Opens a new main tab using the UI. This method is using ad-hoc
// synchronization.
void OpenNewMainTabUsingUIUnsynced() {
int nb_main_tab = chrome_test_util::GetMainTabCount();
id<GREYMatcher> tool_menu_matcher =
grey_accessibilityID(kToolbarToolsMenuButtonIdentifier);
WaitAndTap(tool_menu_matcher, @"Tool menu");
id<GREYMatcher> new_main_tab_button_matcher =
grey_accessibilityID(kToolsMenuNewTabId);
WaitAndTap(new_main_tab_button_matcher, @"New tab button");
[ChromeEarlGrey waitForMainTabCount:(nb_main_tab + 1)];
}
// Closes a tab in the current tab model. Synchronize on tab number afterwards. // Closes a tab in the current tab model. Synchronize on tab number afterwards.
void CloseTabAtIndexAndSync(NSUInteger i) { void CloseTabAtIndexAndSync(NSUInteger i) {
NSUInteger nb_main_tab = chrome_test_util::GetMainTabCount(); NSUInteger nb_main_tab = chrome_test_util::GetMainTabCount();
...@@ -458,6 +439,9 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -458,6 +439,9 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
SwitchToNormalMode(); SwitchToNormalMode();
// Letting page load start.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
// TODO(crbug.com/640977): EarlGrey synchronize on some animations when a // TODO(crbug.com/640977): EarlGrey synchronize on some animations when a
// page is loading. Need to handle synchronization manually for this test. // page is loading. Need to handle synchronization manually for this test.
[[GREYConfiguration sharedInstance] [[GREYConfiguration sharedInstance]
...@@ -465,12 +449,11 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -465,12 +449,11 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
forConfigKey:kGREYConfigKeySynchronizationEnabled]; forConfigKey:kGREYConfigKeySynchronizationEnabled];
// Make sure the button is here and displayed before tapping it. // Make sure the button is here and displayed before tapping it.
id<GREYMatcher> toolMenuMatcher = id<GREYMatcher> toolMenuMatcher =
grey_accessibilityID(kToolbarToolsMenuButtonIdentifier); grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier),
grey_sufficientlyVisible(), nil);
Wait(toolMenuMatcher, @"Tool Menu"); Wait(toolMenuMatcher, @"Tool Menu");
// Letting page load start.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
OpenNewMainTabUsingUIUnsynced(); chrome_test_util::OpenNewTab();
[[GREYConfiguration sharedInstance] [[GREYConfiguration sharedInstance]
setValue:@(YES) setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled]; forConfigKey:kGREYConfigKeySynchronizationEnabled];
...@@ -531,16 +514,18 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -531,16 +514,18 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
std::make_unique<HtmlResponseProvider>(responses), kSlowURLDelay)); std::make_unique<HtmlResponseProvider>(responses), kSlowURLDelay));
SwitchToNormalMode(); SwitchToNormalMode();
// Letting page load start.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
// TODO(crbug.com/640977): EarlGrey synchronize on some animations when a // TODO(crbug.com/640977): EarlGrey synchronize on some animations when a
// page is loading. Need to handle synchronization manually for this test. // page is loading. Need to handle synchronization manually for this test.
[[GREYConfiguration sharedInstance] [[GREYConfiguration sharedInstance]
setValue:@(NO) setValue:@(NO)
forConfigKey:kGREYConfigKeySynchronizationEnabled]; forConfigKey:kGREYConfigKeySynchronizationEnabled];
id<GREYMatcher> toolMenuMatcher = id<GREYMatcher> toolMenuMatcher =
grey_accessibilityID(kToolbarToolsMenuButtonIdentifier); grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier),
grey_sufficientlyVisible(), nil);
Wait(toolMenuMatcher, @"Tool Menu"); Wait(toolMenuMatcher, @"Tool Menu");
// Letting page load start.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
GREYAssertTrue(chrome_test_util::SimulateTabsBackgrounding(), GREYAssertTrue(chrome_test_util::SimulateTabsBackgrounding(),
@"Failed to simulate tab backgrounding."); @"Failed to simulate tab backgrounding.");
......
...@@ -10,8 +10,8 @@ namespace tab_usage_recorder_test_util { ...@@ -10,8 +10,8 @@ namespace tab_usage_recorder_test_util {
// Opens a new incognito tab using the UI and evicts any main tab model tabs. // Opens a new incognito tab using the UI and evicts any main tab model tabs.
void OpenNewIncognitoTabUsingUIAndEvictMainTabs(); void OpenNewIncognitoTabUsingUIAndEvictMainTabs();
// Switches to normal mode using swith button (iPad) or stack view (iPhone). // Switches to normal mode using the tab switcher and selects the
// Assumes current mode is Incognito. // previously-selected normal tab. Assumes current mode is Incognito.
void SwitchToNormalMode(); void SwitchToNormalMode();
} // namespace tab_usage_recorder_test_util } // namespace tab_usage_recorder_test_util
......
...@@ -7,9 +7,17 @@ ...@@ -7,9 +7,17 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "base/ios/block_types.h" #import "base/ios/block_types.h"
#import "ios/chrome/app/main_controller.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/main/browser_view_information.h"
#include "ios/chrome/browser/ui/tab_grid/tab_grid_egtest_util.h"
#include "ios/chrome/browser/ui/tab_switcher/tab_switcher_egtest_util.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_mode.h"
#include "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h" #include "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#include "ios/chrome/browser/web_state_list/web_state_list.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/tab_test_util.h" #import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
...@@ -26,10 +34,56 @@ namespace { ...@@ -26,10 +34,56 @@ namespace {
// The delay to wait for an element to appear before tapping on it. // The delay to wait for an element to appear before tapping on it.
const NSTimeInterval kWaitElementTimeout = 3; const NSTimeInterval kWaitElementTimeout = 3;
// Shows the tab switcher by tapping the switcher button. Works on both phone
// and tablet.
void ShowTabSwitcher() {
id<GREYMatcher> matcher = nil;
switch (GetTabSwitcherMode()) {
case TabSwitcherMode::STACK:
matcher = chrome_test_util::ShowTabsButton();
break;
case TabSwitcherMode::TABLET_SWITCHER:
matcher = chrome_test_util::TabletTabSwitcherOpenButton();
break;
case TabSwitcherMode::GRID:
matcher = chrome_test_util::TabGridOpenButton();
break;
}
DCHECK(matcher);
// Perform a tap with a timeout. Occasionally EG doesn't sync up properly to
// the animations of tab switcher, so it is necessary to poll here.
GREYCondition* tapTabSwitcher =
[GREYCondition conditionWithName:@"Tap tab switcher button"
block:^BOOL {
NSError* error;
[[EarlGrey selectElementWithMatcher:matcher]
performAction:grey_tap()
error:&error];
return error == nil;
}];
// Wait until 2 seconds for the tap.
BOOL hasClicked = [tapTabSwitcher waitWithTimeout:2];
GREYAssertTrue(hasClicked, @"Tab switcher could not be tapped.");
}
// Closes the tabs switcher. // Closes the tabs switcher.
void CloseTabSwitcher() { void CloseTabSwitcher() {
id<GREYMatcher> matcher = chrome_test_util::ButtonWithAccessibilityLabelId( id<GREYMatcher> matcher = nil;
IDS_IOS_TAB_STRIP_LEAVE_TAB_SWITCHER); switch (GetTabSwitcherMode()) {
case TabSwitcherMode::STACK:
matcher = chrome_test_util::ShowTabsButton();
break;
case TabSwitcherMode::TABLET_SWITCHER:
matcher = chrome_test_util::TabletTabSwitcherCloseButton();
break;
case TabSwitcherMode::GRID:
matcher = chrome_test_util::TabGridDoneButton();
break;
}
DCHECK(matcher);
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
} }
...@@ -57,31 +111,36 @@ void OpenNewIncognitoTabUsingUIAndEvictMainTabs() { ...@@ -57,31 +111,36 @@ void OpenNewIncognitoTabUsingUIAndEvictMainTabs() {
void SwitchToNormalMode() { void SwitchToNormalMode() {
GREYAssertTrue(chrome_test_util::IsIncognitoMode(), GREYAssertTrue(chrome_test_util::IsIncognitoMode(),
@"Switching to normal mode is only allowed from Incognito."); @"Switching to normal mode is only allowed from Incognito.");
if (IsIPadIdiom()) {
// Enter the tab switcher. // Enter the tab switcher to switch modes.
id<GREYMatcher> tabSwitcherEnterButton = grey_accessibilityLabel( ShowTabSwitcher();
l10n_util::GetNSStringWithFixup(IDS_IOS_TAB_STRIP_ENTER_TAB_SWITCHER));
[[EarlGrey selectElementWithMatcher:tabSwitcherEnterButton] // Switch modes and exit the tab switcher.
performAction:grey_tap()]; switch (GetTabSwitcherMode()) {
case TabSwitcherMode::STACK:
// Select the non incognito panel. [[EarlGrey selectElementWithMatcher:
id<GREYMatcher> tabSwitcherHeaderPanelButton = chrome_test_util::ButtonWithAccessibilityLabelId(
grey_accessibilityLabel(l10n_util::GetNSStringWithFixup( IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)]
IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS)); performAction:grey_swipeSlowInDirection(kGREYDirectionRight)];
[[EarlGrey selectElementWithMatcher:tabSwitcherHeaderPanelButton] CloseTabSwitcher();
performAction:grey_tap()]; break;
case TabSwitcherMode::TABLET_SWITCHER:
// Leave the tab switcher. [[EarlGrey selectElementWithMatcher:
CloseTabSwitcher(); chrome_test_util::TabletTabSwitcherOpenTabsPanelButton()]
} else { performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] CloseTabSwitcher();
performAction:grey_tap()]; break;
[[EarlGrey selectElementWithMatcher: case TabSwitcherMode::GRID:
chrome_test_util::ButtonWithAccessibilityLabelId( TabModel* model = [[chrome_test_util::GetMainController()
IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)] browserViewInformation] mainTabModel];
performAction:grey_swipeSlowInDirection(kGREYDirectionRight)]; const int tab_index = model.webStateList->active_index();
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
performAction:grey_tap()]; TabGridOpenTabsPanelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCellAtIndex(
tab_index)]
performAction:grey_tap()];
break;
} }
// Turn off synchronization of GREYAssert to test the pending states. // Turn off synchronization of GREYAssert to test the pending states.
......
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