| Index: ui/aura_shell/input_method_event_filter_unittest.cc
|
| diff --git a/ui/aura_shell/input_method_event_filter_unittest.cc b/ui/aura_shell/input_method_event_filter_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3c5ff08b45db8ca167ddcd0f842f190f16bf29f3
|
| --- /dev/null
|
| +++ b/ui/aura_shell/input_method_event_filter_unittest.cc
|
| @@ -0,0 +1,90 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/aura_shell/input_method_event_filter.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| +#include "ui/aura/root_window.h"
|
| +#include "ui/aura/test/aura_test_base.h"
|
| +#include "ui/aura/test/event_generator.h"
|
| +#include "ui/aura/test/test_event_filter.h"
|
| +#include "ui/aura/test/test_windows.h"
|
| +#include "ui/aura_shell/root_window_event_filter.h"
|
| +#include "ui/aura_shell/shell.h"
|
| +#include "ui/aura_shell/shell_window_ids.h"
|
| +#include "ui/aura_shell/test/aura_shell_test_base.h"
|
| +#include "ui/aura_shell/window_util.h"
|
| +
|
| +#if !defined(OS_WIN) && !defined(USE_X11)
|
| +// On platforms except Windows and X11, aura::test::EventGenerator::PressKey
|
| +// generates a key event without native_event(), which is not supported by
|
| +// ui::MockInputMethod.
|
| +#define TestInputMethodKeyEventPropagation \
|
| +DISABLED_TestInputMethodKeyEventPropagation
|
| +#endif
|
| +
|
| +namespace aura_shell {
|
| +namespace test {
|
| +
|
| +typedef aura::test::AuraTestBase InputMethodEventFilterTestWithoutShell;
|
| +typedef AuraShellTestBase InputMethodEventFilterTest;
|
| +
|
| +// Tests if InputMethodEventFilter adds/removes a window property on its
|
| +// construction/destruction.
|
| +TEST_F(InputMethodEventFilterTestWithoutShell, TestInputMethodProperty) {
|
| + aura::RootWindow* root_window = aura::RootWindow::GetInstance();
|
| + internal::RootWindowEventFilter* root_filter =
|
| + new internal::RootWindowEventFilter;
|
| +
|
| + EXPECT_FALSE(root_window->GetProperty(aura::kRootWindowInputMethod));
|
| + {
|
| + internal::InputMethodEventFilter ime_filter;
|
| + root_filter->AddFilter(&ime_filter);
|
| + EXPECT_TRUE(root_window->GetProperty(aura::kRootWindowInputMethod));
|
| + root_filter->RemoveFilter(&ime_filter);
|
| + }
|
| + EXPECT_FALSE(root_window->GetProperty(aura::kRootWindowInputMethod));
|
| +}
|
| +
|
| +// Tests if InputMethodEventFilter dispatches a ui::ET_TRANSLATED_KEY_* event to
|
| +// the root window.
|
| +TEST_F(InputMethodEventFilterTest, TestInputMethodKeyEventPropagation) {
|
| + aura::RootWindow* root_window = aura::RootWindow::GetInstance();
|
| +
|
| + // Add TestEventFilter to the RootWindow.
|
| + aura::test::TestEventFilter test_filter(root_window);
|
| + internal::RootWindowEventFilter* root_filter =
|
| + static_cast<internal::RootWindowEventFilter*>(
|
| + root_window->event_filter());
|
| + ASSERT_TRUE(root_filter);
|
| + root_filter->AddFilter(&test_filter);
|
| +
|
| + // We need an active window. Otherwise, the root window will not forward a key
|
| + // event to event filters.
|
| + aura::Window* default_container = Shell::GetInstance()->GetContainer(
|
| + internal::kShellWindowId_DefaultContainer);
|
| + aura::Window* window = aura::test::CreateTestWindowWithDelegate(
|
| + new aura::test::TestWindowDelegate,
|
| + -1,
|
| + gfx::Rect(),
|
| + default_container);
|
| + ActivateWindow(window);
|
| +
|
| + // Send a fake key event to the root window. InputMethodEventFilter, which is
|
| + // automatically set up by AuraShellTestBase, consumes it and sends a new
|
| + // ui::ET_TRANSLATED_KEY_* event to the root window, which will be consumed by
|
| + // the test event filter.
|
| + aura::test::EventGenerator generator_;
|
| + EXPECT_EQ(0, test_filter.key_event_count());
|
| + generator_.PressKey(ui::VKEY_SPACE, 0);
|
| + EXPECT_EQ(1, test_filter.key_event_count());
|
| + generator_.ReleaseKey(ui::VKEY_SPACE, 0);
|
| + EXPECT_EQ(2, test_filter.key_event_count());
|
| +
|
| + root_filter->RemoveFilter(&test_filter);
|
| +}
|
| +
|
| +} // namespace test
|
| +} // namespace aura_shell
|
|
|