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

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

Issue 1109493002: [MacViews] Fix behavior of non-resizable windows in fullscreen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert to Patch Set 7 Created 5 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
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | 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 // This file tests whichever implementation of NativeAppWindow is used. 5 // This file tests whichever implementation of NativeAppWindow is used.
6 // I.e. it could be NativeAppWindowCocoa or ChromeNativeAppWindowViewsMac. 6 // I.e. it could be NativeAppWindowCocoa or ChromeNativeAppWindowViewsMac.
7 #include "extensions/browser/app_window/native_app_window.h" 7 #include "extensions/browser/app_window/native_app_window.h"
8 8
9 #import <Cocoa/Cocoa.h> 9 #import <Cocoa/Cocoa.h>
10 10
11 #import "base/mac/foundation_util.h" 11 #import "base/mac/foundation_util.h"
12 #import "base/mac/mac_util.h" 12 #import "base/mac/mac_util.h"
13 #import "base/mac/scoped_nsobject.h" 13 #import "base/mac/scoped_nsobject.h"
14 #import "base/mac/sdk_forward_declarations.h" 14 #import "base/mac/sdk_forward_declarations.h"
15 #include "chrome/browser/apps/app_browsertest_util.h" 15 #include "chrome/browser/apps/app_browsertest_util.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/extensions/app_launch_params.h" 17 #include "chrome/browser/ui/extensions/app_launch_params.h"
18 #include "chrome/browser/ui/extensions/application_launch.h" 18 #include "chrome/browser/ui/extensions/application_launch.h"
19 #import "chrome/browser/ui/test/scoped_fake_nswindow_main_status.h" 19 #import "chrome/browser/ui/test/scoped_fake_nswindow_main_status.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
22 #include "extensions/browser/app_window/app_window_registry.h" 22 #include "extensions/browser/app_window/app_window_registry.h"
23 #include "extensions/common/constants.h" 23 #include "extensions/common/constants.h"
24 #import "ui/base/test/nswindow_fullscreen_notification_waiter.h"
24 25
26 using extensions::AppWindow;
25 using extensions::PlatformAppBrowserTest; 27 using extensions::PlatformAppBrowserTest;
26 28
27 namespace { 29 namespace {
28 30
29 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { 31 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest {
30 protected: 32 protected:
31 NativeAppWindowCocoaBrowserTest() {} 33 NativeAppWindowCocoaBrowserTest() {}
32 34
33 void SetUpAppWithWindows(int num_windows) { 35 void SetUpAppWithWindows(int num_windows) {
34 app_ = InstallExtension( 36 app_ = InstallExtension(
(...skipping 18 matching lines...) Expand all
53 }; 55 };
54 56
55 } // namespace 57 } // namespace
56 58
57 // Test interaction of Hide/Show() with Hide/ShowWithApp(). 59 // Test interaction of Hide/Show() with Hide/ShowWithApp().
58 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) { 60 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) {
59 SetUpAppWithWindows(2); 61 SetUpAppWithWindows(2);
60 extensions::AppWindowRegistry::AppWindowList windows = 62 extensions::AppWindowRegistry::AppWindowList windows =
61 extensions::AppWindowRegistry::Get(profile())->app_windows(); 63 extensions::AppWindowRegistry::Get(profile())->app_windows();
62 64
63 extensions::AppWindow* app_window = windows.front(); 65 AppWindow* app_window = windows.front();
64 extensions::NativeAppWindow* native_window = app_window->GetBaseWindow(); 66 extensions::NativeAppWindow* native_window = app_window->GetBaseWindow();
65 NSWindow* ns_window = native_window->GetNativeWindow(); 67 NSWindow* ns_window = native_window->GetNativeWindow();
66 68
67 extensions::AppWindow* other_app_window = windows.back(); 69 AppWindow* other_app_window = windows.back();
68 extensions::NativeAppWindow* other_native_window = 70 extensions::NativeAppWindow* other_native_window =
69 other_app_window->GetBaseWindow(); 71 other_app_window->GetBaseWindow();
70 NSWindow* other_ns_window = other_native_window->GetNativeWindow(); 72 NSWindow* other_ns_window = other_native_window->GetNativeWindow();
71 73
72 // Normal Hide/Show. 74 // Normal Hide/Show.
73 app_window->Hide(); 75 app_window->Hide();
74 EXPECT_FALSE([ns_window isVisible]); 76 EXPECT_FALSE([ns_window isVisible]);
75 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); 77 app_window->Show(AppWindow::SHOW_ACTIVE);
76 EXPECT_TRUE([ns_window isVisible]); 78 EXPECT_TRUE([ns_window isVisible]);
77 79
78 // Normal Hide/ShowWithApp. 80 // Normal Hide/ShowWithApp.
79 native_window->HideWithApp(); 81 native_window->HideWithApp();
80 EXPECT_FALSE([ns_window isVisible]); 82 EXPECT_FALSE([ns_window isVisible]);
81 native_window->ShowWithApp(); 83 native_window->ShowWithApp();
82 EXPECT_TRUE([ns_window isVisible]); 84 EXPECT_TRUE([ns_window isVisible]);
83 85
84 // HideWithApp, Hide, ShowWithApp does not show. 86 // HideWithApp, Hide, ShowWithApp does not show.
85 native_window->HideWithApp(); 87 native_window->HideWithApp();
86 app_window->Hide(); 88 app_window->Hide();
87 native_window->ShowWithApp(); 89 native_window->ShowWithApp();
88 EXPECT_FALSE([ns_window isVisible]); 90 EXPECT_FALSE([ns_window isVisible]);
89 91
90 // Hide, HideWithApp, ShowWithApp does not show. 92 // Hide, HideWithApp, ShowWithApp does not show.
91 native_window->HideWithApp(); 93 native_window->HideWithApp();
92 native_window->ShowWithApp(); 94 native_window->ShowWithApp();
93 EXPECT_FALSE([ns_window isVisible]); 95 EXPECT_FALSE([ns_window isVisible]);
94 96
95 // Return to shown state. 97 // Return to shown state.
96 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); 98 app_window->Show(AppWindow::SHOW_ACTIVE);
97 EXPECT_TRUE([ns_window isVisible]); 99 EXPECT_TRUE([ns_window isVisible]);
98 100
99 // HideWithApp the other window. 101 // HideWithApp the other window.
100 EXPECT_TRUE([other_ns_window isVisible]); 102 EXPECT_TRUE([other_ns_window isVisible]);
101 other_native_window->HideWithApp(); 103 other_native_window->HideWithApp();
102 EXPECT_FALSE([other_ns_window isVisible]); 104 EXPECT_FALSE([other_ns_window isVisible]);
103 105
104 // HideWithApp, Show shows all windows for this app. 106 // HideWithApp, Show shows all windows for this app.
105 native_window->HideWithApp(); 107 native_window->HideWithApp();
106 EXPECT_FALSE([ns_window isVisible]); 108 EXPECT_FALSE([ns_window isVisible]);
107 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); 109 app_window->Show(AppWindow::SHOW_ACTIVE);
108 EXPECT_TRUE([ns_window isVisible]); 110 EXPECT_TRUE([ns_window isVisible]);
109 EXPECT_TRUE([other_ns_window isVisible]); 111 EXPECT_TRUE([other_ns_window isVisible]);
110 112
111 // Hide the other window. 113 // Hide the other window.
112 other_app_window->Hide(); 114 other_app_window->Hide();
113 EXPECT_FALSE([other_ns_window isVisible]); 115 EXPECT_FALSE([other_ns_window isVisible]);
114 116
115 // HideWithApp, ShowWithApp does not show the other window. 117 // HideWithApp, ShowWithApp does not show the other window.
116 native_window->HideWithApp(); 118 native_window->HideWithApp();
117 EXPECT_FALSE([ns_window isVisible]); 119 EXPECT_FALSE([ns_window isVisible]);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 158
157 @end 159 @end
158 160
159 // Test that NativeAppWindow and AppWindow fullscreen state is updated when 161 // Test that NativeAppWindow and AppWindow fullscreen state is updated when
160 // the window is fullscreened natively. 162 // the window is fullscreened natively.
161 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { 163 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) {
162 if (!base::mac::IsOSLionOrLater()) 164 if (!base::mac::IsOSLionOrLater())
163 return; 165 return;
164 166
165 SetUpAppWithWindows(1); 167 SetUpAppWithWindows(1);
166 extensions::AppWindow* app_window = GetFirstAppWindow(); 168 AppWindow* app_window = GetFirstAppWindow();
167 extensions::NativeAppWindow* window = app_window->GetBaseWindow(); 169 extensions::NativeAppWindow* window = app_window->GetBaseWindow();
168 NSWindow* ns_window = app_window->GetNativeWindow(); 170 NSWindow* ns_window = app_window->GetNativeWindow();
169 base::scoped_nsobject<ScopedNotificationWatcher> watcher; 171 base::scoped_nsobject<ScopedNotificationWatcher> watcher;
170 172
171 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, 173 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE,
172 app_window->fullscreen_types_for_test()); 174 app_window->fullscreen_types_for_test());
173 EXPECT_FALSE(window->IsFullscreen()); 175 EXPECT_FALSE(window->IsFullscreen());
174 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); 176 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
175 177
176 watcher.reset([[ScopedNotificationWatcher alloc] 178 watcher.reset([[ScopedNotificationWatcher alloc]
177 initWithNotification:NSWindowDidEnterFullScreenNotification 179 initWithNotification:NSWindowDidEnterFullScreenNotification
178 andObject:ns_window]); 180 andObject:ns_window]);
179 [ns_window toggleFullScreen:nil]; 181 [ns_window toggleFullScreen:nil];
180 [watcher waitForNotification]; 182 [watcher waitForNotification];
181 EXPECT_TRUE(app_window->fullscreen_types_for_test() & 183 EXPECT_TRUE(app_window->fullscreen_types_for_test() &
182 extensions::AppWindow::FULLSCREEN_TYPE_OS); 184 AppWindow::FULLSCREEN_TYPE_OS);
183 EXPECT_TRUE(window->IsFullscreen()); 185 EXPECT_TRUE(window->IsFullscreen());
184 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); 186 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
185 187
186 watcher.reset([[ScopedNotificationWatcher alloc] 188 watcher.reset([[ScopedNotificationWatcher alloc]
187 initWithNotification:NSWindowDidExitFullScreenNotification 189 initWithNotification:NSWindowDidExitFullScreenNotification
188 andObject:ns_window]); 190 andObject:ns_window]);
189 app_window->Restore(); 191 app_window->Restore();
190 EXPECT_FALSE(window->IsFullscreenOrPending()); 192 EXPECT_FALSE(window->IsFullscreenOrPending());
191 [watcher waitForNotification]; 193 [watcher waitForNotification];
192 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, 194 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE,
193 app_window->fullscreen_types_for_test()); 195 app_window->fullscreen_types_for_test());
194 EXPECT_FALSE(window->IsFullscreen()); 196 EXPECT_FALSE(window->IsFullscreen());
195 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); 197 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
196 198
197 watcher.reset([[ScopedNotificationWatcher alloc] 199 watcher.reset([[ScopedNotificationWatcher alloc]
198 initWithNotification:NSWindowDidEnterFullScreenNotification 200 initWithNotification:NSWindowDidEnterFullScreenNotification
199 andObject:ns_window]); 201 andObject:ns_window]);
200 app_window->Fullscreen(); 202 app_window->Fullscreen();
201 EXPECT_TRUE(window->IsFullscreenOrPending()); 203 EXPECT_TRUE(window->IsFullscreenOrPending());
202 [watcher waitForNotification]; 204 [watcher waitForNotification];
203 EXPECT_TRUE(app_window->fullscreen_types_for_test() & 205 EXPECT_TRUE(app_window->fullscreen_types_for_test() &
204 extensions::AppWindow::FULLSCREEN_TYPE_WINDOW_API); 206 AppWindow::FULLSCREEN_TYPE_WINDOW_API);
205 EXPECT_TRUE(window->IsFullscreen()); 207 EXPECT_TRUE(window->IsFullscreen());
206 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); 208 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
207 209
208 watcher.reset([[ScopedNotificationWatcher alloc] 210 watcher.reset([[ScopedNotificationWatcher alloc]
209 initWithNotification:NSWindowDidExitFullScreenNotification 211 initWithNotification:NSWindowDidExitFullScreenNotification
210 andObject:ns_window]); 212 andObject:ns_window]);
211 [ns_window toggleFullScreen:nil]; 213 [ns_window toggleFullScreen:nil];
212 [watcher waitForNotification]; 214 [watcher waitForNotification];
213 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, 215 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE,
214 app_window->fullscreen_types_for_test()); 216 app_window->fullscreen_types_for_test());
215 EXPECT_FALSE(window->IsFullscreen()); 217 EXPECT_FALSE(window->IsFullscreen());
216 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); 218 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
217 } 219 }
218 220
219 // Test that, in frameless windows, the web contents has the same size as the 221 // Test that, in frameless windows, the web contents has the same size as the
220 // window. 222 // window.
221 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Frameless) { 223 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Frameless) {
222 extensions::AppWindow* app_window = 224 AppWindow* app_window = CreateTestAppWindow("{\"frame\": \"none\"}");
223 CreateTestAppWindow("{\"frame\": \"none\"}");
224 NSWindow* ns_window = app_window->GetNativeWindow(); 225 NSWindow* ns_window = app_window->GetNativeWindow();
225 NSView* web_contents = app_window->web_contents()->GetNativeView(); 226 NSView* web_contents = app_window->web_contents()->GetNativeView();
226 EXPECT_TRUE(NSEqualSizes(NSMakeSize(512, 384), [web_contents frame].size)); 227 EXPECT_TRUE(NSEqualSizes(NSMakeSize(512, 384), [web_contents frame].size));
227 // Move and resize the window. 228 // Move and resize the window.
228 NSRect new_frame = NSMakeRect(50, 50, 200, 200); 229 NSRect new_frame = NSMakeRect(50, 50, 200, 200);
229 [ns_window setFrame:new_frame display:YES]; 230 [ns_window setFrame:new_frame display:YES];
230 EXPECT_TRUE(NSEqualSizes(new_frame.size, [web_contents frame].size)); 231 EXPECT_TRUE(NSEqualSizes(new_frame.size, [web_contents frame].size));
231 232
232 // Windows created with NSBorderlessWindowMask by default don't have shadow, 233 // Windows created with NSBorderlessWindowMask by default don't have shadow,
233 // but packaged apps should always have one. 234 // but packaged apps should always have one.
234 EXPECT_TRUE([ns_window hasShadow]); 235 EXPECT_TRUE([ns_window hasShadow]);
235 236
236 // Since the window has no constraints, it should have all of the following 237 // Since the window has no constraints, it should have all of the following
237 // style mask bits. 238 // style mask bits.
238 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | 239 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
239 NSMiniaturizableWindowMask | NSResizableWindowMask | 240 NSMiniaturizableWindowMask | NSResizableWindowMask |
240 NSTexturedBackgroundWindowMask; 241 NSTexturedBackgroundWindowMask;
241 EXPECT_EQ(style_mask, [ns_window styleMask]); 242 EXPECT_EQ(style_mask, [ns_window styleMask]);
242 243
243 CloseAppWindow(app_window); 244 CloseAppWindow(app_window);
244 } 245 }
245 246
246 namespace { 247 namespace {
247 248
248 // Test that resize and fullscreen controls are correctly enabled/disabled. 249 // Test that resize and fullscreen controls are correctly enabled/disabled.
249 void TestControls(extensions::AppWindow* app_window) { 250 void TestControls(AppWindow* app_window) {
250 NSWindow* ns_window = app_window->GetNativeWindow(); 251 NSWindow* ns_window = app_window->GetNativeWindow();
251 252
252 // The window is resizable. 253 // The window is resizable.
253 EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask); 254 EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask);
254 if (base::mac::IsOSSnowLeopard()) 255 if (base::mac::IsOSSnowLeopard())
255 EXPECT_TRUE([ns_window showsResizeIndicator]); 256 EXPECT_TRUE([ns_window showsResizeIndicator]);
256 257
257 // Due to this bug: http://crbug.com/362039, which manifests on the Cocoa 258 // Due to this bug: http://crbug.com/362039, which manifests on the Cocoa
258 // implementation but not the views one, frameless windows should have 259 // implementation but not the views one, frameless windows should have
259 // fullscreen controls disabled. 260 // fullscreen controls disabled.
(...skipping 28 matching lines...) Expand all
288 // Set a minimum size equal to the maximum size. 289 // Set a minimum size equal to the maximum size.
289 app_window->SetContentSizeConstraints(gfx::Size(200, 201), 290 app_window->SetContentSizeConstraints(gfx::Size(200, 201),
290 gfx::Size(200, 201)); 291 gfx::Size(200, 201));
291 EXPECT_EQ(200, [ns_window contentMinSize].width); 292 EXPECT_EQ(200, [ns_window contentMinSize].width);
292 EXPECT_EQ(201, [ns_window contentMinSize].height); 293 EXPECT_EQ(201, [ns_window contentMinSize].height);
293 294
294 // No longer resizable. 295 // No longer resizable.
295 EXPECT_FALSE([ns_window styleMask] & NSResizableWindowMask); 296 EXPECT_FALSE([ns_window styleMask] & NSResizableWindowMask);
296 if (base::mac::IsOSSnowLeopard()) 297 if (base::mac::IsOSSnowLeopard())
297 EXPECT_FALSE([ns_window showsResizeIndicator]); 298 EXPECT_FALSE([ns_window showsResizeIndicator]);
299
300 // If a window is made fullscreen by the API, fullscreen should be enabled so
301 // the user can exit fullscreen.
302 if (base::mac::IsOSLionOrLater()) {
303 base::scoped_nsobject<NSWindowFullscreenNotificationWaiter> waiter([
304 [NSWindowFullscreenNotificationWaiter alloc] initWithWindow:ns_window]);
305 app_window->SetFullscreen(AppWindow::FULLSCREEN_TYPE_WINDOW_API, true);
306 [waiter waitForEnterCount:1 exitCount:0];
307 EXPECT_TRUE([ns_window collectionBehavior] &
308 NSWindowCollectionBehaviorFullScreenPrimary);
309 EXPECT_EQ(NSWidth([[ns_window contentView] frame]),
310 NSWidth([ns_window frame]));
311 // Once it leaves fullscreen, it is disabled again.
312 app_window->SetFullscreen(AppWindow::FULLSCREEN_TYPE_WINDOW_API, false);
313 [waiter waitForEnterCount:1 exitCount:1];
314 EXPECT_FALSE([ns_window collectionBehavior] &
315 NSWindowCollectionBehaviorFullScreenPrimary);
316 }
298 } 317 }
299 318
300 } // namespace 319 } // namespace
301 320
302 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) { 321 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) {
303 TestControls(CreateTestAppWindow("{}")); 322 TestControls(CreateTestAppWindow("{}"));
304 } 323 }
305 324
306 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) { 325 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) {
307 TestControls(CreateTestAppWindow("{\"frame\": \"none\"}")); 326 TestControls(CreateTestAppWindow("{\"frame\": \"none\"}"));
(...skipping 23 matching lines...) Expand all
331 350
332 ScopedFakeNSWindowMainStatus fake_main(ns_window); 351 ScopedFakeNSWindowMainStatus fake_main(ns_window);
333 352
334 [frame_view cacheDisplayInRect:bounds toBitmapImageRep:bitmap]; 353 [frame_view cacheDisplayInRect:bounds toBitmapImageRep:bitmap];
335 color = [bitmap colorAtX:NSMidX(bounds) y:5]; 354 color = [bitmap colorAtX:NSMidX(bounds) y:5];
336 // The window is now active so it should be red (#FF0000). 355 // The window is now active so it should be red (#FF0000).
337 EXPECT_EQ(1, [color redComponent]); 356 EXPECT_EQ(1, [color redComponent]);
338 EXPECT_EQ(0, [color greenComponent]); 357 EXPECT_EQ(0, [color greenComponent]);
339 EXPECT_EQ(0, [color blueComponent]); 358 EXPECT_EQ(0, [color blueComponent]);
340 } 359 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698