Add FakeOmnibox() EG matcher to improve code formatting.
Bug: None
Change-Id: I52f38fe4a1699c9eebd0439f3b8ac9252e855956
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574293
Auto-Submit: Eugene But <eugenebut@chromium.org>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654226}
diff --git a/ios/chrome/browser/prerender/prerender_egtest.mm b/ios/chrome/browser/prerender/prerender_egtest.mm
index 457d00a..84b81b4 100644
--- a/ios/chrome/browser/prerender/prerender_egtest.mm
+++ b/ios/chrome/browser/prerender/prerender_egtest.mm
@@ -77,9 +77,7 @@
[[self class] closeAllTabs];
[ChromeEarlGrey openNewTab];
- [[EarlGrey
- selectElementWithMatcher:grey_accessibilityID(
- ntp_home::FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
performAction:grey_tap()];
[ChromeEarlGrey
waitForElementWithMatcherSufficientlyVisible:chrome_test_util::Omnibox()];
@@ -90,9 +88,7 @@
[ChromeEarlGrey openNewTab];
// Type the begining of the address to have the autocomplete suggestion.
- [[EarlGrey
- selectElementWithMatcher:grey_accessibilityID(
- ntp_home::FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
performAction:grey_tap()];
[ChromeEarlGrey
waitForElementWithMatcherSufficientlyVisible:chrome_test_util::Omnibox()];
diff --git a/ios/chrome/browser/ui/content_suggestions/BUILD.gn b/ios/chrome/browser/ui/content_suggestions/BUILD.gn
index 43f7222..b1d3cdc 100644
--- a/ios/chrome/browser/ui/content_suggestions/BUILD.gn
+++ b/ios/chrome/browser/ui/content_suggestions/BUILD.gn
@@ -224,13 +224,12 @@
"ntp_home_egtest.mm",
"ntp_home_provider_test_singleton.h",
"ntp_home_provider_test_singleton.mm",
- "ntp_home_test_utils.h",
- "ntp_home_test_utils.mm",
]
deps = [
":content_suggestions_constant",
":content_suggestions_ui",
":content_suggestions_ui_util",
+ ":test_support",
"//base",
"//base/test:test_support",
"//components/keyed_service/ios",
@@ -269,3 +268,19 @@
]
configs += [ "//build/config/compiler:enable_arc" ]
}
+
+source_set("test_support") {
+ testonly = true
+ sources = [
+ "ntp_home_test_utils.h",
+ "ntp_home_test_utils.mm",
+ ]
+ deps = [
+ "//components/ntp_snippets",
+ "//ios/chrome/browser/ui/content_suggestions",
+ "//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
+ "//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui",
+ "//ios/third_party/earl_grey:earl_grey+link",
+ ]
+ configs += [ "//build/config/compiler:enable_arc" ]
+}
diff --git a/ios/chrome/browser/ui/content_suggestions/ntp_home_egtest.mm b/ios/chrome/browser/ui/content_suggestions/ntp_home_egtest.mm
index e1ed822..9e8cba0 100644
--- a/ios/chrome/browser/ui/content_suggestions/ntp_home_egtest.mm
+++ b/ios/chrome/browser/ui/content_suggestions/ntp_home_egtest.mm
@@ -267,8 +267,7 @@
GREYAssertTrue(collectionWidth > 0, @"The collection width is nil.");
CGFloat fakeOmniboxWidth = searchFieldWidth(collectionWidth);
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
@@ -282,8 +281,7 @@
@"The collection width has not changed.");
fakeOmniboxWidth = searchFieldWidth(collectionWidthAfterRotation);
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
}
@@ -302,8 +300,7 @@
GREYAssertTrue(collectionWidth > 0, @"The collection width is nil.");
CGFloat fakeOmniboxWidth = searchFieldWidth(collectionWidth);
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
[ChromeEarlGreyUI openSettingsMenu];
@@ -322,8 +319,7 @@
@"The collection width has not changed.");
fakeOmniboxWidth = searchFieldWidth(collectionWidthAfterRotation);
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
}
@@ -346,8 +342,7 @@
// The fake omnibox might be slightly bigger than the screen in order to cover
// it for all screen scale.
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidthBetween(collectionWidth + 1, 2)];
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
@@ -358,8 +353,7 @@
GREYAssertNotEqual(collectionWidth, collectionWidthAfterRotation,
@"The collection width has not changed.");
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())];
}
@@ -563,8 +557,7 @@
CGPoint offsetAfterTap = collectionView.contentOffset;
// Make sure the fake omnibox has been hidden and the collection has moved.
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())];
CGFloat top = ntp_home::CollectionView().safeAreaInsets.top;
@@ -577,8 +570,7 @@
performAction:grey_tapAtPoint(CGPointMake(0, offsetAfterTap.y + 100))];
// Check the fake omnibox is displayed again at the same position.
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:grey_sufficientlyVisible()];
GREYAssertEqual(
@@ -613,8 +605,7 @@
CGPointMake(0, collectionView.contentOffset.y + 100))];
// Check the fake omnibox is displayed again at the same position.
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:grey_sufficientlyVisible()];
// The collection might be slightly moved on iPhone.
@@ -646,8 +637,7 @@
[ChromeEarlGreyUI openNewTab];
// Check that the fake omnibox is here.
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:grey_sufficientlyVisible()];
id<GREYMatcher> tabGridMatcher = nil;
if (IsIPadIdiom()) {
@@ -672,8 +662,7 @@
}
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridNewTabButton()]
performAction:grey_tap()];
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:tabGridMatcher]
assertWithMatcher:grey_accessibilityValue(
@@ -744,8 +733,7 @@
// Taps the fake omnibox and waits for the real omnibox to be visible.
- (void)focusFakebox {
- [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
- FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
performAction:grey_tap()];
[ChromeEarlGrey
waitForElementWithMatcherSufficientlyVisible:chrome_test_util::Omnibox()];
diff --git a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_egtest.mm b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_egtest.mm
index 6acc7152..09bfd38 100644
--- a/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_egtest.mm
+++ b/ios/chrome/browser/ui/omnibox/popup/omnibox_popup_egtest.mm
@@ -245,9 +245,7 @@
// Open a new tab and switch to the first tab.
[ChromeEarlGrey openNewTab];
- [[EarlGrey
- selectElementWithMatcher:grey_accessibilityID(
- ntp_home::FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
performAction:grey_typeText(base::SysUTF8ToNSString(URL1.host()))];
[[EarlGrey selectElementWithMatcher:SwitchTabElementForUrl(URL1)]
performAction:grey_tap()];
@@ -270,9 +268,7 @@
[ChromeEarlGrey goBack];
// Navigate to the other tab.
- [[EarlGrey
- selectElementWithMatcher:grey_accessibilityID(
- ntp_home::FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
performAction:grey_typeText(base::SysUTF8ToNSString(URL1.host()))];
[[EarlGrey selectElementWithMatcher:SwitchTabElementForUrl(URL1)]
performAction:grey_tap()];
@@ -332,9 +328,7 @@
// Start typing url of the two opened pages in a new tab.
[ChromeEarlGrey openNewTab];
- [[EarlGrey
- selectElementWithMatcher:grey_accessibilityID(
- ntp_home::FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
performAction:grey_typeText(@"page")];
// Check that both elements are displayed.
diff --git a/ios/chrome/browser/ui/omnibox/popup/shortcuts/shortcuts_egtest.mm b/ios/chrome/browser/ui/omnibox/popup/shortcuts/shortcuts_egtest.mm
index ac25b34e..375989e 100644
--- a/ios/chrome/browser/ui/omnibox/popup/shortcuts/shortcuts_egtest.mm
+++ b/ios/chrome/browser/ui/omnibox/popup/shortcuts/shortcuts_egtest.mm
@@ -240,9 +240,7 @@
[ChromeEarlGrey openNewTab];
// Tap the fake omnibox.
- [[EarlGrey
- selectElementWithMatcher:grey_accessibilityID(
- ntp_home::FakeOmniboxAccessibilityID())]
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
performAction:grey_tap()];
// Wait for the real omnibox to be visible.
[ChromeEarlGrey
diff --git a/ios/chrome/test/earl_grey/BUILD.gn b/ios/chrome/test/earl_grey/BUILD.gn
index b599c19..4abff58 100644
--- a/ios/chrome/test/earl_grey/BUILD.gn
+++ b/ios/chrome/test/earl_grey/BUILD.gn
@@ -251,6 +251,7 @@
"//ios/chrome/browser/ui/bookmarks:bookmarks_ui",
"//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/commands:commands",
+ "//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui",
"//ios/chrome/browser/ui/history:history_ui",
"//ios/chrome/browser/ui/location_bar:location_bar",
@@ -329,6 +330,7 @@
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/authentication/cells",
"//ios/chrome/browser/ui/bookmarks:bookmarks_ui",
+ "//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui",
"//ios/chrome/browser/ui/location_bar:location_bar",
"//ios/chrome/browser/ui/omnibox:omnibox_internal",
diff --git a/ios/chrome/test/earl_grey/chrome_matchers.h b/ios/chrome/test/earl_grey/chrome_matchers.h
index 18f1d62..22793ace 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers.h
+++ b/ios/chrome/test/earl_grey/chrome_matchers.h
@@ -259,6 +259,9 @@
// Returns matcher for defoucesed omnibox on a new tab.
id<GREYMatcher> NewTabPageOmnibox();
+// Returns matcher for a fake omnibox on a new tab page.
+id<GREYMatcher> FakeOmnibox();
+
// Returns a matcher for the current WebView.
id<GREYMatcher> WebViewMatcher();
diff --git a/ios/chrome/test/earl_grey/chrome_matchers.mm b/ios/chrome/test/earl_grey/chrome_matchers.mm
index 62bbdd7..5d984721 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers.mm
+++ b/ios/chrome/test/earl_grey/chrome_matchers.mm
@@ -329,6 +329,10 @@
return [ChromeMatchersAppInterface NTPOmnibox];
}
+id<GREYMatcher> FakeOmnibox() {
+ return [ChromeMatchersAppInterface fakeOmnibox];
+}
+
id<GREYMatcher> WebViewMatcher() {
return [ChromeMatchersAppInterface webViewMatcher];
}
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 b4425bfe..81dbdfd 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers_app_interface.h
+++ b/ios/chrome/test/earl_grey/chrome_matchers_app_interface.h
@@ -260,6 +260,9 @@
// Returns matcher for defoucesed omnibox on a new tab.
+ (id<GREYMatcher>)NTPOmnibox;
+// Returns matcher for a fake omnibox on a new tab page.
++ (id<GREYMatcher>)fakeOmnibox;
+
// Returns a matcher for the current WebView.
+ (id<GREYMatcher>)webViewMatcher;
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 a741644..b0f0725 100644
--- a/ios/chrome/test/earl_grey/chrome_matchers_app_interface.mm
+++ b/ios/chrome/test/earl_grey/chrome_matchers_app_interface.mm
@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h"
+#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_steady_view.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h"
#import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h"
@@ -550,6 +551,10 @@
grey_minimumVisiblePercent(0.2), nil);
}
++ (id<GREYMatcher>)fakeOmnibox {
+ return grey_accessibilityID(ntp_home::FakeOmniboxAccessibilityID());
+}
+
+ (id<GREYMatcher>)webViewMatcher {
return web::WebViewInWebState(chrome_test_util::GetCurrentWebState());
}