OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
8 #include "ash/drag_drop/drag_drop_controller.h" | 8 #include "ash/drag_drop/drag_drop_controller.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "ash/wm/wm_event.h" | 28 #include "ash/wm/wm_event.h" |
29 #include "base/basictypes.h" | 29 #include "base/basictypes.h" |
30 #include "base/compiler_specific.h" | 30 #include "base/compiler_specific.h" |
31 #include "base/memory/scoped_vector.h" | 31 #include "base/memory/scoped_vector.h" |
32 #include "base/run_loop.h" | 32 #include "base/run_loop.h" |
33 #include "base/strings/string_piece.h" | 33 #include "base/strings/string_piece.h" |
34 #include "base/strings/utf_string_conversions.h" | 34 #include "base/strings/utf_string_conversions.h" |
35 #include "ui/aura/client/aura_constants.h" | 35 #include "ui/aura/client/aura_constants.h" |
36 #include "ui/aura/client/cursor_client.h" | 36 #include "ui/aura/client/cursor_client.h" |
37 #include "ui/aura/client/focus_client.h" | 37 #include "ui/aura/client/focus_client.h" |
38 #include "ui/aura/test/event_generator.h" | |
39 #include "ui/aura/test/test_window_delegate.h" | 38 #include "ui/aura/test/test_window_delegate.h" |
40 #include "ui/aura/test/test_windows.h" | 39 #include "ui/aura/test/test_windows.h" |
41 #include "ui/aura/window.h" | 40 #include "ui/aura/window.h" |
42 #include "ui/aura/window_event_dispatcher.h" | 41 #include "ui/aura/window_event_dispatcher.h" |
43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 42 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 43 #include "ui/events/test/event_generator.h" |
44 #include "ui/gfx/rect_conversions.h" | 44 #include "ui/gfx/rect_conversions.h" |
45 #include "ui/gfx/transform.h" | 45 #include "ui/gfx/transform.h" |
46 #include "ui/views/controls/label.h" | 46 #include "ui/views/controls/label.h" |
47 #include "ui/views/widget/native_widget_aura.h" | 47 #include "ui/views/widget/native_widget_aura.h" |
48 #include "ui/views/widget/widget_delegate.h" | 48 #include "ui/views/widget/widget_delegate.h" |
49 #include "ui/wm/core/window_util.h" | 49 #include "ui/wm/core/window_util.h" |
50 #include "ui/wm/public/activation_delegate.h" | 50 #include "ui/wm/public/activation_delegate.h" |
51 | 51 |
52 namespace ash { | 52 namespace ash { |
53 namespace { | 53 namespace { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 gfx::Transform transform; | 163 gfx::Transform transform; |
164 if (!window->layer()->GetTargetTransformRelativeTo(root->layer(), | 164 if (!window->layer()->GetTargetTransformRelativeTo(root->layer(), |
165 &transform)) { | 165 &transform)) { |
166 return gfx::RectF(); | 166 return gfx::RectF(); |
167 } | 167 } |
168 transform.TransformRect(&bounds); | 168 transform.TransformRect(&bounds); |
169 return bounds; | 169 return bounds; |
170 } | 170 } |
171 | 171 |
172 void ClickWindow(aura::Window* window) { | 172 void ClickWindow(aura::Window* window) { |
173 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); | 173 ui::test::EventGenerator event_generator(window->GetRootWindow(), window); |
174 gfx::RectF target = GetTransformedBounds(window); | 174 gfx::RectF target = GetTransformedBounds(window); |
175 event_generator.ClickLeftButton(); | 175 event_generator.ClickLeftButton(); |
176 } | 176 } |
177 | 177 |
178 void SendKey(ui::KeyboardCode key) { | 178 void SendKey(ui::KeyboardCode key) { |
179 aura::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); | 179 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); |
180 event_generator.PressKey(key, 0); | 180 event_generator.PressKey(key, 0); |
181 event_generator.ReleaseKey(key, 0); | 181 event_generator.ReleaseKey(key, 0); |
182 } | 182 } |
183 | 183 |
184 bool IsSelecting() { | 184 bool IsSelecting() { |
185 return ash::Shell::GetInstance()->window_selector_controller()-> | 185 return ash::Shell::GetInstance()->window_selector_controller()-> |
186 IsSelecting(); | 186 IsSelecting(); |
187 } | 187 } |
188 | 188 |
189 aura::Window* GetFocusedWindow() { | 189 aura::Window* GetFocusedWindow() { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 314 |
315 // Tests selecting a window by tapping on it. | 315 // Tests selecting a window by tapping on it. |
316 TEST_F(WindowSelectorTest, BasicGesture) { | 316 TEST_F(WindowSelectorTest, BasicGesture) { |
317 gfx::Rect bounds(0, 0, 400, 400); | 317 gfx::Rect bounds(0, 0, 400, 400); |
318 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 318 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
319 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 319 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
320 wm::ActivateWindow(window1.get()); | 320 wm::ActivateWindow(window1.get()); |
321 EXPECT_EQ(window1.get(), GetFocusedWindow()); | 321 EXPECT_EQ(window1.get(), GetFocusedWindow()); |
322 ToggleOverview(); | 322 ToggleOverview(); |
323 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); | 323 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); |
324 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 324 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
325 window2.get()); | 325 window2.get()); |
326 generator.GestureTapAt(gfx::ToEnclosingRect( | 326 generator.GestureTapAt(gfx::ToEnclosingRect( |
327 GetTransformedTargetBounds(window2.get())).CenterPoint()); | 327 GetTransformedTargetBounds(window2.get())).CenterPoint()); |
328 EXPECT_EQ(window2.get(), GetFocusedWindow()); | 328 EXPECT_EQ(window2.get(), GetFocusedWindow()); |
329 } | 329 } |
330 | 330 |
331 // Tests that a window does not receive located events when in overview mode. | 331 // Tests that a window does not receive located events when in overview mode. |
332 TEST_F(WindowSelectorTest, WindowDoesNotReceiveEvents) { | 332 TEST_F(WindowSelectorTest, WindowDoesNotReceiveEvents) { |
333 gfx::Rect window_bounds(20, 10, 200, 300); | 333 gfx::Rect window_bounds(20, 10, 200, 300); |
334 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 334 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
335 scoped_ptr<aura::Window> window(CreateWindow(window_bounds)); | 335 scoped_ptr<aura::Window> window(CreateWindow(window_bounds)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 params.bounds = gfx::Rect(0, 0, 400, 400); | 370 params.bounds = gfx::Rect(0, 0, 400, 400); |
371 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 371 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
372 params.parent = window1->parent(); | 372 params.parent = window1->parent(); |
373 widget->Init(params); | 373 widget->Init(params); |
374 widget->Show(); | 374 widget->Show(); |
375 ToggleOverview(); | 375 ToggleOverview(); |
376 | 376 |
377 aura::Window* window2 = widget->GetNativeWindow(); | 377 aura::Window* window2 = widget->GetNativeWindow(); |
378 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window2); | 378 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window2); |
379 gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1); | 379 gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1); |
380 aura::test::EventGenerator event_generator(window2->GetRootWindow(), point); | 380 ui::test::EventGenerator event_generator(window2->GetRootWindow(), point); |
381 | 381 |
382 EXPECT_FALSE(widget->IsClosed()); | 382 EXPECT_FALSE(widget->IsClosed()); |
383 event_generator.ClickLeftButton(); | 383 event_generator.ClickLeftButton(); |
384 EXPECT_TRUE(widget->IsClosed()); | 384 EXPECT_TRUE(widget->IsClosed()); |
385 } | 385 } |
386 | 386 |
387 // Tests entering overview mode with two windows and selecting one. | 387 // Tests entering overview mode with two windows and selecting one. |
388 TEST_F(WindowSelectorTest, FullscreenWindow) { | 388 TEST_F(WindowSelectorTest, FullscreenWindow) { |
389 gfx::Rect bounds(0, 0, 400, 400); | 389 gfx::Rect bounds(0, 0, 400, 400); |
390 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 390 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 aura::Window* window2 = widget2->GetNativeWindow(); | 1006 aura::Window* window2 = widget2->GetNativeWindow(); |
1007 base::string16 panel1_title = base::UTF8ToUTF16("Panel 1"); | 1007 base::string16 panel1_title = base::UTF8ToUTF16("Panel 1"); |
1008 base::string16 panel2_title = base::UTF8ToUTF16("Panel 2"); | 1008 base::string16 panel2_title = base::UTF8ToUTF16("Panel 2"); |
1009 window1->SetTitle(panel1_title); | 1009 window1->SetTitle(panel1_title); |
1010 window2->SetTitle(panel2_title); | 1010 window2->SetTitle(panel2_title); |
1011 wm::ActivateWindow(window1); | 1011 wm::ActivateWindow(window1); |
1012 ToggleOverview(); | 1012 ToggleOverview(); |
1013 | 1013 |
1014 gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1); | 1014 gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1); |
1015 gfx::Point point1(bounds1.top_right().x() - 1, bounds1.top_right().y() - 1); | 1015 gfx::Point point1(bounds1.top_right().x() - 1, bounds1.top_right().y() - 1); |
1016 aura::test::EventGenerator event_generator1(window1->GetRootWindow(), point1); | 1016 ui::test::EventGenerator event_generator1(window1->GetRootWindow(), point1); |
1017 | 1017 |
1018 EXPECT_FALSE(widget1->IsClosed()); | 1018 EXPECT_FALSE(widget1->IsClosed()); |
1019 event_generator1.ClickLeftButton(); | 1019 event_generator1.ClickLeftButton(); |
1020 EXPECT_TRUE(widget1->IsClosed()); | 1020 EXPECT_TRUE(widget1->IsClosed()); |
1021 RunAllPendingInMessageLoop(); | 1021 RunAllPendingInMessageLoop(); |
1022 EXPECT_TRUE(IsSelecting()); | 1022 EXPECT_TRUE(IsSelecting()); |
1023 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).front(); | 1023 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).front(); |
1024 EXPECT_FALSE(window_item->empty()); | 1024 EXPECT_FALSE(window_item->empty()); |
1025 EXPECT_TRUE(window_item->Contains(window2)); | 1025 EXPECT_TRUE(window_item->Contains(window2)); |
1026 EXPECT_TRUE(GetCloseButton(window_item)->IsVisible()); | 1026 EXPECT_TRUE(GetCloseButton(window_item)->IsVisible()); |
1027 | 1027 |
1028 | 1028 |
1029 views::Label* label = GetLabelView(window_item); | 1029 views::Label* label = GetLabelView(window_item); |
1030 EXPECT_EQ(label->text(), panel2_title); | 1030 EXPECT_EQ(label->text(), panel2_title); |
1031 | 1031 |
1032 gfx::RectF bounds2 = GetTransformedBoundsInRootWindow(window2); | 1032 gfx::RectF bounds2 = GetTransformedBoundsInRootWindow(window2); |
1033 gfx::Point point2(bounds2.top_right().x() - 1, bounds2.top_right().y() - 1); | 1033 gfx::Point point2(bounds2.top_right().x() - 1, bounds2.top_right().y() - 1); |
1034 aura::test::EventGenerator event_generator2(window2->GetRootWindow(), point2); | 1034 ui::test::EventGenerator event_generator2(window2->GetRootWindow(), point2); |
1035 | 1035 |
1036 EXPECT_FALSE(widget2->IsClosed()); | 1036 EXPECT_FALSE(widget2->IsClosed()); |
1037 event_generator2.ClickLeftButton(); | 1037 event_generator2.ClickLeftButton(); |
1038 EXPECT_TRUE(widget2->IsClosed()); | 1038 EXPECT_TRUE(widget2->IsClosed()); |
1039 RunAllPendingInMessageLoop(); | 1039 RunAllPendingInMessageLoop(); |
1040 EXPECT_FALSE(IsSelecting()); | 1040 EXPECT_FALSE(IsSelecting()); |
1041 } | 1041 } |
1042 | 1042 |
1043 // Creates three windows and tests filtering them by title. | 1043 // Creates three windows and tests filtering them by title. |
1044 TEST_F(WindowSelectorTest, BasicTextFiltering) { | 1044 TEST_F(WindowSelectorTest, BasicTextFiltering) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 // Dimming all the items should hide the selection widget. | 1115 // Dimming all the items should hide the selection widget. |
1116 FilterItems("Pop"); | 1116 FilterItems("Pop"); |
1117 EXPECT_FALSE(selection_widget_active()); | 1117 EXPECT_FALSE(selection_widget_active()); |
1118 | 1118 |
1119 // Undimming one window should automatically select it. | 1119 // Undimming one window should automatically select it. |
1120 FilterItems("Rock and roll"); | 1120 FilterItems("Rock and roll"); |
1121 EXPECT_EQ(GetSelectedWindow(), window2.get()); | 1121 EXPECT_EQ(GetSelectedWindow(), window2.get()); |
1122 } | 1122 } |
1123 | 1123 |
1124 } // namespace ash | 1124 } // namespace ash |
OLD | NEW |