Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/test/widget_test.h" | 5 #include "ui/views/test/widget_test.h" |
| 6 | 6 |
| 7 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
| 8 #include "ui/aura/window_tree_host.h" | 8 #include "ui/aura/window_tree_host.h" |
| 9 #include "ui/views/widget/widget.h" | 9 #include "ui/views/widget/widget.h" |
| 10 | 10 |
| 11 namespace views { | 11 namespace views { |
| 12 namespace test { | 12 namespace test { |
| 13 | 13 |
| 14 namespace { | |
| 15 | |
| 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; | |
| 28 } | |
| 29 | |
| 30 if (child == *first) | |
| 31 *first = nullptr; | |
| 32 | |
| 33 if (FindLayersInOrder(child->children(), first, second)) | |
| 34 return true; | |
| 35 | |
| 36 // If second is cleared without success, exit early with failure. | |
| 37 if (!*second) | |
| 38 return false; | |
| 39 } | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 14 // static | 45 // static |
| 15 void WidgetTest::SimulateNativeDestroy(Widget* widget) { | 46 void WidgetTest::SimulateNativeDestroy(Widget* widget) { |
| 16 delete widget->GetNativeView(); | 47 delete widget->GetNativeView(); |
| 17 } | 48 } |
| 18 | 49 |
| 19 // static | 50 // static |
| 20 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) { | 51 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) { |
| 21 return window->IsVisible(); | 52 return window->IsVisible(); |
| 22 } | 53 } |
| 23 | 54 |
| 24 // static | 55 // static |
| 56 bool WidgetTest::IsWindowStackedAbove(Widget* above, Widget* below) { | |
| 57 CHECK(above->IsVisible()); | |
|
sky
2015/01/08 04:17:44
CHECKs aren't good for tests. If it hits it means
tapted
2015/01/08 09:07:56
changed to EXPECT_TRUE. The thinking went that the
| |
| 58 CHECK(below->IsVisible()); | |
| 59 | |
| 60 ui::Layer* root_layer = above->GetNativeWindow()->GetRootWindow()->layer(); | |
| 61 | |
| 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); | |
| 66 } | |
| 67 | |
| 68 // static | |
| 25 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) { | 69 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) { |
| 26 return widget->GetNativeWindow()->GetHost()->event_processor(); | 70 return widget->GetNativeWindow()->GetHost()->event_processor(); |
| 27 } | 71 } |
| 28 | 72 |
| 29 } // namespace test | 73 } // namespace test |
| 30 } // namespace views | 74 } // namespace views |
| OLD | NEW |