Commit 6d759e9e authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Convert FormsTestCase to EarlGrey 2

Additionally add a boolean parameter to [ChromeEarlGrey reload] to
make the wait after the reload optional based on the parameter value.

Bug: 987646
Change-Id: I2d6aecf5ed34274b256c66a0b9504cd9a2799992
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1909710
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714623}
parent 3cd75283
......@@ -340,6 +340,7 @@ source_set("eg_tests") {
"//base/test:test_support",
"//components/content_settings/core/common",
"//components/strings",
"//components/url_formatter",
"//components/version_info:version_info",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
......@@ -385,6 +386,7 @@ source_set("eg2_tests") {
"cache_egtest.mm",
"child_window_open_by_dom_egtest.mm",
"error_page_egtest.mm",
"forms_egtest.mm",
"http_auth_egtest.mm",
"js_print_egtest.mm",
"navigation_egtest.mm",
......@@ -396,9 +398,11 @@ source_set("eg2_tests") {
deps = [
"//components/content_settings/core/common",
"//components/strings",
"//components/url_formatter",
"//components/version_info:version_info",
"//ios/chrome/app/strings",
"//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/test:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/net:test_support",
......
......@@ -2,7 +2,6 @@
// 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 <XCTest/XCTest.h>
#include <memory>
......@@ -11,23 +10,20 @@
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/url_formatter.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.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_test_case.h"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/testing/earl_grey/matchers.h"
#import "ios/web/public/test/earl_grey/web_view_actions.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#include "ios/web/public/test/element_selector.h"
#include "ios/web/public/test/http_server/data_response_provider.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
#include "ios/web/public/test/url_test_util.h"
#import "ios/web/public/web_client.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -35,6 +31,7 @@
using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::OmniboxText;
using chrome_test_util::TapWebElement;
using chrome_test_util::WebViewMatcher;
using testing::ElementToDismissAlert;
......@@ -218,14 +215,11 @@ id<GREYMatcher> ResendPostButtonMatcher() {
assertWithMatcher:grey_notNil()];
// WKBasedNavigationManager presents repost confirmation dialog before loading
// stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload];
} else {
// Legacy navigation manager presents repost confirmation dialog after
// loading stops.
[ChromeEarlGrey reload];
}
// stops so do not wait for load to complete because it never will. Legacy
// navigation manager presents repost confirmation dialog after loading stops,
// so wait for load to finish.
BOOL wait = ![ChromeEarlGrey isSlimNavigationManagerEnabled];
[ChromeEarlGrey reloadAndWaitForCompletion:wait];
{
// When slim navigation manager is enabled, synchronization must be disabled
......@@ -271,12 +265,12 @@ id<GREYMatcher> ResendPostButtonMatcher() {
[ChromeEarlGrey loadURL:GetGenericUrl()];
[ChromeEarlGrey goBack];
// WKBasedNavigationManager doesn't triggere repost on |goForward| due to
// WKWebView's back-forward cache. Force reload to trigger repost. Not using
// [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost
// confirmation dialog before loading stops.
// WKBasedNavigationManager doesn't trigger repost on |goForward| due to
// WKWebView's back-forward cache. Force reload to trigger repost. Not waiting
// because WKBasedNavigationManager presents repost confirmation dialog before
// loading stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload];
[ChromeEarlGrey reloadAndWaitForCompletion:NO];
}
{
......@@ -327,7 +321,7 @@ id<GREYMatcher> ResendPostButtonMatcher() {
// [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost
// confirmation dialog before loading stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload];
[ChromeEarlGrey reloadAndWaitForCompletion:NO];
}
{
......@@ -374,8 +368,11 @@ id<GREYMatcher> ResendPostButtonMatcher() {
[ChromeEarlGrey loadURL:GetGenericUrl()];
[self openBackHistory];
[self waitForTabHistoryView];
id<GREYMatcher> historyItem = grey_text(
base::SysUTF16ToNSString(web::GetDisplayTitleForUrl(destinationURL)));
// Mimic |web::GetDisplayTitleForUrl| behavior which uses FormatUrl
// internally. It can't be called directly from the EarlGrey 2 test process.
base::string16 title = url_formatter::FormatUrl(destinationURL);
id<GREYMatcher> historyItem = grey_text(base::SysUTF16ToNSString(title));
[[EarlGrey selectElementWithMatcher:historyItem] performAction:grey_tap()];
[ChromeEarlGrey waitForPageToFinishLoading];
......@@ -411,7 +408,7 @@ id<GREYMatcher> ResendPostButtonMatcher() {
// [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost
// confirmation dialog before loading stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload];
[ChromeEarlGrey reloadAndWaitForCompletion:NO];
}
{
......@@ -470,14 +467,11 @@ id<GREYMatcher> ResendPostButtonMatcher() {
assertWithMatcher:grey_notNil()];
// WKBasedNavigationManager presents repost confirmation dialog before loading
// stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload];
} else {
// Legacy navigation manager presents repost confirmation dialog after
// loading stops.
[ChromeEarlGrey reload];
}
// stops so do not wait for load to complete because it never will. Legacy
// navigation manager presents repost confirmation dialog after loading stops,
// so wait for load to finish.
BOOL wait = ![ChromeEarlGrey isSlimNavigationManagerEnabled];
[ChromeEarlGrey reloadAndWaitForCompletion:wait];
{
// When slim navigation manager is enabled, synchronization must be disabled
......@@ -622,9 +616,7 @@ id<GREYMatcher> ResendPostButtonMatcher() {
conditionWithName:@"Wait for web view to be interactable."
block:^BOOL {
NSError* error = nil;
id<GREYMatcher> webViewMatcher = WebViewInWebState(
chrome_test_util::GetCurrentWebState());
[[EarlGrey selectElementWithMatcher:webViewMatcher]
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
assertWithMatcher:grey_interactable()
error:&error];
return !error;
......@@ -633,10 +625,8 @@ id<GREYMatcher> ResendPostButtonMatcher() {
waitWithTimeout:base::test::ios::kWaitForUIElementTimeout],
@"Web view did not become interactable.");
web::WebState* currentWebState = chrome_test_util::GetCurrentWebState();
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:web::WebViewTapElement(
currentWebState,
performAction:TapWebElement(
[ElementSelector selectorWithElementID:ID])];
// Wait until the keyboard shows up before tapping.
......
......@@ -102,6 +102,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// GREYAssert is induced.
- (void)reload;
// Reloads the page. If |wait| is YES, waits for the loading to complete within
// a timeout, or a GREYAssert is induced.
- (void)reloadAndWaitForCompletion:(BOOL)wait;
// Navigates back to the previous page and waits for the loading to complete
// within a timeout, or a GREYAssert is induced.
- (void)goBack;
......
......@@ -173,8 +173,14 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
}
- (void)reload {
[self reloadAndWaitForCompletion:YES];
}
- (void)reloadAndWaitForCompletion:(BOOL)wait {
[ChromeEarlGreyAppInterface startReloading];
[self waitForPageToFinishLoading];
if (wait) {
[self waitForPageToFinishLoading];
}
}
#pragma mark - Tab Utilities (EG2)
......
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