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/accelerators/accelerator_controller.h" | |
| 5 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 6 #include "ash/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
| 7 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 8 #include "base/bind.h" | 9 #include "base/bind.h" |
| 9 #include "base/event_types.h" | 10 #include "base/event_types.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "ui/aura/client/dispatcher_client.h" | 12 #include "ui/aura/client/dispatcher_client.h" |
| 12 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/base/accelerators/accelerator.h" | |
| 15 | 17 |
| 16 #if defined(USE_X11) | 18 #if defined(USE_X11) |
| 17 #include <X11/Xlib.h> | 19 #include <X11/Xlib.h> |
| 18 #include "ui/base/x/x11_util.h" | 20 #include "ui/base/x/x11_util.h" |
| 19 #endif // USE_X11 | 21 #endif // USE_X11 |
| 20 | 22 |
| 21 namespace ash { | 23 namespace ash { |
| 22 namespace test { | 24 namespace test { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 43 num_key_events_dispatched_++; | 45 num_key_events_dispatched_++; |
| 44 return ui::IsNoopEvent(xev) ? MessagePumpDispatcher::EVENT_QUIT : | 46 return ui::IsNoopEvent(xev) ? MessagePumpDispatcher::EVENT_QUIT : |
| 45 MessagePumpDispatcher::EVENT_IGNORED; | 47 MessagePumpDispatcher::EVENT_IGNORED; |
| 46 } | 48 } |
| 47 #endif | 49 #endif |
| 48 | 50 |
| 49 private: | 51 private: |
| 50 int num_key_events_dispatched_; | 52 int num_key_events_dispatched_; |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 void DispatchKeyEvent() { | 55 class TestTarget : public ui::AcceleratorTarget { |
| 56 public: | |
| 57 TestTarget() : accelerator_pressed_count_(0) {}; | |
|
sky
2012/02/29 22:04:18
nit: no ; here and next line.
| |
| 58 virtual ~TestTarget() {}; | |
| 59 | |
| 60 int accelerator_pressed_count() const { | |
| 61 return accelerator_pressed_count_; | |
| 62 } | |
| 63 | |
| 64 // Overridden from ui::AcceleratorTarget: | |
| 65 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { | |
| 66 accelerator_pressed_count_++; | |
| 67 return true; | |
| 68 } | |
| 69 virtual bool CanHandleAccelerators() const OVERRIDE { | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 int accelerator_pressed_count_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(TestTarget); | |
| 77 }; | |
| 78 | |
| 79 void DispatchKeyReleaseA() { | |
| 54 #if defined(OS_WIN) | 80 #if defined(OS_WIN) |
| 55 MSG native_event = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; | 81 MSG native_event = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; |
| 56 ash::Shell::GetRootWindow()->PostNativeEvent(native_event); | 82 ash::Shell::GetRootWindow()->PostNativeEvent(native_event); |
| 57 #elif defined(USE_X11) | 83 #elif defined(USE_X11) |
| 58 XEvent native_event; | 84 XEvent native_event; |
| 59 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED, | 85 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED, |
| 60 ui::VKEY_A, | 86 ui::VKEY_A, |
| 61 0, | 87 0, |
| 62 &native_event); | 88 &native_event); |
| 63 ash::Shell::GetRootWindow()->PostNativeEvent(&native_event); | 89 ash::Shell::GetRootWindow()->PostNativeEvent(&native_event); |
| 64 #endif | 90 #endif |
| 65 | 91 |
| 66 // Send noop event to signal dispatcher to exit. | 92 // Send noop event to signal dispatcher to exit. |
| 67 ash::Shell::GetRootWindow()->PostNativeEvent(ui::CreateNoopEvent()); | 93 ash::Shell::GetRootWindow()->PostNativeEvent(ui::CreateNoopEvent()); |
| 68 } | 94 } |
| 69 | 95 |
| 70 } // namespace | 96 } // namespace |
| 71 | 97 |
| 72 typedef AshTestBase NestedDispatcherTest; | 98 typedef AshTestBase NestedDispatcherTest; |
| 73 | 99 |
| 74 // Aura window below lock screen in z order. | 100 // Aura window below lock screen in z order. |
| 75 TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { | 101 TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) { |
| 76 MockDispatcher inner_dispatcher; | 102 MockDispatcher inner_dispatcher; |
| 77 aura::Window* default_container = Shell::GetInstance()->GetContainer( | 103 aura::Window* default_container = Shell::GetInstance()->GetContainer( |
| 78 ash::internal::kShellWindowId_DefaultContainer); | 104 internal::kShellWindowId_DefaultContainer); |
| 79 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( | 105 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( |
| 80 0, default_container)); | 106 0, default_container)); |
| 81 scoped_ptr<aura::Window>mock_lock_container( | 107 scoped_ptr<aura::Window>mock_lock_container( |
| 82 aura::test::CreateTestWindowWithId(0, default_container)); | 108 aura::test::CreateTestWindowWithId(0, default_container)); |
| 83 mock_lock_container->set_stops_event_propagation(true); | 109 mock_lock_container->set_stops_event_propagation(true); |
| 84 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); | 110 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); |
| 85 EXPECT_TRUE(aura::test::WindowIsAbove(mock_lock_container.get(), | 111 EXPECT_TRUE(aura::test::WindowIsAbove(mock_lock_container.get(), |
| 86 associated_window.get())); | 112 associated_window.get())); |
| 87 MessageLoop::current()->PostDelayedTask( | 113 MessageLoop::current()->PostDelayedTask( |
| 88 FROM_HERE, | 114 FROM_HERE, |
| 89 base::Bind(&DispatchKeyEvent), | 115 base::Bind(&DispatchKeyReleaseA), |
| 90 base::TimeDelta::FromMilliseconds(100)); | 116 base::TimeDelta::FromMilliseconds(100)); |
| 91 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); | 117 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); |
| 92 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 118 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
| 93 &inner_dispatcher, | 119 &inner_dispatcher, |
| 94 associated_window.get(), | 120 associated_window.get(), |
| 95 true /* nestable_tasks_allowed */); | 121 true /* nestable_tasks_allowed */); |
| 96 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | 122 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
| 97 } | 123 } |
| 98 | 124 |
| 99 // Aura window above lock screen in z order. | 125 // Aura window above lock screen in z order. |
| 100 TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { | 126 TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) { |
| 101 MockDispatcher inner_dispatcher; | 127 MockDispatcher inner_dispatcher; |
| 102 | 128 |
| 103 aura::Window* default_container = Shell::GetInstance()->GetContainer( | 129 aura::Window* default_container = Shell::GetInstance()->GetContainer( |
| 104 ash::internal::kShellWindowId_DefaultContainer); | 130 internal::kShellWindowId_DefaultContainer); |
| 105 scoped_ptr<aura::Window>mock_lock_container( | 131 scoped_ptr<aura::Window>mock_lock_container( |
| 106 aura::test::CreateTestWindowWithId(0, default_container)); | 132 aura::test::CreateTestWindowWithId(0, default_container)); |
| 107 mock_lock_container->set_stops_event_propagation(true); | 133 mock_lock_container->set_stops_event_propagation(true); |
| 108 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); | 134 aura::test::CreateTestWindowWithId(0, mock_lock_container.get()); |
| 109 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( | 135 scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId( |
| 110 0, default_container)); | 136 0, default_container)); |
| 111 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), | 137 EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(), |
| 112 mock_lock_container.get())); | 138 mock_lock_container.get())); |
| 113 | 139 |
| 114 MessageLoop::current()->PostDelayedTask( | 140 MessageLoop::current()->PostDelayedTask( |
| 115 FROM_HERE, | 141 FROM_HERE, |
| 116 base::Bind(&DispatchKeyEvent), | 142 base::Bind(&DispatchKeyReleaseA), |
| 117 base::TimeDelta::FromMilliseconds(100)); | 143 base::TimeDelta::FromMilliseconds(100)); |
| 118 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); | 144 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); |
| 119 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | 145 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( |
| 120 &inner_dispatcher, | 146 &inner_dispatcher, |
| 121 associated_window.get(), | 147 associated_window.get(), |
| 122 true /* nestable_tasks_allowed */); | 148 true /* nestable_tasks_allowed */); |
| 123 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); | 149 EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched()); |
| 124 } | 150 } |
| 125 | 151 |
| 152 // Test that the nested dispatcher handles accelerators. | |
| 153 TEST_F(NestedDispatcherTest, AcceleratorsHandled) { | |
| 154 MockDispatcher inner_dispatcher; | |
| 155 aura::RootWindow* root_window = ash::Shell::GetInstance()->GetRootWindow(); | |
| 156 | |
| 157 ui::Accelerator accelerator(ui::VKEY_A, false, false, false); | |
| 158 accelerator.set_type(ui::ET_TRANSLATED_KEY_RELEASE); | |
| 159 TestTarget target; | |
| 160 Shell::GetInstance()->accelerator_controller()->Register(accelerator, | |
| 161 &target); | |
| 162 | |
| 163 MessageLoop::current()->PostDelayedTask( | |
| 164 FROM_HERE, | |
| 165 base::Bind(&DispatchKeyReleaseA), | |
| 166 base::TimeDelta::FromMilliseconds(100)); | |
|
sky
2012/02/29 22:04:18
Why does this need to delay 100ms? Can't it use Po
pkotwicz
2012/03/01 23:56:37
The delay is arbitrary. However, I beleive the del
oshima
2012/03/02 00:12:21
Sorry I missed this in first review.
On 2012/03/0
| |
| 167 aura::client::GetDispatcherClient(root_window)->RunWithDispatcher( | |
| 168 &inner_dispatcher, | |
| 169 root_window, | |
| 170 true /* nestable_tasks_allowed */); | |
| 171 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | |
| 172 EXPECT_EQ(1, target.accelerator_pressed_count()); | |
| 173 } | |
| 174 | |
| 126 } // namespace test | 175 } // namespace test |
| 127 } // namespace ash | 176 } // namespace ash |
| OLD | NEW |