Commit 2b8fd19b authored by stkhapugin@chromium.org's avatar stkhapugin@chromium.org Committed by Commit Bot

Fix tests with Refresh Location Bar flag ON.

Fixes the tests broken by enabling the refresh location bar, introducing
helpers as necessary.

Bug: 834345, 821821
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ifb767a192c3f4d3f35bf4714768352a83d4a1d99
Reviewed-on: https://chromium-review.googlesource.com/1070147
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565664}
parent 018c6638
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/web/public/test/http_server/html_response_provider.h" #include "ios/web/public/test/http_server/html_response_provider.h"
...@@ -61,9 +62,7 @@ ...@@ -61,9 +62,7 @@
NSString* script = NSString* script =
[NSString stringWithFormat:@"javascript:location.href='%s'\n", [NSString stringWithFormat:@"javascript:location.href='%s'\n",
destinationURL.spec().c_str()]; destinationURL.spec().c_str()];
[ChromeEarlGreyUI focusOmniboxAndType:script];
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
performAction:grey_typeText(script)];
// In the omnibox, the new URL should be present, without the http:// prefix. // In the omnibox, the new URL should be present, without the http:// prefix.
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#import "ios/chrome/browser/ui/location_bar/location_bar_steady_view.h" #import "ios/chrome/browser/ui/location_bar/location_bar_steady_view.h"
#import "ios/chrome/browser/ui/location_bar/extended_touch_target_button.h" #import "ios/chrome/browser/ui/location_bar/extended_touch_target_button.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/browser/ui/util/constraints_ui_util.h" #import "ios/chrome/browser/ui/util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -82,6 +84,11 @@ const CGFloat kButtonTrailingSpacing = 10; ...@@ -82,6 +84,11 @@ const CGFloat kButtonTrailingSpacing = 10;
setContentCompressionResistancePriority:UILayoutPriorityRequired setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis: forAxis:
UILayoutConstraintAxisHorizontal]; UILayoutConstraintAxisHorizontal];
SetA11yLabelAndUiAutomationName(
_locationIconImageView,
IDS_IOS_PAGE_INFO_SECURITY_BUTTON_ACCESSIBILITY_LABEL,
@"Page Security Info");
_locationIconImageView.isAccessibilityElement = YES;
// Setup trailing button. // Setup trailing button.
_trailingButton = _trailingButton =
......
...@@ -17,6 +17,7 @@ source_set("popup_menu") { ...@@ -17,6 +17,7 @@ source_set("popup_menu") {
"//components/bookmarks/browser", "//components/bookmarks/browser",
"//components/feature_engagement/public", "//components/feature_engagement/public",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/bookmarks", "//ios/chrome/browser/bookmarks",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/feature_engagement", "//ios/chrome/browser/feature_engagement",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/feature_engagement/public/feature_constants.h" #include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/tracker.h" #include "components/feature_engagement/public/tracker.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/find_in_page/find_tab_helper.h" #import "ios/chrome/browser/find_in_page/find_tab_helper.h"
#import "ios/chrome/browser/ui/activity_services/canonical_url_retriever.h" #import "ios/chrome/browser/ui/activity_services/canonical_url_retriever.h"
#include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h"
...@@ -451,7 +452,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -451,7 +452,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
self.readLaterItem.enabled = [self isCurrentURLWebURL]; self.readLaterItem.enabled = [self isCurrentURLWebURL];
[self updateBookmarkItem]; [self updateBookmarkItem];
self.findInPageItem.enabled = [self isFindInPageEnabled]; self.findInPageItem.enabled = [self isFindInPageEnabled];
self.siteInformationItem.enabled = [self isCurrentURLWebURL]; self.siteInformationItem.enabled = [self currentWebPageSupportsSiteInfo];
self.requestDesktopSiteItem.enabled = self.requestDesktopSiteItem.enabled =
[self userAgentType] == web::UserAgentType::MOBILE; [self userAgentType] == web::UserAgentType::MOBILE;
self.requestMobileSiteItem.enabled = self.requestMobileSiteItem.enabled =
...@@ -506,6 +507,23 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -506,6 +507,23 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
} }
} }
// Whether the current web page has available site info.
- (BOOL)currentWebPageSupportsSiteInfo {
if (!self.webState)
return NO;
web::NavigationItem* navItem =
self.webState->GetNavigationManager()->GetVisibleItem();
if (!navItem) {
return NO;
}
const GURL& URL = navItem->GetURL();
// Show site info for offline pages.
if (URL.SchemeIs(kChromeUIScheme) && URL.host() == kChromeUIOfflineHost) {
return YES;
}
return URL.is_valid() && !web::GetWebClient()->IsAppSpecificURL(URL);
}
// Whether the current page is a web page. // Whether the current page is a web page.
- (BOOL)isCurrentURLWebURL { - (BOOL)isCurrentURLWebURL {
if (!self.webState) if (!self.webState)
......
...@@ -164,6 +164,8 @@ source_set("eg_tests") { ...@@ -164,6 +164,8 @@ source_set("eg_tests") {
"//ios/chrome/browser/reading_list", "//ios/chrome/browser/reading_list",
"//ios/chrome/browser/ui:ui", "//ios/chrome/browser/ui:ui",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/tools_menu/public",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
"//ios/testing:ios_test_support", "//ios/testing:ios_test_support",
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
#include "components/reading_list/core/reading_list_model.h" #include "components/reading_list/core/reading_list_model.h"
#include "ios/chrome/browser/reading_list/reading_list_model_factory.h" #include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#import "ios/chrome/browser/ui/commands/reading_list_add_command.h" #import "ios/chrome/browser/ui/commands/reading_list_add_command.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_controller.h" #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_controller.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_empty_collection_background.h" #import "ios/chrome/browser/ui/reading_list/reading_list_empty_collection_background.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button.h" #import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button.h"
#include "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/grit/ios_theme_resources.h" #include "ios/chrome/grit/ios_theme_resources.h"
...@@ -370,6 +372,21 @@ std::map<GURL, std::string> ResponsesForDistillationServer() { ...@@ -370,6 +372,21 @@ std::map<GURL, std::string> ResponsesForDistillationServer() {
return responses; return responses;
} }
// Opens the page security info bubble.
void OpenPageSecurityInfoBubble() {
if (IsUIRefreshPhase1Enabled()) {
// In UI Refresh, the security info is accessed through the tools menu.
[ChromeEarlGreyUI openToolsMenu];
// Tap on the Page Info button.
[ChromeEarlGreyUI
tapToolsMenuButton:grey_accessibilityID(kToolsMenuSiteInformation)];
} else {
[[EarlGrey
selectElementWithMatcher:chrome_test_util::PageSecurityInfoIndicator()]
performAction:grey_tap()];
}
}
// Tests that the correct version of kDistillableURL is displayed. // Tests that the correct version of kDistillableURL is displayed.
void AssertIsShowingDistillablePage(bool online) { void AssertIsShowingDistillablePage(bool online) {
NSString* contentToKeep = base::SysUTF8ToNSString(kContentToKeep); NSString* contentToKeep = base::SysUTF8ToNSString(kContentToKeep);
...@@ -407,13 +424,22 @@ void AssertIsShowingDistillablePage(bool online) { ...@@ -407,13 +424,22 @@ void AssertIsShowingDistillablePage(bool online) {
} }
// Test the presence of the omnibox offline chip. // Test the presence of the omnibox offline chip.
[[EarlGrey if (IsRefreshLocationBarEnabled()) {
selectElementWithMatcher:grey_allOf( [[EarlGrey selectElementWithMatcher:
chrome_test_util::PageSecurityInfoButton(), grey_allOf(chrome_test_util::PageSecurityInfoIndicator(),
chrome_test_util::ButtonWithImage( chrome_test_util::ImageViewWithImageNamed(
IDR_IOS_OMNIBOX_OFFLINE), @"location_bar_offline"),
nil)] nil)]
assertWithMatcher:online ? grey_nil() : grey_notNil()]; assertWithMatcher:online ? grey_nil() : grey_notNil()];
} else {
[[EarlGrey
selectElementWithMatcher:grey_allOf(
chrome_test_util::PageSecurityInfoButton(),
chrome_test_util::ButtonWithImage(
IDR_IOS_OMNIBOX_OFFLINE),
nil)]
assertWithMatcher:online ? grey_nil() : grey_notNil()];
}
} }
} // namespace } // namespace
...@@ -493,9 +519,7 @@ void AssertIsShowingDistillablePage(bool online) { ...@@ -493,9 +519,7 @@ void AssertIsShowingDistillablePage(bool online) {
AssertIsShowingDistillablePage(false); AssertIsShowingDistillablePage(false);
// Tap the Omnibox' Info Bubble to open the Page Info. // Tap the Omnibox' Info Bubble to open the Page Info.
[[EarlGrey OpenPageSecurityInfoBubble();
selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()]
performAction:grey_tap()];
// Verify that the Page Info is about offline pages. // Verify that the Page Info is about offline pages.
id<GREYMatcher> pageInfoTitleMatcher = id<GREYMatcher> pageInfoTitleMatcher =
chrome_test_util::StaticTextWithAccessibilityLabelId( chrome_test_util::StaticTextWithAccessibilityLabelId(
......
...@@ -96,6 +96,11 @@ using chrome_test_util::SystemSelectionCalloutCopyButton; ...@@ -96,6 +96,11 @@ using chrome_test_util::SystemSelectionCalloutCopyButton;
[ChromeEarlGrey loadURL:URL]; [ChromeEarlGrey loadURL:URL];
if (IsRefreshLocationBarEnabled()) {
[[EarlGrey
selectElementWithMatcher:chrome_test_util::DefocusedLocationView()]
performAction:grey_tap()];
}
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
assertWithMatcher:chrome_test_util::OmniboxText(URL.GetContent())]; assertWithMatcher:chrome_test_util::OmniboxText(URL.GetContent())];
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
...@@ -279,6 +284,11 @@ using chrome_test_util::SystemSelectionCalloutCopyButton; ...@@ -279,6 +284,11 @@ using chrome_test_util::SystemSelectionCalloutCopyButton;
// Verifies that copying and pasting a URL includes the hidden protocol prefix. // Verifies that copying and pasting a URL includes the hidden protocol prefix.
- (void)testCopyPasteURL { - (void)testCopyPasteURL {
if (IsRefreshLocationBarEnabled()) {
// TODO(crbug.com/834345): Enable this test when long press on the steady
// location bar is supported.
EARL_GREY_TEST_SKIPPED(@"Test not supported yet in UI Refresh.");
}
// TODO(crbug.com/849932): re-enable this test on iOS 10 once the share button // TODO(crbug.com/849932): re-enable this test on iOS 10 once the share button
// is implemented. // is implemented.
if (!base::ios::IsRunningOnIOS11OrLater()) { if (!base::ios::IsRunningOnIOS11OrLater()) {
...@@ -344,13 +354,6 @@ using chrome_test_util::SystemSelectionCalloutCopyButton; ...@@ -344,13 +354,6 @@ using chrome_test_util::SystemSelectionCalloutCopyButton;
} }
[ChromeEarlGrey loadURL:secondURL]; [ChromeEarlGrey loadURL:secondURL];
if (IsRefreshLocationBarEnabled()) {
// Tap on the steady location view to expose omnibox for pasting.
[[EarlGrey
selectElementWithMatcher:chrome_test_util::DefocusedLocationView()]
performAction:grey_tap()];
}
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
performAction:grey_longPress()]; performAction:grey_longPress()];
...@@ -387,7 +390,13 @@ using chrome_test_util::SystemSelectionCalloutCopyButton; ...@@ -387,7 +390,13 @@ using chrome_test_util::SystemSelectionCalloutCopyButton;
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
assertWithMatcher:chrome_test_util::OmniboxText("foo")]; assertWithMatcher:chrome_test_util::OmniboxText("foo")];
id<GREYMatcher> cancelButton = grey_accessibilityLabel(@"Clear Text"); id<GREYMatcher> cancelButton = nil;
if (IsRefreshLocationBarEnabled()) {
cancelButton = grey_accessibilityLabel(@"Clear text");
} else {
cancelButton = grey_accessibilityLabel(@"Clear Text");
}
[[EarlGrey selectElementWithMatcher:cancelButton] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:cancelButton] performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
...@@ -407,11 +416,7 @@ using chrome_test_util::SystemSelectionCalloutCopyButton; ...@@ -407,11 +416,7 @@ using chrome_test_util::SystemSelectionCalloutCopyButton;
web::test::SetUpSimpleHttpServer(responses); web::test::SetUpSimpleHttpServer(responses);
[ChromeEarlGrey loadURL:GURL(URL)]; [ChromeEarlGrey loadURL:GURL(URL)];
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [ChromeEarlGreyUI focusOmniboxAndType:@"javascript:alert('Hello');\n"];
performAction:grey_typeText(@"javascript:alert('Hello');")];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hello")] [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hello")]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
...@@ -426,11 +431,12 @@ using chrome_test_util::SystemSelectionCalloutCopyButton; ...@@ -426,11 +431,12 @@ using chrome_test_util::SystemSelectionCalloutCopyButton;
EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to a typing bug."); EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to a typing bug.");
} }
[ChromeEarlGrey loadURL:GURL("chrome://version")]; [ChromeEarlGrey loadURL:GURL("chrome://version")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] if (IsRefreshLocationBarEnabled()) {
performAction:grey_typeText(@"javascript:alert('Hello');")]; [[EarlGrey
selectElementWithMatcher:chrome_test_util::DefocusedLocationView()]
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")] performAction:grey_tap()];
performAction:grey_tap()]; }
[ChromeEarlGreyUI focusOmniboxAndType:@"javascript:alert('Hello');\n"];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hello")] [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hello")]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
......
...@@ -406,10 +406,11 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) { ...@@ -406,10 +406,11 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) {
NSString* script = NSString* script =
[NSString stringWithFormat:@"javascript:window.location='%s'", [NSString stringWithFormat:@"javascript:window.location='%s'",
targetURL.spec().c_str()]; targetURL.spec().c_str()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
performAction:grey_typeText(script)]; [ChromeEarlGreyUI focusOmniboxAndType:script];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")] [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")]
performAction:grey_tap()]; performAction:grey_tap()];
[ChromeEarlGrey waitForPageToFinishLoading]; [ChromeEarlGrey waitForPageToFinishLoading];
[[EarlGrey selectElementWithMatcher:OmniboxText(targetURL.GetContent())] [[EarlGrey selectElementWithMatcher:OmniboxText(targetURL.GetContent())]
...@@ -441,11 +442,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) { ...@@ -441,11 +442,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) {
[ChromeEarlGrey loadURL:secondURL]; [ChromeEarlGrey loadURL:secondURL];
// Execute some JavaScript in the omnibox. // Execute some JavaScript in the omnibox.
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [ChromeEarlGreyUI focusOmniboxAndType:@"javascript:document.write('foo')\n"];
performAction:grey_typeText(@"javascript:document.write('foo')")];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")]
performAction:grey_tap()];
[ChromeEarlGrey waitForWebViewContainingText:"foo"]; [ChromeEarlGrey waitForWebViewContainingText:"foo"];
// Verify that the JavaScript did not affect history by going back and then // Verify that the JavaScript did not affect history by going back and then
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ios/chrome/test/app/navigation_test_util.h" #include "ios/chrome/test/app/navigation_test_util.h"
#import "ios/chrome/test/app/web_view_interaction_test_util.h" #import "ios/chrome/test/app/web_view_interaction_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/chrome/test/scoped_block_popups_pref.h" #include "ios/chrome/test/scoped_block_popups_pref.h"
...@@ -211,8 +212,7 @@ class CacheTestResponseProvider : public web::DataResponseProvider { ...@@ -211,8 +212,7 @@ class CacheTestResponseProvider : public web::DataResponseProvider {
[ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 1"]; [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 1"];
// Type a search into omnnibox and select the first suggestion (second row) // Type a search into omnnibox and select the first suggestion (second row)
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] [ChromeEarlGreyUI focusOmniboxAndType:@"cachetestfirstpage"];
performAction:grey_typeText(@"cachetestfirstpage")];
[[EarlGrey [[EarlGrey
selectElementWithMatcher:grey_accessibilityID(@"omnibox suggestion 1")] selectElementWithMatcher:grey_accessibilityID(@"omnibox suggestion 1")]
performAction:grey_tap()]; performAction:grey_tap()];
......
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
// accounts menu is not open when this is called there will be a GREYAssert. // accounts menu is not open when this is called there will be a GREYAssert.
+ (void)tapAccountsMenuButton:(id<GREYMatcher>)buttonMatcher; + (void)tapAccountsMenuButton:(id<GREYMatcher>)buttonMatcher;
// Focuses the omnibox by tapping and types |text| into it. The '\n' symbol can
// be passed in order to commit the string.
+ (void)focusOmniboxAndType:(NSString*)text;
// Open a new tab via the tools menu. // Open a new tab via the tools menu.
+ (void)openNewTab; + (void)openNewTab;
......
...@@ -109,6 +109,16 @@ id<GREYAction> ScrollDown() { ...@@ -109,6 +109,16 @@ id<GREYAction> ScrollDown() {
performAction:grey_tap()]; performAction:grey_tap()];
} }
+ (void)focusOmniboxAndType:(NSString*)text {
if (IsRefreshLocationBarEnabled()) {
[[EarlGrey
selectElementWithMatcher:chrome_test_util::DefocusedLocationView()]
performAction:grey_tap()];
}
[[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
performAction:grey_typeText(text)];
}
+ (void)openNewTab { + (void)openNewTab {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
id<GREYMatcher> newTabButtonMatcher = id<GREYMatcher> newTabButtonMatcher =
......
...@@ -19,6 +19,12 @@ id<GREYMatcher> ButtonWithAccessibilityLabelId(int message_id); ...@@ -19,6 +19,12 @@ id<GREYMatcher> ButtonWithAccessibilityLabelId(int message_id);
// accessibility trait UIAccessibilityTraitButton. // accessibility trait UIAccessibilityTraitButton.
id<GREYMatcher> ButtonWithAccessibilityLabel(NSString* label); id<GREYMatcher> ButtonWithAccessibilityLabel(NSString* label);
// Matcher for element with an image corresponding to |image_id|.
id<GREYMatcher> ImageViewWithImage(int image_id);
// Matcher for element with an image defined by its name in the main bundle.
id<GREYMatcher> ImageViewWithImageNamed(NSString* imageName);
// Matcher for element with an image corresponding to |image_id| and // Matcher for element with an image corresponding to |image_id| and
// accessibility trait UIAccessibilityTraitButton. // accessibility trait UIAccessibilityTraitButton.
id<GREYMatcher> ButtonWithImage(int image_id); id<GREYMatcher> ButtonWithImage(int image_id);
...@@ -57,6 +63,8 @@ id<GREYMatcher> DefocusedLocationView(); ...@@ -57,6 +63,8 @@ id<GREYMatcher> DefocusedLocationView();
// Returns a matcher for the page security info button. // Returns a matcher for the page security info button.
id<GREYMatcher> PageSecurityInfoButton(); id<GREYMatcher> PageSecurityInfoButton();
// Returns a matcher for the page security info indicator.
id<GREYMatcher> PageSecurityInfoIndicator();
// Returns matcher for omnibox containing |text|. Performs an exact match of the // Returns matcher for omnibox containing |text|. Performs an exact match of the
// omnibox contents. // omnibox contents.
......
...@@ -96,6 +96,40 @@ id<GREYMatcher> ButtonWithAccessibilityLabelId(int message_id) { ...@@ -96,6 +96,40 @@ id<GREYMatcher> ButtonWithAccessibilityLabelId(int message_id) {
l10n_util::GetNSStringWithFixup(message_id)); l10n_util::GetNSStringWithFixup(message_id));
} }
id<GREYMatcher> ImageViewWithImageNamed(NSString* imageName) {
UIImage* expected_image = [UIImage imageNamed:imageName];
MatchesBlock matches = ^BOOL(UIImageView* imageView) {
return ui::test::uiimage_utils::UIImagesAreEqual(expected_image,
imageView.image);
};
NSString* description_string =
[NSString stringWithFormat:@"Images matching image named %@", imageName];
DescribeToBlock describe = ^(id<GREYDescription> description) {
[description appendText:description_string];
};
id<GREYMatcher> image_matcher =
[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
descriptionBlock:describe];
return image_matcher;
}
id<GREYMatcher> ImageViewWithImage(int image_id) {
UIImage* expected_image = NativeImage(image_id);
MatchesBlock matches = ^BOOL(UIImageView* imageView) {
return ui::test::uiimage_utils::UIImagesAreEqual(expected_image,
imageView.image);
};
NSString* description_string =
[NSString stringWithFormat:@"Images matching %i", image_id];
DescribeToBlock describe = ^(id<GREYDescription> description) {
[description appendText:description_string];
};
id<GREYMatcher> image_matcher =
[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
descriptionBlock:describe];
return image_matcher;
}
id<GREYMatcher> ButtonWithImage(int image_id) { id<GREYMatcher> ButtonWithImage(int image_id) {
UIImage* expected_image = NativeImage(image_id); UIImage* expected_image = NativeImage(image_id);
MatchesBlock matches = ^BOOL(UIButton* button) { MatchesBlock matches = ^BOOL(UIButton* button) {
...@@ -161,6 +195,10 @@ id<GREYMatcher> PageSecurityInfoButton() { ...@@ -161,6 +195,10 @@ id<GREYMatcher> PageSecurityInfoButton() {
return grey_accessibilityLabel(@"Page Security Info"); return grey_accessibilityLabel(@"Page Security Info");
} }
id<GREYMatcher> PageSecurityInfoIndicator() {
return grey_accessibilityLabel(@"Page Security Info");
}
id<GREYMatcher> OmniboxText(std::string text) { id<GREYMatcher> OmniboxText(std::string text) {
return grey_allOf(Omnibox(), return grey_allOf(Omnibox(),
hasProperty(@"text", base::SysUTF8ToNSString(text)), nil); hasProperty(@"text", base::SysUTF8ToNSString(text)), nil);
......
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