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

Side by Side Diff: chrome/browser/extensions/app_process_apitest.cc

Issue 7608015: When determining whether or not to swap processes on navigation, check the top frame's URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/browser/renderer_host/render_view_host.h" 14 #include "content/browser/renderer_host/render_view_host.h"
15 #include "content/browser/tab_contents/tab_contents.h" 15 #include "content/browser/tab_contents/tab_contents.h"
16 #include "net/base/mock_host_resolver.h" 16 #include "net/base/mock_host_resolver.h"
17 17
18 class AppApiTest : public ExtensionApiTest { 18 class AppApiTest : public ExtensionApiTest {
19 protected:
20 // Gets the base URL for files for a specific test, making sure that it uses
21 // "localhost" as the hostname, since that is what the extent is declared
22 // as in the test apps manifests.
23 GURL GetTestBaseURL(std::string test_directory) {
24 GURL::Replacements replace_host;
25 std::string host_str("localhost"); // must stay in scope with replace_host
26 replace_host.SetHostStr(host_str);
27 GURL base_url = test_server()->GetURL(
28 "files/extensions/api_test/" + test_directory + "/");
29 return base_url.ReplaceComponents(replace_host);
30 }
19 }; 31 };
20 32
21 // Simulates a page calling window.open on an URL, and waits for the navigation. 33 // Simulates a page calling window.open on an URL, and waits for the navigation.
22 static void WindowOpenHelper(Browser* browser, 34 static void WindowOpenHelper(Browser* browser,
23 RenderViewHost* opener_host, 35 RenderViewHost* opener_host,
24 const GURL& url, 36 const GURL& url,
25 bool newtab_process_should_equal_opener) { 37 bool newtab_process_should_equal_opener) {
26 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 38 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
27 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');")); 39 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
28 40
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) { 84 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) {
73 CommandLine::ForCurrentProcess()->AppendSwitch( 85 CommandLine::ForCurrentProcess()->AppendSwitch(
74 switches::kDisablePopupBlocking); 86 switches::kDisablePopupBlocking);
75 87
76 host_resolver()->AddRule("*", "127.0.0.1"); 88 host_resolver()->AddRule("*", "127.0.0.1");
77 ASSERT_TRUE(test_server()->Start()); 89 ASSERT_TRUE(test_server()->Start());
78 90
79 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); 91 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
80 92
81 // Open two tabs in the app, one outside it. 93 // Open two tabs in the app, one outside it.
82 GURL base_url = test_server()->GetURL( 94 GURL base_url = GetTestBaseURL("app_process");
83 "files/extensions/api_test/app_process/");
84
85 // The app under test acts on URLs whose host is "localhost",
86 // so the URLs we navigate to must have host "localhost".
87 GURL::Replacements replace_host;
88 std::string host_str("localhost"); // must stay in scope with replace_host
89 replace_host.SetHostStr(host_str);
90 base_url = base_url.ReplaceComponents(replace_host);
91 95
92 // Test both opening a URL in a new tab, and opening a tab and then navigating 96 // Test both opening a URL in a new tab, and opening a tab and then navigating
93 // it. Either way, app tabs should be considered extension processes, but 97 // it. Either way, app tabs should be considered extension processes, but
94 // they have no elevated privileges and thus should not have WebUI bindings. 98 // they have no elevated privileges and thus should not have WebUI bindings.
95 ui_test_utils::NavigateToURLWithDisposition( 99 ui_test_utils::NavigateToURLWithDisposition(
96 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, 100 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
97 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 101 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
98 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()-> 102 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()->
99 is_extension_process()); 103 is_extension_process());
100 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); 104 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 CommandLine::ForCurrentProcess()->AppendSwitch( 173 CommandLine::ForCurrentProcess()->AppendSwitch(
170 switches::kDisablePopupBlocking); 174 switches::kDisablePopupBlocking);
171 175
172 host_resolver()->AddRule("*", "127.0.0.1"); 176 host_resolver()->AddRule("*", "127.0.0.1");
173 ASSERT_TRUE(test_server()->Start()); 177 ASSERT_TRUE(test_server()->Start());
174 178
175 ASSERT_TRUE(LoadExtension( 179 ASSERT_TRUE(LoadExtension(
176 test_data_dir_.AppendASCII("app_process_instances"))); 180 test_data_dir_.AppendASCII("app_process_instances")));
177 181
178 // Open two tabs in the app, one outside it. 182 // Open two tabs in the app, one outside it.
179 GURL base_url = test_server()->GetURL( 183 GURL base_url = GetTestBaseURL("app_process_instances");
180 "files/extensions/api_test/app_process_instances/");
181
182 // The app under test acts on URLs whose host is "localhost",
183 // so the URLs we navigate to must have host "localhost".
184 GURL::Replacements replace_host;
185 std::string host_str("localhost"); // must stay in scope with replace_host
186 replace_host.SetHostStr(host_str);
187 base_url = base_url.ReplaceComponents(replace_host);
188 184
189 // Test both opening a URL in a new tab, and opening a tab and then navigating 185 // Test both opening a URL in a new tab, and opening a tab and then navigating
190 // it. Either way, app tabs should be considered extension processes, but 186 // it. Either way, app tabs should be considered extension processes, but
191 // they have no elevated privileges and thus should not have WebUI bindings. 187 // they have no elevated privileges and thus should not have WebUI bindings.
192 ui_test_utils::NavigateToURLWithDisposition( 188 ui_test_utils::NavigateToURLWithDisposition(
193 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, 189 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
194 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 190 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
195 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()-> 191 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()->
196 is_extension_process()); 192 is_extension_process());
197 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); 193 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
(...skipping 29 matching lines...) Expand all
227 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) { 223 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) {
228 CommandLine::ForCurrentProcess()->AppendSwitch( 224 CommandLine::ForCurrentProcess()->AppendSwitch(
229 switches::kDisablePopupBlocking); 225 switches::kDisablePopupBlocking);
230 226
231 host_resolver()->AddRule("*", "127.0.0.1"); 227 host_resolver()->AddRule("*", "127.0.0.1");
232 ASSERT_TRUE(test_server()->Start()); 228 ASSERT_TRUE(test_server()->Start());
233 229
234 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); 230 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
235 231
236 // Open two tabs in the app. 232 // Open two tabs in the app.
237 GURL base_url = test_server()->GetURL( 233 GURL base_url = GetTestBaseURL("app_process");
238 "files/extensions/api_test/app_process/");
239
240 // The app under test acts on URLs whose host is "localhost",
241 // so the URLs we navigate to must have host "localhost".
242 GURL::Replacements replace_host;
243 std::string host_str("localhost"); // must stay in scope with replace_host
244 replace_host.SetHostStr(host_str);
245 base_url = base_url.ReplaceComponents(replace_host);
246 234
247 browser()->NewTab(); 235 browser()->NewTab();
248 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); 236 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
249 browser()->NewTab(); 237 browser()->NewTab();
250 // Wait until the second tab finishes its redirect train (2 hops). 238 // Wait until the second tab finishes its redirect train (2 hops).
251 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 239 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
252 browser(), base_url.Resolve("path1/redirect.html"), 2); 240 browser(), base_url.Resolve("path1/redirect.html"), 2);
253 241
254 // 3 tabs, including the initial about:blank. The last 2 should be the same 242 // 3 tabs, including the initial about:blank. The last 2 should be the same
255 // process. 243 // process.
(...skipping 10 matching lines...) Expand all
266 // correctly swaps the process. (http://crbug.com/80621) 254 // correctly swaps the process. (http://crbug.com/80621)
267 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) { 255 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) {
268 CommandLine::ForCurrentProcess()->AppendSwitch( 256 CommandLine::ForCurrentProcess()->AppendSwitch(
269 switches::kDisablePopupBlocking); 257 switches::kDisablePopupBlocking);
270 258
271 host_resolver()->AddRule("*", "127.0.0.1"); 259 host_resolver()->AddRule("*", "127.0.0.1");
272 ASSERT_TRUE(test_server()->Start()); 260 ASSERT_TRUE(test_server()->Start());
273 261
274 // The app under test acts on URLs whose host is "localhost", 262 // The app under test acts on URLs whose host is "localhost",
275 // so the URLs we navigate to must have host "localhost". 263 // so the URLs we navigate to must have host "localhost".
276 GURL::Replacements replace_host; 264 GURL base_url = GetTestBaseURL("app_process");
277 std::string host_str("localhost"); // must stay in scope with replace_host
278 replace_host.SetHostStr(host_str);
279 GURL base_url = test_server()->GetURL(
280 "files/extensions/api_test/app_process/");
281 base_url = base_url.ReplaceComponents(replace_host);
282 265
283 // Load an app URL before loading the app. 266 // Load an app URL before loading the app.
284 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); 267 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
285 TabContents* contents = browser()->GetTabContentsAt(0); 268 TabContents* contents = browser()->GetTabContentsAt(0);
286 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process()); 269 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process());
287 270
288 // Load app and reload page. 271 // Load app and reload page.
289 const Extension* app = 272 const Extension* app =
290 LoadExtension(test_data_dir_.AppendASCII("app_process")); 273 LoadExtension(test_data_dir_.AppendASCII("app_process"));
291 ASSERT_TRUE(app); 274 ASSERT_TRUE(app);
(...skipping 12 matching lines...) Expand all
304 ui_test_utils::WaitForNavigation(&contents->controller()); 287 ui_test_utils::WaitForNavigation(&contents->controller());
305 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process()); 288 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process());
306 289
307 // Disable app and reload via JavaScript. 290 // Disable app and reload via JavaScript.
308 DisableExtension(app->id()); 291 DisableExtension(app->id());
309 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), 292 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(),
310 L"", L"location.reload();")); 293 L"", L"location.reload();"));
311 ui_test_utils::WaitForNavigation(&contents->controller()); 294 ui_test_utils::WaitForNavigation(&contents->controller());
312 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process()); 295 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process());
313 } 296 }
297
298
299 // Tests that if we have a non-app process (path3/container.html) that has an
300 // iframe with a URL in the app's extent (path1/iframe.html), then opening a
301 // link from that iframe to a new window to a URL in the app's extent (path1/
302 // empty.html) results in the new window being in an app process. See
303 // http://crbug.com/89272 for more details.
304 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) {
305 CommandLine::ForCurrentProcess()->AppendSwitch(
306 switches::kDisablePopupBlocking);
307
308 host_resolver()->AddRule("*", "127.0.0.1");
309 ASSERT_TRUE(test_server()->Start());
310
311 GURL base_url = GetTestBaseURL("app_process");
312
313 // Load app and start URL (not in the app).
314 const Extension* app =
315 LoadExtension(test_data_dir_.AppendASCII("app_process"));
316 ASSERT_TRUE(app);
317 ui_test_utils::NavigateToURLWithDisposition(
318 browser(),
319 base_url.Resolve("path3/container.html"),
320 CURRENT_TAB,
321 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION |
322 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
323 EXPECT_FALSE(browser()->GetTabContentsAt(0)->render_view_host()->process()->
324 is_extension_process());
325
326 // Wait for popup window to appear.
327 GURL app_url = base_url.Resolve("path1/empty.html");
328 Browser* last_active_browser = BrowserList::GetLastActive();
329 EXPECT_TRUE(last_active_browser);
330 ASSERT_NE(browser(), last_active_browser);
331 TabContents* newtab = last_active_browser->GetSelectedTabContents();
332 EXPECT_TRUE(newtab);
333 if (!newtab->controller().GetLastCommittedEntry() ||
334 newtab->controller().GetLastCommittedEntry()->url() != app_url)
335 ui_test_utils::WaitForNavigation(&newtab->controller());
336
337 // Popup window should be in the app's process.
338 EXPECT_TRUE(last_active_browser->GetTabContentsAt(0)->render_view_host()->
339 process()->is_extension_process());
340 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698