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 // 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 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
13 #include "base/mac/sdk_forward_declarations.h" | 13 #include "base/mac/sdk_forward_declarations.h" |
14 #include "chrome/browser/apps/app_browsertest_util.h" | 14 #include "chrome/browser/apps/app_browsertest_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/extensions/app_launch_params.h" | 16 #include "chrome/browser/ui/extensions/app_launch_params.h" |
17 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
20 #include "extensions/browser/app_window/app_window_registry.h" | 20 #include "extensions/browser/app_window/app_window_registry.h" |
21 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
22 | 22 |
23 using extensions::AppWindow; | |
23 using extensions::PlatformAppBrowserTest; | 24 using extensions::PlatformAppBrowserTest; |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { | 28 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { |
28 protected: | 29 protected: |
29 NativeAppWindowCocoaBrowserTest() {} | 30 NativeAppWindowCocoaBrowserTest() {} |
30 | 31 |
31 void SetUpAppWithWindows(int num_windows) { | 32 void SetUpAppWithWindows(int num_windows) { |
32 app_ = InstallExtension( | 33 app_ = InstallExtension( |
(...skipping 18 matching lines...) Expand all Loading... | |
51 }; | 52 }; |
52 | 53 |
53 } // namespace | 54 } // namespace |
54 | 55 |
55 // Test interaction of Hide/Show() with Hide/ShowWithApp(). | 56 // Test interaction of Hide/Show() with Hide/ShowWithApp(). |
56 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) { | 57 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) { |
57 SetUpAppWithWindows(2); | 58 SetUpAppWithWindows(2); |
58 extensions::AppWindowRegistry::AppWindowList windows = | 59 extensions::AppWindowRegistry::AppWindowList windows = |
59 extensions::AppWindowRegistry::Get(profile())->app_windows(); | 60 extensions::AppWindowRegistry::Get(profile())->app_windows(); |
60 | 61 |
61 extensions::AppWindow* app_window = windows.front(); | 62 AppWindow* app_window = windows.front(); |
62 extensions::NativeAppWindow* native_window = app_window->GetBaseWindow(); | 63 extensions::NativeAppWindow* native_window = app_window->GetBaseWindow(); |
63 NSWindow* ns_window = native_window->GetNativeWindow(); | 64 NSWindow* ns_window = native_window->GetNativeWindow(); |
64 | 65 |
65 extensions::AppWindow* other_app_window = windows.back(); | 66 AppWindow* other_app_window = windows.back(); |
66 extensions::NativeAppWindow* other_native_window = | 67 extensions::NativeAppWindow* other_native_window = |
67 other_app_window->GetBaseWindow(); | 68 other_app_window->GetBaseWindow(); |
68 NSWindow* other_ns_window = other_native_window->GetNativeWindow(); | 69 NSWindow* other_ns_window = other_native_window->GetNativeWindow(); |
69 | 70 |
70 // Normal Hide/Show. | 71 // Normal Hide/Show. |
71 app_window->Hide(); | 72 app_window->Hide(); |
72 EXPECT_FALSE([ns_window isVisible]); | 73 EXPECT_FALSE([ns_window isVisible]); |
73 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); | 74 app_window->Show(AppWindow::SHOW_ACTIVE); |
74 EXPECT_TRUE([ns_window isVisible]); | 75 EXPECT_TRUE([ns_window isVisible]); |
75 | 76 |
76 // Normal Hide/ShowWithApp. | 77 // Normal Hide/ShowWithApp. |
77 native_window->HideWithApp(); | 78 native_window->HideWithApp(); |
78 EXPECT_FALSE([ns_window isVisible]); | 79 EXPECT_FALSE([ns_window isVisible]); |
79 native_window->ShowWithApp(); | 80 native_window->ShowWithApp(); |
80 EXPECT_TRUE([ns_window isVisible]); | 81 EXPECT_TRUE([ns_window isVisible]); |
81 | 82 |
82 // HideWithApp, Hide, ShowWithApp does not show. | 83 // HideWithApp, Hide, ShowWithApp does not show. |
83 native_window->HideWithApp(); | 84 native_window->HideWithApp(); |
84 app_window->Hide(); | 85 app_window->Hide(); |
85 native_window->ShowWithApp(); | 86 native_window->ShowWithApp(); |
86 EXPECT_FALSE([ns_window isVisible]); | 87 EXPECT_FALSE([ns_window isVisible]); |
87 | 88 |
88 // Hide, HideWithApp, ShowWithApp does not show. | 89 // Hide, HideWithApp, ShowWithApp does not show. |
89 native_window->HideWithApp(); | 90 native_window->HideWithApp(); |
90 native_window->ShowWithApp(); | 91 native_window->ShowWithApp(); |
91 EXPECT_FALSE([ns_window isVisible]); | 92 EXPECT_FALSE([ns_window isVisible]); |
92 | 93 |
93 // Return to shown state. | 94 // Return to shown state. |
94 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); | 95 app_window->Show(AppWindow::SHOW_ACTIVE); |
95 EXPECT_TRUE([ns_window isVisible]); | 96 EXPECT_TRUE([ns_window isVisible]); |
96 | 97 |
97 // HideWithApp the other window. | 98 // HideWithApp the other window. |
98 EXPECT_TRUE([other_ns_window isVisible]); | 99 EXPECT_TRUE([other_ns_window isVisible]); |
99 other_native_window->HideWithApp(); | 100 other_native_window->HideWithApp(); |
100 EXPECT_FALSE([other_ns_window isVisible]); | 101 EXPECT_FALSE([other_ns_window isVisible]); |
101 | 102 |
102 // HideWithApp, Show shows all windows for this app. | 103 // HideWithApp, Show shows all windows for this app. |
103 native_window->HideWithApp(); | 104 native_window->HideWithApp(); |
104 EXPECT_FALSE([ns_window isVisible]); | 105 EXPECT_FALSE([ns_window isVisible]); |
105 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); | 106 app_window->Show(AppWindow::SHOW_ACTIVE); |
106 EXPECT_TRUE([ns_window isVisible]); | 107 EXPECT_TRUE([ns_window isVisible]); |
107 EXPECT_TRUE([other_ns_window isVisible]); | 108 EXPECT_TRUE([other_ns_window isVisible]); |
108 | 109 |
109 // Hide the other window. | 110 // Hide the other window. |
110 other_app_window->Hide(); | 111 other_app_window->Hide(); |
111 EXPECT_FALSE([other_ns_window isVisible]); | 112 EXPECT_FALSE([other_ns_window isVisible]); |
112 | 113 |
113 // HideWithApp, ShowWithApp does not show the other window. | 114 // HideWithApp, ShowWithApp does not show the other window. |
114 native_window->HideWithApp(); | 115 native_window->HideWithApp(); |
115 EXPECT_FALSE([ns_window isVisible]); | 116 EXPECT_FALSE([ns_window isVisible]); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 | 155 |
155 @end | 156 @end |
156 | 157 |
157 // Test that NativeAppWindow and AppWindow fullscreen state is updated when | 158 // Test that NativeAppWindow and AppWindow fullscreen state is updated when |
158 // the window is fullscreened natively. | 159 // the window is fullscreened natively. |
159 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { | 160 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { |
160 if (!base::mac::IsOSLionOrLater()) | 161 if (!base::mac::IsOSLionOrLater()) |
161 return; | 162 return; |
162 | 163 |
163 SetUpAppWithWindows(1); | 164 SetUpAppWithWindows(1); |
164 extensions::AppWindow* app_window = GetFirstAppWindow(); | 165 AppWindow* app_window = GetFirstAppWindow(); |
165 extensions::NativeAppWindow* window = app_window->GetBaseWindow(); | 166 extensions::NativeAppWindow* window = app_window->GetBaseWindow(); |
166 NSWindow* ns_window = app_window->GetNativeWindow(); | 167 NSWindow* ns_window = app_window->GetNativeWindow(); |
167 base::scoped_nsobject<ScopedNotificationWatcher> watcher; | 168 base::scoped_nsobject<ScopedNotificationWatcher> watcher; |
168 | 169 |
169 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, | 170 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, |
170 app_window->fullscreen_types_for_test()); | 171 app_window->fullscreen_types_for_test()); |
171 EXPECT_FALSE(window->IsFullscreen()); | 172 EXPECT_FALSE(window->IsFullscreen()); |
172 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 173 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
173 | 174 |
174 watcher.reset([[ScopedNotificationWatcher alloc] | 175 watcher.reset([[ScopedNotificationWatcher alloc] |
175 initWithNotification:NSWindowDidEnterFullScreenNotification | 176 initWithNotification:NSWindowDidEnterFullScreenNotification |
176 andObject:ns_window]); | 177 andObject:ns_window]); |
177 [ns_window toggleFullScreen:nil]; | 178 [ns_window toggleFullScreen:nil]; |
178 [watcher waitForNotification]; | 179 [watcher waitForNotification]; |
179 EXPECT_TRUE(app_window->fullscreen_types_for_test() & | 180 EXPECT_TRUE(app_window->fullscreen_types_for_test() & |
180 extensions::AppWindow::FULLSCREEN_TYPE_OS); | 181 AppWindow::FULLSCREEN_TYPE_OS); |
181 EXPECT_TRUE(window->IsFullscreen()); | 182 EXPECT_TRUE(window->IsFullscreen()); |
182 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | 183 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
183 | 184 |
184 watcher.reset([[ScopedNotificationWatcher alloc] | 185 watcher.reset([[ScopedNotificationWatcher alloc] |
185 initWithNotification:NSWindowDidExitFullScreenNotification | 186 initWithNotification:NSWindowDidExitFullScreenNotification |
186 andObject:ns_window]); | 187 andObject:ns_window]); |
187 app_window->Restore(); | 188 app_window->Restore(); |
188 EXPECT_FALSE(window->IsFullscreenOrPending()); | 189 EXPECT_FALSE(window->IsFullscreenOrPending()); |
189 [watcher waitForNotification]; | 190 [watcher waitForNotification]; |
190 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, | 191 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, |
191 app_window->fullscreen_types_for_test()); | 192 app_window->fullscreen_types_for_test()); |
192 EXPECT_FALSE(window->IsFullscreen()); | 193 EXPECT_FALSE(window->IsFullscreen()); |
193 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 194 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
194 | 195 |
195 watcher.reset([[ScopedNotificationWatcher alloc] | 196 watcher.reset([[ScopedNotificationWatcher alloc] |
196 initWithNotification:NSWindowDidEnterFullScreenNotification | 197 initWithNotification:NSWindowDidEnterFullScreenNotification |
197 andObject:ns_window]); | 198 andObject:ns_window]); |
198 app_window->Fullscreen(); | 199 app_window->Fullscreen(); |
199 EXPECT_TRUE(window->IsFullscreenOrPending()); | 200 EXPECT_TRUE(window->IsFullscreenOrPending()); |
200 [watcher waitForNotification]; | 201 [watcher waitForNotification]; |
201 EXPECT_TRUE(app_window->fullscreen_types_for_test() & | 202 EXPECT_TRUE(app_window->fullscreen_types_for_test() & |
202 extensions::AppWindow::FULLSCREEN_TYPE_WINDOW_API); | 203 AppWindow::FULLSCREEN_TYPE_WINDOW_API); |
203 EXPECT_TRUE(window->IsFullscreen()); | 204 EXPECT_TRUE(window->IsFullscreen()); |
204 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | 205 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
205 | 206 |
206 watcher.reset([[ScopedNotificationWatcher alloc] | 207 watcher.reset([[ScopedNotificationWatcher alloc] |
207 initWithNotification:NSWindowDidExitFullScreenNotification | 208 initWithNotification:NSWindowDidExitFullScreenNotification |
208 andObject:ns_window]); | 209 andObject:ns_window]); |
209 [ns_window toggleFullScreen:nil]; | 210 [ns_window toggleFullScreen:nil]; |
210 [watcher waitForNotification]; | 211 [watcher waitForNotification]; |
211 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, | 212 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, |
212 app_window->fullscreen_types_for_test()); | 213 app_window->fullscreen_types_for_test()); |
213 EXPECT_FALSE(window->IsFullscreen()); | 214 EXPECT_FALSE(window->IsFullscreen()); |
214 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 215 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
215 } | 216 } |
216 | 217 |
217 // Test that, in frameless windows, the web contents has the same size as the | 218 // Test that, in frameless windows, the web contents has the same size as the |
218 // window. | 219 // window. |
219 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Frameless) { | 220 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Frameless) { |
220 extensions::AppWindow* app_window = | 221 AppWindow* app_window = CreateTestAppWindow("{\"frame\": \"none\"}"); |
221 CreateTestAppWindow("{\"frame\": \"none\"}"); | |
222 NSWindow* ns_window = app_window->GetNativeWindow(); | 222 NSWindow* ns_window = app_window->GetNativeWindow(); |
223 NSView* web_contents = app_window->web_contents()->GetNativeView(); | 223 NSView* web_contents = app_window->web_contents()->GetNativeView(); |
224 EXPECT_TRUE(NSEqualSizes(NSMakeSize(512, 384), [web_contents frame].size)); | 224 EXPECT_TRUE(NSEqualSizes(NSMakeSize(512, 384), [web_contents frame].size)); |
225 // Move and resize the window. | 225 // Move and resize the window. |
226 NSRect new_frame = NSMakeRect(50, 50, 200, 200); | 226 NSRect new_frame = NSMakeRect(50, 50, 200, 200); |
227 [ns_window setFrame:new_frame display:YES]; | 227 [ns_window setFrame:new_frame display:YES]; |
228 EXPECT_TRUE(NSEqualSizes(new_frame.size, [web_contents frame].size)); | 228 EXPECT_TRUE(NSEqualSizes(new_frame.size, [web_contents frame].size)); |
229 | 229 |
230 // Windows created with NSBorderlessWindowMask by default don't have shadow, | 230 // Windows created with NSBorderlessWindowMask by default don't have shadow, |
231 // but packaged apps should always have one. | 231 // but packaged apps should always have one. |
232 EXPECT_TRUE([ns_window hasShadow]); | 232 EXPECT_TRUE([ns_window hasShadow]); |
233 | 233 |
234 // Since the window has no constraints, it should have all of the following | 234 // Since the window has no constraints, it should have all of the following |
235 // style mask bits. | 235 // style mask bits. |
236 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | | 236 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
237 NSMiniaturizableWindowMask | NSResizableWindowMask | | 237 NSMiniaturizableWindowMask | NSResizableWindowMask | |
238 NSTexturedBackgroundWindowMask; | 238 NSTexturedBackgroundWindowMask; |
239 EXPECT_EQ(style_mask, [ns_window styleMask]); | 239 EXPECT_EQ(style_mask, [ns_window styleMask]); |
240 | 240 |
241 CloseAppWindow(app_window); | 241 CloseAppWindow(app_window); |
242 } | 242 } |
243 | 243 |
244 namespace { | 244 namespace { |
245 | 245 |
246 // Test that resize and fullscreen controls are correctly enabled/disabled. | 246 // Test that resize and fullscreen controls are correctly enabled/disabled. |
247 void TestControls(extensions::AppWindow* app_window) { | 247 void TestControls(AppWindow* app_window) { |
248 NSWindow* ns_window = app_window->GetNativeWindow(); | 248 NSWindow* ns_window = app_window->GetNativeWindow(); |
249 | 249 |
250 // The window is resizable. | 250 // The window is resizable. |
251 EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask); | 251 EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask); |
252 if (base::mac::IsOSSnowLeopard()) | 252 if (base::mac::IsOSSnowLeopard()) |
253 EXPECT_TRUE([ns_window showsResizeIndicator]); | 253 EXPECT_TRUE([ns_window showsResizeIndicator]); |
254 | 254 |
255 // Due to this bug: http://crbug.com/362039, which manifests on the Cocoa | 255 // Due to this bug: http://crbug.com/362039, which manifests on the Cocoa |
256 // implementation but not the views one, frameless windows should have | 256 // implementation but not the views one, frameless windows should have |
257 // fullscreen controls disabled. | 257 // fullscreen controls disabled. |
(...skipping 28 matching lines...) Expand all Loading... | |
286 // Set a minimum size equal to the maximum size. | 286 // Set a minimum size equal to the maximum size. |
287 app_window->SetContentSizeConstraints(gfx::Size(200, 201), | 287 app_window->SetContentSizeConstraints(gfx::Size(200, 201), |
288 gfx::Size(200, 201)); | 288 gfx::Size(200, 201)); |
289 EXPECT_EQ(200, [ns_window contentMinSize].width); | 289 EXPECT_EQ(200, [ns_window contentMinSize].width); |
290 EXPECT_EQ(201, [ns_window contentMinSize].height); | 290 EXPECT_EQ(201, [ns_window contentMinSize].height); |
291 | 291 |
292 // No longer resizable. | 292 // No longer resizable. |
293 EXPECT_FALSE([ns_window styleMask] & NSResizableWindowMask); | 293 EXPECT_FALSE([ns_window styleMask] & NSResizableWindowMask); |
294 if (base::mac::IsOSSnowLeopard()) | 294 if (base::mac::IsOSSnowLeopard()) |
295 EXPECT_FALSE([ns_window showsResizeIndicator]); | 295 EXPECT_FALSE([ns_window showsResizeIndicator]); |
296 | |
297 // If a window is made fullscreen by the API, fullscreen should be enabled so | |
298 // the user can exit fullscreen. | |
299 if (base::mac::IsOSLionOrLater()) { | |
300 app_window->SetFullscreen(AppWindow::FULLSCREEN_TYPE_WINDOW_API, true); | |
301 EXPECT_TRUE([ns_window collectionBehavior] & | |
302 NSWindowCollectionBehaviorFullScreenPrimary); | |
303 // Once it leaves fullscreen, it is disabled again. | |
304 app_window->SetFullscreen(AppWindow::FULLSCREEN_TYPE_WINDOW_API, false); | |
305 EXPECT_FALSE([ns_window collectionBehavior] & | |
jackhou1
2015/04/24 07:03:01
This line fails. Probably need to wait for the ani
tapted
2015/05/06 06:20:41
bridged_native_widget_interactive_uitest.mm has so
jackhou1
2015/05/13 04:27:53
Done.
| |
306 NSWindowCollectionBehaviorFullScreenPrimary); | |
307 } | |
296 } | 308 } |
297 | 309 |
298 } // namespace | 310 } // namespace |
299 | 311 |
300 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) { | 312 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) { |
301 TestControls(CreateTestAppWindow("{}")); | 313 TestControls(CreateTestAppWindow("{}")); |
302 } | 314 } |
303 | 315 |
304 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) { | 316 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) { |
305 TestControls(CreateTestAppWindow("{\"frame\": \"none\"}")); | 317 TestControls(CreateTestAppWindow("{\"frame\": \"none\"}")); |
306 } | 318 } |
OLD | NEW |