Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: ui/views/bubble/bubble_dialog_delegate_unittest.cc

Issue 2907983002: Allow dialogs to use a custom View as their title. (Closed)
Patch Set: merge Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/bubble/bubble_dialog_delegate.cc ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/bubble/bubble_dialog_delegate_unittest.cc
diff --git a/ui/views/bubble/bubble_dialog_delegate_unittest.cc b/ui/views/bubble/bubble_dialog_delegate_unittest.cc
index 6524d04dcbd87902c7e278e1b9283b64895094f5..0887c8989b6db67f0de2582574eec7ea50b94f65 100644
--- a/ui/views/bubble/bubble_dialog_delegate_unittest.cc
+++ b/ui/views/bubble/bubble_dialog_delegate_unittest.cc
@@ -8,10 +8,12 @@
#include "base/i18n/rtl.h"
#include "base/macros.h"
+#include "base/strings/utf_string_conversions.h"
#include "ui/base/hit_test.h"
#include "ui/events/event_utils.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/label_button.h"
+#include "ui/views/test/test_views.h"
#include "ui/views/test/test_widget_observer.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
@@ -25,7 +27,9 @@ class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
public:
TestBubbleDialogDelegateView(View* anchor_view)
: BubbleDialogDelegateView(anchor_view, BubbleBorder::TOP_LEFT),
- view_(new View()) {
+ view_(new View()),
+ title_view_(nullptr),
+ should_show_close_button_(false) {
view_->SetFocusBehavior(FocusBehavior::ALWAYS);
AddChildView(view_);
}
@@ -36,12 +40,29 @@ class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
gfx::Size CalculatePreferredSize() const override {
return gfx::Size(200, 200);
}
+ void AddedToWidget() override {
+ if (title_view_)
+ GetBubbleFrameView()->SetTitleView(std::move(title_view_));
+ }
+
+ base::string16 GetWindowTitle() const override {
+ return base::ASCIIToUTF16("TITLE TITLE TITLE");
+ }
+
+ bool ShouldShowCloseButton() const override {
+ return should_show_close_button_;
+ }
+
+ void set_title_view(View* title_view) { title_view_.reset(title_view); }
+ void show_close_button() { should_show_close_button_ = true; }
using BubbleDialogDelegateView::SetAnchorRect;
using BubbleDialogDelegateView::GetBubbleFrameView;
private:
View* view_;
+ std::unique_ptr<View> title_view_;
+ bool should_show_close_button_;
DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView);
};
@@ -251,7 +272,7 @@ TEST_F(BubbleDialogDelegateTest, NonClientHitTest) {
const int point;
const int hit;
} cases[] = {
- {border, HTNOWHERE}, {border + 50, HTCLIENT}, {1000, HTNOWHERE},
+ {border, HTNOWHERE}, {border + 60, HTCLIENT}, {1000, HTNOWHERE},
};
for (size_t i = 0; i < arraysize(cases); ++i) {
@@ -333,4 +354,34 @@ TEST_F(BubbleDialogDelegateTest, CloseMethods) {
}
}
+TEST_F(BubbleDialogDelegateTest, CustomTitle) {
+ std::unique_ptr<Widget> anchor_widget(CreateTestWidget());
+ TestBubbleDialogDelegateView* bubble_delegate =
+ new TestBubbleDialogDelegateView(anchor_widget->GetContentsView());
+ constexpr int kTitlePreferredHeight = 20;
+ View* title_view = new StaticSizedView(gfx::Size(10, kTitlePreferredHeight));
+ bubble_delegate->set_title_view(title_view);
+ Widget* bubble_widget =
+ BubbleDialogDelegateView::CreateBubble(bubble_delegate);
+ bubble_widget->Show();
+
+ BubbleFrameView* bubble_frame = static_cast<BubbleFrameView*>(
+ bubble_widget->non_client_view()->frame_view());
+ EXPECT_EQ(title_view, bubble_frame->title());
+ EXPECT_EQ(bubble_frame, title_view->parent());
+ // Title takes up the whole bubble width when there's no icon or close button.
+ EXPECT_EQ(bubble_delegate->width(), title_view->size().width());
+ EXPECT_EQ(kTitlePreferredHeight, title_view->size().height());
+
+ bubble_delegate->show_close_button();
+ bubble_frame->ResetWindowControls();
+ bubble_frame->Layout();
+
+ Button* close_button = bubble_frame->GetCloseButtonForTest();
+ // Title moves over for the close button.
+ EXPECT_EQ(close_button->x() - LayoutProvider::Get()->GetDistanceMetric(
+ DISTANCE_CLOSE_BUTTON_MARGIN),
+ title_view->bounds().right());
+}
+
} // namespace views
« no previous file with comments | « ui/views/bubble/bubble_dialog_delegate.cc ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698