This source file includes following definitions.
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/switches.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
using content::NavigationController;
using content::WebContents;
namespace {
class ProcessManagementTest : public ExtensionBrowserTest {
private:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(
extensions::switches::kEnableExperimentalExtensionApis);
}
};
}
#if defined(OS_WIN)
#define MAYBE_ProcessOverflow DISABLED_ProcessOverflow
#else
#define MAYBE_ProcessOverflow ProcessOverflow
#endif
IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ProcessOverflow) {
content::RenderProcessHost::SetMaxRendererProcessCount(1);
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2")));
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("hosted_app")));
ASSERT_TRUE(
LoadExtension(test_data_dir_.AppendASCII("api_test/app_process")));
GURL base_url = embedded_test_server()->GetURL(
"/extensions/");
GURL::Replacements replace_host;
std::string host_str("localhost");
replace_host.SetHostStr(host_str);
base_url = base_url.ReplaceComponents(replace_host);
const extensions::Extension* extension1 = LoadExtension(
test_data_dir_.AppendASCII("api_test/browser_action/basics"));
ASSERT_TRUE(extension1);
GURL extension1_url = extension1->url();
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("isolated_apps/app1/main.html"),
CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("hosted_app/main.html"),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("test_file.html"),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("isolated_apps/app2/main.html"),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("api_test/app_process/path1/empty.html"),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("test_file_with_body.html"),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("isolated_apps/app1/main.html"),
NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
const extensions::Extension* extension2 = LoadExtension(
test_data_dir_.AppendASCII("api_test/browser_action/close_background"));
ASSERT_TRUE(extension2);
GURL extension2_url = extension2->url();
ASSERT_EQ(9, browser()->tab_strip_model()->count());
content::RenderProcessHost* isolated1_host =
browser()->tab_strip_model()->GetWebContentsAt(0)->GetRenderProcessHost();
content::RenderProcessHost* ntp1_host =
browser()->tab_strip_model()->GetWebContentsAt(1)->GetRenderProcessHost();
content::RenderProcessHost* hosted1_host =
browser()->tab_strip_model()->GetWebContentsAt(2)->GetRenderProcessHost();
content::RenderProcessHost* web1_host =
browser()->tab_strip_model()->GetWebContentsAt(3)->GetRenderProcessHost();
content::RenderProcessHost* isolated2_host =
browser()->tab_strip_model()->GetWebContentsAt(4)->GetRenderProcessHost();
content::RenderProcessHost* ntp2_host =
browser()->tab_strip_model()->GetWebContentsAt(5)->GetRenderProcessHost();
content::RenderProcessHost* hosted2_host =
browser()->tab_strip_model()->GetWebContentsAt(6)->GetRenderProcessHost();
content::RenderProcessHost* web2_host =
browser()->tab_strip_model()->GetWebContentsAt(7)->GetRenderProcessHost();
content::RenderProcessHost* second_isolated1_host =
browser()->tab_strip_model()->GetWebContentsAt(8)->GetRenderProcessHost();
extensions::ProcessManager* process_manager =
extensions::ExtensionSystem::Get(browser()->profile())->
process_manager();
content::RenderProcessHost* extension1_host =
process_manager->GetSiteInstanceForURL(extension1_url)->GetProcess();
content::RenderProcessHost* extension2_host =
process_manager->GetSiteInstanceForURL(extension2_url)->GetProcess();
EXPECT_EQ(isolated1_host, second_isolated1_host);
EXPECT_NE(isolated1_host, isolated2_host);
EXPECT_NE(isolated1_host, ntp1_host);
EXPECT_NE(isolated1_host, hosted1_host);
EXPECT_NE(isolated1_host, web1_host);
EXPECT_NE(isolated1_host, extension1_host);
EXPECT_NE(isolated2_host, ntp1_host);
EXPECT_NE(isolated2_host, hosted1_host);
EXPECT_NE(isolated2_host, web1_host);
EXPECT_NE(isolated2_host, extension1_host);
EXPECT_EQ(ntp1_host, ntp2_host);
EXPECT_NE(ntp1_host, hosted1_host);
EXPECT_NE(ntp1_host, web1_host);
EXPECT_NE(ntp1_host, extension1_host);
EXPECT_EQ(hosted1_host, hosted2_host);
EXPECT_NE(hosted1_host, web1_host);
EXPECT_NE(hosted1_host, extension1_host);
EXPECT_EQ(web1_host, web2_host);
EXPECT_NE(web1_host, extension1_host);
EXPECT_EQ(extension1_host, extension2_host);
}
#if defined(OS_WIN)
#define MAYBE_ExtensionProcessBalancing DISABLED_ExtensionProcessBalancing
#else
#define MAYBE_ExtensionProcessBalancing ExtensionProcessBalancing
#endif
IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ExtensionProcessBalancing) {
content::RenderProcessHost::SetMaxRendererProcessCount(6);
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = embedded_test_server()->GetURL(
"/extensions/");
GURL::Replacements replace_host;
std::string host_str("localhost");
replace_host.SetHostStr(host_str);
base_url = base_url.ReplaceComponents(replace_host);
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test/browser_action/none")));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test/browser_action/basics")));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test/browser_action/remove_popup")));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test/browser_action/add_popup")));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test/browser_action/no_icon")));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("isolated_apps/app1")));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test/management/test")));
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("isolated_apps/app1/main.html"),
CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("api_test/management/test/basics.html"),
CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
std::set<int> process_ids;
Profile* profile = browser()->profile();
extensions::ProcessManager* epm = extensions::ExtensionSystem::Get(profile)->
process_manager();
for (extensions::ProcessManager::const_iterator iter =
epm->background_hosts().begin();
iter != epm->background_hosts().end(); ++iter) {
process_ids.insert((*iter)->render_process_host()->GetID());
}
extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
EXPECT_GE((size_t) 6, process_map->size());
EXPECT_EQ((size_t) 2, process_ids.size());
}