[android_webview] Disable AwSettingsTest broken by Blink roll.
[chromium-blink-merge.git] / content / browser / plugin_browsertest.cc
blob4e613a595bdeb82969e5bc44f3ff5b6de7f5cef5
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.
5 #include "base/command_line.h"
6 #include "base/file_util.h"
7 #include "base/path_service.h"
8 #include "base/utf_string_conversions.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/common/content_switches.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "content/shell/common/shell_switches.h"
13 #include "content/shell/shell.h"
14 #include "content/test/content_browser_test.h"
15 #include "content/test/content_browser_test_utils.h"
16 #include "content/test/net/url_request_mock_http_job.h"
17 #include "ui/gfx/rect.h"
18 #include "webkit/plugins/plugin_switches.h"
20 #if defined(OS_WIN)
21 #include "base/win/registry.h"
22 #endif
24 // TODO(jschuh): Finish plugins on Win64. crbug.com/180861
25 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
26 #define MAYBE(x) DISABLED_##x
27 #else
28 #define MAYBE(x) x
29 #endif
31 namespace content {
32 namespace {
34 void SetUrlRequestMock(const base::FilePath& path) {
35 URLRequestMockHTTPJob::AddUrlHandler(path);
40 class PluginTest : public ContentBrowserTest {
41 protected:
42 PluginTest() {}
44 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
45 // Some NPAPI tests schedule garbage collection to force object tear-down.
46 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose_gc");
48 #if defined(OS_WIN)
49 const testing::TestInfo* const test_info =
50 testing::UnitTest::GetInstance()->current_test_info();
51 if (strcmp(test_info->name(), "MediaPlayerNew") == 0) {
52 // The installer adds our process names to the registry key below. Since
53 // the installer might not have run on this machine, add it manually.
54 base::win::RegKey regkey;
55 if (regkey.Open(HKEY_LOCAL_MACHINE,
56 L"Software\\Microsoft\\MediaPlayer\\ShimInclusionList",
57 KEY_WRITE) == ERROR_SUCCESS) {
58 regkey.CreateKey(L"BROWSER_TESTS.EXE", KEY_READ);
60 } else if (strcmp(test_info->name(), "MediaPlayerOld") == 0) {
61 // When testing the old WMP plugin, we need to force Chrome to not load
62 // the new plugin.
63 command_line->AppendSwitch(switches::kUseOldWMPPlugin);
64 } else if (strcmp(test_info->name(), "FlashSecurity") == 0) {
65 command_line->AppendSwitchASCII(switches::kTestSandbox,
66 "security_tests.dll");
68 #elif defined(OS_MACOSX)
69 base::FilePath plugin_dir;
70 PathService::Get(base::DIR_MODULE, &plugin_dir);
71 plugin_dir = plugin_dir.AppendASCII("plugins");
72 // The plugins directory isn't read by default on the Mac, so it needs to be
73 // explicitly registered.
74 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir);
75 #endif
78 virtual void SetUpOnMainThread() OVERRIDE {
79 base::FilePath path = GetTestFilePath("", "");
80 BrowserThread::PostTask(
81 BrowserThread::IO, FROM_HERE, base::Bind(&SetUrlRequestMock, path));
84 static void LoadAndWaitInWindow(Shell* window, const GURL& url) {
85 string16 expected_title(ASCIIToUTF16("OK"));
86 TitleWatcher title_watcher(window->web_contents(), expected_title);
87 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
88 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("plugin_not_found"));
89 NavigateToURL(window, url);
90 string16 title = title_watcher.WaitAndGetTitle();
91 if (title == ASCIIToUTF16("plugin_not_found")) {
92 const testing::TestInfo* const test_info =
93 testing::UnitTest::GetInstance()->current_test_info();
94 LOG(INFO) << "PluginTest." << test_info->name() <<
95 " not running because plugin not installed.";
96 } else {
97 EXPECT_EQ(expected_title, title);
101 void LoadAndWait(const GURL& url) {
102 LoadAndWaitInWindow(shell(), url);
105 GURL GetURL(const char* filename) {
106 return GetTestUrl("npapi", filename);
109 void NavigateAway() {
110 GURL url = GetTestUrl("", "simple_page.html");
111 LoadAndWait(url);
114 void TestPlugin(const char* filename) {
115 base::FilePath path = GetTestFilePath("plugin", filename);
116 if (!file_util::PathExists(path)) {
117 const testing::TestInfo* const test_info =
118 testing::UnitTest::GetInstance()->current_test_info();
119 LOG(INFO) << "PluginTest." << test_info->name() <<
120 " not running because test data wasn't found.";
121 return;
124 GURL url = GetTestUrl("plugin", filename);
125 LoadAndWait(url);
129 // Make sure that navigating away from a plugin referenced by JS doesn't
130 // crash.
131 IN_PROC_BROWSER_TEST_F(PluginTest, UnloadNoCrash) {
132 LoadAndWait(GetURL("layout_test_plugin.html"));
133 NavigateAway();
136 // Tests if a plugin executing a self deleting script using NPN_GetURL
137 // works without crashing or hanging
138 // Flaky: http://crbug.com/59327
139 IN_PROC_BROWSER_TEST_F(PluginTest, SelfDeletePluginGetUrl) {
140 LoadAndWait(GetURL("self_delete_plugin_geturl.html"));
143 // Tests if a plugin executing a self deleting script using Invoke
144 // works without crashing or hanging
145 // Flaky. See http://crbug.com/30702
146 IN_PROC_BROWSER_TEST_F(PluginTest, SelfDeletePluginInvoke) {
147 LoadAndWait(GetURL("self_delete_plugin_invoke.html"));
150 IN_PROC_BROWSER_TEST_F(PluginTest, NPObjectReleasedOnDestruction) {
151 NavigateToURL(shell(), GetURL("npobject_released_on_destruction.html"));
152 NavigateAway();
155 // Test that a dialog is properly created when a plugin throws an
156 // exception. Should be run for in and out of process plugins, but
157 // the more interesting case is out of process, where we must route
158 // the exception to the correct renderer.
159 IN_PROC_BROWSER_TEST_F(PluginTest, NPObjectSetException) {
160 LoadAndWait(GetURL("npobject_set_exception.html"));
163 #if defined(OS_WIN)
164 // Tests if a plugin executing a self deleting script in the context of
165 // a synchronous mouseup works correctly.
166 // This was never ported to Mac. The only thing remaining is to make
167 // SimulateMouseClick get to Mac plugins, currently it doesn't work.
168 IN_PROC_BROWSER_TEST_F(PluginTest,
169 SelfDeletePluginInvokeInSynchronousMouseUp) {
170 NavigateToURL(shell(), GetURL("execute_script_delete_in_mouse_up.html"));
172 string16 expected_title(ASCIIToUTF16("OK"));
173 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
174 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
175 SimulateMouseClick(shell()->web_contents(), 0,
176 WebKit::WebMouseEvent::ButtonLeft);
177 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
179 #endif
181 // Flaky, http://crbug.com/60071.
182 IN_PROC_BROWSER_TEST_F(PluginTest, GetURLRequest404Response) {
183 GURL url(URLRequestMockHTTPJob::GetMockUrl(
184 base::FilePath().AppendASCII("npapi").
185 AppendASCII("plugin_url_request_404.html")));
186 LoadAndWait(url);
189 // Tests if a plugin executing a self deleting script using Invoke with
190 // a modal dialog showing works without crashing or hanging
191 // Disabled, flakily exceeds timeout, http://crbug.com/46257.
192 IN_PROC_BROWSER_TEST_F(PluginTest, SelfDeletePluginInvokeAlert) {
193 // Navigate asynchronously because if we waitd until it completes, there's a
194 // race condition where the alert can come up before we start watching for it.
195 shell()->LoadURL(GetURL("self_delete_plugin_invoke_alert.html"));
197 string16 expected_title(ASCIIToUTF16("OK"));
198 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
199 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
201 WaitForAppModalDialog(shell());
203 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
206 // Test passing arguments to a plugin.
207 IN_PROC_BROWSER_TEST_F(PluginTest, Arguments) {
208 LoadAndWait(GetURL("arguments.html"));
211 // Test invoking many plugins within a single page.
212 IN_PROC_BROWSER_TEST_F(PluginTest, ManyPlugins) {
213 LoadAndWait(GetURL("many_plugins.html"));
216 // Test various calls to GetURL from a plugin.
217 IN_PROC_BROWSER_TEST_F(PluginTest, GetURL) {
218 LoadAndWait(GetURL("geturl.html"));
221 // Test various calls to GetURL for javascript URLs with
222 // non NULL targets from a plugin.
223 IN_PROC_BROWSER_TEST_F(PluginTest, GetJavaScriptURL) {
224 LoadAndWait(GetURL("get_javascript_url.html"));
227 // Test that calling GetURL with a javascript URL and target=_self
228 // works properly when the plugin is embedded in a subframe.
229 IN_PROC_BROWSER_TEST_F(PluginTest, GetJavaScriptURL2) {
230 LoadAndWait(GetURL("get_javascript_url2.html"));
233 // Test is flaky on linux/cros/win builders. http://crbug.com/71904
234 IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_GetURLRedirectNotification) {
235 LoadAndWait(GetURL("geturl_redirect_notify.html"));
238 // Tests that identity is preserved for NPObjects passed from a plugin
239 // into JavaScript.
240 IN_PROC_BROWSER_TEST_F(PluginTest, NPObjectIdentity) {
241 LoadAndWait(GetURL("npobject_identity.html"));
244 // Tests that if an NPObject is proxies back to its original process, the
245 // original pointer is returned and not a proxy. If this fails the plugin
246 // will crash.
247 IN_PROC_BROWSER_TEST_F(PluginTest, NPObjectProxy) {
248 LoadAndWait(GetURL("npobject_proxy.html"));
251 #if defined(OS_WIN) || defined(OS_MACOSX)
252 // Tests if a plugin executing a self deleting script in the context of
253 // a synchronous paint event works correctly
254 // http://crbug.com/44960
255 IN_PROC_BROWSER_TEST_F(PluginTest, SelfDeletePluginInvokeInSynchronousPaint) {
256 LoadAndWait(GetURL("execute_script_delete_in_paint.html"));
258 #endif
260 // Tests that if a plugin executes a self resizing script in the context of a
261 // synchronous paint, the plugin doesn't use deallocated memory.
262 // http://crbug.com/139462
263 IN_PROC_BROWSER_TEST_F(PluginTest, ResizeDuringPaint) {
264 LoadAndWait(GetURL("resize_during_paint.html"));
267 IN_PROC_BROWSER_TEST_F(PluginTest, SelfDeletePluginInNewStream) {
268 LoadAndWait(GetURL("self_delete_plugin_stream.html"));
271 // This test asserts on Mac in plugin_host in the NPNVWindowNPObject case.
272 #if !(defined(OS_MACOSX) && !defined(NDEBUG))
273 // If this test flakes use http://crbug.com/95558.
274 IN_PROC_BROWSER_TEST_F(PluginTest, DeletePluginInDeallocate) {
275 LoadAndWait(GetURL("plugin_delete_in_deallocate.html"));
277 #endif
279 #if defined(OS_WIN)
281 IN_PROC_BROWSER_TEST_F(PluginTest, VerifyPluginWindowRect) {
282 LoadAndWait(GetURL("verify_plugin_window_rect.html"));
285 // Tests that creating a new instance of a plugin while another one is handling
286 // a paint message doesn't cause deadlock.
287 IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(CreateInstanceInPaint)) {
288 LoadAndWait(GetURL("create_instance_in_paint.html"));
291 // Tests that putting up an alert in response to a paint doesn't deadlock.
292 IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_AlertInWindowMessage) {
293 NavigateToURL(shell(), GetURL("alert_in_window_message.html"));
295 WaitForAppModalDialog(shell());
296 WaitForAppModalDialog(shell());
299 IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(VerifyNPObjectLifetimeTest)) {
300 LoadAndWait(GetURL("npobject_lifetime_test.html"));
303 // Tests that we don't crash or assert if NPP_New fails
304 IN_PROC_BROWSER_TEST_F(PluginTest, NewFails) {
305 LoadAndWait(GetURL("new_fails.html"));
308 IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(SelfDeletePluginInNPNEvaluate)) {
309 LoadAndWait(GetURL("execute_script_delete_in_npn_evaluate.html"));
312 IN_PROC_BROWSER_TEST_F(PluginTest,
313 MAYBE(SelfDeleteCreatePluginInNPNEvaluate)) {
314 LoadAndWait(GetURL("npn_plugin_delete_create_in_evaluate.html"));
317 #endif // OS_WIN
319 // If this flakes, reopen http://crbug.com/17645
320 // As of 6 July 2011, this test is flaky on Windows (perhaps due to timing out).
321 #if !defined(OS_MACOSX)
322 // Disabled on Mac because the plugin side isn't implemented yet, see
323 // "TODO(port)" in plugin_javascript_open_popup.cc.
324 IN_PROC_BROWSER_TEST_F(PluginTest, OpenPopupWindowWithPlugin) {
325 LoadAndWait(GetURL("get_javascript_open_popup_with_plugin.html"));
327 #endif
329 // Test checking the privacy mode is off.
330 IN_PROC_BROWSER_TEST_F(PluginTest, PrivateDisabled) {
331 LoadAndWait(GetURL("private.html"));
334 IN_PROC_BROWSER_TEST_F(PluginTest, ScheduleTimer) {
335 LoadAndWait(GetURL("schedule_timer.html"));
338 IN_PROC_BROWSER_TEST_F(PluginTest, PluginThreadAsyncCall) {
339 LoadAndWait(GetURL("plugin_thread_async_call.html"));
342 // Test checking the privacy mode is on.
343 // If this flakes on Linux, use http://crbug.com/104380
344 IN_PROC_BROWSER_TEST_F(PluginTest, PrivateEnabled) {
345 GURL url = GetURL("private.html");
346 url = GURL(url.spec() + "?private");
347 LoadAndWaitInWindow(CreateOffTheRecordBrowser(), url);
350 #if defined(OS_WIN) || defined(OS_MACOSX)
351 // Test a browser hang due to special case of multiple
352 // plugin instances indulged in sync calls across renderer.
353 IN_PROC_BROWSER_TEST_F(PluginTest, MultipleInstancesSyncCalls) {
354 LoadAndWait(GetURL("multiple_instances_sync_calls.html"));
356 #endif
358 IN_PROC_BROWSER_TEST_F(PluginTest, GetURLRequestFailWrite) {
359 GURL url(URLRequestMockHTTPJob::GetMockUrl(
360 base::FilePath().AppendASCII("npapi").
361 AppendASCII("plugin_url_request_fail_write.html")));
362 LoadAndWait(url);
365 #if defined(OS_WIN)
366 IN_PROC_BROWSER_TEST_F(PluginTest, EnsureScriptingWorksInDestroy) {
367 LoadAndWait(GetURL("ensure_scripting_works_in_destroy.html"));
370 // This test uses a Windows Event to signal to the plugin that it should crash
371 // on NP_Initialize.
372 IN_PROC_BROWSER_TEST_F(PluginTest, NoHangIfInitCrashes) {
373 HANDLE crash_event = CreateEvent(NULL, TRUE, FALSE, L"TestPluginCrashOnInit");
374 SetEvent(crash_event);
375 LoadAndWait(GetURL("no_hang_if_init_crashes.html"));
376 CloseHandle(crash_event);
378 #endif
380 // If this flakes on Mac, use http://crbug.com/111508
381 IN_PROC_BROWSER_TEST_F(PluginTest, PluginReferrerTest) {
382 GURL url(URLRequestMockHTTPJob::GetMockUrl(
383 base::FilePath().AppendASCII("npapi").
384 AppendASCII("plugin_url_request_referrer_test.html")));
385 LoadAndWait(url);
388 #if defined(OS_MACOSX)
389 // Test is flaky, see http://crbug.com/134515.
390 IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_PluginConvertPointTest) {
391 gfx::Rect bounds(50, 50, 400, 400);
392 SetWindowBounds(shell()->window(), bounds);
394 NavigateToURL(shell(), GetURL("convert_point.html"));
396 string16 expected_title(ASCIIToUTF16("OK"));
397 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
398 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
399 // TODO(stuartmorgan): When the automation system supports sending clicks,
400 // change the test to trigger on mouse-down rather than window focus.
402 // TODO: is this code still needed? It was here when it used to run in
403 // browser_tests.
404 //static_cast<WebContentsDelegate*>(shell())->
405 // ActivateContents(shell()->web_contents());
406 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
408 #endif
410 IN_PROC_BROWSER_TEST_F(PluginTest, Flash) {
411 TestPlugin("flash.html");
414 #if defined(OS_WIN)
415 // Windows only test
416 IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_FlashSecurity) {
417 TestPlugin("flash.html");
419 #endif // defined(OS_WIN)
421 #if defined(OS_WIN)
422 // TODO(port) Port the following tests to platforms that have the required
423 // plugins.
424 // Flaky: http://crbug.com/55915
425 IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Quicktime)) {
426 TestPlugin("quicktime.html");
429 // Disabled - http://crbug.com/44662
430 IN_PROC_BROWSER_TEST_F(PluginTest, MediaPlayerNew) {
431 TestPlugin("wmp_new.html");
434 // http://crbug.com/4809
435 IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_MediaPlayerOld) {
436 TestPlugin("wmp_old.html");
439 // Disabled - http://crbug.com/44673
440 IN_PROC_BROWSER_TEST_F(PluginTest, Real) {
441 TestPlugin("real.html");
444 IN_PROC_BROWSER_TEST_F(PluginTest, FlashOctetStream) {
445 TestPlugin("flash-octet-stream.html");
448 #if defined(OS_WIN)
449 // http://crbug.com/53926
450 IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_FlashLayoutWhilePainting) {
451 #else
452 IN_PROC_BROWSER_TEST_F(PluginTest, FlashLayoutWhilePainting) {
453 #endif
454 TestPlugin("flash-layout-while-painting.html");
457 // http://crbug.com/8690
458 IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_Java) {
459 TestPlugin("Java.html");
462 IN_PROC_BROWSER_TEST_F(PluginTest, Silverlight) {
463 TestPlugin("silverlight.html");
465 #endif // defined(OS_WIN)
467 } // namespace content