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 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, KeepaliveOnNetworkRequest) { | |
162 // Load an extension with a lazy background page. | |
163 scoped_refptr<const Extension> extension = | |
164 LoadExtension(test_data_dir_.AppendASCII("api_test") | |
165 .AppendASCII("lazy_background_page") | |
166 .AppendASCII("broadcast_event")); | |
167 ASSERT_TRUE(extension.get()); | |
168 | |
169 ProcessManager* pm = ProcessManager::Get(profile()); | |
170 ProcessManager::FrameSet frames = | |
171 pm->GetRenderFrameHostsForExtension(extension->id()); | |
172 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.
| |
173 | |
174 // Keepalive count at this point is unpredictable as there may be an | |
175 // outstanding event dispatch. We use the current keepalive count as a | |
176 // reliable baseline for future expectations. | |
177 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); | |
178 | |
179 // Simulate some network events. This test assumes no other network requests | |
180 // are pending, i.e., that there are no conflicts with the fake request IDs | |
181 // we're using. This should be a safe assumption because LoadExtension should | |
182 // wait for loads to complete, and we don't run the message loop otherwise. | |
183 content::RenderFrameHost* frame_host = *frames.begin(); | |
184 pm->OnNetworkRequestStarted(frame_host, 1); | |
185 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); | |
186 pm->OnNetworkRequestDone(frame_host, 1); | |
187 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); | |
188 | |
189 // Simulate only a request completion for this ID and ensure it doesn't result | |
190 // 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.
| |
191 pm->OnNetworkRequestDone(frame_host, 2); | |
192 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); | |
193 } | |
194 | |
160 } // namespace extensions | 195 } // namespace extensions |
OLD | NEW |