Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: chrome/browser/apps/app_interactive_uitest.cc

Issue 62763003: Leave fullscreen mode in an app window when ESC key is pressed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disable tests on mac Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « apps/shell_window.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // This test is also highly flaky on MacOS X.
17 #if !defined(OS_MACOSX)
18
19 // Helper class that has to be created in the stack to check if the fullscreen
20 // setting of a NativeWindow has changed since the creation of the object.
21 class FullscreenChangeWaiter {
22 public:
23 explicit FullscreenChangeWaiter(NativeAppWindow* window)
24 : window_(window),
25 initial_fullscreen_state_(window_->IsFullscreen()) {}
26
27 void Wait() {
28 while (initial_fullscreen_state_ != window_->IsFullscreen())
29 content::RunAllPendingInMessageLoop();
30 }
31
32 private:
33 NativeAppWindow* window_;
34 bool initial_fullscreen_state_;
35
36 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter);
37 };
38
39 class AppInteractiveTest : public extensions::PlatformAppBrowserTest {
40 public:
41 bool SimulateKeyPress(ui::KeyboardCode key) {
42 return ui_test_utils::SendKeyPressToWindowSync(
43 GetFirstShellWindow()->GetNativeWindow(),
44 key,
45 false,
46 false,
47 false,
48 false);
49 }
50 };
51
52 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenWindow) {
53 ExtensionTestMessageListener launched_listener("Launched", true);
54 LoadAndLaunchPlatformApp("leave_fullscreen");
55 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
56
57 // When receiving the reply, the application will try to go fullscreen using
58 // the Window API but there is no synchronous way to know if that actually
59 // succeeded. Also, failure will not be notified. A failure case will only be
60 // known with a timeout.
61 {
62 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow());
63
64 launched_listener.Reply("window");
65
66 fs_changed.Wait();
67 }
68
69 // Same idea as above but for leaving fullscreen. Fullscreen mode should be
70 // left when ESC is received.
71 {
72 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow());
73
74 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
75
76 fs_changed.Wait();
77 }
78 }
79
80 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenDOM) {
81 ExtensionTestMessageListener launched_listener("Launched", true);
82 LoadAndLaunchPlatformApp("leave_fullscreen");
83 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
84
85 launched_listener.Reply("dom");
86
87 // Because the DOM way to go fullscreen requires user gesture, we simulate a
88 // key event to get the window entering in fullscreen mode. The reply will
89 // make the window listen for the key event. The reply will be sent to the
90 // renderer process before the keypress and should be received in that order.
91 // When receiving the key event, the application will try to go fullscreen
92 // using the Window API but there is no synchronous way to know if that
93 // actually succeeded. Also, failure will not be notified. A failure case will
94 // only be known with a timeout.
95 {
96 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow());
97
98 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
99
100 fs_changed.Wait();
101 }
102
103 // Same idea as above but for leaving fullscreen. Fullscreen mode should be
104 // left when ESC is received.
105 {
106 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow());
107
108 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
109
110 fs_changed.Wait();
111 }
112 }
113
114 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenWindow) {
115 ExtensionTestMessageListener launched_listener("Launched", true);
116 LoadAndLaunchPlatformApp("prevent_leave_fullscreen");
117 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
118
119 // When receiving the reply, the application will try to go fullscreen using
120 // the Window API but there is no synchronous way to know if that actually
121 // succeeded. Also, failure will not be notified. A failure case will only be
122 // known with a timeout.
123 {
124 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow());
125
126 launched_listener.Reply("window");
127
128 fs_changed.Wait();
129 }
130
131 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
132
133 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
134
135 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
136
137 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
138
139 // We assume that at that point, if we had to leave fullscreen, we should be.
140 // However, by nature, we can not guarantee that and given that we do test
141 // that nothing happens, we might end up with random-success when the feature
142 // is broken.
143 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen());
144 }
145
146 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenDOM) {
147 ExtensionTestMessageListener launched_listener("Launched", true);
148 LoadAndLaunchPlatformApp("prevent_leave_fullscreen");
149 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
150
151 launched_listener.Reply("dom");
152
153 // Because the DOM way to go fullscreen requires user gesture, we simulate a
154 // key event to get the window entering in fullscreen mode. The reply will
155 // make the window listen for the key event. The reply will be sent to the
156 // renderer process before the keypress and should be received in that order.
157 // When receiving the key event, the application will try to go fullscreen
158 // using the Window API but there is no synchronous way to know if that
159 // actually succeeded. Also, failure will not be notified. A failure case will
160 // only be known with a timeout.
161 {
162 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow());
163
164 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
165
166 fs_changed.Wait();
167 }
168
169 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
170
171 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
172
173 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
174
175 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
176
177 // We assume that at that point, if we had to leave fullscreen, we should be.
178 // However, by nature, we can not guarantee that and given that we do test
179 // that nothing happens, we might end up with random-success when the feature
180 // is broken.
181 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen());
182 }
183
184 #endif // !(defined(OS_MACOSX))
185
186 #endif // !(defined(OS_LINUX) && defined(USE_AURA))
OLDNEW
« no previous file with comments | « apps/shell_window.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698