10e4a154fbbcc0faa3ba1a8e1a6608d5f8471382 - chromium/src

1,364 views
Skip to first unread message

mre...@google.com

unread,
Mar 1, 2022, 7:25:55 PM3/1/22
to chromium...@chromium.org
commit 10e4a154fbbcc0faa3ba1a8e1a6608d5f8471382
Author: Mohammad Refaat <mre...@google.com>
AuthorDate: Wed Mar 02 00:24:08 2022
Commit: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
CommitDate: Wed Mar 02 00:24:08 2022

Add EarlGrey tests for search mode in regular tab grid.

Tests added:
1- Tests exiting search reset the tabs count.
2- Tests scrim view is always visible when the searchbar is empty.
3- Tests that tapping on scrim view cancels search mode.
4- Tests that searching tabs using the title filter open tabs correctly.

Added more accurate matcher to check for the current tab grid mode.
Updated testEnterExitSearch to use matchers for the mode.

Added a verification method for the visible tabs, instead of using the
number of webstates from the WebStateList (which is doesn't always
reflect what is on the screen). "In a later CL i'll update all tests on
the file to use this verifier instead".

Bug: 1297920
Change-Id: I9936b39c8ae19981ec18df59a9996742b4ebc659
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3494058
Reviewed-by: Mike Dougherty <mich...@chromium.org>
Reviewed-by: Rohit Rao <rohi...@chromium.org>
Commit-Queue: Mohammad Refaat <mre...@chromium.org>
Cr-Commit-Position: refs/heads/main@{#976482}

diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_egtest.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_egtest.mm
index 2137647..e5b25e25 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_egtest.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_egtest.mm
@@ -38,8 +38,11 @@
using chrome_test_util::AddToBookmarksButton;
using chrome_test_util::AddToReadingListButton;
using chrome_test_util::CloseTabMenuButton;
+using chrome_test_util::TabGridCellAtIndex;
+using chrome_test_util::TabGridNormalModePageControl;
using chrome_test_util::TabGridSearchBar;
using chrome_test_util::TabGridSearchCancelButton;
+using chrome_test_util::TabGridSearchModeToolbar;
using chrome_test_util::TabGridSearchTabsButton;
using chrome_test_util::TabGridSelectTabsMenuButton;

@@ -59,9 +62,19 @@
const CFTimeInterval kSnackbarAppearanceTimeout = 5;
const CFTimeInterval kSnackbarDisappearanceTimeout = 11;

+id<GREYMatcher> TabGridCell() {
+ return grey_allOf(grey_kindOfClassName(@"GridCell"),
+ grey_sufficientlyVisible(), nil);
+}
+
id<GREYMatcher> TabWithTitle(NSString* title) {
- return grey_allOf(grey_accessibilityLabel(title), grey_sufficientlyVisible(),
- nil);
+ return grey_allOf(TabGridCell(), grey_accessibilityLabel(title),
+ grey_sufficientlyVisible(), nil);
+}
+
+id<GREYMatcher> TabWithTitleAndIndex(char* title, unsigned int index) {
+ return grey_allOf(TabWithTitle([NSString stringWithUTF8String:title]),
+ TabGridCellAtIndex(index), nil);
}

// Identifer for cell at given |index| in the tab grid.
@@ -104,6 +117,12 @@
base::test::ios::kWaitForUIElementTimeout, condition);
GREYAssertTrue(fullscreenAchieved, @"BrowserViewHiderView still shown");
}
+
+// Returns a matcher for the scrim view on the tab search.
+id<GREYMatcher> SearchScrim() {
+ return grey_accessibilityID(kTabGridScrimIdentifier);
+}
+
} // namespace

