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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 | 564 |
565 page_ready.Reply("go"); | 565 page_ready.Reply("go"); |
566 | 566 |
567 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 567 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
568 } | 568 } |
569 | 569 |
570 // Tests that the lazy background page updates the chrome://extensions page | 570 // Tests that the lazy background page updates the chrome://extensions page |
571 // when it is destroyed. | 571 // when it is destroyed. |
572 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, UpdateExtensionsPage) { | 572 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, UpdateExtensionsPage) { |
573 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIExtensionsURL)); | 573 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIExtensionsURL)); |
| 574 auto* extensions_page = browser()->tab_strip_model()->GetActiveWebContents(); |
574 | 575 |
575 ResultCatcher catcher; | 576 ResultCatcher catcher; |
576 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 577 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
577 AppendASCII("wait_for_view"); | 578 AppendASCII("wait_for_view"); |
578 const Extension* extension = LoadExtension(extdir); | 579 const Extension* extension = LoadExtension(extdir); |
579 ASSERT_TRUE(extension); | 580 ASSERT_TRUE(extension); |
580 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 581 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
581 | 582 |
582 // The extension should've opened a new tab to an extension page. | 583 // The extension should've opened a new tab to an extension page. |
583 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(), | 584 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(), |
584 browser()->tab_strip_model()->GetActiveWebContents()-> | 585 browser()->tab_strip_model()->GetActiveWebContents()-> |
585 GetURL().spec()); | 586 GetURL().spec()); |
586 | 587 |
587 // Lazy Background Page still exists, because the extension created a new tab | 588 // Lazy Background Page still exists, because the extension created a new tab |
588 // to an extension page. | 589 // to an extension page. |
589 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id())); | 590 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id())); |
590 | 591 |
591 // Close the new tab. | 592 // Close the new tab. |
592 LazyBackgroundObserver page_complete; | 593 LazyBackgroundObserver page_complete; |
593 browser()->tab_strip_model()->CloseWebContentsAt( | 594 browser()->tab_strip_model()->CloseWebContentsAt( |
594 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE); | 595 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE); |
595 page_complete.WaitUntilClosed(); | 596 page_complete.WaitUntilClosed(); |
596 | 597 |
597 // Lazy Background Page has been shut down. | 598 // Lazy Background Page has been shut down. |
598 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 599 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
599 | 600 |
600 // Verify that extensions page shows that the lazy background page is | |
601 // inactive. | |
602 content::RenderFrameHost* frame = content::FrameMatchingPredicate( | |
603 browser()->tab_strip_model()->GetActiveWebContents(), | |
604 base::Bind(&content::FrameHasSourceUrl, | |
605 GURL(chrome::kChromeUIExtensionsFrameURL))); | |
606 | |
607 // Updating the extensions page is a process that has back-and-forth | 601 // Updating the extensions page is a process that has back-and-forth |
608 // communication (i.e., backend tells extensions page something changed, | 602 // communication (i.e., backend tells extensions page something changed, |
609 // extensions page requests updated data, backend responds with updated data, | 603 // extensions page requests updated data, backend responds with updated data, |
610 // and so forth). This makes it difficult to know for sure when the page is | 604 // and so forth). This makes it difficult to know for sure when the page is |
611 // done updating, so just try a few times. We limit the total number of | 605 // done updating, so just try a few times. We limit the total number of |
612 // attempts so that a) the test *fails* (instead of times out), and b) we | 606 // attempts so that a) the test *fails* (instead of times out), and b) we |
613 // know we're not making a ridiculous amount of trips to update the page. | 607 // know we're not making a ridiculous amount of trips to update the page. |
614 bool is_inactive = false; | 608 bool is_inactive = false; |
615 int kMaxTries = 10; | 609 int kMaxTries = 10; |
616 int num_tries = 0; | 610 int num_tries = 0; |
617 while (!is_inactive && num_tries++ < kMaxTries) { | 611 while (!is_inactive && num_tries++ < kMaxTries) { |
618 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 612 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
619 frame, | 613 extensions_page, |
620 "var ele = document.querySelectorAll('div.active-views');" | 614 "var ele = document.querySelectorAll('div.active-views');" |
621 "window.domAutomationController.send(" | 615 "window.domAutomationController.send(" |
622 " ele[0].innerHTML.search('(Inactive)') > 0);", | 616 " ele[0].innerHTML.search('(Inactive)') > 0);", |
623 &is_inactive)); | 617 &is_inactive)); |
624 } | 618 } |
625 } | 619 } |
626 | 620 |
627 // Tests that the lazy background page will be unloaded if the onSuspend event | 621 // Tests that the lazy background page will be unloaded if the onSuspend event |
628 // handler calls an API function such as chrome.storage.local.set(). | 622 // handler calls an API function such as chrome.storage.local.set(). |
629 // See: http://crbug.com/296834 | 623 // See: http://crbug.com/296834 |
630 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 624 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
631 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 625 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
632 } | 626 } |
633 | 627 |
634 // TODO: background page with timer. | 628 // TODO: background page with timer. |
635 // TODO: background page that interacts with popup. | 629 // TODO: background page that interacts with popup. |
636 | 630 |
637 // Ensure that the events page of an extension is properly torn down and the | 631 // Ensure that the events page of an extension is properly torn down and the |
638 // process does not linger around. | 632 // process does not linger around. |
639 // See https://crbug.com/612668. | 633 // See https://crbug.com/612668. |
640 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventProcessCleanup) { | 634 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventProcessCleanup) { |
641 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe")); | 635 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe")); |
642 | 636 |
643 // Lazy Background Page doesn't exist anymore. | 637 // Lazy Background Page doesn't exist anymore. |
644 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 638 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
645 } | 639 } |
646 | 640 |
647 } // namespace extensions | 641 } // namespace extensions |
OLD | NEW |