| 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
| 7 #include "chrome/browser/apps/app_browsertest_util.h" | 7 #include "chrome/browser/apps/app_browsertest_util.h" |
| 8 #include "chrome/browser/lifetime/application_lifetime.h" | 8 #include "chrome/browser/lifetime/application_lifetime.h" |
| 9 #include "chrome/browser/lifetime/keep_alive_registry.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/test/base/interactive_test_utils.h" | 12 #include "chrome/test/base/interactive_test_utils.h" |
| 12 #include "extensions/browser/app_window/native_app_window.h" | 13 #include "extensions/browser/app_window/native_app_window.h" |
| 13 #include "extensions/test/extension_test_message_listener.h" | 14 #include "extensions/test/extension_test_message_listener.h" |
| 14 #include "extensions/test/result_catcher.h" | 15 #include "extensions/test/result_catcher.h" |
| 15 | 16 |
| 16 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
| 17 #include "base/mac/mac_util.h" | 18 #include "base/mac/mac_util.h" |
| 18 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h" | 19 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h" |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 private: | 522 private: |
| 522 DISALLOW_COPY_AND_ASSIGN(AppWindowHiddenKeepAliveTest); | 523 DISALLOW_COPY_AND_ASSIGN(AppWindowHiddenKeepAliveTest); |
| 523 }; | 524 }; |
| 524 | 525 |
| 525 // A window that becomes hidden should not keep Chrome alive. | 526 // A window that becomes hidden should not keep Chrome alive. |
| 526 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHidden) { | 527 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHidden) { |
| 527 LoadAndLaunchPlatformApp("minimal", "Launched"); | 528 LoadAndLaunchPlatformApp("minimal", "Launched"); |
| 528 for (auto* browser : *BrowserList::GetInstance()) | 529 for (auto* browser : *BrowserList::GetInstance()) |
| 529 browser->window()->Close(); | 530 browser->window()->Close(); |
| 530 | 531 |
| 531 EXPECT_TRUE(chrome::WillKeepAlive()); | 532 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| 532 GetFirstAppWindow()->Hide(); | 533 GetFirstAppWindow()->Hide(); |
| 533 EXPECT_FALSE(chrome::WillKeepAlive()); | 534 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| 534 } | 535 } |
| 535 | 536 |
| 536 // A window that is hidden but re-shown should still keep Chrome alive. | 537 // A window that is hidden but re-shown should still keep Chrome alive. |
| 537 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHiddenThenShown) { | 538 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, ShownThenHiddenThenShown) { |
| 538 LoadAndLaunchPlatformApp("minimal", "Launched"); | 539 LoadAndLaunchPlatformApp("minimal", "Launched"); |
| 539 AppWindow* app_window = GetFirstAppWindow(); | 540 AppWindow* app_window = GetFirstAppWindow(); |
| 540 app_window->Hide(); | 541 app_window->Hide(); |
| 541 app_window->Show(AppWindow::SHOW_ACTIVE); | 542 app_window->Show(AppWindow::SHOW_ACTIVE); |
| 542 | 543 |
| 543 EXPECT_TRUE(chrome::WillKeepAlive()); | 544 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| 544 for (auto* browser : *BrowserList::GetInstance()) | 545 for (auto* browser : *BrowserList::GetInstance()) |
| 545 browser->window()->Close(); | 546 browser->window()->Close(); |
| 546 EXPECT_TRUE(chrome::WillKeepAlive()); | 547 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| 547 app_window->GetBaseWindow()->Close(); | 548 app_window->GetBaseWindow()->Close(); |
| 548 } | 549 } |
| 549 | 550 |
| 550 // A window that is created hidden and stays hidden should not keep Chrome | 551 // A window that is created hidden and stays hidden should not keep Chrome |
| 551 // alive. | 552 // alive. |
| 552 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, StaysHidden) { | 553 IN_PROC_BROWSER_TEST_F(AppWindowHiddenKeepAliveTest, StaysHidden) { |
| 553 LoadAndLaunchPlatformApp("hidden", "Launched"); | 554 LoadAndLaunchPlatformApp("hidden", "Launched"); |
| 554 AppWindow* app_window = GetFirstAppWindow(); | 555 AppWindow* app_window = GetFirstAppWindow(); |
| 555 EXPECT_TRUE(app_window->is_hidden()); | 556 EXPECT_TRUE(app_window->is_hidden()); |
| 556 | 557 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 570 | 571 |
| 571 // Close all browser windows. | 572 // Close all browser windows. |
| 572 for (auto* browser : *BrowserList::GetInstance()) | 573 for (auto* browser : *BrowserList::GetInstance()) |
| 573 browser->window()->Close(); | 574 browser->window()->Close(); |
| 574 | 575 |
| 575 // The app window will show after 3 seconds. | 576 // The app window will show after 3 seconds. |
| 576 ExtensionTestMessageListener shown_listener("Shown", false); | 577 ExtensionTestMessageListener shown_listener("Shown", false); |
| 577 launched_listener.Reply(""); | 578 launched_listener.Reply(""); |
| 578 EXPECT_TRUE(shown_listener.WaitUntilSatisfied()); | 579 EXPECT_TRUE(shown_listener.WaitUntilSatisfied()); |
| 579 EXPECT_FALSE(app_window->is_hidden()); | 580 EXPECT_FALSE(app_window->is_hidden()); |
| 580 EXPECT_TRUE(chrome::WillKeepAlive()); | 581 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| 581 app_window->GetBaseWindow()->Close(); | 582 app_window->GetBaseWindow()->Close(); |
| 582 } | 583 } |
| 583 | 584 |
| 584 #endif | 585 #endif |
| OLD | NEW |