Commit d993d06a authored by mkwst's avatar mkwst Committed by Commit bot

Content Shell: Introduce LayoutTestBrowserContext. (Reland)

This splits the DRT-specific parts of ShellBrowserContext out into a new
class that we'll only instantiate when the flag is set.

------------------------------------------------------------------------
This is a re-land of https://codereview.chromium.org/637843003, which
was reverted due to layout test timeouts.
------------------------------------------------------------------------

BUG=420994

Review URL: https://codereview.chromium.org/641343002

Cr-Commit-Position: refs/heads/master@{#299092}
parent 05425887
...@@ -92,6 +92,8 @@ ...@@ -92,6 +92,8 @@
'shell/app/webkit_test_platform_support_win.cc', 'shell/app/webkit_test_platform_support_win.cc',
'shell/browser/ipc_echo_message_filter.cc', 'shell/browser/ipc_echo_message_filter.cc',
'shell/browser/ipc_echo_message_filter.h', 'shell/browser/ipc_echo_message_filter.h',
'shell/browser/layout_test/layout_test_browser_context.cc',
'shell/browser/layout_test/layout_test_browser_context.h',
'shell/browser/layout_test/layout_test_devtools_frontend.cc', 'shell/browser/layout_test/layout_test_devtools_frontend.cc',
'shell/browser/layout_test/layout_test_devtools_frontend.h', 'shell/browser/layout_test/layout_test_devtools_frontend.h',
'shell/browser/layout_test/layout_test_javascript_dialog_manager.cc', 'shell/browser/layout_test/layout_test_javascript_dialog_manager.cc',
......
...@@ -41,6 +41,8 @@ static_library("content_shell_lib") { ...@@ -41,6 +41,8 @@ static_library("content_shell_lib") {
"app/webkit_test_platform_support_win.cc", "app/webkit_test_platform_support_win.cc",
"browser/ipc_echo_message_filter.cc", "browser/ipc_echo_message_filter.cc",
"browser/ipc_echo_message_filter.h", "browser/ipc_echo_message_filter.h",
"browser/layout_test/layout_test_browser_context.cc",
"browser/layout_test/layout_test_browser_context.h",
"browser/layout_test/layout_test_devtools_frontend.cc", "browser/layout_test/layout_test_devtools_frontend.cc",
"browser/layout_test/layout_test_devtools_frontend.h", "browser/layout_test/layout_test_devtools_frontend.h",
"browser/layout_test/layout_test_javascript_dialog_manager.cc", "browser/layout_test/layout_test_javascript_dialog_manager.cc",
......
// Copyright 2014 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/layout_test/layout_test_browser_context.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "content/public/browser/resource_context.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
#include "content/shell/browser/shell_url_request_context_getter.h"
#if defined(OS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_LINUX)
#include "base/nix/xdg_util.h"
#elif defined(OS_MACOSX)
#include "base/base_paths_mac.h"
#endif
namespace content {
LayoutTestBrowserContext::LayoutTestBrowserContext(bool off_the_record,
net::NetLog* net_log)
: ShellBrowserContext(off_the_record, net_log) {
ignore_certificate_errors_ = true;
}
LayoutTestBrowserContext::~LayoutTestBrowserContext() {
}
DownloadManagerDelegate*
LayoutTestBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_.get()) {
download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
download_manager_delegate_->SetDownloadManager(
BrowserContext::GetDownloadManager(this));
// TODO(mkwst): We can avoid this bit in the future by defining a
// LayoutTestDownloadManagerDelegate.
download_manager_delegate_->SetDownloadBehaviorForTesting(
GetPath().Append(FILE_PATH_LITERAL("downloads")));
}
return download_manager_delegate_.get();
}
} // namespace content
// Copyright 2014 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_LAYOUT_TEST_BROWSER_CONTEXT_H_
#define CONTENT_SHELL_BROWSER_LAYOUT_TEST_BROWSER_CONTEXT_H_
#include "base/compiler_specific.h"
#include "content/shell/browser/shell_browser_context.h"
namespace net {
class NetLog;
}
namespace content {
class DownloadManagerDelegate;
class LayoutTestBrowserContext : public ShellBrowserContext {
public:
LayoutTestBrowserContext(bool off_the_record, net::NetLog* net_log);
virtual ~LayoutTestBrowserContext();
// BrowserContext implementation.
virtual DownloadManagerDelegate* GetDownloadManagerDelegate() override;
private:
DISALLOW_COPY_AND_ASSIGN(LayoutTestBrowserContext);
};
} // namespace content
#endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_BROWSER_CONTEXT_H_
...@@ -49,9 +49,9 @@ ShellBrowserContext::ShellResourceContext::GetRequestContext() { ...@@ -49,9 +49,9 @@ ShellBrowserContext::ShellResourceContext::GetRequestContext() {
ShellBrowserContext::ShellBrowserContext(bool off_the_record, ShellBrowserContext::ShellBrowserContext(bool off_the_record,
net::NetLog* net_log) net::NetLog* net_log)
: resource_context_(new ShellResourceContext), : resource_context_(new ShellResourceContext),
ignore_certificate_errors_(false),
off_the_record_(off_the_record), off_the_record_(off_the_record),
net_log_(net_log), net_log_(net_log),
ignore_certificate_errors_(false),
guest_manager_(NULL) { guest_manager_(NULL) {
InitWhileIOAllowed(); InitWhileIOAllowed();
} }
...@@ -65,10 +65,8 @@ ShellBrowserContext::~ShellBrowserContext() { ...@@ -65,10 +65,8 @@ ShellBrowserContext::~ShellBrowserContext() {
void ShellBrowserContext::InitWhileIOAllowed() { void ShellBrowserContext::InitWhileIOAllowed() {
CommandLine* cmd_line = CommandLine::ForCurrentProcess(); CommandLine* cmd_line = CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors) || if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
cmd_line->HasSwitch(switches::kDumpRenderTree)) {
ignore_certificate_errors_ = true; ignore_certificate_errors_ = true;
}
if (cmd_line->HasSwitch(switches::kContentShellDataPath)) { if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath); path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
return; return;
...@@ -106,16 +104,10 @@ bool ShellBrowserContext::IsOffTheRecord() const { ...@@ -106,16 +104,10 @@ bool ShellBrowserContext::IsOffTheRecord() const {
} }
DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() { DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
DownloadManager* manager = BrowserContext::GetDownloadManager(this);
if (!download_manager_delegate_.get()) { if (!download_manager_delegate_.get()) {
download_manager_delegate_.reset(new ShellDownloadManagerDelegate()); download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
download_manager_delegate_->SetDownloadManager(manager); download_manager_delegate_->SetDownloadManager(
CommandLine* cmd_line = CommandLine::ForCurrentProcess(); BrowserContext::GetDownloadManager(this));
if (cmd_line->HasSwitch(switches::kDumpRenderTree)) {
download_manager_delegate_->SetDownloadBehaviorForTesting(
path_.Append(FILE_PATH_LITERAL("downloads")));
}
} }
return download_manager_delegate_.get(); return download_manager_delegate_.get();
......
...@@ -95,19 +95,18 @@ class ShellBrowserContext : public BrowserContext { ...@@ -95,19 +95,18 @@ class ShellBrowserContext : public BrowserContext {
} }
scoped_ptr<ShellResourceContext> resource_context_; scoped_ptr<ShellResourceContext> resource_context_;
bool ignore_certificate_errors_;
scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_;
private: private:
// Performs initialization of the ShellBrowserContext while IO is still // Performs initialization of the ShellBrowserContext while IO is still
// allowed on the current thread. // allowed on the current thread.
void InitWhileIOAllowed(); void InitWhileIOAllowed();
bool off_the_record_; bool off_the_record_;
net::NetLog* net_log_; net::NetLog* net_log_;
bool ignore_certificate_errors_;
base::FilePath path_; base::FilePath path_;
BrowserPluginGuestManager* guest_manager_; BrowserPluginGuestManager* guest_manager_;
scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<ShellURLRequestContextGetter> url_request_getter_; scoped_refptr<ShellURLRequestContextGetter> url_request_getter_;
DISALLOW_COPY_AND_ASSIGN(ShellBrowserContext); DISALLOW_COPY_AND_ASSIGN(ShellBrowserContext);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h" #include "content/public/common/main_function_params.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/shell/browser/layout_test/layout_test_browser_context.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_devtools_delegate.h" #include "content/shell/browser/shell_devtools_delegate.h"
...@@ -128,9 +129,15 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { ...@@ -128,9 +129,15 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
} }
#endif #endif
net_log_.reset(new ShellNetLog("content_shell")); net_log_.reset(new ShellNetLog("content_shell"));
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
browser_context_.reset(new LayoutTestBrowserContext(false, net_log_.get()));
off_the_record_browser_context_.reset(
new LayoutTestBrowserContext(true, net_log_.get()));
} else {
browser_context_.reset(new ShellBrowserContext(false, net_log_.get())); browser_context_.reset(new ShellBrowserContext(false, net_log_.get()));
off_the_record_browser_context_.reset( off_the_record_browser_context_.reset(
new ShellBrowserContext(true, net_log_.get())); new ShellBrowserContext(true, net_log_.get()));
}
Shell::Initialize(); Shell::Initialize();
net::NetModule::SetResourceProvider(PlatformResourceProvider); net::NetModule::SetResourceProvider(PlatformResourceProvider);
......
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