OLD | NEW |
| (Empty) |
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. | |
4 | |
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" | |
8 #include "chrome/test/base/interactive_test_utils.h" | |
9 | |
10 using namespace apps; | |
11 | |
12 // This test does not work on Linux Aura yet. It might be because the fullscreen | |
13 // window is not correctly focused or because key events are not correctly sent. | |
14 #if !(defined(OS_LINUX) && defined(USE_AURA)) | |
15 | |
16 // Helper class that has to be created in the stack to check if the fullscreen | |
17 // setting of a NativeWindow has changed since the creation of the object. | |
18 class FullscreenChangeWaiter { | |
19 public: | |
20 explicit FullscreenChangeWaiter(NativeAppWindow* window) | |
21 : window_(window), | |
22 initial_fullscreen_state_(window_->IsFullscreen()) {} | |
23 | |
24 void Wait() { | |
25 while (initial_fullscreen_state_ != window_->IsFullscreen()) | |
26 content::RunAllPendingInMessageLoop(); | |
27 } | |
28 | |
29 private: | |
30 NativeAppWindow* window_; | |
31 bool initial_fullscreen_state_; | |
32 | |
33 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter); | |
34 }; | |
35 | |
36 class AppInteractiveTest : public extensions::PlatformAppBrowserTest { | |
37 public: | |
38 bool SimulateKeyPress(ui::KeyboardCode key) { | |
39 return ui_test_utils::SendKeyPressToWindowSync( | |
40 GetFirstShellWindow()->GetNativeWindow(), | |
41 key, | |
42 false, | |
43 false, | |
44 false, | |
45 false); | |
46 } | |
47 }; | |
48 | |
49 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenWindow) { | |
50 ExtensionTestMessageListener launched_listener("Launched", true); | |
51 LoadAndLaunchPlatformApp("leave_fullscreen"); | |
52 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
53 | |
54 // When receiving the reply, the application will try to go fullscreen using | |
55 // the Window API but there is no synchronous way to know if that actually | |
56 // succeeded. Also, failure will not be notified. A failure case will only be | |
57 // known with a timeout. | |
58 { | |
59 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
60 | |
61 launched_listener.Reply("window"); | |
62 | |
63 fs_changed.Wait(); | |
64 } | |
65 | |
66 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | |
67 // left when ESC is received. | |
68 { | |
69 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
70 | |
71 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | |
72 | |
73 fs_changed.Wait(); | |
74 } | |
75 } | |
76 | |
77 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenDOM) { | |
78 ExtensionTestMessageListener launched_listener("Launched", true); | |
79 LoadAndLaunchPlatformApp("leave_fullscreen"); | |
80 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
81 | |
82 launched_listener.Reply("dom"); | |
83 | |
84 // Because the DOM way to go fullscreen requires user gesture, we simulate a | |
85 // key event to get the window entering in fullscreen mode. The reply will | |
86 // make the window listen for the key event. The reply will be sent to the | |
87 // renderer process before the keypress and should be received in that order. | |
88 // When receiving the key event, the application will try to go fullscreen | |
89 // using the Window API but there is no synchronous way to know if that | |
90 // actually succeeded. Also, failure will not be notified. A failure case will | |
91 // only be known with a timeout. | |
92 { | |
93 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
94 | |
95 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | |
96 | |
97 fs_changed.Wait(); | |
98 } | |
99 | |
100 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | |
101 // left when ESC is received. | |
102 { | |
103 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
104 | |
105 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | |
106 | |
107 fs_changed.Wait(); | |
108 } | |
109 } | |
110 | |
111 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenWindow) { | |
112 ExtensionTestMessageListener launched_listener("Launched", true); | |
113 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | |
114 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
115 | |
116 // When receiving the reply, the application will try to go fullscreen using | |
117 // the Window API but there is no synchronous way to know if that actually | |
118 // succeeded. Also, failure will not be notified. A failure case will only be | |
119 // known with a timeout. | |
120 { | |
121 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
122 | |
123 launched_listener.Reply("window"); | |
124 | |
125 fs_changed.Wait(); | |
126 } | |
127 | |
128 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | |
129 | |
130 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | |
131 | |
132 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | |
133 | |
134 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | |
135 | |
136 // We assume that at that point, if we had to leave fullscreen, we should be. | |
137 // However, by nature, we can not guarantee that and given that we do test | |
138 // that nothing happens, we might end up with random-success when the feature | |
139 // is broken. | |
140 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | |
141 } | |
142 | |
143 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenDOM) { | |
144 ExtensionTestMessageListener launched_listener("Launched", true); | |
145 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | |
146 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
147 | |
148 launched_listener.Reply("dom"); | |
149 | |
150 // Because the DOM way to go fullscreen requires user gesture, we simulate a | |
151 // key event to get the window entering in fullscreen mode. The reply will | |
152 // make the window listen for the key event. The reply will be sent to the | |
153 // renderer process before the keypress and should be received in that order. | |
154 // When receiving the key event, the application will try to go fullscreen | |
155 // using the Window API but there is no synchronous way to know if that | |
156 // actually succeeded. Also, failure will not be notified. A failure case will | |
157 // only be known with a timeout. | |
158 { | |
159 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
160 | |
161 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | |
162 | |
163 fs_changed.Wait(); | |
164 } | |
165 | |
166 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | |
167 | |
168 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | |
169 | |
170 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | |
171 | |
172 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | |
173 | |
174 // We assume that at that point, if we had to leave fullscreen, we should be. | |
175 // However, by nature, we can not guarantee that and given that we do test | |
176 // that nothing happens, we might end up with random-success when the feature | |
177 // is broken. | |
178 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | |
179 } | |
180 | |
181 #endif // !(defined(OS_LINUX) && defined(USE_AURA)) | |
OLD | NEW |