OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 webView->updateAllLifecyclePhases(); | 333 webView->updateAllLifecyclePhases(); |
334 runPendingTasks(); | 334 runPendingTasks(); |
335 | 335 |
336 webView->mainFrame() | 336 webView->mainFrame() |
337 ->document() | 337 ->document() |
338 .unwrap<Document>() | 338 .unwrap<Document>() |
339 ->body() | 339 ->body() |
340 ->getElementById("translated-plugin") | 340 ->getElementById("translated-plugin") |
341 ->focus(); | 341 ->focus(); |
342 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); | 342 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); |
343 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( | 343 EXPECT_EQ( |
344 WebClipboard::Buffer())); | 344 WebString("x"), |
| 345 Platform::current()->clipboard()->readPlainText(WebClipboard::Buffer())); |
345 } | 346 } |
346 | 347 |
347 TEST_F(WebPluginContainerTest, CopyFromContextMenu) { | 348 TEST_F(WebPluginContainerTest, CopyFromContextMenu) { |
348 registerMockedURL("plugin_container.html"); | 349 registerMockedURL("plugin_container.html"); |
349 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 350 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
350 FrameTestHelpers::WebViewHelper webViewHelper; | 351 FrameTestHelpers::WebViewHelper webViewHelper; |
351 WebView* webView = webViewHelper.initializeAndLoad( | 352 WebView* webView = webViewHelper.initializeAndLoad( |
352 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 353 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
353 DCHECK(webView); | 354 DCHECK(webView); |
354 webView->settings()->setPluginsEnabled(true); | 355 webView->settings()->setPluginsEnabled(true); |
355 webView->resize(WebSize(300, 300)); | 356 webView->resize(WebSize(300, 300)); |
356 webView->updateAllLifecyclePhases(); | 357 webView->updateAllLifecyclePhases(); |
357 runPendingTasks(); | 358 runPendingTasks(); |
358 | 359 |
359 auto event = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, | 360 auto event = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, |
360 WebMouseEvent::Button::Right, | 361 WebMouseEvent::Button::Right, |
361 WebPoint(30, 30), 0); | 362 WebPoint(30, 30), 0); |
362 event.clickCount = 1; | 363 event.clickCount = 1; |
363 | 364 |
364 // Make sure the right-click + Copy works in common scenario. | 365 // Make sure the right-click + Copy works in common scenario. |
365 webView->handleInputEvent(WebCoalescedInputEvent(event)); | 366 webView->handleInputEvent(WebCoalescedInputEvent(event)); |
366 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); | 367 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); |
367 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( | 368 EXPECT_EQ( |
368 WebClipboard::Buffer())); | 369 WebString("x"), |
| 370 Platform::current()->clipboard()->readPlainText(WebClipboard::Buffer())); |
369 | 371 |
370 // Clear the clipboard buffer. | 372 // Clear the clipboard buffer. |
371 Platform::current()->clipboard()->writePlainText(WebString("")); | 373 Platform::current()->clipboard()->writePlainText(WebString("")); |
372 EXPECT_EQ(WebString(""), Platform::current()->clipboard()->readPlainText( | 374 EXPECT_EQ( |
373 WebClipboard::Buffer())); | 375 WebString(""), |
| 376 Platform::current()->clipboard()->readPlainText(WebClipboard::Buffer())); |
374 | 377 |
375 // Now, let's try a more complex scenario: | 378 // Now, let's try a more complex scenario: |
376 // 1) open the context menu. This will focus the plugin. | 379 // 1) open the context menu. This will focus the plugin. |
377 webView->handleInputEvent(WebCoalescedInputEvent(event)); | 380 webView->handleInputEvent(WebCoalescedInputEvent(event)); |
378 // 2) document blurs the plugin, because it can. | 381 // 2) document blurs the plugin, because it can. |
379 webView->clearFocusedElement(); | 382 webView->clearFocusedElement(); |
380 // 3) Copy should still operate on the context node, even though the focus had | 383 // 3) Copy should still operate on the context node, even though the focus had |
381 // shifted. | 384 // shifted. |
382 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); | 385 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); |
383 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( | 386 EXPECT_EQ( |
384 WebClipboard::Buffer())); | 387 WebString("x"), |
| 388 Platform::current()->clipboard()->readPlainText(WebClipboard::Buffer())); |
385 } | 389 } |
386 | 390 |
387 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to | 391 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to |
388 // the clipboard. | 392 // the clipboard. |
389 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest) { | 393 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest) { |
390 registerMockedURL("plugin_container.html"); | 394 registerMockedURL("plugin_container.html"); |
391 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 395 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
392 FrameTestHelpers::WebViewHelper webViewHelper; | 396 FrameTestHelpers::WebViewHelper webViewHelper; |
393 WebView* webView = webViewHelper.initializeAndLoad( | 397 WebView* webView = webViewHelper.initializeAndLoad( |
394 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 398 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
(...skipping 13 matching lines...) Expand all Loading... |
408 modifierKey = static_cast<WebInputEvent::Modifiers>(WebInputEvent::MetaKey | | 412 modifierKey = static_cast<WebInputEvent::Modifiers>(WebInputEvent::MetaKey | |
409 WebInputEvent::NumLockOn | | 413 WebInputEvent::NumLockOn | |
410 WebInputEvent::IsLeft); | 414 WebInputEvent::IsLeft); |
411 #endif | 415 #endif |
412 WebKeyboardEvent webKeyboardEventC(WebInputEvent::RawKeyDown, modifierKey, | 416 WebKeyboardEvent webKeyboardEventC(WebInputEvent::RawKeyDown, modifierKey, |
413 WebInputEvent::TimeStampForTesting); | 417 WebInputEvent::TimeStampForTesting); |
414 webKeyboardEventC.windowsKeyCode = 67; | 418 webKeyboardEventC.windowsKeyCode = 67; |
415 KeyboardEvent* keyEventC = KeyboardEvent::create(webKeyboardEventC, 0); | 419 KeyboardEvent* keyEventC = KeyboardEvent::create(webKeyboardEventC, 0); |
416 toWebPluginContainerImpl(pluginContainerOneElement.pluginContainer()) | 420 toWebPluginContainerImpl(pluginContainerOneElement.pluginContainer()) |
417 ->handleEvent(keyEventC); | 421 ->handleEvent(keyEventC); |
418 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( | 422 EXPECT_EQ( |
419 WebClipboard::Buffer())); | 423 WebString("x"), |
| 424 Platform::current()->clipboard()->readPlainText(WebClipboard::Buffer())); |
420 | 425 |
421 // Clearing |Clipboard::Buffer()|. | 426 // Clearing |Clipboard::Buffer()|. |
422 Platform::current()->clipboard()->writePlainText(WebString("")); | 427 Platform::current()->clipboard()->writePlainText(WebString("")); |
423 EXPECT_EQ(WebString(""), Platform::current()->clipboard()->readPlainText( | 428 EXPECT_EQ( |
424 WebClipboard::Buffer())); | 429 WebString(""), |
| 430 Platform::current()->clipboard()->readPlainText(WebClipboard::Buffer())); |
425 | 431 |
426 WebKeyboardEvent webKeyboardEventInsert(WebInputEvent::RawKeyDown, | 432 WebKeyboardEvent webKeyboardEventInsert(WebInputEvent::RawKeyDown, |
427 modifierKey, | 433 modifierKey, |
428 WebInputEvent::TimeStampForTesting); | 434 WebInputEvent::TimeStampForTesting); |
429 webKeyboardEventInsert.windowsKeyCode = 45; | 435 webKeyboardEventInsert.windowsKeyCode = 45; |
430 KeyboardEvent* keyEventInsert = | 436 KeyboardEvent* keyEventInsert = |
431 KeyboardEvent::create(webKeyboardEventInsert, 0); | 437 KeyboardEvent::create(webKeyboardEventInsert, 0); |
432 toWebPluginContainerImpl(pluginContainerOneElement.pluginContainer()) | 438 toWebPluginContainerImpl(pluginContainerOneElement.pluginContainer()) |
433 ->handleEvent(keyEventInsert); | 439 ->handleEvent(keyEventInsert); |
434 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( | 440 EXPECT_EQ( |
435 WebClipboard::Buffer())); | 441 WebString("x"), |
| 442 Platform::current()->clipboard()->readPlainText(WebClipboard::Buffer())); |
436 } | 443 } |
437 | 444 |
438 // A class to facilitate testing that events are correctly received by plugins. | 445 // A class to facilitate testing that events are correctly received by plugins. |
439 class EventTestPlugin : public FakeWebPlugin { | 446 class EventTestPlugin : public FakeWebPlugin { |
440 public: | 447 public: |
441 EventTestPlugin(WebFrame* frame, const WebPluginParams& params) | 448 EventTestPlugin(WebFrame* frame, const WebPluginParams& params) |
442 : FakeWebPlugin(frame, params), | 449 : FakeWebPlugin(frame, params), |
443 m_lastEventType(WebInputEvent::Undefined) {} | 450 m_lastEventType(WebInputEvent::Undefined) {} |
444 | 451 |
445 WebInputEventResult handleInputEvent(const WebInputEvent& event, | 452 WebInputEventResult handleInputEvent(const WebInputEvent& event, |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 WebString::fromUTF8("translated-plugin")); | 792 WebString::fromUTF8("translated-plugin")); |
786 pluginContainerOneElement.pluginContainer()->setWantsWheelEvents(true); | 793 pluginContainerOneElement.pluginContainer()->setWantsWheelEvents(true); |
787 | 794 |
788 runPendingTasks(); | 795 runPendingTasks(); |
789 EXPECT_TRUE( | 796 EXPECT_TRUE( |
790 webView->page()->frameHost().eventHandlerRegistry().hasEventHandlers( | 797 webView->page()->frameHost().eventHandlerRegistry().hasEventHandlers( |
791 EventHandlerRegistry::WheelEventBlocking)); | 798 EventHandlerRegistry::WheelEventBlocking)); |
792 } | 799 } |
793 | 800 |
794 } // namespace blink | 801 } // namespace blink |
OLD | NEW |