| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 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() OVERRIDE { return gfx::Size(200, 200); } | 40 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } |
| 41 virtual string16 GetWindowTitle() const OVERRIDE { return title_; } | 41 virtual base::string16 GetWindowTitle() const OVERRIDE { return title_; } |
| 42 | 42 |
| 43 // ButtonListener override: | 43 // ButtonListener override: |
| 44 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { | 44 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { |
| 45 last_pressed_button_ = sender; | 45 last_pressed_button_ = sender; |
| 46 } | 46 } |
| 47 | 47 |
| 48 Button* last_pressed_button() const { return last_pressed_button_; } | 48 Button* last_pressed_button() const { return last_pressed_button_; } |
| 49 | 49 |
| 50 void PressEnterAndCheckStates(Button* button) { | 50 void PressEnterAndCheckStates(Button* button) { |
| 51 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false); | 51 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 accepted_ = false; | 66 accepted_ = false; |
| 67 EXPECT_EQ(last_pressed, last_pressed_button_); | 67 EXPECT_EQ(last_pressed, last_pressed_button_); |
| 68 last_pressed_button_ = NULL; | 68 last_pressed_button_ = NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void TearDown() { | 71 void TearDown() { |
| 72 closeable_ = true; | 72 closeable_ = true; |
| 73 GetWidget()->Close(); | 73 GetWidget()->Close(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void set_title(const string16& title) { title_ = title; } | 76 void set_title(const base::string16& title) { title_ = title; } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 bool canceled_; | 79 bool canceled_; |
| 80 bool accepted_; | 80 bool accepted_; |
| 81 // Prevent the dialog from closing, for repeated ok and cancel button clicks. | 81 // Prevent the dialog from closing, for repeated ok and cancel button clicks. |
| 82 bool closeable_; | 82 bool closeable_; |
| 83 Button* last_pressed_button_; | 83 Button* last_pressed_button_; |
| 84 string16 title_; | 84 base::string16 title_; |
| 85 | 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(TestDialog); | 86 DISALLOW_COPY_AND_ASSIGN(TestDialog); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 class DialogTest : public ViewsTestBase { | 89 class DialogTest : public ViewsTestBase { |
| 90 public: | 90 public: |
| 91 DialogTest() : dialog_(NULL) {} | 91 DialogTest() : dialog_(NULL) {} |
| 92 virtual ~DialogTest() {} | 92 virtual ~DialogTest() {} |
| 93 | 93 |
| 94 virtual void SetUp() OVERRIDE { | 94 virtual void SetUp() OVERRIDE { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 114 | 114 |
| 115 TEST_F(DialogTest, DefaultButtons) { | 115 TEST_F(DialogTest, DefaultButtons) { |
| 116 DialogClientView* client_view = dialog()->GetDialogClientView(); | 116 DialogClientView* client_view = dialog()->GetDialogClientView(); |
| 117 LabelButton* ok_button = client_view->ok_button(); | 117 LabelButton* ok_button = client_view->ok_button(); |
| 118 | 118 |
| 119 // DialogDelegate's default button (ok) should be default (and handle enter). | 119 // DialogDelegate's default button (ok) should be default (and handle enter). |
| 120 EXPECT_EQ(ui::DIALOG_BUTTON_OK, dialog()->GetDefaultDialogButton()); | 120 EXPECT_EQ(ui::DIALOG_BUTTON_OK, dialog()->GetDefaultDialogButton()); |
| 121 dialog()->PressEnterAndCheckStates(ok_button); | 121 dialog()->PressEnterAndCheckStates(ok_button); |
| 122 | 122 |
| 123 // Focus another button in the dialog, it should become the default. | 123 // Focus another button in the dialog, it should become the default. |
| 124 LabelButton* button_1 = new LabelButton(dialog(), string16()); | 124 LabelButton* button_1 = new LabelButton(dialog(), base::string16()); |
| 125 client_view->AddChildView(button_1); | 125 client_view->AddChildView(button_1); |
| 126 client_view->OnWillChangeFocus(ok_button, button_1); | 126 client_view->OnWillChangeFocus(ok_button, button_1); |
| 127 EXPECT_TRUE(button_1->is_default()); | 127 EXPECT_TRUE(button_1->is_default()); |
| 128 dialog()->PressEnterAndCheckStates(button_1); | 128 dialog()->PressEnterAndCheckStates(button_1); |
| 129 | 129 |
| 130 // Focus a Checkbox (not a push button), OK should become the default again. | 130 // Focus a Checkbox (not a push button), OK should become the default again. |
| 131 Checkbox* checkbox = new Checkbox(string16()); | 131 Checkbox* checkbox = new Checkbox(base::string16()); |
| 132 client_view->AddChildView(checkbox); | 132 client_view->AddChildView(checkbox); |
| 133 client_view->OnWillChangeFocus(button_1, checkbox); | 133 client_view->OnWillChangeFocus(button_1, checkbox); |
| 134 EXPECT_FALSE(button_1->is_default()); | 134 EXPECT_FALSE(button_1->is_default()); |
| 135 dialog()->PressEnterAndCheckStates(ok_button); | 135 dialog()->PressEnterAndCheckStates(ok_button); |
| 136 | 136 |
| 137 // Focus yet another button in the dialog, it should become the default. | 137 // Focus yet another button in the dialog, it should become the default. |
| 138 LabelButton* button_2 = new LabelButton(dialog(), string16()); | 138 LabelButton* button_2 = new LabelButton(dialog(), base::string16()); |
| 139 client_view->AddChildView(button_2); | 139 client_view->AddChildView(button_2); |
| 140 client_view->OnWillChangeFocus(checkbox, button_2); | 140 client_view->OnWillChangeFocus(checkbox, button_2); |
| 141 EXPECT_FALSE(button_1->is_default()); | 141 EXPECT_FALSE(button_1->is_default()); |
| 142 EXPECT_TRUE(button_2->is_default()); | 142 EXPECT_TRUE(button_2->is_default()); |
| 143 dialog()->PressEnterAndCheckStates(button_2); | 143 dialog()->PressEnterAndCheckStates(button_2); |
| 144 | 144 |
| 145 // Focus nothing, OK should become the default again. | 145 // Focus nothing, OK should become the default again. |
| 146 client_view->OnWillChangeFocus(button_2, NULL); | 146 client_view->OnWillChangeFocus(button_2, NULL); |
| 147 EXPECT_FALSE(button_1->is_default()); | 147 EXPECT_FALSE(button_1->is_default()); |
| 148 EXPECT_FALSE(button_2->is_default()); | 148 EXPECT_FALSE(button_2->is_default()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 // Giving the default test dialog a title will make the bounds the same. | 217 // Giving the default test dialog a title will make the bounds the same. |
| 218 dialog()->set_title(ASCIIToUTF16("Title")); | 218 dialog()->set_title(ASCIIToUTF16("Title")); |
| 219 dialog()->GetWidget()->UpdateWindowTitle(); | 219 dialog()->GetWidget()->UpdateWindowTitle(); |
| 220 View* frame = dialog()->GetWidget()->non_client_view()->frame_view(); | 220 View* frame = dialog()->GetWidget()->non_client_view()->frame_view(); |
| 221 EXPECT_EQ(titled_dialog->GetWidget()->GetWindowBoundsInScreen().height(), | 221 EXPECT_EQ(titled_dialog->GetWidget()->GetWindowBoundsInScreen().height(), |
| 222 frame->GetPreferredSize().height()); | 222 frame->GetPreferredSize().height()); |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace views | 225 } // namespace views |
| OLD | NEW |