0

Add and implement a flag to use tab target in content_shell and web test runner.

Bug: 1370050
Change-Id: I69a6b8c62b0c0911dc185f27491139316f408c4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3982255
Commit-Queue: Mike West <mkwst@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Auto-Submit: Danil Somsikov <dsv@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1064201}
This commit is contained in:
Danil Somsikov
2022-10-27 07:09:19 +00:00
committed by Chromium LUCI CQ
parent 06e1f7099a
commit 9f37e85be7
5 changed files with 24 additions and 2 deletions

@@ -11,6 +11,7 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/containers/contains.h" #include "base/containers/contains.h"
#include "base/containers/cxx20_erase.h" #include "base/containers/cxx20_erase.h"
#include "base/guid.h" #include "base/guid.h"
@@ -38,6 +39,7 @@
#include "content/shell/browser/shell_browser_main_parts.h" #include "content/shell/browser/shell_browser_main_parts.h"
#include "content/shell/browser/shell_content_browser_client.h" #include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_devtools_manager_delegate.h" #include "content/shell/browser/shell_devtools_manager_delegate.h"
#include "content/shell/common/shell_switches.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/resource_request.h"
@@ -225,7 +227,10 @@ void ShellDevToolsBindings::ReadyToCommitNavigation(
void ShellDevToolsBindings::AttachInternal() { void ShellDevToolsBindings::AttachInternal() {
if (agent_host_) if (agent_host_)
agent_host_->DetachClient(this); agent_host_->DetachClient(this);
agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents_); agent_host_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kContentShellDevToolsTabTarget)
? DevToolsAgentHost::GetOrCreateForTab(inspected_contents_)
: DevToolsAgentHost::GetOrCreateFor(inspected_contents_);
agent_host_->AttachClient(this); agent_host_->AttachClient(this);
if (inspect_element_at_x_ != -1) { if (inspect_element_at_x_ != -1) {
agent_host_->InspectElement(inspected_contents_->GetFocusedFrame(), agent_host_->InspectElement(inspected_contents_->GetFocusedFrame(),

@@ -4,6 +4,7 @@
#include "content/shell/browser/shell_devtools_frontend.h" #include "content/shell/browser/shell_devtools_frontend.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@@ -13,14 +14,19 @@
#include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_devtools_bindings.h" #include "content/shell/browser/shell_devtools_bindings.h"
#include "content/shell/browser/shell_devtools_manager_delegate.h" #include "content/shell/browser/shell_devtools_manager_delegate.h"
#include "content/shell/common/shell_switches.h"
namespace content { namespace content {
namespace { namespace {
static GURL GetFrontendURL() { static GURL GetFrontendURL() {
int port = ShellDevToolsManagerDelegate::GetHttpHandlerPort(); int port = ShellDevToolsManagerDelegate::GetHttpHandlerPort();
const char* queryString = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kContentShellDevToolsTabTarget)
? "?targetType=tab"
: "";
return GURL(base::StringPrintf( return GURL(base::StringPrintf(
"http://127.0.0.1:%d/devtools/devtools_app.html", port)); "http://127.0.0.1:%d/devtools/devtools_app.html%s", port, queryString));
} }
} // namespace } // namespace

@@ -30,6 +30,11 @@ const char kContentShellHostWindowSize[] = "content-shell-host-window-size";
// Hides toolbar from content_shell's host window. // Hides toolbar from content_shell's host window.
const char kContentShellHideToolbar[] = "content-shell-hide-toolbar"; const char kContentShellHideToolbar[] = "content-shell-hide-toolbar";
// Let DevTools front-end talk to the target of type "tab" rather than
// "frame" when inspecting a WebContents.
const char kContentShellDevToolsTabTarget[] =
"content-shell-devtools-tab-target";
// Runs Content Shell in web test mode, injecting test-only behaviour for // Runs Content Shell in web test mode, injecting test-only behaviour for
// blink web tests. // blink web tests.
const char kRunWebTests[] = "run-web-tests"; const char kRunWebTests[] = "run-web-tests";

@@ -15,6 +15,7 @@ extern const char kDisableSystemFontCheck[];
extern const char kExposeInternalsForTesting[]; extern const char kExposeInternalsForTesting[];
extern const char kContentShellHostWindowSize[]; extern const char kContentShellHostWindowSize[];
extern const char kContentShellHideToolbar[]; extern const char kContentShellHideToolbar[];
extern const char kContentShellDevToolsTabTarget[];
extern const char kRunWebTests[]; extern const char kRunWebTests[];
// Helper that returns true if kRunWebTests is present in the command line, // Helper that returns true if kRunWebTests is present in the command line,

@@ -16,6 +16,7 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "content/shell/common/shell_switches.h"
#include "content/web_test/browser/web_test_control_host.h" #include "content/web_test/browser/web_test_control_host.h"
#include "content/web_test/common/web_test_switches.h" #include "content/web_test/common/web_test_switches.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
@@ -88,6 +89,10 @@ GURL WebTestDevToolsBindings::MapTestURLIfNeeded(const GURL& test_url,
if (is_debug_dev_tools) if (is_debug_dev_tools)
url_string += "&debugFrontend=true"; url_string += "&debugFrontend=true";
url_string += "&test=" + test_url_string; url_string += "&test=" + test_url_string;
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kContentShellDevToolsTabTarget)) {
url_string += "&targetType=tab";
}
return GURL(url_string); return GURL(url_string);
} }