Chromium Code Reviews| Index: ui/views/widget/widget_unittest.cc |
| =================================================================== |
| --- ui/views/widget/widget_unittest.cc (revision 220608) |
| +++ ui/views/widget/widget_unittest.cc (working copy) |
| @@ -25,6 +25,7 @@ |
| #include "ui/views/window/native_frame_view.h" |
| #if defined(USE_AURA) |
| +#include "ui/aura/client/activation_client.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/env.h" |
| #include "ui/aura/root_window.h" |
| @@ -2383,5 +2384,69 @@ |
| EXPECT_TRUE(std::equal(expected.begin(), expected.end(), widgets.begin())); |
| } |
| +#if defined(OS_WIN) && defined(USE_AURA) |
|
sky
2013/09/03 18:21:51
Since this changes focus it needs to be an interac
ananta
2013/09/03 19:03:31
As per our discussion, focus is a thread specific
|
| +// Tests whether activation and focus change works correctly in Windows AURA. |
| +// We test the following:- |
| +// 1. If the active aura window is correctly set when a top level widget is |
| +// created. |
| +// 2. If the active aura window in widget 1 created above, is set to NULL when |
| +// another top level widget is created and focused. |
| +// 3. On focusing the native platform window for widget 1, the active aura |
| +// window for widget 1 should be set and that for widget 2 should reset. |
| +// TODO(ananta) |
| +// Discuss with erg on how to write this test for linux x11 aura. |
| +TEST_F(WidgetTest, DesktopNativeWidgetAuraActivationAndFocusTest) { |
| + // Create widget 1 and expect the active window to be its window. |
| + View* contents_view1 = new View; |
| + contents_view1->set_focusable(true); |
| + Widget widget1; |
| + Widget::InitParams init_params = |
| + CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| + init_params.bounds = gfx::Rect(0, 0, 200, 200); |
| + init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| + init_params.native_widget = new DesktopNativeWidgetAura(&widget1); |
| + widget1.Init(init_params); |
| + widget1.SetContentsView(contents_view1); |
| + widget1.Show(); |
| + contents_view1->RequestFocus(); |
| + |
| + aura::RootWindow* root_window1= widget1.GetNativeView()->GetRootWindow(); |
| + EXPECT_TRUE(root_window1 != NULL); |
| + aura::client::ActivationClient* activation_client1 = |
| + aura::client::GetActivationClient(root_window1); |
| + EXPECT_TRUE(activation_client1 != NULL); |
| + EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); |
| + |
| + // Create widget 2 and expect the active window to be its window. |
| + View* contents_view2 = new View; |
| + Widget widget2; |
| + Widget::InitParams init_params2 = |
| + CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| + init_params2.bounds = gfx::Rect(0, 0, 200, 200); |
| + init_params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| + init_params2.native_widget = new DesktopNativeWidgetAura(&widget2); |
| + widget2.Init(init_params2); |
| + widget2.SetContentsView(contents_view2); |
| + widget2.Show(); |
| + contents_view2->RequestFocus(); |
| + |
| + aura::RootWindow* root_window2 = widget2.GetNativeView()->GetRootWindow(); |
| + aura::client::ActivationClient* activation_client2 = |
| + aura::client::GetActivationClient(root_window2); |
| + EXPECT_TRUE(activation_client2 != NULL); |
| + EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView()); |
| + EXPECT_EQ(activation_client1->GetActiveWindow(), |
| + reinterpret_cast<aura::Window*>(NULL)); |
| + |
| + // Now set focus back to widget 1 and expect the active window to be its |
| + // window. |
| + ::SetForegroundWindow(root_window1->GetAcceleratedWidget()); |
| + contents_view1->RequestFocus(); |
| + EXPECT_EQ(activation_client2->GetActiveWindow(), |
| + reinterpret_cast<aura::Window*>(NULL)); |
| + EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); |
| +} |
| +#endif |
| + |
| } // namespace test |
| } // namespace views |