Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: chrome/test/plugin/plugin_test.cpp

Issue 3453025: Relanding this patch with the compile fix for Visual studio 2005. The compile... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_browser.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Tests for the top plugins to catch regressions in our plugin host code, as 5 // Tests for the top plugins to catch regressions in our plugin host code, as
6 // well as in the out of process code. Currently this tests: 6 // well as in the out of process code. Currently this tests:
7 // Flash 7 // Flash
8 // Real 8 // Real
9 // QuickTime 9 // QuickTime
10 // Windows Media Player 10 // Windows Media Player
(...skipping 11 matching lines...) Expand all
22 #endif 22 #endif
23 23
24 #include <stdlib.h> 24 #include <stdlib.h>
25 #include <string.h> 25 #include <string.h>
26 #include <memory.h> 26 #include <memory.h>
27 27
28 #include <string> 28 #include <string>
29 29
30 #include "base/file_path.h" 30 #include "base/file_path.h"
31 #include "base/file_util.h" 31 #include "base/file_util.h"
32 #include "base/message_loop.h"
32 #include "base/path_service.h" 33 #include "base/path_service.h"
33 #include "chrome/browser/net/url_request_mock_http_job.h" 34 #include "chrome/browser/net/url_request_mock_http_job.h"
35 #include "chrome/browser/plugin_download_helper.h"
34 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/chrome_paths.h" 37 #include "chrome/common/chrome_paths.h"
36 #include "chrome/test/automation/tab_proxy.h" 38 #include "chrome/test/automation/tab_proxy.h"
37 #include "chrome/test/ui/ui_test.h" 39 #include "chrome/test/ui/ui_test.h"
40 #include "net/base/capturing_net_log.h"
41 #include "net/base/host_resolver.h"
38 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
43 #include "net/base/ssl_config_service_defaults.h"
44 #include "net/http/http_auth_handler_factory.h"
45 #include "net/http/http_cache.h"
46 #include "net/http/http_network_layer.h"
47 #include "net/url_request/url_request_context.h"
48 #include "net/url_request/url_request_status.h"
39 #include "third_party/npapi/bindings/npapi.h" 49 #include "third_party/npapi/bindings/npapi.h"
40 #include "webkit/glue/plugins/plugin_constants_win.h" 50 #include "webkit/glue/plugins/plugin_constants_win.h"
41 #include "webkit/glue/plugins/plugin_list.h" 51 #include "webkit/glue/plugins/plugin_list.h"
42 52
43 #if defined(OS_WIN) 53 #if defined(OS_WIN)
44 #include "base/registry.h" 54 #include "base/registry.h"
45 #endif 55 #endif
46 56
47 class PluginTest : public UITest { 57 class PluginTest : public UITest {
58 public:
59 // Generate the URL for testing a particular test.
60 // HTML for the tests is all located in test_directory\plugin\<testcase>
61 // Set |mock_http| to true to use mock HTTP server.
62 static GURL GetTestUrl(const std::string &test_case, bool mock_http) {
63 static const FilePath::CharType kPluginPath[] = FILE_PATH_LITERAL("plugin");
64 if (mock_http) {
65 FilePath plugin_path = FilePath(kPluginPath).AppendASCII(test_case);
66 return URLRequestMockHTTPJob::GetMockUrl(plugin_path);
67 }
68
69 FilePath path;
70 PathService::Get(chrome::DIR_TEST_DATA, &path);
71 path = path.Append(kPluginPath).AppendASCII(test_case);
72 return net::FilePathToFileURL(path);
73 }
74
48 protected: 75 protected:
49 #if defined(OS_WIN) 76 #if defined(OS_WIN)
50 virtual void SetUp() { 77 virtual void SetUp() {
51 const testing::TestInfo* const test_info = 78 const testing::TestInfo* const test_info =
52 testing::UnitTest::GetInstance()->current_test_info(); 79 testing::UnitTest::GetInstance()->current_test_info();
53 if (strcmp(test_info->name(), "MediaPlayerNew") == 0) { 80 if (strcmp(test_info->name(), "MediaPlayerNew") == 0) {
54 // The installer adds our process names to the registry key below. Since 81 // The installer adds our process names to the registry key below. Since
55 // the installer might not have run on this machine, add it manually. 82 // the installer might not have run on this machine, add it manually.
56 RegKey regkey; 83 RegKey regkey;
57 if (regkey.Open(HKEY_LOCAL_MACHINE, 84 if (regkey.Open(HKEY_LOCAL_MACHINE,
(...skipping 15 matching lines...) Expand all
73 #endif // defined(OS_WIN) 100 #endif // defined(OS_WIN)
74 101
75 void TestPlugin(const std::string& test_case, 102 void TestPlugin(const std::string& test_case,
76 int timeout, 103 int timeout,
77 bool mock_http) { 104 bool mock_http) {
78 GURL url = GetTestUrl(test_case, mock_http); 105 GURL url = GetTestUrl(test_case, mock_http);
79 NavigateToURL(url); 106 NavigateToURL(url);
80 WaitForFinish(timeout, mock_http); 107 WaitForFinish(timeout, mock_http);
81 } 108 }
82 109
83 // Generate the URL for testing a particular test.
84 // HTML for the tests is all located in test_directory\plugin\<testcase>
85 // Set |mock_http| to true to use mock HTTP server.
86 GURL GetTestUrl(const std::string &test_case, bool mock_http) {
87 static const FilePath::CharType kPluginPath[] = FILE_PATH_LITERAL("plugin");
88 if (mock_http) {
89 FilePath plugin_path = FilePath(kPluginPath).AppendASCII(test_case);
90 return URLRequestMockHTTPJob::GetMockUrl(plugin_path);
91 }
92
93 FilePath path;
94 PathService::Get(chrome::DIR_TEST_DATA, &path);
95 path = path.Append(kPluginPath).AppendASCII(test_case);
96 return net::FilePathToFileURL(path);
97 }
98
99 // Waits for the test case to finish. 110 // Waits for the test case to finish.
100 void WaitForFinish(const int wait_time, bool mock_http) { 111 void WaitForFinish(const int wait_time, bool mock_http) {
101 static const char kTestCompleteCookie[] = "status"; 112 static const char kTestCompleteCookie[] = "status";
102 static const char kTestCompleteSuccess[] = "OK"; 113 static const char kTestCompleteSuccess[] = "OK";
103 114
104 GURL url = GetTestUrl("done", mock_http); 115 GURL url = GetTestUrl("done", mock_http);
105 scoped_refptr<TabProxy> tab(GetActiveTab()); 116 scoped_refptr<TabProxy> tab(GetActiveTab());
106 117
107 const std::string result = 118 const std::string result =
108 WaitUntilCookieNonEmpty(tab, url, kTestCompleteCookie, wait_time); 119 WaitUntilCookieNonEmpty(tab, url, kTestCompleteCookie, wait_time);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 187 }
177 188
178 // http://crbug.com/8690 189 // http://crbug.com/8690
179 TEST_F(PluginTest, DISABLED_Java) { 190 TEST_F(PluginTest, DISABLED_Java) {
180 TestPlugin("Java.html", action_max_timeout_ms(), false); 191 TestPlugin("Java.html", action_max_timeout_ms(), false);
181 } 192 }
182 193
183 TEST_F(PluginTest, Silverlight) { 194 TEST_F(PluginTest, Silverlight) {
184 TestPlugin("silverlight.html", action_max_timeout_ms(), false); 195 TestPlugin("silverlight.html", action_max_timeout_ms(), false);
185 } 196 }
197
198 // This class provides functionality to test the plugin installer download
199 // file functionality.
200 class PluginInstallerDownloadTest
201 : public PluginDownloadUrlHelper::DownloadDelegate,
202 public testing::Test {
203 public:
204 // This class provides HTTP request context information for the downloads.
205 class UploadRequestContext : public URLRequestContext {
206 public:
207 UploadRequestContext() {
208 Initialize();
209 }
210
211 ~UploadRequestContext() {
212 DLOG(INFO) << __FUNCTION__;
213 delete http_transaction_factory_;
214 delete http_auth_handler_factory_;
215 }
216
217 void Initialize() {
218 host_resolver_ =
219 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
220 NULL);
221 net::ProxyConfigService* proxy_config_service =
222 net::ProxyService::CreateSystemProxyConfigService(NULL, NULL);
223 DCHECK(proxy_config_service);
224
225 const size_t kNetLogBound = 50u;
226 net_log_.reset(new net::CapturingNetLog(kNetLogBound));
227
228 proxy_service_ = net::ProxyService::Create(proxy_config_service, false, 0,
229 this, net_log_.get(),
230 MessageLoop::current());
231 DCHECK(proxy_service_);
232
233 ssl_config_service_ = new net::SSLConfigServiceDefaults;
234 http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault();
235 http_transaction_factory_ = new net::HttpCache(
236 net::HttpNetworkLayer::CreateFactory(host_resolver_,
237 proxy_service_,
238 ssl_config_service_,
239 http_auth_handler_factory_,
240 network_delegate_,
241 NULL),
242 net::HttpCache::DefaultBackend::InMemory(0));
243 }
244
245 private:
246 scoped_ptr<net::NetLog> net_log_;
247 scoped_ptr<net::URLSecurityManager> url_security_manager_;
248 };
249
250 PluginInstallerDownloadTest()
251 : success_(false),
252 download_helper_(NULL) {}
253 ~PluginInstallerDownloadTest() {}
254
255 void Start() {
256 initial_download_path_ = PluginTest::GetTestUrl("flash.html", false);
257 download_helper_ = new PluginDownloadUrlHelper(
258 initial_download_path_.spec(), base::GetCurrentProcId(), NULL,
259 static_cast<PluginDownloadUrlHelper::DownloadDelegate*>(this));
260 download_helper_->InitiateDownload(new UploadRequestContext);
261
262 MessageLoop::current()->PostDelayedTask(
263 FROM_HERE, new MessageLoop::QuitTask,
264 TestTimeouts::action_max_timeout_ms());
265 }
266
267 virtual void OnDownloadCompleted(const FilePath& download_path,
268 bool success) {
269 success_ = success;
270 final_download_path_ = download_path;
271 MessageLoop::current()->Quit();
272 download_helper_ = NULL;
273 }
274
275 FilePath final_download_path() const {
276 return final_download_path_;
277 }
278
279 FilePath initial_download_path() const {
280 return final_download_path_;
281 }
282
283 bool success() const {
284 return success_;
285 }
286
287 private:
288 FilePath final_download_path_;
289 PluginDownloadUrlHelper* download_helper_;
290 bool success_;
291 GURL initial_download_path_;
292 };
293
294 // This test validates that the plugin downloader downloads the specified file
295 // to a temporary path with the same file name.
296 TEST_F(PluginInstallerDownloadTest, PluginInstallerDownloadPathTest) {
297 MessageLoop loop(MessageLoop::TYPE_IO);
298 Start();
299 loop.Run();
300
301 EXPECT_TRUE(success());
302 EXPECT_TRUE(initial_download_path().BaseName().value() ==
303 final_download_path().BaseName().value());
304 }
186 #endif // defined(OS_WIN) 305 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « chrome/chrome_browser.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698