Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/shell.h" |
| 6 | #include "ash/shell_window_ids.h" |
| 7 | #include "ash/test/ash_test_base.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 8 | #include "ash/test/shell_test_api.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 9 | #include "ash/test/test_activation_delegate.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include "ash/wm/window_util.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 11 | #include "ui/aura/client/cursor_client_observer.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 12 | #include "ui/aura/client/focus_client.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | #include "ui/aura/env.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | #include "ui/aura/test/aura_test_base.h" |
| 15 | #include "ui/aura/test/event_generator.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 16 | #include "ui/aura/test/test_window_delegate.h" |
| 17 | #include "ui/aura/test/test_windows.h" |
| 18 | #include "ui/base/cursor/cursor.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | #include "ui/base/hit_test.h" |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 20 | #include "ui/events/event.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 21 | #include "ui/events/event_processor.h" |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 22 | #include "ui/events/event_utils.h" |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 23 | #include "ui/events/test/test_event_handler.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 24 | #include "ui/gfx/screen.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 25 | #include "ui/wm/core/compound_event_filter.h" |
| 26 | #include "ui/wm/core/input_method_event_filter.h" |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 27 | #include "ui/wm/public/activation_client.h" |
| 28 | #include "ui/wm/public/activation_delegate.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 29 | |
| 30 | namespace { |
| 31 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 32 | class TestingCursorClientObserver : public aura::client::CursorClientObserver { |
| 33 | public: |
| 34 | TestingCursorClientObserver() |
| 35 | : cursor_visibility_(false), |
| 36 | did_visibility_change_(false) {} |
| 37 | void reset() { cursor_visibility_ = did_visibility_change_ = false; } |
| 38 | bool is_cursor_visible() const { return cursor_visibility_; } |
| 39 | bool did_visibility_change() const { return did_visibility_change_; } |
| 40 | |
| 41 | // Overridden from aura::client::CursorClientObserver: |
| 42 | virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE { |
| 43 | cursor_visibility_ = is_visible; |
| 44 | did_visibility_change_ = true; |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | bool cursor_visibility_; |
| 49 | bool did_visibility_change_; |
| 50 | |
| 51 | DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); |
| 52 | }; |
| 53 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 54 | base::TimeDelta getTime() { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 55 | return ui::EventTimeForNow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 58 | // A slightly changed TestEventHandler which can be configured to return a |
| 59 | // specified value for key/mouse event handling. |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 60 | class CustomEventHandler : public ui::test::TestEventHandler { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 61 | public: |
| 62 | CustomEventHandler() |
| 63 | : key_result_(ui::ER_UNHANDLED), |
| 64 | mouse_result_(ui::ER_UNHANDLED) { |
| 65 | } |
| 66 | |
| 67 | virtual ~CustomEventHandler() {} |
| 68 | |
| 69 | void set_key_event_handling_result(ui::EventResult result) { |
| 70 | key_result_ = result; |
| 71 | } |
| 72 | |
| 73 | void set_mouse_event_handling_result(ui::EventResult result) { |
| 74 | mouse_result_ = result; |
| 75 | } |
| 76 | |
| 77 | // Overridden from ui::EventHandler: |
| 78 | virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 79 | ui::test::TestEventHandler::OnKeyEvent(event); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 80 | if (key_result_ & ui::ER_HANDLED) |
| 81 | event->SetHandled(); |
| 82 | if (key_result_ & ui::ER_CONSUMED) |
| 83 | event->StopPropagation(); |
| 84 | } |
| 85 | |
| 86 | virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 87 | ui::test::TestEventHandler::OnMouseEvent(event); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 88 | if (mouse_result_ & ui::ER_HANDLED) |
| 89 | event->SetHandled(); |
| 90 | if (mouse_result_ & ui::ER_CONSUMED) |
| 91 | event->StopPropagation(); |
| 92 | } |
| 93 | |
| 94 | private: |
| 95 | ui::EventResult key_result_; |
| 96 | ui::EventResult mouse_result_; |
| 97 | |
| 98 | DISALLOW_COPY_AND_ASSIGN(CustomEventHandler); |
| 99 | }; |
| 100 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 101 | } // namespace |
| 102 | |
| 103 | namespace ash { |
| 104 | |
| 105 | typedef test::AshTestBase WindowManagerTest; |
| 106 | |
| 107 | class NonFocusableDelegate : public aura::test::TestWindowDelegate { |
| 108 | public: |
| 109 | NonFocusableDelegate() {} |
| 110 | |
| 111 | private: |
| 112 | virtual bool CanFocus() OVERRIDE { |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | DISALLOW_COPY_AND_ASSIGN(NonFocusableDelegate); |
| 117 | }; |
| 118 | |
| 119 | class HitTestWindowDelegate : public aura::test::TestWindowDelegate { |
| 120 | public: |
| 121 | HitTestWindowDelegate() |
| 122 | : hittest_code_(HTNOWHERE) { |
| 123 | } |
| 124 | virtual ~HitTestWindowDelegate() {} |
| 125 | void set_hittest_code(int hittest_code) { hittest_code_ = hittest_code; } |
| 126 | |
| 127 | private: |
| 128 | // Overridden from TestWindowDelegate: |
| 129 | virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| 130 | return hittest_code_; |
| 131 | } |
| 132 | |
| 133 | int hittest_code_; |
| 134 | |
| 135 | DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate); |
| 136 | }; |
| 137 | |
| 138 | TEST_F(WindowManagerTest, Focus) { |
| 139 | // The IME event filter interferes with the basic key event propagation we |
| 140 | // attempt to do here, so we remove it. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 141 | test::ShellTestApi shell_test(Shell::GetInstance()); |
| 142 | Shell::GetInstance()->RemovePreTargetHandler( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 143 | shell_test.input_method_event_filter()); |
| 144 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 145 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 146 | root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); |
| 147 | |
| 148 | // Supplied ids are negative so as not to collide with shell ids. |
| 149 | // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe |
| 150 | // id beyond shell id max? |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 151 | scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
| 152 | SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 153 | scoped_ptr<aura::Window> w11(aura::test::CreateTestWindow( |
| 154 | SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 155 | scoped_ptr<aura::Window> w111(aura::test::CreateTestWindow( |
| 156 | SK_ColorCYAN, -111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 157 | scoped_ptr<aura::Window> w1111(aura::test::CreateTestWindow( |
| 158 | SK_ColorRED, -1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 159 | scoped_ptr<aura::Window> w12(aura::test::CreateTestWindow( |
| 160 | SK_ColorMAGENTA, -12, gfx::Rect(10, 420, 25, 25), w1.get())); |
| 161 | aura::test::ColorTestWindowDelegate* w121delegate = |
| 162 | new aura::test::ColorTestWindowDelegate(SK_ColorYELLOW); |
| 163 | scoped_ptr<aura::Window> w121(aura::test::CreateTestWindowWithDelegate( |
| 164 | w121delegate, -121, gfx::Rect(5, 5, 5, 5), w12.get())); |
| 165 | aura::test::ColorTestWindowDelegate* w122delegate = |
| 166 | new aura::test::ColorTestWindowDelegate(SK_ColorRED); |
| 167 | scoped_ptr<aura::Window> w122(aura::test::CreateTestWindowWithDelegate( |
| 168 | w122delegate, -122, gfx::Rect(10, 5, 5, 5), w12.get())); |
| 169 | aura::test::ColorTestWindowDelegate* w123delegate = |
| 170 | new aura::test::ColorTestWindowDelegate(SK_ColorRED); |
| 171 | scoped_ptr<aura::Window> w123(aura::test::CreateTestWindowWithDelegate( |
| 172 | w123delegate, -123, gfx::Rect(15, 5, 5, 5), w12.get())); |
| 173 | scoped_ptr<aura::Window> w13(aura::test::CreateTestWindow( |
| 174 | SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get())); |
| 175 | |
| 176 | // Click on a sub-window (w121) to focus it. |
| 177 | aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 178 | w121.get()); |
| 179 | generator.ClickLeftButton(); |
| 180 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 181 | aura::client::FocusClient* focus_client = |
| 182 | aura::client::GetFocusClient(w121.get()); |
| 183 | EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 184 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 185 | ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 186 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 187 | // The key press should be sent to the focused sub-window. |
| 188 | ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 189 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&keyev); |
| 190 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 191 | EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); |
| 192 | |
| 193 | // Touch on a sub-window (w122) to focus it. |
| 194 | gfx::Point click_point = w122->bounds().CenterPoint(); |
| 195 | aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point); |
| 196 | ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime()); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 197 | details = dispatcher->OnEventFromSource(&touchev); |
| 198 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 199 | focus_client = aura::client::GetFocusClient(w122.get()); |
| 200 | EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 201 | |
| 202 | // The key press should be sent to the focused sub-window. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 203 | details = dispatcher->OnEventFromSource(&keyev); |
| 204 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 205 | EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); |
| 206 | |
| 207 | // Hiding the focused window will set the focus to its parent if |
| 208 | // it's focusable. |
| 209 | w122->Hide(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 210 | EXPECT_EQ(aura::client::GetFocusClient(w12.get()), |
| 211 | aura::client::GetFocusClient(w122.get())); |
| 212 | EXPECT_EQ(w12.get(), |
| 213 | aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 214 | |
| 215 | // Sets the focus back to w122. |
| 216 | w122->Show(); |
| 217 | w122->Focus(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 218 | EXPECT_EQ(w122.get(), |
| 219 | aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 220 | |
| 221 | // Removing the focused window from parent should set the focus to |
| 222 | // its parent if it's focusable. |
| 223 | w12->RemoveChild(w122.get()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 224 | EXPECT_EQ(NULL, aura::client::GetFocusClient(w122.get())); |
| 225 | EXPECT_EQ(w12.get(), |
| 226 | aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 227 | |
| 228 | // Set the focus to w123, but make the w1 not activatable. |
| 229 | test::TestActivationDelegate activation_delegate(false); |
| 230 | w123->Focus(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 231 | EXPECT_EQ(w123.get(), |
| 232 | aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 233 | aura::client::SetActivationDelegate(w1.get(), &activation_delegate); |
| 234 | |
| 235 | // Hiding the focused window will set the focus to NULL because |
| 236 | // parent window is not focusable. |
| 237 | w123->Hide(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 238 | EXPECT_EQ(aura::client::GetFocusClient(w12.get()), |
| 239 | aura::client::GetFocusClient(w123.get())); |
| 240 | EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 241 | details = dispatcher->OnEventFromSource(&keyev); |
| 242 | EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 243 | |
| 244 | // Set the focus back to w123 |
| 245 | aura::client::SetActivationDelegate(w1.get(), NULL); |
| 246 | w123->Show(); |
| 247 | w123->Focus(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 248 | EXPECT_EQ(w123.get(), |
| 249 | aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 250 | aura::client::SetActivationDelegate(w1.get(), &activation_delegate); |
| 251 | |
| 252 | // Removing the focused window will set the focus to NULL because |
| 253 | // parent window is not focusable. |
| 254 | w12->RemoveChild(w123.get()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 255 | EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 256 | details = dispatcher->OnEventFromSource(&keyev); |
| 257 | EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Various assertion testing for activating windows. |
| 261 | TEST_F(WindowManagerTest, ActivateOnMouse) { |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 262 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 263 | |
| 264 | test::TestActivationDelegate d1; |
| 265 | aura::test::TestWindowDelegate wd; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 266 | scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
| 267 | &wd, -1, gfx::Rect(10, 10, 50, 50))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 268 | d1.SetWindow(w1.get()); |
| 269 | test::TestActivationDelegate d2; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 270 | scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
| 271 | &wd, -2, gfx::Rect(70, 70, 50, 50))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 272 | d2.SetWindow(w2.get()); |
| 273 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 274 | aura::client::FocusClient* focus_client = |
| 275 | aura::client::GetFocusClient(w1.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 276 | |
| 277 | d1.Clear(); |
| 278 | d2.Clear(); |
| 279 | |
| 280 | // Activate window1. |
| 281 | wm::ActivateWindow(w1.get()); |
| 282 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 283 | EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 284 | EXPECT_EQ(1, d1.activated_count()); |
| 285 | EXPECT_EQ(0, d1.lost_active_count()); |
| 286 | d1.Clear(); |
| 287 | |
| 288 | { |
| 289 | // Click on window2. |
| 290 | aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 291 | w2.get()); |
| 292 | generator.ClickLeftButton(); |
| 293 | |
| 294 | // Window2 should have become active. |
| 295 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 296 | EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 297 | EXPECT_EQ(0, d1.activated_count()); |
| 298 | EXPECT_EQ(1, d1.lost_active_count()); |
| 299 | EXPECT_EQ(1, d2.activated_count()); |
| 300 | EXPECT_EQ(0, d2.lost_active_count()); |
| 301 | d1.Clear(); |
| 302 | d2.Clear(); |
| 303 | } |
| 304 | |
| 305 | { |
| 306 | // Click back on window1, but set it up so w1 doesn't activate on click. |
| 307 | aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 308 | w1.get()); |
| 309 | d1.set_activate(false); |
| 310 | generator.ClickLeftButton(); |
| 311 | |
| 312 | // Window2 should still be active and focused. |
| 313 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 314 | EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 315 | EXPECT_EQ(0, d1.activated_count()); |
| 316 | EXPECT_EQ(0, d1.lost_active_count()); |
| 317 | EXPECT_EQ(0, d2.activated_count()); |
| 318 | EXPECT_EQ(0, d2.lost_active_count()); |
| 319 | d1.Clear(); |
| 320 | d2.Clear(); |
| 321 | } |
| 322 | |
| 323 | // Destroy window2, this should make window1 active. |
| 324 | d1.set_activate(true); |
| 325 | w2.reset(); |
| 326 | EXPECT_EQ(0, d2.activated_count()); |
Torne (Richard Coles) | 58537e2 | 2013-09-12 12:10:22 +0100 | [diff] [blame] | 327 | EXPECT_EQ(1, d2.lost_active_count()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 328 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 329 | EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 330 | EXPECT_EQ(1, d1.activated_count()); |
| 331 | EXPECT_EQ(0, d1.lost_active_count()); |
| 332 | |
| 333 | // Clicking an active window with a child shouldn't steal the |
| 334 | // focus from the child. |
| 335 | { |
| 336 | scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 337 | &wd, -11, gfx::Rect(10, 10, 10, 10), w1.get())); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 338 | aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 339 | w11.get()); |
| 340 | // First set the focus to the child |w11|. |
| 341 | generator.ClickLeftButton(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 342 | EXPECT_EQ(w11.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 343 | EXPECT_EQ(w1.get(), wm::GetActiveWindow()); |
| 344 | |
| 345 | // Then click the parent active window. The focus shouldn't move. |
| 346 | gfx::Point left_top = w1->bounds().origin(); |
| 347 | aura::Window::ConvertPointToTarget(w1->parent(), root_window, &left_top); |
| 348 | left_top.Offset(1, 1); |
| 349 | generator.MoveMouseTo(left_top); |
| 350 | generator.ClickLeftButton(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 351 | EXPECT_EQ(w11.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 352 | EXPECT_EQ(w1.get(), wm::GetActiveWindow()); |
| 353 | } |
| 354 | |
| 355 | // Clicking on a non-focusable window inside a background window should still |
| 356 | // give focus to the background window. |
| 357 | { |
| 358 | NonFocusableDelegate nfd; |
| 359 | scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate( |
| 360 | &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get())); |
| 361 | // Move focus to |w2| first. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 362 | scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
| 363 | &wd, -1, gfx::Rect(70, 70, 50, 50))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 364 | aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 365 | w2.get()); |
| 366 | generator.ClickLeftButton(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 367 | EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 368 | EXPECT_FALSE(w11->CanFocus()); |
| 369 | |
| 370 | // Click on |w11|. This should focus w1. |
| 371 | generator.MoveMouseToCenterOf(w11.get()); |
| 372 | generator.ClickLeftButton(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 373 | EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 377 | TEST_F(WindowManagerTest, PanelActivation) { |
| 378 | aura::test::TestWindowDelegate wd; |
| 379 | scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
| 380 | &wd, -1, gfx::Rect(10, 10, 50, 50))); |
| 381 | aura::test::TestWindowDelegate pd; |
| 382 | scoped_ptr<aura::Window> p1(CreateTestWindowInShellWithDelegateAndType( |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 383 | &pd, ui::wm::WINDOW_TYPE_PANEL, -1, gfx::Rect(10, 10, 50, 50))); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 384 | aura::client::FocusClient* focus_client = |
| 385 | aura::client::GetFocusClient(w1.get()); |
| 386 | |
| 387 | // Activate w1. |
| 388 | wm::ActivateWindow(w1.get()); |
| 389 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 390 | |
| 391 | // Activate p1. |
| 392 | wm::ActivateWindow(p1.get()); |
| 393 | EXPECT_TRUE(wm::IsActiveWindow(p1.get())); |
| 394 | EXPECT_EQ(p1.get(), focus_client->GetFocusedWindow()); |
| 395 | |
| 396 | // Activate w1. |
| 397 | wm::ActivateWindow(w1.get()); |
| 398 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 399 | EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
| 400 | |
| 401 | // Clicking on a non-activatable window should not change the active window. |
| 402 | { |
| 403 | NonFocusableDelegate nfd; |
| 404 | scoped_ptr<aura::Window> w3(CreateTestWindowInShellWithDelegate( |
| 405 | &nfd, -1, gfx::Rect(70, 70, 50, 50))); |
| 406 | aura::test::EventGenerator generator3(Shell::GetPrimaryRootWindow(), |
| 407 | w3.get()); |
| 408 | wm::ActivateWindow(p1.get()); |
| 409 | EXPECT_TRUE(wm::IsActiveWindow(p1.get())); |
| 410 | generator3.ClickLeftButton(); |
| 411 | EXPECT_TRUE(wm::IsActiveWindow(p1.get())); |
| 412 | } |
| 413 | } |
| 414 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 415 | // Essentially the same as ActivateOnMouse, but for touch events. |
| 416 | TEST_F(WindowManagerTest, ActivateOnTouch) { |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 417 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 418 | |
| 419 | test::TestActivationDelegate d1; |
| 420 | aura::test::TestWindowDelegate wd; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 421 | scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
| 422 | &wd, -1, gfx::Rect(10, 10, 50, 50))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 423 | d1.SetWindow(w1.get()); |
| 424 | test::TestActivationDelegate d2; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 425 | scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
| 426 | &wd, -2, gfx::Rect(70, 70, 50, 50))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 427 | d2.SetWindow(w2.get()); |
| 428 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 429 | aura::client::FocusClient* focus_client = |
| 430 | aura::client::GetFocusClient(w1.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 431 | |
| 432 | d1.Clear(); |
| 433 | d2.Clear(); |
| 434 | |
| 435 | // Activate window1. |
| 436 | wm::ActivateWindow(w1.get()); |
| 437 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 438 | EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 439 | EXPECT_EQ(1, d1.activated_count()); |
| 440 | EXPECT_EQ(0, d1.lost_active_count()); |
| 441 | d1.Clear(); |
| 442 | |
| 443 | // Touch window2. |
| 444 | gfx::Point press_point = w2->bounds().CenterPoint(); |
| 445 | aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point); |
| 446 | ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime()); |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 447 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 448 | ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 449 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&touchev1); |
| 450 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 451 | |
| 452 | // Window2 should have become active. |
| 453 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 454 | EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 455 | EXPECT_EQ(0, d1.activated_count()); |
| 456 | EXPECT_EQ(1, d1.lost_active_count()); |
| 457 | EXPECT_EQ(1, d2.activated_count()); |
| 458 | EXPECT_EQ(0, d2.lost_active_count()); |
| 459 | d1.Clear(); |
| 460 | d2.Clear(); |
| 461 | |
| 462 | // Touch window1, but set it up so w1 doesn't activate on touch. |
| 463 | press_point = w1->bounds().CenterPoint(); |
| 464 | aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point); |
| 465 | d1.set_activate(false); |
| 466 | ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime()); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 467 | details = dispatcher->OnEventFromSource(&touchev2); |
| 468 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 469 | |
| 470 | // Window2 should still be active and focused. |
| 471 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 472 | EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 473 | EXPECT_EQ(0, d1.activated_count()); |
| 474 | EXPECT_EQ(0, d1.lost_active_count()); |
| 475 | EXPECT_EQ(0, d2.activated_count()); |
| 476 | EXPECT_EQ(0, d2.lost_active_count()); |
| 477 | d1.Clear(); |
| 478 | d2.Clear(); |
| 479 | |
| 480 | // Destroy window2, this should make window1 active. |
| 481 | d1.set_activate(true); |
| 482 | w2.reset(); |
| 483 | EXPECT_EQ(0, d2.activated_count()); |
Torne (Richard Coles) | 58537e2 | 2013-09-12 12:10:22 +0100 | [diff] [blame] | 484 | EXPECT_EQ(1, d2.lost_active_count()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 485 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 486 | EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 487 | EXPECT_EQ(1, d1.activated_count()); |
| 488 | EXPECT_EQ(0, d1.lost_active_count()); |
| 489 | } |
| 490 | |
| 491 | TEST_F(WindowManagerTest, MouseEventCursors) { |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 492 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 493 | |
| 494 | // Create a window. |
| 495 | const int kWindowLeft = 123; |
| 496 | const int kWindowTop = 45; |
| 497 | HitTestWindowDelegate window_delegate; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 498 | scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 499 | &window_delegate, |
| 500 | -1, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 501 | gfx::Rect(kWindowLeft, kWindowTop, 640, 480))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 502 | |
| 503 | // Create two mouse movement events we can switch between. |
| 504 | gfx::Point point1(kWindowLeft, kWindowTop); |
| 505 | aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1); |
| 506 | |
| 507 | gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); |
| 508 | aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2); |
| 509 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 510 | aura::WindowTreeHost* host = root_window->GetHost(); |
| 511 | ui::EventProcessor* dispatcher = host->event_processor(); |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 512 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 513 | // Cursor starts as a pointer (set during Shell::Init()). |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 514 | EXPECT_EQ(ui::kCursorPointer, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 515 | |
| 516 | { |
| 517 | // Resize edges and corners show proper cursors. |
| 518 | window_delegate.set_hittest_code(HTBOTTOM); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 519 | ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); |
| 520 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); |
| 521 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 522 | EXPECT_EQ(ui::kCursorSouthResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | { |
| 526 | window_delegate.set_hittest_code(HTBOTTOMLEFT); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 527 | ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); |
| 528 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); |
| 529 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 530 | EXPECT_EQ(ui::kCursorSouthWestResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | { |
| 534 | window_delegate.set_hittest_code(HTBOTTOMRIGHT); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 535 | ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); |
| 536 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); |
| 537 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 538 | EXPECT_EQ(ui::kCursorSouthEastResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | { |
| 542 | window_delegate.set_hittest_code(HTLEFT); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 543 | ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); |
| 544 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); |
| 545 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 546 | EXPECT_EQ(ui::kCursorWestResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | { |
| 550 | window_delegate.set_hittest_code(HTRIGHT); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 551 | ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); |
| 552 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); |
| 553 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 554 | EXPECT_EQ(ui::kCursorEastResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | { |
| 558 | window_delegate.set_hittest_code(HTTOP); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 559 | ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); |
| 560 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); |
| 561 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 562 | EXPECT_EQ(ui::kCursorNorthResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | { |
| 566 | window_delegate.set_hittest_code(HTTOPLEFT); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 567 | ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); |
| 568 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); |
| 569 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 570 | EXPECT_EQ(ui::kCursorNorthWestResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | { |
| 574 | window_delegate.set_hittest_code(HTTOPRIGHT); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 575 | ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); |
| 576 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); |
| 577 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 578 | EXPECT_EQ(ui::kCursorNorthEastResize, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | { |
| 582 | // Client area uses null cursor. |
| 583 | window_delegate.set_hittest_code(HTCLIENT); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 584 | ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); |
| 585 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); |
| 586 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 587 | EXPECT_EQ(ui::kCursorNull, host->last_cursor().native_type()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 591 | #if defined(OS_WIN) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 592 | #define MAYBE_TransformActivate DISABLED_TransformActivate |
| 593 | #else |
| 594 | #define MAYBE_TransformActivate TransformActivate |
| 595 | #endif |
| 596 | TEST_F(WindowManagerTest, MAYBE_TransformActivate) { |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 597 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 598 | gfx::Size size = root_window->bounds().size(); |
| 599 | EXPECT_EQ(gfx::Rect(size).ToString(), |
| 600 | Shell::GetScreen()->GetDisplayNearestPoint( |
| 601 | gfx::Point()).bounds().ToString()); |
| 602 | |
| 603 | // Rotate it clock-wise 90 degrees. |
| 604 | gfx::Transform transform; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 605 | transform.Translate(size.width(), 0); |
| 606 | transform.Rotate(90.0f); |
Ben Murdoch | a02191e | 2014-04-16 11:17:03 +0100 | [diff] [blame] | 607 | root_window->GetHost()->SetRootTransform(transform); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 608 | |
| 609 | test::TestActivationDelegate d1; |
| 610 | aura::test::TestWindowDelegate wd; |
| 611 | scoped_ptr<aura::Window> w1( |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 612 | CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 15, 50, 50))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 613 | d1.SetWindow(w1.get()); |
| 614 | w1->Show(); |
| 615 | |
| 616 | gfx::Point miss_point(5, 5); |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 617 | transform.TransformPoint(&miss_point); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 618 | ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, |
| 619 | miss_point, |
| 620 | miss_point, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 621 | ui::EF_LEFT_MOUSE_BUTTON, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 622 | ui::EF_LEFT_MOUSE_BUTTON); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 623 | ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 624 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&mouseev1); |
| 625 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 626 | EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 627 | ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, |
| 628 | miss_point, |
| 629 | miss_point, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 630 | ui::EF_LEFT_MOUSE_BUTTON, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 631 | ui::EF_LEFT_MOUSE_BUTTON); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 632 | details = dispatcher->OnEventFromSource(&mouseup); |
| 633 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 634 | |
| 635 | gfx::Point hit_point(5, 15); |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 636 | transform.TransformPoint(&hit_point); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 637 | ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, |
| 638 | hit_point, |
| 639 | hit_point, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 640 | ui::EF_LEFT_MOUSE_BUTTON, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 641 | ui::EF_LEFT_MOUSE_BUTTON); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 642 | details = dispatcher->OnEventFromSource(&mouseev2); |
| 643 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 644 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 645 | EXPECT_EQ(w1.get(), |
| 646 | aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | TEST_F(WindowManagerTest, AdditionalFilters) { |
| 650 | // The IME event filter interferes with the basic key event propagation we |
| 651 | // attempt to do here, so we remove it. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 652 | test::ShellTestApi shell_test(Shell::GetInstance()); |
| 653 | Shell::GetInstance()->RemovePreTargetHandler( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 654 | shell_test.input_method_event_filter()); |
| 655 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 656 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 657 | |
| 658 | // Creates a window and make it active |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 659 | scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
| 660 | SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 661 | wm::ActivateWindow(w1.get()); |
| 662 | |
| 663 | // Creates two addition filters |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 664 | scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); |
| 665 | scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 666 | |
| 667 | // Adds them to root window event filter. |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 668 | ::wm::CompoundEventFilter* env_filter = |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 669 | Shell::GetInstance()->env_filter(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 670 | env_filter->AddHandler(f1.get()); |
| 671 | env_filter->AddHandler(f2.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 672 | |
| 673 | // Dispatches mouse and keyboard events. |
| 674 | ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 675 | ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 676 | ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event); |
| 677 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 678 | ui::MouseEvent mouse_pressed( |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 679 | ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 680 | details = dispatcher->OnEventFromSource(&mouse_pressed); |
| 681 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 682 | |
| 683 | // Both filters should get the events. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 684 | EXPECT_EQ(1, f1->num_key_events()); |
| 685 | EXPECT_EQ(1, f1->num_mouse_events()); |
| 686 | EXPECT_EQ(1, f2->num_key_events()); |
| 687 | EXPECT_EQ(1, f2->num_mouse_events()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 688 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 689 | f1->Reset(); |
| 690 | f2->Reset(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 691 | |
| 692 | // Makes f1 consume events. |
| 693 | f1->set_key_event_handling_result(ui::ER_CONSUMED); |
| 694 | f1->set_mouse_event_handling_result(ui::ER_CONSUMED); |
| 695 | |
| 696 | // Dispatches events. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 697 | details = dispatcher->OnEventFromSource(&key_event); |
| 698 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 699 | ui::MouseEvent mouse_released( |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 700 | ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 701 | details = dispatcher->OnEventFromSource(&mouse_released); |
| 702 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 703 | |
| 704 | // f1 should still get the events but f2 no longer gets them. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 705 | EXPECT_EQ(1, f1->num_key_events()); |
| 706 | EXPECT_EQ(1, f1->num_mouse_events()); |
| 707 | EXPECT_EQ(0, f2->num_key_events()); |
| 708 | EXPECT_EQ(0, f2->num_mouse_events()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 709 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 710 | f1->Reset(); |
| 711 | f2->Reset(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 712 | |
| 713 | // Remove f1 from additonal filters list. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 714 | env_filter->RemoveHandler(f1.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 715 | |
| 716 | // Dispatches events. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 717 | details = dispatcher->OnEventFromSource(&key_event); |
| 718 | ASSERT_FALSE(details.dispatcher_destroyed); |
| 719 | details = dispatcher->OnEventFromSource(&mouse_pressed); |
| 720 | ASSERT_FALSE(details.dispatcher_destroyed); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 721 | |
| 722 | // f1 should get no events since it's out and f2 should get them. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 723 | EXPECT_EQ(0, f1->num_key_events()); |
| 724 | EXPECT_EQ(0, f1->num_mouse_events()); |
| 725 | EXPECT_EQ(1, f2->num_key_events()); |
| 726 | EXPECT_EQ(1, f2->num_mouse_events()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 727 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 728 | env_filter->RemoveHandler(f2.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 731 | #if defined(OS_CHROMEOS) || defined(OS_WIN) |
| 732 | // Touch visually hides the cursor on ChromeOS and Windows |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 733 | TEST_F(WindowManagerTest, UpdateCursorVisibility) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 734 | aura::test::EventGenerator& generator = GetEventGenerator(); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 735 | ::wm::CursorManager* cursor_manager = |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 736 | ash::Shell::GetInstance()->cursor_manager(); |
| 737 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 738 | generator.MoveMouseTo(gfx::Point(0, 0)); |
| 739 | EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 740 | EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 741 | generator.PressTouch(); |
| 742 | EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 743 | EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); |
| 744 | generator.MoveMouseTo(gfx::Point(0, 0)); |
| 745 | EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 746 | EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 747 | generator.ReleaseTouch(); |
| 748 | EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 749 | EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 750 | } |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 751 | #endif // defined(OS_CHROMEOS) || defined(OS_WIN) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 752 | |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 753 | #if defined(OS_CHROMEOS) |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 754 | // ChromeOS is the only platform for which the cursor is hidden on keypress |
| 755 | // (crbug.com/304296). |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 756 | TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { |
| 757 | aura::test::EventGenerator& generator = GetEventGenerator(); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 758 | ::wm::CursorManager* cursor_manager = |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 759 | ash::Shell::GetInstance()->cursor_manager(); |
| 760 | |
| 761 | // Pressing a key hides the cursor but does not disable mouse events. |
| 762 | generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 763 | EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 764 | EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 765 | // Moving mouse shows the cursor. |
| 766 | generator.MoveMouseTo(gfx::Point(0, 0)); |
| 767 | EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 768 | EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 769 | // Releasing a key also hides the cursor but does not disable mouse events. |
| 770 | generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
| 771 | EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 772 | EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 773 | // Moving mouse shows the cursor again. |
| 774 | generator.MoveMouseTo(gfx::Point(0, 0)); |
| 775 | EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 776 | EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 779 | TEST_F(WindowManagerTest, TestCursorClientObserver) { |
| 780 | aura::test::EventGenerator& generator = GetEventGenerator(); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 781 | ::wm::CursorManager* cursor_manager = |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 782 | ash::Shell::GetInstance()->cursor_manager(); |
| 783 | |
| 784 | scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
| 785 | SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
| 786 | wm::ActivateWindow(w1.get()); |
| 787 | |
| 788 | // Add two observers. Both should have OnCursorVisibilityChanged() |
| 789 | // invoked when an event changes the visibility of the cursor. |
| 790 | TestingCursorClientObserver observer_a; |
| 791 | TestingCursorClientObserver observer_b; |
| 792 | cursor_manager->AddObserver(&observer_a); |
| 793 | cursor_manager->AddObserver(&observer_b); |
| 794 | |
| 795 | // Initial state before any events have been sent. |
| 796 | observer_a.reset(); |
| 797 | observer_b.reset(); |
| 798 | EXPECT_FALSE(observer_a.did_visibility_change()); |
| 799 | EXPECT_FALSE(observer_b.did_visibility_change()); |
| 800 | EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 801 | EXPECT_FALSE(observer_b.is_cursor_visible()); |
| 802 | |
| 803 | // Keypress should hide the cursor. |
| 804 | generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 805 | EXPECT_TRUE(observer_a.did_visibility_change()); |
| 806 | EXPECT_TRUE(observer_b.did_visibility_change()); |
| 807 | EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 808 | EXPECT_FALSE(observer_b.is_cursor_visible()); |
| 809 | |
| 810 | // Mouse move should show the cursor. |
| 811 | observer_a.reset(); |
| 812 | observer_b.reset(); |
| 813 | generator.MoveMouseTo(50, 50); |
| 814 | EXPECT_TRUE(observer_a.did_visibility_change()); |
| 815 | EXPECT_TRUE(observer_b.did_visibility_change()); |
| 816 | EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 817 | EXPECT_TRUE(observer_b.is_cursor_visible()); |
| 818 | |
| 819 | // Remove observer_b. Its OnCursorVisibilityChanged() should |
| 820 | // not be invoked past this point. |
| 821 | cursor_manager->RemoveObserver(&observer_b); |
| 822 | |
| 823 | // Gesture tap should hide the cursor. |
| 824 | observer_a.reset(); |
| 825 | observer_b.reset(); |
| 826 | generator.GestureTapAt(gfx::Point(25, 25)); |
| 827 | EXPECT_TRUE(observer_a.did_visibility_change()); |
| 828 | EXPECT_FALSE(observer_b.did_visibility_change()); |
| 829 | EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 830 | |
| 831 | // Mouse move should show the cursor. |
| 832 | observer_a.reset(); |
| 833 | observer_b.reset(); |
| 834 | generator.MoveMouseTo(50, 50); |
| 835 | EXPECT_TRUE(observer_a.did_visibility_change()); |
| 836 | EXPECT_FALSE(observer_b.did_visibility_change()); |
| 837 | EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 838 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 839 | #endif // defined(OS_CHROMEOS) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 840 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 841 | } // namespace ash |