Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "chrome/browser/extensions/browser_action_test_util.h" | 14 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 15 #include "chrome/browser/extensions/extension_browsertest.h" | 15 #include "chrome/browser/extensions/extension_browsertest.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/extensions/test_extension_dir.h" | 17 #include "chrome/browser/extensions/test_extension_dir.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/common/extensions/extension_process_policy.h" | 19 #include "chrome/common/extensions/extension_process_policy.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "content/public/browser/render_process_host.h" | |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 26 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 27 #include "extensions/common/value_builder.h" | 28 #include "extensions/common/value_builder.h" |
| 28 #include "extensions/test/background_page_watcher.h" | 29 #include "extensions/test/background_page_watcher.h" |
| 29 #include "net/dns/mock_host_resolver.h" | 30 #include "net/dns/mock_host_resolver.h" |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 31 | 32 |
| 32 namespace extensions { | 33 namespace extensions { |
| 33 | 34 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); | 521 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); |
| 521 pm->OnNetworkRequestDone(frame_host, 1); | 522 pm->OnNetworkRequestDone(frame_host, 1); |
| 522 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); | 523 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); |
| 523 | 524 |
| 524 // Simulate only a request completion for this ID and ensure it doesn't result | 525 // Simulate only a request completion for this ID and ensure it doesn't result |
| 525 // in keepalive decrement. | 526 // in keepalive decrement. |
| 526 pm->OnNetworkRequestDone(frame_host, 2); | 527 pm->OnNetworkRequestDone(frame_host, 2); |
| 527 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); | 528 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); |
| 528 } | 529 } |
| 529 | 530 |
| 531 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, ExtensionProcessReuse) { | |
| 532 content::RenderProcessHost::SetMaxRendererProcessCount(2); | |
| 533 ProcessManager* pm = ProcessManager::Get(profile()); | |
| 534 | |
| 535 std::set<int> processes; | |
| 536 std::set<const Extension*> installed_extensions; | |
| 537 | |
| 538 // Create 3 extensions, which is more than the process limit. | |
| 539 for (int i = 1; i <= 3; i++) { | |
|
Devlin
2016/04/07 15:06:37
nit: ++i
ncarter (slow)
2016/04/07 21:41:09
Done.
| |
| 540 const Extension* extension = | |
| 541 CreateExtension(base::StringPrintf("Extension %d", i), true); | |
| 542 installed_extensions.insert(extension); | |
| 543 ExtensionHost* extension_host = | |
| 544 pm->GetBackgroundHostForExtension(extension->id()); | |
| 545 | |
| 546 EXPECT_EQ(GURL("chrome-extension://" + extension->id()), | |
|
Devlin
2016/04/07 15:06:37
nit: extension->url()
ncarter (slow)
2016/04/07 21:41:09
Done.
| |
| 547 extension_host->host_contents()->GetSiteInstance()->GetSiteURL()); | |
| 548 | |
| 549 processes.insert(extension_host->render_process_host()->GetID()); | |
| 550 } | |
| 551 | |
| 552 EXPECT_EQ(3U, installed_extensions.size()); | |
|
Devlin
2016/04/07 15:06:37
given the number of 3us here, it might be more rea
ncarter (slow)
2016/04/07 21:41:09
Done.
| |
| 553 | |
| 554 if (content::AreAllSitesIsolatedForTesting()) { | |
| 555 EXPECT_EQ(3U, processes.size()) << "Extension process reuse is expected to " | |
| 556 "be disabled in --site-per-process."; | |
| 557 } else { | |
| 558 EXPECT_LT(processes.size(), 3U) | |
| 559 << "Expected extension process reuse, but none happened."; | |
| 560 } | |
| 561 | |
| 562 // Interact with each extension background page by setting and reading back | |
| 563 // the cookie. This would fail for one of the two extensions in a shared | |
| 564 // process, if that process is locked to a single origin. This is a regression | |
| 565 // test for http://crbug.com/600441. | |
| 566 for (const Extension* extension : installed_extensions) { | |
| 567 content::DOMMessageQueue queue; | |
| 568 ExecuteScriptInBackgroundPageNoWait( | |
| 569 extension->id(), | |
| 570 "document.cookie = 'extension_cookie';" | |
| 571 "window.domAutomationController.send(document.cookie);"); | |
| 572 std::string message; | |
| 573 ASSERT_TRUE(queue.WaitForMessage(&message)); | |
| 574 EXPECT_EQ(message, "\"extension_cookie\""); | |
| 575 } | |
| 576 } | |
| 577 | |
| 530 } // namespace extensions | 578 } // namespace extensions |
| OLD | NEW |