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 "chrome/browser/apps/app_browsertest_util.h"
6 #include "extensions/browser/app_window/native_app_window.h"
12 class AppWindowTest
: public PlatformAppBrowserTest
{
14 void CheckAlwaysOnTopToFullscreen(AppWindow
* window
) {
15 ASSERT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
17 // The always-on-top property should be temporarily disabled when the window
20 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
22 // From the API's point of view, the always-on-top property is enabled.
23 EXPECT_TRUE(window
->IsAlwaysOnTop());
25 // The always-on-top property is restored when the window exits fullscreen.
27 EXPECT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
30 void CheckNormalToFullscreen(AppWindow
* window
) {
31 // If the always-on-top property is false, it should remain this way when
32 // entering and exiting fullscreen mode.
33 ASSERT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
35 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
37 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
40 void CheckFullscreenToAlwaysOnTop(AppWindow
* window
) {
41 ASSERT_TRUE(window
->GetBaseWindow()->IsFullscreenOrPending());
43 // Now enable always-on-top at runtime and ensure the property does not get
44 // applied immediately because the window is in fullscreen mode.
45 window
->SetAlwaysOnTop(true);
46 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
48 // From the API's point of view, the always-on-top property is enabled.
49 EXPECT_TRUE(window
->IsAlwaysOnTop());
51 // Ensure the always-on-top property is applied when exiting fullscreen.
53 EXPECT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
59 // Tests are flaky on Mac as transitioning to fullscreen is not instantaneous
60 // and throws errors when entering/exiting fullscreen too quickly.
61 #if defined(OS_MACOSX)
62 #define MAYBE_InitAlwaysOnTopToFullscreen DISABLED_InitAlwaysOnTopToFullscreen
64 #define MAYBE_InitAlwaysOnTopToFullscreen InitAlwaysOnTopToFullscreen
67 // Tests a window created with always-on-top enabled and ensures that the
68 // property is temporarily switched off when entering fullscreen mode.
69 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_InitAlwaysOnTopToFullscreen
) {
70 AppWindow
* window
= CreateTestAppWindow("{ \"alwaysOnTop\": true }");
72 CheckAlwaysOnTopToFullscreen(window
);
74 window
->SetAlwaysOnTop(false);
75 CheckNormalToFullscreen(window
);
77 CloseAppWindow(window
);
80 #if defined(OS_MACOSX)
81 #define MAYBE_RuntimeAlwaysOnTopToFullscreen \
82 DISABLED_RuntimeAlwaysOnTopToFullscreen
84 #define MAYBE_RuntimeAlwaysOnTopToFullscreen RuntimeAlwaysOnTopToFullscreen
87 // Tests a window with always-on-top enabled at runtime and ensures that the
88 // property is temporarily switched off when entering fullscreen mode.
89 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_RuntimeAlwaysOnTopToFullscreen
) {
90 AppWindow
* window
= CreateTestAppWindow("{}");
92 CheckNormalToFullscreen(window
);
94 window
->SetAlwaysOnTop(true);
95 CheckAlwaysOnTopToFullscreen(window
);
97 CloseAppWindow(window
);
100 #if defined(OS_MACOSX)
101 #define MAYBE_InitFullscreenToAlwaysOnTop DISABLED_InitFullscreenToAlwaysOnTop
103 #define MAYBE_InitFullscreenToAlwaysOnTop InitFullscreenToAlwaysOnTop
106 // Tests a window created initially in fullscreen mode and ensures that the
107 // always-on-top property does not get applied until it exits fullscreen.
108 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_InitFullscreenToAlwaysOnTop
) {
109 AppWindow
* window
= CreateTestAppWindow("{ \"state\": \"fullscreen\" }");
111 CheckFullscreenToAlwaysOnTop(window
);
113 CloseAppWindow(window
);
116 #if defined(OS_MACOSX)
117 #define MAYBE_RuntimeFullscreenToAlwaysOnTop \
118 DISABLED_RuntimeFullscreenToAlwaysOnTop
120 #define MAYBE_RuntimeFullscreenToAlwaysOnTop RuntimeFullscreenToAlwaysOnTop
123 // Tests a window that enters fullscreen mode at runtime and ensures that the
124 // always-on-top property does not get applied until it exits fullscreen.
125 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_RuntimeFullscreenToAlwaysOnTop
) {
126 AppWindow
* window
= CreateTestAppWindow("{}");
129 window
->Fullscreen();
130 CheckFullscreenToAlwaysOnTop(window
);
132 CloseAppWindow(window
);
135 #if defined(OS_MACOSX)
136 #define MAYBE_InitFullscreenAndAlwaysOnTop DISABLED_InitFullscreenAndAlwaysOnTop
138 #define MAYBE_InitFullscreenAndAlwaysOnTop InitFullscreenAndAlwaysOnTop
141 // Tests a window created with both fullscreen and always-on-top enabled. Ensure
142 // that always-on-top is only applied when the window exits fullscreen.
143 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_InitFullscreenAndAlwaysOnTop
) {
144 AppWindow
* window
= CreateTestAppWindow(
145 "{ \"alwaysOnTop\": true, \"state\": \"fullscreen\" }");
148 EXPECT_TRUE(window
->GetBaseWindow()->IsFullscreenOrPending());
149 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
151 // From the API's point of view, the always-on-top property is enabled.
152 EXPECT_TRUE(window
->IsAlwaysOnTop());
155 EXPECT_TRUE(window
->GetBaseWindow()->IsAlwaysOnTop());
157 CloseAppWindow(window
);
160 #if defined(OS_MACOSX)
161 #define MAYBE_DisableAlwaysOnTopInFullscreen \
162 DISABLED_DisableAlwaysOnTopInFullscreen
164 #define MAYBE_DisableAlwaysOnTopInFullscreen DisableAlwaysOnTopInFullscreen
167 // Tests a window created with always-on-top enabled, but then disabled while
168 // in fullscreen mode. After exiting fullscreen, always-on-top should remain
170 IN_PROC_BROWSER_TEST_F(AppWindowTest
, MAYBE_DisableAlwaysOnTopInFullscreen
) {
171 AppWindow
* window
= CreateTestAppWindow("{ \"alwaysOnTop\": true }");
174 // Disable always-on-top while in fullscreen mode.
175 window
->Fullscreen();
176 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
177 window
->SetAlwaysOnTop(false);
178 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
180 // Ensure that always-on-top remains disabled.
182 EXPECT_FALSE(window
->GetBaseWindow()->IsAlwaysOnTop());
184 CloseAppWindow(window
);
187 } // namespace extensions