Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / extensions / browser / app_window / app_window_interactive_uitest.cc
blob8de07abd643451511138c4c8717be6d348c88e02
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"
8 namespace extensions {
10 namespace {
12 class AppWindowTest : public PlatformAppBrowserTest {
13 protected:
14 void CheckAlwaysOnTopToFullscreen(AppWindow* window) {
15 ASSERT_TRUE(window->GetBaseWindow()->IsAlwaysOnTop());
17 // The always-on-top property should be temporarily disabled when the window
18 // enters fullscreen.
19 window->Fullscreen();
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.
26 window->Restore();
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());
34 window->Fullscreen();
35 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
36 window->Restore();
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.
52 window->Restore();
53 EXPECT_TRUE(window->GetBaseWindow()->IsAlwaysOnTop());
57 } // namespace
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
63 #else
64 #define MAYBE_InitAlwaysOnTopToFullscreen InitAlwaysOnTopToFullscreen
65 #endif
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 }");
71 ASSERT_TRUE(window);
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
83 #else
84 #define MAYBE_RuntimeAlwaysOnTopToFullscreen RuntimeAlwaysOnTopToFullscreen
85 #endif
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("{}");
91 ASSERT_TRUE(window);
92 CheckNormalToFullscreen(window);
94 window->SetAlwaysOnTop(true);
95 CheckAlwaysOnTopToFullscreen(window);
97 CloseAppWindow(window);
100 #if defined(OS_MACOSX)
101 #define MAYBE_InitFullscreenToAlwaysOnTop DISABLED_InitFullscreenToAlwaysOnTop
102 #else
103 #define MAYBE_InitFullscreenToAlwaysOnTop InitFullscreenToAlwaysOnTop
104 #endif
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\" }");
110 ASSERT_TRUE(window);
111 CheckFullscreenToAlwaysOnTop(window);
113 CloseAppWindow(window);
116 #if defined(OS_MACOSX)
117 #define MAYBE_RuntimeFullscreenToAlwaysOnTop \
118 DISABLED_RuntimeFullscreenToAlwaysOnTop
119 #else
120 #define MAYBE_RuntimeFullscreenToAlwaysOnTop RuntimeFullscreenToAlwaysOnTop
121 #endif
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("{}");
127 ASSERT_TRUE(window);
129 window->Fullscreen();
130 CheckFullscreenToAlwaysOnTop(window);
132 CloseAppWindow(window);
135 #if defined(OS_MACOSX)
136 #define MAYBE_InitFullscreenAndAlwaysOnTop DISABLED_InitFullscreenAndAlwaysOnTop
137 #else
138 #define MAYBE_InitFullscreenAndAlwaysOnTop InitFullscreenAndAlwaysOnTop
139 #endif
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\" }");
146 ASSERT_TRUE(window);
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());
154 window->Restore();
155 EXPECT_TRUE(window->GetBaseWindow()->IsAlwaysOnTop());
157 CloseAppWindow(window);
160 #if defined(OS_MACOSX)
161 #define MAYBE_DisableAlwaysOnTopInFullscreen \
162 DISABLED_DisableAlwaysOnTopInFullscreen
163 #else
164 #define MAYBE_DisableAlwaysOnTopInFullscreen DisableAlwaysOnTopInFullscreen
165 #endif
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
169 // disabled.
170 IN_PROC_BROWSER_TEST_F(AppWindowTest, MAYBE_DisableAlwaysOnTopInFullscreen) {
171 AppWindow* window = CreateTestAppWindow("{ \"alwaysOnTop\": true }");
172 ASSERT_TRUE(window);
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.
181 window->Restore();
182 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
184 CloseAppWindow(window);
187 } // namespace extensions