Commit c989ac71 authored by danakj's avatar danakj Committed by Commit Bot

Remove GCController dependency on BlinkTestRunner

Rather than passing a BlinkTestRunner unrelated to the current frame
to GCController, we drop its dependency on BlinkTestRunner, as it can
get the task runner from its own WebLocalFrame directly.

Renames BindTo() methods to Install() as they are all there to install
JS bindings, and forward through to other Install() methods.

Moves the GCController binding installation out to the frame, as it is
done per-frame, instead of going through the "global" TestInterfaces.

R=nasko@chromium.org

Bug: 866140, 1069111
Change-Id: I75325ee908d31dca7d9dcd8a5b7673d999dd891d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150396Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759396}
parent fd4beeb2
......@@ -249,7 +249,7 @@ GamepadController::GamepadController() {
Reset();
}
GamepadController::~GamepadController() {}
GamepadController::~GamepadController() = default;
void GamepadController::Reset() {
memset(gamepads_, 0, sizeof(*gamepads_));
......
......@@ -5,7 +5,6 @@
#include "content/shell/test_runner/gc_controller.h"
#include "base/bind.h"
#include "content/shell/renderer/web_test/blink_test_runner.h"
#include "gin/arguments.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
......@@ -18,8 +17,7 @@ namespace content {
gin::WrapperInfo GCController::kWrapperInfo = {gin::kEmbedderNativeGin};
// static
void GCController::Install(BlinkTestRunner* blink_test_runner,
blink::WebLocalFrame* frame) {
void GCController::Install(blink::WebLocalFrame* frame) {
v8::Isolate* isolate = blink::MainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = frame->MainWorldScriptContext();
......@@ -29,7 +27,7 @@ void GCController::Install(BlinkTestRunner* blink_test_runner,
v8::Context::Scope context_scope(context);
gin::Handle<GCController> controller =
gin::CreateHandle(isolate, new GCController(blink_test_runner));
gin::CreateHandle(isolate, new GCController(frame));
if (controller.IsEmpty())
return;
v8::Local<v8::Object> global = context->Global();
......@@ -39,8 +37,7 @@ void GCController::Install(BlinkTestRunner* blink_test_runner,
.Check();
}
GCController::GCController(BlinkTestRunner* blink_test_runner)
: blink_test_runner_(blink_test_runner) {}
GCController::GCController(blink::WebLocalFrame* frame) : frame_(frame) {}
GCController::~GCController() = default;
......@@ -74,14 +71,16 @@ void GCController::AsyncCollectAll(const gin::Arguments& args) {
"v8::Function.");
return;
}
v8::UniquePersistent<v8::Function> func(
v8::UniquePersistent<v8::Function> js_callback(
args.isolate(), v8::Local<v8::Function>::Cast(args.PeekNext()));
CHECK(!func.IsEmpty());
blink_test_runner_->PostTask(
// Bind the js callback into a OnceClosure that will be run asynchronously in
// a fresh call stack.
base::OnceClosure run_async =
base::BindOnce(&GCController::AsyncCollectAllWithEmptyStack,
base::Unretained(this), std::move(func)));
weak_ptr_factory_.GetWeakPtr(), std::move(js_callback));
frame_->GetTaskRunner(blink::TaskType::kInternalTest)
->PostTask(FROM_HERE, std::move(run_async));
}
void GCController::AsyncCollectAllWithEmptyStack(
......
......@@ -6,6 +6,7 @@
#define CONTENT_SHELL_TEST_RUNNER_GC_CONTROLLER_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "gin/wrappable.h"
namespace blink {
......@@ -17,13 +18,11 @@ class Arguments;
}
namespace content {
class BlinkTestRunner;
class GCController : public gin::Wrappable<GCController> {
public:
static gin::WrapperInfo kWrapperInfo;
static void Install(BlinkTestRunner* blink_test_runner,
blink::WebLocalFrame* frame);
static void Install(blink::WebLocalFrame* frame);
private:
// In the first GC cycle, a weak callback of the DOM wrapper is called back
......@@ -34,7 +33,7 @@ class GCController : public gin::Wrappable<GCController> {
// that are chained. Seven GC cycles look enough in most tests.
static constexpr int kNumberOfGCsForFullCollection = 7;
explicit GCController(BlinkTestRunner* blink_test_runner);
explicit GCController(blink::WebLocalFrame* frame);
~GCController() override;
// gin::Wrappable.
......@@ -49,7 +48,8 @@ class GCController : public gin::Wrappable<GCController> {
void AsyncCollectAllWithEmptyStack(
v8::UniquePersistent<v8::Function> callback);
BlinkTestRunner* blink_test_runner_;
blink::WebLocalFrame* const frame_;
base::WeakPtrFactory<GCController> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(GCController);
};
......
......@@ -14,7 +14,6 @@
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "content/shell/test_runner/gamepad_controller.h"
#include "content/shell/test_runner/gc_controller.h"
#include "content/shell/test_runner/test_runner.h"
#include "content/shell/test_runner/text_input_controller.h"
#include "content/shell/test_runner/web_view_test_proxy.h"
......@@ -46,10 +45,8 @@ void TestInterfaces::SetMainView(blink::WebView* web_view) {
test_runner_->SetMainView(web_view);
}
void TestInterfaces::BindTo(blink::WebLocalFrame* frame) {
void TestInterfaces::Install(blink::WebLocalFrame* frame) {
gamepad_controller_->Install(frame);
// TODO(danakj): Pass the frame's renderview's BlinkTestRunner.
GCController::Install(GetFirstBlinkTestRunner(), frame);
}
void TestInterfaces::ResetTestHelperControllers() {
......
......@@ -29,7 +29,7 @@ class TestInterfaces {
~TestInterfaces();
void SetMainView(blink::WebView* web_view);
void BindTo(blink::WebLocalFrame* frame);
void Install(blink::WebLocalFrame* frame);
void ResetTestHelperControllers();
void ResetAll();
bool TestIsRunning();
......
......@@ -16,6 +16,7 @@
#include "content/shell/renderer/web_test/blink_test_runner.h"
#include "content/shell/test_runner/accessibility_controller.h"
#include "content/shell/test_runner/event_sender.h"
#include "content/shell/test_runner/gc_controller.h"
#include "content/shell/test_runner/mock_screen_orientation_client.h"
#include "content/shell/test_runner/test_interfaces.h"
#include "content/shell/test_runner/test_plugin.h"
......@@ -507,9 +508,12 @@ void WebFrameTestClient::DidClearWindowObject() {
web_frame_test_proxy_->GetLocalRootWebWidgetTestProxy();
blink::WebLocalFrame* frame = web_frame_test_proxy_->GetWebFrame();
interfaces->BindTo(frame);
web_view_test_proxy_->BindTo(frame);
web_widget_test_proxy->BindTo(frame);
// These calls will install the various JS bindings for web tests into the
// frame before JS has a chance to run.
GCController::Install(frame);
interfaces->Install(frame);
web_view_test_proxy_->Install(frame);
web_widget_test_proxy->Install(frame);
}
blink::WebEffectiveConnectionType
......
......@@ -92,7 +92,7 @@ void WebViewTestProxy::Reset() {
}
}
void WebViewTestProxy::BindTo(blink::WebLocalFrame* frame) {
void WebViewTestProxy::Install(blink::WebLocalFrame* frame) {
accessibility_controller_.Install(frame);
text_input_controller_.Install(frame);
view_test_runner_.Install(frame);
......
......@@ -91,7 +91,7 @@ class WebViewTestProxy : public content::RenderViewImpl {
TestRunnerForSpecificView* view_test_runner() { return &view_test_runner_; }
void Reset();
void BindTo(blink::WebLocalFrame* frame);
void Install(blink::WebLocalFrame* frame);
private:
// RenderViewImpl has no public destructor.
......
......@@ -164,7 +164,7 @@ void WebWidgetTestProxy::Reset() {
UseSynchronousResizeModeForTesting(false);
}
void WebWidgetTestProxy::BindTo(blink::WebLocalFrame* frame) {
void WebWidgetTestProxy::Install(blink::WebLocalFrame* frame) {
event_sender_.Install(frame);
}
......
......@@ -87,7 +87,7 @@ class WebWidgetTestProxy : public content::RenderWidget {
EventSender* event_sender() { return &event_sender_; }
void Reset();
void BindTo(blink::WebLocalFrame* frame);
void Install(blink::WebLocalFrame* frame);
void EndSyntheticGestures();
......
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