Skip to content

Commit 93e9aa4

Browse files
author
Kurt Horimoto
committed
Check that tab switcher is active/inactive before visibility check.
As shown in the referenced bug, testCloseAllTabs was failing because the stack view visibility check was checking for a nil stack view. This is likely occurring because the visibility check was occurring before the touch event that should show the tab switcher is handled. Adding this condition will wait for the touch event to be handled before checking for visibility. BUG=693517 Review-Url: https://codereview.chromium.org/2706403006 Cr-Commit-Position: refs/heads/master@{#455293} (cherry picked from commit 389418d) Review-Url: https://codereview.chromium.org/2734283002 . Cr-Commit-Position: refs/branch-heads/3029@{#56} Cr-Branched-From: 939b32e-refs/heads/master@{#454471}
1 parent eb7089a commit 93e9aa4

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

ios/chrome/browser/ui/stack_view/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ source_set("eg_tests") {
144144
"//ios/chrome/browser/ui/tools_menu",
145145
"//ios/chrome/test/app:test_support",
146146
"//ios/chrome/test/earl_grey:test_support",
147+
"//ios/testing:ios_test_support",
147148
"//ios/testing/earl_grey:earl_grey_support",
148149
]
149150
libs = [ "XCTest.framework" ]

ios/chrome/browser/ui/stack_view/stack_view_egtest.mm

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
2525
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
2626
#include "ios/testing/earl_grey/disabled_test_macros.h"
27+
#import "ios/testing/wait_util.h"
2728

2829
#if !defined(__has_feature) || !__has_feature(objc_arc)
2930
#error "This file requires ARC support."
@@ -50,7 +51,30 @@
5051
return ViewMatchingView([chrome_test_util::GetStackViewController() view]);
5152
}
5253

53-
// Waits for the Stack View to be visible/hidden.
54+
// Waits for the Stack View to be active/inactive.
55+
void WaitForStackViewActive(bool active) {
56+
NSString* activeStatusString = active ? @"active" : @"inactive";
57+
NSString* activeTabSwitcherDescription =
58+
[NSString stringWithFormat:@"Waiting for tab switcher to be %@.",
59+
activeStatusString];
60+
BOOL (^activeTabSwitcherBlock)
61+
() = ^BOOL {
62+
BOOL isActive = chrome_test_util::GetStackViewController() &&
63+
chrome_test_util::IsTabSwitcherActive();
64+
return active ? isActive : !isActive;
65+
};
66+
GREYCondition* activeTabSwitcherCondition =
67+
[GREYCondition conditionWithName:activeTabSwitcherDescription
68+
block:activeTabSwitcherBlock];
69+
NSString* assertDescription = [NSString
70+
stringWithFormat:@"Tab switcher did not become %@.", activeStatusString];
71+
72+
GREYAssert([activeTabSwitcherCondition
73+
waitWithTimeout:testing::kWaitForUIElementTimeout],
74+
assertDescription);
75+
}
76+
77+
// Verify the visibility of the stack view.
5478
void CheckForStackViewVisibility(bool visible) {
5579
id<GREYMatcher> visibilityMatcher =
5680
grey_allOf(visible ? grey_sufficientlyVisible() : grey_notVisible(),
@@ -70,6 +94,7 @@ void OpenStackView() {
7094
[[EarlGrey selectElementWithMatcher:stackButtonMatcher]
7195
performAction:grey_tap()];
7296
// Verify that a StackViewController was presented.
97+
WaitForStackViewActive(true);
7398
CheckForStackViewVisibility(true);
7499
}
75100

@@ -105,6 +130,7 @@ void OpenNewTabUsingStackView() {
105130
ShowDeckWithType(DeckType::NORMAL);
106131
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"New Tab")]
107132
performAction:grey_tap()];
133+
WaitForStackViewActive(false);
108134
CheckForStackViewVisibility(false);
109135
}
110136

@@ -121,6 +147,7 @@ void OpenNewIncognitoTabUsingStackView() {
121147
NSString* newIncognitoTabID = kToolsMenuNewIncognitoTabId;
122148
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newIncognitoTabID)]
123149
performAction:grey_tap()];
150+
WaitForStackViewActive(false);
124151
CheckForStackViewVisibility(false);
125152
}
126153

@@ -137,6 +164,7 @@ void SelectTabUsingStackView(Tab* tab) {
137164
[[EarlGrey selectElementWithMatcher:ViewMatchingView(card_title_label)]
138165
performAction:grey_tap()];
139166
// Wait for the StackViewController to be dismissed.
167+
WaitForStackViewActive(false);
140168
CheckForStackViewVisibility(false);
141169
// Checks that the next Tab has been selected.
142170
GREYAssertEqual(tab, chrome_test_util::GetCurrentTab(),
@@ -187,13 +215,7 @@ - (void)testCloseTab {
187215
}
188216

189217
// Tests closing all Tabs in the stack view.
190-
// TODO(crbug.com/693517): Re-enable this test on simulator.
191-
#if TARGET_IPHONE_SIMULATOR
192-
#define MAYBE_testCloseAllTabs FLAKY_testCloseAllTabs
193-
#else
194-
#define MAYBE_testCloseAllTabs testCloseAllTabs
195-
#endif
196-
- (void)MAYBE_testCloseAllTabs {
218+
- (void)testCloseAllTabs {
197219
// The StackViewController is only used on iPhones.
198220
if (IsIPadIdiom())
199221
EARL_GREY_TEST_SKIPPED(@"Stack view is not used on iPads.");

0 commit comments

Comments
 (0)