| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id())); | 503 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id())); |
| 504 | 504 |
| 505 // Navigate away, closing the message channel and therefore the background | 505 // Navigate away, closing the message channel and therefore the background |
| 506 // page. | 506 // page. |
| 507 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 507 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 508 lazybg.WaitUntilClosed(); | 508 lazybg.WaitUntilClosed(); |
| 509 | 509 |
| 510 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 510 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Tests that a KeepaliveImpulse increments the keep alive count, but eventually | |
| 514 // times out and background page will still close. | |
| 515 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, ImpulseAddsCount) { | |
| 516 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 517 const Extension* extension = LoadExtensionAndWait("messaging"); | |
| 518 ASSERT_TRUE(extension); | |
| 519 | |
| 520 // Lazy Background Page doesn't exist yet. | |
| 521 ProcessManager* pm = ProcessManager::Get(browser()->profile()); | |
| 522 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id())); | |
| 523 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 524 | |
| 525 // Navigate to a page that opens a message channel to the background page. | |
| 526 ResultCatcher catcher; | |
| 527 LazyBackgroundObserver lazybg; | |
| 528 ui_test_utils::NavigateToURL( | |
| 529 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); | |
| 530 lazybg.WaitUntilLoaded(); | |
| 531 | |
| 532 // Add an impulse and the keep alive count increases. | |
| 533 int previous_keep_alive_count = pm->GetLazyKeepaliveCount(extension); | |
| 534 pm->KeepaliveImpulse(extension); | |
| 535 EXPECT_EQ(previous_keep_alive_count + 1, | |
| 536 pm->GetLazyKeepaliveCount(extension)); | |
| 537 | |
| 538 // Navigate away, closing the message channel and therefore the background | |
| 539 // page after the impulse times out. | |
| 540 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
| 541 lazybg.WaitUntilClosed(); | |
| 542 | |
| 543 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id())); | |
| 544 } | |
| 545 | |
| 546 // Tests that the lazy background page receives the unload event when we | 513 // Tests that the lazy background page receives the unload event when we |
| 547 // close it, and that it can execute simple API calls that don't require an | 514 // close it, and that it can execute simple API calls that don't require an |
| 548 // asynchronous response. | 515 // asynchronous response. |
| 549 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnUnload) { | 516 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnUnload) { |
| 550 ASSERT_TRUE(LoadExtensionAndWait("on_unload")); | 517 ASSERT_TRUE(LoadExtensionAndWait("on_unload")); |
| 551 | 518 |
| 552 // Lazy Background Page has been shut down. | 519 // Lazy Background Page has been shut down. |
| 553 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 520 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
| 554 | 521 |
| 555 // The browser action has a new title. | 522 // The browser action has a new title. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 // See https://crbug.com/612668. | 655 // See https://crbug.com/612668. |
| 689 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageIsolatedExtensionsApiTest, | 656 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageIsolatedExtensionsApiTest, |
| 690 EventProcessCleanup) { | 657 EventProcessCleanup) { |
| 691 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe")); | 658 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe")); |
| 692 | 659 |
| 693 // Lazy Background Page doesn't exist anymore. | 660 // Lazy Background Page doesn't exist anymore. |
| 694 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 661 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
| 695 } | 662 } |
| 696 | 663 |
| 697 } // namespace extensions | 664 } // namespace extensions |
| OLD | NEW |