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" | |
10 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
11 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
12 #include "chrome/browser/apps/app_browsertest_util.h" | 11 #include "chrome/browser/apps/app_browsertest_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/extensions/application_launch.h" | 13 #include "chrome/browser/ui/extensions/application_launch.h" |
15 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
16 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 16 #include "extensions/browser/app_window/app_window_registry.h" |
17 | 17 |
18 using extensions::PlatformAppBrowserTest; | 18 using extensions::PlatformAppBrowserTest; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { | 22 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { |
23 protected: | 23 protected: |
24 NativeAppWindowCocoaBrowserTest() {} | 24 NativeAppWindowCocoaBrowserTest() {} |
25 | 25 |
26 void SetUpAppWithWindows(int num_windows) { | 26 void SetUpAppWithWindows(int num_windows) { |
(...skipping 18 matching lines...) Expand all Loading... |
45 | 45 |
46 private: | 46 private: |
47 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest); | 47 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest); |
48 }; | 48 }; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 // Test interaction of Hide/Show() with Hide/ShowWithApp(). | 52 // Test interaction of Hide/Show() with Hide/ShowWithApp(). |
53 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) { | 53 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) { |
54 SetUpAppWithWindows(2); | 54 SetUpAppWithWindows(2); |
55 apps::AppWindowRegistry::AppWindowList windows = | 55 extensions::AppWindowRegistry::AppWindowList windows = |
56 apps::AppWindowRegistry::Get(profile())->app_windows(); | 56 extensions::AppWindowRegistry::Get(profile())->app_windows(); |
57 | 57 |
58 apps::AppWindow* app_window = windows.front(); | 58 extensions::AppWindow* app_window = windows.front(); |
59 extensions::NativeAppWindow* native_window = app_window->GetBaseWindow(); | 59 extensions::NativeAppWindow* native_window = app_window->GetBaseWindow(); |
60 NSWindow* ns_window = native_window->GetNativeWindow(); | 60 NSWindow* ns_window = native_window->GetNativeWindow(); |
61 | 61 |
62 apps::AppWindow* other_app_window = windows.back(); | 62 extensions::AppWindow* other_app_window = windows.back(); |
63 extensions::NativeAppWindow* other_native_window = | 63 extensions::NativeAppWindow* other_native_window = |
64 other_app_window->GetBaseWindow(); | 64 other_app_window->GetBaseWindow(); |
65 NSWindow* other_ns_window = other_native_window->GetNativeWindow(); | 65 NSWindow* other_ns_window = other_native_window->GetNativeWindow(); |
66 | 66 |
67 // Normal Hide/Show. | 67 // Normal Hide/Show. |
68 app_window->Hide(); | 68 app_window->Hide(); |
69 EXPECT_FALSE([ns_window isVisible]); | 69 EXPECT_FALSE([ns_window isVisible]); |
70 app_window->Show(apps::AppWindow::SHOW_ACTIVE); | 70 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); |
71 EXPECT_TRUE([ns_window isVisible]); | 71 EXPECT_TRUE([ns_window isVisible]); |
72 | 72 |
73 // Normal Hide/ShowWithApp. | 73 // Normal Hide/ShowWithApp. |
74 native_window->HideWithApp(); | 74 native_window->HideWithApp(); |
75 EXPECT_FALSE([ns_window isVisible]); | 75 EXPECT_FALSE([ns_window isVisible]); |
76 native_window->ShowWithApp(); | 76 native_window->ShowWithApp(); |
77 EXPECT_TRUE([ns_window isVisible]); | 77 EXPECT_TRUE([ns_window isVisible]); |
78 | 78 |
79 // HideWithApp, Hide, ShowWithApp does not show. | 79 // HideWithApp, Hide, ShowWithApp does not show. |
80 native_window->HideWithApp(); | 80 native_window->HideWithApp(); |
81 app_window->Hide(); | 81 app_window->Hide(); |
82 native_window->ShowWithApp(); | 82 native_window->ShowWithApp(); |
83 EXPECT_FALSE([ns_window isVisible]); | 83 EXPECT_FALSE([ns_window isVisible]); |
84 | 84 |
85 // Hide, HideWithApp, ShowWithApp does not show. | 85 // Hide, HideWithApp, ShowWithApp does not show. |
86 native_window->HideWithApp(); | 86 native_window->HideWithApp(); |
87 native_window->ShowWithApp(); | 87 native_window->ShowWithApp(); |
88 EXPECT_FALSE([ns_window isVisible]); | 88 EXPECT_FALSE([ns_window isVisible]); |
89 | 89 |
90 // Return to shown state. | 90 // Return to shown state. |
91 app_window->Show(apps::AppWindow::SHOW_ACTIVE); | 91 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); |
92 EXPECT_TRUE([ns_window isVisible]); | 92 EXPECT_TRUE([ns_window isVisible]); |
93 | 93 |
94 // HideWithApp the other window. | 94 // HideWithApp the other window. |
95 EXPECT_TRUE([other_ns_window isVisible]); | 95 EXPECT_TRUE([other_ns_window isVisible]); |
96 other_native_window->HideWithApp(); | 96 other_native_window->HideWithApp(); |
97 EXPECT_FALSE([other_ns_window isVisible]); | 97 EXPECT_FALSE([other_ns_window isVisible]); |
98 | 98 |
99 // HideWithApp, Show shows all windows for this app. | 99 // HideWithApp, Show shows all windows for this app. |
100 native_window->HideWithApp(); | 100 native_window->HideWithApp(); |
101 EXPECT_FALSE([ns_window isVisible]); | 101 EXPECT_FALSE([ns_window isVisible]); |
102 app_window->Show(apps::AppWindow::SHOW_ACTIVE); | 102 app_window->Show(extensions::AppWindow::SHOW_ACTIVE); |
103 EXPECT_TRUE([ns_window isVisible]); | 103 EXPECT_TRUE([ns_window isVisible]); |
104 EXPECT_TRUE([other_ns_window isVisible]); | 104 EXPECT_TRUE([other_ns_window isVisible]); |
105 | 105 |
106 // Hide the other window. | 106 // Hide the other window. |
107 other_app_window->Hide(); | 107 other_app_window->Hide(); |
108 EXPECT_FALSE([other_ns_window isVisible]); | 108 EXPECT_FALSE([other_ns_window isVisible]); |
109 | 109 |
110 // HideWithApp, ShowWithApp does not show the other window. | 110 // HideWithApp, ShowWithApp does not show the other window. |
111 native_window->HideWithApp(); | 111 native_window->HideWithApp(); |
112 EXPECT_FALSE([ns_window isVisible]); | 112 EXPECT_FALSE([ns_window isVisible]); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 @end | 164 @end |
165 | 165 |
166 // Test that NativeAppWindow and AppWindow fullscreen state is updated when | 166 // Test that NativeAppWindow and AppWindow fullscreen state is updated when |
167 // the window is fullscreened natively. | 167 // the window is fullscreened natively. |
168 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { | 168 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { |
169 if (!base::mac::IsOSLionOrLater()) | 169 if (!base::mac::IsOSLionOrLater()) |
170 return; | 170 return; |
171 | 171 |
172 SetUpAppWithWindows(1); | 172 SetUpAppWithWindows(1); |
173 apps::AppWindow* app_window = GetFirstAppWindow(); | 173 extensions::AppWindow* app_window = GetFirstAppWindow(); |
174 extensions::NativeAppWindow* window = app_window->GetBaseWindow(); | 174 extensions::NativeAppWindow* window = app_window->GetBaseWindow(); |
175 NSWindow* ns_window = app_window->GetNativeWindow(); | 175 NSWindow* ns_window = app_window->GetNativeWindow(); |
176 base::scoped_nsobject<ScopedNotificationWatcher> watcher; | 176 base::scoped_nsobject<ScopedNotificationWatcher> watcher; |
177 | 177 |
178 EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE, | 178 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, |
179 app_window->fullscreen_types_for_test()); | 179 app_window->fullscreen_types_for_test()); |
180 EXPECT_FALSE(window->IsFullscreen()); | 180 EXPECT_FALSE(window->IsFullscreen()); |
181 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 181 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
182 | 182 |
183 watcher.reset([[ScopedNotificationWatcher alloc] | 183 watcher.reset([[ScopedNotificationWatcher alloc] |
184 initWithNotification:NSWindowDidEnterFullScreenNotification | 184 initWithNotification:NSWindowDidEnterFullScreenNotification |
185 andObject:ns_window]); | 185 andObject:ns_window]); |
186 [ns_window toggleFullScreen:nil]; | 186 [ns_window toggleFullScreen:nil]; |
187 [watcher waitForNotification]; | 187 [watcher waitForNotification]; |
188 EXPECT_TRUE(app_window->fullscreen_types_for_test() & | 188 EXPECT_TRUE(app_window->fullscreen_types_for_test() & |
189 apps::AppWindow::FULLSCREEN_TYPE_OS); | 189 extensions::AppWindow::FULLSCREEN_TYPE_OS); |
190 EXPECT_TRUE(window->IsFullscreen()); | 190 EXPECT_TRUE(window->IsFullscreen()); |
191 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | 191 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
192 | 192 |
193 watcher.reset([[ScopedNotificationWatcher alloc] | 193 watcher.reset([[ScopedNotificationWatcher alloc] |
194 initWithNotification:NSWindowDidExitFullScreenNotification | 194 initWithNotification:NSWindowDidExitFullScreenNotification |
195 andObject:ns_window]); | 195 andObject:ns_window]); |
196 app_window->Restore(); | 196 app_window->Restore(); |
197 EXPECT_FALSE(window->IsFullscreenOrPending()); | 197 EXPECT_FALSE(window->IsFullscreenOrPending()); |
198 [watcher waitForNotification]; | 198 [watcher waitForNotification]; |
199 EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE, | 199 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, |
200 app_window->fullscreen_types_for_test()); | 200 app_window->fullscreen_types_for_test()); |
201 EXPECT_FALSE(window->IsFullscreen()); | 201 EXPECT_FALSE(window->IsFullscreen()); |
202 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 202 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
203 | 203 |
204 watcher.reset([[ScopedNotificationWatcher alloc] | 204 watcher.reset([[ScopedNotificationWatcher alloc] |
205 initWithNotification:NSWindowDidEnterFullScreenNotification | 205 initWithNotification:NSWindowDidEnterFullScreenNotification |
206 andObject:ns_window]); | 206 andObject:ns_window]); |
207 app_window->Fullscreen(); | 207 app_window->Fullscreen(); |
208 EXPECT_TRUE(window->IsFullscreenOrPending()); | 208 EXPECT_TRUE(window->IsFullscreenOrPending()); |
209 [watcher waitForNotification]; | 209 [watcher waitForNotification]; |
210 EXPECT_TRUE(app_window->fullscreen_types_for_test() & | 210 EXPECT_TRUE(app_window->fullscreen_types_for_test() & |
211 apps::AppWindow::FULLSCREEN_TYPE_WINDOW_API); | 211 extensions::AppWindow::FULLSCREEN_TYPE_WINDOW_API); |
212 EXPECT_TRUE(window->IsFullscreen()); | 212 EXPECT_TRUE(window->IsFullscreen()); |
213 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | 213 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
214 | 214 |
215 watcher.reset([[ScopedNotificationWatcher alloc] | 215 watcher.reset([[ScopedNotificationWatcher alloc] |
216 initWithNotification:NSWindowDidExitFullScreenNotification | 216 initWithNotification:NSWindowDidExitFullScreenNotification |
217 andObject:ns_window]); | 217 andObject:ns_window]); |
218 [ns_window toggleFullScreen:nil]; | 218 [ns_window toggleFullScreen:nil]; |
219 [watcher waitForNotification]; | 219 [watcher waitForNotification]; |
220 EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE, | 220 EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE, |
221 app_window->fullscreen_types_for_test()); | 221 app_window->fullscreen_types_for_test()); |
222 EXPECT_FALSE(window->IsFullscreen()); | 222 EXPECT_FALSE(window->IsFullscreen()); |
223 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 223 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
224 } | 224 } |
OLD | NEW |