Automated Commit: Committing new LKGM version 7479.0.0 for chromeos.
[chromium-blink-merge.git] / ui / views / test / widget_test_aura.cc
blob502d7d0b247a5ccdac94377f93d5f1d1dd9a8924
1 // Copyright 2014 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.
5 #include "ui/views/test/widget_test.h"
7 #include "ui/aura/client/focus_client.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_tree_host.h"
10 #include "ui/views/widget/widget.h"
12 #if defined(USE_X11)
13 #include <X11/Xutil.h>
14 #include "ui/gfx/x/x11_types.h"
15 #endif
17 namespace views {
18 namespace test {
20 namespace {
22 // Perform a pre-order traversal of |children| and all descendants, looking for
23 // |first| and |second|. If |first| is found before |second|, return true.
24 // When a layer is found, it is set to null. Returns once |second| is found, or
25 // when there are no children left.
26 // Note that ui::Layer children are bottom-to-top stacking order.
27 bool FindLayersInOrder(const std::vector<ui::Layer*>& children,
28 const ui::Layer** first,
29 const ui::Layer** second) {
30 for (const ui::Layer* child : children) {
31 if (child == *second) {
32 *second = nullptr;
33 return *first == nullptr;
36 if (child == *first)
37 *first = nullptr;
39 if (FindLayersInOrder(child->children(), first, second))
40 return true;
42 // If second is cleared without success, exit early with failure.
43 if (!*second)
44 return false;
46 return false;
49 } // namespace
51 // static
52 void WidgetTest::SimulateNativeDestroy(Widget* widget) {
53 delete widget->GetNativeView();
56 // static
57 void WidgetTest::SimulateNativeActivate(Widget* widget) {
58 gfx::NativeView native_view = widget->GetNativeView();
59 aura::client::GetFocusClient(native_view)->FocusWindow(native_view);
62 // static
63 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) {
64 return window->IsVisible();
67 // static
68 bool WidgetTest::IsWindowStackedAbove(Widget* above, Widget* below) {
69 EXPECT_TRUE(above->IsVisible());
70 EXPECT_TRUE(below->IsVisible());
72 ui::Layer* root_layer = above->GetNativeWindow()->GetRootWindow()->layer();
74 // Traversal is bottom-to-top, so |below| should be found first.
75 const ui::Layer* first = below->GetLayer();
76 const ui::Layer* second = above->GetLayer();
77 return FindLayersInOrder(root_layer->children(), &first, &second);
80 // static
81 gfx::Size WidgetTest::GetNativeWidgetMinimumContentSize(Widget* widget) {
82 // On Windows, HWNDMessageHandler receives a WM_GETMINMAXINFO message whenever
83 // the window manager is interested in knowing the size constraints. On
84 // ChromeOS, it's handled internally. Elsewhere, the size constraints need to
85 // be pushed to the window server when they change.
86 #if defined(OS_CHROMEOS) || defined(OS_WIN)
87 return widget->GetNativeWindow()->delegate()->GetMinimumSize();
88 #elif defined(USE_X11)
89 XSizeHints hints;
90 long supplied_return;
91 XGetWMNormalHints(
92 gfx::GetXDisplay(),
93 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget(), &hints,
94 &supplied_return);
95 return gfx::Size(hints.min_width, hints.min_height);
96 #else
97 NOTREACHED();
98 return gfx::Size();
99 #endif
102 // static
103 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) {
104 return widget->GetNativeWindow()->GetHost()->event_processor();
107 // static
108 ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget(
109 Widget* widget) {
110 return widget->GetNativeWindow()->GetRootWindow()->GetHost();
113 } // namespace test
114 } // namespace views