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

Unified Diff: ui/views/window/dialog_delegate_unittest.cc

Issue 2840623002: Re-land 4ced9f3c7e9534b6b730d: Fix layout of BubbleFrameView when there's only a close button in th… (Closed)
Patch Set: Created 3 years, 8 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_frame_view_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/window/dialog_delegate_unittest.cc
diff --git a/ui/views/window/dialog_delegate_unittest.cc b/ui/views/window/dialog_delegate_unittest.cc
index d11cfddde8f6aabf0595da8212e837a7e92e24b4..ff365d4f98b2c78200ceb69eaf8c4e087a715e21 100644
--- a/ui/views/window/dialog_delegate_unittest.cc
+++ b/ui/views/window/dialog_delegate_unittest.cc
@@ -28,15 +28,7 @@ namespace {
class TestDialog : public DialogDelegateView {
public:
- TestDialog()
- : input_(new views::Textfield()),
- canceled_(false),
- accepted_(false),
- closed_(false),
- closeable_(false),
- should_handle_escape_(false) {
- AddChildView(input_);
- }
+ TestDialog() : input_(new views::Textfield()) { AddChildView(input_); }
~TestDialog() override {}
void Init() {
@@ -51,6 +43,7 @@ class TestDialog : public DialogDelegateView {
bool ShouldShowWindowTitle() const override {
return !title_.empty();
}
+ bool ShouldShowCloseButton() const override { return show_close_button_; }
// DialogDelegateView overrides:
bool Cancel() override {
@@ -66,7 +59,6 @@ class TestDialog : public DialogDelegateView {
return closeable_;
}
- // DialogDelegateView overrides:
gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
bool AcceleratorPressed(const ui::Accelerator& accelerator) override {
return should_handle_escape_;
@@ -92,6 +84,9 @@ class TestDialog : public DialogDelegateView {
}
void set_title(const base::string16& title) { title_ = title; }
+ void set_show_close_button(bool show_close) {
+ show_close_button_ = show_close;
+ }
void set_should_handle_escape(bool should_handle_escape) {
should_handle_escape_ = should_handle_escape;
}
@@ -100,13 +95,14 @@ class TestDialog : public DialogDelegateView {
private:
views::Textfield* input_;
- bool canceled_;
- bool accepted_;
- bool closed_;
+ bool canceled_ = false;
+ bool accepted_ = false;
+ bool closed_ = false;
// Prevent the dialog from closing, for repeated ok and cancel button clicks.
- bool closeable_;
+ bool closeable_ = false;
base::string16 title_;
- bool should_handle_escape_;
+ bool show_close_button_ = true;
+ bool should_handle_escape_ = false;
DISALLOW_COPY_AND_ASSIGN(TestDialog);
};
@@ -118,9 +114,8 @@ class DialogTest : public ViewsTestBase {
void SetUp() override {
ViewsTestBase::SetUp();
- dialog_ = new TestDialog();
- dialog_->Init();
- DialogDelegate::CreateDialogWidget(dialog_, GetContext(), nullptr)->Show();
+ InitializeDialog();
+ ShowDialog();
}
void TearDown() override {
@@ -128,6 +123,18 @@ class DialogTest : public ViewsTestBase {
ViewsTestBase::TearDown();
}
+ void InitializeDialog() {
+ if (dialog_)
+ dialog_->TearDown();
+
+ dialog_ = new TestDialog();
+ dialog_->Init();
+ }
+
+ void ShowDialog() {
+ DialogDelegate::CreateDialogWidget(dialog_, GetContext(), nullptr)->Show();
+ }
+
void SimulateKeyEvent(const ui::KeyEvent& event) {
ui::KeyEvent event_copy = event;
if (dialog()->GetFocusManager()->OnKeyEvent(event_copy))
@@ -208,12 +215,38 @@ TEST_F(DialogTest, HitTest_HiddenTitle) {
const int point;
const int hit;
} cases[] = {
- { border, HTSYSMENU },
- { border + 10, HTSYSMENU },
- { border + 20, HTCLIENT },
- { border + 50, HTCLIENT },
- { border + 60, HTCLIENT },
- { 1000, HTNOWHERE },
+ {border, HTSYSMENU},
+ {border + 10, HTSYSMENU},
+ {border + 20, HTNOWHERE},
+ {border + 50, HTCLIENT /* Space is reserved for the close button. */},
+ {border + 60, HTCLIENT},
+ {1000, HTNOWHERE},
+ };
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ gfx::Point point(cases[i].point, cases[i].point);
+ EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point))
+ << " case " << i << " with border: " << border << ", at point "
+ << cases[i].point;
+ }
+}
+
+TEST_F(DialogTest, HitTest_HiddenTitleNoCloseButton) {
+ InitializeDialog();
+ dialog()->set_show_close_button(false);
+ ShowDialog();
+
+ const NonClientView* view = dialog()->GetWidget()->non_client_view();
+ BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view());
+ const int border = frame->bubble_border()->GetBorderThickness();
+
+ struct {
+ const int point;
+ const int hit;
+ } cases[] = {
+ {border, HTSYSMENU}, {border + 10, HTSYSMENU},
+ {border + 20, HTCLIENT}, {border + 50, HTCLIENT},
+ {border + 60, HTCLIENT}, {1000, HTNOWHERE},
};
for (size_t i = 0; i < arraysize(cases); ++i) {
« no previous file with comments | « ui/views/bubble/bubble_frame_view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698