OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 static_cast<DialogClientView*>(window->client_view()); | 1704 static_cast<DialogClientView*>(window->client_view()); |
1705 ok_button_ = client_view_->ok_button(); | 1705 ok_button_ = client_view_->ok_button(); |
1706 cancel_button_ = client_view_->cancel_button(); | 1706 cancel_button_ = client_view_->cancel_button(); |
1707 } | 1707 } |
1708 | 1708 |
1709 virtual void TearDown() OVERRIDE { | 1709 virtual void TearDown() OVERRIDE { |
1710 test_dialog_->TearDown(); | 1710 test_dialog_->TearDown(); |
1711 ViewTest::TearDown(); | 1711 ViewTest::TearDown(); |
1712 } | 1712 } |
1713 | 1713 |
1714 void SimulatePressingEnterAndCheckDefaultButton(ButtonID button_id) { | 1714 void SimulatePressingEnterAndCheckHandledButton(ButtonID button_id) { |
1715 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false); | 1715 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false); |
1716 focus_manager_->OnKeyEvent(event); | 1716 focus_manager_->OnKeyEvent(event); |
1717 switch (button_id) { | 1717 switch (button_id) { |
1718 case OK: | 1718 case OK: |
1719 EXPECT_TRUE(test_dialog_->oked_); | 1719 EXPECT_TRUE(test_dialog_->oked_); |
1720 EXPECT_FALSE(test_dialog_->canceled_); | 1720 EXPECT_FALSE(test_dialog_->canceled_); |
1721 EXPECT_FALSE(test_dialog_->last_pressed_button_); | 1721 EXPECT_FALSE(test_dialog_->last_pressed_button_); |
1722 break; | 1722 break; |
1723 case CANCEL: | 1723 case CANCEL: |
1724 EXPECT_FALSE(test_dialog_->oked_); | 1724 EXPECT_FALSE(test_dialog_->oked_); |
(...skipping 17 matching lines...) Expand all Loading... |
1742 } | 1742 } |
1743 | 1743 |
1744 FocusManager* focus_manager_; | 1744 FocusManager* focus_manager_; |
1745 TestDialog* test_dialog_; | 1745 TestDialog* test_dialog_; |
1746 DialogClientView* client_view_; | 1746 DialogClientView* client_view_; |
1747 LabelButton* ok_button_; | 1747 LabelButton* ok_button_; |
1748 LabelButton* cancel_button_; | 1748 LabelButton* cancel_button_; |
1749 }; | 1749 }; |
1750 | 1750 |
1751 TEST_F(DefaultButtonTest, DialogDefaultButtonTest) { | 1751 TEST_F(DefaultButtonTest, DialogDefaultButtonTest) { |
1752 // Window has just been shown, we expect the default button specified in the | 1752 // The dialog should initially honor the delegate's specified default button. |
1753 // DialogDelegate. | |
1754 EXPECT_TRUE(ok_button_->is_default()); | |
1755 | |
1756 // Simulate pressing enter, that should trigger the OK button. | |
1757 SimulatePressingEnterAndCheckDefaultButton(OK); | |
1758 | |
1759 // Simulate focusing another button, it should become the default button. | |
1760 client_view_->OnWillChangeFocus(ok_button_, test_dialog_->button1_); | |
1761 EXPECT_FALSE(ok_button_->is_default()); | |
1762 EXPECT_TRUE(test_dialog_->button1_->is_default()); | |
1763 // Simulate pressing enter, that should trigger button1. | |
1764 SimulatePressingEnterAndCheckDefaultButton(BUTTON1); | |
1765 | |
1766 // Now select something that is not a button, the OK should become the default | |
1767 // button again. | |
1768 client_view_->OnWillChangeFocus(test_dialog_->button1_, | |
1769 test_dialog_->checkbox_); | |
1770 EXPECT_TRUE(ok_button_->is_default()); | |
1771 EXPECT_FALSE(test_dialog_->button1_->is_default()); | |
1772 SimulatePressingEnterAndCheckDefaultButton(OK); | |
1773 | |
1774 // Select yet another button. | |
1775 client_view_->OnWillChangeFocus(test_dialog_->checkbox_, | |
1776 test_dialog_->button2_); | |
1777 EXPECT_FALSE(ok_button_->is_default()); | |
1778 EXPECT_FALSE(test_dialog_->button1_->is_default()); | |
1779 EXPECT_TRUE(test_dialog_->button2_->is_default()); | |
1780 SimulatePressingEnterAndCheckDefaultButton(BUTTON2); | |
1781 | |
1782 // Focus nothing. | |
1783 client_view_->OnWillChangeFocus(test_dialog_->button2_, NULL); | |
1784 EXPECT_TRUE(ok_button_->is_default()); | 1753 EXPECT_TRUE(ok_button_->is_default()); |
1785 EXPECT_FALSE(test_dialog_->button1_->is_default()); | 1754 EXPECT_FALSE(test_dialog_->button1_->is_default()); |
1786 EXPECT_FALSE(test_dialog_->button2_->is_default()); | 1755 EXPECT_FALSE(test_dialog_->button2_->is_default()); |
1787 SimulatePressingEnterAndCheckDefaultButton(OK); | 1756 |
| 1757 // Simulate pressing enter, that should trigger the OK button. |
| 1758 SimulatePressingEnterAndCheckHandledButton(OK); |
| 1759 |
| 1760 // Focusing another button changes enter handling, but not the default button. |
| 1761 FocusManager* focus_manager = client_view_->GetFocusManager(); |
| 1762 focus_manager->SetFocusedView(test_dialog_->button1_); |
| 1763 EXPECT_TRUE(ok_button_->is_default()); |
| 1764 EXPECT_FALSE(test_dialog_->button1_->is_default()); |
| 1765 EXPECT_FALSE(test_dialog_->button2_->is_default()); |
| 1766 // Simulate pressing enter, that should trigger button1. |
| 1767 SimulatePressingEnterAndCheckHandledButton(BUTTON1); |
| 1768 |
| 1769 // Focusing a non-button view invokes OK. |
| 1770 focus_manager->SetFocusedView(test_dialog_->checkbox_); |
| 1771 EXPECT_TRUE(ok_button_->is_default()); |
| 1772 EXPECT_FALSE(test_dialog_->button1_->is_default()); |
| 1773 EXPECT_FALSE(test_dialog_->button2_->is_default()); |
| 1774 SimulatePressingEnterAndCheckHandledButton(OK); |
| 1775 |
| 1776 // Focus yet another button. |
| 1777 focus_manager->SetFocusedView(test_dialog_->button2_); |
| 1778 EXPECT_TRUE(ok_button_->is_default()); |
| 1779 EXPECT_FALSE(test_dialog_->button1_->is_default()); |
| 1780 EXPECT_FALSE(test_dialog_->button2_->is_default()); |
| 1781 SimulatePressingEnterAndCheckHandledButton(BUTTON2); |
| 1782 |
| 1783 // Focus nothing. |
| 1784 focus_manager->ClearFocus(); |
| 1785 EXPECT_TRUE(ok_button_->is_default()); |
| 1786 EXPECT_FALSE(test_dialog_->button1_->is_default()); |
| 1787 EXPECT_FALSE(test_dialog_->button2_->is_default()); |
| 1788 SimulatePressingEnterAndCheckHandledButton(OK); |
1788 | 1789 |
1789 // Focus the cancel button. | 1790 // Focus the cancel button. |
1790 client_view_->OnWillChangeFocus(NULL, cancel_button_); | 1791 focus_manager->SetFocusedView(cancel_button_); |
1791 EXPECT_FALSE(ok_button_->is_default()); | 1792 EXPECT_TRUE(ok_button_->is_default()); |
1792 EXPECT_TRUE(cancel_button_->is_default()); | |
1793 EXPECT_FALSE(test_dialog_->button1_->is_default()); | 1793 EXPECT_FALSE(test_dialog_->button1_->is_default()); |
1794 EXPECT_FALSE(test_dialog_->button2_->is_default()); | 1794 EXPECT_FALSE(test_dialog_->button2_->is_default()); |
1795 SimulatePressingEnterAndCheckDefaultButton(CANCEL); | 1795 SimulatePressingEnterAndCheckHandledButton(CANCEL); |
1796 } | 1796 } |
1797 | 1797 |
1798 class ButtonDropDownTest : public ViewTest { | 1798 class ButtonDropDownTest : public ViewTest { |
1799 public: | 1799 public: |
1800 ButtonDropDownTest() | 1800 ButtonDropDownTest() |
1801 : test_dialog_(NULL), | 1801 : test_dialog_(NULL), |
1802 button_as_view_(NULL) { | 1802 button_as_view_(NULL) { |
1803 } | 1803 } |
1804 | 1804 |
1805 virtual void SetUp() OVERRIDE { | 1805 virtual void SetUp() OVERRIDE { |
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3364 // Set to non default value. | 3364 // Set to non default value. |
3365 v->layer()->set_scale_content(false); | 3365 v->layer()->set_scale_content(false); |
3366 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); | 3366 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); |
3367 ui::Layer* new_layer = v->layer(); | 3367 ui::Layer* new_layer = v->layer(); |
3368 EXPECT_FALSE(new_layer->scale_content()); | 3368 EXPECT_FALSE(new_layer->scale_content()); |
3369 } | 3369 } |
3370 | 3370 |
3371 #endif // USE_AURA | 3371 #endif // USE_AURA |
3372 | 3372 |
3373 } // namespace views | 3373 } // namespace views |
OLD | NEW |