summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-25 14:08:51 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-25 14:08:51 +0000
commitfd3ad516a833d0cdb3f39dad28b03526d53e3ddd (patch)
tree986448c608d2c6012da9c1cc065657171a7854f2
parentb3909d5383516d114432751463f39eb639cb1cfa (diff)
downloadchromium_src-fd3ad516a833d0cdb3f39dad28b03526d53e3ddd.zip
chromium_src-fd3ad516a833d0cdb3f39dad28b03526d53e3ddd.tar.gz
chromium_src-fd3ad516a833d0cdb3f39dad28b03526d53e3ddd.tar.bz2
Relanding this patch with the compile fix for Visual studio 2005. The compiler gets
confused between the two Delegate classes URLRequest::Delegate and the PluginDownloadHelper::Delegate class. Renaming the latter seems to work Fix a regression introduced in the chrome plugin installer on Windows in revision 54316 which was to remove usages of GetTempDir. However the change failed to take into account that the file name which is used to perform the download eventually is shell executed on windows. In this case the download was performed on a temporary file which causes ShellExecute to put up a confirmation dialog asking the user to select the application for opening the file. Fix is to rename the temp file path to the desired file path on success. Fixes bug http://code.google.com/p/chromium/issues/detail?id=56746 Bug=56746 Test=Covered by plugin installer plugin test. TBR=jam Review URL: http://codereview.chromium.org/3453025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60577 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/plugin_download_helper.cc190
-rw-r--r--chrome/browser/plugin_download_helper.h80
-rw-r--r--chrome/browser/plugin_process_host.cc202
-rw-r--r--chrome/browser/plugin_process_host.h1
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/test/plugin/plugin_test.cpp151
6 files changed, 411 insertions, 215 deletions
diff --git a/chrome/browser/plugin_download_helper.cc b/chrome/browser/plugin_download_helper.cc
new file mode 100644
index 0000000..5f17725
--- /dev/null
+++ b/chrome/browser/plugin_download_helper.cc
@@ -0,0 +1,190 @@
+// Copyright (c) 2010 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/browser/plugin_download_helper.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+
+#include "base/file_util.h"
+#include "chrome/browser/net/url_request_tracking.h"
+#include "net/base/io_buffer.h"
+
+PluginDownloadUrlHelper::PluginDownloadUrlHelper(
+ const std::string& download_url,
+ int source_child_unique_id,
+ gfx::NativeWindow caller_window,
+ PluginDownloadUrlHelper::DownloadDelegate* delegate)
+ : download_file_request_(NULL),
+ download_file_buffer_(new net::IOBuffer(kDownloadFileBufferSize)),
+ download_file_caller_window_(caller_window),
+ download_url_(download_url),
+ download_source_child_unique_id_(source_child_unique_id),
+ delegate_(delegate) {
+ memset(download_file_buffer_->data(), 0, kDownloadFileBufferSize);
+ download_file_.reset(new net::FileStream());
+}
+
+PluginDownloadUrlHelper::~PluginDownloadUrlHelper() {
+ if (download_file_request_) {
+ delete download_file_request_;
+ download_file_request_ = NULL;
+ }
+}
+
+void PluginDownloadUrlHelper::InitiateDownload(
+ URLRequestContext* request_context) {
+ download_file_request_ = new URLRequest(GURL(download_url_), this);
+ chrome_browser_net::SetOriginProcessUniqueIDForRequest(
+ download_source_child_unique_id_, download_file_request_);
+ download_file_request_->set_context(request_context);
+ download_file_request_->Start();
+}
+
+void PluginDownloadUrlHelper::OnAuthRequired(
+ URLRequest* request,
+ net::AuthChallengeInfo* auth_info) {
+ URLRequest::Delegate::OnAuthRequired(request, auth_info);
+ DownloadCompletedHelper(false);
+}
+
+void PluginDownloadUrlHelper::OnSSLCertificateError(
+ URLRequest* request,
+ int cert_error,
+ net::X509Certificate* cert) {
+ URLRequest::Delegate::OnSSLCertificateError(request, cert_error, cert);
+ DownloadCompletedHelper(false);
+}
+
+void PluginDownloadUrlHelper::OnResponseStarted(URLRequest* request) {
+ if (!download_file_->IsOpen()) {
+ // This is safe because once the temp file has been safely created, an
+ // attacker can't drop a symlink etc into place.
+ file_util::CreateTemporaryFile(&download_file_path_);
+ download_file_->Open(download_file_path_,
+ base::PLATFORM_FILE_CREATE_ALWAYS |
+ base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE);
+ if (!download_file_->IsOpen()) {
+ NOTREACHED();
+ OnDownloadCompleted(request);
+ return;
+ }
+ }
+ if (!request->status().is_success()) {
+ OnDownloadCompleted(request);
+ } else {
+ // Initiate a read.
+ int bytes_read = 0;
+ if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
+ &bytes_read)) {
+ // If the error is not an IO pending, then we're done
+ // reading.
+ if (!request->status().is_io_pending()) {
+ OnDownloadCompleted(request);
+ }
+ } else if (bytes_read == 0) {
+ OnDownloadCompleted(request);
+ } else {
+ OnReadCompleted(request, bytes_read);
+ }
+ }
+}
+
+void PluginDownloadUrlHelper::OnReadCompleted(URLRequest* request,
+ int bytes_read) {
+ DCHECK(download_file_->IsOpen());
+
+ if (bytes_read == 0) {
+ OnDownloadCompleted(request);
+ return;
+ }
+
+ int request_bytes_read = bytes_read;
+
+ while (request->status().is_success()) {
+ int bytes_written = download_file_->Write(download_file_buffer_->data(),
+ request_bytes_read, NULL);
+ DCHECK((bytes_written < 0) || (bytes_written == request_bytes_read));
+
+ if ((bytes_written < 0) || (bytes_written != request_bytes_read)) {
+ DownloadCompletedHelper(false);
+ break;
+ }
+
+ // Start reading
+ request_bytes_read = 0;
+ if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
+ &request_bytes_read)) {
+ if (!request->status().is_io_pending()) {
+ // If the error is not an IO pending, then we're done
+ // reading.
+ OnDownloadCompleted(request);
+ }
+ break;
+ } else if (request_bytes_read == 0) {
+ OnDownloadCompleted(request);
+ break;
+ }
+ }
+}
+
+void PluginDownloadUrlHelper::OnDownloadCompleted(URLRequest* request) {
+ bool success = true;
+ if (!request->status().is_success()) {
+ success = false;
+ } else if (!download_file_->IsOpen()) {
+ success = false;
+ }
+
+ DownloadCompletedHelper(success);
+}
+
+void PluginDownloadUrlHelper::DownloadCompletedHelper(bool success) {
+ if (download_file_->IsOpen()) {
+ download_file_.reset();
+ }
+
+ if (success) {
+ FilePath new_download_file_path =
+ download_file_path_.DirName().AppendASCII(
+ download_file_request_->url().ExtractFileName());
+
+ file_util::Delete(new_download_file_path, false);
+
+ if (!file_util::ReplaceFileW(download_file_path_,
+ new_download_file_path)) {
+ DLOG(ERROR) << "Failed to rename file:"
+ << download_file_path_.value()
+ << " to file:"
+ << new_download_file_path.value();
+ } else {
+ download_file_path_ = new_download_file_path;
+ }
+ }
+
+ if (delegate_) {
+ delegate_->OnDownloadCompleted(download_file_path_, success);
+ } else {
+ std::wstring path = download_file_path_.value();
+ COPYDATASTRUCT download_file_data = {0};
+ download_file_data.cbData =
+ static_cast<unsigned long>((path.length() + 1) * sizeof(wchar_t));
+ download_file_data.lpData = const_cast<wchar_t *>(path.c_str());
+ download_file_data.dwData = success;
+
+ if (::IsWindow(download_file_caller_window_)) {
+ ::SendMessage(download_file_caller_window_, WM_COPYDATA, NULL,
+ reinterpret_cast<LPARAM>(&download_file_data));
+ }
+ }
+
+ // Don't access any members after this.
+ delete this;
+}
+
+#endif // OS_WIN
+
+
+
+
diff --git a/chrome/browser/plugin_download_helper.h b/chrome/browser/plugin_download_helper.h
new file mode 100644
index 0000000..5d1a243
--- /dev/null
+++ b/chrome/browser/plugin_download_helper.h
@@ -0,0 +1,80 @@
+// Copyright (c) 2010 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_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_
+#define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_
+#pragma once
+
+#include <string>
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include "base/file_path.h"
+#include "gfx/native_widget_types.h"
+#include "net/base/file_stream.h"
+#include "net/url_request/url_request.h"
+
+// The PluginDownloadUrlHelper is used to handle one download URL request
+// from the plugin. Each download request is handled by a new instance
+// of this class.
+class PluginDownloadUrlHelper : public URLRequest::Delegate {
+ static const int kDownloadFileBufferSize = 32768;
+ public:
+ // The delegate receives notification about the status of downloads
+ // initiated.
+ class DownloadDelegate {
+ public:
+ virtual ~DownloadDelegate() {}
+
+ virtual void OnDownloadCompleted(const FilePath& download_path,
+ bool success) {}
+ };
+
+ PluginDownloadUrlHelper(const std::string& download_url,
+ int source_pid, gfx::NativeWindow caller_window,
+ PluginDownloadUrlHelper::DownloadDelegate* delegate);
+ ~PluginDownloadUrlHelper();
+
+ void InitiateDownload(URLRequestContext* request_context);
+
+ // URLRequest::Delegate
+ virtual void OnAuthRequired(URLRequest* request,
+ net::AuthChallengeInfo* auth_info);
+ virtual void OnSSLCertificateError(URLRequest* request,
+ int cert_error,
+ net::X509Certificate* cert);
+ virtual void OnResponseStarted(URLRequest* request);
+ virtual void OnReadCompleted(URLRequest* request, int bytes_read);
+
+ void OnDownloadCompleted(URLRequest* request);
+
+ protected:
+ void DownloadCompletedHelper(bool success);
+
+ // The download file request initiated by the plugin.
+ URLRequest* download_file_request_;
+ // Handle to the downloaded file.
+ scoped_ptr<net::FileStream> download_file_;
+ // The full path of the downloaded file.
+ FilePath download_file_path_;
+ // The buffer passed off to URLRequest::Read.
+ scoped_refptr<net::IOBuffer> download_file_buffer_;
+ // TODO(port): this comment doesn't describe the situation on Posix.
+ // The window handle for sending the WM_COPYDATA notification,
+ // indicating that the download completed.
+ gfx::NativeWindow download_file_caller_window_;
+
+ std::string download_url_;
+ int download_source_child_unique_id_;
+
+ PluginDownloadUrlHelper::DownloadDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper);
+};
+
+#endif // OS_WIN
+
+#endif // CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_
+
+
diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc
index 8d99eab..2032a84 100644
--- a/chrome/browser/plugin_process_host.cc
+++ b/chrome/browser/plugin_process_host.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/chrome_plugin_browsing_context.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_request_tracking.h"
+#include "chrome/browser/plugin_download_helper.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
@@ -37,7 +38,6 @@
#include "gfx/native_widget_types.h"
#include "ipc/ipc_switches.h"
#include "net/base/cookie_store.h"
-#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
@@ -56,201 +56,6 @@ static const char kDefaultPluginFinderURL[] =
"https://dl-ssl.google.com/edgedl/chrome/plugins/plugins2.xml";
#if defined(OS_WIN)
-
-// The PluginDownloadUrlHelper is used to handle one download URL request
-// from the plugin. Each download request is handled by a new instance
-// of this class.
-class PluginDownloadUrlHelper : public URLRequest::Delegate {
- static const int kDownloadFileBufferSize = 32768;
- public:
- PluginDownloadUrlHelper(const std::string& download_url,
- int source_pid, gfx::NativeWindow caller_window);
- ~PluginDownloadUrlHelper();
-
- void InitiateDownload();
-
- // URLRequest::Delegate
- virtual void OnAuthRequired(URLRequest* request,
- net::AuthChallengeInfo* auth_info);
- virtual void OnSSLCertificateError(URLRequest* request,
- int cert_error,
- net::X509Certificate* cert);
- virtual void OnResponseStarted(URLRequest* request);
- virtual void OnReadCompleted(URLRequest* request, int bytes_read);
-
- void OnDownloadCompleted(URLRequest* request);
-
- protected:
- void DownloadCompletedHelper(bool success);
-
- // The download file request initiated by the plugin.
- URLRequest* download_file_request_;
- // Handle to the downloaded file.
- scoped_ptr<net::FileStream> download_file_;
- // The full path of the downloaded file.
- FilePath download_file_path_;
- // The buffer passed off to URLRequest::Read.
- scoped_refptr<net::IOBuffer> download_file_buffer_;
- // TODO(port): this comment doesn't describe the situation on Posix.
- // The window handle for sending the WM_COPYDATA notification,
- // indicating that the download completed.
- gfx::NativeWindow download_file_caller_window_;
-
- std::string download_url_;
- int download_source_child_unique_id_;
-
- DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper);
-};
-
-PluginDownloadUrlHelper::PluginDownloadUrlHelper(
- const std::string& download_url,
- int source_child_unique_id,
- gfx::NativeWindow caller_window)
- : download_file_request_(NULL),
- download_file_buffer_(new net::IOBuffer(kDownloadFileBufferSize)),
- download_file_caller_window_(caller_window),
- download_url_(download_url),
- download_source_child_unique_id_(source_child_unique_id) {
- DCHECK(::IsWindow(caller_window));
- memset(download_file_buffer_->data(), 0, kDownloadFileBufferSize);
- download_file_.reset(new net::FileStream());
-}
-
-PluginDownloadUrlHelper::~PluginDownloadUrlHelper() {
- if (download_file_request_) {
- delete download_file_request_;
- download_file_request_ = NULL;
- }
-}
-
-void PluginDownloadUrlHelper::InitiateDownload() {
- download_file_request_ = new URLRequest(GURL(download_url_), this);
- chrome_browser_net::SetOriginProcessUniqueIDForRequest(
- download_source_child_unique_id_, download_file_request_);
- download_file_request_->set_context(
- Profile::GetDefaultRequestContext()->GetURLRequestContext());
- download_file_request_->Start();
-}
-
-void PluginDownloadUrlHelper::OnAuthRequired(
- URLRequest* request,
- net::AuthChallengeInfo* auth_info) {
- URLRequest::Delegate::OnAuthRequired(request, auth_info);
- DownloadCompletedHelper(false);
-}
-
-void PluginDownloadUrlHelper::OnSSLCertificateError(
- URLRequest* request,
- int cert_error,
- net::X509Certificate* cert) {
- URLRequest::Delegate::OnSSLCertificateError(request, cert_error, cert);
- DownloadCompletedHelper(false);
-}
-
-void PluginDownloadUrlHelper::OnResponseStarted(URLRequest* request) {
- if (!download_file_->IsOpen()) {
- // This is safe because once the temp file has been safely created, an
- // attacker can't drop a symlink etc into place.
- file_util::CreateTemporaryFile(&download_file_path_);
- download_file_->Open(download_file_path_,
- base::PLATFORM_FILE_CREATE_ALWAYS |
- base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE);
- if (!download_file_->IsOpen()) {
- NOTREACHED();
- OnDownloadCompleted(request);
- return;
- }
- }
- if (!request->status().is_success()) {
- OnDownloadCompleted(request);
- } else {
- // Initiate a read.
- int bytes_read = 0;
- if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
- &bytes_read)) {
- // If the error is not an IO pending, then we're done
- // reading.
- if (!request->status().is_io_pending()) {
- OnDownloadCompleted(request);
- }
- } else if (bytes_read == 0) {
- OnDownloadCompleted(request);
- } else {
- OnReadCompleted(request, bytes_read);
- }
- }
-}
-
-void PluginDownloadUrlHelper::OnReadCompleted(URLRequest* request,
- int bytes_read) {
- DCHECK(download_file_->IsOpen());
-
- if (bytes_read == 0) {
- OnDownloadCompleted(request);
- return;
- }
-
- int request_bytes_read = bytes_read;
-
- while (request->status().is_success()) {
- int bytes_written = download_file_->Write(download_file_buffer_->data(),
- request_bytes_read, NULL);
- DCHECK((bytes_written < 0) || (bytes_written == request_bytes_read));
-
- if ((bytes_written < 0) || (bytes_written != request_bytes_read)) {
- DownloadCompletedHelper(false);
- break;
- }
-
- // Start reading
- request_bytes_read = 0;
- if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
- &request_bytes_read)) {
- if (!request->status().is_io_pending()) {
- // If the error is not an IO pending, then we're done
- // reading.
- OnDownloadCompleted(request);
- }
- break;
- } else if (request_bytes_read == 0) {
- OnDownloadCompleted(request);
- break;
- }
- }
-}
-
-void PluginDownloadUrlHelper::OnDownloadCompleted(URLRequest* request) {
- bool success = true;
- if (!request->status().is_success()) {
- success = false;
- } else if (!download_file_->IsOpen()) {
- success = false;
- }
-
- DownloadCompletedHelper(success);
-}
-
-void PluginDownloadUrlHelper::DownloadCompletedHelper(bool success) {
- if (download_file_->IsOpen()) {
- download_file_.reset();
- }
-
- std::wstring path = download_file_path_.value();
- COPYDATASTRUCT download_file_data = {0};
- download_file_data.cbData =
- static_cast<unsigned long>((path.length() + 1) * sizeof(wchar_t));
- download_file_data.lpData = const_cast<wchar_t *>(path.c_str());
- download_file_data.dwData = success;
-
- if (::IsWindow(download_file_caller_window_)) {
- ::SendMessage(download_file_caller_window_, WM_COPYDATA, NULL,
- reinterpret_cast<LPARAM>(&download_file_data));
- }
-
- // Don't access any members after this.
- delete this;
-}
-
void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) {
// The window is destroyed at this point, we just care about its parent, which
// is the intermediate window we created.
@@ -267,8 +72,9 @@ void PluginProcessHost::OnDownloadUrl(const std::string& url,
int source_pid,
gfx::NativeWindow caller_window) {
PluginDownloadUrlHelper* download_url_helper =
- new PluginDownloadUrlHelper(url, source_pid, caller_window);
- download_url_helper->InitiateDownload();
+ new PluginDownloadUrlHelper(url, source_pid, caller_window, NULL);
+ download_url_helper->InitiateDownload(
+ Profile::GetDefaultRequestContext()->GetURLRequestContext());
}
void PluginProcessHost::AddWindow(HWND window) {
diff --git a/chrome/browser/plugin_process_host.h b/chrome/browser/plugin_process_host.h
index a632308..d7c278e 100644
--- a/chrome/browser/plugin_process_host.h
+++ b/chrome/browser/plugin_process_host.h
@@ -18,7 +18,6 @@
#include "chrome/browser/browser_child_process_host.h"
#include "chrome/browser/net/resolve_proxy_msg_helper.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
-#include "gfx/native_widget_types.h"
#include "ipc/ipc_channel_handle.h"
#include "webkit/glue/plugins/webplugininfo.h"
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 0d57944..9740913 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2235,6 +2235,8 @@
'browser/platform_util_common_linux.cc',
'browser/platform_util_mac.mm',
'browser/platform_util_win.cc',
+ 'browser/plugin_download_helper.cc',
+ 'browser/plugin_download_helper.h',
'browser/plugin_exceptions_table_model.cc',
'browser/plugin_exceptions_table_model.h',
'browser/plugin_installer.cc',
diff --git a/chrome/test/plugin/plugin_test.cpp b/chrome/test/plugin/plugin_test.cpp
index aaf2e37..3d0a2ed 100644
--- a/chrome/test/plugin/plugin_test.cpp
+++ b/chrome/test/plugin/plugin_test.cpp
@@ -29,13 +29,23 @@
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/message_loop.h"
#include "base/path_service.h"
#include "chrome/browser/net/url_request_mock_http_job.h"
+#include "chrome/browser/plugin_download_helper.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/ui/ui_test.h"
+#include "net/base/capturing_net_log.h"
+#include "net/base/host_resolver.h"
#include "net/base/net_util.h"
+#include "net/base/ssl_config_service_defaults.h"
+#include "net/http/http_auth_handler_factory.h"
+#include "net/http/http_cache.h"
+#include "net/http/http_network_layer.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_status.h"
#include "third_party/npapi/bindings/npapi.h"
#include "webkit/glue/plugins/plugin_constants_win.h"
#include "webkit/glue/plugins/plugin_list.h"
@@ -45,6 +55,23 @@
#endif
class PluginTest : public UITest {
+ public:
+ // Generate the URL for testing a particular test.
+ // HTML for the tests is all located in test_directory\plugin\<testcase>
+ // Set |mock_http| to true to use mock HTTP server.
+ static GURL GetTestUrl(const std::string &test_case, bool mock_http) {
+ static const FilePath::CharType kPluginPath[] = FILE_PATH_LITERAL("plugin");
+ if (mock_http) {
+ FilePath plugin_path = FilePath(kPluginPath).AppendASCII(test_case);
+ return URLRequestMockHTTPJob::GetMockUrl(plugin_path);
+ }
+
+ FilePath path;
+ PathService::Get(chrome::DIR_TEST_DATA, &path);
+ path = path.Append(kPluginPath).AppendASCII(test_case);
+ return net::FilePathToFileURL(path);
+ }
+
protected:
#if defined(OS_WIN)
virtual void SetUp() {
@@ -80,22 +107,6 @@ class PluginTest : public UITest {
WaitForFinish(timeout, mock_http);
}
- // Generate the URL for testing a particular test.
- // HTML for the tests is all located in test_directory\plugin\<testcase>
- // Set |mock_http| to true to use mock HTTP server.
- GURL GetTestUrl(const std::string &test_case, bool mock_http) {
- static const FilePath::CharType kPluginPath[] = FILE_PATH_LITERAL("plugin");
- if (mock_http) {
- FilePath plugin_path = FilePath(kPluginPath).AppendASCII(test_case);
- return URLRequestMockHTTPJob::GetMockUrl(plugin_path);
- }
-
- FilePath path;
- PathService::Get(chrome::DIR_TEST_DATA, &path);
- path = path.Append(kPluginPath).AppendASCII(test_case);
- return net::FilePathToFileURL(path);
- }
-
// Waits for the test case to finish.
void WaitForFinish(const int wait_time, bool mock_http) {
static const char kTestCompleteCookie[] = "status";
@@ -183,4 +194,112 @@ TEST_F(PluginTest, DISABLED_Java) {
TEST_F(PluginTest, Silverlight) {
TestPlugin("silverlight.html", action_max_timeout_ms(), false);
}
+
+// This class provides functionality to test the plugin installer download
+// file functionality.
+class PluginInstallerDownloadTest
+ : public PluginDownloadUrlHelper::DownloadDelegate,
+ public testing::Test {
+ public:
+ // This class provides HTTP request context information for the downloads.
+ class UploadRequestContext : public URLRequestContext {
+ public:
+ UploadRequestContext() {
+ Initialize();
+ }
+
+ ~UploadRequestContext() {
+ DLOG(INFO) << __FUNCTION__;
+ delete http_transaction_factory_;
+ delete http_auth_handler_factory_;
+ }
+
+ void Initialize() {
+ host_resolver_ =
+ net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
+ NULL);
+ net::ProxyConfigService* proxy_config_service =
+ net::ProxyService::CreateSystemProxyConfigService(NULL, NULL);
+ DCHECK(proxy_config_service);
+
+ const size_t kNetLogBound = 50u;
+ net_log_.reset(new net::CapturingNetLog(kNetLogBound));
+
+ proxy_service_ = net::ProxyService::Create(proxy_config_service, false, 0,
+ this, net_log_.get(),
+ MessageLoop::current());
+ DCHECK(proxy_service_);
+
+ ssl_config_service_ = new net::SSLConfigServiceDefaults;
+ http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault();
+ http_transaction_factory_ = new net::HttpCache(
+ net::HttpNetworkLayer::CreateFactory(host_resolver_,
+ proxy_service_,
+ ssl_config_service_,
+ http_auth_handler_factory_,
+ network_delegate_,
+ NULL),
+ net::HttpCache::DefaultBackend::InMemory(0));
+ }
+
+ private:
+ scoped_ptr<net::NetLog> net_log_;
+ scoped_ptr<net::URLSecurityManager> url_security_manager_;
+ };
+
+ PluginInstallerDownloadTest()
+ : success_(false),
+ download_helper_(NULL) {}
+ ~PluginInstallerDownloadTest() {}
+
+ void Start() {
+ initial_download_path_ = PluginTest::GetTestUrl("flash.html", false);
+ download_helper_ = new PluginDownloadUrlHelper(
+ initial_download_path_.spec(), base::GetCurrentProcId(), NULL,
+ static_cast<PluginDownloadUrlHelper::DownloadDelegate*>(this));
+ download_helper_->InitiateDownload(new UploadRequestContext);
+
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, new MessageLoop::QuitTask,
+ TestTimeouts::action_max_timeout_ms());
+ }
+
+ virtual void OnDownloadCompleted(const FilePath& download_path,
+ bool success) {
+ success_ = success;
+ final_download_path_ = download_path;
+ MessageLoop::current()->Quit();
+ download_helper_ = NULL;
+ }
+
+ FilePath final_download_path() const {
+ return final_download_path_;
+ }
+
+ FilePath initial_download_path() const {
+ return final_download_path_;
+ }
+
+ bool success() const {
+ return success_;
+ }
+
+ private:
+ FilePath final_download_path_;
+ PluginDownloadUrlHelper* download_helper_;
+ bool success_;
+ GURL initial_download_path_;
+};
+
+// This test validates that the plugin downloader downloads the specified file
+// to a temporary path with the same file name.
+TEST_F(PluginInstallerDownloadTest, PluginInstallerDownloadPathTest) {
+ MessageLoop loop(MessageLoop::TYPE_IO);
+ Start();
+ loop.Run();
+
+ EXPECT_TRUE(success());
+ EXPECT_TRUE(initial_download_path().BaseName().value() ==
+ final_download_path().BaseName().value());
+}
#endif // defined(OS_WIN)