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