OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_util.h" | |
31 #include "base/path_service.h" | |
32 #include "base/test/test_timeouts.h" | |
33 #include "chrome/common/chrome_switches.h" | |
34 #include "chrome/common/chrome_paths.h" | |
35 #include "chrome/test/automation/automation_proxy.h" | |
36 #include "chrome/test/automation/tab_proxy.h" | |
37 #include "chrome/test/base/ui_test_utils.h" | |
38 #include "chrome/test/ui/ui_test.h" | |
39 #include "content/test/net/url_request_mock_http_job.h" | |
40 #include "net/base/net_util.h" | |
41 #include "third_party/npapi/bindings/npapi.h" | |
42 #include "webkit/plugins/npapi/plugin_constants_win.h" | |
43 #include "webkit/plugins/npapi/plugin_list.h" | |
44 #include "webkit/plugins/plugin_switches.h" | |
45 | |
46 #if defined(OS_WIN) | |
47 #include "base/win/registry.h" | |
48 #endif | |
49 | |
50 class PluginTest : public UITest { | |
51 public: | |
52 // Generate the URL for testing a particular test. | |
53 // HTML for the tests is all located in test_directory\plugin\<testcase> | |
54 // Set |mock_http| to true to use mock HTTP server. | |
55 static GURL GetTestUrl(const std::string& test_case, | |
56 const std::string& query, | |
57 bool mock_http) { | |
58 static const FilePath::CharType kPluginPath[] = FILE_PATH_LITERAL("plugin"); | |
59 if (mock_http) { | |
60 FilePath plugin_path = FilePath(kPluginPath).AppendASCII(test_case); | |
61 GURL url = URLRequestMockHTTPJob::GetMockUrl(plugin_path); | |
62 if (!query.empty()) { | |
63 GURL::Replacements replacements; | |
64 replacements.SetQueryStr(query); | |
65 return url.ReplaceComponents(replacements); | |
66 } | |
67 return url; | |
68 } | |
69 | |
70 FilePath path; | |
71 PathService::Get(chrome::DIR_TEST_DATA, &path); | |
72 path = path.Append(kPluginPath).AppendASCII(test_case); | |
73 return ui_test_utils::GetFileUrlWithQuery(path, query); | |
74 } | |
75 | |
76 protected: | |
77 virtual void SetUp() { | |
78 #if defined(OS_WIN) | |
79 const testing::TestInfo* const test_info = | |
80 testing::UnitTest::GetInstance()->current_test_info(); | |
81 if (strcmp(test_info->name(), "MediaPlayerNew") == 0) { | |
82 // The installer adds our process names to the registry key below. Since | |
83 // the installer might not have run on this machine, add it manually. | |
84 base::win::RegKey regkey; | |
85 if (regkey.Open(HKEY_LOCAL_MACHINE, | |
86 L"Software\\Microsoft\\MediaPlayer\\ShimInclusionList", | |
87 KEY_WRITE) == ERROR_SUCCESS) { | |
88 regkey.CreateKey(L"CHROME.EXE", KEY_READ); | |
89 } | |
90 } else if (strcmp(test_info->name(), "MediaPlayerOld") == 0) { | |
91 // When testing the old WMP plugin, we need to force Chrome to not load | |
92 // the new plugin. | |
93 launch_arguments_.AppendSwitch(switches::kUseOldWMPPlugin); | |
94 } else if (strcmp(test_info->name(), "FlashSecurity") == 0) { | |
95 launch_arguments_.AppendSwitchASCII(switches::kTestSandbox, | |
96 "security_tests.dll"); | |
97 } | |
98 #elif defined(OS_MACOSX) | |
99 // The plugins directory isn't read by default on the Mac, so it needs to be | |
100 // explicitly registered. | |
101 launch_arguments_.AppendSwitchPath( | |
102 switches::kExtraPluginDir, browser_directory_.AppendASCII("plugins")); | |
103 #endif // defined(OS_WIN) | |
104 | |
105 launch_arguments_.AppendSwitch(switches::kAllowOutdatedPlugins); | |
106 launch_arguments_.AppendSwitch(switches::kAlwaysAuthorizePlugins); | |
107 | |
108 UITest::SetUp(); | |
109 } | |
110 | |
111 void TestPlugin(const std::string& test_case, | |
112 const std::string& query, | |
113 int timeout, | |
114 bool mock_http) { | |
115 GURL url = GetTestUrl(test_case, query, mock_http); | |
116 NavigateToURL(url); | |
117 WaitForFinish(timeout, mock_http); | |
118 } | |
119 | |
120 // Waits for the test case to finish. | |
121 void WaitForFinish(const int wait_time, bool mock_http) { | |
122 static const char kTestCompleteCookie[] = "status"; | |
123 static const char kTestCompleteSuccess[] = "OK"; | |
124 | |
125 GURL url = GetTestUrl("done", "", mock_http); | |
126 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
127 | |
128 const std::string result = | |
129 WaitUntilCookieNonEmpty(tab, url, kTestCompleteCookie, wait_time); | |
130 ASSERT_EQ(kTestCompleteSuccess, result); | |
131 } | |
132 }; | |
133 | |
134 TEST_F(PluginTest, Flash) { | |
135 // Note: This does not work with the npwrapper on 64-bit Linux. Install the | |
136 // native 64-bit Flash to run the test. | |
137 // TODO(thestig) Update this list if we decide to only test against internal | |
138 // Flash plugin in the future? | |
139 std::string kFlashQuery = | |
140 #if defined(OS_WIN) | |
141 "npswf32.dll" | |
142 #elif defined(OS_MACOSX) | |
143 "Flash Player.plugin" | |
144 #elif defined(OS_POSIX) | |
145 "libflashplayer.so" | |
146 #endif | |
147 ""; | |
148 TestPlugin("flash.html", kFlashQuery, | |
149 TestTimeouts::action_max_timeout_ms(), false); | |
150 } | |
151 | |
152 #if defined(OS_WIN) | |
153 // Windows only test | |
154 TEST_F(PluginTest, DISABLED_FlashSecurity) { | |
155 TestPlugin("flash.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
156 } | |
157 #endif // defined(OS_WIN) | |
158 | |
159 #if defined(OS_WIN) | |
160 // TODO(port) Port the following tests to platforms that have the required | |
161 // plugins. | |
162 // Flaky: http://crbug.com/55915 | |
163 TEST_F(PluginTest, DISABLED_Quicktime) { | |
164 TestPlugin("quicktime.html", "", | |
165 TestTimeouts::action_max_timeout_ms(), false); | |
166 } | |
167 | |
168 // Disabled - http://crbug.com/44662 | |
169 TEST_F(PluginTest, DISABLED_MediaPlayerNew) { | |
170 TestPlugin("wmp_new.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
171 } | |
172 | |
173 // http://crbug.com/4809 | |
174 TEST_F(PluginTest, DISABLED_MediaPlayerOld) { | |
175 TestPlugin("wmp_old.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
176 } | |
177 | |
178 // Disabled - http://crbug.com/44673 | |
179 TEST_F(PluginTest, DISABLED_Real) { | |
180 TestPlugin("real.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
181 } | |
182 | |
183 TEST_F(PluginTest, FlashOctetStream) { | |
184 TestPlugin("flash-octet-stream.html", "", | |
185 TestTimeouts::action_max_timeout_ms(), false); | |
186 } | |
187 | |
188 #if defined(OS_WIN) | |
189 // http://crbug.com/53926 | |
190 TEST_F(PluginTest, DISABLED_FlashLayoutWhilePainting) { | |
191 #else | |
192 TEST_F(PluginTest, FlashLayoutWhilePainting) { | |
193 #endif | |
194 TestPlugin("flash-layout-while-painting.html", "", | |
195 TestTimeouts::action_max_timeout_ms(), true); | |
196 } | |
197 | |
198 // http://crbug.com/8690 | |
199 TEST_F(PluginTest, DISABLED_Java) { | |
200 TestPlugin("Java.html", "", TestTimeouts::action_max_timeout_ms(), false); | |
201 } | |
202 | |
203 TEST_F(PluginTest, Silverlight) { | |
204 TestPlugin("silverlight.html", "", | |
205 TestTimeouts::action_max_timeout_ms(), false); | |
206 } | |
207 #endif // defined(OS_WIN) | |
OLD | NEW |