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/window.h"
8 #include "ui/aura/window_tree_host.h"
9 #include "ui/views/widget/widget.h"
12 #include <X11/Xutil.h>
13 #include "ui/gfx/x/x11_types.h"
21 // Perform a pre-order traversal of |children| and all descendants, looking for
22 // |first| and |second|. If |first| is found before |second|, return true.
23 // When a layer is found, it is set to null. Returns once |second| is found, or
24 // when there are no children left.
25 // Note that ui::Layer children are bottom-to-top stacking order.
26 bool FindLayersInOrder(const std::vector
<ui::Layer
*>& children
,
27 const ui::Layer
** first
,
28 const ui::Layer
** second
) {
29 for (const ui::Layer
* child
: children
) {
30 if (child
== *second
) {
32 return *first
== nullptr;
38 if (FindLayersInOrder(child
->children(), first
, second
))
41 // If second is cleared without success, exit early with failure.
51 void WidgetTest::SimulateNativeDestroy(Widget
* widget
) {
52 delete widget
->GetNativeView();
56 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window
) {
57 return window
->IsVisible();
61 bool WidgetTest::IsWindowStackedAbove(Widget
* above
, Widget
* below
) {
62 EXPECT_TRUE(above
->IsVisible());
63 EXPECT_TRUE(below
->IsVisible());
65 ui::Layer
* root_layer
= above
->GetNativeWindow()->GetRootWindow()->layer();
67 // Traversal is bottom-to-top, so |below| should be found first.
68 const ui::Layer
* first
= below
->GetLayer();
69 const ui::Layer
* second
= above
->GetLayer();
70 return FindLayersInOrder(root_layer
->children(), &first
, &second
);
74 gfx::Size
WidgetTest::GetNativeWidgetMinimumContentSize(Widget
* widget
) {
75 // On Windows, HWNDMessageHandler receives a WM_GETMINMAXINFO message whenever
76 // the window manager is interested in knowing the size constraints. On
77 // ChromeOS, it's handled internally. Elsewhere, the size constraints need to
78 // be pushed to the window server when they change.
79 #if defined(OS_CHROMEOS) || defined(OS_WIN)
80 return widget
->GetNativeWindow()->delegate()->GetMinimumSize();
81 #elif defined(USE_X11)
86 widget
->GetNativeWindow()->GetHost()->GetAcceleratedWidget(), &hints
,
88 return gfx::Size(hints
.min_width
, hints
.min_height
);
95 ui::EventProcessor
* WidgetTest::GetEventProcessor(Widget
* widget
) {
96 return widget
->GetNativeWindow()->GetHost()->event_processor();