Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/test/ash_test_base.h" | 5 #include "ash/test/ash_test_base.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/test/test_session_state_delegate.h" | 10 #include "ash/common/test/test_session_state_delegate.h" |
| 11 #include "ash/common/test/test_system_tray_delegate.h" | 11 #include "ash/common/test/test_system_tray_delegate.h" |
| 12 #include "ash/common/wm/window_positioner.h" | 12 #include "ash/common/wm/window_positioner.h" |
| 13 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 14 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 15 #include "ash/display/extended_mouse_warp_controller.h" | 15 #include "ash/display/extended_mouse_warp_controller.h" |
| 16 #include "ash/display/mouse_cursor_event_filter.h" | 16 #include "ash/display/mouse_cursor_event_filter.h" |
| 17 #include "ash/display/unified_mouse_warp_controller.h" | 17 #include "ash/display/unified_mouse_warp_controller.h" |
| 18 #include "ash/display/window_tree_host_manager.h" | 18 #include "ash/display/window_tree_host_manager.h" |
| 19 #include "ash/ime/input_method_event_handler.h" | 19 #include "ash/ime/input_method_event_handler.h" |
| 20 #include "ash/mus/window_manager.h" | |
| 21 #include "ash/mus/window_manager_application.h" | |
| 20 #include "ash/root_window_controller.h" | 22 #include "ash/root_window_controller.h" |
| 21 #include "ash/shell.h" | 23 #include "ash/shell.h" |
| 22 #include "ash/shell/toplevel_window.h" | 24 #include "ash/shell/toplevel_window.h" |
| 23 #include "ash/test/ash_test_environment.h" | 25 #include "ash/test/ash_test_environment.h" |
| 24 #include "ash/test/ash_test_helper.h" | 26 #include "ash/test/ash_test_helper.h" |
| 25 #include "ash/test/test_shell_delegate.h" | 27 #include "ash/test/test_shell_delegate.h" |
| 26 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 27 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 29 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 28 #include "ui/aura/client/aura_constants.h" | 30 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/aura/client/screen_position_client.h" | 31 #include "ui/aura/client/screen_position_client.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 43 #include "ui/events/gesture_detection/gesture_configuration.h" | 45 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 44 #include "ui/gfx/geometry/point.h" | 46 #include "ui/gfx/geometry/point.h" |
| 45 #include "ui/wm/core/coordinate_conversion.h" | 47 #include "ui/wm/core/coordinate_conversion.h" |
| 46 | 48 |
| 47 #if defined(USE_X11) | 49 #if defined(USE_X11) |
| 48 #include "ui/gfx/x/x11_connection.h" // nogncheck | 50 #include "ui/gfx/x/x11_connection.h" // nogncheck |
| 49 #endif | 51 #endif |
| 50 | 52 |
| 51 namespace ash { | 53 namespace ash { |
| 52 namespace test { | 54 namespace test { |
| 53 namespace { | |
| 54 | 55 |
| 55 class AshEventGeneratorDelegate | 56 class AshEventGeneratorDelegate |
| 56 : public aura::test::EventGeneratorDelegateAura { | 57 : public aura::test::EventGeneratorDelegateAura { |
| 57 public: | 58 public: |
| 58 AshEventGeneratorDelegate() {} | 59 explicit AshEventGeneratorDelegate(AshTestHelper* ash_test_helper) |
| 60 : ash_test_helper_(ash_test_helper) { | |
| 61 DCHECK(ash_test_helper_); | |
| 62 } | |
| 59 ~AshEventGeneratorDelegate() override {} | 63 ~AshEventGeneratorDelegate() override {} |
| 60 | 64 |
| 61 // aura::test::EventGeneratorDelegateAura overrides: | 65 // aura::test::EventGeneratorDelegateAura overrides: |
| 62 aura::WindowTreeHost* GetHostAt( | 66 aura::WindowTreeHost* GetHostAt( |
| 63 const gfx::Point& point_in_screen) const override { | 67 const gfx::Point& point_in_screen) const override { |
| 64 display::Screen* screen = display::Screen::GetScreen(); | 68 display::Screen* screen = display::Screen::GetScreen(); |
| 65 display::Display display = screen->GetDisplayNearestPoint(point_in_screen); | 69 display::Display display = screen->GetDisplayNearestPoint(point_in_screen); |
| 66 return WmShell::Get() | 70 return WmShell::Get() |
| 67 ->GetRootWindowForDisplayId(display.id()) | 71 ->GetRootWindowForDisplayId(display.id()) |
| 68 ->aura_window() | 72 ->aura_window() |
| 69 ->GetHost(); | 73 ->GetHost(); |
| 70 } | 74 } |
| 71 | 75 |
| 72 aura::client::ScreenPositionClient* GetScreenPositionClient( | 76 aura::client::ScreenPositionClient* GetScreenPositionClient( |
| 73 const aura::Window* window) const override { | 77 const aura::Window* window) const override { |
| 74 return aura::client::GetScreenPositionClient(window->GetRootWindow()); | 78 return aura::client::GetScreenPositionClient(window->GetRootWindow()); |
| 75 } | 79 } |
| 76 | 80 |
| 77 void DispatchKeyEventToIME(ui::EventTarget* target, | 81 void DispatchKeyEventToIME(ui::EventTarget* target, |
| 78 ui::KeyEvent* event) override { | 82 ui::KeyEvent* event) override { |
| 79 // In Ash environment, the key event will be processed by event rewriters | 83 // In Ash environment, the key event will be processed by event rewriters |
| 80 // first. | 84 // first. |
| 81 } | 85 } |
| 82 | 86 |
| 87 void DispatchEventToPointerWatchers(ui::EventTarget* target, | |
| 88 const ui::PointerEvent& event) override { | |
|
sadrul
2017/03/16 03:22:47
Instead of doing this here, can you override this
James Cook
2017/03/16 19:13:32
Great idea! By doing that I was able to inject the
| |
| 89 // In classic ash PointerWatchers are triggered by an EventHandler on | |
| 90 // ash::Shell and don't need special handling. | |
| 91 if (!WmShell::Get()->IsRunningInMash()) | |
| 92 return; | |
| 93 | |
| 94 // Route events though WindowManager similar to production mash. Does | |
| 95 // nothing if there are no pointer watchers installed. | |
| 96 ash_test_helper_->window_manager_app() | |
| 97 ->window_manager() | |
| 98 ->OnPointerEventObserved(event, static_cast<aura::Window*>(target)); | |
|
James Cook
2017/03/15 19:01:19
I think this cast is OK -- aura::test::EventGenera
| |
| 99 } | |
| 100 | |
| 83 private: | 101 private: |
| 102 AshTestHelper* const ash_test_helper_; | |
| 103 | |
| 84 DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate); | 104 DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate); |
| 85 }; | 105 }; |
| 86 | 106 |
| 87 } // namespace | |
| 88 | |
| 89 ///////////////////////////////////////////////////////////////////////////// | 107 ///////////////////////////////////////////////////////////////////////////// |
| 90 | 108 |
| 91 AshTestBase::AshTestBase() | 109 AshTestBase::AshTestBase() |
| 92 : setup_called_(false), teardown_called_(false), start_session_(true) { | 110 : setup_called_(false), teardown_called_(false), start_session_(true) { |
| 93 #if defined(USE_X11) | 111 #if defined(USE_X11) |
| 94 // This is needed for tests which use this base class but are run in browser | 112 // This is needed for tests which use this base class but are run in browser |
| 95 // test binaries so don't get the default initialization in the unit test | 113 // test binaries so don't get the default initialization in the unit test |
| 96 // suite. | 114 // suite. |
| 97 gfx::InitializeThreadedX11(); | 115 gfx::InitializeThreadedX11(); |
| 98 #endif | 116 #endif |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 ->GetShelf(); | 188 ->GetShelf(); |
| 171 } | 189 } |
| 172 | 190 |
| 173 // static | 191 // static |
| 174 SystemTray* AshTestBase::GetPrimarySystemTray() { | 192 SystemTray* AshTestBase::GetPrimarySystemTray() { |
| 175 return Shell::GetInstance()->GetPrimarySystemTray(); | 193 return Shell::GetInstance()->GetPrimarySystemTray(); |
| 176 } | 194 } |
| 177 | 195 |
| 178 ui::test::EventGenerator& AshTestBase::GetEventGenerator() { | 196 ui::test::EventGenerator& AshTestBase::GetEventGenerator() { |
| 179 if (!event_generator_) { | 197 if (!event_generator_) { |
| 180 event_generator_.reset( | 198 event_generator_.reset(new ui::test::EventGenerator( |
| 181 new ui::test::EventGenerator(new AshEventGeneratorDelegate())); | 199 new AshEventGeneratorDelegate(ash_test_helper_.get()))); |
| 182 } | 200 } |
| 183 return *event_generator_.get(); | 201 return *event_generator_.get(); |
| 184 } | 202 } |
| 185 | 203 |
| 186 // static | 204 // static |
| 187 display::Display::Rotation AshTestBase::GetActiveDisplayRotation(int64_t id) { | 205 display::Display::Rotation AshTestBase::GetActiveDisplayRotation(int64_t id) { |
| 188 return Shell::GetInstance() | 206 return Shell::GetInstance() |
| 189 ->display_manager() | 207 ->display_manager() |
| 190 ->GetDisplayInfo(id) | 208 ->GetDisplayInfo(id) |
| 191 .GetActiveRotation(); | 209 .GetActiveRotation(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId( | 416 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 399 display_manager()->GetSecondaryDisplay().id()); | 417 display_manager()->GetSecondaryDisplay().id()); |
| 400 } | 418 } |
| 401 | 419 |
| 402 display::Display AshTestBase::GetSecondaryDisplay() { | 420 display::Display AshTestBase::GetSecondaryDisplay() { |
| 403 return ash_test_helper_->GetSecondaryDisplay(); | 421 return ash_test_helper_->GetSecondaryDisplay(); |
| 404 } | 422 } |
| 405 | 423 |
| 406 } // namespace test | 424 } // namespace test |
| 407 } // namespace ash | 425 } // namespace ash |
| OLD | NEW |