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/widget/native_widget_mac.h"
7 #import <Cocoa/Cocoa.h>
9 #include "ui/views/test/widget_test.h"
14 // Tests for NativeWidgetMac that rely on global window manager state, and can
15 // not be parallelized.
16 class NativeWidgetMacInteractiveUITest
18 public ::testing::WithParamInterface<bool> {
20 NativeWidgetMacInteractiveUITest() {}
22 Widget* MakeWidget() {
23 return GetParam() ? CreateTopLevelFramelessPlatformWidget()
24 : CreateTopLevelPlatformWidget();
27 // Overridden form testing::Test:
28 virtual void SetUp() {
29 // Unbundled applications (those without Info.plist) default to
30 // NSApplicationActivationPolicyProhibited, which prohibits the application
31 // obtaining key status.
32 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
37 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacInteractiveUITest);
40 // Test that showing a window causes it to attain global keyWindow status.
41 TEST_P(NativeWidgetMacInteractiveUITest, ShowAttainsKeyStatus) {
42 Widget* widget = MakeWidget();
44 EXPECT_FALSE(widget->IsActive());
46 EXPECT_TRUE(widget->IsActive());
49 EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]);
53 // Test that ShowInactive does not take keyWindow status from an active window.
54 TEST_P(NativeWidgetMacInteractiveUITest, ShowInactiveIgnoresKeyStatus) {
55 Widget* widget = MakeWidget();
57 // In an application with only a single window, that window is always "active"
58 // for the application unless that window is not visible. However, it will not
60 EXPECT_FALSE(widget->IsActive());
61 widget->ShowInactive();
62 EXPECT_TRUE(widget->IsActive());
64 EXPECT_FALSE([widget->GetNativeWindow() isKeyWindow]);
66 // Creating a second widget should now keep that widget active.
67 Widget* widget2 = MakeWidget();
69 widget->ShowInactive();
71 EXPECT_FALSE(widget->IsActive());
72 EXPECT_TRUE(widget2->IsActive());
74 EXPECT_FALSE([widget->GetNativeWindow() isKeyWindow]);
75 EXPECT_TRUE([widget2->GetNativeWindow() isKeyWindow]);
77 // And finally activating the inactive widget should activate it and make it
80 EXPECT_TRUE(widget->IsActive());
82 EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]);
88 INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance,
89 NativeWidgetMacInteractiveUITest,