OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "apps/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
10 #include "chrome/browser/apps/app_browsertest_util.h" | 10 #include "chrome/browser/apps/app_browsertest_util.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 other_window->Hide(); | 100 other_window->Hide(); |
101 EXPECT_FALSE([other_ns_window isVisible]); | 101 EXPECT_FALSE([other_ns_window isVisible]); |
102 | 102 |
103 // HideWithApp, ShowWithApp does not show the other window. | 103 // HideWithApp, ShowWithApp does not show the other window. |
104 window->HideWithApp(); | 104 window->HideWithApp(); |
105 EXPECT_FALSE([ns_window isVisible]); | 105 EXPECT_FALSE([ns_window isVisible]); |
106 window->ShowWithApp(); | 106 window->ShowWithApp(); |
107 EXPECT_TRUE([ns_window isVisible]); | 107 EXPECT_TRUE([ns_window isVisible]); |
108 EXPECT_FALSE([other_ns_window isVisible]); | 108 EXPECT_FALSE([other_ns_window isVisible]); |
109 } | 109 } |
110 | |
111 // Only test fullscreen for 10.7 and above. | |
112 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | |
113 #if !defined(MAC_OS_X_VERSION_10_7) || \ | |
114 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | |
115 | |
116 @interface NSWindow (LionSDKDeclarations) | |
117 - (void)toggleFullScreen:(id)sender; | |
118 @end | |
119 | |
120 enum { | |
121 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7, | |
122 NSFullScreenWindowMask = 1 << 14 | |
123 }; | |
124 | |
125 NSString* const NSWindowDidEnterFullScreenNotification = | |
126 @"NSWindowDidEnterFullScreenNotification"; | |
127 NSString* const NSWindowDidExitFullScreenNotification = | |
128 @"NSWindowDidExitFullScreenNotification"; | |
129 | |
tapted
2014/05/15 06:39:20
#endif here
jackhou1
2014/05/15 07:15:29
Done.
| |
130 @interface ScopedNotificationWatcher : NSObject { | |
131 @private | |
132 BOOL received_; | |
133 } | |
134 - (id)initWithNotification:(NSString*)notification | |
135 andObject:(NSObject*)object; | |
136 - (void)onNotification:(NSString*)notification; | |
137 - (void)waitForNotification; | |
138 @end | |
139 | |
140 @implementation ScopedNotificationWatcher | |
141 | |
142 - (id)initWithNotification:(NSString*)notification | |
143 andObject:(NSObject*)object { | |
144 if ((self = [super init])) { | |
145 [[NSNotificationCenter defaultCenter] | |
146 addObserver:self | |
147 selector:@selector(onNotification:) | |
148 name:notification | |
149 object:object]; | |
150 } | |
151 return self; | |
152 } | |
153 | |
154 - (void)onNotification:(NSString*)notification { | |
155 received_ = YES; | |
156 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
157 } | |
158 | |
159 - (void)waitForNotification { | |
160 while (!received_) | |
161 content::RunAllPendingInMessageLoop(); | |
162 } | |
163 | |
164 @end | |
165 | |
166 // Test that NativeAppWindow and AppWindow fullscreen state is updated when | |
167 // the window is fullscreened natively. | |
168 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { | |
169 SetUpAppWithWindows(1); | |
tapted
2014/05/15 06:39:20
here do
// Only test fullscreen for 10.7 and abov
jackhou1
2014/05/15 07:15:29
Done.
| |
170 apps::AppWindow* app_window = GetFirstAppWindow(); | |
171 apps::NativeAppWindow* window = app_window->GetBaseWindow(); | |
172 NSWindow* ns_window = app_window->GetNativeWindow(); | |
173 base::scoped_nsobject<ScopedNotificationWatcher> watcher; | |
174 | |
175 EXPECT_FALSE(window->IsFullscreen()); | |
176 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | |
177 | |
178 watcher.reset([[ScopedNotificationWatcher alloc] | |
179 initWithNotification:NSWindowDidEnterFullScreenNotification | |
180 andObject:ns_window]); | |
181 [ns_window toggleFullScreen:nil]; | |
182 [watcher waitForNotification]; | |
183 EXPECT_TRUE(window->IsFullscreen()); | |
184 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | |
tapted
2014/05/15 06:39:20
I think it's worth moving `IsFullscreen` out of th
jackhou1
2014/05/15 07:15:29
Added AppWindow::fullscreen_types_for_test like ap
| |
185 | |
186 watcher.reset([[ScopedNotificationWatcher alloc] | |
187 initWithNotification:NSWindowDidExitFullScreenNotification | |
188 andObject:ns_window]); | |
189 app_window->Restore(); | |
tapted
2014/05/15 06:39:20
does window->IsFullscreenOrPending() change immedi
jackhou1
2014/05/15 07:15:29
Done.
| |
190 [watcher waitForNotification]; | |
191 EXPECT_FALSE(window->IsFullscreen()); | |
192 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | |
193 | |
194 watcher.reset([[ScopedNotificationWatcher alloc] | |
195 initWithNotification:NSWindowDidEnterFullScreenNotification | |
196 andObject:ns_window]); | |
197 app_window->Fullscreen(); | |
198 [watcher waitForNotification]; | |
tapted
2014/05/15 06:39:20
likewise window->IsFullscreenOrPending() should be
jackhou1
2014/05/15 07:15:29
I take it you mean true? The comment on IsFullscre
tapted
2014/05/15 07:44:40
oops - yep.
| |
199 EXPECT_TRUE(window->IsFullscreen()); | |
200 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | |
201 | |
202 watcher.reset([[ScopedNotificationWatcher alloc] | |
203 initWithNotification:NSWindowDidExitFullScreenNotification | |
204 andObject:ns_window]); | |
205 [ns_window toggleFullScreen:nil]; | |
206 [watcher waitForNotification]; | |
tapted
2014/05/15 06:39:20
(but this one is native, so window->IsFullscreenOr
| |
207 EXPECT_FALSE(window->IsFullscreen()); | |
208 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | |
209 } | |
210 | |
211 #endif // MAC_OS_X_VERSION_10_7 | |
OLD | NEW |