Commit feb841d1 authored by Dominic Farolino's avatar Dominic Farolino Committed by Chromium LUCI CQ

MBI: Fix kLegacy DCHECK in AgentSchedulingGroup for MockASG usages

Before this CL, MockAgentSchedulingGroup would always invoke the
AgentSchedulingGroup base class constructor which is now reserved for
the kLegacy MBI feature mode. This caused the ctor to DCHECK in tests
when MBI mode was enabled.

After this CL, MockAgentSchedulingGroup conditionally invokes the right
AgentSchedulingGroup constructor given the flag. Consequently,
MockRenderThread::GetIOTaskRunner() needs to be able to return a
non-null TaskRunner. This CL gives MockRenderThread the ability to set
a new IOTaskRunner manually so that it can be returned when necessary.

While we're here we also remove
PrintMockRenderThread_set_io_thread_for_testing() since the base class
MockRenderThread now handles that. We also entirely remove
ChromeMockRenderThread.

Bug: 1158656
Change-Id: I1ab1231048ecc1b798549634811706f86a7bafb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2591929
Commit-Queue: Dominic Farolino <dom@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837106}
parent 23f02cf0
......@@ -412,23 +412,3 @@ static_library("renderer") {
deps += [ "//chrome/common/performance_manager/mojom" ]
}
}
static_library("test_support") {
testonly = true
visibility = [ "//chrome/test:test_support" ]
sources = [
"chrome_mock_render_thread.cc",
"chrome_mock_render_thread.h",
]
deps = [
":renderer",
"//chrome/common/search:mojo_bindings",
"//components/safe_browsing/content/renderer/phishing_classifier:unit_tests_support",
"//content/test:test_support",
"//extensions/buildflags",
"//testing/gmock",
"//testing/gtest",
]
}
// Copyright (c) 2012 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 "chrome/renderer/chrome_mock_render_thread.h"
#include "base/single_thread_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
ChromeMockRenderThread::ChromeMockRenderThread() {
}
ChromeMockRenderThread::~ChromeMockRenderThread() {
}
scoped_refptr<base::SingleThreadTaskRunner>
ChromeMockRenderThread::GetIOTaskRunner() {
return io_task_runner_;
}
void ChromeMockRenderThread::set_io_task_runner(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
io_task_runner_ = task_runner;
}
// Copyright (c) 2011 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 CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
#define CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
#include <string>
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "content/public/test/mock_render_thread.h"
// Extends content::MockRenderThread to know about extension messages.
class ChromeMockRenderThread : public content::MockRenderThread {
public:
ChromeMockRenderThread();
~ChromeMockRenderThread() override;
// content::RenderThread overrides.
scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() override;
//////////////////////////////////////////////////////////////////////////
// The following functions are called by the test itself.
void set_io_task_runner(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
protected:
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
DISALLOW_COPY_AND_ASSIGN(ChromeMockRenderThread);
};
#endif // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
......@@ -200,6 +200,8 @@ static_library("test_support") {
deps = [
"//build:chromeos_buildflags",
"//chrome/common/search:mojo_bindings",
"//components/safe_browsing/content/renderer/phishing_classifier:unit_tests_support",
"//components/security_interstitials/content:security_interstitial_page",
]
......@@ -215,7 +217,6 @@ static_library("test_support") {
"//chrome/common:non_code_constants",
"//chrome/common:test_support",
"//chrome/renderer",
"//chrome/renderer:test_support",
"//chrome/utility",
"//components/autofill/core/browser:test_support",
"//components/bookmarks/test",
......
......@@ -99,9 +99,6 @@ void ChromeRenderViewTest::SetUp() {
ChromeUnitTestSuite::InitializeProviders();
ChromeUnitTestSuite::InitializeResourceBundle();
chrome_render_thread_ = new ChromeMockRenderThread();
render_thread_.reset(chrome_render_thread_);
registry_ = std::make_unique<service_manager::BinderRegistry>();
// TODO(crbug/862989): Before this SetUp, the test agents defined at the end
......
......@@ -8,7 +8,6 @@
#include <memory>
#include <string>
#include "chrome/renderer/chrome_mock_render_thread.h"
#include "content/public/test/render_view_test.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
......@@ -51,9 +50,6 @@ class ChromeRenderViewTest : public content::RenderViewTest {
std::unique_ptr<service_manager::BinderRegistry> registry_;
blink::AssociatedInterfaceRegistry associated_interfaces_;
// Naked pointer as ownership is with content::RenderViewTest::render_thread_.
ChromeMockRenderThread* chrome_render_thread_ = nullptr;
};
#endif // CHROME_TEST_BASE_CHROME_RENDER_VIEW_TEST_H_
......@@ -28,16 +28,6 @@ PrintMockRenderThread::PrintMockRenderThread()
PrintMockRenderThread::~PrintMockRenderThread() = default;
scoped_refptr<base::SingleThreadTaskRunner>
PrintMockRenderThread::GetIOTaskRunner() {
return io_task_runner_;
}
void PrintMockRenderThread::set_io_task_runner(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
io_task_runner_ = task_runner;
}
bool PrintMockRenderThread::OnMessageReceived(const IPC::Message& msg) {
if (content::MockRenderThread::OnMessageReceived(msg))
return true;
......
......@@ -30,15 +30,6 @@ class PrintMockRenderThread : public content::MockRenderThread {
PrintMockRenderThread& operator=(const PrintMockRenderThread&) = delete;
~PrintMockRenderThread() override;
// content::RenderThread overrides.
scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() override;
//////////////////////////////////////////////////////////////////////////
// The following functions are called by the test itself.
void set_io_task_runner(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
#if BUILDFLAG(ENABLE_PRINTING)
// Returns the pseudo-printer instance.
MockPrinter* printer();
......@@ -91,8 +82,6 @@ class PrintMockRenderThread : public content::MockRenderThread {
// Vector of <page_number, content_data_size> that were previewed.
std::vector<std::pair<uint32_t, uint32_t>> print_preview_pages_;
#endif
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
};
#endif // COMPONENTS_PRINTING_TEST_PRINT_MOCK_RENDER_THREAD_H_
......@@ -125,7 +125,7 @@ IPC::SyncMessageFilter* MockRenderThread::GetSyncMessageFilter() {
scoped_refptr<base::SingleThreadTaskRunner>
MockRenderThread::GetIOTaskRunner() {
return scoped_refptr<base::SingleThreadTaskRunner>();
return io_task_runner_;
}
void MockRenderThread::BindHostReceiver(mojo::GenericPendingReceiver receiver) {
......
......@@ -49,6 +49,11 @@ class MockRenderThread : public RenderThread {
// Provides access to the messages that have been received by this thread.
IPC::TestSink& sink() { return sink_; }
void SetIOTaskRunner(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
io_task_runner_ = std::move(task_runner);
}
// RenderThread implementation:
bool Send(IPC::Message* msg) override;
IPC::SyncChannel* GetChannel() override;
......@@ -125,6 +130,8 @@ class MockRenderThread : public RenderThread {
IPC::TestSink sink_;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
// Routing ID what will be assigned to the next view, widget, or frame.
int32_t next_routing_id_;
......
......@@ -237,11 +237,6 @@ bool GetWindowsKeyCode(char ascii_character, int* key_code) {
}
}
std::unique_ptr<AgentSchedulingGroup> CreateAgentSchedulingGroup(
RenderThread& render_thread) {
return std::make_unique<MockAgentSchedulingGroup>(render_thread);
}
} // namespace
class RendererBlinkPlatformImplTestOverrideImpl
......@@ -426,6 +421,8 @@ void RenderViewTest::SetUp() {
if (!render_thread_)
render_thread_ = std::make_unique<MockRenderThread>();
render_thread_->SetIOTaskRunner(test_io_thread_->task_runner());
// Blink needs to be initialized before calling CreateContentRendererClient()
// because it uses blink internally.
blink_platform_impl_.Initialize();
......@@ -439,7 +436,7 @@ void RenderViewTest::SetUp() {
SetBrowserClientForTesting(content_browser_client_.get());
SetRendererClientForTesting(content_renderer_client_.get());
agent_scheduling_group_ = CreateAgentSchedulingGroup(*render_thread_);
agent_scheduling_group_ = MockAgentSchedulingGroup::Create(*render_thread_);
render_widget_host_ = CreateRenderWidgetHost();
#if defined(OS_WIN)
......
......@@ -7,12 +7,40 @@
#include "base/no_destructor.h"
#include "content/renderer/render_thread_impl.h"
namespace {
static features::MBIMode GetMBIMode() {
return base::FeatureList::IsEnabled(features::kMBIMode)
? features::kMBIModeParam.Get()
: features::MBIMode::kLegacy;
}
} // namespace
namespace content {
MockAgentSchedulingGroup::MockAgentSchedulingGroup(RenderThread& render_thread)
: AgentSchedulingGroup(
// static
std::unique_ptr<MockAgentSchedulingGroup> MockAgentSchedulingGroup::Create(
RenderThread& render_thread) {
return (GetMBIMode() == features::MBIMode::kLegacy)
? std::make_unique<MockAgentSchedulingGroup>(
render_thread, mojo::PendingAssociatedReceiver<
mojom::AgentSchedulingGroup>())
: std::make_unique<MockAgentSchedulingGroup>(
render_thread,
mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup>()) {}
mojo::PendingReceiver<IPC::mojom::ChannelBootstrap>());
}
MockAgentSchedulingGroup::MockAgentSchedulingGroup(
RenderThread& render_thread,
mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup>
pending_receiver)
: AgentSchedulingGroup(render_thread, std::move(pending_receiver)) {}
MockAgentSchedulingGroup::MockAgentSchedulingGroup(
RenderThread& render_thread,
mojo::PendingReceiver<IPC::mojom::ChannelBootstrap> pending_receiver)
: AgentSchedulingGroup(render_thread, std::move(pending_receiver)) {}
mojom::RouteProvider* MockAgentSchedulingGroup::GetRemoteRouteProvider() {
DCHECK(!RenderThreadImpl::current());
......
......@@ -5,6 +5,8 @@
#ifndef CONTENT_RENDERER_MOCK_AGENT_SCHEDULING_GROUP_H_
#define CONTENT_RENDERER_MOCK_AGENT_SCHEDULING_GROUP_H_
#include <memory>
#include "base/callback.h"
#include "content/common/associated_interfaces.mojom.h"
#include "content/common/content_export.h"
......@@ -22,8 +24,17 @@ class RenderThread;
// in the browser process.
class MockAgentSchedulingGroup : public AgentSchedulingGroup {
public:
explicit MockAgentSchedulingGroup(RenderThread& render_thread);
static std::unique_ptr<MockAgentSchedulingGroup> Create(
RenderThread& render_thread);
MockAgentSchedulingGroup(
RenderThread& render_thread,
mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup>
pending_receiver);
MockAgentSchedulingGroup(
RenderThread& render_thread,
mojo::PendingReceiver<IPC::mojom::ChannelBootstrap> pending_receiver);
private:
mojom::RouteProvider* GetRemoteRouteProvider() override;
};
......
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