@interface TabGridTestCase : WebHttpServerChromeTestCase {
@@ -118,11 +137,18 @@

- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
-
- if ([self isRunningTest:@selector(testEnterExitSearch)]) {
- config.features_enabled.push_back(kTabsSearch);
+ std::vector<SEL> searchTests = {
+ @selector(testEnterExitSearch),
+ @selector(testTabGridResetAfterExitingSearch),
+ @selector(testScrimVisibleInSearchModeWhenSearchBarIsEmpty),
+ @selector(testTapOnSearchScrimExitsSearchMode),
+ @selector(testSearchRegularOpenTabs)};
+ for (SEL test : searchTests) {
+ if ([self isRunningTest:test]) {
+ config.features_enabled.push_back(kTabsSearch);
+ break;
+ }
}
-
return config;
}

@@ -1208,15 +1234,130 @@
[ChromeEarlGrey openNewTab];
[ChromeEarlGrey showTabSwitcher];

+ // Enter search mode.
[[EarlGrey selectElementWithMatcher:TabGridSearchTabsButton()]
performAction:grey_tap()];
- [[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridSearchBar()]
- performAction:grey_typeText(@"text")];
+
+ // Verify that search mode is active.
+ [[EarlGrey
+ selectElementWithMatcher:chrome_test_util::TabGridSearchModeToolbar()]
+ assertWithMatcher:grey_notNil()];
+
+ // Exit search mode.
[[EarlGrey selectElementWithMatcher:TabGridSearchCancelButton()]
performAction:grey_tap()];

- GREYAssertEqual([ChromeEarlGrey mainTabCount], 2,
- @"All tabs did not return after exiting search.");
+ // Verify that normal mode is active.
+ [[EarlGrey
+ selectElementWithMatcher:chrome_test_util::TabGridNormalModePageControl()]
+ assertWithMatcher:grey_notNil()];
+}
+
+// Tests that exiting search mode reset the tabs count to the original number.
+- (void)testTabGridResetAfterExitingSearch {
+ [ChromeEarlGrey openNewTab];
+ [ChromeEarlGrey showTabSwitcher];
+
+ // Enter search mode & search with a query that produce no results.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchTabsButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridSearchBar()]
+ performAction:grey_typeText(@"hello")];
+
+ // Verify that search reduced the number of visible tabs.
+ [self verifyVisibleTabsCount:0];
+
+ // Exit search mode & verify that tabs grid was reset.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchCancelButton()]
+ performAction:grey_tap()];
+ [self verifyVisibleTabsCount:2];
+}
+
+// Tests that the scrim view is always shown when the search bar is empty in the
+// search mode.
+- (void)testScrimVisibleInSearchModeWhenSearchBarIsEmpty {
+ [ChromeEarlGrey openNewTab];
+ [ChromeEarlGrey showTabSwitcher];
+
+ // Enter search mode.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchTabsButton()]
+ performAction:grey_tap()];
+
+ // Upon entry, the search bar is empty. Verify that scrim is visible.
+ [[EarlGrey selectElementWithMatcher:SearchScrim()]
+ assertWithMatcher:grey_notNil()];
+
+ // Searching with any query should render scrim invisible.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchBar()]
+ performAction:grey_typeText(@"text")];
+ [[EarlGrey selectElementWithMatcher:SearchScrim()]
+ assertWithMatcher:grey_nil()];
+
+ // Clearing search bar text should render scrim visible again.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchBar()]
+ performAction:grey_clearText()];
+ [[EarlGrey selectElementWithMatcher:SearchScrim()]
+ assertWithMatcher:grey_notNil()];
+
+ // Cancel search mode.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchCancelButton()]
+ performAction:grey_tap()];
+
+ // Verify that scrim is not visible anymore.
+ [[EarlGrey selectElementWithMatcher:SearchScrim()]
+ assertWithMatcher:grey_nil()];
+}
+
+// Tests that tapping on the scrim view while in search mode dismisses the scrim
+// and exits search mode.
+- (void)testTapOnSearchScrimExitsSearchMode {
+ [ChromeEarlGrey openNewTab];
+ [ChromeEarlGrey showTabSwitcher];
+
+ // Enter search mode.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchTabsButton()]
+ performAction:grey_tap()];
+
+ // Tap on scrim.
+ [[EarlGrey selectElementWithMatcher:SearchScrim()] performAction:grey_tap()];
+
+ // Verify that search mode is exit, scrim not visible, and transition to
+ // normal mode was successful.
+ [[EarlGrey selectElementWithMatcher:SearchScrim()]
+ assertWithMatcher:grey_nil()];
+ [[EarlGrey selectElementWithMatcher:TabGridNormalModePageControl()]
+ assertWithMatcher:grey_notNil()];
+ [self verifyVisibleTabsCount:2];
+}
+
+// Tests that searching in open tabs in the regular mode will filter the tabs
+// correctly.
+- (void)testSearchRegularOpenTabs {
+ [self loadTestURLsInNewTabs];
+ [ChromeEarlGrey showTabSwitcher];
+
+ [self verifyVisibleTabsCount:4];
+
+ // Enter search mode.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchTabsButton()]
+ performAction:grey_tap()];
+
+ // Searching with the word "Page" should match only 3 results.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchBar()]
+ performAction:grey_typeText(@"Page")];
+ [self verifyVisibleTabsCount:3];
+
+ // Verify that search results are correct and in the expected order.
+ [[EarlGrey selectElementWithMatcher:TabWithTitleAndIndex(kTitle1, 0)]
+ assertWithMatcher:grey_notNil()];
+ [[EarlGrey selectElementWithMatcher:TabWithTitleAndIndex(kTitle2, 1)]
+ assertWithMatcher:grey_notNil()];
+ [[EarlGrey selectElementWithMatcher:TabWithTitleAndIndex(kTitle4, 2)]
+ assertWithMatcher:grey_notNil()];
+
+ // Cancel search mode.
+ [[EarlGrey selectElementWithMatcher:TabGridSearchCancelButton()]
+ performAction:grey_tap()];
}

