Commit d94b0217 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: add DialogDelegate GetFootnoteView

Some unit tests need access to the footnote view of a dialog. This
change adds a method to DialogDelegate to get the footnote view, and
changes a test suite (BookmarkBubbleTest) to use it.

Bug: 1011446
Change-Id: Ica62c0512a36b6f58c26b3ad8e9694e6a7c2cbad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900363
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713483}
parent d3fdde5a
......@@ -61,17 +61,12 @@ class BookmarkBubbleViewTest : public BrowserWithTestWindowTest {
// Create a fake anchor view for the bubble.
anchor_ = std::make_unique<views::View>();
std::unique_ptr<BubbleSyncPromoDelegate> delegate;
bubble_.reset(new BookmarkBubbleView(anchor_.get(), nullptr,
std::move(delegate), profile(),
GURL(kTestBookmarkURL), true));
bubble_.reset(new BookmarkBubbleView(anchor_.get(), nullptr, nullptr,
profile(), GURL(kTestBookmarkURL),
true));
bubble_->Init();
}
std::unique_ptr<views::View> CreateFootnoteView() {
return bubble_->CreateFootnoteView();
}
std::unique_ptr<BookmarkBubbleView> bubble_;
private:
......@@ -85,14 +80,13 @@ TEST_F(BookmarkBubbleViewTest, SyncPromoSignedIn) {
signin::MakePrimaryAccountAvailable(
IdentityManagerFactory::GetForProfile(profile()), "fake_username");
CreateBubbleView();
std::unique_ptr<views::View> footnote = CreateFootnoteView();
EXPECT_FALSE(footnote);
EXPECT_FALSE(bubble_->GetFootnoteViewForTesting());
}
// Verifies that the sync promo is displayed for a user that is not signed in.
TEST_F(BookmarkBubbleViewTest, SyncPromoNotSignedIn) {
CreateBubbleView();
std::unique_ptr<views::View> footnote = CreateFootnoteView();
views::View* footnote = bubble_->GetFootnoteViewForTesting();
#if defined(OS_CHROMEOS)
EXPECT_FALSE(footnote);
#else // !defined(OS_CHROMEOS)
......
......@@ -495,6 +495,14 @@ void BubbleFrameView::SetFootnoteView(std::unique_ptr<View> view) {
footnote_margins_, std::move(view), radius));
}
View* BubbleFrameView::GetFootnoteView() const {
if (!footnote_container_)
return nullptr;
DCHECK_EQ(1u, footnote_container_->children().size());
return footnote_container_->children()[0];
}
void BubbleFrameView::SetCornerRadius(int radius) {
bubble_border_->SetCornerRadius(radius);
}
......
......@@ -108,6 +108,7 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
// line and has a solid background by being embedded in a
// FootnoteContainerView. An example footnote would be some help text.
void SetFootnoteView(std::unique_ptr<View> view);
View* GetFootnoteView() const;
void set_footnote_margins(const gfx::Insets& footnote_margins) {
footnote_margins_ = footnote_margins;
}
......
......@@ -261,6 +261,21 @@ views::View* DialogDelegate::GetExtraView() {
return client ? client->extra_view() : nullptr;
}
views::View* DialogDelegate::GetFootnoteViewForTesting() {
if (!GetWidget())
return footnote_view_.get();
NonClientFrameView* frame = GetWidget()->non_client_view()->frame_view();
// CreateDialogFrameView above always uses BubbleFrameView. There are
// subclasses that override CreateDialogFrameView, but none of them override
// it to create anything other than a BubbleFrameView.
// TODO(https://crbug.com/1011446): Make CreateDialogFrameView final, then
// remove this DCHECK.
DCHECK_EQ(frame->GetClassName(), BubbleFrameView::kViewClassName);
return static_cast<BubbleFrameView*>(frame)->GetFootnoteView();
}
void DialogDelegate::AddObserver(DialogObserver* observer) {
observer_list_.AddObserver(observer);
}
......
......@@ -169,6 +169,10 @@ class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
views::LabelButton* GetCancelButton();
views::View* GetExtraView();
// Helper for accessing the footnote view. Unlike the three methods just
// above, this *is* safe to call before OnDialogInitialized.
views::View* GetFootnoteViewForTesting();
// Add or remove an observer notified by calls to DialogModelChanged().
void AddObserver(DialogObserver* observer);
void RemoveObserver(DialogObserver* observer);
......
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