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

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

Issue 2689963003: Don't report a keepalive count for persistent pages. (Closed)
Patch Set: Address review comments Created 3 years, 10 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
« no previous file with comments | « no previous file | extensions/browser/process_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 19 matching lines...) Expand all
30 #include "content/public/browser/render_frame_host.h" 30 #include "content/public/browser/render_frame_host.h"
31 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
33 #include "content/public/common/browser_side_navigation_policy.h" 33 #include "content/public/common/browser_side_navigation_policy.h"
34 #include "content/public/test/browser_test_utils.h" 34 #include "content/public/test/browser_test_utils.h"
35 #include "content/public/test/test_navigation_observer.h" 35 #include "content/public/test/test_navigation_observer.h"
36 #include "content/public/test/test_utils.h" 36 #include "content/public/test/test_utils.h"
37 #include "extensions/browser/app_window/app_window.h" 37 #include "extensions/browser/app_window/app_window.h"
38 #include "extensions/browser/app_window/app_window_registry.h" 38 #include "extensions/browser/app_window/app_window_registry.h"
39 #include "extensions/browser/process_manager.h" 39 #include "extensions/browser/process_manager.h"
40 #include "extensions/common/manifest_handlers/background_info.h"
40 #include "extensions/common/permissions/permissions_data.h" 41 #include "extensions/common/permissions/permissions_data.h"
41 #include "extensions/common/value_builder.h" 42 #include "extensions/common/value_builder.h"
42 #include "extensions/test/background_page_watcher.h" 43 #include "extensions/test/background_page_watcher.h"
43 #include "net/dns/mock_host_resolver.h" 44 #include "net/dns/mock_host_resolver.h"
44 #include "net/test/embedded_test_server/embedded_test_server.h" 45 #include "net/test/embedded_test_server/embedded_test_server.h"
45 46
46 namespace extensions { 47 namespace extensions {
47 48
48 namespace { 49 namespace {
49 50
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 ASSERT_EQ(0u, pm->background_hosts().size()); 280 ASSERT_EQ(0u, pm->background_hosts().size());
280 ASSERT_EQ(0u, pm->GetAllFrames().size()); 281 ASSERT_EQ(0u, pm->GetAllFrames().size());
281 282
282 // Load an extension with a background page. 283 // Load an extension with a background page.
283 scoped_refptr<const Extension> extension = 284 scoped_refptr<const Extension> extension =
284 LoadExtension(test_data_dir_.AppendASCII("api_test") 285 LoadExtension(test_data_dir_.AppendASCII("api_test")
285 .AppendASCII("browser_action") 286 .AppendASCII("browser_action")
286 .AppendASCII("none")); 287 .AppendASCII("none"));
287 ASSERT_TRUE(extension.get()); 288 ASSERT_TRUE(extension.get());
288 289
290 EXPECT_TRUE(BackgroundInfo::HasPersistentBackgroundPage(extension.get()));
291 EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(extension.get()));
292
289 // Process manager gains a background host. 293 // Process manager gains a background host.
290 EXPECT_EQ(1u, pm->background_hosts().size()); 294 EXPECT_EQ(1u, pm->background_hosts().size());
291 EXPECT_EQ(1u, pm->GetAllFrames().size()); 295 EXPECT_EQ(1u, pm->GetAllFrames().size());
292 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); 296 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id()));
293 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); 297 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()));
294 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); 298 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size());
295 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); 299 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id()));
296 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(extension.get()));
297 300
298 // Unload the extension. 301 // Unload the extension.
299 UnloadExtension(extension->id()); 302 UnloadExtension(extension->id());
300 303
301 // Background host disappears. 304 // Background host disappears.
302 EXPECT_EQ(0u, pm->background_hosts().size()); 305 EXPECT_EQ(0u, pm->background_hosts().size());
303 EXPECT_EQ(0u, pm->GetAllFrames().size()); 306 EXPECT_EQ(0u, pm->GetAllFrames().size());
304 EXPECT_FALSE(pm->GetBackgroundHostForExtension(extension->id())); 307 EXPECT_FALSE(pm->GetBackgroundHostForExtension(extension->id()));
305 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); 308 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()));
306 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); 309 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size());
307 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); 310 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id()));
308 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(extension.get()));
309 } 311 }
310 312
311 // Test that loading an extension with a browser action does not create a 313 // Test that loading an extension with a browser action does not create a
312 // background page and that clicking on the action creates the appropriate 314 // background page and that clicking on the action creates the appropriate
313 // ExtensionHost. 315 // ExtensionHost.
314 // Disabled due to flake, see http://crbug.com/315242 316 // Disabled due to flake, see http://crbug.com/315242
315 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, 317 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest,
316 DISABLED_PopupHostCreation) { 318 DISABLED_PopupHostCreation) {
317 ProcessManager* pm = ProcessManager::Get(profile()); 319 ProcessManager* pm = ProcessManager::Get(profile());
318 320
319 // Load an extension with the ability to open a popup but no background 321 // Load an extension with the ability to open a popup but no background
320 // page. 322 // page.
321 scoped_refptr<const Extension> popup = 323 scoped_refptr<const Extension> popup =
322 LoadExtension(test_data_dir_.AppendASCII("api_test") 324 LoadExtension(test_data_dir_.AppendASCII("api_test")
323 .AppendASCII("browser_action") 325 .AppendASCII("browser_action")
324 .AppendASCII("popup")); 326 .AppendASCII("popup"));
325 ASSERT_TRUE(popup.get()); 327 ASSERT_TRUE(popup.get());
326 328
329 EXPECT_FALSE(BackgroundInfo::HasBackgroundPage(extension.get()));
330 EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(extension.get()));
331
327 // No background host was added. 332 // No background host was added.
328 EXPECT_EQ(0u, pm->background_hosts().size()); 333 EXPECT_EQ(0u, pm->background_hosts().size());
329 EXPECT_EQ(0u, pm->GetAllFrames().size()); 334 EXPECT_EQ(0u, pm->GetAllFrames().size());
330 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); 335 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id()));
331 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); 336 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(popup->id()).size());
332 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); 337 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url()));
333 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); 338 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id()));
334 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get()));
335 339
336 // Simulate clicking on the action to open a popup. 340 // Simulate clicking on the action to open a popup.
337 BrowserActionTestUtil test_util(browser()); 341 BrowserActionTestUtil test_util(browser());
338 content::WindowedNotificationObserver frame_observer( 342 content::WindowedNotificationObserver frame_observer(
339 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 343 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
340 content::NotificationService::AllSources()); 344 content::NotificationService::AllSources());
341 // Open popup in the first extension. 345 // Open popup in the first extension.
342 test_util.Press(0); 346 test_util.Press(0);
343 frame_observer.Wait(); 347 frame_observer.Wait();
344 ASSERT_TRUE(test_util.HasPopup()); 348 ASSERT_TRUE(test_util.HasPopup());
345 349
346 // We now have a view, but still no background hosts. 350 // We now have a view, but still no background hosts.
347 EXPECT_EQ(0u, pm->background_hosts().size()); 351 EXPECT_EQ(0u, pm->background_hosts().size());
348 EXPECT_EQ(1u, pm->GetAllFrames().size()); 352 EXPECT_EQ(1u, pm->GetAllFrames().size());
349 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); 353 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id()));
350 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); 354 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(popup->id()).size());
351 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); 355 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url()));
352 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); 356 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id()));
353 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get()));
Devlin 2017/02/14 17:48:37 nitty nit: might be worth keeping this (as a check
Wez 2017/02/14 20:02:22 Done.
354 } 357 }
355 358
356 // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not 359 // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not
357 // interact with an installed extension with that ID. Regression test 360 // interact with an installed extension with that ID. Regression test
358 // for bug 357382. 361 // for bug 357382.
359 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) { 362 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) {
360 ProcessManager* pm = ProcessManager::Get(profile()); 363 ProcessManager* pm = ProcessManager::Get(profile());
361 364
362 // We start with no background hosts. 365 // We start with no background hosts.
363 ASSERT_EQ(0u, pm->background_hosts().size()); 366 ASSERT_EQ(0u, pm->background_hosts().size());
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 ASSERT_TRUE(extension.get()); 605 ASSERT_TRUE(extension.get());
603 606
604 ProcessManager* pm = ProcessManager::Get(profile()); 607 ProcessManager* pm = ProcessManager::Get(profile());
605 ProcessManager::FrameSet frames = 608 ProcessManager::FrameSet frames =
606 pm->GetRenderFrameHostsForExtension(extension->id()); 609 pm->GetRenderFrameHostsForExtension(extension->id());
607 ASSERT_EQ(1u, frames.size()); 610 ASSERT_EQ(1u, frames.size());
608 611
609 // Keepalive count at this point is unpredictable as there may be an 612 // Keepalive count at this point is unpredictable as there may be an
610 // outstanding event dispatch. We use the current keepalive count as a 613 // outstanding event dispatch. We use the current keepalive count as a
611 // reliable baseline for future expectations. 614 // reliable baseline for future expectations.
615 EXPECT_TRUE(BackgroundInfo::HasLazyBackgroundPage(extension.get()));
612 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); 616 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get());
617 EXPECT_LE(0, baseline_keepalive);
613 618
614 // Simulate some network events. This test assumes no other network requests 619 // Simulate some network events. This test assumes no other network requests
615 // are pending, i.e., that there are no conflicts with the fake request IDs 620 // are pending, i.e., that there are no conflicts with the fake request IDs
616 // we're using. This should be a safe assumption because LoadExtension should 621 // we're using. This should be a safe assumption because LoadExtension should
617 // wait for loads to complete, and we don't run the message loop otherwise. 622 // wait for loads to complete, and we don't run the message loop otherwise.
618 content::RenderFrameHost* frame_host = *frames.begin(); 623 content::RenderFrameHost* frame_host = *frames.begin();
619 pm->OnNetworkRequestStarted(frame_host, 1); 624 pm->OnNetworkRequestStarted(frame_host, 1);
620 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); 625 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get()));
621 pm->OnNetworkRequestDone(frame_host, 1); 626 pm->OnNetworkRequestDone(frame_host, 1);
622 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); 627 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get()));
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 EXPECT_TRUE(ExecuteScriptAndExtractBool( 1161 EXPECT_TRUE(ExecuteScriptAndExtractBool(
1157 popup, "window.domAutomationController.send(!!window.opener)", 1162 popup, "window.domAutomationController.send(!!window.opener)",
1158 &is_opener_defined)); 1163 &is_opener_defined));
1159 EXPECT_TRUE(is_opener_defined); 1164 EXPECT_TRUE(is_opener_defined);
1160 1165
1161 // Verify that postMessage to window.opener works. 1166 // Verify that postMessage to window.opener works.
1162 VerifyPostMessageToOpener(popup->GetMainFrame(), extension_frame); 1167 VerifyPostMessageToOpener(popup->GetMainFrame(), extension_frame);
1163 } 1168 }
1164 1169
1165 } // namespace extensions 1170 } // namespace extensions
OLDNEW
« 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