Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / views / test / widget_test_aura.cc
blob778f1f0c99af09ebab14fb07236261a0ff677b4f
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"
11 #if defined(USE_X11)
12 #include <X11/Xutil.h>
13 #include "ui/gfx/x/x11_types.h"
14 #endif
16 namespace views {
17 namespace test {
19 namespace {
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) {
31 *second = nullptr;
32 return *first == nullptr;
35 if (child == *first)
36 *first = nullptr;
38 if (FindLayersInOrder(child->children(), first, second))
39 return true;
41 // If second is cleared without success, exit early with failure.
42 if (!*second)
43 return false;
45 return false;
48 } // namespace
50 // static
51 void WidgetTest::SimulateNativeDestroy(Widget* widget) {
52 delete widget->GetNativeView();
55 // static
56 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) {
57 return window->IsVisible();
60 // static
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);
73 // static
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)
82 XSizeHints hints;
83 long supplied_return;
84 XGetWMNormalHints(
85 gfx::GetXDisplay(),
86 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget(), &hints,
87 &supplied_return);
88 return gfx::Size(hints.min_width, hints.min_height);
89 #else
90 NOTREACHED();
91 #endif
94 // static
95 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) {
96 return widget->GetNativeWindow()->GetHost()->event_processor();
99 } // namespace test
100 } // namespace views