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

Side by Side Diff: ui/views/focus/focus_manager_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/focus/focus_manager_test.cc ('k') | ui/views/focus/focus_traversal_unittest.cc » ('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> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/aura/client/focus_client.h"
10 #include "ui/aura/window.h"
9 #include "ui/base/accelerators/accelerator.h" 11 #include "ui/base/accelerators/accelerator.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 12 #include "ui/events/keycodes/keyboard_codes.h"
11 #include "ui/views/accessible_pane_view.h" 13 #include "ui/views/accessible_pane_view.h"
12 #include "ui/views/controls/button/label_button.h" 14 #include "ui/views/controls/button/label_button.h"
13 #include "ui/views/controls/textfield/textfield.h" 15 #include "ui/views/controls/textfield/textfield.h"
14 #include "ui/views/focus/focus_manager_factory.h" 16 #include "ui/views/focus/focus_manager_factory.h"
15 #include "ui/views/focus/focus_manager_test.h" 17 #include "ui/views/focus/focus_manager_test.h"
16 #include "ui/views/focus/widget_focus_manager.h" 18 #include "ui/views/focus/widget_focus_manager.h"
17 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
18 20
19 #if defined(USE_AURA)
20 #include "ui/aura/client/focus_client.h"
21 #include "ui/aura/window.h"
22 #endif
23
24 namespace views { 21 namespace views {
25 22
26 void FocusNativeView(gfx::NativeView view) {
27 #if defined(USE_AURA)
28 aura::client::GetFocusClient(view)->FocusWindow(view);
29 #elif defined(OS_WIN)
30 SetFocus(view);
31 #else
32 #error
33 #endif
34 }
35
36 enum FocusTestEventType { 23 enum FocusTestEventType {
37 ON_FOCUS = 0, 24 ON_FOCUS = 0,
38 ON_BLUR 25 ON_BLUR
39 }; 26 };
40 27
41 struct FocusTestEvent { 28 struct FocusTestEvent {
42 FocusTestEvent(FocusTestEventType type, int view_id) 29 FocusTestEvent(FocusTestEventType type, int view_id)
43 : type(type), 30 : type(type),
44 view_id(view_id) { 31 view_id(view_id) {
45 } 32 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 scoped_ptr<Widget> widget1(new Widget); 128 scoped_ptr<Widget> widget1(new Widget);
142 widget1->Init(params); 129 widget1->Init(params);
143 widget1->Show(); 130 widget1->Show();
144 131
145 scoped_ptr<Widget> widget2(new Widget); 132 scoped_ptr<Widget> widget2(new Widget);
146 widget2->Init(params); 133 widget2->Init(params);
147 widget2->Show(); 134 widget2->Show();
148 135
149 widget_listener.ClearFocusChanges(); 136 widget_listener.ClearFocusChanges();
150 gfx::NativeView native_view1 = widget1->GetNativeView(); 137 gfx::NativeView native_view1 = widget1->GetNativeView();
151 FocusNativeView(native_view1); 138 aura::client::GetFocusClient(native_view1)->FocusWindow(native_view1);
152 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size())); 139 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size()));
153 EXPECT_EQ(native_view1, widget_listener.focus_changes()[0].second); 140 EXPECT_EQ(native_view1, widget_listener.focus_changes()[0].second);
154 EXPECT_EQ(native_view1, widget_listener.focus_changes()[1].second); 141 EXPECT_EQ(native_view1, widget_listener.focus_changes()[1].second);
155 142
156 widget_listener.ClearFocusChanges(); 143 widget_listener.ClearFocusChanges();
157 gfx::NativeView native_view2 = widget2->GetNativeView(); 144 gfx::NativeView native_view2 = widget2->GetNativeView();
158 FocusNativeView(native_view2); 145 aura::client::GetFocusClient(native_view2)->FocusWindow(native_view2);
159 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size())); 146 ASSERT_EQ(2, static_cast<int>(widget_listener.focus_changes().size()));
160 EXPECT_EQ(NativeViewPair(native_view1, native_view2), 147 EXPECT_EQ(NativeViewPair(native_view1, native_view2),
161 widget_listener.focus_changes()[0]); 148 widget_listener.focus_changes()[0]);
162 EXPECT_EQ(NativeViewPair(native_view1, native_view2), 149 EXPECT_EQ(NativeViewPair(native_view1, native_view2),
163 widget_listener.focus_changes()[1]); 150 widget_listener.focus_changes()[1]);
164 } 151 }
165 152
166 // Counts accelerator calls. 153 // Counts accelerator calls.
167 class TestAcceleratorTarget : public ui::AcceleratorTarget { 154 class TestAcceleratorTarget : public ui::AcceleratorTarget {
168 public: 155 public:
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 546
560 virtual void TearDown() { 547 virtual void TearDown() {
561 FocusManagerFactory::Install(NULL); 548 FocusManagerFactory::Install(NULL);
562 ViewsTestBase::TearDown(); 549 ViewsTestBase::TearDown();
563 } 550 }
564 551
565 FocusManager* tracked_focus_manager_; 552 FocusManager* tracked_focus_manager_;
566 DtorTrackVector dtor_tracker_; 553 DtorTrackVector dtor_tracker_;
567 }; 554 };
568 555
569 #if !defined(USE_AURA)
570 TEST_F(FocusManagerDtorTest, FocusManagerDestructedLast) {
571 // Setup views hierarchy.
572 GetContentsView()->AddChildView(new Textfield());
573 GetContentsView()->AddChildView(new LabelButtonDtorTracked(
574 base::ASCIIToUTF16("button"), &dtor_tracker_));
575
576 // Close the window.
577 GetWidget()->Close();
578 RunPendingMessages();
579
580 // Test window, button and focus manager should all be destructed.
581 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size()));
582
583 // Focus manager should be the last one to destruct.
584 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str());
585 }
586 #endif
587
588 namespace { 556 namespace {
589 557
590 class FocusInAboutToRequestFocusFromTabTraversalView : public View { 558 class FocusInAboutToRequestFocusFromTabTraversalView : public View {
591 public: 559 public:
592 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {} 560 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {}
593 561
594 void set_view_to_focus(View* view) { view_to_focus_ = view; } 562 void set_view_to_focus(View* view) { view_to_focus_ = view; }
595 563
596 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE { 564 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE {
597 view_to_focus_->RequestFocus(); 565 view_to_focus_->RequestFocus();
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); 852 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView());
885 853
886 // Allow focus to go to the parent, and focus backwards which should now move 854 // Allow focus to go to the parent, and focus backwards which should now move
887 // up |widget_view| (in the parent). 855 // up |widget_view| (in the parent).
888 delegate->set_should_advance_focus_to_parent(true); 856 delegate->set_should_advance_focus_to_parent(true);
889 GetFocusManager()->AdvanceFocus(true); 857 GetFocusManager()->AdvanceFocus(true);
890 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); 858 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView());
891 } 859 }
892 860
893 } // namespace views 861 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/focus/focus_manager_test.cc ('k') | ui/views/focus/focus_traversal_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698