OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/apps/app_browsertest_util.h" | 5 #include "chrome/browser/apps/app_browsertest_util.h" |
| 6 #include "chrome/browser/lifetime/application_lifetime.h" |
| 7 #include "chrome/browser/ui/browser_iterator.h" |
| 8 #include "chrome/browser/ui/browser_window.h" |
6 #include "chrome/test/base/interactive_test_utils.h" | 9 #include "chrome/test/base/interactive_test_utils.h" |
7 #include "extensions/browser/app_window/native_app_window.h" | 10 #include "extensions/browser/app_window/native_app_window.h" |
8 #include "extensions/test/extension_test_message_listener.h" | 11 #include "extensions/test/extension_test_message_listener.h" |
9 #include "extensions/test/result_catcher.h" | 12 #include "extensions/test/result_catcher.h" |
10 | 13 |
11 #if defined(OS_MACOSX) && !defined(OS_IOS) | 14 #if defined(OS_MACOSX) && !defined(OS_IOS) |
12 #include "base/mac/mac_util.h" | 15 #include "base/mac/mac_util.h" |
13 #endif | 16 #endif |
14 | 17 |
15 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; | 453 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; |
451 } | 454 } |
452 | 455 |
453 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { | 456 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { |
454 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; | 457 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; |
455 } | 458 } |
456 | 459 |
457 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, TestDrawAttention) { | 460 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, TestDrawAttention) { |
458 ASSERT_TRUE(RunAppWindowInteractiveTest("testDrawAttention")) << message_; | 461 ASSERT_TRUE(RunAppWindowInteractiveTest("testDrawAttention")) << message_; |
459 } | 462 } |
| 463 |
| 464 // Only Linux and Windows use keep-alive to determine when to shut down. |
| 465 #if defined(OS_LINUX) || defined(OS_WIN) |
| 466 |
| 467 // In general, hidden windows should not keep Chrome alive. The exception is |
| 468 // when windows are created hidden, we allow the app some time to show the |
| 469 // the window. |
| 470 class AppWindowHiddenKeepAliveTest : public extensions::PlatformAppBrowserTest { |
| 471 protected: |
| 472 AppWindowHiddenKeepAliveTest() {} |
| 473 |
| 474 private: |
| 475 DISALLOW_COPY_AND_ASSIGN(AppWindowHiddenKeepAliveTest); |
| 476 }; |
| 477 |
| 478 // A window that becomes hidden should not keep Chrome alive. |
| 479 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHidden) { |
| 480 LoadAndLaunchPlatformApp("minimal", "Launched"); |
| 481 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
| 482 it->window()->Close(); |
| 483 |
| 484 EXPECT_TRUE(chrome::WillKeepAlive()); |
| 485 GetFirstAppWindow()->Hide(); |
| 486 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 487 } |
| 488 |
| 489 // A window that is hidden but re-shown should still keep Chrome alive. |
| 490 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHiddenThenShown) { |
| 491 LoadAndLaunchPlatformApp("minimal", "Launched"); |
| 492 AppWindow* app_window = GetFirstAppWindow(); |
| 493 app_window->Hide(); |
| 494 app_window->Show(AppWindow::SHOW_ACTIVE); |
| 495 |
| 496 EXPECT_TRUE(chrome::WillKeepAlive()); |
| 497 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
| 498 it->window()->Close(); |
| 499 EXPECT_TRUE(chrome::WillKeepAlive()); |
| 500 app_window->GetBaseWindow()->Close(); |
| 501 } |
| 502 |
| 503 // A window that is created hidden and stays hidden should not keep Chrome |
| 504 // alive. |
| 505 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, StaysHidden) { |
| 506 LoadAndLaunchPlatformApp("hidden", "Launched"); |
| 507 AppWindow* app_window = GetFirstAppWindow(); |
| 508 EXPECT_TRUE(app_window->is_hidden()); |
| 509 |
| 510 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
| 511 it->window()->Close(); |
| 512 // This will time out if the command above does not terminate Chrome. |
| 513 content::RunMessageLoop(); |
| 514 } |
| 515 |
| 516 // A window that is created hidden but shown soon after should keep Chrome |
| 517 // alive. |
| 518 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, HiddenThenShown) { |
| 519 ExtensionTestMessageListener launched_listener("Launched", true); |
| 520 LoadAndLaunchPlatformApp("hidden_then_shown", &launched_listener); |
| 521 AppWindow* app_window = GetFirstAppWindow(); |
| 522 EXPECT_TRUE(app_window->is_hidden()); |
| 523 |
| 524 // Close all browser windows. |
| 525 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
| 526 it->window()->Close(); |
| 527 |
| 528 // The app window will show after 3 seconds. |
| 529 ExtensionTestMessageListener shown_listener("Shown", false); |
| 530 launched_listener.Reply(""); |
| 531 EXPECT_TRUE(shown_listener.WaitUntilSatisfied()); |
| 532 EXPECT_FALSE(app_window->is_hidden()); |
| 533 EXPECT_TRUE(chrome::WillKeepAlive()); |
| 534 app_window->GetBaseWindow()->Close(); |
| 535 } |
| 536 |
| 537 #endif |
OLD | NEW |