Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / views / test / widget_test_aura.cc
blob822ea98e8be301cd131972aadd96235e85d2e96e
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 namespace views {
12 namespace test {
14 namespace {
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) {
26 *second = nullptr;
27 return *first == nullptr;
30 if (child == *first)
31 *first = nullptr;
33 if (FindLayersInOrder(child->children(), first, second))
34 return true;
36 // If second is cleared without success, exit early with failure.
37 if (!*second)
38 return false;
40 return false;
43 } // namespace
45 // static
46 void WidgetTest::SimulateNativeDestroy(Widget* widget) {
47 delete widget->GetNativeView();
50 // static
51 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) {
52 return window->IsVisible();
55 // static
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);
68 // static
69 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) {
70 return widget->GetNativeWindow()->GetHost()->event_processor();
73 } // namespace test
74 } // namespace views