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

Side by Side Diff: ui/views/view_unittest.cc

Issue 191723003: Nukes USE_AURA ifdefs from views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: incorporate feedback Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "grit/ui_strings.h" 11 #include "grit/ui_strings.h"
12 #include "ui/aura/window_event_dispatcher.h"
12 #include "ui/base/accelerators/accelerator.h" 13 #include "ui/base/accelerators/accelerator.h"
13 #include "ui/base/clipboard/clipboard.h" 14 #include "ui/base/clipboard/clipboard.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/compositor/compositor.h" 16 #include "ui/compositor/compositor.h"
16 #include "ui/compositor/layer.h" 17 #include "ui/compositor/layer.h"
17 #include "ui/compositor/layer_animator.h" 18 #include "ui/compositor/layer_animator.h"
18 #include "ui/compositor/test/draw_waiter_for_test.h" 19 #include "ui/compositor/test/draw_waiter_for_test.h"
19 #include "ui/events/event.h" 20 #include "ui/events/event.h"
21 #include "ui/events/gestures/gesture_recognizer.h"
20 #include "ui/events/keycodes/keyboard_codes.h" 22 #include "ui/events/keycodes/keyboard_codes.h"
21 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/path.h" 24 #include "ui/gfx/path.h"
23 #include "ui/gfx/transform.h" 25 #include "ui/gfx/transform.h"
24 #include "ui/views/background.h" 26 #include "ui/views/background.h"
25 #include "ui/views/controls/native/native_view_host.h" 27 #include "ui/views/controls/native/native_view_host.h"
26 #include "ui/views/controls/scroll_view.h" 28 #include "ui/views/controls/scroll_view.h"
27 #include "ui/views/controls/textfield/textfield.h" 29 #include "ui/views/controls/textfield/textfield.h"
28 #include "ui/views/focus/view_storage.h" 30 #include "ui/views/focus/view_storage.h"
29 #include "ui/views/test/views_test_base.h" 31 #include "ui/views/test/views_test_base.h"
30 #include "ui/views/view.h" 32 #include "ui/views/view.h"
31 #include "ui/views/views_delegate.h" 33 #include "ui/views/views_delegate.h"
32 #include "ui/views/widget/native_widget.h" 34 #include "ui/views/widget/native_widget.h"
33 #include "ui/views/widget/root_view.h" 35 #include "ui/views/widget/root_view.h"
34 #include "ui/views/window/dialog_client_view.h" 36 #include "ui/views/window/dialog_client_view.h"
35 #include "ui/views/window/dialog_delegate.h" 37 #include "ui/views/window/dialog_delegate.h"
36 38
37 #if defined(OS_WIN) 39 #if defined(OS_WIN)
38 #include "ui/views/test/test_views_delegate.h" 40 #include "ui/views/test/test_views_delegate.h"
39 #endif 41 #endif
40 #if defined(USE_AURA)
41 #include "ui/aura/window_event_dispatcher.h"
42 #include "ui/events/gestures/gesture_recognizer.h"
43 #endif
44 42
45 using base::ASCIIToUTF16; 43 using base::ASCIIToUTF16;
46 44
47 namespace { 45 namespace {
48 46
49 // Returns true if |ancestor| is an ancestor of |layer|. 47 // Returns true if |ancestor| is an ancestor of |layer|.
50 bool LayerIsAncestor(const ui::Layer* ancestor, const ui::Layer* layer) { 48 bool LayerIsAncestor(const ui::Layer* ancestor, const ui::Layer* layer) {
51 while (layer && layer != ancestor) 49 while (layer && layer != ancestor)
52 layer = layer->parent(); 50 layer = layer->parent();
53 return layer == ancestor; 51 return layer == ancestor;
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 } 1576 }
1579 1577
1580 //////////////////////////////////////////////////////////////////////////////// 1578 ////////////////////////////////////////////////////////////////////////////////
1581 // Accelerators 1579 // Accelerators
1582 //////////////////////////////////////////////////////////////////////////////// 1580 ////////////////////////////////////////////////////////////////////////////////
1583 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) { 1581 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) {
1584 accelerator_count_map_[accelerator]++; 1582 accelerator_count_map_[accelerator]++;
1585 return true; 1583 return true;
1586 } 1584 }
1587 1585
1588 #if defined(OS_WIN) && !defined(USE_AURA) 1586 // TODO: these tests were initially commented out when getting aura to
1587 // run. Figure out if still valuable and either nuke or fix.
1588 #if defined(false)
1589 TEST_F(ViewTest, ActivateAccelerator) { 1589 TEST_F(ViewTest, ActivateAccelerator) {
1590 // Register a keyboard accelerator before the view is added to a window. 1590 // Register a keyboard accelerator before the view is added to a window.
1591 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1591 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1592 TestView* view = new TestView(); 1592 TestView* view = new TestView();
1593 view->Reset(); 1593 view->Reset();
1594 view->AddAccelerator(return_accelerator); 1594 view->AddAccelerator(return_accelerator);
1595 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 1595 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1596 1596
1597 // Create a window and add the view as its child. 1597 // Create a window and add the view as its child.
1598 scoped_ptr<Widget> widget(new Widget); 1598 scoped_ptr<Widget> widget(new Widget);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 view->ResetAccelerators(); 1643 view->ResetAccelerators();
1644 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1644 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1645 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); 1645 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2);
1646 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); 1646 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2);
1647 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); 1647 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator));
1648 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); 1648 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2);
1649 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); 1649 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2);
1650 1650
1651 widget->CloseNow(); 1651 widget->CloseNow();
1652 } 1652 }
1653 #endif
1654 1653
1655 #if defined(OS_WIN) && !defined(USE_AURA)
1656 TEST_F(ViewTest, HiddenViewWithAccelerator) { 1654 TEST_F(ViewTest, HiddenViewWithAccelerator) {
1657 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1655 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1658 TestView* view = new TestView(); 1656 TestView* view = new TestView();
1659 view->Reset(); 1657 view->Reset();
1660 view->AddAccelerator(return_accelerator); 1658 view->AddAccelerator(return_accelerator);
1661 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 1659 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1662 1660
1663 scoped_ptr<Widget> widget(new Widget); 1661 scoped_ptr<Widget> widget(new Widget);
1664 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 1662 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1665 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 1663 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1666 params.bounds = gfx::Rect(0, 0, 100, 100); 1664 params.bounds = gfx::Rect(0, 0, 100, 100);
1667 widget->Init(params); 1665 widget->Init(params);
1668 View* root = widget->GetRootView(); 1666 View* root = widget->GetRootView();
1669 root->AddChildView(view); 1667 root->AddChildView(view);
1670 widget->Show(); 1668 widget->Show();
1671 1669
1672 FocusManager* focus_manager = widget->GetFocusManager(); 1670 FocusManager* focus_manager = widget->GetFocusManager();
1673 ASSERT_TRUE(focus_manager); 1671 ASSERT_TRUE(focus_manager);
1674 1672
1675 view->SetVisible(false); 1673 view->SetVisible(false);
1676 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1674 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1677 1675
1678 view->SetVisible(true); 1676 view->SetVisible(true);
1679 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); 1677 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
1680 1678
1681 widget->CloseNow(); 1679 widget->CloseNow();
1682 } 1680 }
1683 #endif
1684 1681
1685 #if defined(OS_WIN) && !defined(USE_AURA)
1686 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) { 1682 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) {
1687 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1683 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1688 TestView* view = new TestView(); 1684 TestView* view = new TestView();
1689 view->Reset(); 1685 view->Reset();
1690 view->AddAccelerator(return_accelerator); 1686 view->AddAccelerator(return_accelerator);
1691 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 1687 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1692 1688
1693 scoped_ptr<Widget> widget(new Widget); 1689 scoped_ptr<Widget> widget(new Widget);
1694 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 1690 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1695 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 1691 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
(...skipping 11 matching lines...) Expand all
1707 widget->Show(); 1703 widget->Show();
1708 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); 1704 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
1709 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); 1705 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
1710 1706
1711 widget->Hide(); 1707 widget->Hide();
1712 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1708 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1713 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); 1709 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
1714 1710
1715 widget->CloseNow(); 1711 widget->CloseNow();
1716 } 1712 }
1717 #endif
1718 1713
1719 #if defined(OS_WIN) && !defined(USE_AURA)
1720 //////////////////////////////////////////////////////////////////////////////// 1714 ////////////////////////////////////////////////////////////////////////////////
1721 // Mouse-wheel message rerouting 1715 // Mouse-wheel message rerouting
1722 //////////////////////////////////////////////////////////////////////////////// 1716 ////////////////////////////////////////////////////////////////////////////////
1723 class ScrollableTestView : public View { 1717 class ScrollableTestView : public View {
1724 public: 1718 public:
1725 ScrollableTestView() { } 1719 ScrollableTestView() { }
1726 1720
1727 virtual gfx::Size GetPreferredSize() { 1721 virtual gfx::Size GetPreferredSize() {
1728 return gfx::Size(100, 10000); 1722 return gfx::Size(100, 10000);
1729 } 1723 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 // scroll-view). 1783 // scroll-view).
1790 1784
1791 // First to the Window's HWND. 1785 // First to the Window's HWND.
1792 ::SendMessage(view_with_controls->GetWidget()->GetNativeView(), 1786 ::SendMessage(view_with_controls->GetWidget()->GetNativeView(),
1793 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); 1787 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250));
1794 EXPECT_EQ(20, scroll_view->GetVisibleRect().y()); 1788 EXPECT_EQ(20, scroll_view->GetVisibleRect().y());
1795 1789
1796 window1->CloseNow(); 1790 window1->CloseNow();
1797 window2->CloseNow(); 1791 window2->CloseNow();
1798 } 1792 }
1799 #endif 1793 #endif // false
1800 1794
1801 //////////////////////////////////////////////////////////////////////////////// 1795 ////////////////////////////////////////////////////////////////////////////////
1802 // Native view hierachy 1796 // Native view hierachy
1803 //////////////////////////////////////////////////////////////////////////////// 1797 ////////////////////////////////////////////////////////////////////////////////
1804 class ToplevelWidgetObserverView : public View { 1798 class ToplevelWidgetObserverView : public View {
1805 public: 1799 public:
1806 ToplevelWidgetObserverView() : toplevel_(NULL) { 1800 ToplevelWidgetObserverView() : toplevel_(NULL) {
1807 } 1801 }
1808 virtual ~ToplevelWidgetObserverView() { 1802 virtual ~ToplevelWidgetObserverView() {
1809 } 1803 }
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 EXPECT_EQ(1, v1.GetIndexOf(&v3)); 2947 EXPECT_EQ(1, v1.GetIndexOf(&v3));
2954 v1.AddChildView(&v3); 2948 v1.AddChildView(&v3);
2955 EXPECT_EQ(0, v1.GetIndexOf(&v2)); 2949 EXPECT_EQ(0, v1.GetIndexOf(&v2));
2956 EXPECT_EQ(1, v1.GetIndexOf(&v3)); 2950 EXPECT_EQ(1, v1.GetIndexOf(&v3));
2957 } 2951 }
2958 2952
2959 //////////////////////////////////////////////////////////////////////////////// 2953 ////////////////////////////////////////////////////////////////////////////////
2960 // Layers 2954 // Layers
2961 //////////////////////////////////////////////////////////////////////////////// 2955 ////////////////////////////////////////////////////////////////////////////////
2962 2956
2963 #if defined(USE_AURA)
2964
2965 namespace { 2957 namespace {
2966 2958
2967 // Test implementation of LayerAnimator. 2959 // Test implementation of LayerAnimator.
2968 class TestLayerAnimator : public ui::LayerAnimator { 2960 class TestLayerAnimator : public ui::LayerAnimator {
2969 public: 2961 public:
2970 TestLayerAnimator(); 2962 TestLayerAnimator();
2971 2963
2972 const gfx::Rect& last_bounds() const { return last_bounds_; } 2964 const gfx::Rect& last_bounds() const { return last_bounds_; }
2973 2965
2974 // LayerAnimator. 2966 // LayerAnimator.
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3539 3531
3540 // Test the new layer order. |v1_old_layer| should be above the layers 3532 // Test the new layer order. |v1_old_layer| should be above the layers
3541 // for |v1| and |v2|. 3533 // for |v1| and |v2|.
3542 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); 3534 const std::vector<ui::Layer*>& child_layers_post = root_layer->children();
3543 ASSERT_EQ(3u, child_layers_post.size()); 3535 ASSERT_EQ(3u, child_layers_post.size());
3544 EXPECT_EQ(v1->layer(), child_layers_post[0]); 3536 EXPECT_EQ(v1->layer(), child_layers_post[0]);
3545 EXPECT_EQ(v2->layer(), child_layers_post[1]); 3537 EXPECT_EQ(v2->layer(), child_layers_post[1]);
3546 EXPECT_EQ(v1_old_layer, child_layers_post[2]); 3538 EXPECT_EQ(v1_old_layer, child_layers_post[2]);
3547 } 3539 }
3548 3540
3549 #endif // USE_AURA
3550
3551 TEST_F(ViewTest, FocusableAssertions) { 3541 TEST_F(ViewTest, FocusableAssertions) {
3552 // View subclasses may change insets based on whether they are focusable, 3542 // View subclasses may change insets based on whether they are focusable,
3553 // which effects the preferred size. To avoid preferred size changing around 3543 // which effects the preferred size. To avoid preferred size changing around
3554 // these Views need to key off the last value set to SetFocusable(), not 3544 // these Views need to key off the last value set to SetFocusable(), not
3555 // whether the View is focusable right now. For this reason it's important 3545 // whether the View is focusable right now. For this reason it's important
3556 // that focusable() return the last value passed to SetFocusable and not 3546 // that focusable() return the last value passed to SetFocusable and not
3557 // whether the View is focusable right now. 3547 // whether the View is focusable right now.
3558 TestView view; 3548 TestView view;
3559 view.SetFocusable(true); 3549 view.SetFocusable(true);
3560 EXPECT_TRUE(view.focusable()); 3550 EXPECT_TRUE(view.focusable());
3561 view.SetEnabled(false); 3551 view.SetEnabled(false);
3562 EXPECT_TRUE(view.focusable()); 3552 EXPECT_TRUE(view.focusable());
3563 view.SetFocusable(false); 3553 view.SetFocusable(false);
3564 EXPECT_FALSE(view.focusable()); 3554 EXPECT_FALSE(view.focusable());
3565 } 3555 }
3566 3556
3567 } // namespace views 3557 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698