Commit d02b6092 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Turn on Messages flag for EG Tests

This change turns on the Infobar Messages feature flag and modifies
assertions to check for the different accessibility identifiers.
Tests that are no longer relevant because only one infobar is
shown at a given time are removed.

Change-Id: Iffae041b5dce319b3a376e71f73afff80d441061
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095079
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748980}
parent 39170911
...@@ -121,12 +121,14 @@ source_set("eg_tests") { ...@@ -121,12 +121,14 @@ source_set("eg_tests") {
deps = [ deps = [
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/infobars/core:feature_flags",
"//ios/chrome/app:app_internal", "//ios/chrome/app:app_internal",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser:browser", "//ios/chrome/browser:browser",
"//ios/chrome/browser/download", "//ios/chrome/browser/download",
"//ios/chrome/browser/download:test_support", "//ios/chrome/browser/download:test_support",
"//ios/chrome/browser/ui/browser_view", "//ios/chrome/browser/ui/browser_view",
"//ios/chrome/browser/ui/infobars/banners:public",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/test:eg_test_support", "//ios/chrome/test:eg_test_support",
"//ios/chrome/test:test_support", "//ios/chrome/test:test_support",
...@@ -160,10 +162,12 @@ source_set("eg2_tests") { ...@@ -160,10 +162,12 @@ source_set("eg2_tests") {
] ]
deps = [ deps = [
"//components/infobars/core:feature_flags",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser:chrome_url_constants", "//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/download:mime_types", "//ios/chrome/browser/download:mime_types",
"//ios/chrome/browser/download:test_support", "//ios/chrome/browser/download:test_support",
"//ios/chrome/browser/ui/infobars/banners:public",
"//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/testing:embedded_test_server_support", "//ios/testing:embedded_test_server_support",
......
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
#include "base/bind.h" #include "base/bind.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "components/infobars/core/infobar_feature.h"
#include "ios/chrome/browser/download/download_test_util.h" #include "ios/chrome/browser/download/download_test_util.h"
#include "ios/chrome/browser/download/pass_kit_mime_type.h" #include "ios/chrome/browser/download/pass_kit_mime_type.h"
#import "ios/chrome/browser/ui/infobars/banners/infobar_banner_constants.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.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_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/testing/earl_grey/app_launch_manager.h"
#import "ios/testing/earl_grey/earl_grey_test.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_request.h"
...@@ -20,6 +23,7 @@ ...@@ -20,6 +23,7 @@
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#if defined(CHROME_EARL_GREY_1) #if defined(CHROME_EARL_GREY_1)
#include "base/test/scoped_feature_list.h"
// EG1 test relies on view controller presentation as the signal that PassKit // EG1 test relies on view controller presentation as the signal that PassKit
// Dialog is shown. // Dialog is shown.
#import "ios/chrome/app/main_controller.h" // nogncheck #import "ios/chrome/app/main_controller.h" // nogncheck
...@@ -38,9 +42,10 @@ namespace { ...@@ -38,9 +42,10 @@ namespace {
// Returns matcher for PassKit error infobar. // Returns matcher for PassKit error infobar.
id<GREYMatcher> PassKitErrorInfobar() { id<GREYMatcher> PassKitErrorInfobar() {
using l10n_util::GetNSStringWithFixup; return grey_allOf(grey_accessibilityID(kInfobarBannerViewIdentifier),
NSString* label = GetNSStringWithFixup(IDS_IOS_GENERIC_PASSKIT_ERROR); grey_accessibilityLabel(
return grey_accessibilityLabel(label); l10n_util::GetNSString(IDS_IOS_GENERIC_PASSKIT_ERROR)),
nil);
} }
// PassKit landing page and download request handler. // PassKit landing page and download request handler.
...@@ -70,15 +75,30 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse( ...@@ -70,15 +75,30 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse(
@interface PassKitEGTest : ChromeTestCase @interface PassKitEGTest : ChromeTestCase
@end @end
@implementation PassKitEGTest @implementation PassKitEGTest {
#if defined(CHROME_EARL_GREY_1)
base::test::ScopedFeatureList _featureList;
#endif
}
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
// Turn on Messages UI.
#if defined(CHROME_EARL_GREY_1)
_featureList.InitAndEnableFeature(kIOSInfobarUIReboot);
#endif
self.testServer->RegisterRequestHandler(base::Bind(&GetResponse)); self.testServer->RegisterRequestHandler(base::Bind(&GetResponse));
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start."); GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
} }
- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
config.features_enabled.push_back(kIOSInfobarUIReboot);
return config;
}
// Tests that Chrome presents PassKit error infobar if pkpass file cannot be // Tests that Chrome presents PassKit error infobar if pkpass file cannot be
// parsed. // parsed.
- (void)testPassKitParsingError { - (void)testPassKitParsingError {
......
...@@ -184,6 +184,10 @@ source_set("eg_tests") { ...@@ -184,6 +184,10 @@ source_set("eg_tests") {
deps = [ deps = [
":eg_test_support", ":eg_test_support",
"//base", "//base",
"//base/test:test_support",
"//components/infobars/core:feature_flags",
"//ios/chrome/browser/ui/infobars:constants",
"//ios/chrome/browser/ui/infobars/banners:public",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
"//ios/testing/earl_grey:earl_grey_support", "//ios/testing/earl_grey:earl_grey_support",
"//ios/web/public/test/http_server", "//ios/web/public/test/http_server",
......
...@@ -5,10 +5,16 @@ ...@@ -5,10 +5,16 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h"
#include "components/infobars/core/infobar_feature.h"
#import "ios/chrome/browser/ui/infobars/banners/infobar_banner_constants.h"
#import "ios/chrome/browser/ui/infobars/infobar_constants.h"
#import "ios/chrome/browser/ui/infobars/infobar_manager_app_interface.h" #import "ios/chrome/browser/ui/infobars/infobar_manager_app_interface.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_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/testing/earl_grey/app_launch_manager.h"
#import "ios/testing/earl_grey/earl_grey_test.h" #import "ios/testing/earl_grey/earl_grey_test.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"
...@@ -28,20 +34,18 @@ ...@@ -28,20 +34,18 @@
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(InfobarManagerAppInterface); GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(InfobarManagerAppInterface);
#endif // defined(CHROME_EARL_GREY_2) #endif // defined(CHROME_EARL_GREY_2)
namespace { using base::test::ios::WaitUntilConditionOrTimeout;
// Timeout for how long to wait for an infobar to appear or disapper. namespace {
const CFTimeInterval kTimeout = 4.0;
// Verifies that a single TestInfoBar with |message| is either present or absent // Verifies that a single TestInfoBar with |message| is either present or absent
// on the current tab. // on the current tab.
void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
id<GREYMatcher> expected_visibility =
visible ? grey_minimumVisiblePercent(1.0f) : grey_notVisible();
NSString* condition_name = NSString* condition_name =
visible ? @"Waiting for infobar to show" : @"Waiting for infobar to hide"; visible ? @"Waiting for infobar to show" : @"Waiting for infobar to hide";
id<GREYMatcher> expected_visibility = visible ? grey_notNil() : grey_nil();
#if defined(CHROME_EARL_GREY_1) #if defined(CHROME_EARL_GREY_1)
CFTimeInterval kTimeout = 4.0;
[[GREYCondition [[GREYCondition
conditionWithName:condition_name conditionWithName:condition_name
block:^BOOL { block:^BOOL {
...@@ -54,20 +58,20 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { ...@@ -54,20 +58,20 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
return error == nil; return error == nil;
}] waitWithTimeout:kTimeout]; }] waitWithTimeout:kTimeout];
#elif defined(CHROME_EARL_GREY_2) #elif defined(CHROME_EARL_GREY_2)
GREYAssertTrue( BOOL bannerShown = WaitUntilConditionOrTimeout(
[[GREYCondition kInfobarBannerDefaultPresentationDurationInSeconds, ^{
conditionWithName:condition_name NSError* error = nil;
block:^BOOL { [[EarlGrey
NSError* error = nil; selectElementWithMatcher:grey_allOf(
[[EarlGrey grey_accessibilityID(
selectElementWithMatcher: kInfobarBannerViewIdentifier),
chrome_test_util:: grey_accessibilityLabel(message), nil)]
StaticTextWithAccessibilityLabel(message)] assertWithMatcher:expected_visibility
assertWithMatcher:expected_visibility error:&error];
error:&error]; return error == nil;
return error == nil; });
}] waitWithTimeout:kTimeout],
condition_name); GREYAssertTrue(bannerShown, condition_name);
#else #else
#error Must define either CHROME_EARL_GREY_1 or CHROME_EARL_GREY_2. #error Must define either CHROME_EARL_GREY_1 or CHROME_EARL_GREY_2.
#endif #endif
...@@ -79,12 +83,18 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { ...@@ -79,12 +83,18 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
@interface InfobarTestCase : ChromeTestCase @interface InfobarTestCase : ChromeTestCase
@end @end
@implementation InfobarTestCase @implementation InfobarTestCase {
base::test::ScopedFeatureList _featureList;
}
- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
config.features_enabled.push_back(kIOSInfobarUIReboot);
return config;
}
// Tests that page infobars don't persist on navigation. // Tests that page infobars don't persist on navigation.
- (void)testInfobarsDismissOnNavigate { - (void)testInfobarsDismissOnNavigate {
web::test::SetUpFileBasedHttpServer();
// Open a new tab and navigate to the test page. // Open a new tab and navigate to the test page.
const GURL testURL = web::test::HttpServer::MakeUrl( const GURL testURL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/pony.html"); "http://ios/testing/data/http_server_files/pony.html");
...@@ -118,7 +128,6 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { ...@@ -118,7 +128,6 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
"http://ios/testing/data/http_server_files/destination.html"); "http://ios/testing/data/http_server_files/destination.html");
const GURL ponyURL = web::test::HttpServer::MakeUrl( const GURL ponyURL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/pony.html"); "http://ios/testing/data/http_server_files/pony.html");
web::test::SetUpFileBasedHttpServer();
// Create the first tab and navigate to the test page. // Create the first tab and navigate to the test page.
[ChromeEarlGrey loadURL:destinationURL]; [ChromeEarlGrey loadURL:destinationURL];
...@@ -151,19 +160,13 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { ...@@ -151,19 +160,13 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
// navigation does not hide the infobar in the second tab. // navigation does not hide the infobar in the second tab.
[ChromeEarlGrey loadURL:ponyURL]; [ChromeEarlGrey loadURL:ponyURL];
// Close the first tab. Verify that there is only one tab remaining and its // Close the first tab. Verify that there is only one tab remaining.
// infobar is visible.
[ChromeEarlGrey closeCurrentTab]; [ChromeEarlGrey closeCurrentTab];
[ChromeEarlGrey waitForMainTabCount:1]; [ChromeEarlGrey waitForMainTabCount:1];
VerifyTestInfoBarVisibleForCurrentTab(true, infoBarMessage);
GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:1],
@"Incorrect number of infobars.");
} }
// Tests that the Infobar dissapears once the "OK" button is tapped. // Tests that the Infobar dissapears once the "OK" button is tapped.
- (void)testInfobarButtonDismissal { - (void)testInfobarButtonDismissal {
web::test::SetUpFileBasedHttpServer();
// Open a new tab and navigate to the test page. // Open a new tab and navigate to the test page.
const GURL testURL = web::test::HttpServer::MakeUrl( const GURL testURL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/pony.html"); "http://ios/testing/data/http_server_files/pony.html");
...@@ -194,7 +197,10 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { ...@@ -194,7 +197,10 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
// Tests adding an Infobar on top of an existing one. // Tests adding an Infobar on top of an existing one.
- (void)testInfobarTopMostVisible { - (void)testInfobarTopMostVisible {
web::test::SetUpFileBasedHttpServer(); // Turn on Messages UI.
#if defined(CHROME_EARL_GREY_1)
_featureList.InitAndEnableFeature(kIOSInfobarUIReboot);
#endif
// Open a new tab and navigate to the test page. // Open a new tab and navigate to the test page.
const GURL testURL = web::test::HttpServer::MakeUrl( const GURL testURL = web::test::HttpServer::MakeUrl(
...@@ -224,15 +230,21 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { ...@@ -224,15 +230,21 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
[InfobarManagerAppInterface [InfobarManagerAppInterface
addTestInfoBarToCurrentTabWithMessage:secondInfoBarMessage], addTestInfoBarToCurrentTabWithMessage:secondInfoBarMessage],
@"Failed to add infobar to test tab."); @"Failed to add infobar to test tab.");
VerifyTestInfoBarVisibleForCurrentTab(true, secondInfoBarMessage);
VerifyTestInfoBarVisibleForCurrentTab(false, firstInfoBarMessage);
GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:2], GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:2],
@"Incorrect number of infobars."); @"Incorrect number of infobars.");
VerifyTestInfoBarVisibleForCurrentTab(false, firstInfoBarMessage);
VerifyTestInfoBarVisibleForCurrentTab(true, secondInfoBarMessage);
// Confirm infobars are destroyed after their banners are dismissed.
GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:1],
@"Incorrect number of infobars.");
} }
// Tests that a taller Infobar layout is correct and the OK button is tappable. // Tests that a taller Infobar layout is correct and the OK button is tappable.
- (void)testInfobarTallerLayout { - (void)testInfobarTallerLayout {
web::test::SetUpFileBasedHttpServer(); // Turn on Messages UI.
#if defined(CHROME_EARL_GREY_1)
_featureList.InitAndEnableFeature(kIOSInfobarUIReboot);
#endif
// Open a new tab and navigate to the test page. // Open a new tab and navigate to the test page.
const GURL testURL = web::test::HttpServer::MakeUrl( const GURL testURL = web::test::HttpServer::MakeUrl(
...@@ -264,58 +276,4 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { ...@@ -264,58 +276,4 @@ void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:0], GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:0],
@"Incorrect number of infobars."); @"Incorrect number of infobars.");
} }
// Tests that adding an Infobar of lower height on top of a taller Infobar only
// displays the top shorter one, and that after dismissing the shorter Infobar
// the taller infobar is now completely displayed again.
- (void)testInfobarTopMostVisibleHeight {
web::test::SetUpFileBasedHttpServer();
// Open a new tab and navigate to the test page.
const GURL testURL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/pony.html");
[ChromeEarlGrey loadURL:testURL];
[ChromeEarlGrey waitForMainTabCount:1];
// First Infobar Message
NSString* firstInfoBarMessage =
@"This is a really long message that will cause this infobar height to "
@"increase since Confirm Infobar heights changes depending on its "
@"message.";
// Add a test infobar to the current tab. Verify that the infobar is present
// in the model and that the infobar view is visible on screen.
GREYAssertTrue([InfobarManagerAppInterface
addTestInfoBarToCurrentTabWithMessage:firstInfoBarMessage],
@"Failed to add infobar to test tab.");
VerifyTestInfoBarVisibleForCurrentTab(true, firstInfoBarMessage);
GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:1],
@"Incorrect number of infobars.");
// Second Infobar Message
NSString* secondInfoBarMessage = @"TestSecondInfoBar";
// Add a second test infobar to the current tab. Verify that the infobar is
// present in the model, and that only this second infobar is now visible on
// screen.
GREYAssertTrue(
[InfobarManagerAppInterface
addTestInfoBarToCurrentTabWithMessage:secondInfoBarMessage],
@"Failed to add infobar to test tab.");
VerifyTestInfoBarVisibleForCurrentTab(true, secondInfoBarMessage);
VerifyTestInfoBarVisibleForCurrentTab(false, firstInfoBarMessage);
GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:2],
@"Incorrect number of infobars.");
// Dismiss the second Infobar.
[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_buttonTitle(@"OK"),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
VerifyTestInfoBarVisibleForCurrentTab(false, secondInfoBarMessage);
VerifyTestInfoBarVisibleForCurrentTab(true, firstInfoBarMessage);
GREYAssertTrue([InfobarManagerAppInterface verifyInfobarCount:1],
@"Incorrect number of infobars.");
}
@end @end
...@@ -48,7 +48,6 @@ const char kPageURL[] = "/test-page.html"; ...@@ -48,7 +48,6 @@ const char kPageURL[] = "/test-page.html";
const char kPageURL2[] = "/test-page-2.html"; const char kPageURL2[] = "/test-page-2.html";
const char kPageURL3[] = "/test-page-3.html"; const char kPageURL3[] = "/test-page-3.html";
const char kLinkID[] = "linkID"; const char kLinkID[] = "linkID";
const char kTextID[] = "textID";
const char kPageLoadedString[] = "Page loaded!"; const char kPageLoadedString[] = "Page loaded!";
// The title of the test infobar. // The title of the test infobar.
...@@ -73,18 +72,6 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse( ...@@ -73,18 +72,6 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
return std::move(http_response); return std::move(http_response);
} }
// Provides response for a very tall page.
std::unique_ptr<net::test_server::HttpResponse> TallPageResponse(
const net::test_server::HttpRequest& request) {
std::unique_ptr<net::test_server::BasicHttpResponse> http_response =
std::make_unique<net::test_server::BasicHttpResponse>();
http_response->set_code(net::HTTP_OK);
http_response->set_content(
"<html><body><p style=\"height:2000pt\"></p><p id=\"" +
std::string(kTextID) + "\">" + kPageLoadedString + "</p></body></html>");
return std::move(http_response);
}
// Returns a matcher for the bookmark button. // Returns a matcher for the bookmark button.
id<GREYMatcher> BookmarkButton() { id<GREYMatcher> BookmarkButton() {
return chrome_test_util::ButtonWithAccessibilityLabelId(IDS_TOOLTIP_STAR); return chrome_test_util::ButtonWithAccessibilityLabelId(IDS_TOOLTIP_STAR);
...@@ -541,100 +528,6 @@ UIViewController* TopPresentedViewController() { ...@@ -541,100 +528,6 @@ UIViewController* TopPresentedViewController() {
CheckToolbarButtonVisibility(originalTraitCollection, YES); CheckToolbarButtonVisibility(originalTraitCollection, YES);
} }
// Tests the interactions between the infobars and the bottom toolbar during
// fullscreen.
- (void)testInfobarFullscreen {
if (![ChromeEarlGrey isSplitToolbarMode]) {
// The interaction between the infobar and fullscreen only happens in split
// toolbar mode.
return;
}
// Setup the server.
self.testServer->RegisterRequestHandler(
base::BindRepeating(&TallPageResponse));
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
// Navigate to a page.
[ChromeEarlGrey loadURL:self.testServer->GetURL(kPageURL)];
GREYAssert(
[AdaptiveToolbarAppInterface addInfobarWithTitle:kTestInfoBarTitle],
@"Fail to create infobar.");
GREYAssert(
[[GREYCondition
conditionWithName:@"Waiting for infobar to show"
block:^BOOL {
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:
chrome_test_util::
StaticTextWithAccessibilityLabel(
kTestInfoBarTitle)]
assertWithMatcher:grey_sufficientlyVisible()
error:&error];
return error == nil;
}] waitWithTimeout:4],
@"Infobar did not show.");
// Check that the button is visible.
[[EarlGrey selectElementWithMatcher:chrome_test_util::OKButton()]
assertWithMatcher:grey_sufficientlyVisible()];
#if defined(CHROME_EARL_GREY_1)
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
#else
UIWindow* window =
[[GREY_REMOTE_CLASS_IN_APP(UIApplication) sharedApplication] keyWindow];
#endif
GREYElementMatcherBlock* positionMatcher = [GREYElementMatcherBlock
matcherWithMatchesBlock:^BOOL(UIView* element) {
UILayoutGuide* guide =
[ChromeEarlGreyAppInterface guideWithName:kSecondaryToolbarGuide
view:element];
CGFloat toolbarTopPoint = CGRectGetMinY(
[window convertRect:guide.layoutFrame fromView:guide.owningView]);
CGFloat buttonBottomPoint = CGRectGetMaxY(
[window convertRect:element.frame fromView:element.superview]);
CGFloat bottomSafeArea = CGFLOAT_MAX;
bottomSafeArea = CGRectGetMaxY(window.safeAreaLayoutGuide.layoutFrame);
CGFloat infobarContentBottomPoint =
MIN(bottomSafeArea, toolbarTopPoint);
BOOL buttonIsAbove = buttonBottomPoint < infobarContentBottomPoint - 10;
BOOL buttonIsNear = buttonBottomPoint > infobarContentBottomPoint - 30;
return buttonIsAbove && buttonIsNear;
}
descriptionBlock:^void(id<GREYDescription> description) {
[description
appendText:@"Infobar is position on top of the bottom toolbar."];
}];
// Check that the button is positionned above the bottom toolbar.
[[EarlGrey selectElementWithMatcher:chrome_test_util::OKButton()]
assertWithMatcher:positionMatcher];
// Scroll down
[[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()]
performAction:grey_swipeFastInDirection(kGREYDirectionUp)];
// Check that the button is visible.
[[EarlGrey selectElementWithMatcher:chrome_test_util::OKButton()]
assertWithMatcher:grey_sufficientlyVisible()];
// Check that the secondary toolbar is not visible.
[[EarlGrey
selectElementWithMatcher:grey_kindOfClassName(@"SecondaryToolbarView")]
assertWithMatcher:grey_not(grey_sufficientlyVisible())];
// Check that the button is positionned above the bottom toolbar (i.e. at the
// bottom).
[[EarlGrey selectElementWithMatcher:chrome_test_util::OKButton()]
assertWithMatcher:positionMatcher];
}
// Verifies that the back/forward buttons are working and are correctly enabled // Verifies that the back/forward buttons are working and are correctly enabled
// during navigations. // during navigations.
- (void)testNavigationButtons { - (void)testNavigationButtons {
......
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