Commit 47dfc956 authored by ben@chromium.org's avatar ben@chromium.org

Enable FocusManager tests for Aura.

- Now building the file!
- Disable some tests that only work on Windows.
- Remove some dead Gtk code.

http://crbug.com/102572
TEST=unittests
Review URL: http://codereview.chromium.org/8642002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111220 0039d316-1c4b-4281-b951-d872f2087c98
parent ace7ca0c
......@@ -384,10 +384,6 @@ ui::AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator(
return accelerator_manager_->GetCurrentTarget(accelerator);
}
void FocusManager::FocusNativeView(gfx::NativeView native_view) {
widget_->FocusNativeView(native_view);
}
// static
bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) {
return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown();
......
......@@ -230,9 +230,6 @@ class VIEWS_EXPORT FocusManager {
ui::AcceleratorTarget* GetCurrentTargetForAccelerator(
const ui::Accelerator& accelertor) const;
// Sets the focus to the specified native view.
virtual void FocusNativeView(gfx::NativeView native_view);
// Clears the native view having the focus.
virtual void ClearNativeFocus();
......
// 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/views/focus/focus_manager_test.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/widget/widget.h"
namespace views {
////////////////////////////////////////////////////////////////////////////////
// FocusManagerTest, public:
FocusManagerTest::FocusManagerTest()
: contents_view_(new View),
focus_change_listener_(NULL) {
}
FocusManagerTest::~FocusManagerTest() {
}
FocusManager* FocusManagerTest::GetFocusManager() {
return GetWidget()->GetFocusManager();
}
////////////////////////////////////////////////////////////////////////////////
// FocusManagerTest, ViewTestBase overrides:
void FocusManagerTest::SetUp() {
ViewsTestBase::SetUp();
Widget* widget =
Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 1024, 768));
InitContentView();
widget->Show();
}
void FocusManagerTest::TearDown() {
if (focus_change_listener_)
GetFocusManager()->RemoveFocusChangeListener(focus_change_listener_);
GetWidget()->Close();
// Flush the message loop to make application verifiers happy.
RunPendingMessages();
ViewsTestBase::TearDown();
}
////////////////////////////////////////////////////////////////////////////////
// FocusManagerTest, WidgetDelegate implementation:
View* FocusManagerTest::GetContentsView() {
return contents_view_;
}
Widget* FocusManagerTest::GetWidget() {
return contents_view_->GetWidget();
}
const Widget* FocusManagerTest::GetWidget() const {
return contents_view_->GetWidget();
}
////////////////////////////////////////////////////////////////////////////////
// FocusManagerTest, protected:
void FocusManagerTest::InitContentView() {
}
void FocusManagerTest::AddFocusChangeListener(FocusChangeListener* listener) {
ASSERT_FALSE(focus_change_listener_);
focus_change_listener_ = listener;
GetFocusManager()->AddFocusChangeListener(listener);
}
#if defined(OS_WIN) && !defined(USE_AURA)
void FocusManagerTest::SimulateActivateWindow() {
SendMessage(GetWidget()->GetNativeWindow(), WM_ACTIVATE, WA_ACTIVE, NULL);
}
void FocusManagerTest::SimulateDeactivateWindow() {
SendMessage(GetWidget()->GetNativeWindow(), WM_ACTIVATE, WA_INACTIVE, NULL);
}
void FocusManagerTest::PostKeyDown(ui::KeyboardCode key_code) {
PostMessage(GetWidget()->GetNativeView(), WM_KEYDOWN, key_code, 0);
}
void FocusManagerTest::PostKeyUp(ui::KeyboardCode key_code) {
PostMessage(GetWidget()->GetNativeView(), WM_KEYUP, key_code, 0);
}
#endif
////////////////////////////////////////////////////////////////////////////////
// TestFocusChangeListener
TestFocusChangeListener::TestFocusChangeListener() {
}
TestFocusChangeListener::~TestFocusChangeListener() {
}
void TestFocusChangeListener::OnWillChangeFocus(View* focused_before,
View* focused_now) {
focus_changes_.push_back(ViewPair(focused_before, focused_now));
}
void TestFocusChangeListener::OnDidChangeFocus(View* focused_before,
View* focused_now) {
}
void TestFocusChangeListener::ClearFocusChanges() {
focus_changes_.clear();
}
} // namespace views
// 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.
#ifndef UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_
#define UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_
#include "ui/views/focus/focus_manager.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget_delegate.h"
namespace views {
class FocusChangeListener;
class FocusManagerTest : public ViewsTestBase,
public WidgetDelegate {
public:
FocusManagerTest();
virtual ~FocusManagerTest();
// Convenience to obtain the focus manager for the test's hosting widget.
FocusManager* GetFocusManager();
// Overridden from ViewsTestBase:
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
// Overridden from WidgetDelegate:
virtual View* GetContentsView() OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
virtual const Widget* GetWidget() const OVERRIDE;
protected:
// Called after the Widget is initialized and the content view is added.
// Override to add controls to the layout.
virtual void InitContentView();
void AddFocusChangeListener(FocusChangeListener* listener);
#if defined(OS_WIN) && !defined(USE_AURA)
// Mocks activating/deactivating the window.
void SimulateActivateWindow();
void SimulateDeactivateWindow();
void PostKeyDown(ui::KeyboardCode key_code);
void PostKeyUp(ui::KeyboardCode key_code);
#endif
private:
View* contents_view_;
FocusChangeListener* focus_change_listener_;
DISALLOW_COPY_AND_ASSIGN(FocusManagerTest);
};
typedef std::pair<View*, View*> ViewPair;
// Use to record focus change notifications.
class TestFocusChangeListener : public FocusChangeListener {
public:
TestFocusChangeListener();
virtual ~TestFocusChangeListener();
const std::vector<ViewPair>& focus_changes() const { return focus_changes_; }
void ClearFocusChanges();
// Overridden from FocusChangeListener:
virtual void OnWillChangeFocus(View* focused_before,
View* focused_now) OVERRIDE;
virtual void OnDidChangeFocus(View* focused_before,
View* focused_now) OVERRIDE;
private:
// A vector of which views lost/gained focus.
std::vector<ViewPair> focus_changes_;
DISALLOW_COPY_AND_ASSIGN(TestFocusChangeListener);
};
} // namespace views
#endif // UI_VIEWS_FOCUS_FOCUS_MANAGER_TEST_H_
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -510,8 +510,7 @@ void NativeWidgetAura::ClearNativeFocus() {
}
void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) {
// http://crbug.com/102572
NOTIMPLEMENTED();
window_->GetFocusManager()->SetFocusedWindow(native_view);
}
gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const {
......
......@@ -526,7 +526,11 @@
'../ui/views/bubble/bubble_frame_view_unittest.cc',
'../ui/views/events/event_unittest.cc',
'../ui/views/focus/accelerator_handler_gtk_unittest.cc',
'../ui/views/focus/focus_manager_test.h',
'../ui/views/focus/focus_manager_test.cc',
'../ui/views/focus/focus_manager_unittest.cc',
'../ui/views/focus/focus_manager_unittest_win.cc',
'../ui/views/focus/focus_traversal_unittest.cc',
'../ui/views/layout/box_layout_unittest.cc',
'../ui/views/layout/grid_layout_unittest.cc',
'../ui/views/touchui/touch_selection_controller_impl_unittest.cc',
......@@ -600,7 +604,6 @@
'../ui/aura/aura.gyp:test_support_aura',
],
'sources/': [
['exclude', '../ui/views/focus/focus_manager_unittest.cc'], # TODO(beng):
['exclude', 'controls/combobox/native_combobox_views_unittest.cc'],
['exclude', 'controls/table/table_view_unittest.cc'],
['exclude', 'controls/tabbed_pane/tabbed_pane_unittest.cc'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment