Commit 5e0fd9d7 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Clean up content::RenderViewTest.

- Explain |view_| member's life time.
- Remove an old comment that does not make sense.
- std::make_unique() everywhere.

Change-Id: I42360b80ea66fbd38705223a162f1683b49ab5b3
Reviewed-on: https://chromium-review.googlesource.com/740709
Commit-Queue: Nick Carter <nick@chromium.org>
Reviewed-by: default avatarNick Carter <nick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513254}
parent 6fcd0ed3
......@@ -9,7 +9,6 @@
#include <cctype>
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
......@@ -152,8 +151,9 @@ RenderViewTest::RendererBlinkPlatformImplTestOverride::Get() const {
void RenderViewTest::RendererBlinkPlatformImplTestOverride::Initialize() {
renderer_scheduler_ = blink::scheduler::RendererScheduler::Create();
blink_platform_impl_.reset(
new RendererBlinkPlatformImplTestOverrideImpl(renderer_scheduler_.get()));
blink_platform_impl_ =
std::make_unique<RendererBlinkPlatformImplTestOverrideImpl>(
renderer_scheduler_.get());
}
void RenderViewTest::RendererBlinkPlatformImplTestOverride::Shutdown() {
......@@ -161,7 +161,7 @@ void RenderViewTest::RendererBlinkPlatformImplTestOverride::Shutdown() {
blink_platform_impl_->Shutdown();
}
RenderViewTest::RenderViewTest() : view_(nullptr) {
RenderViewTest::RenderViewTest() {
RenderFrameImpl::InstallCreateHook(&TestRenderFrame::CreateTestRenderFrame);
}
......@@ -234,17 +234,18 @@ void RenderViewTest::GoForward(const GURL& url, const PageState& state) {
}
void RenderViewTest::SetUp() {
test_io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart));
ipc_support_.reset(new mojo::edk::ScopedIPCSupport(
test_io_thread_ =
std::make_unique<base::TestIOThread>(base::TestIOThread::kAutoStart);
ipc_support_ = std::make_unique<mojo::edk::ScopedIPCSupport>(
test_io_thread_->task_runner(),
mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST));
mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST);
// Subclasses can set render_thread_ with their own implementation before
// calling RenderViewTest::SetUp().
// The render thread needs to exist before blink::Initialize. It also mirrors
// the order on Chromium initialization.
if (!render_thread_)
render_thread_.reset(new MockRenderThread());
render_thread_ = std::make_unique<MockRenderThread>();
render_thread_->set_routing_id(kRouteId);
render_thread_->set_new_window_routing_id(kNewWindowRouteId);
render_thread_->set_new_window_main_frame_widget_routing_id(
......@@ -274,15 +275,16 @@ void RenderViewTest::SetUp() {
#endif
#if defined(OS_MACOSX)
autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
autorelease_pool_ = std::make_unique<base::mac::ScopedNSAutoreleasePool>();
#endif
command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM));
field_trial_list_.reset(new base::FieldTrialList(nullptr));
command_line_ =
std::make_unique<base::CommandLine>(base::CommandLine::NO_PROGRAM);
field_trial_list_ = std::make_unique<base::FieldTrialList>(nullptr);
// We don't use the descriptor here anyways so it's ok to pass -1.
base::FieldTrialList::CreateTrialsFromCommandLine(
*command_line_, switches::kFieldTrialHandle, -1);
params_.reset(new MainFunctionParams(*command_line_));
platform_.reset(new RendererMainPlatformDelegate(*params_));
params_ = std::make_unique<MainFunctionParams>(*command_line_);
platform_ = std::make_unique<RendererMainPlatformDelegate>(*params_);
platform_->PlatformInitialize();
// Setting flags and really doing anything with WebKit is fairly fragile and
......@@ -301,12 +303,13 @@ void RenderViewTest::SetUp() {
// ResourceBundle isn't initialized (since we have to use a diferent test
// suite implementation than for content_unittests). For browser_tests, this
// is already initialized.
if (!ui::ResourceBundle::HasSharedInstance())
if (!ui::ResourceBundle::HasSharedInstance()) {
ui::ResourceBundle::InitSharedInstanceWithLocale(
"en-US", nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
}
compositor_deps_.reset(new FakeCompositorDependencies);
mock_process_.reset(new MockRenderProcess);
compositor_deps_ = std::make_unique<FakeCompositorDependencies>();
mock_process_ = std::make_unique<MockRenderProcess>();
mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
view_params->opener_frame_route_id = MSG_ROUTING_NONE;
......@@ -328,11 +331,8 @@ void RenderViewTest::SetUp() {
view_params->min_size = gfx::Size();
view_params->max_size = gfx::Size();
// This needs to pass the mock render thread to the view.
RenderViewImpl* view =
RenderViewImpl::Create(compositor_deps_.get(), std::move(view_params),
RenderWidget::ShowCallback());
view_ = view;
view_ = RenderViewImpl::Create(compositor_deps_.get(), std::move(view_params),
RenderWidget::ShowCallback());
}
void RenderViewTest::TearDown() {
......@@ -346,6 +346,8 @@ void RenderViewTest::TearDown() {
leak_detector->PrepareForLeakDetection(view_->GetWebView()->MainFrame());
// |view_| is ref-counted and deletes itself during the RunUntilIdle() call
// below.
view_ = nullptr;
mock_process_.reset();
......@@ -357,7 +359,7 @@ void RenderViewTest::TearDown() {
base::RunLoop().RunUntilIdle();
#if defined(OS_MACOSX)
autorelease_pool_.reset(NULL);
autorelease_pool_.reset();
#endif
leak_detector->CollectGarbageAndReport();
......@@ -412,27 +414,27 @@ void RenderViewTest::SendWebGestureEvent(
SendInputEvent(gesture_event);
}
const char* const kGetCoordinatesScript =
"(function() {"
" function GetCoordinates(elem) {"
" if (!elem)"
" return [ 0, 0];"
" var coordinates = [ elem.offsetLeft, elem.offsetTop];"
" var parent_coordinates = GetCoordinates(elem.offsetParent);"
" coordinates[0] += parent_coordinates[0];"
" coordinates[1] += parent_coordinates[1];"
" return [ Math.round(coordinates[0]),"
" Math.round(coordinates[1])];"
" };"
" var elem = document.getElementById('$1');"
" if (!elem)"
" return null;"
" var bounds = GetCoordinates(elem);"
" bounds[2] = Math.round(elem.offsetWidth);"
" bounds[3] = Math.round(elem.offsetHeight);"
" return bounds;"
"})();";
gfx::Rect RenderViewTest::GetElementBounds(const std::string& element_id) {
static constexpr char kGetCoordinatesScript[] =
"(function() {"
" function GetCoordinates(elem) {"
" if (!elem)"
" return [ 0, 0];"
" var coordinates = [ elem.offsetLeft, elem.offsetTop];"
" var parent_coordinates = GetCoordinates(elem.offsetParent);"
" coordinates[0] += parent_coordinates[0];"
" coordinates[1] += parent_coordinates[1];"
" return [ Math.round(coordinates[0]),"
" Math.round(coordinates[1])];"
" };"
" var elem = document.getElementById('$1');"
" if (!elem)"
" return null;"
" var bounds = GetCoordinates(elem);"
" bounds[2] = Math.round(elem.offsetWidth);"
" bounds[3] = Math.round(elem.offsetHeight);"
" return bounds;"
"})();";
std::vector<std::string> params;
params.push_back(element_id);
std::string script =
......
......@@ -190,14 +190,13 @@ class RenderViewTest : public testing::Test, blink::WebLeakDetectorClient {
// blink::WebLeakDetectorClient implementation.
void OnLeakDetectionComplete(const Result& result) override;
protected:
base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<FakeCompositorDependencies> compositor_deps_;
std::unique_ptr<MockRenderProcess> mock_process_;
// We use a naked pointer because we don't want to expose RenderViewImpl in
// the embedder's namespace.
RenderView* view_;
RenderView* view_ = nullptr;
RendererBlinkPlatformImplTestOverride blink_platform_impl_;
std::unique_ptr<ContentClient> content_client_;
std::unique_ptr<ContentBrowserClient> content_browser_client_;
......
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