Commit 8ff84a88 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Simplify TestBubbleFrameView::GetWidget().

Move the widget creation to the constructor, so GetWidget() becomes
trivial and removes the need for member variables to be mutable.
BubbleFrameViewTest.GetBoundsForClientViewWithClose also no longer needs
to call GetWidget() for its side effect.

Change-Id: Ic904c808c37be8f4a61bf9e0bccdbc281ba16c0f
Reviewed-on: https://chromium-review.googlesource.com/1123774Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577243}
parent 55cc8bb5
...@@ -50,7 +50,8 @@ const int kExpectedAdditionalHeight = 12; ...@@ -50,7 +50,8 @@ const int kExpectedAdditionalHeight = 12;
class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate { class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate {
public: public:
TestBubbleFrameViewWidgetDelegate(Widget* widget) : widget_(widget) {} explicit TestBubbleFrameViewWidgetDelegate(Widget* widget)
: widget_(widget) {}
~TestBubbleFrameViewWidgetDelegate() override {} ~TestBubbleFrameViewWidgetDelegate() override {}
...@@ -77,35 +78,31 @@ class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate { ...@@ -77,35 +78,31 @@ class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate {
} }
private: private:
Widget* widget_; Widget* const widget_;
View* contents_view_ = nullptr; // Owned by |widget_|. View* contents_view_ = nullptr; // Owned by |widget_|.
bool should_show_close_ = false; bool should_show_close_ = false;
}; };
class TestBubbleFrameView : public BubbleFrameView { class TestBubbleFrameView : public BubbleFrameView {
public: public:
TestBubbleFrameView(ViewsTestBase* test_base) explicit TestBubbleFrameView(ViewsTestBase* test_base)
: BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)), : BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)),
test_base_(test_base),
available_bounds_(gfx::Rect(0, 0, 1000, 1000)) { available_bounds_(gfx::Rect(0, 0, 1000, 1000)) {
SetBubbleBorder(std::unique_ptr<BubbleBorder>( SetBubbleBorder(std::make_unique<BubbleBorder>(
new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor))); kArrow, BubbleBorder::NO_SHADOW, kColor));
widget_ = std::make_unique<Widget>();
widget_delegate_ =
std::make_unique<TestBubbleFrameViewWidgetDelegate>(widget_.get());
Widget::InitParams params =
test_base->CreateParams(Widget::InitParams::TYPE_BUBBLE);
params.delegate = widget_delegate_.get();
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget_->Init(params);
} }
~TestBubbleFrameView() override {} ~TestBubbleFrameView() override {}
// View overrides: // View overrides:
const Widget* GetWidget() const override { const Widget* GetWidget() const override {
if (!widget_) {
widget_.reset(new Widget);
widget_delegate_.reset(
new TestBubbleFrameViewWidgetDelegate(widget_.get()));
Widget::InitParams params =
test_base_->CreateParams(Widget::InitParams::TYPE_BUBBLE);
params.delegate = widget_delegate_.get();
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget_->Init(params);
}
return widget_.get(); return widget_.get();
} }
...@@ -119,13 +116,10 @@ class TestBubbleFrameView : public BubbleFrameView { ...@@ -119,13 +116,10 @@ class TestBubbleFrameView : public BubbleFrameView {
} }
private: private:
ViewsTestBase* test_base_; const gfx::Rect available_bounds_;
gfx::Rect available_bounds_;
// Widget returned by GetWidget(). Only created if GetWidget() is called. std::unique_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_;
mutable std::unique_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_; std::unique_ptr<Widget> widget_;
mutable std::unique_ptr<Widget> widget_;
DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView);
}; };
...@@ -159,9 +153,6 @@ TEST_F(BubbleFrameViewTest, RemoveFootnoteView) { ...@@ -159,9 +153,6 @@ TEST_F(BubbleFrameViewTest, RemoveFootnoteView) {
TEST_F(BubbleFrameViewTest, GetBoundsForClientViewWithClose) { TEST_F(BubbleFrameViewTest, GetBoundsForClientViewWithClose) {
TestBubbleFrameView frame(this); TestBubbleFrameView frame(this);
// TestBubbleFrameView::GetWidget() is responsible for creating the widget and
// widget delegate at first call, so it is called here for that side-effect.
ignore_result(frame.GetWidget());
frame.widget_delegate()->SetShouldShowCloseButton(true); frame.widget_delegate()->SetShouldShowCloseButton(true);
frame.ResetWindowControls(); frame.ResetWindowControls();
EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); EXPECT_EQ(kArrow, frame.bubble_border()->arrow());
......
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