Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ui / views / test / widget_test_mac.mm
blob2f1698dadd2bf55e4b79d72c6122a9b0f63e88aa
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
14 @end
16 @implementation IsKeyWindowDonor
17 - (BOOL)isKeyWindow {
18   return YES;
20 @end
22 namespace views {
23 namespace test {
25 namespace {
27 class FakeActivationMac : public WidgetTest::FakeActivation {
28  public:
29   FakeActivationMac()
30       : swizzler_([NSWindow class],
31                   [IsKeyWindowDonor class],
32                   @selector(isKeyWindow)) {}
34  private:
35   base::mac::ScopedObjCClassSwizzler swizzler_;
37   DISALLOW_COPY_AND_ASSIGN(FakeActivationMac);
40 }  // namespace
42 // static
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]);
48   [window close];
51 // static
52 bool WidgetTest::IsNativeWindowVisible(gfx::NativeWindow window) {
53   return [window isVisible];
56 // static
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]) {
66     if (window == second)
67       return !first;
69     if (window == first)
70       first = nil;
71   }
72   return false;
75 // static
76 gfx::Size WidgetTest::GetNativeWidgetMinimumContentSize(Widget* widget) {
77   return gfx::Size([widget->GetNativeWindow() contentMinSize]);
80 // static
81 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) {
82   return static_cast<internal::RootView*>(widget->GetRootView());
85 // static
86 scoped_ptr<WidgetTest::FakeActivation> WidgetTest::FakeWidgetIsActiveAlways() {
87   return make_scoped_ptr(new FakeActivationMac);
90 }  // namespace test
91 }  // namespace views