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" |
40 #include "extensions/test/extension_test_message_listener.h" | 41 #include "extensions/test/extension_test_message_listener.h" |
41 #include "extensions/test/result_catcher.h" | 42 #include "extensions/test/result_catcher.h" |
42 #include "net/dns/mock_host_resolver.h" | 43 #include "net/dns/mock_host_resolver.h" |
43 #include "net/test/embedded_test_server/embedded_test_server.h" | 44 #include "net/test/embedded_test_server/embedded_test_server.h" |
44 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
45 #include "url/gurl.h" | 46 #include "url/gurl.h" |
46 | 47 |
47 using bookmarks::BookmarkModel; | 48 using bookmarks::BookmarkModel; |
48 using bookmarks::BookmarkNode; | 49 using bookmarks::BookmarkNode; |
49 | 50 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 98 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
98 // Set shorter delays to prevent test timeouts. | 99 // Set shorter delays to prevent test timeouts. |
99 ProcessManager::SetEventPageIdleTimeForTesting(1); | 100 ProcessManager::SetEventPageIdleTimeForTesting(1); |
100 ProcessManager::SetEventPageSuspendingTimeForTesting(1); | 101 ProcessManager::SetEventPageSuspendingTimeForTesting(1); |
101 } | 102 } |
102 | 103 |
103 void SetUpCommandLine(base::CommandLine* command_line) override { | 104 void SetUpCommandLine(base::CommandLine* command_line) override { |
104 ExtensionApiTest::SetUpCommandLine(command_line); | 105 ExtensionApiTest::SetUpCommandLine(command_line); |
105 // Disable background network activity as it can suddenly bring the Lazy | 106 // Disable background network activity as it can suddenly bring the Lazy |
106 // Background Page alive. | 107 // Background Page alive. |
107 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); | 108 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); |
108 command_line->AppendSwitch(switches::kNoProxyServer); | 109 command_line->AppendSwitch(::switches::kNoProxyServer); |
109 } | 110 } |
110 | 111 |
111 // Loads the extension, which temporarily starts the lazy background page | 112 // Loads the extension, which temporarily starts the lazy background page |
112 // to dispatch the onInstalled event. We wait until it shuts down again. | 113 // to dispatch the onInstalled event. We wait until it shuts down again. |
113 const Extension* LoadExtensionAndWait(const std::string& test_name) { | 114 const Extension* LoadExtensionAndWait(const std::string& test_name) { |
114 LazyBackgroundObserver page_complete; | 115 LazyBackgroundObserver page_complete; |
115 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 116 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
116 AppendASCII(test_name); | 117 AppendASCII(test_name); |
117 const Extension* extension = LoadExtension(extdir); | 118 const Extension* extension = LoadExtension(extdir); |
118 if (extension) | 119 if (extension) |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 // Tests that the lazy background page will be unloaded if the onSuspend event | 653 // Tests that the lazy background page will be unloaded if the onSuspend event |
653 // handler calls an API function such as chrome.storage.local.set(). | 654 // handler calls an API function such as chrome.storage.local.set(). |
654 // See: http://crbug.com/296834 | 655 // See: http://crbug.com/296834 |
655 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 656 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
656 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 657 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
657 } | 658 } |
658 | 659 |
659 // TODO: background page with timer. | 660 // TODO: background page with timer. |
660 // TODO: background page that interacts with popup. | 661 // TODO: background page that interacts with popup. |
661 | 662 |
| 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 |
662 } // namespace extensions | 698 } // namespace extensions |
OLD | NEW |