Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 23702017: Ensure that the AURA focused window is set correctly when the window is activated. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/events/event_utils.h" 15 #include "ui/base/events/event_utils.h"
16 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/gfx/point.h" 17 #include "ui/gfx/point.h"
18 #include "ui/views/bubble/bubble_delegate.h" 18 #include "ui/views/bubble/bubble_delegate.h"
19 #include "ui/views/controls/textfield/textfield.h" 19 #include "ui/views/controls/textfield/textfield.h"
20 #include "ui/views/test/test_views_delegate.h" 20 #include "ui/views/test/test_views_delegate.h"
21 #include "ui/views/test/views_test_base.h" 21 #include "ui/views/test/views_test_base.h"
22 #include "ui/views/views_delegate.h" 22 #include "ui/views/views_delegate.h"
23 #include "ui/views/widget/native_widget_delegate.h" 23 #include "ui/views/widget/native_widget_delegate.h"
24 #include "ui/views/widget/root_view.h" 24 #include "ui/views/widget/root_view.h"
25 #include "ui/views/window/native_frame_view.h" 25 #include "ui/views/window/native_frame_view.h"
26 26
27 #if defined(USE_AURA) 27 #if defined(USE_AURA)
28 #include "ui/aura/client/activation_client.h"
28 #include "ui/aura/client/aura_constants.h" 29 #include "ui/aura/client/aura_constants.h"
29 #include "ui/aura/env.h" 30 #include "ui/aura/env.h"
30 #include "ui/aura/root_window.h" 31 #include "ui/aura/root_window.h"
31 #include "ui/aura/test/test_cursor_client.h" 32 #include "ui/aura/test/test_cursor_client.h"
32 #include "ui/aura/test/test_window_delegate.h" 33 #include "ui/aura/test/test_window_delegate.h"
33 #include "ui/aura/window.h" 34 #include "ui/aura/window.h"
34 #include "ui/views/widget/native_widget_aura.h" 35 #include "ui/views/widget/native_widget_aura.h"
35 #if !defined(OS_CHROMEOS) 36 #if !defined(OS_CHROMEOS)
36 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 37 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
37 #endif 38 #endif
(...skipping 2338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 expected.insert(w21); 2377 expected.insert(w21);
2377 expected.insert(w22); 2378 expected.insert(w22);
2378 2379
2379 std::set<Widget*> widgets; 2380 std::set<Widget*> widgets;
2380 Widget::GetAllChildWidgets(toplevel->GetNativeView(), &widgets); 2381 Widget::GetAllChildWidgets(toplevel->GetNativeView(), &widgets);
2381 2382
2382 EXPECT_EQ(expected.size(), widgets.size()); 2383 EXPECT_EQ(expected.size(), widgets.size());
2383 EXPECT_TRUE(std::equal(expected.begin(), expected.end(), widgets.begin())); 2384 EXPECT_TRUE(std::equal(expected.begin(), expected.end(), widgets.begin()));
2384 } 2385 }
2385 2386
2387 #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
2388 // Tests whether activation and focus change works correctly in Windows AURA.
2389 // We test the following:-
2390 // 1. If the active aura window is correctly set when a top level widget is
2391 // created.
2392 // 2. If the active aura window in widget 1 created above, is set to NULL when
2393 // another top level widget is created and focused.
2394 // 3. On focusing the native platform window for widget 1, the active aura
2395 // window for widget 1 should be set and that for widget 2 should reset.
2396 // TODO(ananta)
2397 // Discuss with erg on how to write this test for linux x11 aura.
2398 TEST_F(WidgetTest, DesktopNativeWidgetAuraActivationAndFocusTest) {
2399 // Create widget 1 and expect the active window to be its window.
2400 View* contents_view1 = new View;
2401 contents_view1->set_focusable(true);
2402 Widget widget1;
2403 Widget::InitParams init_params =
2404 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
2405 init_params.bounds = gfx::Rect(0, 0, 200, 200);
2406 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2407 init_params.native_widget = new DesktopNativeWidgetAura(&widget1);
2408 widget1.Init(init_params);
2409 widget1.SetContentsView(contents_view1);
2410 widget1.Show();
2411 contents_view1->RequestFocus();
2412
2413 aura::RootWindow* root_window1= widget1.GetNativeView()->GetRootWindow();
2414 EXPECT_TRUE(root_window1 != NULL);
2415 aura::client::ActivationClient* activation_client1 =
2416 aura::client::GetActivationClient(root_window1);
2417 EXPECT_TRUE(activation_client1 != NULL);
2418 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView());
2419
2420 // Create widget 2 and expect the active window to be its window.
2421 View* contents_view2 = new View;
2422 Widget widget2;
2423 Widget::InitParams init_params2 =
2424 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
2425 init_params2.bounds = gfx::Rect(0, 0, 200, 200);
2426 init_params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2427 init_params2.native_widget = new DesktopNativeWidgetAura(&widget2);
2428 widget2.Init(init_params2);
2429 widget2.SetContentsView(contents_view2);
2430 widget2.Show();
2431 contents_view2->RequestFocus();
2432
2433 aura::RootWindow* root_window2 = widget2.GetNativeView()->GetRootWindow();
2434 aura::client::ActivationClient* activation_client2 =
2435 aura::client::GetActivationClient(root_window2);
2436 EXPECT_TRUE(activation_client2 != NULL);
2437 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView());
2438 EXPECT_EQ(activation_client1->GetActiveWindow(),
2439 reinterpret_cast<aura::Window*>(NULL));
2440
2441 // Now set focus back to widget 1 and expect the active window to be its
2442 // window.
2443 ::SetForegroundWindow(root_window1->GetAcceleratedWidget());
2444 contents_view1->RequestFocus();
2445 EXPECT_EQ(activation_client2->GetActiveWindow(),
2446 reinterpret_cast<aura::Window*>(NULL));
2447 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView());
2448 }
2449 #endif
2450
2386 } // namespace test 2451 } // namespace test
2387 } // namespace views 2452 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698