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

Unified Diff: chrome/browser/extensions/process_manager_browsertest.cc

Issue 1366393002: Prevent imbalanced keepalive counts in ProcessManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a test! Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/browser/process_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/process_manager_browsertest.cc
diff --git a/chrome/browser/extensions/process_manager_browsertest.cc b/chrome/browser/extensions/process_manager_browsertest.cc
index c8a8e003843952b9bb66f5736e54990338d40f60..c72427047d918db70a2c137fda0d60c5415045ca 100644
--- a/chrome/browser/extensions/process_manager_browsertest.cc
+++ b/chrome/browser/extensions/process_manager_browsertest.cc
@@ -157,4 +157,39 @@ IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) {
EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id()));
}
+// Verify correct keepalive count behavior on network request events.
+IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, KeepaliveOnNetworkRequest) {
+ // Load an extension with a lazy background page.
+ scoped_refptr<const Extension> extension =
+ LoadExtension(test_data_dir_.AppendASCII("api_test")
+ .AppendASCII("lazy_background_page")
+ .AppendASCII("broadcast_event"));
+ ASSERT_TRUE(extension.get());
+
+ ProcessManager* pm = ProcessManager::Get(profile());
+ ProcessManager::FrameSet frames =
+ pm->GetRenderFrameHostsForExtension(extension->id());
+ EXPECT_EQ(1u, frames.size());
Devlin 2015/09/28 21:51:48 nitty nit: may as well make this an assert, since
Ken Rockot(use gerrit already) 2015/09/28 21:55:20 Done.
+
+ // Keepalive count at this point is unpredictable as there may be an
+ // outstanding event dispatch. We use the current keepalive count as a
+ // reliable baseline for future expectations.
+ int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get());
+
+ // Simulate some network events. This test assumes no other network requests
+ // are pending, i.e., that there are no conflicts with the fake request IDs
+ // we're using. This should be a safe assumption because LoadExtension should
+ // wait for loads to complete, and we don't run the message loop otherwise.
+ content::RenderFrameHost* frame_host = *frames.begin();
+ pm->OnNetworkRequestStarted(frame_host, 1);
+ EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get()));
+ pm->OnNetworkRequestDone(frame_host, 1);
+ EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get()));
+
+ // Simulate only a request completion for this ID and ensure it doesn't result
+ // in keepalive decrement.
Devlin 2015/09/28 21:51:48 nit: add // Regression test for crbug.com/535716.
Ken Rockot(use gerrit already) 2015/09/28 21:55:20 Done.
+ pm->OnNetworkRequestDone(frame_host, 2);
+ EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get()));
+}
+
} // namespace extensions
« no previous file with comments | « no previous file | extensions/browser/process_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698