diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-08 01:13:25 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-08 01:13:25 +0000 |
commit | e8e0f3691a410d6de40bfff021b0da33425f36cb (patch) | |
tree | eba7275ce7aac42fb014896f2b65a09026c0499c /chrome/views/view_unittest.cc | |
parent | 4adc70599db32d760184ec908f11c7d000b6b79c (diff) | |
download | chromium_src-e8e0f3691a410d6de40bfff021b0da33425f36cb.zip chromium_src-e8e0f3691a410d6de40bfff021b0da33425f36cb.tar.gz chromium_src-e8e0f3691a410d6de40bfff021b0da33425f36cb.tar.bz2 |
In dialogs, when the focus moves to a button, that button should become the default button.
When the focus is not a button, then the default button should be the one the delegate specifies.
BUG=4132
TEST=Open the option dialog. OK should be the default and focused button. Move the focus around by pressing tab. When a button is selected, it should be the default button.
Review URL: http://codereview.chromium.org/10230
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/view_unittest.cc')
-rw-r--r-- | chrome/views/view_unittest.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc index ca6d026..e7196a0 100644 --- a/chrome/views/view_unittest.cc +++ b/chrome/views/view_unittest.cc @@ -5,6 +5,8 @@ #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/path.h" #include "chrome/views/background.h" +#include "chrome/views/checkbox.h" +#include "chrome/views/dialog_delegate.h" #include "chrome/views/event.h" #include "chrome/views/root_view.h" #include "chrome/views/view.h" @@ -580,3 +582,76 @@ TEST_F(ViewTest, HitTestMasks) { EXPECT_EQ(v1, root_view->GetViewForPoint(v1_origin)); EXPECT_EQ(root_view, root_view->GetViewForPoint(v2_origin)); } + +class TestDialogView : public views::View, + public views::DialogDelegate { + public: + TestDialogView() { + } + + // views::DialogDelegate implementation: + virtual int GetDialogButtons() const { + return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL; + } + + virtual int GetDefaultDialogButton() const { + return DIALOGBUTTON_OK; + } + + virtual View* GetContentsView() { + views::View* container = new views::View(); + button1_ = new views::NativeButton(L"Button1"); + button2_ = new views::NativeButton(L"Button2"); + checkbox_ = new views::CheckBox(L"My checkbox"); + container->AddChildView(button1_); + container->AddChildView(button2_); + container->AddChildView(checkbox_); + return container; + } + views::NativeButton* button1_; + views::NativeButton* button2_; + views::NativeButton* checkbox_; +}; + +TEST_F(ViewTest, DialogDefaultButtonTest) { + TestDialogView* dialog_view_ = new TestDialogView(); + views::Window* window = + views::Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 100, 100), + dialog_view_); + views::DialogClientView* client_view = + static_cast<views::DialogClientView*>(window->client_view()); + views::NativeButton* ok_button = client_view->ok_button(); + views::NativeButton* cancel_button = client_view->cancel_button(); + + EXPECT_TRUE(ok_button->IsDefaultButton()); + + // Simualte focusing another button, it should become the default button. + client_view->FocusWillChange(ok_button, dialog_view_->button1_); + EXPECT_FALSE(ok_button->IsDefaultButton()); + EXPECT_TRUE(dialog_view_->button1_->IsDefaultButton()); + + // Now select something that is not a button, the OK should become the default + // button again. + client_view->FocusWillChange(dialog_view_->button1_, dialog_view_->checkbox_); + EXPECT_TRUE(ok_button->IsDefaultButton()); + EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton()); + + // Select yet another button. + client_view->FocusWillChange(dialog_view_->checkbox_, dialog_view_->button2_); + EXPECT_FALSE(ok_button->IsDefaultButton()); + EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton()); + EXPECT_TRUE(dialog_view_->button2_->IsDefaultButton()); + + // Focus nothing. + client_view->FocusWillChange(dialog_view_->button2_, NULL); + EXPECT_TRUE(ok_button->IsDefaultButton()); + EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton()); + EXPECT_FALSE(dialog_view_->button2_->IsDefaultButton()); + + // Focus the cancel button. + client_view->FocusWillChange(NULL, cancel_button); + EXPECT_FALSE(ok_button->IsDefaultButton()); + EXPECT_TRUE(cancel_button->IsDefaultButton()); + EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton()); + EXPECT_FALSE(dialog_view_->button2_->IsDefaultButton()); +}
\ No newline at end of file |