OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/renderer/browser_plugin/browser_plugin_browsertest.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_browsertest.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "content/common/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin_messages.h" |
11 #include "content/public/common/content_constants.h" | 11 #include "content/public/common/content_constants.h" |
12 #include "content/renderer/browser_plugin/browser_plugin.h" | 12 #include "content/renderer/browser_plugin/browser_plugin.h" |
13 #include "content/renderer/browser_plugin/mock_browser_plugin.h" | 13 #include "content/renderer/browser_plugin/mock_browser_plugin.h" |
14 #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h" | 14 #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h" |
| 15 #include "content/renderer/browser_plugin/mock_browser_plugin_texture_provider.h
" |
15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
16 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 17 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
17 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
21 | 22 |
| 23 using ::testing::_; |
| 24 |
22 namespace { | 25 namespace { |
23 const char kHTMLForBrowserPluginObject[] = | 26 const char kHTMLForBrowserPluginObject[] = |
24 "<object id='browserplugin' width='640px' height='480px'" | 27 "<object id='browserplugin' width='640px' height='480px'" |
25 " src='foo' type='%s'>"; | 28 " src='foo' type='%s'>"; |
26 | 29 |
27 const char kHTMLForSourcelessPluginObject[] = | 30 const char kHTMLForSourcelessPluginObject[] = |
28 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; | 31 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; |
29 | 32 |
30 const char kHTMLForPartitionedPluginObject[] = | 33 const char kHTMLForPartitionedPluginObject[] = |
31 "<object id='browserplugin' width='640px' height='480px'" | 34 "<object id='browserplugin' width='640px' height='480px'" |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 ExecuteJavaScript(kAddEventListener); | 636 ExecuteJavaScript(kAddEventListener); |
634 | 637 |
635 // Pretend that the guest has crashed. | 638 // Pretend that the guest has crashed. |
636 browser_plugin->GuestGone(0, base::TERMINATION_STATUS_PROCESS_WAS_KILLED); | 639 browser_plugin->GuestGone(0, base::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
637 | 640 |
638 ProcessPendingMessages(); | 641 ProcessPendingMessages(); |
639 | 642 |
640 EXPECT_EQ(NULL, browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 643 EXPECT_EQ(NULL, browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
641 } | 644 } |
642 | 645 |
| 646 TEST_F(BrowserPluginTest, TextureProviderInitDestroyNoClient) { |
| 647 MockBrowserPluginTextureProvider *provider = |
| 648 new MockBrowserPluginTextureProvider( |
| 649 1, |
| 650 2, |
| 651 NULL, |
| 652 scoped_refptr<base::MessageLoopProxy>()); |
| 653 |
| 654 // Make sure we setup and destroy the filter. |
| 655 EXPECT_CALL(*provider, RemoveFilter()); |
| 656 EXPECT_CALL(*provider, SetUpFilter()); |
| 657 |
| 658 provider->Initialize(); |
| 659 provider->Destroy(); |
| 660 } |
| 661 |
| 662 namespace { |
| 663 |
| 664 class MockTextureProviderClient |
| 665 : WebKit::WebExternalTextureProvider::Client { |
| 666 public: |
| 667 void setProvider(WebKit::WebExternalTextureProvider* provider) { |
| 668 provider->setTextureProviderClient(this); |
| 669 } |
| 670 |
| 671 MOCK_METHOD0(stopUsingProvider, void()); |
| 672 MOCK_METHOD1(didReceiveFrame, void(unsigned)); |
| 673 MOCK_METHOD3(didUpdateTextureParams, void(bool, |
| 674 bool, |
| 675 const WebKit::WebFloatRect&)); |
| 676 MOCK_METHOD0(insertSyncPoint, unsigned()); |
| 677 }; |
| 678 |
| 679 } |
| 680 |
| 681 TEST_F(BrowserPluginTest, TextureProviderClient) { |
| 682 |
| 683 MockBrowserPluginTextureProvider *provider = |
| 684 new MockBrowserPluginTextureProvider( |
| 685 100, |
| 686 200, |
| 687 NULL, |
| 688 scoped_refptr<base::MessageLoopProxy>()); |
| 689 |
| 690 // We expect OnBuffersSwapped to send an ack. |
| 691 EXPECT_CALL(*provider, Send(_)); |
| 692 EXPECT_CALL(*provider, RemoveFilter()); |
| 693 EXPECT_CALL(*provider, SetUpFilter()); |
| 694 |
| 695 provider->Initialize(); |
| 696 |
| 697 MockTextureProviderClient client; |
| 698 // Make sure client is notified when the provider goes away. |
| 699 EXPECT_CALL(client, stopUsingProvider()); |
| 700 // Make sure OnBuffersSwapped informs the client of new texture |
| 701 // and inserts a sync point. |
| 702 EXPECT_CALL(client, didReceiveFrame(_)); |
| 703 EXPECT_CALL(client, insertSyncPoint()); |
| 704 // Make sure OnSurfaceResize informs the client of new params. |
| 705 EXPECT_CALL(client, didUpdateTextureParams(_, _, _)); |
| 706 client.setProvider(provider); |
| 707 |
| 708 provider->OnBuffersSwapped(100, 300, 200, 400); |
| 709 gfx::Size size(640, 480); |
| 710 provider->OnSurfaceResize(100, size); |
| 711 |
| 712 provider->Destroy(); |
| 713 } |
| 714 |
| 715 TEST_F(BrowserPluginTest, TextureProviderClientPendingSwap) { |
| 716 |
| 717 MockBrowserPluginTextureProvider *provider = |
| 718 new MockBrowserPluginTextureProvider( |
| 719 100, |
| 720 200, |
| 721 NULL, |
| 722 scoped_refptr<base::MessageLoopProxy>()); |
| 723 // We expect OnBuffersSwapped to send an ack. |
| 724 EXPECT_CALL(*provider, Send(_)); |
| 725 EXPECT_CALL(*provider, RemoveFilter()); |
| 726 EXPECT_CALL(*provider, SetUpFilter()); |
| 727 provider->Initialize(); |
| 728 |
| 729 MockTextureProviderClient client; |
| 730 // Make sure client is notified when the provider goes away. |
| 731 EXPECT_CALL(client, stopUsingProvider()); |
| 732 // Make sure OnBuffersSwapped informs the client of new texture |
| 733 // and inserts a sync point. |
| 734 EXPECT_CALL(client, didReceiveFrame(_)); |
| 735 EXPECT_CALL(client, insertSyncPoint()); |
| 736 |
| 737 // If we receive swap buffers before we have a client, |
| 738 // we need to inform the client once it's set. |
| 739 provider->OnBuffersSwapped(100, 300, 200, 400); |
| 740 client.setProvider(provider); |
| 741 |
| 742 provider->Destroy(); |
| 743 } |
| 744 |
643 } // namespace content | 745 } // namespace content |
OLD | NEW |