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") { ...@@ -340,6 +340,7 @@ source_set("eg_tests") {
"//base/test:test_support", "//base/test:test_support",
"//components/content_settings/core/common", "//components/content_settings/core/common",
"//components/strings", "//components/strings",
"//components/url_formatter",
"//components/version_info:version_info", "//components/version_info:version_info",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
...@@ -385,6 +386,7 @@ source_set("eg2_tests") { ...@@ -385,6 +386,7 @@ source_set("eg2_tests") {
"cache_egtest.mm", "cache_egtest.mm",
"child_window_open_by_dom_egtest.mm", "child_window_open_by_dom_egtest.mm",
"error_page_egtest.mm", "error_page_egtest.mm",
"forms_egtest.mm",
"http_auth_egtest.mm", "http_auth_egtest.mm",
"js_print_egtest.mm", "js_print_egtest.mm",
"navigation_egtest.mm", "navigation_egtest.mm",
...@@ -396,9 +398,11 @@ source_set("eg2_tests") { ...@@ -396,9 +398,11 @@ source_set("eg2_tests") {
deps = [ deps = [
"//components/content_settings/core/common", "//components/content_settings/core/common",
"//components/strings", "//components/strings",
"//components/url_formatter",
"//components/version_info:version_info", "//components/version_info:version_info",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser:chrome_url_constants", "//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/test:eg_test_support+eg2", "//ios/chrome/test:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/net:test_support", "//ios/net:test_support",
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#include <memory> #include <memory>
...@@ -11,23 +10,20 @@ ...@@ -11,23 +10,20 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "components/strings/grit/components_strings.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/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/app/tab_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_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"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.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/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/element_selector.h"
#include "ios/web/public/test/http_server/data_response_provider.h" #include "ios/web/public/test/http_server/data_response_provider.h"
#import "ios/web/public/test/http_server/http_server.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/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) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -35,6 +31,7 @@ ...@@ -35,6 +31,7 @@
using chrome_test_util::ButtonWithAccessibilityLabelId; using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::OmniboxText; using chrome_test_util::OmniboxText;
using chrome_test_util::TapWebElement;
using chrome_test_util::WebViewMatcher; using chrome_test_util::WebViewMatcher;
using testing::ElementToDismissAlert; using testing::ElementToDismissAlert;
...@@ -218,14 +215,11 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -218,14 +215,11 @@ id<GREYMatcher> ResendPostButtonMatcher() {
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// WKBasedNavigationManager presents repost confirmation dialog before loading // WKBasedNavigationManager presents repost confirmation dialog before loading
// stops. // stops so do not wait for load to complete because it never will. Legacy
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) { // navigation manager presents repost confirmation dialog after loading stops,
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload]; // so wait for load to finish.
} else { BOOL wait = ![ChromeEarlGrey isSlimNavigationManagerEnabled];
// Legacy navigation manager presents repost confirmation dialog after [ChromeEarlGrey reloadAndWaitForCompletion:wait];
// loading stops.
[ChromeEarlGrey reload];
}
{ {
// When slim navigation manager is enabled, synchronization must be disabled // When slim navigation manager is enabled, synchronization must be disabled
...@@ -271,12 +265,12 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -271,12 +265,12 @@ id<GREYMatcher> ResendPostButtonMatcher() {
[ChromeEarlGrey loadURL:GetGenericUrl()]; [ChromeEarlGrey loadURL:GetGenericUrl()];
[ChromeEarlGrey goBack]; [ChromeEarlGrey goBack];
// WKBasedNavigationManager doesn't triggere repost on |goForward| due to // WKBasedNavigationManager doesn't trigger repost on |goForward| due to
// WKWebView's back-forward cache. Force reload to trigger repost. Not using // WKWebView's back-forward cache. Force reload to trigger repost. Not waiting
// [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost // because WKBasedNavigationManager presents repost confirmation dialog before
// confirmation dialog before loading stops. // loading stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) { if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload]; [ChromeEarlGrey reloadAndWaitForCompletion:NO];
} }
{ {
...@@ -327,7 +321,7 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -327,7 +321,7 @@ id<GREYMatcher> ResendPostButtonMatcher() {
// [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost // [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost
// confirmation dialog before loading stops. // confirmation dialog before loading stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) { if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload]; [ChromeEarlGrey reloadAndWaitForCompletion:NO];
} }
{ {
...@@ -374,8 +368,11 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -374,8 +368,11 @@ id<GREYMatcher> ResendPostButtonMatcher() {
[ChromeEarlGrey loadURL:GetGenericUrl()]; [ChromeEarlGrey loadURL:GetGenericUrl()];
[self openBackHistory]; [self openBackHistory];
[self waitForTabHistoryView]; [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()]; [[EarlGrey selectElementWithMatcher:historyItem] performAction:grey_tap()];
[ChromeEarlGrey waitForPageToFinishLoading]; [ChromeEarlGrey waitForPageToFinishLoading];
...@@ -411,7 +408,7 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -411,7 +408,7 @@ id<GREYMatcher> ResendPostButtonMatcher() {
// [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost // [ChromeEarlGrey reload] because WKBasedNavigationManager presents repost
// confirmation dialog before loading stops. // confirmation dialog before loading stops.
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) { if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload]; [ChromeEarlGrey reloadAndWaitForCompletion:NO];
} }
{ {
...@@ -470,14 +467,11 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -470,14 +467,11 @@ id<GREYMatcher> ResendPostButtonMatcher() {
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// WKBasedNavigationManager presents repost confirmation dialog before loading // WKBasedNavigationManager presents repost confirmation dialog before loading
// stops. // stops so do not wait for load to complete because it never will. Legacy
if ([ChromeEarlGrey isSlimNavigationManagerEnabled]) { // navigation manager presents repost confirmation dialog after loading stops,
[chrome_test_util::BrowserCommandDispatcherForMainBVC() reload]; // so wait for load to finish.
} else { BOOL wait = ![ChromeEarlGrey isSlimNavigationManagerEnabled];
// Legacy navigation manager presents repost confirmation dialog after [ChromeEarlGrey reloadAndWaitForCompletion:wait];
// loading stops.
[ChromeEarlGrey reload];
}
{ {
// When slim navigation manager is enabled, synchronization must be disabled // When slim navigation manager is enabled, synchronization must be disabled
...@@ -622,9 +616,7 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -622,9 +616,7 @@ id<GREYMatcher> ResendPostButtonMatcher() {
conditionWithName:@"Wait for web view to be interactable." conditionWithName:@"Wait for web view to be interactable."
block:^BOOL { block:^BOOL {
NSError* error = nil; NSError* error = nil;
id<GREYMatcher> webViewMatcher = WebViewInWebState( [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
chrome_test_util::GetCurrentWebState());
[[EarlGrey selectElementWithMatcher:webViewMatcher]
assertWithMatcher:grey_interactable() assertWithMatcher:grey_interactable()
error:&error]; error:&error];
return !error; return !error;
...@@ -633,10 +625,8 @@ id<GREYMatcher> ResendPostButtonMatcher() { ...@@ -633,10 +625,8 @@ id<GREYMatcher> ResendPostButtonMatcher() {
waitWithTimeout:base::test::ios::kWaitForUIElementTimeout], waitWithTimeout:base::test::ios::kWaitForUIElementTimeout],
@"Web view did not become interactable."); @"Web view did not become interactable.");
web::WebState* currentWebState = chrome_test_util::GetCurrentWebState();
[[EarlGrey selectElementWithMatcher:WebViewMatcher()] [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:web::WebViewTapElement( performAction:TapWebElement(
currentWebState,
[ElementSelector selectorWithElementID:ID])]; [ElementSelector selectorWithElementID:ID])];
// Wait until the keyboard shows up before tapping. // Wait until the keyboard shows up before tapping.
......
...@@ -102,6 +102,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -102,6 +102,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// GREYAssert is induced. // GREYAssert is induced.
- (void)reload; - (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 // Navigates back to the previous page and waits for the loading to complete
// within a timeout, or a GREYAssert is induced. // within a timeout, or a GREYAssert is induced.
- (void)goBack; - (void)goBack;
......
...@@ -173,8 +173,14 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -173,8 +173,14 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
} }
- (void)reload { - (void)reload {
[self reloadAndWaitForCompletion:YES];
}
- (void)reloadAndWaitForCompletion:(BOOL)wait {
[ChromeEarlGreyAppInterface startReloading]; [ChromeEarlGreyAppInterface startReloading];
[self waitForPageToFinishLoading]; if (wait) {
[self waitForPageToFinishLoading];
}
} }
#pragma mark - Tab Utilities (EG2) #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