Migrate away from the PrefMetricsService-based device ID in PrefHashCalculator.
[chromium-blink-merge.git] / ui / views / widget / native_widget_mac_interactive_uitest.mm
blobaaba60a4c786e091fa15ab27f35d0ee30e312883
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"
11 namespace views {
12 namespace test {
14 // Tests for NativeWidgetMac that rely on global window manager state, and can
15 // not be parallelized.
16 class NativeWidgetMacInteractiveUITest
17     : public WidgetTest,
18       public ::testing::WithParamInterface<bool> {
19  public:
20   NativeWidgetMacInteractiveUITest() {}
22   Widget* MakeWidget() {
23     return GetParam() ? CreateTopLevelFramelessPlatformWidget()
24                       : CreateTopLevelPlatformWidget();
25   }
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];
33     WidgetTest::SetUp();
34   }
36  private:
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());
45   widget->Show();
46   EXPECT_TRUE(widget->IsActive());
48   RunPendingMessages();
49   EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]);
50   widget->CloseNow();
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
59   // be key.
60   EXPECT_FALSE(widget->IsActive());
61   widget->ShowInactive();
62   EXPECT_TRUE(widget->IsActive());
63   RunPendingMessages();
64   EXPECT_FALSE([widget->GetNativeWindow() isKeyWindow]);
66   // Creating a second widget should now keep that widget active.
67   Widget* widget2 = MakeWidget();
68   widget2->Show();
69   widget->ShowInactive();
71   EXPECT_FALSE(widget->IsActive());
72   EXPECT_TRUE(widget2->IsActive());
73   RunPendingMessages();
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
78   // key.
79   widget->Activate();
80   EXPECT_TRUE(widget->IsActive());
81   RunPendingMessages();
82   EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]);
84   widget2->CloseNow();
85   widget->CloseNow();
88 INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance,
89                         NativeWidgetMacInteractiveUITest,
90                         ::testing::Bool());
92 }  // namespace test
93 }  // namespace views