OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 8 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/url_constants.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/public/browser/child_process_security_policy.h" |
| 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/common/content_switches.h" |
| 16 #include "content/public/test/test_utils.h" |
| 17 |
| 18 using WebUIBrowserTest = InProcessBrowserTest; |
| 19 |
| 20 // Tests that navigating between WebUIs of different types results in |
| 21 // SiteInstance swap when running in process-per-tab process model. |
| 22 IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, ForceSwapOnDifferenteWebUITypes) { |
| 23 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 24 switches::kProcessPerTab); |
| 25 content::WebContents* web_contents = |
| 26 browser()->tab_strip_model()->GetActiveWebContents(); |
| 27 |
| 28 const GURL web_ui_url(std::string(content::kChromeUIScheme) + "://" + |
| 29 std::string(chrome::kChromeUIFlagsHost)); |
| 30 EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 31 web_contents->GetBrowserContext(), web_ui_url)); |
| 32 ui_test_utils::NavigateToURL(browser(), web_ui_url); |
| 33 EXPECT_TRUE( |
| 34 content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| 35 web_contents->GetRenderProcessHost()->GetID())); |
| 36 |
| 37 // Capture the SiteInstance before navigating for later comparison. |
| 38 scoped_refptr<content::SiteInstance> orig_site_instance( |
| 39 web_contents->GetSiteInstance()); |
| 40 |
| 41 // Navigate to a different WebUI type and ensure that the SiteInstance |
| 42 // has changed and the new process also has WebUI bindings. |
| 43 const GURL web_ui_url2(std::string(content::kChromeUIScheme) + "://" + |
| 44 std::string(chrome::kChromeUIVersionHost)); |
| 45 EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 46 web_contents->GetBrowserContext(), web_ui_url2)); |
| 47 ui_test_utils::NavigateToURL(browser(), web_ui_url2); |
| 48 EXPECT_NE(orig_site_instance, web_contents->GetSiteInstance()); |
| 49 EXPECT_TRUE( |
| 50 content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| 51 web_contents->GetRenderProcessHost()->GetID())); |
| 52 } |
OLD | NEW |