Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Side by Side Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 630363003: More NativeWidget -> Widget notifications: visibility, minimize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20140704-Mac-VIEWS-ActivationChanges
Patch Set: rebase on crrev/654393002 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #import "ui/views/widget/native_widget_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "ui/views/test/test_widget_observer.h"
10 #include "ui/views/test/widget_test.h"
11
12 namespace views {
13 namespace test {
14
15 // Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which
16 // need access to Cocoa APIs.
17 typedef WidgetTest NativeWidgetMacTest;
18
19 class WidgetChangeObserver : public TestWidgetObserver {
20 public:
21 WidgetChangeObserver(Widget* widget)
22 : TestWidgetObserver(widget),
23 gained_visible_count_(0),
24 lost_visible_count_(0) {}
25
26 int gained_visible_count() const { return gained_visible_count_; }
27 int lost_visible_count() const { return lost_visible_count_; }
28
29 private:
30 // WidgetObserver:
31 virtual void OnWidgetVisibilityChanged(Widget* widget,
32 bool visible) OVERRIDE {
33 ++(visible ? gained_visible_count_ : lost_visible_count_);
34 }
35
36 int gained_visible_count_;
37 int lost_visible_count_;
38
39 DISALLOW_COPY_AND_ASSIGN(WidgetChangeObserver);
40 };
41
42 // Test visibility states triggered externally.
43 TEST_F(NativeWidgetMacTest, HideAndShowExternally) {
44 Widget* widget = CreateTopLevelPlatformWidget();
45 NSWindow* ns_window = widget->GetNativeWindow();
46 WidgetChangeObserver observer(widget);
47
48 // Should initially be hidden.
49 EXPECT_FALSE(widget->IsVisible());
50 EXPECT_FALSE([ns_window isVisible]);
51 EXPECT_EQ(0, observer.gained_visible_count());
52 EXPECT_EQ(0, observer.lost_visible_count());
53
54 widget->Show();
55 EXPECT_TRUE(widget->IsVisible());
56 EXPECT_TRUE([ns_window isVisible]);
57 EXPECT_EQ(1, observer.gained_visible_count());
58 EXPECT_EQ(0, observer.lost_visible_count());
59
60 widget->Hide();
61 EXPECT_FALSE(widget->IsVisible());
62 EXPECT_FALSE([ns_window isVisible]);
63 EXPECT_EQ(1, observer.gained_visible_count());
64 EXPECT_EQ(1, observer.lost_visible_count());
65
66 widget->Show();
67 EXPECT_TRUE(widget->IsVisible());
68 EXPECT_TRUE([ns_window isVisible]);
69 EXPECT_EQ(2, observer.gained_visible_count());
70 EXPECT_EQ(1, observer.lost_visible_count());
71
72 // Test when hiding individual windows.
73 [ns_window orderOut:nil];
74 EXPECT_FALSE(widget->IsVisible());
75 EXPECT_FALSE([ns_window isVisible]);
76 EXPECT_EQ(2, observer.gained_visible_count());
77 EXPECT_EQ(2, observer.lost_visible_count());
78
79 [ns_window orderFront:nil];
80 EXPECT_TRUE(widget->IsVisible());
81 EXPECT_TRUE([ns_window isVisible]);
82 EXPECT_EQ(3, observer.gained_visible_count());
83 EXPECT_EQ(2, observer.lost_visible_count());
84
85 // Test when hiding the entire application. This doesn't send an orderOut:
86 // to the NSWindow.
87 [NSApp hide:nil];
88 EXPECT_FALSE(widget->IsVisible());
89 EXPECT_FALSE([ns_window isVisible]);
90 EXPECT_EQ(3, observer.gained_visible_count());
91 EXPECT_EQ(3, observer.lost_visible_count());
92
93 [NSApp unhideWithoutActivation];
94 EXPECT_TRUE(widget->IsVisible());
95 EXPECT_TRUE([ns_window isVisible]);
96 EXPECT_EQ(4, observer.gained_visible_count());
97 EXPECT_EQ(3, observer.lost_visible_count());
98
99 // Hide again to test unhiding with an activation.
100 [NSApp hide:nil];
101 EXPECT_EQ(4, observer.lost_visible_count());
102 [NSApp unhide:nil];
103 EXPECT_EQ(5, observer.gained_visible_count());
104
105 // No change when closing.
106 widget->CloseNow();
107 EXPECT_EQ(4, observer.lost_visible_count());
108 EXPECT_EQ(5, observer.gained_visible_count());
109 }
110
111 // Test minimized states triggered externally, implied visibility and restored
112 // bounds whilst minimized.
113 TEST_F(NativeWidgetMacTest, MiniaturizeExternally) {
114 Widget* widget = CreateTopLevelPlatformWidget();
115 NSWindow* ns_window = widget->GetNativeWindow();
116 WidgetChangeObserver observer(widget);
117
118 widget->Show();
119 EXPECT_EQ(1, observer.gained_visible_count());
120 EXPECT_EQ(0, observer.lost_visible_count());
121 const gfx::Rect restored_bounds = widget->GetRestoredBounds();
122 EXPECT_FALSE(restored_bounds.IsEmpty());
123
124 [ns_window miniaturize:nil];
125
126 EXPECT_TRUE(widget->IsMinimized());
127 EXPECT_FALSE(widget->IsVisible());
128 EXPECT_EQ(1, observer.gained_visible_count());
129 EXPECT_EQ(1, observer.lost_visible_count());
130 EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
131
132 [ns_window deminiaturize:nil];
133 EXPECT_FALSE(widget->IsMinimized());
134 EXPECT_TRUE(widget->IsVisible());
135 EXPECT_EQ(2, observer.gained_visible_count());
136 EXPECT_EQ(1, observer.lost_visible_count());
137 EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
138
139 EXPECT_FALSE([ns_window isMiniaturized]);
140 widget->Minimize();
141 EXPECT_TRUE(widget->IsMinimized());
142 EXPECT_TRUE([ns_window isMiniaturized]);
143 EXPECT_EQ(2, observer.gained_visible_count());
144 EXPECT_EQ(2, observer.lost_visible_count());
145 EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
146
147 widget->Restore(); // If miniaturized, should deminiaturize.
148 EXPECT_FALSE(widget->IsMinimized());
149 EXPECT_FALSE([ns_window isMiniaturized]);
150 EXPECT_EQ(3, observer.gained_visible_count());
151 EXPECT_EQ(2, observer.lost_visible_count());
152 EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
153
154 widget->Restore(); // If not miniaturized, does nothing.
155 EXPECT_FALSE(widget->IsMinimized());
156 EXPECT_FALSE([ns_window isMiniaturized]);
157 EXPECT_EQ(3, observer.gained_visible_count());
158 EXPECT_EQ(2, observer.lost_visible_count());
159 EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
160 }
161
162 } // namespace test
163 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698