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

Side by Side Diff: chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm

Issue 280483004: [Mac] Update fullscreen state when window is fullscreened natively. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/apps/native_app_window_cocoa.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
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 "base/mac/mac_util.h"
10 #include "chrome/browser/apps/app_browsertest_util.h" 11 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/extensions/application_launch.h" 13 #include "chrome/browser/ui/extensions/application_launch.h"
13 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
14 #include "content/public/test/test_utils.h" 15 #include "content/public/test/test_utils.h"
15 16
16 using extensions::PlatformAppBrowserTest; 17 using extensions::PlatformAppBrowserTest;
17 18
18 namespace { 19 namespace {
19 20
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 other_window->Hide(); 101 other_window->Hide();
101 EXPECT_FALSE([other_ns_window isVisible]); 102 EXPECT_FALSE([other_ns_window isVisible]);
102 103
103 // HideWithApp, ShowWithApp does not show the other window. 104 // HideWithApp, ShowWithApp does not show the other window.
104 window->HideWithApp(); 105 window->HideWithApp();
105 EXPECT_FALSE([ns_window isVisible]); 106 EXPECT_FALSE([ns_window isVisible]);
106 window->ShowWithApp(); 107 window->ShowWithApp();
107 EXPECT_TRUE([ns_window isVisible]); 108 EXPECT_TRUE([ns_window isVisible]);
108 EXPECT_FALSE([other_ns_window isVisible]); 109 EXPECT_FALSE([other_ns_window isVisible]);
109 } 110 }
111
112 // Only test fullscreen for 10.7 and above.
113 // Replicate specific 10.7 SDK declarations for building with prior SDKs.
114 #if !defined(MAC_OS_X_VERSION_10_7) || \
115 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
116
117 @interface NSWindow (LionSDKDeclarations)
118 - (void)toggleFullScreen:(id)sender;
119 @end
120
121 enum {
122 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7,
123 NSFullScreenWindowMask = 1 << 14
124 };
125
126 NSString* const NSWindowDidEnterFullScreenNotification =
127 @"NSWindowDidEnterFullScreenNotification";
128 NSString* const NSWindowDidExitFullScreenNotification =
129 @"NSWindowDidExitFullScreenNotification";
130
131 #endif // MAC_OS_X_VERSION_10_7
132
133 @interface ScopedNotificationWatcher : NSObject {
134 @private
135 BOOL received_;
136 }
137 - (id)initWithNotification:(NSString*)notification
138 andObject:(NSObject*)object;
139 - (void)onNotification:(NSString*)notification;
140 - (void)waitForNotification;
141 @end
142
143 @implementation ScopedNotificationWatcher
144
145 - (id)initWithNotification:(NSString*)notification
146 andObject:(NSObject*)object {
147 if ((self = [super init])) {
148 [[NSNotificationCenter defaultCenter]
149 addObserver:self
150 selector:@selector(onNotification:)
151 name:notification
152 object:object];
153 }
154 return self;
155 }
156
157 - (void)onNotification:(NSString*)notification {
158 received_ = YES;
159 [[NSNotificationCenter defaultCenter] removeObserver:self];
160 }
161
162 - (void)waitForNotification {
163 while (!received_)
164 content::RunAllPendingInMessageLoop();
165 }
166
167 @end
168
169 // Test that NativeAppWindow and AppWindow fullscreen state is updated when
170 // the window is fullscreened natively.
171 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) {
172 if (!base::mac::IsOSLionOrLater())
173 return;
174
175 SetUpAppWithWindows(1);
176 apps::AppWindow* app_window = GetFirstAppWindow();
177 apps::NativeAppWindow* window = app_window->GetBaseWindow();
178 NSWindow* ns_window = app_window->GetNativeWindow();
179 base::scoped_nsobject<ScopedNotificationWatcher> watcher;
180
181 EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE,
182 app_window->fullscreen_types_for_test());
183 EXPECT_FALSE(window->IsFullscreen());
184 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
185
186 watcher.reset([[ScopedNotificationWatcher alloc]
187 initWithNotification:NSWindowDidEnterFullScreenNotification
188 andObject:ns_window]);
189 [ns_window toggleFullScreen:nil];
190 [watcher waitForNotification];
191 EXPECT_TRUE(app_window->fullscreen_types_for_test() &
192 apps::AppWindow::FULLSCREEN_TYPE_OS);
193 EXPECT_TRUE(window->IsFullscreen());
194 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
195
196 watcher.reset([[ScopedNotificationWatcher alloc]
197 initWithNotification:NSWindowDidExitFullScreenNotification
198 andObject:ns_window]);
199 app_window->Restore();
200 EXPECT_FALSE(window->IsFullscreenOrPending());
201 [watcher waitForNotification];
202 EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE,
203 app_window->fullscreen_types_for_test());
204 EXPECT_FALSE(window->IsFullscreen());
205 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
206
207 watcher.reset([[ScopedNotificationWatcher alloc]
208 initWithNotification:NSWindowDidEnterFullScreenNotification
209 andObject:ns_window]);
210 app_window->Fullscreen();
211 EXPECT_TRUE(window->IsFullscreenOrPending());
212 [watcher waitForNotification];
213 EXPECT_TRUE(app_window->fullscreen_types_for_test() &
214 apps::AppWindow::FULLSCREEN_TYPE_WINDOW_API);
215 EXPECT_TRUE(window->IsFullscreen());
216 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
217
218 watcher.reset([[ScopedNotificationWatcher alloc]
219 initWithNotification:NSWindowDidExitFullScreenNotification
220 andObject:ns_window]);
221 [ns_window toggleFullScreen:nil];
222 [watcher waitForNotification];
223 EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE,
224 app_window->fullscreen_types_for_test());
225 EXPECT_FALSE(window->IsFullscreen());
226 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
227 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698