#pragma mark - Helper Methods
@@ -1232,6 +1373,23 @@
[ChromeEarlGrey waitForWebStateContainingText:kResponse3];
}

+- (void)loadTestURLsInNewTabs {
+ [ChromeEarlGrey loadURL:_URL1];
+ [ChromeEarlGrey waitForWebStateContainingText:kResponse1];
+
+ [ChromeEarlGrey openNewTab];
+ [ChromeEarlGrey loadURL:_URL2];
+ [ChromeEarlGrey waitForWebStateContainingText:kResponse2];
+
+ [ChromeEarlGrey openNewTab];
+ [ChromeEarlGrey loadURL:_URL3];
+ [ChromeEarlGrey waitForWebStateContainingText:kResponse3];
+
+ [ChromeEarlGrey openNewTab];
+ [ChromeEarlGrey loadURL:_URL4];
+ [ChromeEarlGrey waitForWebStateContainingText:kResponse4];
+}
+
// Loads a URL in a new tab and deletes it to populate Recent Tabs. Then,
// navigates to the Recent tabs via tab grid.
- (void)prepareRecentTabWithURL:(const GURL&)URL
@@ -1337,4 +1495,21 @@
@"Snackbar did not disappear.");
}

+// Verifies that the tab grid has exactly |expectedCount| tabs.
+- (void)verifyVisibleTabsCount:(NSUInteger)expectedCount {
+ // Verify that the cell # |expectedCount| exist.
+ if (expectedCount == 0) {
+ [[EarlGrey selectElementWithMatcher:TabGridCell()]
+ assertWithMatcher:grey_nil()];
+ } else {
+ [[[EarlGrey selectElementWithMatcher:TabGridCell()]
+ atIndex:expectedCount - 1] assertWithMatcher:grey_notNil()];
+ }
+ // Then verify that there is no more cells after that.
+ [[EarlGrey
+ selectElementWithMatcher:grey_allOf(TabGridCell(),
+ TabGridCellAtIndex(expectedCount),
+ nil)] assertWithMatcher:grey_nil()];
+}
+
@end
diff --git a/ios/chrome/test/earl_grey/chrome_matchers.h b/ios/chrome/test/earl_grey/chrome_matchers.h
index 738ab80..bc2e0810 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers.h
+++ b/ios/chrome/test/earl_grey/chrome_matchers.h
@@ -487,6 +487,11 @@
// the tab grid.
id<GREYMatcher> TabGridOtherDevicesPanelButton();

+// Returns a matcher that matches tab grid normal mode page control - The
+// PageControl panel always exist only on the tab grid normal mode, So this can
+// be used to validate that the tab grid normal mode is active.
+id<GREYMatcher> TabGridNormalModePageControl();
+
// Returns a matcher for the tab grid background.
id<GREYMatcher> TabGridBackground();

@@ -642,6 +647,9 @@
// Returns a matcher for the tab grid search cancel button.
id<GREYMatcher> TabGridSearchCancelButton();

