diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-25 08:41:26 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-25 08:41:26 +0000 |
commit | b5654bbbc18aadc3572b3c41c0e04e46cc094b89 (patch) | |
tree | 1d3106bee8aa2f8581316e9d533e2c8d2b7d01b2 /chrome/test/plugin | |
parent | 4c78276ddaaf22b6842f46c62c8ff82f56b912da (diff) | |
download | chromium_src-b5654bbbc18aadc3572b3c41c0e04e46cc094b89.zip chromium_src-b5654bbbc18aadc3572b3c41c0e04e46cc094b89.tar.gz chromium_src-b5654bbbc18aadc3572b3c41c0e04e46cc094b89.tar.bz2 |
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.
Review URL: http://codereview.chromium.org/3432028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60574 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/plugin')
-rw-r--r-- | chrome/test/plugin/plugin_test.cpp | 150 |
1 files changed, 134 insertions, 16 deletions
diff --git a/chrome/test/plugin/plugin_test.cpp b/chrome/test/plugin/plugin_test.cpp index aaf2e37..7d6d870 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,111 @@ 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::Delegate, + 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::Delegate*>(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) |