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

Side by Side Diff: ui/views/focus/focus_manager_unittest.cc

Issue 10562025: aura: Fix WidgetFocusChangeListener::OnNativeFocusChange(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge again Created 8 years, 6 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/focus/focus_manager_test.cc ('k') | ui/views/widget/native_widget_aura.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 <utility>
6 #include <vector>
7
5 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
6 #include "ui/base/accelerators/accelerator.h" 9 #include "ui/base/accelerators/accelerator.h"
7 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
8 #include "ui/views/controls/button/text_button.h" 11 #include "ui/views/controls/button/text_button.h"
9 #include "ui/views/controls/textfield/textfield.h" 12 #include "ui/views/controls/textfield/textfield.h"
10 #include "ui/views/focus/accelerator_handler.h" 13 #include "ui/views/focus/accelerator_handler.h"
11 #include "ui/views/focus/focus_manager_factory.h" 14 #include "ui/views/focus/focus_manager_factory.h"
12 #include "ui/views/focus/focus_manager_test.h" 15 #include "ui/views/focus/focus_manager_test.h"
16 #include "ui/views/focus/widget_focus_manager.h"
13 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
14 18
15 #if !defined(USE_AURA) 19 #if !defined(USE_AURA)
16 #include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h" 20 #include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
17 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" 21 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
18 #endif 22 #endif
19 23
20 namespace views { 24 namespace views {
21 25
22 enum FocusTestEventType { 26 enum FocusTestEventType {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 view2->RequestFocus(); 112 view2->RequestFocus();
109 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); 113 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size()));
110 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view1, view2)); 114 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view1, view2));
111 listener.ClearFocusChanges(); 115 listener.ClearFocusChanges();
112 116
113 GetFocusManager()->ClearFocus(); 117 GetFocusManager()->ClearFocus();
114 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); 118 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size()));
115 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view2, null_view)); 119 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view2, null_view));
116 } 120 }
117 121
122 TEST_F(FocusManagerTest, WidgetFocusChangeListener) {
Daniel Erat 2012/06/18 19:25:15 This test times out on non-Aura Windows. I know n
123 TestWidgetFocusChangeListener widget_listener;
124 AddWidgetFocusChangeListener(&widget_listener);
125
126 Widget::InitParams params;
127 params.type = views::Widget::InitParams::TYPE_WINDOW;
128 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
129 params.bounds = gfx::Rect(10, 10, 100, 100);
130 params.parent_widget = GetWidget();
131
132 scoped_ptr<Widget> widget1(new Widget);
133 widget1->Init(params);
134 widget1->Show();
135
136 scoped_ptr<Widget> widget2(new Widget);
137 widget2->Init(params);
138 widget2->Show();
139
140 widget_listener.ClearFocusChanges();
141 gfx::NativeView native_view1 = widget1->GetNativeView();
142 GetWidget()->FocusNativeView(native_view1);
143 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size()));
144 EXPECT_EQ(native_view1, widget_listener.focus_changes()[0].second);
145 EXPECT_EQ(native_view1, widget_listener.focus_changes()[1].second);
146
147 widget_listener.ClearFocusChanges();
148 gfx::NativeView native_view2 = widget2->GetNativeView();
149 GetWidget()->FocusNativeView(native_view2);
150 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size()));
151 EXPECT_EQ(NativeViewPair(native_view1, native_view2),
152 widget_listener.focus_changes()[0]);
153 EXPECT_EQ(NativeViewPair(native_view1, native_view2),
154 widget_listener.focus_changes()[1]);
155 }
156
118 #if !defined(USE_AURA) 157 #if !defined(USE_AURA)
119 class TestTextfield : public Textfield { 158 class TestTextfield : public Textfield {
120 public: 159 public:
121 TestTextfield() {} 160 TestTextfield() {}
122 virtual gfx::NativeView TestGetNativeControlView() { 161 virtual gfx::NativeView TestGetNativeControlView() {
123 return native_wrapper_->GetTestingHandle(); 162 return native_wrapper_->GetTestingHandle();
124 } 163 }
125 }; 164 };
126 165
127 class TestTabbedPane : public TabbedPane { 166 class TestTabbedPane : public TabbedPane {
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 637
599 // Test window, button and focus manager should all be destructed. 638 // Test window, button and focus manager should all be destructed.
600 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); 639 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size()));
601 640
602 // Focus manager should be the last one to destruct. 641 // Focus manager should be the last one to destruct.
603 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); 642 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str());
604 } 643 }
605 #endif 644 #endif
606 645
607 } // namespace views 646 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/focus/focus_manager_test.cc ('k') | ui/views/widget/native_widget_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698