OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 "base/basictypes.h" |
| 6 #include "ui/views/widget/widget.h" |
| 7 |
| 8 #if defined(USE_AURA) |
| 9 #include "ui/aura/client/activation_client.h" |
| 10 #include "ui/aura/root_window.h" |
| 11 #include "ui/views/test/views_test_base.h" |
| 12 #if !defined(OS_CHROMEOS) |
| 13 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 14 #endif |
| 15 #endif |
| 16 |
| 17 namespace views { |
| 18 |
| 19 #if defined(OS_WIN) && defined(USE_AURA) |
| 20 // Tests whether activation and focus change works correctly in Windows AURA. |
| 21 // We test the following:- |
| 22 // 1. If the active aura window is correctly set when a top level widget is |
| 23 // created. |
| 24 // 2. If the active aura window in widget 1 created above, is set to NULL when |
| 25 // another top level widget is created and focused. |
| 26 // 3. On focusing the native platform window for widget 1, the active aura |
| 27 // window for widget 1 should be set and that for widget 2 should reset. |
| 28 // TODO(ananta) |
| 29 // Discuss with erg on how to write this test for linux x11 aura. |
| 30 TEST_F(ViewsTestBase, DesktopNativeWidgetAuraActivationAndFocusTest) { |
| 31 // Create widget 1 and expect the active window to be its window. |
| 32 View* contents_view1 = new View; |
| 33 contents_view1->set_focusable(true); |
| 34 Widget widget1; |
| 35 Widget::InitParams init_params = |
| 36 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 37 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 38 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 39 init_params.native_widget = new DesktopNativeWidgetAura(&widget1); |
| 40 widget1.Init(init_params); |
| 41 widget1.SetContentsView(contents_view1); |
| 42 widget1.Show(); |
| 43 aura::RootWindow* root_window1= widget1.GetNativeView()->GetRootWindow(); |
| 44 contents_view1->RequestFocus(); |
| 45 |
| 46 EXPECT_TRUE(root_window1 != NULL); |
| 47 aura::client::ActivationClient* activation_client1 = |
| 48 aura::client::GetActivationClient(root_window1); |
| 49 EXPECT_TRUE(activation_client1 != NULL); |
| 50 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); |
| 51 |
| 52 // Create widget 2 and expect the active window to be its window. |
| 53 View* contents_view2 = new View; |
| 54 Widget widget2; |
| 55 Widget::InitParams init_params2 = |
| 56 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 57 init_params2.bounds = gfx::Rect(0, 0, 200, 200); |
| 58 init_params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 59 init_params2.native_widget = new DesktopNativeWidgetAura(&widget2); |
| 60 widget2.Init(init_params2); |
| 61 widget2.SetContentsView(contents_view2); |
| 62 widget2.Show(); |
| 63 aura::RootWindow* root_window2 = widget2.GetNativeView()->GetRootWindow(); |
| 64 contents_view2->RequestFocus(); |
| 65 ::SetActiveWindow(root_window2->GetAcceleratedWidget()); |
| 66 |
| 67 aura::client::ActivationClient* activation_client2 = |
| 68 aura::client::GetActivationClient(root_window2); |
| 69 EXPECT_TRUE(activation_client2 != NULL); |
| 70 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView()); |
| 71 EXPECT_EQ(activation_client1->GetActiveWindow(), |
| 72 reinterpret_cast<aura::Window*>(NULL)); |
| 73 |
| 74 // Now set focus back to widget 1 and expect the active window to be its |
| 75 // window. |
| 76 contents_view1->RequestFocus(); |
| 77 ::SetActiveWindow(root_window1->GetAcceleratedWidget()); |
| 78 EXPECT_EQ(activation_client2->GetActiveWindow(), |
| 79 reinterpret_cast<aura::Window*>(NULL)); |
| 80 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); |
| 81 } |
| 82 #endif |
| 83 |
| 84 } // namespace views |
OLD | NEW |