OLD | NEW |
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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "ui/base/hit_test.h" | 6 #include "ui/base/hit_test.h" |
7 #include "ui/views/bubble/bubble_border.h" | 7 #include "ui/views/bubble/bubble_border.h" |
8 #include "ui/views/bubble/bubble_frame_view.h" | 8 #include "ui/views/bubble/bubble_frame_view.h" |
9 #include "ui/views/controls/button/button_dropdown.h" | 9 #include "ui/views/controls/button/button_dropdown.h" |
10 #include "ui/views/controls/button/checkbox.h" | 10 #include "ui/views/controls/button/checkbox.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // DialogDelegateView overrides: | 30 // DialogDelegateView overrides: |
31 virtual bool Cancel() OVERRIDE { | 31 virtual bool Cancel() OVERRIDE { |
32 canceled_ = true; | 32 canceled_ = true; |
33 return closeable_; | 33 return closeable_; |
34 } | 34 } |
35 virtual bool Accept() OVERRIDE { | 35 virtual bool Accept() OVERRIDE { |
36 accepted_ = true; | 36 accepted_ = true; |
37 return closeable_; | 37 return closeable_; |
38 } | 38 } |
39 | 39 |
40 // View override: | 40 // DialogDelegateView overrides: |
41 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } | 41 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } |
| 42 virtual string16 GetWindowTitle() const OVERRIDE { return title_; } |
42 | 43 |
43 // ButtonListener override: | 44 // ButtonListener override: |
44 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { | 45 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { |
45 last_pressed_button_ = sender; | 46 last_pressed_button_ = sender; |
46 } | 47 } |
47 | 48 |
48 Button* last_pressed_button() const { return last_pressed_button_; } | 49 Button* last_pressed_button() const { return last_pressed_button_; } |
49 | 50 |
50 void PressEnterAndCheckStates(Button* button) { | 51 void PressEnterAndCheckStates(Button* button) { |
51 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false); | 52 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false); |
(...skipping 14 matching lines...) Expand all Loading... |
66 accepted_ = false; | 67 accepted_ = false; |
67 EXPECT_EQ(last_pressed, last_pressed_button_); | 68 EXPECT_EQ(last_pressed, last_pressed_button_); |
68 last_pressed_button_ = NULL; | 69 last_pressed_button_ = NULL; |
69 } | 70 } |
70 | 71 |
71 void TearDown() { | 72 void TearDown() { |
72 closeable_ = true; | 73 closeable_ = true; |
73 GetWidget()->Close(); | 74 GetWidget()->Close(); |
74 } | 75 } |
75 | 76 |
| 77 void set_title(const string16& title) { title_ = title; } |
| 78 |
76 private: | 79 private: |
77 bool canceled_; | 80 bool canceled_; |
78 bool accepted_; | 81 bool accepted_; |
79 // Prevent the dialog from closing, for repeated ok and cancel button clicks. | 82 // Prevent the dialog from closing, for repeated ok and cancel button clicks. |
80 bool closeable_; | 83 bool closeable_; |
81 Button* last_pressed_button_; | 84 Button* last_pressed_button_; |
| 85 string16 title_; |
82 | 86 |
83 DISALLOW_COPY_AND_ASSIGN(TestDialog); | 87 DISALLOW_COPY_AND_ASSIGN(TestDialog); |
84 }; | 88 }; |
85 | 89 |
86 class DialogTest : public ViewsTestBase { | 90 class DialogTest : public ViewsTestBase { |
87 public: | 91 public: |
88 DialogTest() : dialog_(NULL) {} | 92 DialogTest() : dialog_(NULL) {} |
89 virtual ~DialogTest() {} | 93 virtual ~DialogTest() {} |
90 | 94 |
91 virtual void SetUp() OVERRIDE { | 95 virtual void SetUp() OVERRIDE { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 dialog()->CheckAndResetStates(true, false, NULL); | 197 dialog()->CheckAndResetStates(true, false, NULL); |
194 } | 198 } |
195 | 199 |
196 TEST_F(DialogTest, RemoveDefaultButton) { | 200 TEST_F(DialogTest, RemoveDefaultButton) { |
197 // Removing buttons from the dialog here should not cause a crash on close. | 201 // Removing buttons from the dialog here should not cause a crash on close. |
198 delete dialog()->GetDialogClientView()->ok_button(); | 202 delete dialog()->GetDialogClientView()->ok_button(); |
199 delete dialog()->GetDialogClientView()->cancel_button(); | 203 delete dialog()->GetDialogClientView()->cancel_button(); |
200 } | 204 } |
201 | 205 |
202 TEST_F(DialogTest, HitTest) { | 206 TEST_F(DialogTest, HitTest) { |
| 207 if (!DialogDelegate::UseNewStyle()) |
| 208 return; |
| 209 |
| 210 // Ensure that the new style's BubbleFrameView hit-tests as expected. |
203 const NonClientView* view = dialog()->GetWidget()->non_client_view(); | 211 const NonClientView* view = dialog()->GetWidget()->non_client_view(); |
| 212 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); |
| 213 const int border = frame->bubble_border()->GetBorderThickness(); |
204 | 214 |
205 if (DialogDelegate::UseNewStyle()) { | 215 struct { |
206 // Ensure that the new style's BubbleFrameView hit-tests as expected. | 216 const int point; |
207 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); | 217 const int hit; |
208 const int border = frame->bubble_border()->GetBorderThickness(); | 218 } cases[] = { |
| 219 { border, HTSYSMENU }, |
| 220 { border + 10, HTSYSMENU }, |
| 221 { border + 20, HTCAPTION }, |
| 222 { border + 40, HTCLIENT }, |
| 223 { border + 50, HTCLIENT }, |
| 224 { 1000, HTNOWHERE }, |
| 225 }; |
209 | 226 |
210 struct { | 227 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
211 const int point; | 228 gfx::Point point(cases[i].point, cases[i].point); |
212 const int hit; | 229 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point)) |
213 } cases[] = { | 230 << " with border: " << border << ", at point " << cases[i].point; |
214 { border, HTSYSMENU }, | |
215 { border + 10, HTSYSMENU }, | |
216 { border + 20, HTCAPTION }, | |
217 { border + 40, HTCLIENT }, | |
218 { border + 50, HTCLIENT }, | |
219 { 1000, HTNOWHERE }, | |
220 }; | |
221 | |
222 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | |
223 gfx::Point point(cases[i].point, cases[i].point); | |
224 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point)) | |
225 << " with border: " << border << ", at point " << cases[i].point; | |
226 } | |
227 } | 231 } |
228 } | 232 } |
229 | 233 |
| 234 TEST_F(DialogTest, InitialBoundsAccommodateTitle) { |
| 235 if (!DialogDelegate::UseNewStyle()) |
| 236 return; |
| 237 |
| 238 TestDialog* titled_dialog(new TestDialog()); |
| 239 titled_dialog->set_title(ASCIIToUTF16("Title")); |
| 240 DialogDelegate::CreateDialogWidget(titled_dialog, GetContext(), NULL); |
| 241 |
| 242 // Titled dialogs have taller initial frame bounds than untitled dialogs. |
| 243 EXPECT_GT(titled_dialog->GetWidget()->GetWindowBoundsInScreen().height(), |
| 244 dialog()->GetWidget()->GetWindowBoundsInScreen().height()); |
| 245 |
| 246 // Giving the default test dialog a title will make the bounds the same. |
| 247 dialog()->set_title(ASCIIToUTF16("Title")); |
| 248 dialog()->GetWidget()->UpdateWindowTitle(); |
| 249 View* frame = dialog()->GetWidget()->non_client_view()->frame_view(); |
| 250 EXPECT_EQ(titled_dialog->GetWidget()->GetWindowBoundsInScreen().height(), |
| 251 frame->GetPreferredSize().height()); |
| 252 } |
| 253 |
230 } // namespace views | 254 } // namespace views |
OLD | NEW |