Commit 158ff1c1 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Deflake and consolidate more tab grid button flake.

For some reason this button constantly gets a long press when it
should be a tap.  Consolidate this hack.

Change-Id: Ia6f0f36d9e2aea79673ac0c74fc0d95289d0b043
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892220Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Auto-Submit: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711596}
parent bb1664c2
...@@ -35,26 +35,6 @@ namespace { ...@@ -35,26 +35,6 @@ 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.
bool ShowTabSwitcher() {
id<GREYMatcher> matcher = chrome_test_util::TabGridOpenButton();
// 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.
return [tapTabSwitcher waitWithTimeout:2];
}
} // namespace } // namespace
namespace tab_usage_recorder_test_util { namespace tab_usage_recorder_test_util {
...@@ -83,7 +63,7 @@ void SwitchToNormalMode() { ...@@ -83,7 +63,7 @@ void SwitchToNormalMode() {
@"Switching to normal mode is only allowed from Incognito."); @"Switching to normal mode is only allowed from Incognito.");
// Enter the tab grid to switch modes. // Enter the tab grid to switch modes.
GREYAssertTrue(ShowTabSwitcher(), @"Tab switcher could not be tapped."); [ChromeEarlGrey showTabSwitcher];
// Switch modes and exit the tab grid. // Switch modes and exit the tab grid.
TabModel* model = chrome_test_util::GetMainController() TabModel* model = chrome_test_util::GetMainController()
......
...@@ -30,29 +30,6 @@ using chrome_test_util::TabGridOpenTabsPanelButton; ...@@ -30,29 +30,6 @@ using chrome_test_util::TabGridOpenTabsPanelButton;
namespace { namespace {
// Shows the tab switcher by tapping the switcher button. Works on both phone
// and tablet.
void ShowTabSwitcher() {
id<GREYMatcher> matcher = TabGridOpenButton();
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 clicked.");
}
// Hides the tab switcher by tapping the switcher button. Works on both phone // Hides the tab switcher by tapping the switcher button. Works on both phone
// and tablet. // and tablet.
void ShowTabViewController() { void ShowTabViewController() {
...@@ -118,23 +95,21 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -118,23 +95,21 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Tests entering the tab switcher when one normal tab is open. // Tests entering the tab switcher when one normal tab is open.
- (void)testEnterSwitcherWithOneNormalTab { - (void)testEnterSwitcherWithOneNormalTab {
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
} }
// Tests entering the tab switcher when more than one normal tab is open. // Tests entering the tab switcher when more than one normal tab is open.
- (void)testEnterSwitcherWithMultipleNormalTabs { - (void)testEnterSwitcherWithMultipleNormalTabs {
[ChromeEarlGreyUI openNewTab]; [ChromeEarlGreyUI openNewTab];
[ChromeEarlGreyUI openNewTab]; [ChromeEarlGreyUI openNewTab];
[ChromeEarlGrey showTabSwitcher];
ShowTabSwitcher();
} }
// Tests entering the tab switcher when one incognito tab is open. // Tests entering the tab switcher when one incognito tab is open.
- (void)testEnterSwitcherWithOneIncognitoTab { - (void)testEnterSwitcherWithOneIncognitoTab {
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGrey closeAllNormalTabs]; [ChromeEarlGrey closeAllNormalTabs];
[ChromeEarlGrey showTabSwitcher];
ShowTabSwitcher();
} }
// Tests entering the tab switcher when more than one incognito tab is open. // Tests entering the tab switcher when more than one incognito tab is open.
...@@ -143,8 +118,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -143,8 +118,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey closeAllNormalTabs]; [ChromeEarlGrey closeAllNormalTabs];
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGrey showTabSwitcher];
ShowTabSwitcher();
} }
// Tests entering the switcher when multiple tabs of both types are open. // Tests entering the switcher when multiple tabs of both types are open.
...@@ -152,8 +126,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -152,8 +126,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGreyUI openNewTab]; [ChromeEarlGreyUI openNewTab];
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGrey showTabSwitcher];
ShowTabSwitcher();
} }
// Tests entering the tab switcher by closing the last normal tab. // Tests entering the tab switcher by closing the last normal tab.
...@@ -177,7 +150,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -177,7 +150,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab1_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab1_title]];
// Enter and leave the switcher. // Enter and leave the switcher.
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
ShowTabViewController(); ShowTabViewController();
// Verify that the original tab is visible again. // Verify that the original tab is visible again.
...@@ -192,7 +165,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -192,7 +165,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[self setUpTestServer]; [self setUpTestServer];
// 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(); [ChromeEarlGrey showTabSwitcher];
id<GREYMatcher> matcher = TabGridNewTabButton(); id<GREYMatcher> matcher = TabGridNewTabButton();
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
...@@ -213,7 +186,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -213,7 +186,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey closeAllNormalTabs]; [ChromeEarlGrey closeAllNormalTabs];
// 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(); [ChromeEarlGrey showTabSwitcher];
id<GREYMatcher> matcher = TabGridNewIncognitoTabButton(); id<GREYMatcher> matcher = TabGridNewIncognitoTabButton();
[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
...@@ -230,7 +203,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -230,7 +203,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[self setUpTestServer]; [self setUpTestServer];
// Go from normal mode to incognito mode. // Go from normal mode to incognito mode.
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
[[EarlGrey selectElementWithMatcher:TabGridIncognitoTabsPanelButton()] [[EarlGrey selectElementWithMatcher:TabGridIncognitoTabsPanelButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:TabGridNewIncognitoTabButton()] [[EarlGrey selectElementWithMatcher:TabGridNewIncognitoTabButton()]
...@@ -242,7 +215,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -242,7 +215,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
waitForWebStateContainingText:base::SysNSStringToUTF8(incognito_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(incognito_title)];
// Go from incognito mode to normal mode. // Go from incognito mode to normal mode.
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
[[EarlGrey selectElementWithMatcher:TabGridOpenTabsPanelButton()] [[EarlGrey selectElementWithMatcher:TabGridOpenTabsPanelButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:TabGridNewTabButton()] [[EarlGrey selectElementWithMatcher:TabGridNewTabButton()]
...@@ -268,12 +241,12 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -268,12 +241,12 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGreyUI openNewTab]; [ChromeEarlGreyUI openNewTab];
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab3_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab3_title]];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
SelectTab(tab1_title); SelectTab(tab1_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab1_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab1_title)];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
SelectTab(tab3_title); SelectTab(tab3_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab3_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab3_title)];
...@@ -295,12 +268,12 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -295,12 +268,12 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab3_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab3_title]];
[ChromeEarlGrey closeAllNormalTabs]; [ChromeEarlGrey closeAllNormalTabs];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
SelectTab(tab1_title); SelectTab(tab1_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab1_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab1_title)];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
SelectTab(tab3_title); SelectTab(tab3_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab3_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab3_title)];
...@@ -317,7 +290,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -317,7 +290,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGrey loadURL:[self makeURLForTitle:incognito_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:incognito_title]];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
// Switch to the normal panel and select the one tab that is there. // Switch to the normal panel and select the one tab that is there.
[[EarlGrey selectElementWithMatcher:TabGridOpenTabsPanelButton()] [[EarlGrey selectElementWithMatcher:TabGridOpenTabsPanelButton()]
performAction:grey_tap()]; performAction:grey_tap()];
...@@ -325,7 +298,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -325,7 +298,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(normal_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(normal_title)];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
// Switch to the incognito panel and select the one tab that is there. // Switch to the incognito panel and select the one tab that is there.
[[EarlGrey selectElementWithMatcher:TabGridIncognitoTabsPanelButton()] [[EarlGrey selectElementWithMatcher:TabGridIncognitoTabsPanelButton()]
performAction:grey_tap()]; performAction:grey_tap()];
...@@ -362,7 +335,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -362,7 +335,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Show the tab switcher and return to the BVC, in portrait. // Show the tab switcher and return to the BVC, in portrait.
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait [ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil]; error:nil];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
SelectTab(tab_title); SelectTab(tab_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)];
...@@ -370,7 +343,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -370,7 +343,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Show the tab switcher and return to the BVC, in landscape. // Show the tab switcher and return to the BVC, in landscape.
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft [ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
error:nil]; error:nil];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
SelectTab(tab_title); SelectTab(tab_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)];
...@@ -378,7 +351,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -378,7 +351,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Show the tab switcher and return to the BVC, in portrait. // Show the tab switcher and return to the BVC, in portrait.
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait [ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil]; error:nil];
ShowTabSwitcher(); [ChromeEarlGrey showTabSwitcher];
SelectTab(tab_title); SelectTab(tab_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)];
......
...@@ -286,6 +286,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -286,6 +286,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// Returns a unique identifier for the next Tab. // Returns a unique identifier for the next Tab.
- (NSString*)nextTabID; - (NSString*)nextTabID;
// Shows the tab switcher by tapping the switcher button. Works on both phone
// and tablet.
- (void)showTabSwitcher;
#pragma mark - SignIn Utilities (EG2) #pragma mark - SignIn Utilities (EG2)
// Signs the user out, clears the known accounts entirely and checks whether the // Signs the user out, clears the known accounts entirely and checks whether the
......
...@@ -335,6 +335,24 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -335,6 +335,24 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface nextTabID]; return [ChromeEarlGreyAppInterface nextTabID];
} }
- (void)showTabSwitcher {
id<GREYMatcher> matcher = chrome_test_util::TabGridOpenButton();
// 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];
EG_TEST_HELPER_ASSERT_TRUE(hasClicked, @"Tab switcher could not be clicked.");
}
#pragma mark - Cookie Utilities (EG2) #pragma mark - Cookie Utilities (EG2)
- (NSDictionary*)cookies { - (NSDictionary*)cookies {
...@@ -493,8 +511,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -493,8 +511,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
} }
- (void)triggerRestoreViaTabGridRemoveAllUndo { - (void)triggerRestoreViaTabGridRemoveAllUndo {
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [ChromeEarlGrey showTabSwitcher];
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCloseAllButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCloseAllButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey [[EarlGrey
......
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