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"
16 // Perform a pre-order traversal of |children| and all descendants, looking for
17 // |first| and |second|. If |first| is found before |second|, return true.
18 // When a layer is found, it is set to null. Returns once |second| is found, or
19 // when there are no children left.
20 // Note that ui::Layer children are bottom-to-top stacking order.
21 bool FindLayersInOrder(const std::vector
<ui::Layer
*>& children
,
22 const ui::Layer
** first
,
23 const ui::Layer
** second
) {
24 for (const ui::Layer
* child
: children
) {
25 if (child
== *second
) {
27 return *first
== nullptr;
33 if (FindLayersInOrder(child
->children(), first
, second
))
36 // If second is cleared without success, exit early with failure.
46 void WidgetTest::SimulateNativeDestroy(Widget
* widget
) {
47 delete widget
->GetNativeView();
51 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window
) {
52 return window
->IsVisible();
56 bool WidgetTest::IsWindowStackedAbove(Widget
* above
, Widget
* below
) {
57 EXPECT_TRUE(above
->IsVisible());
58 EXPECT_TRUE(below
->IsVisible());
60 ui::Layer
* root_layer
= above
->GetNativeWindow()->GetRootWindow()->layer();
62 // Traversal is bottom-to-top, so |below| should be found first.
63 const ui::Layer
* first
= below
->GetLayer();
64 const ui::Layer
* second
= above
->GetLayer();
65 return FindLayersInOrder(root_layer
->children(), &first
, &second
);
69 ui::EventProcessor
* WidgetTest::GetEventProcessor(Widget
* widget
) {
70 return widget
->GetNativeWindow()->GetHost()->event_processor();