| Index: chrome/browser/extensions/app_process_apitest.cc
|
| diff --git a/chrome/browser/extensions/app_process_apitest.cc b/chrome/browser/extensions/app_process_apitest.cc
|
| index 7f670458ccb2b0ed076b4e6a75a8fa15f68c332f..7192af277844fb61ffb38efb4b2a820650dd6c0e 100644
|
| --- a/chrome/browser/extensions/app_process_apitest.cc
|
| +++ b/chrome/browser/extensions/app_process_apitest.cc
|
| @@ -28,21 +28,6 @@
|
| using content::NavigationController;
|
| using content::WebContents;
|
|
|
| -class AppApiTest : public ExtensionApiTest {
|
| - protected:
|
| - // Gets the base URL for files for a specific test, making sure that it uses
|
| - // "localhost" as the hostname, since that is what the extent is declared
|
| - // as in the test apps manifests.
|
| - GURL GetTestBaseURL(std::string test_directory) {
|
| - GURL::Replacements replace_host;
|
| - std::string host_str("localhost"); // must stay in scope with replace_host
|
| - replace_host.SetHostStr(host_str);
|
| - GURL base_url = test_server()->GetURL(
|
| - "files/extensions/api_test/" + test_directory + "/");
|
| - return base_url.ReplaceComponents(replace_host);
|
| - }
|
| -};
|
| -
|
| // Simulates a page calling window.open on an URL, and waits for the navigation.
|
| static void WindowOpenHelper(Browser* browser,
|
| RenderViewHost* opener_host,
|
| @@ -87,12 +72,97 @@ static void NavigateTabHelper(WebContents* contents, const GURL& url) {
|
| EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL());
|
| }
|
|
|
| +class AppApiTest : public ExtensionApiTest {
|
| + protected:
|
| + // Gets the base URL for files for a specific test, making sure that it uses
|
| + // "localhost" as the hostname, since that is what the extent is declared
|
| + // as in the test apps manifests.
|
| + GURL GetTestBaseURL(std::string test_directory) {
|
| + GURL::Replacements replace_host;
|
| + std::string host_str("localhost"); // must stay in scope with replace_host
|
| + replace_host.SetHostStr(host_str);
|
| + GURL base_url = test_server()->GetURL(
|
| + "files/extensions/api_test/" + test_directory + "/");
|
| + return base_url.ReplaceComponents(replace_host);
|
| + }
|
| +
|
| + // Pass flags to make testing apps easier.
|
| + void SetUpCommandLine(CommandLine* command_line) {
|
| + ExtensionApiTest::SetUpCommandLine(command_line);
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + switches::kDisablePopupBlocking);
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + switches::kAllowHTTPBackgroundPage);
|
| + }
|
| +
|
| + // Helper function to test that independent tabs of the named app are loaded
|
| + // into separate processes.
|
| + void TestAppInstancesHelper(std::string app_name) {
|
| + LOG(INFO) << "Start of test.";
|
| +
|
| + extensions::ProcessMap* process_map =
|
| + browser()->profile()->GetExtensionService()->process_map();
|
| +
|
| + host_resolver()->AddRule("*", "127.0.0.1");
|
| + ASSERT_TRUE(test_server()->Start());
|
| +
|
| + ASSERT_TRUE(LoadExtension(
|
| + test_data_dir_.AppendASCII(app_name)));
|
| +
|
| + // Open two tabs in the app, one outside it.
|
| + GURL base_url = GetTestBaseURL(app_name);
|
| +
|
| + // Test both opening a URL in a new tab, and opening a tab and then
|
| + // navigating it. Either way, app tabs should be considered extension
|
| + // processes, but they have no elevated privileges and thus should not
|
| + // have WebUI bindings.
|
| + ui_test_utils::NavigateToURLWithDisposition(
|
| + browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
|
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
|
| + LOG(INFO) << "Nav 1.";
|
| + EXPECT_TRUE(process_map->Contains(
|
| + browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID()));
|
| + EXPECT_FALSE(browser()->GetWebContentsAt(1)->GetWebUI());
|
| +
|
| + ui_test_utils::WindowedNotificationObserver tab_added_observer(
|
| + content::NOTIFICATION_TAB_ADDED,
|
| + content::NotificationService::AllSources());
|
| + browser()->NewTab();
|
| + tab_added_observer.Wait();
|
| + LOG(INFO) << "New tab.";
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + base_url.Resolve("path2/empty.html"));
|
| + LOG(INFO) << "Nav 2.";
|
| + EXPECT_TRUE(process_map->Contains(
|
| + browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()));
|
| + EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI());
|
| +
|
| + // We should have opened 2 new extension tabs. Including the original blank
|
| + // tab, we now have 3 tabs. The two app tabs should not be in the same
|
| + // process, since they do not have the background permission. (Thus, we
|
| + // want to separate them to improve responsiveness.)
|
| + ASSERT_EQ(3, browser()->tab_count());
|
| + RenderViewHost* host1 = browser()->GetWebContentsAt(1)->GetRenderViewHost();
|
| + RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost();
|
| + EXPECT_NE(host1->process(), host2->process());
|
| +
|
| + // Opening tabs with window.open should keep the page in the opener's
|
| + // process.
|
| + ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
|
| + WindowOpenHelper(browser(), host1,
|
| + base_url.Resolve("path1/empty.html"), true);
|
| + LOG(INFO) << "WindowOpenHelper 1.";
|
| + WindowOpenHelper(browser(), host2,
|
| + base_url.Resolve("path2/empty.html"), true);
|
| + LOG(INFO) << "End of test.";
|
| + }
|
| +};
|
| +
|
| +// Tests that hosted apps with the background permission get a process-per-app
|
| +// model, since all pages need to be able to script the background page.
|
| IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) {
|
| LOG(INFO) << "Start of test.";
|
|
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kDisablePopupBlocking);
|
| -
|
| extensions::ProcessMap* process_map =
|
| browser()->profile()->GetExtensionService()->process_map();
|
|
|
| @@ -200,71 +270,19 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) {
|
| // Test that hosted apps without the background permission use a process per app
|
| // instance model, such that separate instances are in separate processes.
|
| IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) {
|
| - LOG(INFO) << "Start of test.";
|
| -
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kDisablePopupBlocking);
|
| -
|
| - extensions::ProcessMap* process_map =
|
| - browser()->profile()->GetExtensionService()->process_map();
|
| -
|
| - host_resolver()->AddRule("*", "127.0.0.1");
|
| - ASSERT_TRUE(test_server()->Start());
|
| -
|
| - ASSERT_TRUE(LoadExtension(
|
| - test_data_dir_.AppendASCII("app_process_instances")));
|
| -
|
| - // Open two tabs in the app, one outside it.
|
| - GURL base_url = GetTestBaseURL("app_process_instances");
|
| -
|
| - // Test both opening a URL in a new tab, and opening a tab and then navigating
|
| - // it. Either way, app tabs should be considered extension processes, but
|
| - // they have no elevated privileges and thus should not have WebUI bindings.
|
| - ui_test_utils::NavigateToURLWithDisposition(
|
| - browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
|
| - ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
|
| - LOG(INFO) << "Nav 1.";
|
| - EXPECT_TRUE(process_map->Contains(
|
| - browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID()));
|
| - EXPECT_FALSE(browser()->GetWebContentsAt(1)->GetWebUI());
|
| -
|
| - ui_test_utils::WindowedNotificationObserver tab_added_observer(
|
| - content::NOTIFICATION_TAB_ADDED,
|
| - content::NotificationService::AllSources());
|
| - browser()->NewTab();
|
| - tab_added_observer.Wait();
|
| - LOG(INFO) << "New tab.";
|
| - ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
|
| - LOG(INFO) << "Nav 2.";
|
| - EXPECT_TRUE(process_map->Contains(
|
| - browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()));
|
| - EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI());
|
| -
|
| - // We should have opened 2 new extension tabs. Including the original blank
|
| - // tab, we now have 3 tabs. The two app tabs should not be in the same
|
| - // process, since they do not have the background permission. (Thus, we want
|
| - // to separate them to improve responsiveness.)
|
| - ASSERT_EQ(3, browser()->tab_count());
|
| - RenderViewHost* host1 = browser()->GetWebContentsAt(1)->GetRenderViewHost();
|
| - RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost();
|
| - EXPECT_NE(host1->process(), host2->process());
|
| + TestAppInstancesHelper("app_process_instances");
|
| +}
|
|
|
| - // Opening tabs with window.open should keep the page in the opener's process.
|
| - ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
|
| - WindowOpenHelper(browser(), host1,
|
| - base_url.Resolve("path1/empty.html"), true);
|
| - LOG(INFO) << "WindowOpenHelper 1.";
|
| - WindowOpenHelper(browser(), host2,
|
| - base_url.Resolve("path2/empty.html"), true);
|
| - LOG(INFO) << "End of test.";
|
| +// Test that hosted apps with the background permission but that set
|
| +// allow_js_access to false also use a process per app instance model.
|
| +// Separate instances should be in separate processes.
|
| +IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessBackgroundInstances) {
|
| + TestAppInstancesHelper("app_process_background_instances");
|
| }
|
|
|
| // Tests that bookmark apps do not use the app process model and are treated
|
| // like normal web pages instead. http://crbug.com/104636.
|
| IN_PROC_BROWSER_TEST_F(AppApiTest, BookmarkAppGetsNormalProcess) {
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kDisablePopupBlocking);
|
| -
|
| ExtensionService* service = browser()->profile()->GetExtensionService();
|
| extensions::ProcessMap* process_map = service->process_map();
|
|
|
| @@ -345,9 +363,6 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, BookmarkAppGetsNormalProcess) {
|
| #define MAYBE_AppProcessRedirectBack AppProcessRedirectBack
|
| #endif
|
| IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessRedirectBack) {
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kDisablePopupBlocking);
|
| -
|
| host_resolver()->AddRule("*", "127.0.0.1");
|
| ASSERT_TRUE(test_server()->Start());
|
|
|
| @@ -388,9 +403,6 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessRedirectBack) {
|
| // Ensure that reloading a URL after installing or uninstalling it as an app
|
| // correctly swaps the process. (http://crbug.com/80621)
|
| IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) {
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kDisablePopupBlocking);
|
| -
|
| extensions::ProcessMap* process_map =
|
| browser()->profile()->GetExtensionService()->process_map();
|
|
|
| @@ -478,9 +490,6 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) {
|
| // empty.html) results in the new window being in an app process. See
|
| // http://crbug.com/89272 for more details.
|
| IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) {
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kDisablePopupBlocking);
|
| -
|
| extensions::ProcessMap* process_map =
|
| browser()->profile()->GetExtensionService()->process_map();
|
|
|
| @@ -576,9 +585,6 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) {
|
| // missing special permissions and should be scriptable from the iframe.
|
| // See http://crbug.com/92669 for more details.
|
| IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) {
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kDisablePopupBlocking);
|
| -
|
| extensions::ProcessMap* process_map =
|
| browser()->profile()->GetExtensionService()->process_map();
|
|
|
|
|