Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: chrome/browser/extensions/lazy_background_page_apitest.cc

Issue 2028873002: Fix event page process cleanup when running in --isolate-extensions mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup empty lines and formatting. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
664 // Test class to allow test cases to run in --isolate-extensions mode.
665 class LazyBackgroundPageIsolatedExtensionsApiTest
666 : public LazyBackgroundPageApiTest {
667 public:
668 LazyBackgroundPageIsolatedExtensionsApiTest() {}
669 ~LazyBackgroundPageIsolatedExtensionsApiTest() override {}
670
671 void SetUpInProcessBrowserTestFixture() override {
672 LazyBackgroundPageApiTest::SetUpInProcessBrowserTestFixture();
673
674 // This is needed to allow example.com to actually resolve and load in
675 // tests.
676 host_resolver()->AddRule("*", "127.0.0.1");
677 }
678
679 void SetUpCommandLine(base::CommandLine* command_line) override {
680 LazyBackgroundPageApiTest::SetUpCommandLine(command_line);
681 command_line->AppendSwitch(switches::kIsolateExtensions);
682 }
683
684 private:
685 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageIsolatedExtensionsApiTest);
686 };
687
688 // Ensure that the events page of an extension is properly torn down and the
689 // process does not linger around when running in --isolate-extensions mode.
690 // See https://crbug.com/612668.
691 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageIsolatedExtensionsApiTest,
692 EventProcessCleanup) {
Devlin 2016/05/31 22:45:30 This almost seems like a test that would be good t
nasko 2016/06/01 21:22:19 There is already enough coverage for the regular c
693 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe"));
694
695 // Lazy Background Page doesn't exist anymore.
696 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
697 }
698
662 } // namespace extensions 699 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698