Commit 837cbb87 authored by Eric Aleshire's avatar Eric Aleshire Committed by Commit Bot

Move GREYAsserts from chrome_earl_grey_ui into the corresponding EG tests.

This is part of EG1 to EG2 migration, which involves moving EarlGrey code from
app-side helpers into test code. For GREYAsserts, the policy is to take assert-
containing-helpers, modify them to return NSError* with localizedDescription
containing the assert failure (in the event of a failure), and then assert
on the result of the helper on the test side.

Bug: 922813
Change-Id: I9d881648b15a3e1bd69eed3ccfa20d7aee7d3dfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1562756
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650512}
parent f1198d75
......@@ -96,7 +96,9 @@ void AssertURLIs(const GURL& expectedURL) {
"http://ios/testing/data/http_server_files/two_pages.pdf");
[ChromeEarlGrey loadURL:URL];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
// Initial y scroll positions are set to make room for the toolbar.
// TODO(crbug.com/618887) Replace use of specific values when API which
// generates these values is exposed.
......@@ -136,12 +138,15 @@ void AssertURLIs(const GURL& expectedURL) {
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
// Test that the toolbar is still visible even after attempting to hide it
// on swipe up.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError2 = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError2,
toolbarVisibleError2.localizedDescription);
// Reenable synchronization.
if (@available(iOS 12, *)) {
......@@ -170,18 +175,24 @@ void AssertURLIs(const GURL& expectedURL) {
// Test that the toolbar is hidden after a user swipes up.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
// Test that the toolbar is visible after a user swipes down.
[[EarlGrey
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
// Test that the toolbar is hidden after a user swipes up.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError2 =
[ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError2,
toolbarNotVisibleError2.localizedDescription);
}
// Tests that link clicks from a chrome:// to chrome:// link result in the
......@@ -225,12 +236,15 @@ void AssertURLIs(const GURL& expectedURL) {
// Scroll to hide the UI.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
// Test that the toolbar is visible when moving from one chrome:// link to
// another chrome:// link.
GREYAssert(TapWebViewElementWithId("version"), @"Failed to tap \"version\"");
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
}
// Tests hiding and showing of the header with a user scroll on a long page.
......@@ -243,16 +257,21 @@ void AssertURLIs(const GURL& expectedURL) {
web::test::SetUpSimpleHttpServer(responses);
[ChromeEarlGrey loadURL:URL];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
// Simulate a user scroll down.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
// Simulate a user scroll up.
[[EarlGrey
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError2 = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError2,
toolbarVisibleError2.localizedDescription);
}
// Tests that reloading of a page shows the header even if it was not shown
......@@ -273,12 +292,15 @@ void AssertURLIs(const GURL& expectedURL) {
// Hide the toolbar.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
GREYAssert(TapWebViewElementWithId("link"), @"Failed to tap \"link\"");
// Main test is here: Make sure the header is still visible!
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
}
// Test to make sure the header is shown when a Tab opened by the current Tab is
......@@ -314,7 +336,9 @@ void AssertURLIs(const GURL& expectedURL) {
// Hide the toolbar.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
// Open new window.
GREYAssert(TapWebViewElementWithId("link1"), @"Failed to tap \"link1\"");
......@@ -327,7 +351,10 @@ void AssertURLIs(const GURL& expectedURL) {
// Hide the toolbar.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError2 =
[ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError2,
toolbarNotVisibleError2.localizedDescription);
// Close the tab by tapping link2.
NSError* error = nil;
......@@ -347,7 +374,8 @@ void AssertURLIs(const GURL& expectedURL) {
// Make sure the toolbar is on the screen.
[ChromeEarlGrey waitForMainTabCount:1];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
}
// Tests that the header is shown when a regular page (non-native page) is
......@@ -377,24 +405,32 @@ void AssertURLIs(const GURL& expectedURL) {
[ChromeEarlGrey waitForWebViewContainingText:"link1"];
// Dismiss the toolbar.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
// Navigate to the other page.
GREYAssert(TapWebViewElementWithId("link1"), @"Failed to tap \"link1\"");
[ChromeEarlGrey waitForWebViewContainingText:"link2"];
// Make sure toolbar is shown since a new load has started.
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
// Dismiss the toolbar.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError2 =
[ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError2,
toolbarNotVisibleError2.localizedDescription);
// Go back.
GREYAssert(TapWebViewElementWithId("link2"), @"Failed to tap \"link2\"");
// Make sure the toolbar has loaded now that a new page has loaded.
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError2 = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError2,
toolbarVisibleError2.localizedDescription);
}
// Tests that the header is shown when a native page is loaded from a page where
......@@ -416,13 +452,16 @@ void AssertURLIs(const GURL& expectedURL) {
// Dismiss the toolbar.
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
// Go back to NTP, which is a native view.
GREYAssert(TapWebViewElementWithId("link"), @"Failed to tap \"link\"");
// Make sure the toolbar is visible now that a new page has loaded.
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
}
// Tests that the header is shown when loading an error page in a native view
......@@ -443,11 +482,14 @@ void AssertURLIs(const GURL& expectedURL) {
[ChromeEarlGrey loadURL:URL];
HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO];
NSError* toolbarNotVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:NO];
GREYAssertNil(toolbarNotVisibleError,
toolbarNotVisibleError.localizedDescription);
GREYAssert(TapWebViewElementWithId("link"), @"Failed to tap \"link\"");
AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl());
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* toolbarVisibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(toolbarVisibleError, toolbarVisibleError.localizedDescription);
}
@end
......@@ -196,7 +196,8 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider {
[[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)]
assertWithMatcher:grey_sufficientlyVisible()];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* visibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(visibleError, visibleError.localizedDescription);
infinitePendingProvider->Abort();
}
......@@ -236,7 +237,8 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider {
[[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)]
assertWithMatcher:grey_sufficientlyVisible()];
[ChromeEarlGreyUI waitForToolbarVisible:YES];
NSError* visibleError = [ChromeEarlGreyUI waitForToolbarVisible:YES];
GREYAssertNil(visibleError, visibleError.localizedDescription);
infinitePendingProvider->Abort();
}
......
......@@ -6,8 +6,10 @@
#define IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_UI_H_
#import <Foundation/Foundation.h>
#include "base/compiler_specific.h"
@protocol GREYMatcher;
@class NSError;
// Test methods that perform actions on Chrome. These methods only affect Chrome
// using the UI with Earl Grey.
......@@ -80,7 +82,7 @@
// Waits for toolbar to become visible if |isVisible| is YES, otherwise waits
// for it to disappear. If the condition is not met within a timeout, a
// GREYAssert is induced.
+ (void)waitForToolbarVisible:(BOOL)isVisible;
+ (NSError*)waitForToolbarVisible:(BOOL)isVisible WARN_UNUSED_RESULT;
@end
......
......@@ -19,6 +19,7 @@
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#include "ios/chrome/test/app/navigation_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/web/public/test/earl_grey/js_test_util.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
......@@ -204,7 +205,7 @@ id<GREYAction> ScrollDown() {
performAction:grey_tap()];
}
+ (void)waitForToolbarVisible:(BOOL)isVisible {
+ (NSError*)waitForToolbarVisible:(BOOL)isVisible {
const NSTimeInterval kWaitForToolbarAnimationTimeout = 1.0;
ConditionBlock condition = ^{
NSError* error = nil;
......@@ -216,9 +217,13 @@ id<GREYAction> ScrollDown() {
};
NSString* errorMessage =
isVisible ? @"Toolbar was not visible" : @"Toolbar was visible";
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
kWaitForToolbarAnimationTimeout, condition),
errorMessage);
if (!base::test::ios::WaitUntilConditionOrTimeout(
kWaitForToolbarAnimationTimeout, condition)) {
return chrome_test_util::NSErrorWithLocalizedDescription(errorMessage);
}
return nil;
}
@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