| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 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: | |
| 7 // Flash | |
| 8 // Real | |
| 9 // QuickTime | |
| 10 // Windows Media Player | |
| 11 // -this includes both WMP plugins. npdsplay.dll is the older one that | |
| 12 // comes with XP. np-mswmp.dll can be downloaded from Microsoft and | |
| 13 // needs SP2 or Vista. | |
| 14 | |
| 15 #include "build/build_config.h" | |
| 16 | |
| 17 #if defined(OS_WIN) | |
| 18 #include <windows.h> | |
| 19 #include <shellapi.h> | |
| 20 #include <shlobj.h> | |
| 21 #include <comutil.h> | |
| 22 #endif | |
| 23 | |
| 24 #include <stdlib.h> | |
| 25 #include <string.h> | |
| 26 #include <memory.h> | |
| 27 | |
| 28 #include <string> | |
| 29 | |
| 30 #include "base/file_path.h" | |
| 31 #include "base/file_util.h" | |
| 32 #include "base/message_loop.h" | |
| 33 #include "base/path_service.h" | |
| 34 #include "base/test/test_timeouts.h" | |
| 35 #include "chrome/browser/plugin_download_helper.h" | |
| 36 #include "chrome/common/chrome_switches.h" | |
| 37 #include "chrome/common/chrome_paths.h" | |
| 38 #include "chrome/test/automation/automation_proxy.h" | |
| 39 #include "chrome/test/automation/tab_proxy.h" | |
| 40 #include "chrome/test/base/ui_test_utils.h" | |
| 41 #include "chrome/test/ui/ui_test.h" | |
| 42 #include "content/browser/net/url_request_mock_http_job.h" | |
| 43 #include "net/base/net_util.h" | |
| 44 #include "net/url_request/url_request_test_util.h" | |
| 45 #include "third_party/npapi/bindings/npapi.h" | |
| 46 #include "webkit/plugins/npapi/plugin_constants_win.h" | |
| 47 #include "webkit/plugins/npapi/plugin_list.h" | |
| 48 #include "webkit/plugins/plugin_switches.h" | |
| 49 | |
| 50 #if defined(OS_WIN) | |
| 51 #include "base/win/registry.h" | |
| 52 #endif | |
| 53 | |
| 54 class PluginTest : public UITest { | |
| 55 public: | |
| 56 // Generate the URL for testing a particular test. | |
| 57 // HTML for the tests is all located in test_directory\plugin\<testcase> | |
| 58 // Set |mock_http| to true to use mock HTTP server. | |
| 59 static GURL GetTestUrl(const std::string& test_case, | |
| 60 const std::string& query, | |
| 61 bool mock_http) { | |
| 62 static const FilePath::CharType kPluginPath[] = FILE_PATH_LITERAL("plugin"); | |
| 63 if (mock_http) { | |
| 64 FilePath plugin_path = FilePath(kPluginPath).AppendASCII(test_case); | |
| 65 GURL url = URLRequestMockHTTPJob::GetMockUrl(plugin_path); | |
| 66 if (!query.empty()) { | |
| 67 GURL::Replacements replacements; | |
| 68 replacements.SetQueryStr(query); | |
| 69 return url.ReplaceComponents(replacements); | |
| 70 } | |
| 71 return url; | |
| 72 } | |
| 73 | |
| 74 FilePath path; | |
| 75 PathService::Get(chrome::DIR_TEST_DATA, &path); | |
| 76 path = path.Append(kPluginPath).AppendASCII(test_case); | |
| 77 return ui_test_utils::GetFileUrlWithQuery(path, query); | |
| 78 } | |
| 79 | |
| 80 protected: | |
| 81 virtual void SetUp() { | |
| 82 #if defined(OS_WIN) | |
| 83 const testing::TestInfo* const test_info = | |
| 84 testing::UnitTest::GetInstance()->current_test_info(); | |
| 85 if (strcmp(test_info->name(), "MediaPlayerNew") == 0) { | |
| 86 // The installer adds our process names to the registry key below. Since | |
| 87 // the installer might not have run on this machine, add it manually. | |
| 88 base::win::RegKey regkey; | |
| 89 if (regkey.Open(HKEY_LOCAL_MACHINE, | |
| 90 L"Software\\Microsoft\\MediaPlayer\\ShimInclusionList", | |
| 91 KEY_WRITE) == ERROR_SUCCESS) { | |
| 92 regkey.CreateKey(L"CHROME.EXE", KEY_READ); | |
| 93 } | |
| 94 } else if (strcmp(test_info->name(), "MediaPlayerOld") == 0) { | |
| 95 // When testing the old WMP plugin, we need to force Chrome to not load | |
| 96 // the new plugin. | |
| 97 launch_arguments_.AppendSwitch(switches::kUseOldWMPPlugin); | |
| 98 } else if (strcmp(test_info->name(), "FlashSecurity") == 0) { | |
| 99 launch_arguments_.AppendSwitchASCII(switches::kTestSandbox, | |
| 100 "security_tests.dll"); | |
| 101 } | |
| 102 #endif // defined(OS_WIN) | |
| 103 | |
| 104 launch_arguments_.AppendSwitch(switches::kAllowOutdatedPlugins); | |
| 105 launch_arguments_.AppendSwitch(switches::kAlwaysAuthorizePlugins); | |
| 106 | |
| 107 UITest::SetUp(); | |
| 108 } | |
| 109 | |
| 110 void TestPlugin(const std::string& test_case, | |
| 111 const std::string& query, | |
| 112 int timeout, | |
| 113 bool mock_http) { | |
| 114 GURL url = GetTestUrl(test_case, query, mock_http); | |
| 115 NavigateToURL(url); | |
| 116 WaitForFinish(timeout, mock_http); | |
| 117 } | |
| 118 | |
| 119 // Waits for the test case to finish. | |
| 120 void WaitForFinish(const int wait_time, bool mock_http) { | |
| 121 static const char kTestCompleteCookie[] = "status"; | |
| 122 static const char kTestCompleteSuccess[] = "OK"; | |
| 123 | |
| 124 GURL url = GetTestUrl("done", "", mock_http); | |
| 125 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 126 | |
| 127 const std::string result = | |
| 128 WaitUntilCookieNonEmpty(tab, url, kTestCompleteCookie, wait_time); | |
| 129 ASSERT_EQ(kTestCompleteSuccess, result); | |
| 130 } | |
| 131 }; | |
| 132 | |
| 133 TEST_F(PluginTest, Flash) { | |
| 134 // Note: This does not work with the npwrapper on 64-bit Linux. Install the | |
| 135 // native 64-bit Flash to run the test. | |
| 136 // TODO(thestig) Update this list if we decide to only test against internal | |
| 137 // Flash plugin in the future? | |
| 138 std::string kFlashQuery = | |
| 139 #if defined(OS_WIN) | |
| 140 "npswf32.dll" | |
| 141 #elif defined(OS_MACOSX) | |
| 142 "Flash Player.plugin" | |
| 143 #elif defined(OS_POSIX) | |
| 144 "libflashplayer.so" | |
| 145 #endif | |
| 146 ; | |
| 147 TestPlugin("flash.html", kFlashQuery, | |
| 148 TestTimeouts::action_max_timeout_ms(), false); | |
| 149 } | |
| 150 | |
| 151 class ClickToPlayPluginTest : public PluginTest { | |
| 152 public: | |
| 153 ClickToPlayPluginTest() { | |
| 154 dom_automation_enabled_ = true; | |
| 155 } | |
| 156 }; | |
| 157 | |
| 158 TEST_F(ClickToPlayPluginTest, Flash) { | |
| 159 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
| 160 ASSERT_TRUE(browser.get()); | |
| 161 ASSERT_TRUE(browser->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 162 CONTENT_SETTING_BLOCK)); | |
| 163 | |
| 164 GURL url = GetTestUrl("flash-clicktoplay.html", "", true); | |
| 165 NavigateToURL(url); | |
| 166 | |
| 167 scoped_refptr<TabProxy> tab(browser->GetTab(0)); | |
| 168 ASSERT_TRUE(tab.get()); | |
| 169 | |
| 170 ASSERT_TRUE(tab->LoadBlockedPlugins()); | |
| 171 | |
| 172 WaitForFinish(TestTimeouts::action_max_timeout_ms(), true); | |
| 173 } | |
| 174 | |
| 175 TEST_F(ClickToPlayPluginTest, FlashDocument) { | |
| 176 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
| 177 ASSERT_TRUE(browser.get()); | |
| 178 ASSERT_TRUE(browser->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 179 CONTENT_SETTING_BLOCK)); | |
| 180 | |
| 181 scoped_refptr<TabProxy> tab(browser->GetTab(0)); | |
| 182 ASSERT_TRUE(tab.get()); | |
| 183 GURL url = GetTestUrl("js-invoker.swf", "callback=done", true); | |
| 184 NavigateToURL(url); | |
| 185 | |
| 186 // Inject the callback function into the HTML page generated by the browser. | |
| 187 ASSERT_TRUE(tab->ExecuteJavaScript("window.done = function() {" | |
| 188 " window.location = \"done.html\";" | |
| 189 "}")); | |
| 190 | |
| 191 ASSERT_TRUE(tab->LoadBlockedPlugins()); | |
| 192 | |
| 193 WaitForFinish(TestTimeouts::action_max_timeout_ms(), true); | |
| 194 } | |
| 195 | |
| 196 #if defined(OS_WIN) | |
| 197 // Windows only test | |
| 198 TEST_F(PluginTest, DISABLED_FlashSecurity) { | |
| 199 TestPlugin("flash.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
| 200 } | |
| 201 #endif // defined(OS_WIN) | |
| 202 | |
| 203 #if defined(OS_WIN) | |
| 204 // TODO(port) Port the following tests to platforms that have the required | |
| 205 // plugins. | |
| 206 // Flaky: http://crbug.com/55915 | |
| 207 TEST_F(PluginTest, FLAKY_Quicktime) { | |
| 208 TestPlugin("quicktime.html", "", | |
| 209 TestTimeouts::action_max_timeout_ms(), false); | |
| 210 } | |
| 211 | |
| 212 // Disabled - http://crbug.com/44662 | |
| 213 TEST_F(PluginTest, DISABLED_MediaPlayerNew) { | |
| 214 TestPlugin("wmp_new.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
| 215 } | |
| 216 | |
| 217 // http://crbug.com/4809 | |
| 218 TEST_F(PluginTest, DISABLED_MediaPlayerOld) { | |
| 219 TestPlugin("wmp_old.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
| 220 } | |
| 221 | |
| 222 // Disabled - http://crbug.com/44673 | |
| 223 TEST_F(PluginTest, DISABLED_Real) { | |
| 224 TestPlugin("real.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
| 225 } | |
| 226 | |
| 227 TEST_F(PluginTest, FlashOctetStream) { | |
| 228 TestPlugin("flash-octet-stream.html", "", | |
| 229 TestTimeouts::action_max_timeout_ms(), false); | |
| 230 } | |
| 231 | |
| 232 #if defined(OS_WIN) | |
| 233 // http://crbug.com/53926 | |
| 234 TEST_F(PluginTest, FLAKY_FlashLayoutWhilePainting) { | |
| 235 #else | |
| 236 TEST_F(PluginTest, FlashLayoutWhilePainting) { | |
| 237 #endif | |
| 238 TestPlugin("flash-layout-while-painting.html", "", | |
| 239 TestTimeouts::action_max_timeout_ms(), true); | |
| 240 } | |
| 241 | |
| 242 // http://crbug.com/8690 | |
| 243 TEST_F(PluginTest, DISABLED_Java) { | |
| 244 TestPlugin("Java.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
| 245 } | |
| 246 | |
| 247 TEST_F(PluginTest, Silverlight) { | |
| 248 TestPlugin("silverlight.html", "", | |
| 249 TestTimeouts::action_max_timeout_ms(), false); | |
| 250 } | |
| 251 | |
| 252 // This class provides functionality to test the plugin installer download | |
| 253 // file functionality. | |
| 254 class PluginInstallerDownloadTest | |
| 255 : public PluginDownloadUrlHelper::DownloadDelegate, | |
| 256 public testing::Test { | |
| 257 public: | |
| 258 PluginInstallerDownloadTest() | |
| 259 : success_(false), | |
| 260 download_helper_(NULL) {} | |
| 261 ~PluginInstallerDownloadTest() {} | |
| 262 | |
| 263 void Start() { | |
| 264 initial_download_path_ = PluginTest::GetTestUrl("flash.html", "", false); | |
| 265 download_helper_ = new PluginDownloadUrlHelper( | |
| 266 initial_download_path_.spec(), NULL, | |
| 267 static_cast<PluginDownloadUrlHelper::DownloadDelegate*>(this)); | |
| 268 download_helper_->InitiateDownload(new TestURLRequestContext); | |
| 269 | |
| 270 MessageLoop::current()->PostDelayedTask( | |
| 271 FROM_HERE, new MessageLoop::QuitTask, | |
| 272 TestTimeouts::action_max_timeout_ms()); | |
| 273 } | |
| 274 | |
| 275 virtual void OnDownloadCompleted(const FilePath& download_path, | |
| 276 bool success) { | |
| 277 success_ = success; | |
| 278 final_download_path_ = download_path; | |
| 279 MessageLoop::current()->Quit(); | |
| 280 download_helper_ = NULL; | |
| 281 } | |
| 282 | |
| 283 FilePath final_download_path() const { | |
| 284 return final_download_path_; | |
| 285 } | |
| 286 | |
| 287 FilePath initial_download_path() const { | |
| 288 return final_download_path_; | |
| 289 } | |
| 290 | |
| 291 bool success() const { | |
| 292 return success_; | |
| 293 } | |
| 294 | |
| 295 private: | |
| 296 FilePath final_download_path_; | |
| 297 PluginDownloadUrlHelper* download_helper_; | |
| 298 bool success_; | |
| 299 GURL initial_download_path_; | |
| 300 }; | |
| 301 | |
| 302 // This test validates that the plugin downloader downloads the specified file | |
| 303 // to a temporary path with the same file name. | |
| 304 TEST_F(PluginInstallerDownloadTest, PluginInstallerDownloadPathTest) { | |
| 305 MessageLoop loop(MessageLoop::TYPE_IO); | |
| 306 Start(); | |
| 307 loop.Run(); | |
| 308 | |
| 309 EXPECT_TRUE(success()); | |
| 310 EXPECT_TRUE(initial_download_path().BaseName().value() == | |
| 311 final_download_path().BaseName().value()); | |
| 312 } | |
| 313 #endif // defined(OS_WIN) | |
| OLD | NEW |