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

Content Shell: Introduce LayoutTestDownloadManagerDelegate.

This patch moves the DRT-specific bits of ShellDownloadManagerDelegate
into a new layout-test-only subclass.

BUG=420994

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

Cr-Commit-Position: refs/heads/master@{#299107}
parent 4015690f
...@@ -94,6 +94,8 @@ ...@@ -94,6 +94,8 @@
'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.cc',
'shell/browser/layout_test/layout_test_browser_context.h', 'shell/browser/layout_test/layout_test_browser_context.h',
'shell/browser/layout_test/layout_test_download_manager_delegate.cc',
'shell/browser/layout_test/layout_test_download_manager_delegate.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',
......
...@@ -43,6 +43,8 @@ static_library("content_shell_lib") { ...@@ -43,6 +43,8 @@ static_library("content_shell_lib") {
"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.cc",
"browser/layout_test/layout_test_browser_context.h", "browser/layout_test/layout_test_browser_context.h",
"browser/layout_test/layout_test_download_manager_delegate.cc",
"browser/layout_test/layout_test_download_manager_delegate.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",
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_context.h"
#include "content/shell/browser/shell_download_manager_delegate.h" #include "content/shell/browser/layout_test/layout_test_download_manager_delegate.h"
#include "content/shell/browser/shell_url_request_context_getter.h" #include "content/shell/browser/shell_url_request_context_getter.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -35,11 +35,9 @@ LayoutTestBrowserContext::~LayoutTestBrowserContext() { ...@@ -35,11 +35,9 @@ LayoutTestBrowserContext::~LayoutTestBrowserContext() {
DownloadManagerDelegate* DownloadManagerDelegate*
LayoutTestBrowserContext::GetDownloadManagerDelegate() { LayoutTestBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_.get()) { if (!download_manager_delegate_.get()) {
download_manager_delegate_.reset(new ShellDownloadManagerDelegate()); download_manager_delegate_.reset(new LayoutTestDownloadManagerDelegate());
download_manager_delegate_->SetDownloadManager( download_manager_delegate_->SetDownloadManager(
BrowserContext::GetDownloadManager(this)); BrowserContext::GetDownloadManager(this));
// TODO(mkwst): We can avoid this bit in the future by defining a
// LayoutTestDownloadManagerDelegate.
download_manager_delegate_->SetDownloadBehaviorForTesting( download_manager_delegate_->SetDownloadBehaviorForTesting(
GetPath().Append(FILE_PATH_LITERAL("downloads"))); GetPath().Append(FILE_PATH_LITERAL("downloads")));
} }
......
// 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_download_manager_delegate.h"
#if defined(OS_WIN)
#include <windows.h>
#include <commdlg.h>
#endif
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
#include "content/shell/browser/webkit_test_controller.h"
#include "net/base/filename_util.h"
#if defined(OS_WIN)
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#endif
namespace content {
LayoutTestDownloadManagerDelegate::LayoutTestDownloadManagerDelegate()
: ShellDownloadManagerDelegate() {}
LayoutTestDownloadManagerDelegate::~LayoutTestDownloadManagerDelegate(){
}
bool LayoutTestDownloadManagerDelegate::ShouldOpenDownload(
DownloadItem* item,
const DownloadOpenDelayedCallback& callback) {
if (WebKitTestController::Get()->IsMainWindow(item->GetWebContents()) &&
item->GetMimeType() == "text/html") {
WebKitTestController::Get()->OpenURL(
net::FilePathToFileURL(item->GetFullPath()));
}
return true;
}
} // 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_LAYOUT_TEST_DOWNLOAD_MANAGER_DELEGATE_H_
#define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_DOWNLOAD_MANAGER_DELEGATE_H_
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
namespace content {
class DownloadItem;
class LayoutTestDownloadManagerDelegate : public ShellDownloadManagerDelegate {
public:
LayoutTestDownloadManagerDelegate();
virtual ~LayoutTestDownloadManagerDelegate();
// ShellDownloadManagerDelegate implementation.
virtual bool ShouldOpenDownload(
DownloadItem* item,
const DownloadOpenDelayedCallback& callback) override;
private:
DISALLOW_COPY_AND_ASSIGN(LayoutTestDownloadManagerDelegate);
};
} // namespace content
#endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_DOWNLOAD_MANAGER_DELEGATE_H_
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/shell/browser/webkit_test_controller.h"
#include "content/shell/common/shell_switches.h" #include "content/shell/common/shell_switches.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
...@@ -98,12 +97,6 @@ bool ShellDownloadManagerDelegate::DetermineDownloadTarget( ...@@ -98,12 +97,6 @@ bool ShellDownloadManagerDelegate::DetermineDownloadTarget(
bool ShellDownloadManagerDelegate::ShouldOpenDownload( bool ShellDownloadManagerDelegate::ShouldOpenDownload(
DownloadItem* item, DownloadItem* item,
const DownloadOpenDelayedCallback& callback) { const DownloadOpenDelayedCallback& callback) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree) &&
WebKitTestController::Get()->IsMainWindow(item->GetWebContents()) &&
item->GetMimeType() == "text/html") {
WebKitTestController::Get()->OpenURL(
net::FilePathToFileURL(item->GetFullPath()));
}
return true; return true;
} }
......
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