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

Side by Side Diff: ui/views/window/dialog_delegate_unittest.cc

Issue 2880433002: views: don't snap dialogs with no buttons (Closed)
Patch Set: add unittest Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/base/hit_test.h" 9 #include "ui/base/hit_test.h"
10 #include "ui/events/event_processor.h" 10 #include "ui/events/event_processor.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return closeable_; 59 return closeable_;
60 } 60 }
61 61
62 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } 62 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
63 bool AcceleratorPressed(const ui::Accelerator& accelerator) override { 63 bool AcceleratorPressed(const ui::Accelerator& accelerator) override {
64 return should_handle_escape_; 64 return should_handle_escape_;
65 } 65 }
66 base::string16 GetWindowTitle() const override { return title_; } 66 base::string16 GetWindowTitle() const override { return title_; }
67 View* GetInitiallyFocusedView() override { return input_; } 67 View* GetInitiallyFocusedView() override { return input_; }
68 bool ShouldUseCustomFrame() const override { return true; } 68 bool ShouldUseCustomFrame() const override { return true; }
69 int GetDialogButtons() const override { return dialog_buttons_; }
69 70
70 void CheckAndResetStates(bool canceled, 71 void CheckAndResetStates(bool canceled,
71 bool accepted, 72 bool accepted,
72 bool closed) { 73 bool closed) {
73 EXPECT_EQ(canceled, canceled_); 74 EXPECT_EQ(canceled, canceled_);
74 canceled_ = false; 75 canceled_ = false;
75 EXPECT_EQ(accepted, accepted_); 76 EXPECT_EQ(accepted, accepted_);
76 accepted_ = false; 77 accepted_ = false;
77 EXPECT_EQ(closed, closed_); 78 EXPECT_EQ(closed, closed_);
78 closed_ = false; 79 closed_ = false;
79 } 80 }
80 81
81 void TearDown() { 82 void TearDown() {
82 closeable_ = true; 83 closeable_ = true;
83 GetWidget()->Close(); 84 GetWidget()->Close();
84 } 85 }
85 86
86 void set_title(const base::string16& title) { title_ = title; } 87 void set_title(const base::string16& title) { title_ = title; }
87 void set_show_close_button(bool show_close) { 88 void set_show_close_button(bool show_close) {
88 show_close_button_ = show_close; 89 show_close_button_ = show_close;
89 } 90 }
90 void set_should_handle_escape(bool should_handle_escape) { 91 void set_should_handle_escape(bool should_handle_escape) {
91 should_handle_escape_ = should_handle_escape; 92 should_handle_escape_ = should_handle_escape;
92 } 93 }
94 void set_dialog_buttons(int dialog_buttons) {
95 dialog_buttons_ = dialog_buttons;
96 }
93 97
94 views::Textfield* input() { return input_; } 98 views::Textfield* input() { return input_; }
95 99
96 private: 100 private:
97 views::Textfield* input_; 101 views::Textfield* input_;
98 bool canceled_ = false; 102 bool canceled_ = false;
99 bool accepted_ = false; 103 bool accepted_ = false;
100 bool closed_ = false; 104 bool closed_ = false;
101 // Prevent the dialog from closing, for repeated ok and cancel button clicks. 105 // Prevent the dialog from closing, for repeated ok and cancel button clicks.
102 bool closeable_ = false; 106 bool closeable_ = false;
103 base::string16 title_; 107 base::string16 title_;
104 bool show_close_button_ = true; 108 bool show_close_button_ = true;
105 bool should_handle_escape_ = false; 109 bool should_handle_escape_ = false;
110 int dialog_buttons_ = ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
106 111
107 DISALLOW_COPY_AND_ASSIGN(TestDialog); 112 DISALLOW_COPY_AND_ASSIGN(TestDialog);
108 }; 113 };
109 114
110 class DialogTest : public ViewsTestBase { 115 class DialogTest : public ViewsTestBase {
111 public: 116 public:
112 DialogTest() : dialog_(nullptr) {} 117 DialogTest() : dialog_(nullptr) {}
113 ~DialogTest() override {} 118 ~DialogTest() override {}
114 119
115 void SetUp() override { 120 void SetUp() override {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 380
376 // On showing the dialog, the initially focused View will be the OK button. 381 // On showing the dialog, the initially focused View will be the OK button.
377 // Since it is no longer focusable, focus should advance to the next focusable 382 // Since it is no longer focusable, focus should advance to the next focusable
378 // View, which is |textfield|. 383 // View, which is |textfield|.
379 dialog_widget->Show(); 384 dialog_widget->Show();
380 EXPECT_TRUE(textfield->HasFocus()); 385 EXPECT_TRUE(textfield->HasFocus());
381 EXPECT_EQ(textfield, dialog->GetFocusManager()->GetFocusedView()); 386 EXPECT_EQ(textfield, dialog->GetFocusManager()->GetFocusedView());
382 dialog_widget->CloseNow(); 387 dialog_widget->CloseNow();
383 } 388 }
384 389
390 TEST_F(DialogTest, DontSnapWithoutButtons) {
391 TestDialog dialog;
392 EXPECT_TRUE(dialog.ShouldSnapFrameWidth());
393 dialog.set_dialog_buttons(ui::DIALOG_BUTTON_NONE);
394 EXPECT_FALSE(dialog.ShouldSnapFrameWidth());
395 }
396
385 } // namespace views 397 } // namespace views
OLDNEW
« ui/views/window/dialog_delegate.cc ('K') | « ui/views/window/dialog_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698