Commit 7c6040db authored by Eric Aleshire's avatar Eric Aleshire Committed by Commit Bot

Convert chrome_earl_grey's goBack to compile under EG2.

goBack requires waitForPageToFinishLoading, so that is converted also.
The wait is moved from app-side to test-side using a GREYCondition.

Uses http://crrev.com/c/1578949 as a guideline.

Bug: 922813
Change-Id: I4e4616f5f9bc7857e89e28df01171d3167e396c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610548
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661096}
parent d9bef2dd
...@@ -38,11 +38,25 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -38,11 +38,25 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// will properly synchronize the UI for Earl Grey tests. // will properly synchronize the UI for Earl Grey tests.
@interface ChromeEarlGreyImpl : BaseEGTestHelperImpl @interface ChromeEarlGreyImpl : BaseEGTestHelperImpl
#pragma mark - History Utilities #pragma mark - History Utilities (EG2)
// Clears browsing history. Raises an EarlGrey exception if history is not // Clears browsing history. Raises an EarlGrey exception if history is not
// cleared within a timeout. // cleared within a timeout.
- (void)clearBrowsingHistory; - (void)clearBrowsingHistory;
#pragma mark - Navigation Utilities (EG2)
// Navigates back to the previous page and waits for the loading to complete
// within a timeout, or a GREYAssert is induced.
// TODO(crbug.com/963613): Change return type to void when
// CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)goBack;
// Waits for the page to finish loading within a timeout, or a GREYAssert is
// induced.
// TODO(crbug.com/963613): Change return type to void when
// CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)waitForPageToFinishLoading;
@end @end
// Helpers that only compile under EarlGrey 1 are included in this "EG1" // Helpers that only compile under EarlGrey 1 are included in this "EG1"
...@@ -85,12 +99,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -85,12 +99,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// CHROME_EG_ASSERT_NO_ERROR is removed. // CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)reload; - (NSError*)reload;
// Navigates back to the previous page and waits for the loading to complete
// within a timeout, or a GREYAssert is induced.
// TODO(crbug.com/963613): Change return type to void when
// CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)goBack;
// Navigates forward to the next page and waits for the loading to complete // Navigates forward to the next page and waits for the loading to complete
// within a timeout, or a GREYAssert is induced. // within a timeout, or a GREYAssert is induced.
// TODO(crbug.com/963613): Change return type to void when // TODO(crbug.com/963613): Change return type to void when
...@@ -120,12 +128,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -120,12 +128,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// Closes the current tab and waits for the UI to complete. // Closes the current tab and waits for the UI to complete.
- (void)closeCurrentTab; - (void)closeCurrentTab;
// Waits for the page to finish loading within a timeout, or a GREYAssert is
// induced.
// TODO(crbug.com/963613): Change return type to void when
// CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)waitForPageToFinishLoading;
// Taps html element with |elementID| in the current web view. // Taps html element with |elementID| in the current web view.
- (NSError*)tapWebViewElementWithID:(NSString*)elementID WARN_UNUSED_RESULT; - (NSError*)tapWebViewElementWithID:(NSString*)elementID WARN_UNUSED_RESULT;
......
...@@ -39,9 +39,14 @@ ...@@ -39,9 +39,14 @@
#endif #endif
using base::test::ios::kWaitForJSCompletionTimeout; using base::test::ios::kWaitForJSCompletionTimeout;
using base::test::ios::kWaitForPageLoadTimeout;
using base::test::ios::kWaitForUIElementTimeout; using base::test::ios::kWaitForUIElementTimeout;
using base::test::ios::WaitUntilConditionOrTimeout; using base::test::ios::WaitUntilConditionOrTimeout;
namespace {
NSString* kWaitForPageToFinishLoadingError = @"Page did not finish loading";
}
#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."
#endif #endif
...@@ -63,6 +68,26 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -63,6 +68,26 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
} }
- (NSError*)goBack {
[ChromeEarlGreyAppInterface goBack];
[self waitForPageToFinishLoading];
return nil;
}
- (NSError*)waitForPageToFinishLoading {
GREYCondition* finishedLoading = [GREYCondition
conditionWithName:kWaitForPageToFinishLoadingError
block:^{
return ![ChromeEarlGreyAppInterface isLoading];
}];
bool pageLoaded = [finishedLoading waitWithTimeout:kWaitForPageLoadTimeout];
EG_TEST_HELPER_ASSERT_TRUE(pageLoaded, kWaitForPageToFinishLoadingError);
return nil;
}
@end @end
// The helpers below only compile under EarlGrey1. // The helpers below only compile under EarlGrey1.
...@@ -160,13 +185,6 @@ id ExecuteJavaScript(NSString* javascript, ...@@ -160,13 +185,6 @@ id ExecuteJavaScript(NSString* javascript,
return nil; return nil;
} }
- (NSError*)goBack {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() goBack];
[self waitForPageToFinishLoading];
return nil;
}
- (NSError*)goForward { - (NSError*)goForward {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() goForward]; [chrome_test_util::BrowserCommandDispatcherForMainBVC() goForward];
[self waitForPageToFinishLoading]; [self waitForPageToFinishLoading];
...@@ -208,13 +226,6 @@ id ExecuteJavaScript(NSString* javascript, ...@@ -208,13 +226,6 @@ id ExecuteJavaScript(NSString* javascript,
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
} }
- (NSError*)waitForPageToFinishLoading {
bool pageLoaded = chrome_test_util::WaitForPageToFinishLoading();
EG_TEST_HELPER_ASSERT_TRUE(pageLoaded, @"Page did not finish loading");
return nil;
}
- (NSError*)tapWebViewElementWithID:(NSString*)elementID { - (NSError*)tapWebViewElementWithID:(NSString*)elementID {
BOOL success = BOOL success =
web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(),
......
...@@ -17,6 +17,12 @@ ...@@ -17,6 +17,12 @@
// operation failed. // operation failed.
+ (NSError*)clearBrowsingHistory; + (NSError*)clearBrowsingHistory;
// Returns YES if the current WebState is loading.
+ (BOOL)isLoading;
// Navigates back to the previous page.
+ (void)goBack;
@end @end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_APP_INTERFACE_H_ #endif // IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_APP_INTERFACE_H_
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#import "ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/history_test_util.h" #import "ios/chrome/test/app/history_test_util.h"
#include "ios/chrome/test/app/navigation_test_util.h"
#import "ios/testing/nserror_util.h" #import "ios/testing/nserror_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -22,4 +24,12 @@ ...@@ -22,4 +24,12 @@
@"Clearing browser history timed out"); @"Clearing browser history timed out");
} }
+ (bool)isLoading {
return chrome_test_util::IsLoading();
}
+ (void)goBack {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() goBack];
}
@end @end
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