OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ui/views/widget/native_widget_mac.h" | 5 #import "ui/views/widget/native_widget_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
| 9 #include "base/run_loop.h" |
9 #include "ui/views/test/test_widget_observer.h" | 10 #include "ui/views/test/test_widget_observer.h" |
10 #include "ui/views/test/widget_test.h" | 11 #include "ui/views/test/widget_test.h" |
11 | 12 |
12 namespace views { | 13 namespace views { |
13 namespace test { | 14 namespace test { |
14 | 15 |
15 // Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which | 16 // Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which |
16 // need access to Cocoa APIs. | 17 // need access to Cocoa APIs. |
17 typedef WidgetTest NativeWidgetMacTest; | 18 typedef WidgetTest NativeWidgetMacTest; |
18 | 19 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 79 |
79 [ns_window orderFront:nil]; | 80 [ns_window orderFront:nil]; |
80 EXPECT_TRUE(widget->IsVisible()); | 81 EXPECT_TRUE(widget->IsVisible()); |
81 EXPECT_TRUE([ns_window isVisible]); | 82 EXPECT_TRUE([ns_window isVisible]); |
82 EXPECT_EQ(3, observer.gained_visible_count()); | 83 EXPECT_EQ(3, observer.gained_visible_count()); |
83 EXPECT_EQ(2, observer.lost_visible_count()); | 84 EXPECT_EQ(2, observer.lost_visible_count()); |
84 | 85 |
85 // Test when hiding the entire application. This doesn't send an orderOut: | 86 // Test when hiding the entire application. This doesn't send an orderOut: |
86 // to the NSWindow. | 87 // to the NSWindow. |
87 [NSApp hide:nil]; | 88 [NSApp hide:nil]; |
| 89 // When the activation policy is NSApplicationActivationPolicyRegular, the |
| 90 // calls via NSApp are asynchronous, and the run loop needs to be flushed. |
| 91 // With NSApplicationActivationPolicyProhibited, the following RunUntilIdle |
| 92 // calls are superfluous, but don't hurt. |
| 93 base::RunLoop().RunUntilIdle(); |
88 EXPECT_FALSE(widget->IsVisible()); | 94 EXPECT_FALSE(widget->IsVisible()); |
89 EXPECT_FALSE([ns_window isVisible]); | 95 EXPECT_FALSE([ns_window isVisible]); |
90 EXPECT_EQ(3, observer.gained_visible_count()); | 96 EXPECT_EQ(3, observer.gained_visible_count()); |
91 EXPECT_EQ(3, observer.lost_visible_count()); | 97 EXPECT_EQ(3, observer.lost_visible_count()); |
92 | 98 |
93 [NSApp unhideWithoutActivation]; | 99 [NSApp unhideWithoutActivation]; |
| 100 base::RunLoop().RunUntilIdle(); |
94 EXPECT_TRUE(widget->IsVisible()); | 101 EXPECT_TRUE(widget->IsVisible()); |
95 EXPECT_TRUE([ns_window isVisible]); | 102 EXPECT_TRUE([ns_window isVisible]); |
96 EXPECT_EQ(4, observer.gained_visible_count()); | 103 EXPECT_EQ(4, observer.gained_visible_count()); |
97 EXPECT_EQ(3, observer.lost_visible_count()); | 104 EXPECT_EQ(3, observer.lost_visible_count()); |
98 | 105 |
99 // Hide again to test unhiding with an activation. | 106 // Hide again to test unhiding with an activation. |
100 [NSApp hide:nil]; | 107 [NSApp hide:nil]; |
| 108 base::RunLoop().RunUntilIdle(); |
101 EXPECT_EQ(4, observer.lost_visible_count()); | 109 EXPECT_EQ(4, observer.lost_visible_count()); |
102 [NSApp unhide:nil]; | 110 [NSApp unhide:nil]; |
| 111 base::RunLoop().RunUntilIdle(); |
103 EXPECT_EQ(5, observer.gained_visible_count()); | 112 EXPECT_EQ(5, observer.gained_visible_count()); |
104 | 113 |
| 114 // Hide again to test makeKeyAndOrderFront:. |
| 115 [ns_window orderOut:nil]; |
| 116 EXPECT_FALSE(widget->IsVisible()); |
| 117 EXPECT_FALSE([ns_window isVisible]); |
| 118 EXPECT_EQ(5, observer.gained_visible_count()); |
| 119 EXPECT_EQ(5, observer.lost_visible_count()); |
| 120 |
| 121 [ns_window makeKeyAndOrderFront:nil]; |
| 122 EXPECT_TRUE(widget->IsVisible()); |
| 123 EXPECT_TRUE([ns_window isVisible]); |
| 124 EXPECT_EQ(6, observer.gained_visible_count()); |
| 125 EXPECT_EQ(5, observer.lost_visible_count()); |
| 126 |
105 // No change when closing. | 127 // No change when closing. |
106 widget->CloseNow(); | 128 widget->CloseNow(); |
107 EXPECT_EQ(4, observer.lost_visible_count()); | 129 EXPECT_EQ(5, observer.lost_visible_count()); |
108 EXPECT_EQ(5, observer.gained_visible_count()); | 130 EXPECT_EQ(6, observer.gained_visible_count()); |
109 } | 131 } |
110 | 132 |
111 // A view that counts calls to OnPaint(). | 133 // A view that counts calls to OnPaint(). |
112 class PaintCountView : public View { | 134 class PaintCountView : public View { |
113 public: | 135 public: |
114 PaintCountView() : paint_count_(0) { | 136 PaintCountView() : paint_count_(0) { |
115 SetBounds(0, 0, 100, 100); | 137 SetBounds(0, 0, 100, 100); |
116 } | 138 } |
117 | 139 |
118 // View: | 140 // View: |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // But this should work. | 252 // But this should work. |
231 widget->Minimize(); | 253 widget->Minimize(); |
232 EXPECT_TRUE(widget->IsMinimized()); | 254 EXPECT_TRUE(widget->IsMinimized()); |
233 | 255 |
234 // Test closing while minimized. | 256 // Test closing while minimized. |
235 widget->CloseNow(); | 257 widget->CloseNow(); |
236 } | 258 } |
237 | 259 |
238 } // namespace test | 260 } // namespace test |
239 } // namespace views | 261 } // namespace views |
OLD | NEW |