Commit 148c5a06 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add EG test for infobar with adaptive toolbar

This CL adds an Earl Grey test to check the interactions between the
infobars and the bottom adaptive toolbar.

Bug: 804747
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ife30026fd1390d4b86896aca2f7f0f33407926cc
Reviewed-on: https://chromium-review.googlesource.com/955023
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541795}
parent b18148a5
......@@ -47,6 +47,19 @@ source_set("unit_tests") {
]
}
source_set("test_support") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"test_infobar_delegate.h",
"test_infobar_delegate.mm",
]
deps = [
"//base",
"//components/infobars/core",
]
}
source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
......@@ -54,6 +67,7 @@ source_set("eg_tests") {
"infobar_egtest.mm",
]
deps = [
":test_support",
"//base",
"//components/infobars/core",
"//ios/chrome/app:app_internal",
......
......@@ -6,14 +6,13 @@
#import <XCTest/XCTest.h>
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_manager.h"
#import "ios/chrome/app/main_controller.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/infobars/test_infobar_delegate.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_earl_grey.h"
......@@ -30,36 +29,9 @@
namespace {
// The title of the test infobar.
const char kTestInfoBarTitle[] = "TestInfoBar";
// Timeout for how long to wait for an infobar to appear or disapper.
const CFTimeInterval kTimeout = 4.0;
// An infobar that displays a single line of text and no buttons.
class TestInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
static bool Create(infobars::InfoBarManager* infobar_manager);
// InfoBarDelegate implementation.
InfoBarIdentifier GetIdentifier() const override { return TEST_INFOBAR; }
// ConfirmInfoBarDelegate implementation.
base::string16 GetMessageText() const override {
return base::ASCIIToUTF16(kTestInfoBarTitle);
}
int GetButtons() const override {
return ConfirmInfoBarDelegate::BUTTON_NONE;
}
};
bool TestInfoBarDelegate::Create(infobars::InfoBarManager* infobar_manager) {
DCHECK(infobar_manager);
return !!infobar_manager->AddInfoBar(infobar_manager->CreateConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate)));
}
// Returns the InfoBarManager for the current tab. Only works in normal
// (non-incognito) mode.
infobars::InfoBarManager* GetCurrentInfoBarManager() {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_INFOBARS_TEST_INFOBAR_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_INFOBARS_TEST_INFOBAR_DELEGATE_H_
#include "base/strings/utf_string_conversions.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
// The title of the test infobar.
extern const char kTestInfoBarTitle[];
// An infobar that displays a single line of text and no buttons.
class TestInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
static bool Create(infobars::InfoBarManager* infobar_manager);
// InfoBarDelegate implementation.
InfoBarIdentifier GetIdentifier() const override;
// ConfirmInfoBarDelegate implementation.
base::string16 GetMessageText() const override;
int GetButtons() const override;
};
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_TEST_INFOBAR_DELEGATE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/infobars/test_infobar_delegate.h"
#include "components/infobars/core/infobar.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const char kTestInfoBarTitle[] = "TestInfoBar";
bool TestInfoBarDelegate::Create(infobars::InfoBarManager* infobar_manager) {
DCHECK(infobar_manager);
return !!infobar_manager->AddInfoBar(infobar_manager->CreateConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate)));
}
TestInfoBarDelegate::InfoBarIdentifier TestInfoBarDelegate::GetIdentifier()
const {
return TEST_INFOBAR;
}
base::string16 TestInfoBarDelegate::GetMessageText() const {
return base::ASCIIToUTF16(kTestInfoBarTitle);
}
int TestInfoBarDelegate::GetButtons() const {
return ConfirmInfoBarDelegate::BUTTON_OK;
}
......@@ -94,7 +94,9 @@ source_set("eg_tests") {
"//base",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/ui:ui_util",
"//ios/chrome/browser/ui/infobars:test_support",
"//ios/chrome/browser/ui/toolbar/buttons",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
......
......@@ -5,12 +5,16 @@
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#include "base/strings/sys_string_conversions.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/ui/infobars/test_infobar_delegate.h"
#import "ios/chrome/browser/ui/toolbar/adaptive/primary_toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/adaptive/secondary_toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/buttons/toolbar_constants.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/chrome/browser/ui/util/top_view_controller.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/test/app/bookmarks_test_util.h"
......@@ -35,6 +39,7 @@ const char kPageURL[] = "/test-page.html";
const char kPageURL2[] = "/test-page-2.html";
const char kPageURL3[] = "/test-page-3.html";
const char kLinkID[] = "linkID";
const char kTextID[] = "textID";
const char kPageLoadedString[] = "Page loaded!";
// Provides responses for redirect and changed window location URLs.
......@@ -49,6 +54,18 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
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.
id<GREYMatcher> BookmarkButton() {
return chrome_test_util::ButtonWithAccessibilityLabelId(IDS_TOOLTIP_STAR);
......@@ -90,6 +107,12 @@ id<GREYMatcher> VisibleInSecondaryToolbar() {
grey_sufficientlyVisible(), nil);
}
bool AddInfobar() {
infobars::InfoBarManager* manager =
InfoBarManagerImpl::FromWebState(chrome_test_util::GetCurrentWebState());
return TestInfoBarDelegate::Create(manager);
}
// Rotate the device if it is an iPhone or change the trait collection to
// compact width if it is an iPad. Returns the new trait collection.
UITraitCollection* RotateOrChangeTraitCollection(
......@@ -375,6 +398,94 @@ void CheckToolbarButtonVisibilityWithOmniboxFocused(
}
}
// Tests the interactions between the infobars and the bottom toolbar during
// fullscreen.
- (void)testInfobarFullscreen {
if (!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 and check the bookmark button is not selected.
[ChromeEarlGrey loadURL:self.testServer->GetURL(kPageURL)];
GREYAssert(AddInfobar(), @"Failed to add infobar.");
[[GREYCondition
conditionWithName:@"Waiting for infobar to show"
block:^BOOL {
NSError* error = nil;
[[EarlGrey
selectElementWithMatcher:
chrome_test_util::StaticTextWithAccessibilityLabel(
base::SysUTF8ToNSString(kTestInfoBarTitle))]
assertWithMatcher:grey_sufficientlyVisible()
error:&error];
return error == nil;
}] waitWithTimeout:4];
// Check that the button is visible.
[[EarlGrey selectElementWithMatcher:chrome_test_util::OKButton()]
assertWithMatcher:grey_sufficientlyVisible()];
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
GREYElementMatcherBlock* positionMatcher = [GREYElementMatcherBlock
matcherWithMatchesBlock:^BOOL(UIView* element) {
UILayoutGuide* guide =
[NamedGuide guideWithName:kSecondaryToolbar 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;
if (@available(iOS 11, *)) {
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:web::WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
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_kindOfClass([SecondaryToolbarView class])]
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
// during navigations.
- (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