| 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 <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
| 10 #include "ui/views/widget/root_view.h" | 10 #include "ui/views/widget/root_view.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 namespace test { | 13 namespace test { |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 void WidgetTest::SimulateNativeDestroy(Widget* widget) { | 16 void WidgetTest::SimulateNativeDestroy(Widget* widget) { |
| 17 // Retain the window while closing it, otherwise the window may lose its last | 17 // Retain the window while closing it, otherwise the window may lose its last |
| 18 // owner before -[NSWindow close] completes (this offends AppKit). Usually | 18 // owner before -[NSWindow close] completes (this offends AppKit). Usually |
| 19 // this reference will exist on an event delivered to the runloop. | 19 // this reference will exist on an event delivered to the runloop. |
| 20 base::scoped_nsobject<NSWindow> window([widget->GetNativeWindow() retain]); | 20 base::scoped_nsobject<NSWindow> window([widget->GetNativeWindow() retain]); |
| 21 [window close]; | 21 [window close]; |
| 22 } | 22 } |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) { | 25 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) { |
| 26 return [window isVisible]; | 26 return [window isVisible]; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 bool WidgetTest::IsWindowStackedAbove(Widget* above, Widget* below) { |
| 31 EXPECT_TRUE(above->IsVisible()); |
| 32 EXPECT_TRUE(below->IsVisible()); |
| 33 |
| 34 // -[NSApplication orderedWindows] are ordered front-to-back. |
| 35 NSWindow* first = above->GetNativeWindow(); |
| 36 NSWindow* second = below->GetNativeWindow(); |
| 37 |
| 38 for (NSWindow* window in [NSApp orderedWindows]) { |
| 39 if (window == second) |
| 40 return !first; |
| 41 |
| 42 if (window == first) |
| 43 first = nil; |
| 44 } |
| 45 return false; |
| 46 } |
| 47 |
| 48 // static |
| 30 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) { | 49 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) { |
| 31 return static_cast<internal::RootView*>(widget->GetRootView()); | 50 return static_cast<internal::RootView*>(widget->GetRootView()); |
| 32 } | 51 } |
| 33 | 52 |
| 34 } // namespace test | 53 } // namespace test |
| 35 } // namespace views | 54 } // namespace views |
| OLD | NEW |