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

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_FALSE(app_window->fullscreen_types_for_test());
tapted 2014/05/15 07:44:40 nit: EXPECT_EQ(0, .. (it will give a nicer log me
jackhou1 2014/05/15 08:05:03 Done.
182 EXPECT_FALSE(window->IsFullscreen());
183 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
184
185 watcher.reset([[ScopedNotificationWatcher alloc]
186 initWithNotification:NSWindowDidEnterFullScreenNotification
187 andObject:ns_window]);
188 [ns_window toggleFullScreen:nil];
189 [watcher waitForNotification];
190 EXPECT_TRUE(app_window->fullscreen_types_for_test() &
191 apps::AppWindow::FULLSCREEN_TYPE_OS);
192 EXPECT_TRUE(window->IsFullscreen());
193 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
194
195 watcher.reset([[ScopedNotificationWatcher alloc]
196 initWithNotification:NSWindowDidExitFullScreenNotification
197 andObject:ns_window]);
198 app_window->Restore();
199 EXPECT_FALSE(window->IsFullscreenOrPending());
200 [watcher waitForNotification];
201 EXPECT_FALSE(app_window->fullscreen_types_for_test());
202 EXPECT_FALSE(window->IsFullscreen());
203 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
204
205 watcher.reset([[ScopedNotificationWatcher alloc]
206 initWithNotification:NSWindowDidEnterFullScreenNotification
207 andObject:ns_window]);
208 app_window->Fullscreen();
209 EXPECT_TRUE(window->IsFullscreenOrPending());
210 [watcher waitForNotification];
211 EXPECT_TRUE(app_window->fullscreen_types_for_test() &
212 apps::AppWindow::FULLSCREEN_TYPE_WINDOW_API);
213 EXPECT_TRUE(window->IsFullscreen());
214 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
215
216 watcher.reset([[ScopedNotificationWatcher alloc]
217 initWithNotification:NSWindowDidExitFullScreenNotification
218 andObject:ns_window]);
219 [ns_window toggleFullScreen:nil];
220 [watcher waitForNotification];
221 EXPECT_FALSE(app_window->fullscreen_types_for_test());
222 EXPECT_FALSE(window->IsFullscreen());
223 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
224 }
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