Commit a0ea5195 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

webui: Move some WebUIs tests to content/browser/webui

Similar WebUI tests are scattered throughout chrome/ and content/. This
Cl aims to slightly improve things by consolidating tests under
content/browser/webui. Now we have:

content/browser/webui/web_ui_browsertest.cc
content/browser/webui/web_ui_mojo_browsertest.cc
content/browser/webui/web_ui_navigation_browsertest.cc
content/browser/webui/web_ui_security_browsertest.cc

Change-Id: I6f869df20743872c8b84a3458bc096b80bc8773e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875900
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712062}
parent 8e9eeff7
......@@ -1322,7 +1322,6 @@ if (!is_android) {
"../browser/ui/webui/profile_helper_browsertest.cc",
"../browser/ui/webui/settings/settings_ui_browsertest.cc",
"../browser/ui/webui/signin/user_manager_ui_browsertest.cc",
"../browser/ui/webui/webui_browsertest.cc",
"../browser/ui/webui/webui_load_timer_browsertest.cc",
"../browser/ui/webui/webui_webview_browsertest.cc",
"../browser/ui/zoom/zoom_controller_browsertest.cc",
......
......@@ -14,31 +14,29 @@
#include "base/strings/utf_string_conversions.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.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"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/webui/content_web_ui_controller_factory.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "third_party/blink/public/platform/web_mouse_event.h"
#include "third_party/blink/public/platform/web_mouse_wheel_event.h"
#include "ui/events/base_event_utils.h"
namespace content {
namespace {
using WebUIImplBrowserTest = InProcessBrowserTest;
using WebUIImplBrowserTest = ContentBrowserTest;
class TestWebUIMessageHandler : public content::WebUIMessageHandler {
class TestWebUIMessageHandler : public WebUIMessageHandler {
public:
void RegisterMessages() override {
web_ui()->RegisterMessageCallback(
......@@ -73,7 +71,7 @@ class TestWebUIMessageHandler : public content::WebUIMessageHandler {
base::RepeatingClosure finish_closure_;
};
class WebUIRequiringGestureBrowserTest : public InProcessBrowserTest {
class WebUIRequiringGestureBrowserTest : public ContentBrowserTest {
public:
WebUIRequiringGestureBrowserTest() {
clock_.SetNowTicks(base::TimeTicks::Now());
......@@ -85,7 +83,7 @@ class WebUIRequiringGestureBrowserTest : public InProcessBrowserTest {
}
void SetUpOnMainThread() override {
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIFlagsURL));
ASSERT_TRUE(NavigateToURL(web_contents(), GetWebUIURL(kChromeUIGpuHost)));
test_handler_ = new TestWebUIMessageHandler();
web_contents()->GetWebUI()->AddMessageHandler(
base::WrapUnique(test_handler_));
......@@ -104,12 +102,8 @@ class WebUIRequiringGestureBrowserTest : public InProcessBrowserTest {
void AdvanceClock(base::TimeDelta delta) { clock_.Advance(delta); }
content::WebContents* web_contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
content::RenderFrameHost* main_rfh() {
return web_contents()->GetMainFrame();
}
WebContents* web_contents() { return shell()->web_contents(); }
RenderFrameHost* main_rfh() { return web_contents()->GetMainFrame(); }
TestWebUIMessageHandler* test_handler() { return test_handler_; }
......@@ -127,60 +121,49 @@ class WebUIRequiringGestureBrowserTest : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(WebUIImplBrowserTest, ForceSwapOnDifferenteWebUITypes) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kProcessPerTab);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
WebContents* web_contents = shell()->web_contents();
const GURL web_ui_url(std::string(content::kChromeUIScheme) + "://" +
std::string(chrome::kChromeUIFlagsHost));
EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
const GURL web_ui_url(GetWebUIURL(kChromeUIHistogramHost));
EXPECT_TRUE(ContentWebUIControllerFactory::GetInstance()->UseWebUIForURL(
web_contents->GetBrowserContext(), web_ui_url));
ui_test_utils::NavigateToURL(browser(), web_ui_url);
EXPECT_TRUE(
content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
web_contents->GetMainFrame()->GetProcess()->GetID()));
ASSERT_TRUE(NavigateToURL(web_contents, web_ui_url));
EXPECT_TRUE(ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
web_contents->GetMainFrame()->GetProcess()->GetID()));
// Capture the SiteInstance before navigating for later comparison.
scoped_refptr<content::SiteInstance> orig_site_instance(
scoped_refptr<SiteInstance> orig_site_instance(
web_contents->GetSiteInstance());
// Navigate to a different WebUI type and ensure that the SiteInstance
// has changed and the new process also has WebUI bindings.
const GURL web_ui_url2(std::string(content::kChromeUIScheme) + "://" +
std::string(chrome::kChromeUIVersionHost));
EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
const GURL web_ui_url2(GetWebUIURL(kChromeUIGpuHost));
EXPECT_TRUE(ContentWebUIControllerFactory::GetInstance()->UseWebUIForURL(
web_contents->GetBrowserContext(), web_ui_url2));
ui_test_utils::NavigateToURL(browser(), web_ui_url2);
ASSERT_TRUE(NavigateToURL(web_contents, web_ui_url2));
EXPECT_NE(orig_site_instance, web_contents->GetSiteInstance());
EXPECT_TRUE(
content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
web_contents->GetMainFrame()->GetProcess()->GetID()));
EXPECT_TRUE(ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
web_contents->GetMainFrame()->GetProcess()->GetID()));
}
IN_PROC_BROWSER_TEST_F(WebUIImplBrowserTest, SameDocumentNavigationsAndReload) {
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL));
content::WebUIMessageHandler* test_handler = new TestWebUIMessageHandler;
browser()
->tab_strip_model()
->GetActiveWebContents()
->GetWebUI()
->AddMessageHandler(base::WrapUnique(test_handler));
auto* web_contents = shell()->web_contents();
ASSERT_TRUE(NavigateToURL(web_contents, GetWebUIURL(kChromeUIHistogramHost)));
WebUIMessageHandler* test_handler = new TestWebUIMessageHandler;
web_contents->GetWebUI()->AddMessageHandler(base::WrapUnique(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(), WindowOpenDisposition::CURRENT_TAB);
content::WaitForLoadStop(
browser()->tab_strip_model()->GetActiveWebContents());
ASSERT_TRUE(ExecuteScript(web_contents,
"window.history.pushState({}, '', 'foo.html')"));
shell()->GoBackOrForward(-1);
WaitForLoadStop(web_contents);
// Test handler should still have JavaScript allowed after in-page navigation.
EXPECT_TRUE(test_handler->IsJavascriptAllowed());
chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
content::WaitForLoadStop(
browser()->tab_strip_model()->GetActiveWebContents());
shell()->Reload();
WaitForLoadStop(web_contents);
// Verify that after a reload, the test handler has been disallowed.
EXPECT_FALSE(test_handler->IsJavascriptAllowed());
......@@ -246,3 +229,5 @@ IN_PROC_BROWSER_TEST_F(WebUIRequiringGestureBrowserTest,
SendMessageAndWaitForFinish();
EXPECT_EQ(2, test_handler()->message_requiring_gesture_count());
}
} // namespace content
......@@ -889,7 +889,6 @@ test("content_browsertests") {
"../browser/frame_host/render_frame_host_manager_browsertest.cc",
"../browser/frame_host/render_frame_message_filter_browsertest.cc",
"../browser/frame_host/sec_fetch_browsertest.cc",
"../browser/frame_host/webui_navigation_browsertest.cc",
"../browser/generic_sensor/generic_sensor_browsertest.cc",
"../browser/gpu/gpu_ipc_browsertests.cc",
"../browser/gpu/in_process_gpu_thread_browsertests.cc",
......@@ -1041,7 +1040,9 @@ test("content_browsertests") {
"../browser/webrtc/webrtc_video_capture_shared_device_browsertest.cc",
"../browser/webrtc/webrtc_webcam_browsertest.cc",
"../browser/webrtc/webrtc_webcam_browsertest.h",
"../browser/webui/web_ui_browsertest.cc",
"../browser/webui/web_ui_mojo_browsertest.cc",
"../browser/webui/web_ui_navigation_browsertest.cc",
"../browser/webui/web_ui_security_browsertest.cc",
"../browser/worker_host/worker_browsertest.cc",
"../browser/worker_network_isolation_key_browsertest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment