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

Unified Diff: chrome/browser/extensions/app_process_apitest.cc

Issue 7328029: Use process-per-app-instance for hosted apps without background permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update tests. Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
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 898a16c48011661a8a8824d5b7edac8fffaf2457..be41e6981df514b7af193b0085b363dd047b6f09 100644
--- a/chrome/browser/extensions/app_process_apitest.cc
+++ b/chrome/browser/extensions/app_process_apitest.cc
@@ -110,8 +110,9 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) {
EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui());
// The extension should have opened 3 new tabs. Including the original blank
- // tab, we now have 4 tabs. Two should be part of the extension app, and
- // grouped in the same process.
+ // tab, we now have 4 tabs. Because the app_process app has the background
+ // permission, all of its instances are in the same process. Thus two tabs
+ // should be part of the extension app and grouped in the same process.
ASSERT_EQ(4, browser()->tab_count());
RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host();
@@ -154,6 +155,61 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) {
ASSERT_TRUE(windowOpenerValid);
}
+// 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) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kDisablePopupBlocking);
+
+ 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 = test_server()->GetURL(
+ "files/extensions/api_test/app_process_instances/");
+
+ // The app under test acts on URLs whose host is "localhost",
+ // so the URLs we navigate to must have host "localhost".
+ GURL::Replacements replace_host;
+ std::string host_str("localhost"); // must stay in scope with replace_host
+ replace_host.SetHostStr(host_str);
+ base_url = base_url.ReplaceComponents(replace_host);
+
+ // 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);
+ EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()->
+ is_extension_process());
+ EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
+ browser()->NewTab();
+ ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
+ EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()->
+ is_extension_process());
+ EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui());
+
+ // The extension should have opened 2 new tabs. Including the original blank
Matt Perry 2011/07/08 22:18:35 the extension didn't open the tabs, we did, right?
Charlie Reis 2011/07/08 22:49:50 Yep. Fixed in the test above as well.
+ // 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()->GetTabContentsAt(1)->render_view_host();
+ RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host();
+ 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);
+ WindowOpenHelper(browser(), host2,
+ base_url.Resolve("path2/empty.html"), true);
+}
+
// Tests that app process switching works properly in the following scenario:
// 1. navigate to a page1 in the app
// 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")

Powered by Google App Engine
This is Rietveld 408576698