OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/process_manager.h" | 5 #include "extensions/browser/process_manager.h" |
6 | 6 |
7 #include "chrome/browser/extensions/browser_action_test_util.h" | 7 #include "chrome/browser/extensions/browser_action_test_util.h" |
8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 content::WebContents* extension_web_contents = | 150 content::WebContents* extension_web_contents = |
151 content::WebContents::FromRenderFrameHost( | 151 content::WebContents::FromRenderFrameHost( |
152 *pm->GetRenderFrameHostsForExtension(extension->id()).begin()); | 152 *pm->GetRenderFrameHostsForExtension(extension->id()).begin()); |
153 EXPECT_TRUE(extension_web_contents->GetSiteInstance() != | 153 EXPECT_TRUE(extension_web_contents->GetSiteInstance() != |
154 tab_web_contents->GetSiteInstance()); | 154 tab_web_contents->GetSiteInstance()); |
155 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()) != | 155 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()) != |
156 tab_web_contents->GetSiteInstance()); | 156 tab_web_contents->GetSiteInstance()); |
157 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); | 157 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); |
158 } | 158 } |
159 | 159 |
| 160 // Verify correct keepalive count behavior on network request events. |
| 161 // Regression test for http://crbug.com/535716. |
| 162 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, KeepaliveOnNetworkRequest) { |
| 163 // Load an extension with a lazy background page. |
| 164 scoped_refptr<const Extension> extension = |
| 165 LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 166 .AppendASCII("lazy_background_page") |
| 167 .AppendASCII("broadcast_event")); |
| 168 ASSERT_TRUE(extension.get()); |
| 169 |
| 170 ProcessManager* pm = ProcessManager::Get(profile()); |
| 171 ProcessManager::FrameSet frames = |
| 172 pm->GetRenderFrameHostsForExtension(extension->id()); |
| 173 ASSERT_EQ(1u, frames.size()); |
| 174 |
| 175 // Keepalive count at this point is unpredictable as there may be an |
| 176 // outstanding event dispatch. We use the current keepalive count as a |
| 177 // reliable baseline for future expectations. |
| 178 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); |
| 179 |
| 180 // Simulate some network events. This test assumes no other network requests |
| 181 // are pending, i.e., that there are no conflicts with the fake request IDs |
| 182 // we're using. This should be a safe assumption because LoadExtension should |
| 183 // wait for loads to complete, and we don't run the message loop otherwise. |
| 184 content::RenderFrameHost* frame_host = *frames.begin(); |
| 185 pm->OnNetworkRequestStarted(frame_host, 1); |
| 186 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); |
| 187 pm->OnNetworkRequestDone(frame_host, 1); |
| 188 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); |
| 189 |
| 190 // Simulate only a request completion for this ID and ensure it doesn't result |
| 191 // in keepalive decrement. |
| 192 pm->OnNetworkRequestDone(frame_host, 2); |
| 193 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); |
| 194 } |
| 195 |
160 } // namespace extensions | 196 } // namespace extensions |
OLD | NEW |