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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
50 #include "public/platform/WebClipboard.h" | 50 #include "public/platform/WebClipboard.h" |
51 #include "public/platform/WebCompositorSupport.h" | 51 #include "public/platform/WebCompositorSupport.h" |
52 #include "public/platform/WebLayer.h" | 52 #include "public/platform/WebLayer.h" |
53 #include "public/platform/WebMouseWheelEvent.h" | 53 #include "public/platform/WebMouseWheelEvent.h" |
54 #include "public/platform/WebThread.h" | 54 #include "public/platform/WebThread.h" |
55 #include "public/platform/WebTouchEvent.h" | 55 #include "public/platform/WebTouchEvent.h" |
56 #include "public/platform/WebURLLoaderMockFactory.h" | 56 #include "public/platform/WebURLLoaderMockFactory.h" |
57 #include "public/web/WebDocument.h" | 57 #include "public/web/WebDocument.h" |
58 #include "public/web/WebElement.h" | 58 #include "public/web/WebElement.h" |
59 #include "public/web/WebFrame.h" | |
60 #include "public/web/WebFrameClient.h" | 59 #include "public/web/WebFrameClient.h" |
61 #include "public/web/WebPluginParams.h" | 60 #include "public/web/WebPluginParams.h" |
62 #include "public/web/WebPrintParams.h" | 61 #include "public/web/WebPrintParams.h" |
63 #include "public/web/WebSettings.h" | 62 #include "public/web/WebSettings.h" |
64 #include "public/web/WebView.h" | 63 #include "public/web/WebView.h" |
65 #include "testing/gtest/include/gtest/gtest.h" | 64 #include "testing/gtest/include/gtest/gtest.h" |
66 #include "web/WebLocalFrameImpl.h" | 65 #include "web/WebLocalFrameImpl.h" |
67 #include "web/WebPluginContainerImpl.h" | 66 #include "web/WebPluginContainerImpl.h" |
68 #include "web/tests/FakeWebPlugin.h" | 67 #include "web/tests/FakeWebPlugin.h" |
69 #include "web/tests/FrameTestHelpers.h" | 68 #include "web/tests/FrameTestHelpers.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 100 |
102 protected: | 101 protected: |
103 std::string base_url_; | 102 std::string base_url_; |
104 }; | 103 }; |
105 | 104 |
106 namespace { | 105 namespace { |
107 | 106 |
108 template <typename T> | 107 template <typename T> |
109 class CustomPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient { | 108 class CustomPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient { |
110 public: | 109 public: |
111 WebPlugin* CreatePlugin(WebLocalFrame* frame, | 110 WebPlugin* CreatePlugin(const WebPluginParams& params) override { |
112 const WebPluginParams& params) override { | 111 return new T(params); |
113 return new T(frame, params); | |
114 } | 112 } |
115 }; | 113 }; |
116 | 114 |
117 class TestPluginWebFrameClient; | 115 class TestPluginWebFrameClient; |
118 | 116 |
119 // Subclass of FakeWebPlugin that has a selection of 'x' as plain text and 'y' | 117 // Subclass of FakeWebPlugin that has a selection of 'x' as plain text and 'y' |
120 // as markup text. | 118 // as markup text. |
121 class TestPlugin : public FakeWebPlugin { | 119 class TestPlugin : public FakeWebPlugin { |
122 public: | 120 public: |
123 TestPlugin(WebFrame* frame, | 121 TestPlugin(const WebPluginParams& params, |
124 const WebPluginParams& params, | |
125 TestPluginWebFrameClient* test_client) | 122 TestPluginWebFrameClient* test_client) |
126 : FakeWebPlugin(frame, params) { | 123 : FakeWebPlugin(params), test_client_(test_client) {} |
127 test_client_ = test_client; | |
128 } | |
129 | 124 |
130 bool HasSelection() const override { return true; } | 125 bool HasSelection() const override { return true; } |
131 WebString SelectionAsText() const override { return WebString("x"); } | 126 WebString SelectionAsText() const override { return WebString("x"); } |
132 WebString SelectionAsMarkup() const override { return WebString("y"); } | 127 WebString SelectionAsMarkup() const override { return WebString("y"); } |
133 bool SupportsPaginatedPrint() override { return true; } | 128 bool SupportsPaginatedPrint() override { return true; } |
134 int PrintBegin(const WebPrintParams& print_params) override { return 1; } | 129 int PrintBegin(const WebPrintParams& print_params) override { return 1; } |
135 void PrintPage(int page_number, WebCanvas*) override; | 130 void PrintPage(int page_number, WebCanvas*) override; |
136 | 131 |
137 private: | 132 private: |
138 TestPluginWebFrameClient* test_client_; | 133 TestPluginWebFrameClient* const test_client_; |
139 }; | 134 }; |
140 | 135 |
141 class TestPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient { | 136 class TestPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient { |
142 WebPlugin* CreatePlugin(WebLocalFrame* frame, | 137 WebPlugin* CreatePlugin(const WebPluginParams& params) override { |
143 const WebPluginParams& params) override { | |
144 if (params.mime_type == "application/x-webkit-test-webplugin" || | 138 if (params.mime_type == "application/x-webkit-test-webplugin" || |
145 params.mime_type == "application/pdf") | 139 params.mime_type == "application/pdf") |
146 return new TestPlugin(frame, params, this); | 140 return new TestPlugin(params, this); |
147 return WebFrameClient::CreatePlugin(frame, params); | 141 return WebFrameClient::CreatePlugin(params); |
148 } | 142 } |
149 | 143 |
150 public: | 144 public: |
151 void OnPrintPage() { printed_page_ = true; } | 145 void OnPrintPage() { printed_page_ = true; } |
152 bool PrintedAtLeastOnePage() { return printed_page_; } | 146 bool PrintedAtLeastOnePage() const { return printed_page_; } |
153 | 147 |
154 private: | 148 private: |
155 bool printed_page_ = false; | 149 bool printed_page_ = false; |
156 }; | 150 }; |
157 | 151 |
158 void TestPlugin::PrintPage(int page_number, WebCanvas* canvas) { | 152 void TestPlugin::PrintPage(int page_number, WebCanvas* canvas) { |
159 DCHECK(test_client_); | 153 DCHECK(test_client_); |
160 test_client_->OnPrintPage(); | 154 test_client_->OnPrintPage(); |
161 } | 155 } |
162 | 156 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 KeyboardEvent::Create(web_keyboard_event_insert, 0); | 441 KeyboardEvent::Create(web_keyboard_event_insert, 0); |
448 ToWebPluginContainerImpl(plugin_container_one_element.PluginContainer()) | 442 ToWebPluginContainerImpl(plugin_container_one_element.PluginContainer()) |
449 ->HandleEvent(key_event_insert); | 443 ->HandleEvent(key_event_insert); |
450 EXPECT_EQ(WebString("x"), Platform::Current()->Clipboard()->ReadPlainText( | 444 EXPECT_EQ(WebString("x"), Platform::Current()->Clipboard()->ReadPlainText( |
451 WebClipboard::Buffer())); | 445 WebClipboard::Buffer())); |
452 } | 446 } |
453 | 447 |
454 // A class to facilitate testing that events are correctly received by plugins. | 448 // A class to facilitate testing that events are correctly received by plugins. |
455 class EventTestPlugin : public FakeWebPlugin { | 449 class EventTestPlugin : public FakeWebPlugin { |
456 public: | 450 public: |
457 EventTestPlugin(WebFrame* frame, const WebPluginParams& params) | 451 explicit EventTestPlugin(const WebPluginParams& params) |
458 : FakeWebPlugin(frame, params), | 452 : FakeWebPlugin(params), last_event_type_(WebInputEvent::kUndefined) {} |
459 last_event_type_(WebInputEvent::kUndefined) {} | |
460 | 453 |
461 WebInputEventResult HandleInputEvent(const WebInputEvent& event, | 454 WebInputEventResult HandleInputEvent(const WebInputEvent& event, |
462 WebCursorInfo&) override { | 455 WebCursorInfo&) override { |
463 last_event_type_ = event.GetType(); | 456 last_event_type_ = event.GetType(); |
464 if (WebInputEvent::IsMouseEventType(event.GetType()) || | 457 if (WebInputEvent::IsMouseEventType(event.GetType()) || |
465 event.GetType() == WebInputEvent::kMouseWheel) { | 458 event.GetType() == WebInputEvent::kMouseWheel) { |
466 const WebMouseEvent& mouse_event = | 459 const WebMouseEvent& mouse_event = |
467 static_cast<const WebMouseEvent&>(event); | 460 static_cast<const WebMouseEvent&>(event); |
468 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x, | 461 last_event_location_ = IntPoint(mouse_event.PositionInWidget().x, |
469 mouse_event.PositionInWidget().y); | 462 mouse_event.PositionInWidget().y); |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 // Cause the plugin's frame to be detached. | 926 // Cause the plugin's frame to be detached. |
934 web_view_helper.Reset(); | 927 web_view_helper.Reset(); |
935 } | 928 } |
936 | 929 |
937 TEST_F(WebPluginContainerTest, TopmostAfterDetachTest) { | 930 TEST_F(WebPluginContainerTest, TopmostAfterDetachTest) { |
938 static WebRect topmost_rect(10, 10, 40, 40); | 931 static WebRect topmost_rect(10, 10, 40, 40); |
939 | 932 |
940 // Plugin that checks isRectTopmost in destroy(). | 933 // Plugin that checks isRectTopmost in destroy(). |
941 class TopmostPlugin : public FakeWebPlugin { | 934 class TopmostPlugin : public FakeWebPlugin { |
942 public: | 935 public: |
943 TopmostPlugin(WebFrame* frame, const WebPluginParams& params) | 936 explicit TopmostPlugin(const WebPluginParams& params) |
944 : FakeWebPlugin(frame, params) {} | 937 : FakeWebPlugin(params) {} |
945 | 938 |
946 bool IsRectTopmost() { return Container()->IsRectTopmost(topmost_rect); } | 939 bool IsRectTopmost() { return Container()->IsRectTopmost(topmost_rect); } |
947 | 940 |
948 void Destroy() override { | 941 void Destroy() override { |
949 // In destroy, isRectTopmost is no longer valid. | 942 // In destroy, IsRectTopmost is no longer valid. |
950 EXPECT_FALSE(Container()->IsRectTopmost(topmost_rect)); | 943 EXPECT_FALSE(Container()->IsRectTopmost(topmost_rect)); |
951 FakeWebPlugin::Destroy(); | 944 FakeWebPlugin::Destroy(); |
952 } | 945 } |
953 }; | 946 }; |
954 | 947 |
955 RegisterMockedURL("plugin_container.html"); | 948 RegisterMockedURL("plugin_container.html"); |
956 CustomPluginWebFrameClient<TopmostPlugin> | 949 // The client must outlive WebViewHelper. |
957 plugin_web_frame_client; // Must outlive webViewHelper. | 950 CustomPluginWebFrameClient<TopmostPlugin> plugin_web_frame_client; |
958 FrameTestHelpers::WebViewHelper web_view_helper; | 951 FrameTestHelpers::WebViewHelper web_view_helper; |
959 WebView* web_view = web_view_helper.InitializeAndLoad( | 952 WebView* web_view = web_view_helper.InitializeAndLoad( |
960 base_url_ + "plugin_container.html", true, &plugin_web_frame_client); | 953 base_url_ + "plugin_container.html", true, &plugin_web_frame_client); |
961 DCHECK(web_view); | 954 DCHECK(web_view); |
962 web_view->GetSettings()->SetPluginsEnabled(true); | 955 web_view->GetSettings()->SetPluginsEnabled(true); |
963 web_view->Resize(WebSize(300, 300)); | 956 web_view->Resize(WebSize(300, 300)); |
964 web_view->UpdateAllLifecyclePhases(); | 957 web_view->UpdateAllLifecyclePhases(); |
965 RunPendingTasks(); | 958 RunPendingTasks(); |
966 | 959 |
967 WebPluginContainerImpl* plugin_container_impl = | 960 WebPluginContainerImpl* plugin_container_impl = |
(...skipping 10 matching lines...) Expand all Loading... |
978 // Cause the plugin's frame to be detached. | 971 // Cause the plugin's frame to be detached. |
979 web_view_helper.Reset(); | 972 web_view_helper.Reset(); |
980 | 973 |
981 EXPECT_FALSE(plugin_container_impl->IsRectTopmost(topmost_rect)); | 974 EXPECT_FALSE(plugin_container_impl->IsRectTopmost(topmost_rect)); |
982 } | 975 } |
983 | 976 |
984 namespace { | 977 namespace { |
985 | 978 |
986 class CompositedPlugin : public FakeWebPlugin { | 979 class CompositedPlugin : public FakeWebPlugin { |
987 public: | 980 public: |
988 CompositedPlugin(WebLocalFrame* frame, const WebPluginParams& params) | 981 explicit CompositedPlugin(const WebPluginParams& params) |
989 : FakeWebPlugin(frame, params), | 982 : FakeWebPlugin(params), |
990 layer_(Platform::Current()->CompositorSupport()->CreateLayer()) {} | 983 layer_(Platform::Current()->CompositorSupport()->CreateLayer()) {} |
991 | 984 |
992 WebLayer* GetWebLayer() const { return layer_.get(); } | 985 WebLayer* GetWebLayer() const { return layer_.get(); } |
993 | 986 |
994 // WebPlugin | 987 // WebPlugin |
995 | 988 |
996 bool Initialize(WebPluginContainer* container) override { | 989 bool Initialize(WebPluginContainer* container) override { |
997 if (!FakeWebPlugin::Initialize(container)) | 990 if (!FakeWebPlugin::Initialize(container)) |
998 return false; | 991 return false; |
999 container->SetWebLayer(layer_.get()); | 992 container->SetWebLayer(layer_.get()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 web_view->MainFrame()->GetDocument().GetElementById( | 1063 web_view->MainFrame()->GetDocument().GetElementById( |
1071 WebString::FromUTF8("translated-plugin")); | 1064 WebString::FromUTF8("translated-plugin")); |
1072 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); | 1065 plugin_container_one_element.PluginContainer()->SetWantsWheelEvents(true); |
1073 | 1066 |
1074 RunPendingTasks(); | 1067 RunPendingTasks(); |
1075 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( | 1068 EXPECT_TRUE(web_view->GetPage()->GetEventHandlerRegistry().HasEventHandlers( |
1076 EventHandlerRegistry::kWheelEventBlocking)); | 1069 EventHandlerRegistry::kWheelEventBlocking)); |
1077 } | 1070 } |
1078 | 1071 |
1079 } // namespace blink | 1072 } // namespace blink |
OLD | NEW |