Skip to content

Commit

Permalink
Check that tab switcher is active/inactive before visibility check.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Kurt Horimoto committed Mar 8, 2017
1 parent eb7089a commit 93e9aa4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions ios/chrome/browser/ui/stack_view/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/tools_menu",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/testing:ios_test_support",
"//ios/testing/earl_grey:earl_grey_support",
]
libs = [ "XCTest.framework" ]
Expand Down
38 changes: 30 additions & 8 deletions ios/chrome/browser/ui/stack_view/stack_view_egtest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/testing/earl_grey/disabled_test_macros.h"
#import "ios/testing/wait_util.h"

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

// Waits for the Stack View to be visible/hidden.
// Waits for the Stack View to be active/inactive.
void WaitForStackViewActive(bool active) {
NSString* activeStatusString = active ? @"active" : @"inactive";
NSString* activeTabSwitcherDescription =
[NSString stringWithFormat:@"Waiting for tab switcher to be %@.",
activeStatusString];
BOOL (^activeTabSwitcherBlock)
() = ^BOOL {
BOOL isActive = chrome_test_util::GetStackViewController() &&
chrome_test_util::IsTabSwitcherActive();
return active ? isActive : !isActive;
};
GREYCondition* activeTabSwitcherCondition =
[GREYCondition conditionWithName:activeTabSwitcherDescription
block:activeTabSwitcherBlock];
NSString* assertDescription = [NSString
stringWithFormat:@"Tab switcher did not become %@.", activeStatusString];

GREYAssert([activeTabSwitcherCondition
waitWithTimeout:testing::kWaitForUIElementTimeout],
assertDescription);
}

// Verify the visibility of the stack view.
void CheckForStackViewVisibility(bool visible) {
id<GREYMatcher> visibilityMatcher =
grey_allOf(visible ? grey_sufficientlyVisible() : grey_notVisible(),
Expand All @@ -70,6 +94,7 @@ void OpenStackView() {
[[EarlGrey selectElementWithMatcher:stackButtonMatcher]
performAction:grey_tap()];
// Verify that a StackViewController was presented.
WaitForStackViewActive(true);
CheckForStackViewVisibility(true);
}

Expand Down Expand Up @@ -105,6 +130,7 @@ void OpenNewTabUsingStackView() {
ShowDeckWithType(DeckType::NORMAL);
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"New Tab")]
performAction:grey_tap()];
WaitForStackViewActive(false);
CheckForStackViewVisibility(false);
}

Expand All @@ -121,6 +147,7 @@ void OpenNewIncognitoTabUsingStackView() {
NSString* newIncognitoTabID = kToolsMenuNewIncognitoTabId;
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newIncognitoTabID)]
performAction:grey_tap()];
WaitForStackViewActive(false);
CheckForStackViewVisibility(false);
}

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

// Tests closing all Tabs in the stack view.
// TODO(crbug.com/693517): Re-enable this test on simulator.
#if TARGET_IPHONE_SIMULATOR
#define MAYBE_testCloseAllTabs FLAKY_testCloseAllTabs
#else
#define MAYBE_testCloseAllTabs testCloseAllTabs
#endif
- (void)MAYBE_testCloseAllTabs {
- (void)testCloseAllTabs {
// The StackViewController is only used on iPhones.
if (IsIPadIdiom())
EARL_GREY_TEST_SKIPPED(@"Stack view is not used on iPads.");
Expand Down

0 comments on commit 93e9aa4

Please sign in to comment.