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

Side by Side Diff: ash/wm/window_manager_unittest.cc

Issue 2872343003: Remove InputMethodEventHandler. (Closed)
Patch Set: Add a unittest. Created 3 years, 7 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
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/public/cpp/config.h" 5 #include "ash/public/cpp/config.h"
6 #include "ash/public/cpp/shell_window_ids.h" 6 #include "ash/public/cpp/shell_window_ids.h"
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/test_activation_delegate.h" 9 #include "ash/test/test_activation_delegate.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 105
106 int hittest_code_; 106 int hittest_code_;
107 107
108 DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate); 108 DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate);
109 }; 109 };
110 110
111 TEST_F(WindowManagerTest, Focus) { 111 TEST_F(WindowManagerTest, Focus) {
112 // The IME event filter interferes with the basic key event propagation we 112 // The IME event filter interferes with the basic key event propagation we
113 // attempt to do here, so we disable it. 113 // attempt to do here, so we disable it.
114 // 114 const bool kSkipIME = true;
115 DisableIME(); 115
116 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 116 aura::Window* root_window = Shell::GetPrimaryRootWindow();
117 root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); 117 root_window->SetBounds(gfx::Rect(0, 0, 510, 510));
118 118
119 // Supplied ids are negative so as not to collide with shell ids. 119 // Supplied ids are negative so as not to collide with shell ids.
120 // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe 120 // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe
121 // id beyond shell id max? 121 // id beyond shell id max?
122 std::unique_ptr<aura::Window> w1( 122 std::unique_ptr<aura::Window> w1(
123 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500))); 123 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500)));
124 std::unique_ptr<aura::Window> w11(aura::test::CreateTestWindow( 124 std::unique_ptr<aura::Window> w11(aura::test::CreateTestWindow(
125 SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get())); 125 SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get()));
(...skipping 23 matching lines...) Expand all
149 generator.ClickLeftButton(); 149 generator.ClickLeftButton();
150 150
151 aura::client::FocusClient* focus_client = 151 aura::client::FocusClient* focus_client =
152 aura::client::GetFocusClient(w121.get()); 152 aura::client::GetFocusClient(w121.get());
153 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow()); 153 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow());
154 154
155 ui::EventSink* sink = root_window->GetHost()->event_sink(); 155 ui::EventSink* sink = root_window->GetHost()->event_sink();
156 156
157 // The key press should be sent to the focused sub-window. 157 // The key press should be sent to the focused sub-window.
158 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 158 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
159 keyev.set_skip_ime(kSkipIME);
159 ui::EventDispatchDetails details = sink->OnEventFromSource(&keyev); 160 ui::EventDispatchDetails details = sink->OnEventFromSource(&keyev);
160 ASSERT_FALSE(details.dispatcher_destroyed); 161 ASSERT_FALSE(details.dispatcher_destroyed);
161 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); 162 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code());
162 163
163 // Touch on a sub-window (w122) to focus it. 164 // Touch on a sub-window (w122) to focus it.
164 gfx::Point click_point = w122->bounds().CenterPoint(); 165 gfx::Point click_point = w122->bounds().CenterPoint();
165 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point); 166 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point);
166 ui::TouchEvent touchev( 167 ui::TouchEvent touchev(
167 ui::ET_TOUCH_PRESSED, click_point, getTime(), 168 ui::ET_TOUCH_PRESSED, click_point, getTime(),
168 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); 169 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
169 details = sink->OnEventFromSource(&touchev); 170 details = sink->OnEventFromSource(&touchev);
170 ASSERT_FALSE(details.dispatcher_destroyed); 171 ASSERT_FALSE(details.dispatcher_destroyed);
171 focus_client = aura::client::GetFocusClient(w122.get()); 172 focus_client = aura::client::GetFocusClient(w122.get());
172 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow()); 173 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow());
173 174
174 // The key press should be sent to the focused sub-window. 175 // The key press should be sent to the focused sub-window.
175 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 176 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
177 keyev.set_skip_ime(kSkipIME);
176 details = sink->OnEventFromSource(&keyev); 178 details = sink->OnEventFromSource(&keyev);
177 ASSERT_FALSE(details.dispatcher_destroyed); 179 ASSERT_FALSE(details.dispatcher_destroyed);
178 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); 180 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code());
179 181
180 // Hiding the focused window will set the focus to its parent if 182 // Hiding the focused window will set the focus to its parent if
181 // it's focusable. 183 // it's focusable.
182 w122->Hide(); 184 w122->Hide();
183 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), 185 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
184 aura::client::GetFocusClient(w122.get())); 186 aura::client::GetFocusClient(w122.get()));
185 EXPECT_EQ(w12.get(), 187 EXPECT_EQ(w12.get(),
(...skipping 19 matching lines...) Expand all
205 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 207 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
206 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 208 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
207 209
208 // Hiding the focused window will set the focus to NULL because 210 // Hiding the focused window will set the focus to NULL because
209 // parent window is not focusable. 211 // parent window is not focusable.
210 w123->Hide(); 212 w123->Hide();
211 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), 213 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
212 aura::client::GetFocusClient(w123.get())); 214 aura::client::GetFocusClient(w123.get()));
213 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 215 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
214 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 216 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
217 keyev.set_skip_ime(kSkipIME);
215 details = sink->OnEventFromSource(&keyev); 218 details = sink->OnEventFromSource(&keyev);
216 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed); 219 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
217 220
218 // Set the focus back to w123 221 // Set the focus back to w123
219 aura::client::SetActivationDelegate(w1.get(), NULL); 222 aura::client::SetActivationDelegate(w1.get(), NULL);
220 w123->Show(); 223 w123->Show();
221 w123->Focus(); 224 w123->Focus();
222 EXPECT_EQ(w123.get(), 225 EXPECT_EQ(w123.get(),
223 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 226 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
224 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 227 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
225 228
226 // Removing the focused window will set the focus to NULL because 229 // Removing the focused window will set the focus to NULL because
227 // parent window is not focusable. 230 // parent window is not focusable.
228 w12->RemoveChild(w123.get()); 231 w12->RemoveChild(w123.get());
229 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); 232 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get()));
230 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 233 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
234 keyev.set_skip_ime(kSkipIME);
231 details = sink->OnEventFromSource(&keyev); 235 details = sink->OnEventFromSource(&keyev);
232 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed); 236 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
233 237
234 // Must set to NULL since the activation delegate will be destroyed before 238 // Must set to NULL since the activation delegate will be destroyed before
235 // the windows. 239 // the windows.
236 aura::client::SetActivationDelegate(w1.get(), NULL); 240 aura::client::SetActivationDelegate(w1.get(), NULL);
237 } 241 }
238 242
239 // Various assertion testing for activating windows. 243 // Various assertion testing for activating windows.
240 TEST_F(WindowManagerTest, ActivateOnMouse) { 244 TEST_F(WindowManagerTest, ActivateOnMouse) {
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 details = sink->OnEventFromSource(&mouseev2); 671 details = sink->OnEventFromSource(&mouseev2);
668 ASSERT_FALSE(details.dispatcher_destroyed); 672 ASSERT_FALSE(details.dispatcher_destroyed);
669 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 673 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
670 EXPECT_EQ(w1.get(), 674 EXPECT_EQ(w1.get(),
671 aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); 675 aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
672 } 676 }
673 677
674 TEST_F(WindowManagerTest, AdditionalFilters) { 678 TEST_F(WindowManagerTest, AdditionalFilters) {
675 // The IME event filter interferes with the basic key event propagation we 679 // The IME event filter interferes with the basic key event propagation we
676 // attempt to do here, so we disable it. 680 // attempt to do here, so we disable it.
677 DisableIME(); 681 const bool kSkipIME = true;
682
678 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 683 aura::Window* root_window = Shell::GetPrimaryRootWindow();
679 684
680 // Creates a window and make it active 685 // Creates a window and make it active
681 std::unique_ptr<aura::Window> w1( 686 std::unique_ptr<aura::Window> w1(
682 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); 687 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100)));
683 wm::ActivateWindow(w1.get()); 688 wm::ActivateWindow(w1.get());
684 689
685 // Creates two addition filters 690 // Creates two addition filters
686 std::unique_ptr<CustomEventHandler> f1(new CustomEventHandler); 691 std::unique_ptr<CustomEventHandler> f1(new CustomEventHandler);
687 std::unique_ptr<CustomEventHandler> f2(new CustomEventHandler); 692 std::unique_ptr<CustomEventHandler> f2(new CustomEventHandler);
688 693
689 // Adds them to root window event filter. 694 // Adds them to root window event filter.
690 ::wm::CompoundEventFilter* env_filter = Shell::Get()->env_filter(); 695 ::wm::CompoundEventFilter* env_filter = Shell::Get()->env_filter();
691 env_filter->AddHandler(f1.get()); 696 env_filter->AddHandler(f1.get());
692 env_filter->AddHandler(f2.get()); 697 env_filter->AddHandler(f2.get());
693 698
694 // Dispatches mouse and keyboard events. 699 // Dispatches mouse and keyboard events.
695 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); 700 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
701 key_event.set_skip_ime(kSkipIME);
696 ui::EventSink* sink = root_window->GetHost()->event_sink(); 702 ui::EventSink* sink = root_window->GetHost()->event_sink();
697 ui::EventDispatchDetails details = sink->OnEventFromSource(&key_event); 703 ui::EventDispatchDetails details = sink->OnEventFromSource(&key_event);
698 ASSERT_FALSE(details.dispatcher_destroyed); 704 ASSERT_FALSE(details.dispatcher_destroyed);
699 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 705 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
700 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); 706 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0);
701 details = sink->OnEventFromSource(&mouse_pressed); 707 details = sink->OnEventFromSource(&mouse_pressed);
702 ASSERT_FALSE(details.dispatcher_destroyed); 708 ASSERT_FALSE(details.dispatcher_destroyed);
703 709
704 // Both filters should get the events. 710 // Both filters should get the events.
705 EXPECT_EQ(1, f1->num_key_events()); 711 EXPECT_EQ(1, f1->num_key_events());
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 observer_b.reset(); 903 observer_b.reset();
898 generator.MoveMouseTo(50, 50); 904 generator.MoveMouseTo(50, 50);
899 EXPECT_TRUE(observer_a.did_visibility_change()); 905 EXPECT_TRUE(observer_a.did_visibility_change());
900 EXPECT_FALSE(observer_b.did_visibility_change()); 906 EXPECT_FALSE(observer_b.did_visibility_change());
901 EXPECT_TRUE(observer_a.is_cursor_visible()); 907 EXPECT_TRUE(observer_a.is_cursor_visible());
902 908
903 cursor_manager->RemoveObserver(&observer_a); 909 cursor_manager->RemoveObserver(&observer_a);
904 } 910 }
905 911
906 } // namespace ash 912 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698