Chromium Code Reviews| Index: chrome/browser/ui/webui/webui_browsertest.cc |
| diff --git a/chrome/browser/ui/webui/webui_browsertest.cc b/chrome/browser/ui/webui/webui_browsertest.cc |
| index 7c76fe70a1e4c44e1fa47fe7791e1675bd4b62e2..751d209b1a54b3e089ff9202496e397f03d355a7 100644 |
| --- a/chrome/browser/ui/webui/webui_browsertest.cc |
| +++ b/chrome/browser/ui/webui/webui_browsertest.cc |
| @@ -4,6 +4,7 @@ |
| #include "base/command_line.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| #include "chrome/common/chrome_switches.h" |
| @@ -12,14 +13,25 @@ |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "content/public/browser/child_process_security_policy.h" |
| #include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/web_ui_message_handler.h" |
| #include "content/public/common/content_switches.h" |
| +#include "content/public/test/browser_test_utils.h" |
| #include "content/public/test/test_utils.h" |
| -using WebUIBrowserTest = InProcessBrowserTest; |
| +namespace { |
| + |
| +class TestWebUIMessageHandler : public content::WebUIMessageHandler { |
| + public: |
| + void RegisterMessages() override{}; |
|
Charlie Reis
2016/06/27 22:18:19
Style nit: Space after override (unless git cl for
tommycli
2016/06/27 22:24:07
Done. Ah git cl format got confused by the extra s
|
| +}; |
| + |
| +} // namespace |
| + |
| +using WebUIImplBrowserTest = InProcessBrowserTest; |
| // Tests that navigating between WebUIs of different types results in |
| // SiteInstance swap when running in process-per-tab process model. |
| -IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, ForceSwapOnDifferenteWebUITypes) { |
| +IN_PROC_BROWSER_TEST_F(WebUIImplBrowserTest, ForceSwapOnDifferenteWebUITypes) { |
| base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| switches::kProcessPerTab); |
| content::WebContents* web_contents = |
| @@ -50,3 +62,33 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, ForceSwapOnDifferenteWebUITypes) { |
| content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| web_contents->GetRenderProcessHost()->GetID())); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F(WebUIImplBrowserTest, InPageNavigationsAndReload) { |
| + ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL)); |
| + |
| + content::WebUIMessageHandler* test_handler = new TestWebUIMessageHandler; |
| + browser() |
| + ->tab_strip_model() |
| + ->GetActiveWebContents() |
| + ->GetWebUI() |
| + ->AddMessageHandler(test_handler); |
| + test_handler->AllowJavascriptForTesting(); |
| + |
| + // Push onto window.history. Back should now be an in-page navigation. |
| + ASSERT_TRUE(content::ExecuteScript( |
| + browser()->tab_strip_model()->GetActiveWebContents(), |
| + "window.history.pushState({}, '', 'foo.html')")); |
| + chrome::GoBack(browser(), CURRENT_TAB); |
| + content::WaitForLoadStop( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| + |
| + // Test handler should still have JavaScript allowed after in-page navigation. |
| + EXPECT_TRUE(test_handler->IsJavascriptAllowed()); |
| + |
| + chrome::Reload(browser(), CURRENT_TAB); |
| + content::WaitForLoadStop( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| + |
| + // Verify that after a reload, the test handler has been disallowed. |
| + EXPECT_FALSE(test_handler->IsJavascriptAllowed()); |
| +} |