+// Returns a matcher for the tab grid search mode toolbar.
+id<GREYMatcher> TabGridSearchModeToolbar();
+
} // namespace chrome_test_util

#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_H_
diff --git a/ios/chrome/test/earl_grey/chrome_matchers.mm b/ios/chrome/test/earl_grey/chrome_matchers.mm
index 89f1ce4..aa7d80c 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers.mm
+++ b/ios/chrome/test/earl_grey/chrome_matchers.mm
@@ -602,6 +602,10 @@
return [ChromeMatchersAppInterface tabGridOtherDevicesPanelButton];
}

+id<GREYMatcher> TabGridNormalModePageControl() {
+ return [ChromeMatchersAppInterface tabGridNormalModePageControl];
+}
+
id<GREYMatcher> TabGridBackground() {
return [ChromeMatchersAppInterface tabGridBackground];
}
@@ -801,4 +805,8 @@
return [ChromeMatchersAppInterface tabGridSearchCancelButton];
}

+id<GREYMatcher> TabGridSearchModeToolbar() {
+ return [ChromeMatchersAppInterface tabGridSearchModeToolbar];
+}
+
} // namespace chrome_test_util
diff --git a/ios/chrome/test/earl_grey/chrome_matchers_app_interface.h b/ios/chrome/test/earl_grey/chrome_matchers_app_interface.h
index 3a5fa9a..008b19d 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers_app_interface.h
+++ b/ios/chrome/test/earl_grey/chrome_matchers_app_interface.h
@@ -474,6 +474,11 @@
// the tab grid.
+ (id<GREYMatcher>)tabGridOtherDevicesPanelButton;

+// Returns a matcher that matches tab grid normal mode page control - The
+// PageControl panel always exist only on the tab grid normal mode, So this can
+// be used to validate that the tab grid normal mode is active.
++ (id<GREYMatcher>)tabGridNormalModePageControl;
+
// Returns the GREYMatcher for the background of the tab grid.
+ (id<GREYMatcher>)tabGridBackground;

@@ -627,6 +632,9 @@
// Returns a matcher for the tab grid search cancel button.
+ (id<GREYMatcher>)tabGridSearchCancelButton;

+// Returns a matcher for the tab grid search mode toolbar.
++ (id<GREYMatcher>)tabGridSearchModeToolbar;
+
@end

#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_APP_INTERFACE_H_
diff --git a/ios/chrome/test/earl_grey/chrome_matchers_app_interface.mm b/ios/chrome/test/earl_grey/chrome_matchers_app_interface.mm
index 78417e2..cb9aa6f 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers_app_interface.mm
+++ b/ios/chrome/test/earl_grey/chrome_matchers_app_interface.mm
@@ -930,6 +930,18 @@
return grey_accessibilityID(kTabGridRemoteTabsPageButtonIdentifier);
}

++ (id<GREYMatcher>)tabGridNormalModePageControl {
+ return grey_allOf(
+ grey_kindOfClassName(@"UIControl"),
+ grey_descendant(
+ [ChromeMatchersAppInterface tabGridIncognitoTabsPanelButton]),
+ grey_descendant([ChromeMatchersAppInterface tabGridOpenTabsPanelButton]),
+ grey_descendant(
+ [ChromeMatchersAppInterface tabGridOtherDevicesPanelButton]),
+ grey_ancestor(grey_kindOfClassName(@"UIToolbar")),
+ grey_sufficientlyVisible(), nil);
+}
+
+ (id<GREYMatcher>)tabGridBackground {
return grey_accessibilityID(kGridBackgroundIdentifier);
}
@@ -1214,4 +1226,12 @@
grey_sufficientlyVisible(), nil);
}

++ (id<GREYMatcher>)tabGridSearchModeToolbar {
+ return grey_allOf(
+ grey_kindOfClassName(@"UIToolbar"),
+ grey_descendant([ChromeMatchersAppInterface tabGridSearchBar]),
+ grey_descendant([ChromeMatchersAppInterface tabGridSearchCancelButton]),
+ grey_sufficientlyVisible(), nil);
+}
+
@end
Reply all
Reply to author
Forward
0 new messages