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

Side by Side Diff: ash/extended_desktop_unittest.cc

Issue 11299219: Rework FocusManager as FocusClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | « ash/display/screen_position_controller.cc ('k') | ash/root_window_controller.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 "ash/display/display_controller.h" 5 #include "ash/display/display_controller.h"
6 #include "ash/display/display_manager.h" 6 #include "ash/display/display_manager.h"
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/system/tray/system_tray.h" 10 #include "ash/system/tray/system_tray.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/coordinate_conversion.h" 12 #include "ash/wm/coordinate_conversion.h"
13 #include "ash/wm/property_util.h" 13 #include "ash/wm/property_util.h"
14 #include "ash/wm/window_cycle_controller.h" 14 #include "ash/wm/window_cycle_controller.h"
15 #include "ash/wm/window_properties.h" 15 #include "ash/wm/window_properties.h"
16 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "ui/aura/client/activation_client.h" 18 #include "ui/aura/client/activation_client.h"
19 #include "ui/aura/client/capture_client.h" 19 #include "ui/aura/client/capture_client.h"
20 #include "ui/aura/focus_manager.h" 20 #include "ui/aura/client/focus_client.h"
21 #include "ui/aura/root_window.h" 21 #include "ui/aura/root_window.h"
22 #include "ui/aura/test/event_generator.h" 22 #include "ui/aura/test/event_generator.h"
23 #include "ui/aura/test/test_windows.h" 23 #include "ui/aura/test/test_windows.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/base/cursor/cursor.h" 25 #include "ui/base/cursor/cursor.h"
26 #include "ui/base/events/event_handler.h" 26 #include "ui/base/events/event_handler.h"
27 #include "ui/gfx/display.h" 27 #include "ui/gfx/display.h"
28 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
29 #include "ui/views/controls/textfield/textfield.h" 29 #include "ui/views/controls/textfield/textfield.h"
30 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 UpdateDisplay("1000x600,600x400"); 112 UpdateDisplay("1000x600,600x400");
113 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 113 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
114 114
115 // All root windows must have the root window controller. 115 // All root windows must have the root window controller.
116 ASSERT_EQ(2U, root_windows.size()); 116 ASSERT_EQ(2U, root_windows.size());
117 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); 117 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
118 iter != root_windows.end(); ++iter) { 118 iter != root_windows.end(); ++iter) {
119 EXPECT_TRUE(GetRootWindowController(*iter) != NULL); 119 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
120 } 120 }
121 // Make sure root windows share the same controllers. 121 // Make sure root windows share the same controllers.
122 EXPECT_EQ(root_windows[0]->GetFocusManager(), 122 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
123 root_windows[1]->GetFocusManager()); 123 aura::client::GetFocusClient(root_windows[1]));
124 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]), 124 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
125 aura::client::GetActivationClient(root_windows[1])); 125 aura::client::GetActivationClient(root_windows[1]));
126 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), 126 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
127 aura::client::GetCaptureClient(root_windows[1])); 127 aura::client::GetCaptureClient(root_windows[1]));
128 } 128 }
129 129
130 TEST_F(ExtendedDesktopTest, Activation) { 130 TEST_F(ExtendedDesktopTest, Activation) {
131 UpdateDisplay("1000x600,600x400"); 131 UpdateDisplay("1000x600,600x400");
132 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 132 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
133 133
134 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); 134 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
135 views::Widget* widget_on_2nd = 135 views::Widget* widget_on_2nd =
136 CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); 136 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
137 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); 137 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
138 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); 138 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
139 139
140 EXPECT_EQ(widget_on_2nd->GetNativeView(), 140 EXPECT_EQ(widget_on_2nd->GetNativeView(),
141 root_windows[0]->GetFocusManager()->GetFocusedWindow()); 141 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
142 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); 142 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
143 143
144 aura::test::EventGenerator generator_1st(root_windows[0]); 144 aura::test::EventGenerator generator_1st(root_windows[0]);
145 aura::test::EventGenerator generator_2nd(root_windows[1]); 145 aura::test::EventGenerator generator_2nd(root_windows[1]);
146 146
147 // Clicking a window changes the active window and active root window. 147 // Clicking a window changes the active window and active root window.
148 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); 148 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
149 generator_1st.ClickLeftButton(); 149 generator_1st.ClickLeftButton();
150 150
151 EXPECT_EQ(widget_on_1st->GetNativeView(), 151 EXPECT_EQ(widget_on_1st->GetNativeView(),
152 root_windows[0]->GetFocusManager()->GetFocusedWindow()); 152 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
153 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); 153 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
154 154
155 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); 155 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
156 generator_2nd.ClickLeftButton(); 156 generator_2nd.ClickLeftButton();
157 157
158 EXPECT_EQ(widget_on_2nd->GetNativeView(), 158 EXPECT_EQ(widget_on_2nd->GetNativeView(),
159 root_windows[0]->GetFocusManager()->GetFocusedWindow()); 159 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
160 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); 160 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
161 } 161 }
162 162
163 TEST_F(ExtendedDesktopTest, SystemModal) { 163 TEST_F(ExtendedDesktopTest, SystemModal) {
164 UpdateDisplay("1000x600,600x400"); 164 UpdateDisplay("1000x600,600x400");
165 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 165 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
166 166
167 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); 167 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
168 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); 168 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
169 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); 169 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 views::Textfield* textfield = new views::Textfield; 663 views::Textfield* textfield = new views::Textfield;
664 lock_widget->SetContentsView(textfield); 664 lock_widget->SetContentsView(textfield);
665 665
666 ash::Shell::GetContainer( 666 ash::Shell::GetContainer(
667 Shell::GetPrimaryRootWindow(), 667 Shell::GetPrimaryRootWindow(),
668 ash::internal::kShellWindowId_LockScreenContainer)-> 668 ash::internal::kShellWindowId_LockScreenContainer)->
669 AddChild(lock_widget->GetNativeView()); 669 AddChild(lock_widget->GetNativeView());
670 lock_widget->Show(); 670 lock_widget->Show();
671 textfield->RequestFocus(); 671 textfield->RequestFocus();
672 672
673 aura::FocusManager* focus_manager = root_windows[0]->GetFocusManager(); 673 aura::client::FocusClient* focus_client =
674 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); 674 aura::client::GetFocusClient(root_windows[0]);
675 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
675 676
676 // The lock window should get events on both root windows. 677 // The lock window should get events on both root windows.
677 aura::test::EventGenerator generator1(root_windows[0]); 678 aura::test::EventGenerator generator1(root_windows[0]);
678 generator1.PressKey(ui::VKEY_A, 0); 679 generator1.PressKey(ui::VKEY_A, 0);
679 generator1.ReleaseKey(ui::VKEY_A, 0); 680 generator1.ReleaseKey(ui::VKEY_A, 0);
680 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); 681 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
681 EXPECT_EQ("a", UTF16ToASCII(textfield->text())); 682 EXPECT_EQ("a", UTF16ToASCII(textfield->text()));
682 683
683 aura::test::EventGenerator generator2(root_windows[1]); 684 aura::test::EventGenerator generator2(root_windows[1]);
684 generator2.PressKey(ui::VKEY_B, 0); 685 generator2.PressKey(ui::VKEY_B, 0);
685 generator2.ReleaseKey(ui::VKEY_B, 0); 686 generator2.ReleaseKey(ui::VKEY_B, 0);
686 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); 687 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
687 EXPECT_EQ("ab", UTF16ToASCII(textfield->text())); 688 EXPECT_EQ("ab", UTF16ToASCII(textfield->text()));
688 689
689 // Deleting 2nd display. The lock window still should get the events. 690 // Deleting 2nd display. The lock window still should get the events.
690 UpdateDisplay("100x100"); 691 UpdateDisplay("100x100");
691 generator2.PressKey(ui::VKEY_C, 0); 692 generator2.PressKey(ui::VKEY_C, 0);
692 generator2.ReleaseKey(ui::VKEY_C, 0); 693 generator2.ReleaseKey(ui::VKEY_C, 0);
693 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); 694 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
694 EXPECT_EQ("abc", UTF16ToASCII(textfield->text())); 695 EXPECT_EQ("abc", UTF16ToASCII(textfield->text()));
695 696
696 // Creating 2nd display again, and lock window still should get events 697 // Creating 2nd display again, and lock window still should get events
697 // on both root windows. 698 // on both root windows.
698 UpdateDisplay("100x100,200x200"); 699 UpdateDisplay("100x100,200x200");
699 root_windows = Shell::GetAllRootWindows(); 700 root_windows = Shell::GetAllRootWindows();
700 generator1.PressKey(ui::VKEY_D, 0); 701 generator1.PressKey(ui::VKEY_D, 0);
701 generator1.ReleaseKey(ui::VKEY_D, 0); 702 generator1.ReleaseKey(ui::VKEY_D, 0);
702 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); 703 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
703 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text())); 704 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text()));
704 705
705 aura::test::EventGenerator generator22(root_windows[1]); 706 aura::test::EventGenerator generator22(root_windows[1]);
706 generator22.PressKey(ui::VKEY_E, 0); 707 generator22.PressKey(ui::VKEY_E, 0);
707 generator22.ReleaseKey(ui::VKEY_E, 0); 708 generator22.ReleaseKey(ui::VKEY_E, 0);
708 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); 709 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
709 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); 710 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text()));
710 } 711 }
711 712
712 } // namespace internal 713 } // namespace internal
713 } // namespace ash 714 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/screen_position_controller.cc ('k') | ash/root_window_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698