| 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/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 virtual ~TestDialog() {} | 27 virtual ~TestDialog() {} |
| 28 | 28 |
| 29 // DialogDelegateView overrides: | 29 // DialogDelegateView overrides: |
| 30 virtual bool Cancel() OVERRIDE { | 30 virtual bool Cancel() override { |
| 31 canceled_ = true; | 31 canceled_ = true; |
| 32 return closeable_; | 32 return closeable_; |
| 33 } | 33 } |
| 34 virtual bool Accept() OVERRIDE { | 34 virtual bool Accept() override { |
| 35 accepted_ = true; | 35 accepted_ = true; |
| 36 return closeable_; | 36 return closeable_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 // DialogDelegateView overrides: | 39 // DialogDelegateView overrides: |
| 40 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 40 virtual gfx::Size GetPreferredSize() const override { |
| 41 return gfx::Size(200, 200); | 41 return gfx::Size(200, 200); |
| 42 } | 42 } |
| 43 virtual base::string16 GetWindowTitle() const OVERRIDE { return title_; } | 43 virtual base::string16 GetWindowTitle() const override { return title_; } |
| 44 virtual bool UseNewStyleForThisDialog() const OVERRIDE { return true; } | 44 virtual bool UseNewStyleForThisDialog() const override { return true; } |
| 45 | 45 |
| 46 // ButtonListener override: | 46 // ButtonListener override: |
| 47 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { | 47 virtual void ButtonPressed(Button* sender, const ui::Event& event) override { |
| 48 last_pressed_button_ = sender; | 48 last_pressed_button_ = sender; |
| 49 } | 49 } |
| 50 | 50 |
| 51 Button* last_pressed_button() const { return last_pressed_button_; } | 51 Button* last_pressed_button() const { return last_pressed_button_; } |
| 52 | 52 |
| 53 void PressEnterAndCheckStates(Button* button) { | 53 void PressEnterAndCheckStates(Button* button) { |
| 54 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); | 54 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); |
| 55 GetFocusManager()->OnKeyEvent(key_event); | 55 GetFocusManager()->OnKeyEvent(key_event); |
| 56 const DialogClientView* client_view = GetDialogClientView(); | 56 const DialogClientView* client_view = GetDialogClientView(); |
| 57 EXPECT_EQ(canceled_, client_view->cancel_button()->is_default()); | 57 EXPECT_EQ(canceled_, client_view->cancel_button()->is_default()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 87 base::string16 title_; | 87 base::string16 title_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(TestDialog); | 89 DISALLOW_COPY_AND_ASSIGN(TestDialog); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 class DialogTest : public ViewsTestBase { | 92 class DialogTest : public ViewsTestBase { |
| 93 public: | 93 public: |
| 94 DialogTest() : dialog_(NULL) {} | 94 DialogTest() : dialog_(NULL) {} |
| 95 virtual ~DialogTest() {} | 95 virtual ~DialogTest() {} |
| 96 | 96 |
| 97 virtual void SetUp() OVERRIDE { | 97 virtual void SetUp() override { |
| 98 ViewsTestBase::SetUp(); | 98 ViewsTestBase::SetUp(); |
| 99 dialog_ = new TestDialog(); | 99 dialog_ = new TestDialog(); |
| 100 DialogDelegate::CreateDialogWidget(dialog_, GetContext(), NULL)->Show(); | 100 DialogDelegate::CreateDialogWidget(dialog_, GetContext(), NULL)->Show(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 virtual void TearDown() OVERRIDE { | 103 virtual void TearDown() override { |
| 104 dialog_->TearDown(); | 104 dialog_->TearDown(); |
| 105 ViewsTestBase::TearDown(); | 105 ViewsTestBase::TearDown(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TestDialog* dialog() const { return dialog_; } | 108 TestDialog* dialog() const { return dialog_; } |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 TestDialog* dialog_; | 111 TestDialog* dialog_; |
| 112 | 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(DialogTest); | 113 DISALLOW_COPY_AND_ASSIGN(DialogTest); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 frame2->GetPreferredSize().height()); | 222 frame2->GetPreferredSize().height()); |
| 223 | 223 |
| 224 // Giving the default test dialog a title will yield the same bounds. | 224 // Giving the default test dialog a title will yield the same bounds. |
| 225 dialog()->set_title(base::ASCIIToUTF16("Title")); | 225 dialog()->set_title(base::ASCIIToUTF16("Title")); |
| 226 dialog()->GetWidget()->UpdateWindowTitle(); | 226 dialog()->GetWidget()->UpdateWindowTitle(); |
| 227 EXPECT_EQ(frame1->GetPreferredSize().height(), | 227 EXPECT_EQ(frame1->GetPreferredSize().height(), |
| 228 frame2->GetPreferredSize().height()); | 228 frame2->GetPreferredSize().height()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 } // namespace views | 231 } // namespace views |
| OLD | NEW |