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

Side by Side Diff: chrome/browser/ui/webui/webui_browsertest.cc

Issue 2099563002: WebUI: DisallowJavascript only on Refresh and non-same-page navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix style Created 4 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
« no previous file with comments | « no previous file | content/browser/webui/web_ui_impl.h » ('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 2015 The Chromium Authors. All rights reserved. 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 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/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/ui/browser.h" 6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/browser_commands.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 9 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
9 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
11 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/child_process_security_policy.h" 14 #include "content/public/browser/child_process_security_policy.h"
14 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/web_ui_message_handler.h"
15 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
18 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
17 20
18 using WebUIBrowserTest = InProcessBrowserTest; 21 namespace {
22
23 class TestWebUIMessageHandler : public content::WebUIMessageHandler {
24 public:
25 void RegisterMessages() override {}
26 };
27
28 } // namespace
29
30 using WebUIImplBrowserTest = InProcessBrowserTest;
19 31
20 // Tests that navigating between WebUIs of different types results in 32 // Tests that navigating between WebUIs of different types results in
21 // SiteInstance swap when running in process-per-tab process model. 33 // SiteInstance swap when running in process-per-tab process model.
22 IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, ForceSwapOnDifferenteWebUITypes) { 34 IN_PROC_BROWSER_TEST_F(WebUIImplBrowserTest, ForceSwapOnDifferenteWebUITypes) {
23 base::CommandLine::ForCurrentProcess()->AppendSwitch( 35 base::CommandLine::ForCurrentProcess()->AppendSwitch(
24 switches::kProcessPerTab); 36 switches::kProcessPerTab);
25 content::WebContents* web_contents = 37 content::WebContents* web_contents =
26 browser()->tab_strip_model()->GetActiveWebContents(); 38 browser()->tab_strip_model()->GetActiveWebContents();
27 39
28 const GURL web_ui_url(std::string(content::kChromeUIScheme) + "://" + 40 const GURL web_ui_url(std::string(content::kChromeUIScheme) + "://" +
29 std::string(chrome::kChromeUIFlagsHost)); 41 std::string(chrome::kChromeUIFlagsHost));
30 EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 42 EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
31 web_contents->GetBrowserContext(), web_ui_url)); 43 web_contents->GetBrowserContext(), web_ui_url));
32 ui_test_utils::NavigateToURL(browser(), web_ui_url); 44 ui_test_utils::NavigateToURL(browser(), web_ui_url);
(...skipping 10 matching lines...) Expand all
43 const GURL web_ui_url2(std::string(content::kChromeUIScheme) + "://" + 55 const GURL web_ui_url2(std::string(content::kChromeUIScheme) + "://" +
44 std::string(chrome::kChromeUIVersionHost)); 56 std::string(chrome::kChromeUIVersionHost));
45 EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 57 EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
46 web_contents->GetBrowserContext(), web_ui_url2)); 58 web_contents->GetBrowserContext(), web_ui_url2));
47 ui_test_utils::NavigateToURL(browser(), web_ui_url2); 59 ui_test_utils::NavigateToURL(browser(), web_ui_url2);
48 EXPECT_NE(orig_site_instance, web_contents->GetSiteInstance()); 60 EXPECT_NE(orig_site_instance, web_contents->GetSiteInstance());
49 EXPECT_TRUE( 61 EXPECT_TRUE(
50 content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( 62 content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
51 web_contents->GetRenderProcessHost()->GetID())); 63 web_contents->GetRenderProcessHost()->GetID()));
52 } 64 }
65
66 IN_PROC_BROWSER_TEST_F(WebUIImplBrowserTest, InPageNavigationsAndReload) {
67 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL));
68
69 content::WebUIMessageHandler* test_handler = new TestWebUIMessageHandler;
70 browser()
71 ->tab_strip_model()
72 ->GetActiveWebContents()
73 ->GetWebUI()
74 ->AddMessageHandler(test_handler);
75 test_handler->AllowJavascriptForTesting();
76
77 // Push onto window.history. Back should now be an in-page navigation.
78 ASSERT_TRUE(content::ExecuteScript(
79 browser()->tab_strip_model()->GetActiveWebContents(),
80 "window.history.pushState({}, '', 'foo.html')"));
81 chrome::GoBack(browser(), CURRENT_TAB);
82 content::WaitForLoadStop(
83 browser()->tab_strip_model()->GetActiveWebContents());
84
85 // Test handler should still have JavaScript allowed after in-page navigation.
86 EXPECT_TRUE(test_handler->IsJavascriptAllowed());
87
88 chrome::Reload(browser(), CURRENT_TAB);
89 content::WaitForLoadStop(
90 browser()->tab_strip_model()->GetActiveWebContents());
91
92 // Verify that after a reload, the test handler has been disallowed.
93 EXPECT_FALSE(test_handler->IsJavascriptAllowed());
94 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/webui/web_ui_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698