| 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 19 matching lines...) Expand all Loading... |
| 30 #include "components/bookmarks/browser/bookmark_utils.h" | 30 #include "components/bookmarks/browser/bookmark_utils.h" |
| 31 #include "components/bookmarks/test/bookmark_test_helpers.h" | 31 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
| 34 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
| 35 #include "extensions/browser/extension_host.h" | 35 #include "extensions/browser/extension_host.h" |
| 36 #include "extensions/browser/extension_registry.h" | 36 #include "extensions/browser/extension_registry.h" |
| 37 #include "extensions/browser/extension_registry_observer.h" | 37 #include "extensions/browser/extension_registry_observer.h" |
| 38 #include "extensions/browser/process_manager.h" | 38 #include "extensions/browser/process_manager.h" |
| 39 #include "extensions/common/extension.h" | 39 #include "extensions/common/extension.h" |
| 40 #include "extensions/common/switches.h" | |
| 41 #include "extensions/test/extension_test_message_listener.h" | 40 #include "extensions/test/extension_test_message_listener.h" |
| 42 #include "extensions/test/result_catcher.h" | 41 #include "extensions/test/result_catcher.h" |
| 43 #include "net/dns/mock_host_resolver.h" | 42 #include "net/dns/mock_host_resolver.h" |
| 44 #include "net/test/embedded_test_server/embedded_test_server.h" | 43 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 46 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 47 | 46 |
| 48 using bookmarks::BookmarkModel; | 47 using bookmarks::BookmarkModel; |
| 49 using bookmarks::BookmarkNode; | 48 using bookmarks::BookmarkNode; |
| 50 | 49 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 97 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 99 // Set shorter delays to prevent test timeouts. | 98 // Set shorter delays to prevent test timeouts. |
| 100 ProcessManager::SetEventPageIdleTimeForTesting(1); | 99 ProcessManager::SetEventPageIdleTimeForTesting(1); |
| 101 ProcessManager::SetEventPageSuspendingTimeForTesting(1); | 100 ProcessManager::SetEventPageSuspendingTimeForTesting(1); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void SetUpCommandLine(base::CommandLine* command_line) override { | 103 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 105 ExtensionApiTest::SetUpCommandLine(command_line); | 104 ExtensionApiTest::SetUpCommandLine(command_line); |
| 106 // Disable background network activity as it can suddenly bring the Lazy | 105 // Disable background network activity as it can suddenly bring the Lazy |
| 107 // Background Page alive. | 106 // Background Page alive. |
| 108 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); | 107 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); |
| 109 command_line->AppendSwitch(::switches::kNoProxyServer); | 108 command_line->AppendSwitch(switches::kNoProxyServer); |
| 110 } | 109 } |
| 111 | 110 |
| 112 // Loads the extension, which temporarily starts the lazy background page | 111 // Loads the extension, which temporarily starts the lazy background page |
| 113 // to dispatch the onInstalled event. We wait until it shuts down again. | 112 // to dispatch the onInstalled event. We wait until it shuts down again. |
| 114 const Extension* LoadExtensionAndWait(const std::string& test_name) { | 113 const Extension* LoadExtensionAndWait(const std::string& test_name) { |
| 115 LazyBackgroundObserver page_complete; | 114 LazyBackgroundObserver page_complete; |
| 116 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 115 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
| 117 AppendASCII(test_name); | 116 AppendASCII(test_name); |
| 118 const Extension* extension = LoadExtension(extdir); | 117 const Extension* extension = LoadExtension(extdir); |
| 119 if (extension) | 118 if (extension) |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 // Tests that the lazy background page will be unloaded if the onSuspend event | 652 // Tests that the lazy background page will be unloaded if the onSuspend event |
| 654 // handler calls an API function such as chrome.storage.local.set(). | 653 // handler calls an API function such as chrome.storage.local.set(). |
| 655 // See: http://crbug.com/296834 | 654 // See: http://crbug.com/296834 |
| 656 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 655 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
| 657 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 656 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
| 658 } | 657 } |
| 659 | 658 |
| 660 // TODO: background page with timer. | 659 // TODO: background page with timer. |
| 661 // TODO: background page that interacts with popup. | 660 // TODO: background page that interacts with popup. |
| 662 | 661 |
| 663 // Test class to allow test cases to run in --isolate-extensions mode. | |
| 664 class LazyBackgroundPageIsolatedExtensionsApiTest | |
| 665 : public LazyBackgroundPageApiTest { | |
| 666 public: | |
| 667 LazyBackgroundPageIsolatedExtensionsApiTest() {} | |
| 668 ~LazyBackgroundPageIsolatedExtensionsApiTest() override {} | |
| 669 | |
| 670 void SetUpInProcessBrowserTestFixture() override { | |
| 671 LazyBackgroundPageApiTest::SetUpInProcessBrowserTestFixture(); | |
| 672 | |
| 673 // This is needed to allow example.com to actually resolve and load in | |
| 674 // tests. | |
| 675 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 676 } | |
| 677 | |
| 678 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 679 LazyBackgroundPageApiTest::SetUpCommandLine(command_line); | |
| 680 command_line->AppendSwitch(switches::kIsolateExtensions); | |
| 681 } | |
| 682 | |
| 683 private: | |
| 684 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageIsolatedExtensionsApiTest); | |
| 685 }; | |
| 686 | |
| 687 // Ensure that the events page of an extension is properly torn down and the | |
| 688 // process does not linger around when running in --isolate-extensions mode. | |
| 689 // See https://crbug.com/612668. | |
| 690 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageIsolatedExtensionsApiTest, | |
| 691 EventProcessCleanup) { | |
| 692 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe")); | |
| 693 | |
| 694 // Lazy Background Page doesn't exist anymore. | |
| 695 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | |
| 696 } | |
| 697 | |
| 698 } // namespace extensions | 662 } // namespace extensions |
| OLD | NEW |