Commit 1af2dc94 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Reland "Convert browser side's legacy IPCs of BlinkTest message to Mojo"

This is a reland of 4184bbb0

Original change's description:
> Convert browser side's legacy IPCs of BlinkTest message to Mojo
>
> As a step to convert legacy IPCs to the Mojo, this CL
> converts browser side's BlinkTest IPCs to Mojo. This
> CL introduces WebTestClient interface to replace the
> IPC messages to Mojo methods in web_test.mojom file.
> The interface starts to support the original messages
> as below,
>
>  - InitiateLayoutDump()
>  - PrintMessageToStderr()
>  - SetPopupBlockingEnabled()
>  - NavigateSecondaryWindow()
>  - GoToOffset
>  - Reload()
>  - LoadURLForFrame()
>  - CloseRemainingWindows()
>  - ResetDone()
>  - SendBluetoothManualChooserEvent()
>  - GetBluetoothManualChooserEvents()
>  - SetBluetoothManualChooser()
>
> This CL should not change any behavior.
>
> Bug: 1039247
> Change-Id: Ic30f8cc0cb19ec8a306b577f3c10567d91bdccf1
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002047
> Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
> Reviewed-by: Mike West <mkwst@chromium.org>
> Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
> Cr-Commit-Position: refs/heads/master@{#732388}

Bug: 1039247
Change-Id: I16f452ba3c78f69f31d04cb3c92c5b76a3814c86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007311
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733790}
parent e31f7dd3
......@@ -170,6 +170,8 @@ jumbo_static_library("content_shell_lib") {
"browser/web_test/test_info_extractor.h",
"browser/web_test/web_test_background_fetch_delegate.cc",
"browser/web_test/web_test_background_fetch_delegate.h",
"browser/web_test/web_test_blink_test_client.cc",
"browser/web_test/web_test_blink_test_client.h",
"browser/web_test/web_test_bluetooth_adapter_provider.cc",
"browser/web_test/web_test_bluetooth_adapter_provider.h",
"browser/web_test/web_test_bluetooth_chooser_factory.cc",
......
......@@ -803,28 +803,9 @@ bool BlinkTestController::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(BlinkTestController, message)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_PrintMessage, OnPrintMessage)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_PrintMessageToStderr,
OnPrintMessageToStderr)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_InitiateLayoutDump,
OnInitiateLayoutDump)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_OverridePreferences,
OnOverridePreferences)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_SetPopupBlockingEnabled,
OnSetPopupBlockingEnabled)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_NavigateSecondaryWindow,
OnNavigateSecondaryWindow)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_GoToOffset, OnGoToOffset)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_Reload, OnReload)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_LoadURLForFrame, OnLoadURLForFrame)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_CloseRemainingWindows,
OnCloseRemainingWindows)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_ResetDone, OnResetDone)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_SetBluetoothManualChooser,
OnSetBluetoothManualChooser)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_GetBluetoothManualChooserEvents,
OnGetBluetoothManualChooserEvents)
IPC_MESSAGE_HANDLER(BlinkTestHostMsg_SendBluetoothManualChooserEvent,
OnSendBluetoothManualChooserEvent)
IPC_MESSAGE_HANDLER(WebTestHostMsg_BlockThirdPartyCookies,
OnBlockThirdPartyCookies)
IPC_MESSAGE_UNHANDLED(handled = false)
......
......@@ -184,6 +184,20 @@ class BlinkTestController : public WebContentsObserver,
return accumulated_web_test_runtime_flags_changes_;
}
void OnInitiateLayoutDump();
void OnResetDone();
void OnPrintMessageToStderr(const std::string& message);
void OnReload();
void OnCloseRemainingWindows();
void OnGoToOffset(int offset);
void OnSetBluetoothManualChooser(bool enable);
void OnGetBluetoothManualChooserEvents();
void OnSendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument);
void OnSetPopupBlockingEnabled(bool block_popups);
void OnLoadURLForFrame(const GURL& url, const std::string& frame_name);
void OnNavigateSecondaryWindow(const GURL& url);
private:
enum TestPhase { BETWEEN_TESTS, DURING_TEST, CLEAN_UP };
......@@ -211,26 +225,13 @@ class BlinkTestController : public WebContentsObserver,
void OnAudioDump(const std::vector<unsigned char>& audio_dump);
void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image);
void OnTextDump(const std::string& dump);
void OnInitiateLayoutDump();
void OnDumpFrameLayoutResponse(int frame_tree_node_id,
const std::string& dump);
void OnPrintMessageToStderr(const std::string& message);
void OnPrintMessage(const std::string& message);
void OnOverridePreferences(const WebPreferences& prefs);
void OnSetPopupBlockingEnabled(bool block_popups);
void OnTestFinished();
void OnNavigateSecondaryWindow(const GURL& url);
void OnGoToOffset(int offset);
void OnReload();
void OnLoadURLForFrame(const GURL& url, const std::string& frame_name);
void OnCaptureSessionHistory();
void OnCloseRemainingWindows();
void OnResetDone();
void OnLeakDetectionDone(const LeakDetector::LeakDetectionReport& report);
void OnSetBluetoothManualChooser(bool enable);
void OnGetBluetoothManualChooserEvents();
void OnSendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument);
void OnBlockThirdPartyCookies(bool block);
mojo::AssociatedRemote<mojom::WebTestControl>& GetWebTestControlRemote(
RenderFrameHost* frame);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/shell/browser/web_test/web_test_blink_test_client.h"
#include <memory>
#include <string>
#include <utility>
#include "content/shell/browser/web_test/blink_test_controller.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace content {
// static
void WebTestBlinkTestClient::Create(
mojo::PendingReceiver<mojom::WebTestClient> receiver) {
mojo::MakeSelfOwnedReceiver(std::make_unique<WebTestBlinkTestClient>(),
std::move(receiver));
}
void WebTestBlinkTestClient::InitiateLayoutDump() {
BlinkTestController::Get()->OnInitiateLayoutDump();
}
void WebTestBlinkTestClient::PrintMessageToStderr(const std::string& message) {
BlinkTestController::Get()->OnPrintMessageToStderr(message);
}
void WebTestBlinkTestClient::Reload() {
BlinkTestController::Get()->OnReload();
}
void WebTestBlinkTestClient::CloseRemainingWindows() {
BlinkTestController::Get()->OnCloseRemainingWindows();
}
void WebTestBlinkTestClient::GoToOffset(int offset) {
BlinkTestController::Get()->OnGoToOffset(offset);
}
void WebTestBlinkTestClient::SendBluetoothManualChooserEvent(
const std::string& event,
const std::string& argument) {
BlinkTestController::Get()->OnSendBluetoothManualChooserEvent(event,
argument);
}
void WebTestBlinkTestClient::SetBluetoothManualChooser(bool enable) {
BlinkTestController::Get()->OnSetBluetoothManualChooser(enable);
}
void WebTestBlinkTestClient::GetBluetoothManualChooserEvents() {
BlinkTestController::Get()->OnGetBluetoothManualChooserEvents();
}
void WebTestBlinkTestClient::SetPopupBlockingEnabled(bool block_popups) {
BlinkTestController::Get()->OnSetPopupBlockingEnabled(block_popups);
}
void WebTestBlinkTestClient::LoadURLForFrame(const GURL& url,
const std::string& frame_name) {
BlinkTestController::Get()->OnLoadURLForFrame(url, frame_name);
}
void WebTestBlinkTestClient::NavigateSecondaryWindow(const GURL& url) {
BlinkTestController::Get()->OnNavigateSecondaryWindow(url);
}
} // namespace content
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_SHELL_BROWSER_WEB_TEST_WEB_TEST_BLINK_TEST_CLIENT_H_
#define CONTENT_SHELL_BROWSER_WEB_TEST_WEB_TEST_BLINK_TEST_CLIENT_H_
#include "base/macros.h"
#include "content/shell/common/web_test.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "url/gurl.h"
namespace content {
class WebTestBlinkTestClient : public mojom::WebTestClient {
public:
WebTestBlinkTestClient() = default;
~WebTestBlinkTestClient() override = default;
static void Create(mojo::PendingReceiver<mojom::WebTestClient> receiver);
private:
// WebTestClient implementation.
void InitiateLayoutDump() override;
void PrintMessageToStderr(const std::string& message) override;
void Reload() override;
void CloseRemainingWindows() override;
void GoToOffset(int offset) override;
void SendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument) override;
void SetBluetoothManualChooser(bool enable) override;
void GetBluetoothManualChooserEvents() override;
void SetPopupBlockingEnabled(bool block_popups) override;
void LoadURLForFrame(const GURL& url, const std::string& frame_name) override;
void NavigateSecondaryWindow(const GURL& url) override;
DISALLOW_COPY_AND_ASSIGN(WebTestBlinkTestClient);
};
} // namespace content
#endif // CONTENT_SHELL_BROWSER_WEB_TEST_WEB_TEST_BLINK_TEST_CLIENT_H_
......@@ -30,6 +30,7 @@
#include "content/shell/browser/web_test/fake_bluetooth_chooser.h"
#include "content/shell/browser/web_test/fake_bluetooth_chooser_factory.h"
#include "content/shell/browser/web_test/mojo_web_test_helper.h"
#include "content/shell/browser/web_test/web_test_blink_test_client.h"
#include "content/shell/browser/web_test/web_test_bluetooth_fake_adapter_setter_impl.h"
#include "content/shell/browser/web_test/web_test_browser_context.h"
#include "content/shell/browser/web_test/web_test_browser_main_parts.h"
......@@ -156,6 +157,9 @@ void WebTestContentBrowserClient::ExposeInterfacesToRenderer(
base::BindRepeating(&WebTestBluetoothFakeAdapterSetterImpl::Create),
ui_task_runner);
registry->AddInterface(base::BindRepeating(&WebTestBlinkTestClient::Create),
ui_task_runner);
registry->AddInterface(base::BindRepeating(&bluetooth::FakeBluetooth::Create),
ui_task_runner);
// This class outlives |render_process_host|, which owns |registry|. Since
......
......@@ -49,6 +49,7 @@ struct WebTestDump {
gfx.mojom.Rect selection_rect;
};
// Blink test messages sent from the browser process to the renderer.
interface WebTestControl {
CaptureDump() => (WebTestDump result);
......@@ -85,3 +86,49 @@ interface WebTestControl {
// Reply Bluetooth manual events to BlinkTestRunner.
ReplyBluetoothManualChooserEvents(array<string> events);
};
// Blink test messages sent from the renderer process to the browser.
interface WebTestClient {
// Asks the browser process to perform a layout dump spanning all the
// (potentially cross-process) frames. This goes through multiple
// WebTestControl.DumpFrameLayout calls and ends with sending of
// BlinkTestMsg_LayoutDumpCompleted.
InitiateLayoutDump();
// Add a message to stderr (not saved to expected output files, for debugging
// only).
PrintMessageToStderr(string message);
// Trigger a reload navigation on the main WebView.
Reload();
// Invoked when the embedder should close all but the main WebView.
CloseRemainingWindows();
// Trigger a GoToOffset navigation on the main WebView.
GoToOffset(int32 offset);
// Calls the BluetoothChooser::EventHandler with the arguments here. Valid
// event strings are:
// * "cancel" - simulates the user canceling the chooser.
// * "select" - simulates the user selecting a device whose device ID is in
// |argument|.
SendBluetoothManualChooserEvent(string event, string argument);
// If |enable| is true makes the Bluetooth chooser record its input and wait
// for instructions from the test program on how to proceed. Otherwise
// fall backs to the browser's default chooser.
SetBluetoothManualChooser(bool enable);
// Returns the events recorded since the last call to this function.
GetBluetoothManualChooserEvents();
// Manages the popup blocking setting to used for web tests.
SetPopupBlockingEnabled(bool block_popups);
// Trigger a loadURL navigation on the main WebView.
LoadURLForFrame(url.mojom.Url url, string frame_name);
// Naivgate a URL on the secondary window.
NavigateSecondaryWindow(url.mojom.Url url);
};
......@@ -15,37 +15,11 @@
#define IPC_MESSAGE_START BlinkTestMsgStart
// Asks the browser process to perform a layout dump spanning all the
// (potentially cross-process) frames. This goes through multiple
// WebTestControl.DumpFrameLayout calls and ends with sending of
// LayoutDumpCompleted.
// TODO(crbug.com/1039247): LayoutDumpCompleted call should be removed and the
// callback should happen part of LayoutDump call on the host interface.
IPC_MESSAGE_ROUTED0(BlinkTestHostMsg_InitiateLayoutDump)
IPC_MESSAGE_ROUTED0(BlinkTestHostMsg_ResetDone)
// WebTestDelegate related.
IPC_MESSAGE_ROUTED1(BlinkTestHostMsg_OverridePreferences,
content::WebPreferences /* preferences */)
IPC_MESSAGE_ROUTED1(BlinkTestHostMsg_PrintMessage, std::string /* message */)
IPC_MESSAGE_ROUTED1(BlinkTestHostMsg_PrintMessageToStderr,
std::string /* message */)
IPC_MESSAGE_ROUTED1(BlinkTestHostMsg_NavigateSecondaryWindow, GURL /* url */)
IPC_MESSAGE_ROUTED1(BlinkTestHostMsg_GoToOffset, int /* offset */)
IPC_MESSAGE_ROUTED0(BlinkTestHostMsg_Reload)
IPC_MESSAGE_ROUTED2(BlinkTestHostMsg_LoadURLForFrame,
GURL /* url */,
std::string /* frame_name */)
IPC_MESSAGE_ROUTED0(BlinkTestHostMsg_CloseRemainingWindows)
IPC_MESSAGE_ROUTED1(BlinkTestHostMsg_SetBluetoothManualChooser,
bool /* enable */)
IPC_MESSAGE_ROUTED0(BlinkTestHostMsg_GetBluetoothManualChooserEvents)
IPC_MESSAGE_ROUTED2(BlinkTestHostMsg_SendBluetoothManualChooserEvent,
std::string /* event */,
std::string /* argument */)
IPC_MESSAGE_ROUTED1(BlinkTestHostMsg_SetPopupBlockingEnabled,
bool /* block_popups */)
#endif // CONTENT_SHELL_COMMON_WEB_TEST_BLINK_TEST_MESSAGES_H_
......@@ -182,7 +182,7 @@ void BlinkTestRunner::SetEditCommand(const std::string& name,
}
void BlinkTestRunner::PrintMessageToStderr(const std::string& message) {
Send(new BlinkTestHostMsg_PrintMessageToStderr(routing_id(), message));
GetWebTestClientRemote().PrintMessageToStderr(message);
}
void BlinkTestRunner::PrintMessage(const std::string& message) {
......@@ -260,8 +260,7 @@ void BlinkTestRunner::ApplyPreferences() {
}
void BlinkTestRunner::SetPopupBlockingEnabled(bool block_popups) {
Send(
new BlinkTestHostMsg_SetPopupBlockingEnabled(routing_id(), block_popups));
GetWebTestClientRemote().SetPopupBlockingEnabled(block_popups);
}
void BlinkTestRunner::UseUnfortunateSynchronousResizeMode(bool enable) {
......@@ -289,7 +288,7 @@ void BlinkTestRunner::ResetAutoResizeMode() {
}
void BlinkTestRunner::NavigateSecondaryWindow(const GURL& url) {
Send(new BlinkTestHostMsg_NavigateSecondaryWindow(routing_id(), url));
GetWebTestClientRemote().NavigateSecondaryWindow(url);
}
void BlinkTestRunner::InspectSecondaryWindow() {
......@@ -358,20 +357,19 @@ void BlinkTestRunner::SetBluetoothFakeAdapter(const std::string& adapter_name,
}
void BlinkTestRunner::SetBluetoothManualChooser(bool enable) {
Send(new BlinkTestHostMsg_SetBluetoothManualChooser(routing_id(), enable));
GetWebTestClientRemote().SetBluetoothManualChooser(enable);
}
void BlinkTestRunner::GetBluetoothManualChooserEvents(
base::OnceCallback<void(const std::vector<std::string>&)> callback) {
get_bluetooth_events_callbacks_.push_back(std::move(callback));
Send(new BlinkTestHostMsg_GetBluetoothManualChooserEvents(routing_id()));
GetWebTestClientRemote().GetBluetoothManualChooserEvents();
}
void BlinkTestRunner::SendBluetoothManualChooserEvent(
const std::string& event,
const std::string& argument) {
Send(new BlinkTestHostMsg_SendBluetoothManualChooserEvent(routing_id(), event,
argument));
GetWebTestClientRemote().SendBluetoothManualChooserEvent(event, argument);
}
void BlinkTestRunner::SetFocus(blink::WebView* web_view, bool focus) {
......@@ -527,7 +525,7 @@ void BlinkTestRunner::CaptureLocalLayoutDump() {
// TODO(vmpstr): Since CaptureDump is called from the browser, we can be
// smart and move this logic directly to the browser.
waiting_for_layout_dump_results_ = true;
Send(new BlinkTestHostMsg_InitiateLayoutDump(routing_id()));
GetWebTestClientRemote().InitiateLayoutDump();
}
}
......@@ -588,7 +586,7 @@ void BlinkTestRunner::CaptureDumpComplete() {
}
void BlinkTestRunner::CloseRemainingWindows() {
Send(new BlinkTestHostMsg_CloseRemainingWindows(routing_id()));
GetWebTestClientRemote().CloseRemainingWindows();
}
void BlinkTestRunner::DeleteAllCookies() {
......@@ -600,16 +598,16 @@ int BlinkTestRunner::NavigationEntryCount() {
}
void BlinkTestRunner::GoToOffset(int offset) {
Send(new BlinkTestHostMsg_GoToOffset(routing_id(), offset));
GetWebTestClientRemote().GoToOffset(offset);
}
void BlinkTestRunner::Reload() {
Send(new BlinkTestHostMsg_Reload(routing_id()));
GetWebTestClientRemote().Reload();
}
void BlinkTestRunner::LoadURLForFrame(const WebURL& url,
const std::string& frame_name) {
Send(new BlinkTestHostMsg_LoadURLForFrame(routing_id(), url, frame_name));
GetWebTestClientRemote().LoadURLForFrame(url, frame_name);
}
bool BlinkTestRunner::AllowExternalPages() {
......@@ -740,6 +738,14 @@ BlinkTestRunner::GetBluetoothFakeAdapterSetter() {
return *bluetooth_fake_adapter_setter_;
}
mojom::WebTestClient& BlinkTestRunner::GetWebTestClientRemote() {
if (!web_test_client_remote_) {
RenderThread::Get()->BindHostReceiver(
web_test_client_remote_.BindNewPipeAndPassReceiver());
}
return *web_test_client_remote_;
}
void BlinkTestRunner::OnSetupSecondaryRenderer() {
DCHECK(!is_main_window_);
......
......@@ -180,6 +180,9 @@ class BlinkTestRunner : public RenderViewObserver,
mojo::Remote<mojom::WebTestBluetoothFakeAdapterSetter>
bluetooth_fake_adapter_setter_;
mojom::WebTestClient& GetWebTestClientRemote();
mojo::Remote<mojom::WebTestClient> web_test_client_remote_;
test_runner::TestPreferences prefs_;
mojom::ShellTestConfigurationPtr test_config_;
......
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