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 <Cocoa/Cocoa.h>
9 #import "base/mac/scoped_nsobject.h"
10 #import "base/mac/scoped_objc_class_swizzler.h"
11 #include "ui/views/widget/root_view.h"
13 @interface IsKeyWindowDonor : NSObject
16 @implementation IsKeyWindowDonor
27 class FakeActivationMac : public WidgetTest::FakeActivation {
30 : swizzler_([NSWindow class],
31 [IsKeyWindowDonor class],
32 @selector(isKeyWindow)) {}
35 base::mac::ScopedObjCClassSwizzler swizzler_;
37 DISALLOW_COPY_AND_ASSIGN(FakeActivationMac);
43 void WidgetTest::SimulateNativeDestroy(Widget* widget) {
44 // Retain the window while closing it, otherwise the window may lose its last
45 // owner before -[NSWindow close] completes (this offends AppKit). Usually
46 // this reference will exist on an event delivered to the runloop.
47 base::scoped_nsobject<NSWindow> window([widget->GetNativeWindow() retain]);
52 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) {
53 return [window isVisible];
57 bool WidgetTest::IsWindowStackedAbove(Widget* above, Widget* below) {
58 EXPECT_TRUE(above->IsVisible());
59 EXPECT_TRUE(below->IsVisible());
61 // -[NSApplication orderedWindows] are ordered front-to-back.
62 NSWindow* first = above->GetNativeWindow();
63 NSWindow* second = below->GetNativeWindow();
65 for (NSWindow* window in [NSApp orderedWindows]) {
76 gfx::Size WidgetTest::GetNativeWidgetMinimumContentSize(Widget* widget) {
77 return gfx::Size([widget->GetNativeWindow() contentMinSize]);
81 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) {
82 return static_cast<internal::RootView*>(widget->GetRootView());
86 scoped_ptr<WidgetTest::FakeActivation> WidgetTest::FakeWidgetIsActiveAlways() {
87 return make_scoped_ptr(new FakeActivationMac);