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

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

Issue 2739193004: Check for already existing entry when adding to SiteProcessMap. (Closed)
Patch Set: Fix. Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/sessions/session_tab_helper.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/extension_process_policy.h" 18 #include "chrome/common/extensions/extension_process_policy.h"
17 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/site_instance.h" 25 #include "content/public/browser/site_instance.h"
23 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
25 #include "content/public/test/test_navigation_observer.h" 28 #include "content/public/test/test_navigation_observer.h"
26 #include "extensions/browser/extension_host.h" 29 #include "extensions/browser/extension_host.h"
27 #include "extensions/browser/process_manager.h" 30 #include "extensions/browser/process_manager.h"
28 #include "extensions/browser/process_map.h" 31 #include "extensions/browser/process_map.h"
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // Verify that we really have the Chrome Web Store app loaded in the Web 386 // Verify that we really have the Chrome Web Store app loaded in the Web
384 // Contents. 387 // Contents.
385 content::RenderProcessHost* new_process_host = 388 content::RenderProcessHost* new_process_host =
386 web_contents->GetMainFrame()->GetProcess(); 389 web_contents->GetMainFrame()->GetProcess();
387 EXPECT_TRUE(extensions::ProcessMap::Get(profile())->Contains( 390 EXPECT_TRUE(extensions::ProcessMap::Get(profile())->Contains(
388 extensions::kWebStoreAppId, new_process_host->GetID())); 391 extensions::kWebStoreAppId, new_process_host->GetID()));
389 392
390 // Verify that Chrome Web Store is isolated in a separate renderer process. 393 // Verify that Chrome Web Store is isolated in a separate renderer process.
391 EXPECT_NE(old_process_host, new_process_host); 394 EXPECT_NE(old_process_host, new_process_host);
392 } 395 }
396
397 // This test verifies that blocked navigations to extensions pages do not
398 // overwrite process-per-site map inside content/.
399 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
400 NavigateToBlockedExtensionPageInNewTab) {
401 host_resolver()->AddRule("*", "127.0.0.1");
402 ASSERT_TRUE(embedded_test_server()->Start());
403
404 // Load an extension, which will block a request for a specifig page in it.
Devlin 2017/03/11 01:52:17 *specific
nasko 2017/03/13 17:22:03 Done.
405 const extensions::Extension* extension =
406 LoadExtension(test_data_dir_.AppendASCII("web_request_blocking"));
407 ASSERT_TRUE(extension);
408
409 WebContents* web_contents =
410 browser()->tab_strip_model()->GetActiveWebContents();
411 WebContents* new_web_contents = nullptr;
412 GURL blocked_url(extension->GetResourceURL("/blocked.html"));
413
414 // Navigating to the blocked extension URL should be done through a redirect,
415 // otherwise it will result in an OpenURL IPC from the renderer process, which
416 // will initiate a navigation through the browser process.
417 GURL redirect_url(
418 embedded_test_server()->GetURL("/server-redirect?" + blocked_url.spec()));
419
420 // Navigate the current tab to the test page in the extension, which will
421 // create the extension process and register the webRequest blocking listener.
422 {
423 content::TestNavigationObserver observer(web_contents);
Devlin 2017/03/11 01:52:17 Doesn't NavigateToURL by default block until navig
nasko 2017/03/13 17:22:03 Good point :). I had so many iterations of this co
424 ui_test_utils::NavigateToURL(browser(),
425 extension->GetResourceURL("/test.html"));
426 observer.Wait();
427 }
428
429 // Open a new tab to about:blank, which will result in a new SiteInstance
430 // without an explicit site set.
431 {
432 content::WindowedNotificationObserver tab_added_observer(
433 chrome::NOTIFICATION_TAB_ADDED,
434 content::NotificationService::AllSources());
435 EXPECT_TRUE(content::ExecuteScript(
436 web_contents, "chrome.tabs.create({url: 'about:blank'});"));
Devlin 2017/03/11 01:52:18 Does this have to be done through the extension AP
nasko 2017/03/13 17:22:03 I was trying to mimic as closely what I observed.
437 tab_added_observer.Wait();
438 new_web_contents = browser()->tab_strip_model()->GetActiveWebContents();
439
440 // If the navigation hasn't committed yet, the test needs to wait for it.
441 if (new_web_contents->GetLastCommittedURL() != GURL(url::kAboutBlankURL)) {
Devlin 2017/03/11 01:52:17 The above might also solve this, since NavigateToU
nasko 2017/03/13 17:22:03 Done.
442 content::TestNavigationObserver observer(new_web_contents);
443 observer.Wait();
444 }
445 }
446
447 // Navigate the new tab to an extension URL that will be blocked by
448 // webRequest.
449 {
450 std::string script = base::StringPrintf("location.href = '%s';",
451 redirect_url.spec().c_str());
452 content::TestNavigationObserver observer(new_web_contents);
453 EXPECT_TRUE(content::ExecuteScript(new_web_contents, script));
Devlin 2017/03/11 01:52:17 Same question - does this need to be through Execu
nasko 2017/03/13 17:22:03 This needs to be a renderer initiated navigation a
454 observer.Wait();
455
456 EXPECT_EQ(observer.last_navigation_url(), blocked_url);
457 EXPECT_FALSE(observer.last_navigation_succeeded());
458 }
459
460 // Very subtle check for content/ internal functionality :(.
461 // When a navigation is blocked, it still commits an error page. Since
462 // extensions use the process-per-site model, each extension URL is registered
Devlin 2017/03/11 01:52:17 nit: process-per-extension? process-per-origin?
nasko 2017/03/13 17:22:03 Our codebase and docs already talk about process-p
463 // in a map from URL to a process. Creating a brand new SiteInstance for the
464 // extension URL should always result in a SiteInstance that has a process and
465 // the process is the same for all SiteInstances.
466 scoped_refptr<content::SiteInstance> new_site_instance =
467 content::SiteInstance::CreateForURL(web_contents->GetBrowserContext(),
468 extension->GetResourceURL(""));
Devlin 2017/03/11 01:52:17 nit: extension->url()
nasko 2017/03/13 17:22:03 Done.
469 EXPECT_TRUE(new_site_instance->HasProcess());
470 EXPECT_EQ(new_site_instance->GetProcess(),
471 web_contents->GetSiteInstance()->GetProcess());
472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698