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

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: pass strings by reference 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
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..020456f2222c55175121a8b9b364a46a83168300 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,8 @@ class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
public:
TestBubbleDialogDelegateView(View* anchor_view)
: BubbleDialogDelegateView(anchor_view, BubbleBorder::TOP_LEFT),
- view_(new View()) {
+ view_(new View()),
+ title_view_(nullptr) {
view_->SetFocusBehavior(FocusBehavior::ALWAYS);
AddChildView(view_);
}
@@ -37,11 +40,24 @@ class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
return gfx::Size(200, 200);
}
+ base::string16 GetWindowTitle() const override {
+ return base::ASCIIToUTF16("TITLE TITLE TITLE");
+ }
+
+ View* CreateTitleView(base::string16 title_text) override {
+ EXPECT_EQ(title_text, GetWindowTitle());
+ return title_view_;
+ }
+
+ void set_title_view(View* title_view) { title_view_ = title_view; }
+ View* title_view() { return title_view_; }
+
using BubbleDialogDelegateView::SetAnchorRect;
using BubbleDialogDelegateView::GetBubbleFrameView;
private:
View* view_;
+ View* title_view_;
DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView);
};
@@ -251,7 +267,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 +349,19 @@ 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 title_preferred_height = 20;
Peter Kasting 2017/06/17 01:16:20 Nit: Use kNamingStyle
Bret 2017/06/21 22:37:54 Done.
+ View* title_view = new StaticSizedView(gfx::Size(10, title_preferred_height));
+ bubble_delegate->set_title_view(title_view);
+ Widget* bubble_widget =
+ BubbleDialogDelegateView::CreateBubble(bubble_delegate);
+ bubble_widget->Show();
+ // Title takes up the whole bubble width when there's no icon or close button.
Peter Kasting 2017/06/17 01:16:20 Nit: Maybe this means the below statement should b
Bret 2017/06/21 22:37:54 I split this into two EXPECTs for the width and he
+ EXPECT_EQ(gfx::Size(bubble_delegate->width(), title_preferred_height),
+ title_view->size());
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698