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

Side by Side 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: Fix incognito function. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_host.h" 7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/extensions/extension_process_manager.h" 8 #include "chrome/browser/extensions/extension_process_manager.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); 102 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
103 EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()-> 103 EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()->
104 is_extension_process()); 104 is_extension_process());
105 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); 105 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui());
106 browser()->NewTab(); 106 browser()->NewTab();
107 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); 107 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html"));
108 EXPECT_FALSE(browser()->GetTabContentsAt(3)->render_view_host()->process()-> 108 EXPECT_FALSE(browser()->GetTabContentsAt(3)->render_view_host()->process()->
109 is_extension_process()); 109 is_extension_process());
110 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui()); 110 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui());
111 111
112 // The extension should have opened 3 new tabs. Including the original blank 112 // We should have opened 3 new extension tabs. Including the original blank
113 // tab, we now have 4 tabs. Two should be part of the extension app, and 113 // tab, we now have 4 tabs. Because the app_process app has the background
114 // grouped in the same process. 114 // permission, all of its instances are in the same process. Thus two tabs
115 // should be part of the extension app and grouped in the same process.
115 ASSERT_EQ(4, browser()->tab_count()); 116 ASSERT_EQ(4, browser()->tab_count());
116 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host(); 117 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host();
117 118
118 EXPECT_EQ(host->process(), 119 EXPECT_EQ(host->process(),
119 browser()->GetTabContentsAt(2)->render_view_host()->process()); 120 browser()->GetTabContentsAt(2)->render_view_host()->process());
120 EXPECT_NE(host->process(), 121 EXPECT_NE(host->process(),
121 browser()->GetTabContentsAt(3)->render_view_host()->process()); 122 browser()->GetTabContentsAt(3)->render_view_host()->process());
122 123
123 // Now let's do the same using window.open. The same should happen. 124 // Now let's do the same using window.open. The same should happen.
124 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); 125 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
(...skipping 22 matching lines...) Expand all
147 EXPECT_EQ(host->process(), 148 EXPECT_EQ(host->process(),
148 browser()->GetTabContentsAt(6)->render_view_host()->process()); 149 browser()->GetTabContentsAt(6)->render_view_host()->process());
149 bool windowOpenerValid = false; 150 bool windowOpenerValid = false;
150 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 151 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
151 browser()->GetTabContentsAt(6)->render_view_host(), L"", 152 browser()->GetTabContentsAt(6)->render_view_host(), L"",
152 L"window.domAutomationController.send(window.opener != null)", 153 L"window.domAutomationController.send(window.opener != null)",
153 &windowOpenerValid)); 154 &windowOpenerValid));
154 ASSERT_TRUE(windowOpenerValid); 155 ASSERT_TRUE(windowOpenerValid);
155 } 156 }
156 157
158 // Test that hosted apps without the background permission use a process per app
159 // instance model, such that separate instances are in separate processes.
160 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) {
161 CommandLine::ForCurrentProcess()->AppendSwitch(
162 switches::kDisablePopupBlocking);
163
164 host_resolver()->AddRule("*", "127.0.0.1");
165 ASSERT_TRUE(test_server()->Start());
166
167 ASSERT_TRUE(LoadExtension(
168 test_data_dir_.AppendASCII("app_process_instances")));
169
170 // Open two tabs in the app, one outside it.
171 GURL base_url = test_server()->GetURL(
172 "files/extensions/api_test/app_process_instances/");
173
174 // The app under test acts on URLs whose host is "localhost",
175 // so the URLs we navigate to must have host "localhost".
176 GURL::Replacements replace_host;
177 std::string host_str("localhost"); // must stay in scope with replace_host
178 replace_host.SetHostStr(host_str);
179 base_url = base_url.ReplaceComponents(replace_host);
180
181 // Test both opening a URL in a new tab, and opening a tab and then navigating
182 // it. Either way, app tabs should be considered extension processes, but
183 // they have no elevated privileges and thus should not have WebUI bindings.
184 ui_test_utils::NavigateToURLWithDisposition(
185 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
186 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
187 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()->
188 is_extension_process());
189 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
190 browser()->NewTab();
191 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
192 EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()->
193 is_extension_process());
194 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui());
195
196 // We should have opened 2 new extension tabs. Including the original blank
197 // tab, we now have 3 tabs. The two app tabs should not be in the same
198 // process, since they do not have the background permission. (Thus, we want
199 // to separate them to improve responsiveness.)
200 ASSERT_EQ(3, browser()->tab_count());
201 RenderViewHost* host1 = browser()->GetTabContentsAt(1)->render_view_host();
202 RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host();
203 EXPECT_NE(host1->process(), host2->process());
204
205 // Opening tabs with window.open should keep the page in the opener's process.
206 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
207 WindowOpenHelper(browser(), host1,
208 base_url.Resolve("path1/empty.html"), true);
209 WindowOpenHelper(browser(), host2,
210 base_url.Resolve("path2/empty.html"), true);
211 }
212
157 // Tests that app process switching works properly in the following scenario: 213 // Tests that app process switching works properly in the following scenario:
158 // 1. navigate to a page1 in the app 214 // 1. navigate to a page1 in the app
159 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") 215 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")
160 // 3. page2 redirects back to a page in the app 216 // 3. page2 redirects back to a page in the app
161 // The final navigation should end up in the app process. 217 // The final navigation should end up in the app process.
162 // See http://crbug.com/61757 218 // See http://crbug.com/61757
163 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) { 219 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) {
164 CommandLine::ForCurrentProcess()->AppendSwitch( 220 CommandLine::ForCurrentProcess()->AppendSwitch(
165 switches::kDisablePopupBlocking); 221 switches::kDisablePopupBlocking);
166 222
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ui_test_utils::WaitForNavigation(&contents->controller()); 296 ui_test_utils::WaitForNavigation(&contents->controller());
241 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process()); 297 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process());
242 298
243 // Disable app and reload via JavaScript. 299 // Disable app and reload via JavaScript.
244 DisableExtension(app->id()); 300 DisableExtension(app->id());
245 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), 301 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(),
246 L"", L"location.reload();")); 302 L"", L"location.reload();"));
247 ui_test_utils::WaitForNavigation(&contents->controller()); 303 ui_test_utils::WaitForNavigation(&contents->controller());
248 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process()); 304 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process());
249 } 305 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/extensions/extension_process_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698