Commit 6a083248 authored by Lindsay Pasricha's avatar Lindsay Pasricha Committed by Commit Bot

[ios] Convert web view shell EarlGrey matchers to ObjC

We need to port matchers to ObjC in order to be accessible in EG2 to
the Test and the App processes. Also created
shell_matchers_shorthand.h/mm to minimize the changes to call sites.

Bug: 930859
Change-Id: Ia4a4ba8c7dd3b805600ea0c46c5b737a8282189d
Reviewed-on: https://chromium-review.googlesource.com/c/1471914
Commit-Queue: Lindsay Pasricha <lindsayw@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636214}
parent 2808b7ec
......@@ -87,6 +87,8 @@ source_set("earl_grey_test_support") {
"earl_grey/shell_earl_grey.mm",
"earl_grey/shell_matchers.h",
"earl_grey/shell_matchers.mm",
"earl_grey/shell_matchers_shorthand.h",
"earl_grey/shell_matchers_shorthand.mm",
"earl_grey/web_shell_test_case.h",
"earl_grey/web_shell_test_case.mm",
]
......
......@@ -18,6 +18,7 @@
#import "ios/web/shell/test/earl_grey/shell_actions.h"
#import "ios/web/shell/test/earl_grey/shell_earl_grey.h"
#import "ios/web/shell/test/earl_grey/shell_matchers.h"
#import "ios/web/shell/test/earl_grey/shell_matchers_shorthand.h"
#import "ios/web/shell/test/earl_grey/web_shell_test_case.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......
......@@ -5,30 +5,34 @@
#ifndef IOS_WEB_SHELL_TEST_EARL_GREY_SHELL_MATCHERS_H_
#define IOS_WEB_SHELL_TEST_EARL_GREY_SHELL_MATCHERS_H_
#import <Foundation/Foundation.h>
#include <string>
#import <EarlGrey/EarlGrey.h>
// ObjC matcher class for use in EG2 tests (Test and App process).
// Shell_matchers_shorthand.h/mm is C++ and for use when writing EG1 tests.
@protocol GREYMatcher;
namespace web {
@interface ShellMatchers : NSObject
// Matcher for the WKWebView.
id<GREYMatcher> WebView();
+ (id<GREYMatcher>)webView;
// Matcher for WKWebView's scroll view.
id<GREYMatcher> WebViewScrollView();
+ (id<GREYMatcher>)webViewScrollView;
// Matcher for web shell address field text property equal to |text|.
id<GREYMatcher> AddressFieldText(std::string text);
+ (id<GREYMatcher>)addressFieldWithText:(NSString*)text;
// Matcher for back button in web shell.
id<GREYMatcher> BackButton();
+ (id<GREYMatcher>)backButton;
// Matcher for forward button in web shell.
id<GREYMatcher> ForwardButton();
+ (id<GREYMatcher>)forwardButton;
// Matcher for address field in web shell.
id<GREYMatcher> AddressField();
+ (id<GREYMatcher>)addressField;
} // namespace web
@end
#endif // IOS_WEB_SHELL_TEST_EARL_GREY_SHELL_MATCHERS_H_
......@@ -17,17 +17,17 @@
#error "This file requires ARC support."
#endif
namespace web {
@implementation ShellMatchers
id<GREYMatcher> WebView() {
return WebViewInWebState(shell_test_util::GetCurrentWebState());
+ (id<GREYMatcher>)webView {
return WebViewInWebState(web::shell_test_util::GetCurrentWebState());
}
id<GREYMatcher> WebViewScrollView() {
return WebViewScrollView(shell_test_util::GetCurrentWebState());
+ (id<GREYMatcher>)webViewScrollView {
return WebViewScrollView(web::shell_test_util::GetCurrentWebState());
}
id<GREYMatcher> AddressFieldText(std::string text) {
+ (id<GREYMatcher>)addressFieldWithText:(NSString*)text {
MatchesBlock matches = ^BOOL(UIView* view) {
if (![view isKindOfClass:[UITextField class]]) {
return NO;
......@@ -39,12 +39,12 @@ id<GREYMatcher> AddressFieldText(std::string text) {
UITextField* text_field = base::mac::ObjCCastStrict<UITextField>(view);
NSString* error_message = [NSString
stringWithFormat:
@"Address field text did not match. expected: %@, actual: %@",
base::SysUTF8ToNSString(text), text_field.text];
@"Address field text did not match. expected: %@, actual: %@", text,
text_field.text];
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout,
^{
return base::SysNSStringToUTF8(text_field.text) == text;
return [text_field.text isEqualToString:text];
}),
error_message);
return YES;
......@@ -52,23 +52,23 @@ id<GREYMatcher> AddressFieldText(std::string text) {
DescribeToBlock describe = ^(id<GREYDescription> description) {
[description appendText:@"address field containing "];
[description appendText:base::SysUTF8ToNSString(text)];
[description appendText:text];
};
return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
descriptionBlock:describe];
}
id<GREYMatcher> BackButton() {
+ (id<GREYMatcher>)backButton {
return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel);
}
id<GREYMatcher> ForwardButton() {
+ (id<GREYMatcher>)forwardButton {
return grey_accessibilityLabel(kWebShellForwardButtonAccessibilityLabel);
}
id<GREYMatcher> AddressField() {
+ (id<GREYMatcher>)addressField {
return grey_accessibilityLabel(kWebShellAddressFieldAccessibilityLabel);
}
} // namespace web
@end
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_SHELL_TEST_EARL_GREY_SHELL_MATCHERS_SHORTHAND_H_
#define IOS_WEB_SHELL_TEST_EARL_GREY_SHELL_MATCHERS_SHORTHAND_H_
#import <Foundation/Foundation.h>
#include <string>
// Matchers for use in EG1 tests and in EG2 App Process.
@protocol GREYMatcher;
namespace web {
// Matcher for the WKWebView.
id<GREYMatcher> WebView();
// Matcher for WKWebView's scroll view.
id<GREYMatcher> WebViewScrollView();
// Matcher for web shell address field text property equal to |text|.
id<GREYMatcher> AddressFieldText(std::string text);
// Matcher for back button in web shell.
id<GREYMatcher> BackButton();
// Matcher for forward button in web shell.
id<GREYMatcher> ForwardButton();
// Matcher for address field in web shell.
id<GREYMatcher> AddressField();
} // namespace web
#endif // IOS_WEB_SHELL_TEST_EARL_GREY_SHELL_MATCHERS_SHORTHAND_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <WebKit/WebKit.h>
#include "base/strings/sys_string_conversions.h"
#import "ios/web/shell/test/earl_grey/shell_matchers.h"
#import "ios/web/shell/test/earl_grey/shell_matchers_shorthand.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web {
id<GREYMatcher> WebView() {
return [ShellMatchers webView];
}
id<GREYMatcher> WebViewScrollView() {
return [ShellMatchers webViewScrollView];
}
id<GREYMatcher> AddressFieldText(std::string text) {
return [ShellMatchers addressFieldWithText:base::SysUTF8ToNSString(text)];
}
id<GREYMatcher> BackButton() {
return [ShellMatchers backButton];
}
id<GREYMatcher> ForwardButton() {
return [ShellMatchers forwardButton];
}
id<GREYMatcher> AddressField() {
return [ShellMatchers addressField];
}
} // namespace web
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#include <map>
#include "base/strings/stringprintf.h"
......@@ -10,6 +12,7 @@
#include "ios/web/public/test/http_server/http_server_util.h"
#import "ios/web/shell/test/earl_grey/shell_earl_grey.h"
#import "ios/web/shell/test/earl_grey/shell_matchers.h"
#import "ios/web/shell/test/earl_grey/shell_matchers_shorthand.h"
#import "ios/web/shell/test/earl_grey/web_shell_test_case.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......
......@@ -12,6 +12,7 @@
#include "ios/web/public/test/http_server/http_server_util.h"
#import "ios/web/shell/test/earl_grey/shell_earl_grey.h"
#import "ios/web/shell/test/earl_grey/shell_matchers.h"
#import "ios/web/shell/test/earl_grey/shell_matchers_shorthand.h"
#import "ios/web/shell/test/earl_grey/web_shell_test_case.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......
......@@ -10,6 +10,7 @@
#include "ios/web/public/test/http_server/http_server_util.h"
#import "ios/web/shell/test/earl_grey/shell_earl_grey.h"
#import "ios/web/shell/test/earl_grey/shell_matchers.h"
#import "ios/web/shell/test/earl_grey/shell_matchers_shorthand.h"
#import "ios/web/shell/test/earl_grey/web_shell_test_case.h"
#include "net/http/http_status_code.h"
......
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