Introduce SetName and SetDiscoverable functions to BluetoothAdapter.
[chromium-blink-merge.git] / apps / shell_window_interactive_uitest.cc
blob69f5563f7f6b8c4f20c68eb779832f2746a50d16
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
3 // found in the LICENSE file.
5 #include "apps/ui/native_app_window.h"
6 #include "chrome/browser/apps/app_browsertest_util.h"
7 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 using extensions::PlatformAppBrowserTest;
10 using extensions::Extension;
12 namespace apps {
14 namespace {
16 const char kDefaultTestApp[] = "shell_window/generic";
18 class ShellWindowTest : public PlatformAppBrowserTest {
19 protected:
20 // Load the test app and create a window. The window must be closed by the
21 // caller in order to terminate the test.
22 // |app_path| is the name of the test.
23 // |window_create_options| are the options that will be passed to
24 // chrome.app.window.create() in the test app.
25 ShellWindow* OpenWindow(const char* app_path,
26 const char* window_create_options) {
27 ExtensionTestMessageListener launched_listener("launched", true);
28 ExtensionTestMessageListener loaded_listener("window_loaded", false);
30 // Load and launch the test app.
31 const Extension* extension = LoadAndLaunchPlatformApp(app_path);
32 EXPECT_TRUE(extension);
33 EXPECT_TRUE(launched_listener.WaitUntilSatisfied());
35 // Send the options for window creation.
36 launched_listener.Reply(window_create_options);
38 // Wait for the window to be opened and loaded.
39 EXPECT_TRUE(loaded_listener.WaitUntilSatisfied());
41 EXPECT_EQ(1U, GetShellWindowCount());
42 ShellWindow* shell_window = GetFirstShellWindow();
43 return shell_window;
46 void CheckAlwaysOnTopToFullscreen(ShellWindow* window) {
47 ASSERT_TRUE(window->GetBaseWindow()->IsAlwaysOnTop());
49 // The always-on-top property should be temporarily disabled when the window
50 // enters fullscreen.
51 window->Fullscreen();
52 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
54 // From the API's point of view, the always-on-top property is enabled.
55 EXPECT_TRUE(window->IsAlwaysOnTop());
57 // The always-on-top property is restored when the window exits fullscreen.
58 window->Restore();
59 EXPECT_TRUE(window->GetBaseWindow()->IsAlwaysOnTop());
62 void CheckNormalToFullscreen(ShellWindow* window) {
63 // If the always-on-top property is false, it should remain this way when
64 // entering and exiting fullscreen mode.
65 ASSERT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
66 window->Fullscreen();
67 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
68 window->Restore();
69 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
72 void CheckFullscreenToAlwaysOnTop(ShellWindow* window) {
73 ASSERT_TRUE(window->GetBaseWindow()->IsFullscreenOrPending());
75 // Now enable always-on-top at runtime and ensure the property does not get
76 // applied immediately because the window is in fullscreen mode.
77 window->SetAlwaysOnTop(true);
78 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
80 // From the API's point of view, the always-on-top property is enabled.
81 EXPECT_TRUE(window->IsAlwaysOnTop());
83 // Ensure the always-on-top property is applied when exiting fullscreen.
84 window->Restore();
85 EXPECT_TRUE(window->GetBaseWindow()->IsAlwaysOnTop());
89 } // namespace
91 // Tests are flaky on Mac as transitioning to fullscreen is not instantaneous
92 // and throws errors when entering/exiting fullscreen too quickly.
93 #if defined(OS_MACOSX)
94 #define MAYBE_InitAlwaysOnTopToFullscreen DISABLED_InitAlwaysOnTopToFullscreen
95 #else
96 #define MAYBE_InitAlwaysOnTopToFullscreen InitAlwaysOnTopToFullscreen
97 #endif
99 // Tests a window created with always-on-top enabled and ensures that the
100 // property is temporarily switched off when entering fullscreen mode.
101 IN_PROC_BROWSER_TEST_F(ShellWindowTest, MAYBE_InitAlwaysOnTopToFullscreen) {
102 ShellWindow* window = OpenWindow(
103 kDefaultTestApp, "{ \"alwaysOnTop\": true }");
104 ASSERT_TRUE(window);
105 CheckAlwaysOnTopToFullscreen(window);
107 window->SetAlwaysOnTop(false);
108 CheckNormalToFullscreen(window);
110 CloseShellWindow(window);
113 #if defined(OS_MACOSX)
114 #define MAYBE_RuntimeAlwaysOnTopToFullscreen DISABLED_RuntimeAlwaysOnTopToFullscreen
115 #else
116 #define MAYBE_RuntimeAlwaysOnTopToFullscreen RuntimeAlwaysOnTopToFullscreen
117 #endif
119 // Tests a window with always-on-top enabled at runtime and ensures that the
120 // property is temporarily switched off when entering fullscreen mode.
121 IN_PROC_BROWSER_TEST_F(ShellWindowTest, MAYBE_RuntimeAlwaysOnTopToFullscreen) {
122 ShellWindow* window = OpenWindow(
123 kDefaultTestApp, "{}");
124 ASSERT_TRUE(window);
125 CheckNormalToFullscreen(window);
127 window->SetAlwaysOnTop(true);
128 CheckAlwaysOnTopToFullscreen(window);
130 CloseShellWindow(window);
133 #if defined(OS_MACOSX)
134 #define MAYBE_InitFullscreenToAlwaysOnTop DISABLED_InitFullscreenToAlwaysOnTop
135 #else
136 #define MAYBE_InitFullscreenToAlwaysOnTop InitFullscreenToAlwaysOnTop
137 #endif
139 // Tests a window created initially in fullscreen mode and ensures that the
140 // always-on-top property does not get applied until it exits fullscreen.
141 IN_PROC_BROWSER_TEST_F(ShellWindowTest, MAYBE_InitFullscreenToAlwaysOnTop) {
142 ShellWindow* window = OpenWindow(
143 kDefaultTestApp, "{ \"state\": \"fullscreen\" }");
144 ASSERT_TRUE(window);
145 CheckFullscreenToAlwaysOnTop(window);
147 CloseShellWindow(window);
150 #if defined(OS_MACOSX)
151 #define MAYBE_RuntimeFullscreenToAlwaysOnTop DISABLED_RuntimeFullscreenToAlwaysOnTop
152 #else
153 #define MAYBE_RuntimeFullscreenToAlwaysOnTop RuntimeFullscreenToAlwaysOnTop
154 #endif
156 // Tests a window that enters fullscreen mode at runtime and ensures that the
157 // always-on-top property does not get applied until it exits fullscreen.
158 IN_PROC_BROWSER_TEST_F(ShellWindowTest, MAYBE_RuntimeFullscreenToAlwaysOnTop) {
159 ShellWindow* window = OpenWindow(
160 kDefaultTestApp, "{}");
161 ASSERT_TRUE(window);
163 window->Fullscreen();
164 CheckFullscreenToAlwaysOnTop(window);
166 CloseShellWindow(window);
169 #if defined(OS_MACOSX)
170 #define MAYBE_InitFullscreenAndAlwaysOnTop DISABLED_InitFullscreenAndAlwaysOnTop
171 #else
172 #define MAYBE_InitFullscreenAndAlwaysOnTop InitFullscreenAndAlwaysOnTop
173 #endif
175 // Tests a window created with both fullscreen and always-on-top enabled. Ensure
176 // that always-on-top is only applied when the window exits fullscreen.
177 IN_PROC_BROWSER_TEST_F(ShellWindowTest, MAYBE_InitFullscreenAndAlwaysOnTop) {
178 ShellWindow* window = OpenWindow(
179 kDefaultTestApp, "{ \"alwaysOnTop\": true, \"state\": \"fullscreen\" }");
180 ASSERT_TRUE(window);
182 EXPECT_TRUE(window->GetBaseWindow()->IsFullscreenOrPending());
183 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
185 // From the API's point of view, the always-on-top property is enabled.
186 EXPECT_TRUE(window->IsAlwaysOnTop());
188 window->Restore();
189 EXPECT_TRUE(window->GetBaseWindow()->IsAlwaysOnTop());
191 CloseShellWindow(window);
194 #if defined(OS_MACOSX)
195 #define MAYBE_DisableAlwaysOnTopInFullscreen DISABLED_DisableAlwaysOnTopInFullscreen
196 #else
197 #define MAYBE_DisableAlwaysOnTopInFullscreen DisableAlwaysOnTopInFullscreen
198 #endif
200 // Tests a window created with always-on-top enabled, but then disabled while
201 // in fullscreen mode. After exiting fullscreen, always-on-top should remain
202 // disabled.
203 IN_PROC_BROWSER_TEST_F(ShellWindowTest, MAYBE_DisableAlwaysOnTopInFullscreen) {
204 ShellWindow* window = OpenWindow(
205 kDefaultTestApp, "{ \"alwaysOnTop\": true }");
206 ASSERT_TRUE(window);
208 // Disable always-on-top while in fullscreen mode.
209 window->Fullscreen();
210 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
211 window->SetAlwaysOnTop(false);
212 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
214 // Ensure that always-on-top remains disabled.
215 window->Restore();
216 EXPECT_FALSE(window->GetBaseWindow()->IsAlwaysOnTop());
218 CloseShellWindow(window);
221 } // namespace apps