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

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

Issue 933893003: Use standard icon/title in global error bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/checkbox.h" 9 #include "ui/views/controls/button/checkbox.h"
10 #include "ui/views/controls/button/label_button.h" 10 #include "ui/views/controls/button/label_button.h"
11 #include "ui/views/test/views_test_base.h" 11 #include "ui/views/test/views_test_base.h"
12 #include "ui/views/widget/widget.h" 12 #include "ui/views/widget/widget.h"
13 #include "ui/views/window/dialog_client_view.h" 13 #include "ui/views/window/dialog_client_view.h"
14 #include "ui/views/window/dialog_delegate.h" 14 #include "ui/views/window/dialog_delegate.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 namespace { 18 namespace {
19 19
20 class TestDialog : public DialogDelegateView, public ButtonListener { 20 class TestDialog : public DialogDelegateView, public ButtonListener {
21 public: 21 public:
22 TestDialog() 22 TestDialog()
23 : canceled_(false), 23 : canceled_(false),
24 accepted_(false), 24 accepted_(false),
25 closeable_(false), 25 closeable_(false),
26 last_pressed_button_(NULL) {} 26 last_pressed_button_(NULL) {}
27 ~TestDialog() override {} 27 ~TestDialog() override {}
28 28
29 // WidgetDelegate overrides:
30 bool ShouldShowWindowTitle() const override {
31 return !title_.empty();
32 }
33
29 // DialogDelegateView overrides: 34 // DialogDelegateView overrides:
30 bool Cancel() override { 35 bool Cancel() override {
31 canceled_ = true; 36 canceled_ = true;
32 return closeable_; 37 return closeable_;
33 } 38 }
34 bool Accept() override { 39 bool Accept() override {
35 accepted_ = true; 40 accepted_ = true;
36 return closeable_; 41 return closeable_;
37 } 42 }
38 43
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 dialog()->GetFocusManager()->OnKeyEvent(return_key); 181 dialog()->GetFocusManager()->OnKeyEvent(return_key);
177 dialog()->CheckAndResetStates(true, false, NULL); 182 dialog()->CheckAndResetStates(true, false, NULL);
178 } 183 }
179 184
180 TEST_F(DialogTest, RemoveDefaultButton) { 185 TEST_F(DialogTest, RemoveDefaultButton) {
181 // Removing buttons from the dialog here should not cause a crash on close. 186 // Removing buttons from the dialog here should not cause a crash on close.
182 delete dialog()->GetDialogClientView()->ok_button(); 187 delete dialog()->GetDialogClientView()->ok_button();
183 delete dialog()->GetDialogClientView()->cancel_button(); 188 delete dialog()->GetDialogClientView()->cancel_button();
184 } 189 }
185 190
186 TEST_F(DialogTest, HitTest) { 191 TEST_F(DialogTest, HitTest_HiddenTitle) {
187 // Ensure that the new style's BubbleFrameView hit-tests as expected. 192 // Ensure that BubbleFrameView hit-tests as expected when the title is hidden.
188 const NonClientView* view = dialog()->GetWidget()->non_client_view(); 193 const NonClientView* view = dialog()->GetWidget()->non_client_view();
189 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); 194 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view());
190 const int border = frame->bubble_border()->GetBorderThickness(); 195 const int border = frame->bubble_border()->GetBorderThickness();
191 196
192 struct { 197 struct {
193 const int point; 198 const int point;
194 const int hit; 199 const int hit;
195 } cases[] = { 200 } cases[] = {
196 { border, HTSYSMENU }, 201 { border, HTSYSMENU },
197 { border + 10, HTSYSMENU }, 202 { border + 10, HTSYSMENU },
203 { border + 20, HTCLIENT },
204 { border + 50, HTCLIENT },
205 { border + 60, HTCLIENT },
206 { 1000, HTNOWHERE },
207 };
208
209 for (size_t i = 0; i < arraysize(cases); ++i) {
210 gfx::Point point(cases[i].point, cases[i].point);
211 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point))
212 << " with border: " << border << ", at point " << cases[i].point;
213 }
214 }
215
216 TEST_F(DialogTest, HitTest_WithTitle) {
217 // Ensure that BubbleFrameView hit-tests as expected when the title is shown.
218 const NonClientView* view = dialog()->GetWidget()->non_client_view();
219 dialog()->set_title(base::ASCIIToUTF16("Title"));
220 dialog()->GetWidget()->UpdateWindowTitle();
221 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view());
222 const int border = frame->bubble_border()->GetBorderThickness();
223
224 struct {
225 const int point;
226 const int hit;
227 } cases[] = {
228 { border, HTSYSMENU },
229 { border + 10, HTSYSMENU },
198 { border + 20, HTCAPTION }, 230 { border + 20, HTCAPTION },
199 { border + 40, HTCLIENT },
200 { border + 50, HTCLIENT }, 231 { border + 50, HTCLIENT },
232 { border + 60, HTCLIENT },
201 { 1000, HTNOWHERE }, 233 { 1000, HTNOWHERE },
202 }; 234 };
203 235
204 for (size_t i = 0; i < arraysize(cases); ++i) { 236 for (size_t i = 0; i < arraysize(cases); ++i) {
205 gfx::Point point(cases[i].point, cases[i].point); 237 gfx::Point point(cases[i].point, cases[i].point);
206 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point)) 238 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point))
207 << " with border: " << border << ", at point " << cases[i].point; 239 << " with border: " << border << ", at point " << cases[i].point;
208 } 240 }
209 } 241 }
210 242
211 TEST_F(DialogTest, BoundsAccommodateTitle) { 243 TEST_F(DialogTest, BoundsAccommodateTitle) {
212 TestDialog* dialog2(new TestDialog()); 244 TestDialog* dialog2(new TestDialog());
213 dialog2->set_title(base::ASCIIToUTF16("Title")); 245 dialog2->set_title(base::ASCIIToUTF16("Title"));
214 DialogDelegate::CreateDialogWidget(dialog2, GetContext(), NULL); 246 DialogDelegate::CreateDialogWidget(dialog2, GetContext(), NULL);
215 247
216 // Titled dialogs have taller initial frame bounds than untitled dialogs. 248 // Titled dialogs have taller initial frame bounds than untitled dialogs.
217 View* frame1 = dialog()->GetWidget()->non_client_view()->frame_view(); 249 View* frame1 = dialog()->GetWidget()->non_client_view()->frame_view();
218 View* frame2 = dialog2->GetWidget()->non_client_view()->frame_view(); 250 View* frame2 = dialog2->GetWidget()->non_client_view()->frame_view();
219 EXPECT_LT(frame1->GetPreferredSize().height(), 251 EXPECT_LT(frame1->GetPreferredSize().height(),
220 frame2->GetPreferredSize().height()); 252 frame2->GetPreferredSize().height());
221 253
222 // Giving the default test dialog a title will yield the same bounds. 254 // Giving the default test dialog a title will yield the same bounds.
223 dialog()->set_title(base::ASCIIToUTF16("Title")); 255 dialog()->set_title(base::ASCIIToUTF16("Title"));
224 dialog()->GetWidget()->UpdateWindowTitle(); 256 dialog()->GetWidget()->UpdateWindowTitle();
225 EXPECT_EQ(frame1->GetPreferredSize().height(), 257 EXPECT_EQ(frame1->GetPreferredSize().height(),
226 frame2->GetPreferredSize().height()); 258 frame2->GetPreferredSize().height());
227 } 259 }
228 260
229 } // namespace views 261 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698