Commit 9bbfdb18 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Deletes InfobarContainerDelegates

Since the InfobarView is no longer communicating its size to Infobar.cc
there's no need to have the machinery necessary so Infobar.cc communicates
with our InfobarContainerView.

The InfobarContainerView will be updated via the VC viewDidLayoutSubviews
which was the change made on https://crrev.com/c/1321849/

Adds an extra test case.

Bug: 892376
Change-Id: I5457c17a8e1e586b02b5ca9906abd4341e5a56d4
Reviewed-on: https://chromium-review.googlesource.com/c/1325034Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606911}
parent a5a398e8
...@@ -10,11 +10,8 @@ source_set("infobars") { ...@@ -10,11 +10,8 @@ source_set("infobars") {
"confirm_infobar_controller.mm", "confirm_infobar_controller.mm",
"infobar.h", "infobar.h",
"infobar.mm", "infobar.mm",
"infobar_container_delegate_ios.h",
"infobar_container_delegate_ios.mm",
"infobar_container_ios.h", "infobar_container_ios.h",
"infobar_container_ios.mm", "infobar_container_ios.mm",
"infobar_container_state_delegate.h",
"infobar_controller+protected.h", "infobar_controller+protected.h",
"infobar_controller.h", "infobar_controller.h",
"infobar_controller.mm", "infobar_controller.mm",
......
// Copyright 2017 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_INFOBARS_INFOBAR_CONTAINER_DELEGATE_IOS_H_
#define IOS_CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_DELEGATE_IOS_H_
#import <Foundation/Foundation.h>
#include "components/infobars/core/infobar_container.h"
#include "third_party/skia/include/core/SkColor.h"
@protocol InfobarContainerStateDelegate;
// iOS implementation of InfoBarContainer::Delegate. Most of the method
// implementations are no-ops, since the iOS UI should not be driven or managed
// by the cross-platform infobar code.
class InfoBarContainerDelegateIOS
: public infobars::InfoBarContainer::Delegate {
public:
explicit InfoBarContainerDelegateIOS(
id<InfobarContainerStateDelegate> delegate)
: delegate_(delegate) {}
~InfoBarContainerDelegateIOS() override {}
// Informs |delegate_| that the container state has changed.
void InfoBarContainerStateChanged(bool is_animating) override;
private:
__weak id<InfobarContainerStateDelegate> delegate_;
};
#endif // IOS_CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_DELEGATE_IOS_H_
// Copyright 2017 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/infobars/infobar_container_delegate_ios.h"
#include "base/logging.h"
#include "ios/chrome/browser/infobars/infobar_container_state_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
void InfoBarContainerDelegateIOS::InfoBarContainerStateChanged(
bool is_animating) {
[delegate_ infoBarContainerStateDidChangeAnimated:is_animating];
}
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
// that only the front most one is visible at any time. // that only the front most one is visible at any time.
class InfoBarContainerIOS : public infobars::InfoBarContainer { class InfoBarContainerIOS : public infobars::InfoBarContainer {
public: public:
InfoBarContainerIOS(infobars::InfoBarContainer::Delegate* delegate, InfoBarContainerIOS(id<InfobarContainerConsumer> consumer);
id<InfobarContainerConsumer> consumer);
~InfoBarContainerIOS() override; ~InfoBarContainerIOS() override;
protected: protected:
...@@ -28,7 +27,6 @@ class InfoBarContainerIOS : public infobars::InfoBarContainer { ...@@ -28,7 +27,6 @@ class InfoBarContainerIOS : public infobars::InfoBarContainer {
void PlatformSpecificInfoBarStateChanged(bool is_animating) override; void PlatformSpecificInfoBarStateChanged(bool is_animating) override;
private: private:
InfoBarContainer::Delegate* delegate_;
id<InfobarContainerConsumer> consumer_; id<InfobarContainerConsumer> consumer_;
DISALLOW_COPY_AND_ASSIGN(InfoBarContainerIOS); DISALLOW_COPY_AND_ASSIGN(InfoBarContainerIOS);
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
#include "ios/chrome/browser/infobars/infobar_container_ios.h" #include "ios/chrome/browser/infobars/infobar_container_ios.h"
#include <stddef.h>
#include "base/logging.h"
#include "ios/chrome/browser/infobars/infobar.h" #include "ios/chrome/browser/infobars/infobar.h"
#import "ios/chrome/browser/ui/infobars/infobar_container_consumer.h" #import "ios/chrome/browser/ui/infobars/infobar_container_consumer.h"
...@@ -14,15 +11,10 @@ ...@@ -14,15 +11,10 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
InfoBarContainerIOS::InfoBarContainerIOS( InfoBarContainerIOS::InfoBarContainerIOS(id<InfobarContainerConsumer> consumer)
infobars::InfoBarContainer::Delegate* delegate, : InfoBarContainer(nullptr), consumer_(consumer) {}
id<InfobarContainerConsumer> consumer)
: InfoBarContainer(delegate), delegate_(delegate), consumer_(consumer) {
DCHECK(delegate);
}
InfoBarContainerIOS::~InfoBarContainerIOS() { InfoBarContainerIOS::~InfoBarContainerIOS() {
delegate_ = nullptr;
RemoveAllInfoBarsForDestruction(); RemoveAllInfoBarsForDestruction();
} }
...@@ -36,13 +28,6 @@ void InfoBarContainerIOS::PlatformSpecificRemoveInfoBar( ...@@ -36,13 +28,6 @@ void InfoBarContainerIOS::PlatformSpecificRemoveInfoBar(
infobars::InfoBar* infobar) { infobars::InfoBar* infobar) {
InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar); InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar);
infobar_ios->RemoveView(); infobar_ios->RemoveView();
// If computed_height() is 0, then the infobar was removed after an animation.
// In this case, signal the delegate that the state changed.
// Otherwise, the infobar is being replaced by another one. Do not call the
// delegate in this case, as the delegate will be updated when the new infobar
// is added.
if (infobar->computed_height() == 0 && delegate_)
delegate_->InfoBarContainerStateChanged(false);
} }
void InfoBarContainerIOS::PlatformSpecificInfoBarStateChanged( void InfoBarContainerIOS::PlatformSpecificInfoBarStateChanged(
......
// Copyright 2017 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_INFOBARS_INFOBAR_CONTAINER_STATE_DELEGATE_H_
#define IOS_CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_STATE_DELEGATE_H_
#import <Foundation/Foundation.h>
// Delegate protocol for an object that is informed of events relating to the
// state of the infobar container.
@protocol InfobarContainerStateDelegate
// Tells the delegate that the infobar container's state changed. If |animated|
// is YES, the state change happened as part of an animation.
- (void)infoBarContainerStateDidChangeAnimated:(BOOL)animated;
@end
#endif // IOS_CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_STATE_DELEGATE_H_
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
#import "ios/chrome/browser/ui/infobars/infobar_container_mediator.h" #import "ios/chrome/browser/ui/infobars/infobar_container_mediator.h"
#include "ios/chrome/browser/infobars/infobar_container_delegate_ios.h"
#include "ios/chrome/browser/infobars/infobar_container_ios.h" #include "ios/chrome/browser/infobars/infobar_container_ios.h"
#include "ios/chrome/browser/infobars/infobar_container_state_delegate.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h" #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/tabs/tab.h" #import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_model.h" #import "ios/chrome/browser/tabs/tab_model.h"
...@@ -23,11 +21,8 @@ ...@@ -23,11 +21,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface InfobarContainerMediator ()<InfobarContainerStateDelegate, @interface InfobarContainerMediator ()<TabModelObserver,
TabModelObserver,
WebStateListObserving> { WebStateListObserving> {
// Bridge class to deliver container change notifications.
std::unique_ptr<InfoBarContainerDelegateIOS> _infoBarContainerDelegate;
// A single infobar container handles all infobars in all tabs. It keeps // A single infobar container handles all infobars in all tabs. It keeps
// track of infobars for current tab (accessed via infobar helper of // track of infobars for current tab (accessed via infobar helper of
// the current tab). // the current tab).
...@@ -61,9 +56,7 @@ ...@@ -61,9 +56,7 @@
_tabModel = tabModel; _tabModel = tabModel;
_webStateList = _tabModel.webStateList; _webStateList = _tabModel.webStateList;
_infoBarContainerDelegate.reset(new InfoBarContainerDelegateIOS(self)); _infoBarContainer.reset(new InfoBarContainerIOS(_consumer));
_infoBarContainer.reset(
new InfoBarContainerIOS(_infoBarContainerDelegate.get(), _consumer));
infobars::InfoBarManager* infoBarManager = nullptr; infobars::InfoBarManager* infoBarManager = nullptr;
if (_tabModel.currentTab) { if (_tabModel.currentTab) {
DCHECK(_tabModel.currentTab.webState); DCHECK(_tabModel.currentTab.webState);
...@@ -85,12 +78,6 @@ ...@@ -85,12 +78,6 @@
_webStateListObserver.reset(); _webStateListObserver.reset();
} }
#pragma mark - InfobarContainerStateDelegate
- (void)infoBarContainerStateDidChangeAnimated:(BOOL)animated {
[self.consumer updateLayoutAnimated:animated];
}
#pragma mark - TabModelObserver #pragma mark - TabModelObserver
// TODO(crbug.com/892376): Stop observing TabModel and use WebStateList instead. // TODO(crbug.com/892376): Stop observing TabModel and use WebStateList instead.
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h" #import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
#import "ios/chrome/browser/infobars/infobar_container_state_delegate.h"
namespace infobars { namespace infobars {
class InfoBarManager; class InfoBarManager;
} }
......
...@@ -56,7 +56,7 @@ bool AddTestInfoBarToCurrentTabWithMessage(NSString* message) { ...@@ -56,7 +56,7 @@ bool AddTestInfoBarToCurrentTabWithMessage(NSString* message) {
// on the current tab. // on the current tab.
void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) { void VerifyTestInfoBarVisibleForCurrentTab(bool visible, NSString* message) {
id<GREYMatcher> expected_visibility = id<GREYMatcher> expected_visibility =
visible ? grey_sufficientlyVisible() : grey_notVisible(); 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";
...@@ -222,6 +222,38 @@ void VerifyNumberOfInfobarsInManager(size_t number_of_infobars) { ...@@ -222,6 +222,38 @@ void VerifyNumberOfInfobarsInManager(size_t number_of_infobars) {
VerifyNumberOfInfobarsInManager(2); VerifyNumberOfInfobarsInManager(2);
} }
// Tests that a taller Infobar layout is correct and the OK button is tappable.
- (void)testInfobarTallerLayout {
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];
// 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.
GREYAssert(AddTestInfoBarToCurrentTabWithMessage(firstInfoBarMessage),
@"Failed to add infobar to test tab.");
VerifyTestInfoBarVisibleForCurrentTab(true, firstInfoBarMessage);
VerifyNumberOfInfobarsInManager(1);
// Dismiss the Infobar.
[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_buttonTitle(@"OK"),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
VerifyTestInfoBarVisibleForCurrentTab(false, firstInfoBarMessage);
VerifyNumberOfInfobarsInManager(0);
}
// Tests that adding an Infobar of lower height on top of a taller Infobar only // 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 // displays the top shorter one, and that after dismissing the shorter Infobar
// the taller infobar is now completely displayed again. // the taller infobar is now completely displayed again.
......
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