1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "apps/ui/native_app_window.h"
6 #include "chrome/browser/apps/app_browsertest_util.h"
8 using extensions::PlatformAppBrowserTest
;
9 using extensions::Extension
;
15 class AppWindowTest
: public PlatformAppBrowserTest
{
17 void CheckAlwaysOnTopToFullscreen(AppWindow
* window
) {
18 ASSERT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
20 // The always-on-top property should be temporarily disabled when the window
23 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
25 // From the API's point of view, the always-on-top property is enabled.
26 EXPECT_TRUE(window
->IsAlwaysOnTop());
28 // The always-on-top property is restored when the window exits fullscreen.
30 EXPECT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
33 void CheckNormalToFullscreen(AppWindow
* window
) {
34 // If the always-on-top property is false, it should remain this way when
35 // entering and exiting fullscreen mode.
36 ASSERT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
38 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
40 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
43 void CheckFullscreenToAlwaysOnTop(AppWindow
* window
) {
44 ASSERT_TRUE(window
->GetBaseWindow()->IsFullscreenOrPending());
46 // Now enable always-on-top at runtime and ensure the property does not get
47 // applied immediately because the window is in fullscreen mode.
48 window
->SetAlwaysOnTop(true);
49 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
51 // From the API's point of view, the always-on-top property is enabled.
52 EXPECT_TRUE(window
->IsAlwaysOnTop());
54 // Ensure the always-on-top property is applied when exiting fullscreen.
56 EXPECT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
62 // Tests are flaky on Mac as transitioning to fullscreen is not instantaneous
63 // and throws errors when entering/exiting fullscreen too quickly.
64 #if defined(OS_MACOSX)
65 #define MAYBE_InitAlwaysOnTopToFullscreen DISABLED_InitAlwaysOnTopToFullscreen
67 #define MAYBE_InitAlwaysOnTopToFullscreen InitAlwaysOnTopToFullscreen
70 // Tests a window created with always-on-top enabled and ensures that the
71 // property is temporarily switched off when entering fullscreen mode.
72 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_InitAlwaysOnTopToFullscreen
) {
73 AppWindow
* window
= CreateTestAppWindow("{ \"alwaysOnTop\": true }");
75 CheckAlwaysOnTopToFullscreen(window
);
77 window
->SetAlwaysOnTop(false);
78 CheckNormalToFullscreen(window
);
80 CloseAppWindow(window
);
83 #if defined(OS_MACOSX)
84 #define MAYBE_RuntimeAlwaysOnTopToFullscreen \
85 DISABLED_RuntimeAlwaysOnTopToFullscreen
87 #define MAYBE_RuntimeAlwaysOnTopToFullscreen RuntimeAlwaysOnTopToFullscreen
90 // Tests a window with always-on-top enabled at runtime and ensures that the
91 // property is temporarily switched off when entering fullscreen mode.
92 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_RuntimeAlwaysOnTopToFullscreen
) {
93 AppWindow
* window
= CreateTestAppWindow("{}");
95 CheckNormalToFullscreen(window
);
97 window
->SetAlwaysOnTop(true);
98 CheckAlwaysOnTopToFullscreen(window
);
100 CloseAppWindow(window
);
103 #if defined(OS_MACOSX)
104 #define MAYBE_InitFullscreenToAlwaysOnTop DISABLED_InitFullscreenToAlwaysOnTop
106 #define MAYBE_InitFullscreenToAlwaysOnTop InitFullscreenToAlwaysOnTop
109 // Tests a window created initially in fullscreen mode and ensures that the
110 // always-on-top property does not get applied until it exits fullscreen.
111 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_InitFullscreenToAlwaysOnTop
) {
112 AppWindow
* window
= CreateTestAppWindow("{ \"state\": \"fullscreen\" }");
114 CheckFullscreenToAlwaysOnTop(window
);
116 CloseAppWindow(window
);
119 #if defined(OS_MACOSX)
120 #define MAYBE_RuntimeFullscreenToAlwaysOnTop \
121 DISABLED_RuntimeFullscreenToAlwaysOnTop
123 #define MAYBE_RuntimeFullscreenToAlwaysOnTop RuntimeFullscreenToAlwaysOnTop
126 // Tests a window that enters fullscreen mode at runtime and ensures that the
127 // always-on-top property does not get applied until it exits fullscreen.
128 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_RuntimeFullscreenToAlwaysOnTop
) {
129 AppWindow
* window
= CreateTestAppWindow("{}");
132 window
->Fullscreen();
133 CheckFullscreenToAlwaysOnTop(window
);
135 CloseAppWindow(window
);
138 #if defined(OS_MACOSX)
139 #define MAYBE_InitFullscreenAndAlwaysOnTop DISABLED_InitFullscreenAndAlwaysOnTop
141 #define MAYBE_InitFullscreenAndAlwaysOnTop InitFullscreenAndAlwaysOnTop
144 // Tests a window created with both fullscreen and always-on-top enabled. Ensure
145 // that always-on-top is only applied when the window exits fullscreen.
146 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_InitFullscreenAndAlwaysOnTop
) {
147 AppWindow
* window
= CreateTestAppWindow(
148 "{ \"alwaysOnTop\": true, \"state\": \"fullscreen\" }");
151 EXPECT_TRUE(window
->GetBaseWindow()->IsFullscreenOrPending());
152 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
154 // From the API's point of view, the always-on-top property is enabled.
155 EXPECT_TRUE(window
->IsAlwaysOnTop());
158 EXPECT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
160 CloseAppWindow(window
);
163 #if defined(OS_MACOSX)
164 #define MAYBE_DisableAlwaysOnTopInFullscreen \
165 DISABLED_DisableAlwaysOnTopInFullscreen
167 #define MAYBE_DisableAlwaysOnTopInFullscreen DisableAlwaysOnTopInFullscreen
170 // Tests a window created with always-on-top enabled, but then disabled while
171 // in fullscreen mode. After exiting fullscreen, always-on-top should remain
173 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_DisableAlwaysOnTopInFullscreen
) {
174 AppWindow
* window
= CreateTestAppWindow("{ \"alwaysOnTop\": true }");
177 // Disable always-on-top while in fullscreen mode.
178 window
->Fullscreen();
179 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
180 window
->SetAlwaysOnTop(false);
181 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
183 // Ensure that always-on-top remains disabled.
185 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
187 CloseAppWindow(window
);