1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "build/build_config.h"
#include "chrome/browser/apps/platform_apps/app_window_interactive_uitest_base.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
#include "ui/views/win/hwnd_message_handler_delegate.h"
#include "ui/views/win/hwnd_util.h"
#endif
using extensions::AppWindow;
using extensions::NativeAppWindow;
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) {
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("leave_fullscreen", &launched_listener);
// We start by making sure the window is actually focused.
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
// When receiving the reply, the application will try to go fullscreen using
// the Window API but there is no synchronous way to know if that actually
// succeeded. Also, failure will not be notified. A failure case will only be
// known with a timeout.
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
launched_listener.Reply("window");
fs_changed.Wait();
}
// Depending on the platform, going fullscreen might create an animation.
// We want to make sure that the ESC key we will send next is actually going
// to be received and the application might not receive key events during the
// animation so we should wait for the key focus to be back.
WaitUntilKeyFocus();
// Same idea as above but for leaving fullscreen. Fullscreen mode should be
// left when ESC is received.
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
fs_changed.Wait();
}
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenDOM) {
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("leave_fullscreen", &launched_listener);
// We start by making sure the window is actually focused.
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
launched_listener.Reply("dom");
// Because the DOM way to go fullscreen requires user gesture, we simulate a
// key event to get the window entering in fullscreen mode. The reply will
// make the window listen for the key event. The reply will be sent to the
// renderer process before the keypress and should be received in that order.
// When receiving the key event, the application will try to go fullscreen
// using the Window API but there is no synchronous way to know if that
// actually succeeded. Also, failure will not be notified. A failure case will
// only be known with a timeout.
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
fs_changed.Wait();
}
// Depending on the platform, going fullscreen might create an animation.
// We want to make sure that the ESC key we will send next is actually going
// to be received and the application might not receive key events during the
// animation so we should wait for the key focus to be back.
WaitUntilKeyFocus();
// Same idea as above but for leaving fullscreen. Fullscreen mode should be
// left when ESC is received.
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
fs_changed.Wait();
}
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
ESCDoesNotLeaveFullscreenWindow) {
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("prevent_leave_fullscreen", &launched_listener);
// We start by making sure the window is actually focused.
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
// When receiving the reply, the application will try to go fullscreen using
// the Window API but there is no synchronous way to know if that actually
// succeeded. Also, failure will not be notified. A failure case will only be
// known with a timeout.
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
launched_listener.Reply("window");
fs_changed.Wait();
}
// Depending on the platform, going fullscreen might create an animation.
// We want to make sure that the ESC key we will send next is actually going
// to be received and the application might not receive key events during the
// animation so we should wait for the key focus to be back.
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED");
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
// We assume that at that point, if we had to leave fullscreen, we should be.
// However, by nature, we can not guarantee that and given that we do test
// that nothing happens, we might end up with random-success when the feature
// is broken.
EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCDoesNotLeaveFullscreenDOM) {
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("prevent_leave_fullscreen", &launched_listener);
// We start by making sure the window is actually focused.
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
launched_listener.Reply("dom");
// Because the DOM way to go fullscreen requires user gesture, we simulate a
// key event to get the window entering in fullscreen mode. The reply will
// make the window listen for the key event. The reply will be sent to the
// renderer process before the keypress and should be received in that order.
// When receiving the key event, the application will try to go fullscreen
// using the Window API but there is no synchronous way to know if that
// actually succeeded. Also, failure will not be notified. A failure case will
// only be known with a timeout.
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
fs_changed.Wait();
}
// Depending on the platform, going fullscreen might create an animation.
// We want to make sure that the ESC key we will send next is actually going
// to be received and the application might not receive key events during the
// animation so we should wait for the key focus to be back.
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED");
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
// We assume that at that point, if we had to leave fullscreen, we should be.
// However, by nature, we can not guarantee that and given that we do test
// that nothing happens, we might end up with random-success when the feature
// is broken.
EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
}
// This test is duplicated from ESCDoesNotLeaveFullscreenWindow.
// It runs the same test, but uses the old permission names: 'fullscreen'
// and 'overrideEscFullscreen'.
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
ESCDoesNotLeaveFullscreenOldPermission) {
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("prevent_leave_fullscreen_old", &launched_listener);
// We start by making sure the window is actually focused.
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
// When receiving the reply, the application will try to go fullscreen using
// the Window API but there is no synchronous way to know if that actually
// succeeded. Also, failure will not be notified. A failure case will only be
// known with a timeout.
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
launched_listener.Reply("window");
fs_changed.Wait();
}
// Depending on the platform, going fullscreen might create an animation.
// We want to make sure that the ESC key we will send next is actually going
// to be received and the application might not receive key events during the
// animation so we should wait for the key focus to be back.
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED");
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
// We assume that at that point, if we had to leave fullscreen, we should be.
// However, by nature, we can not guarantee that and given that we do test
// that nothing happens, we might end up with random-success when the feature
// is broken.
EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
}
#if BUILDFLAG(IS_MAC) || defined(THREAD_SANITIZER) || BUILDFLAG(IS_LINUX)
// http://crbug.com/404081
// http://crbug.com/1263448 (tsan)
// http://crbug.com/1263661 (linux)
#define MAYBE_TestInnerBounds DISABLED_TestInnerBounds
#else
#define MAYBE_TestInnerBounds TestInnerBounds
#endif
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestInnerBounds) {
ASSERT_TRUE(RunAppWindowInteractiveTest("testInnerBounds")) << message_;
}
void AppWindowInteractiveTest::TestOuterBoundsHelper(
const std::string& frame_type) {
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
const extensions::Extension* app =
LoadAndLaunchPlatformApp("outer_bounds", &launched_listener);
launched_listener.Reply(frame_type);
launched_listener.Reset();
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
launched_listener.Reply(std::string());
AppWindow* window = GetFirstAppWindowForApp(app->id());
gfx::Rect window_bounds;
gfx::Size min_size, max_size;
#if BUILDFLAG(IS_WIN)
// Get the bounds from the HWND.
HWND hwnd = views::HWNDForNativeWindow(window->GetNativeWindow());
RECT rect;
::GetWindowRect(hwnd, &rect);
window_bounds = gfx::Rect(rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top);
// HWNDMessageHandler calls this when responding to WM_GETMINMAXSIZE, so it's
// the closest to what the window will see.
views::HWNDMessageHandlerDelegate* host =
static_cast<views::HWNDMessageHandlerDelegate*>(
static_cast<views::DesktopWindowTreeHostWin*>(
aura::WindowTreeHost::GetForAcceleratedWidget(hwnd)));
host->GetMinMaxSize(&min_size, &max_size);
#endif // BUILDFLAG(IS_WIN)
// These match the values in the outer_bounds/test.js
EXPECT_EQ(gfx::Rect(10, 11, 300, 301), window_bounds);
EXPECT_EQ(window->GetBaseWindow()->GetBounds(), window_bounds);
EXPECT_GE(200, min_size.width());
EXPECT_GE(201, min_size.height());
EXPECT_EQ(400, max_size.width());
EXPECT_EQ(401, max_size.height());
}
// TODO(jackhou): Make this test work for other OSes.
#if !BUILDFLAG(IS_WIN)
#define MAYBE_TestOuterBoundsFrameChrome DISABLED_TestOuterBoundsFrameChrome
#define MAYBE_TestOuterBoundsFrameNone DISABLED_TestOuterBoundsFrameNone
#define MAYBE_TestOuterBoundsFrameColor DISABLED_TestOuterBoundsFrameColor
#else
#define MAYBE_TestOuterBoundsFrameChrome TestOuterBoundsFrameChrome
#define MAYBE_TestOuterBoundsFrameNone TestOuterBoundsFrameNone
#define MAYBE_TestOuterBoundsFrameColor TestOuterBoundsFrameColor
#endif
// Test that the outer bounds match that of the native window.
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
MAYBE_TestOuterBoundsFrameChrome) {
TestOuterBoundsHelper("chrome");
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
MAYBE_TestOuterBoundsFrameNone) {
TestOuterBoundsHelper("none");
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
MAYBE_TestOuterBoundsFrameColor) {
TestOuterBoundsHelper("color");
}
// This test does not work on Linux Aura because ShowInactive() is not
// implemented. See http://crbug.com/325142
// It also does not work on MacOS because ::ShowInactive() ends up behaving like
// ::Show() because of Cocoa conventions. See http://crbug.com/326987
// Those tests should be disabled on Linux GTK when they are enabled on the
// other platforms, see http://crbug.com/328829.
// Flaky failures on Windows; see https://crbug.com/788283.
#if ((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(USE_AURA)) || \
BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
#define MAYBE_TestCreate DISABLED_TestCreate
#else
#define MAYBE_TestCreate TestCreate
#endif
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) {
ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_;
}
// This test does not work on Linux Aura because ShowInactive() is not
// implemented. See http://crbug.com/325142
// It also does not work on Windows because of the document being focused even
// though the window is not activated. See http://crbug.com/326986
// It also does not work on MacOS because ::ShowInactive() ends up behaving like
// ::Show() because of Cocoa conventions. See http://crbug.com/326987
// Those tests should be disabled on Linux GTK when they are enabled on the
// other platforms, see http://crbug.com/328829
#if ((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(USE_AURA)) || \
BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#define MAYBE_TestShow DISABLED_TestShow
#else
#define MAYBE_TestShow TestShow
#endif
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) {
ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, TestDrawAttention) {
ASSERT_TRUE(RunAppWindowInteractiveTest("testDrawAttention")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, TestCreateHidden) {
// Created hidden both times.
{
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("hidden_with_id", &launched_listener);
EXPECT_TRUE(launched_listener.WaitUntilSatisfied());
ExtensionTestMessageListener create_listener_1("Launched",
ReplyBehavior::kWillReply);
launched_listener.Reply("createHidden");
EXPECT_TRUE(create_listener_1.WaitUntilSatisfied());
AppWindow* app_window = GetFirstAppWindow();
EXPECT_TRUE(app_window->is_hidden());
ExtensionTestMessageListener create_listener_2("Launched");
create_listener_1.Reply("createHidden");
EXPECT_TRUE(create_listener_2.WaitUntilSatisfied());
EXPECT_TRUE(app_window->is_hidden());
app_window->GetBaseWindow()->Close();
}
// Created hidden, then visible. The second create should show the window.
{
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("hidden_with_id", &launched_listener);
EXPECT_TRUE(launched_listener.WaitUntilSatisfied());
ExtensionTestMessageListener create_listener_1("Launched",
ReplyBehavior::kWillReply);
launched_listener.Reply("createHidden");
EXPECT_TRUE(create_listener_1.WaitUntilSatisfied());
AppWindow* app_window = GetFirstAppWindow();
EXPECT_TRUE(app_window->is_hidden());
ExtensionTestMessageListener create_listener_2("Launched");
create_listener_1.Reply("createVisible");
EXPECT_TRUE(create_listener_2.WaitUntilSatisfied());
EXPECT_FALSE(app_window->is_hidden());
app_window->GetBaseWindow()->Close();
}
}
// http://crbug.com/502516
#define MAYBE_TestFullscreen DISABLED_TestFullscreen
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestFullscreen) {
ASSERT_TRUE(RunAppWindowInteractiveTest("testFullscreen")) << message_;
}
// Only Linux and Windows use keep-alive to determine when to shut down.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
// In general, hidden windows should not keep Chrome alive. The exception is
// when windows are created hidden, we allow the app some time to show the
// the window.
class AppWindowHiddenKeepAliveTest : public extensions::PlatformAppBrowserTest {
public:
AppWindowHiddenKeepAliveTest(const AppWindowHiddenKeepAliveTest&) = delete;
AppWindowHiddenKeepAliveTest& operator=(const AppWindowHiddenKeepAliveTest&) =
delete;
protected:
AppWindowHiddenKeepAliveTest() = default;
};
// A window that becomes hidden should not keep Chrome alive.
IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHidden) {
LoadAndLaunchPlatformApp("minimal", "Launched");
for (Browser* browser : *BrowserList::GetInstance()) {
browser->window()->Close();
}
EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered(
KeepAliveOrigin::CHROME_APP_DELEGATE));
GetFirstAppWindow()->Hide();
EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsOriginRegistered(
KeepAliveOrigin::CHROME_APP_DELEGATE));
}
// A window that is hidden but re-shown should still keep Chrome alive.
IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHiddenThenShown) {
LoadAndLaunchPlatformApp("minimal", "Launched");
AppWindow* app_window = GetFirstAppWindow();
app_window->Hide();
app_window->Show(AppWindow::SHOW_ACTIVE);
EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered(
KeepAliveOrigin::CHROME_APP_DELEGATE));
for (Browser* browser : *BrowserList::GetInstance()) {
browser->window()->Close();
}
EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered(
KeepAliveOrigin::CHROME_APP_DELEGATE));
app_window->GetBaseWindow()->Close();
}
// A window that is created hidden and stays hidden should not keep Chrome
// alive.
IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, StaysHidden) {
LoadAndLaunchPlatformApp("hidden", "Launched");
AppWindow* app_window = GetFirstAppWindow();
EXPECT_TRUE(app_window->is_hidden());
for (Browser* browser : *BrowserList::GetInstance()) {
browser->window()->Close();
}
RunUntilBrowserProcessQuits();
}
// A window that is created hidden but shown soon after should keep Chrome
// alive.
IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, HiddenThenShown) {
ExtensionTestMessageListener launched_listener("Launched",
ReplyBehavior::kWillReply);
LoadAndLaunchPlatformApp("hidden_then_shown", &launched_listener);
AppWindow* app_window = GetFirstAppWindow();
EXPECT_TRUE(app_window->is_hidden());
// Close all browser windows.
for (Browser* browser : *BrowserList::GetInstance()) {
browser->window()->Close();
}
// The app window will show after 3 seconds.
ExtensionTestMessageListener shown_listener("Shown");
launched_listener.Reply("");
EXPECT_TRUE(shown_listener.WaitUntilSatisfied());
EXPECT_FALSE(app_window->is_hidden());
EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered(
KeepAliveOrigin::CHROME_APP_DELEGATE));
app_window->GetBaseWindow()->Close();
}
#endif
|