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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "public/web/WebPluginContainer.h" | 31 #include "public/web/WebPluginContainer.h" |
32 | 32 |
| 33 #include <memory> |
| 34 #include <string> |
33 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
34 #include "core/events/KeyboardEvent.h" | 36 #include "core/events/KeyboardEvent.h" |
35 #include "core/frame/EventHandlerRegistry.h" | 37 #include "core/frame/EventHandlerRegistry.h" |
36 #include "core/frame/FrameHost.h" | 38 #include "core/frame/FrameHost.h" |
37 #include "core/layout/LayoutObject.h" | 39 #include "core/layout/LayoutObject.h" |
38 #include "core/page/Page.h" | 40 #include "core/page/Page.h" |
39 #include "platform/PlatformEvent.h" | 41 #include "platform/PlatformEvent.h" |
40 #include "platform/graphics/GraphicsContext.h" | 42 #include "platform/graphics/GraphicsContext.h" |
41 #include "platform/graphics/paint/CullRect.h" | 43 #include "platform/graphics/paint/CullRect.h" |
42 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" | 44 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" |
(...skipping 17 matching lines...) Expand all Loading... |
60 #include "public/web/WebPluginParams.h" | 62 #include "public/web/WebPluginParams.h" |
61 #include "public/web/WebPrintParams.h" | 63 #include "public/web/WebPrintParams.h" |
62 #include "public/web/WebSettings.h" | 64 #include "public/web/WebSettings.h" |
63 #include "public/web/WebView.h" | 65 #include "public/web/WebView.h" |
64 #include "testing/gtest/include/gtest/gtest.h" | 66 #include "testing/gtest/include/gtest/gtest.h" |
65 #include "web/WebLocalFrameImpl.h" | 67 #include "web/WebLocalFrameImpl.h" |
66 #include "web/WebPluginContainerImpl.h" | 68 #include "web/WebPluginContainerImpl.h" |
67 #include "web/WebViewImpl.h" | 69 #include "web/WebViewImpl.h" |
68 #include "web/tests/FakeWebPlugin.h" | 70 #include "web/tests/FakeWebPlugin.h" |
69 #include "web/tests/FrameTestHelpers.h" | 71 #include "web/tests/FrameTestHelpers.h" |
70 #include <memory> | |
71 | 72 |
72 using blink::testing::runPendingTasks; | 73 using blink::testing::runPendingTasks; |
73 | 74 |
74 namespace blink { | 75 namespace blink { |
75 | 76 |
76 class WebPluginContainerTest : public ::testing::Test { | 77 class WebPluginContainerTest : public ::testing::Test { |
77 public: | 78 public: |
78 WebPluginContainerTest() : m_baseURL("http://www.test.com/") {} | 79 WebPluginContainerTest() : m_baseURL("http://www.test.com/") {} |
79 | 80 |
80 void TearDown() override { | 81 void TearDown() override { |
81 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 82 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
82 WebCache::clear(); | 83 WebCache::clear(); |
83 } | 84 } |
84 | 85 |
85 void calculateGeometry(WebPluginContainerImpl* pluginContainerImpl, | 86 void calculateGeometry(WebPluginContainerImpl* pluginContainerImpl, |
86 IntRect& windowRect, | 87 IntRect& windowRect, |
87 IntRect& clipRect, | 88 IntRect& clipRect, |
88 IntRect& unobscuredRect, | 89 IntRect& unobscuredRect, |
89 Vector<IntRect>& cutOutRects) { | 90 Vector<IntRect>& cutOutRects) { |
90 pluginContainerImpl->calculateGeometry(windowRect, clipRect, unobscuredRect, | 91 pluginContainerImpl->calculateGeometry(windowRect, clipRect, unobscuredRect, |
91 cutOutRects); | 92 cutOutRects); |
92 } | 93 } |
93 | 94 |
| 95 void registerMockedURL( |
| 96 const std::string& fileName, |
| 97 const std::string& mimeType = std::string("text/html")) { |
| 98 URLTestHelpers::registerMockedURLLoadFromBase( |
| 99 WebString::fromUTF8(m_baseURL), testing::webTestDataPath(), |
| 100 WebString::fromUTF8(fileName), WebString::fromUTF8(mimeType)); |
| 101 } |
| 102 |
94 protected: | 103 protected: |
95 std::string m_baseURL; | 104 std::string m_baseURL; |
96 }; | 105 }; |
97 | 106 |
98 namespace { | 107 namespace { |
99 | 108 |
100 template <typename T> | 109 template <typename T> |
101 class CustomPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient { | 110 class CustomPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient { |
102 public: | 111 public: |
103 WebPlugin* createPlugin(WebLocalFrame* frame, | 112 WebPlugin* createPlugin(WebLocalFrame* frame, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 163 |
155 WebPluginContainer* getWebPluginContainer(WebView* webView, | 164 WebPluginContainer* getWebPluginContainer(WebView* webView, |
156 const WebString& id) { | 165 const WebString& id) { |
157 WebElement element = webView->mainFrame()->document().getElementById(id); | 166 WebElement element = webView->mainFrame()->document().getElementById(id); |
158 return element.pluginContainer(); | 167 return element.pluginContainer(); |
159 } | 168 } |
160 | 169 |
161 } // namespace | 170 } // namespace |
162 | 171 |
163 TEST_F(WebPluginContainerTest, WindowToLocalPointTest) { | 172 TEST_F(WebPluginContainerTest, WindowToLocalPointTest) { |
164 URLTestHelpers::registerMockedURLFromBaseURL( | 173 registerMockedURL("plugin_container.html"); |
165 WebString::fromUTF8(m_baseURL.c_str()), | |
166 WebString::fromUTF8("plugin_container.html")); | |
167 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 174 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
168 FrameTestHelpers::WebViewHelper webViewHelper; | 175 FrameTestHelpers::WebViewHelper webViewHelper; |
169 WebView* webView = webViewHelper.initializeAndLoad( | 176 WebView* webView = webViewHelper.initializeAndLoad( |
170 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 177 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
171 DCHECK(webView); | 178 DCHECK(webView); |
172 webView->settings()->setPluginsEnabled(true); | 179 webView->settings()->setPluginsEnabled(true); |
173 webView->resize(WebSize(300, 300)); | 180 webView->resize(WebSize(300, 300)); |
174 webView->updateAllLifecyclePhases(); | 181 webView->updateAllLifecyclePhases(); |
175 runPendingTasks(); | 182 runPendingTasks(); |
176 | 183 |
(...skipping 14 matching lines...) Expand all Loading... |
191 WebPoint point3 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(0, 10)); | 198 WebPoint point3 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(0, 10)); |
192 ASSERT_EQ(10, point3.x); | 199 ASSERT_EQ(10, point3.x); |
193 ASSERT_EQ(0, point3.y); | 200 ASSERT_EQ(0, point3.y); |
194 WebPoint point4 = | 201 WebPoint point4 = |
195 pluginContainerTwo->rootFrameToLocalPoint(WebPoint(-10, 10)); | 202 pluginContainerTwo->rootFrameToLocalPoint(WebPoint(-10, 10)); |
196 ASSERT_EQ(10, point4.x); | 203 ASSERT_EQ(10, point4.x); |
197 ASSERT_EQ(10, point4.y); | 204 ASSERT_EQ(10, point4.y); |
198 } | 205 } |
199 | 206 |
200 TEST_F(WebPluginContainerTest, PluginDocumentPluginIsFocused) { | 207 TEST_F(WebPluginContainerTest, PluginDocumentPluginIsFocused) { |
201 URLTestHelpers::registerMockedURLFromBaseURL( | 208 registerMockedURL("test.pdf", "application/pdf"); |
202 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("test.pdf"), | |
203 WebString::fromUTF8("application/pdf")); | |
204 | 209 |
205 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 210 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
206 FrameTestHelpers::WebViewHelper webViewHelper; | 211 FrameTestHelpers::WebViewHelper webViewHelper; |
207 WebView* webView = webViewHelper.initializeAndLoad( | 212 WebView* webView = webViewHelper.initializeAndLoad( |
208 m_baseURL + "test.pdf", true, &pluginWebFrameClient); | 213 m_baseURL + "test.pdf", true, &pluginWebFrameClient); |
209 DCHECK(webView); | 214 DCHECK(webView); |
210 webView->updateAllLifecyclePhases(); | 215 webView->updateAllLifecyclePhases(); |
211 | 216 |
212 WebDocument document = webView->mainFrame()->document(); | 217 WebDocument document = webView->mainFrame()->document(); |
213 EXPECT_TRUE(document.isPluginDocument()); | 218 EXPECT_TRUE(document.isPluginDocument()); |
214 WebPluginContainer* pluginContainer = | 219 WebPluginContainer* pluginContainer = |
215 getWebPluginContainer(webView, "plugin"); | 220 getWebPluginContainer(webView, "plugin"); |
216 EXPECT_EQ(document.focusedElement(), pluginContainer->element()); | 221 EXPECT_EQ(document.focusedElement(), pluginContainer->element()); |
217 } | 222 } |
218 | 223 |
219 TEST_F(WebPluginContainerTest, IFramePluginDocumentNotFocused) { | 224 TEST_F(WebPluginContainerTest, IFramePluginDocumentNotFocused) { |
220 URLTestHelpers::registerMockedURLFromBaseURL( | 225 registerMockedURL("test.pdf", "application/pdf"); |
221 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("test.pdf"), | 226 registerMockedURL("iframe_pdf.html", "text/html"); |
222 WebString::fromUTF8("application/pdf")); | |
223 URLTestHelpers::registerMockedURLFromBaseURL( | |
224 WebString::fromUTF8(m_baseURL.c_str()), | |
225 WebString::fromUTF8("iframe_pdf.html"), WebString::fromUTF8("text/html")); | |
226 | 227 |
227 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 228 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
228 FrameTestHelpers::WebViewHelper webViewHelper; | 229 FrameTestHelpers::WebViewHelper webViewHelper; |
229 WebView* webView = webViewHelper.initializeAndLoad( | 230 WebView* webView = webViewHelper.initializeAndLoad( |
230 m_baseURL + "iframe_pdf.html", true, &pluginWebFrameClient); | 231 m_baseURL + "iframe_pdf.html", true, &pluginWebFrameClient); |
231 DCHECK(webView); | 232 DCHECK(webView); |
232 webView->updateAllLifecyclePhases(); | 233 webView->updateAllLifecyclePhases(); |
233 | 234 |
234 WebDocument document = webView->mainFrame()->document(); | 235 WebDocument document = webView->mainFrame()->document(); |
235 WebFrame* iframe = webView->mainFrame()->firstChild(); | 236 WebFrame* iframe = webView->mainFrame()->firstChild(); |
236 EXPECT_TRUE(iframe->document().isPluginDocument()); | 237 EXPECT_TRUE(iframe->document().isPluginDocument()); |
237 WebPluginContainer* pluginContainer = | 238 WebPluginContainer* pluginContainer = |
238 iframe->document().getElementById("plugin").pluginContainer(); | 239 iframe->document().getElementById("plugin").pluginContainer(); |
239 EXPECT_NE(document.focusedElement(), pluginContainer->element()); | 240 EXPECT_NE(document.focusedElement(), pluginContainer->element()); |
240 EXPECT_NE(iframe->document().focusedElement(), pluginContainer->element()); | 241 EXPECT_NE(iframe->document().focusedElement(), pluginContainer->element()); |
241 } | 242 } |
242 | 243 |
243 TEST_F(WebPluginContainerTest, PrintOnePage) { | 244 TEST_F(WebPluginContainerTest, PrintOnePage) { |
244 URLTestHelpers::registerMockedURLFromBaseURL( | 245 registerMockedURL("test.pdf", "application/pdf"); |
245 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("test.pdf"), | |
246 WebString::fromUTF8("application/pdf")); | |
247 | 246 |
248 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 247 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
249 FrameTestHelpers::WebViewHelper webViewHelper; | 248 FrameTestHelpers::WebViewHelper webViewHelper; |
250 WebView* webView = webViewHelper.initializeAndLoad( | 249 WebView* webView = webViewHelper.initializeAndLoad( |
251 m_baseURL + "test.pdf", true, &pluginWebFrameClient); | 250 m_baseURL + "test.pdf", true, &pluginWebFrameClient); |
252 DCHECK(webView); | 251 DCHECK(webView); |
253 webView->updateAllLifecyclePhases(); | 252 webView->updateAllLifecyclePhases(); |
254 runPendingTasks(); | 253 runPendingTasks(); |
255 WebFrame* frame = webView->mainFrame(); | 254 WebFrame* frame = webView->mainFrame(); |
256 | 255 |
257 WebPrintParams printParams; | 256 WebPrintParams printParams; |
258 printParams.printContentArea.width = 500; | 257 printParams.printContentArea.width = 500; |
259 printParams.printContentArea.height = 500; | 258 printParams.printContentArea.height = 500; |
260 | 259 |
261 frame->printBegin(printParams); | 260 frame->printBegin(printParams); |
262 PaintRecorder recorder; | 261 PaintRecorder recorder; |
263 frame->printPage(0, recorder.beginRecording(IntRect())); | 262 frame->printPage(0, recorder.beginRecording(IntRect())); |
264 frame->printEnd(); | 263 frame->printEnd(); |
265 DCHECK(pluginWebFrameClient.printedAtLeastOnePage()); | 264 DCHECK(pluginWebFrameClient.printedAtLeastOnePage()); |
266 } | 265 } |
267 | 266 |
268 TEST_F(WebPluginContainerTest, PrintAllPages) { | 267 TEST_F(WebPluginContainerTest, PrintAllPages) { |
269 URLTestHelpers::registerMockedURLFromBaseURL( | 268 registerMockedURL("test.pdf", "application/pdf"); |
270 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("test.pdf"), | |
271 WebString::fromUTF8("application/pdf")); | |
272 | 269 |
273 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 270 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
274 FrameTestHelpers::WebViewHelper webViewHelper; | 271 FrameTestHelpers::WebViewHelper webViewHelper; |
275 WebView* webView = webViewHelper.initializeAndLoad( | 272 WebView* webView = webViewHelper.initializeAndLoad( |
276 m_baseURL + "test.pdf", true, &pluginWebFrameClient); | 273 m_baseURL + "test.pdf", true, &pluginWebFrameClient); |
277 DCHECK(webView); | 274 DCHECK(webView); |
278 webView->updateAllLifecyclePhases(); | 275 webView->updateAllLifecyclePhases(); |
279 runPendingTasks(); | 276 runPendingTasks(); |
280 WebFrame* frame = webView->mainFrame(); | 277 WebFrame* frame = webView->mainFrame(); |
281 | 278 |
282 WebPrintParams printParams; | 279 WebPrintParams printParams; |
283 printParams.printContentArea.width = 500; | 280 printParams.printContentArea.width = 500; |
284 printParams.printContentArea.height = 500; | 281 printParams.printContentArea.height = 500; |
285 | 282 |
286 frame->printBegin(printParams); | 283 frame->printBegin(printParams); |
287 PaintRecorder recorder; | 284 PaintRecorder recorder; |
288 frame->printPagesWithBoundaries(recorder.beginRecording(IntRect()), | 285 frame->printPagesWithBoundaries(recorder.beginRecording(IntRect()), |
289 WebSize()); | 286 WebSize()); |
290 frame->printEnd(); | 287 frame->printEnd(); |
291 DCHECK(pluginWebFrameClient.printedAtLeastOnePage()); | 288 DCHECK(pluginWebFrameClient.printedAtLeastOnePage()); |
292 } | 289 } |
293 | 290 |
294 TEST_F(WebPluginContainerTest, LocalToWindowPointTest) { | 291 TEST_F(WebPluginContainerTest, LocalToWindowPointTest) { |
295 URLTestHelpers::registerMockedURLFromBaseURL( | 292 registerMockedURL("plugin_container.html"); |
296 WebString::fromUTF8(m_baseURL.c_str()), | |
297 WebString::fromUTF8("plugin_container.html")); | |
298 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 293 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
299 FrameTestHelpers::WebViewHelper webViewHelper; | 294 FrameTestHelpers::WebViewHelper webViewHelper; |
300 WebView* webView = webViewHelper.initializeAndLoad( | 295 WebView* webView = webViewHelper.initializeAndLoad( |
301 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 296 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
302 DCHECK(webView); | 297 DCHECK(webView); |
303 webView->settings()->setPluginsEnabled(true); | 298 webView->settings()->setPluginsEnabled(true); |
304 webView->resize(WebSize(300, 300)); | 299 webView->resize(WebSize(300, 300)); |
305 webView->updateAllLifecyclePhases(); | 300 webView->updateAllLifecyclePhases(); |
306 runPendingTasks(); | 301 runPendingTasks(); |
307 | 302 |
(...skipping 13 matching lines...) Expand all Loading... |
321 WebPoint point3 = pluginContainerTwo->localToRootFramePoint(WebPoint(10, 0)); | 316 WebPoint point3 = pluginContainerTwo->localToRootFramePoint(WebPoint(10, 0)); |
322 ASSERT_EQ(0, point3.x); | 317 ASSERT_EQ(0, point3.x); |
323 ASSERT_EQ(10, point3.y); | 318 ASSERT_EQ(10, point3.y); |
324 WebPoint point4 = pluginContainerTwo->localToRootFramePoint(WebPoint(10, 10)); | 319 WebPoint point4 = pluginContainerTwo->localToRootFramePoint(WebPoint(10, 10)); |
325 ASSERT_EQ(-10, point4.x); | 320 ASSERT_EQ(-10, point4.x); |
326 ASSERT_EQ(10, point4.y); | 321 ASSERT_EQ(10, point4.y); |
327 } | 322 } |
328 | 323 |
329 // Verifies executing the command 'Copy' results in copying to the clipboard. | 324 // Verifies executing the command 'Copy' results in copying to the clipboard. |
330 TEST_F(WebPluginContainerTest, Copy) { | 325 TEST_F(WebPluginContainerTest, Copy) { |
331 URLTestHelpers::registerMockedURLFromBaseURL( | 326 registerMockedURL("plugin_container.html"); |
332 WebString::fromUTF8(m_baseURL.c_str()), | |
333 WebString::fromUTF8("plugin_container.html")); | |
334 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 327 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
335 FrameTestHelpers::WebViewHelper webViewHelper; | 328 FrameTestHelpers::WebViewHelper webViewHelper; |
336 WebView* webView = webViewHelper.initializeAndLoad( | 329 WebView* webView = webViewHelper.initializeAndLoad( |
337 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 330 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
338 DCHECK(webView); | 331 DCHECK(webView); |
339 webView->settings()->setPluginsEnabled(true); | 332 webView->settings()->setPluginsEnabled(true); |
340 webView->resize(WebSize(300, 300)); | 333 webView->resize(WebSize(300, 300)); |
341 webView->updateAllLifecyclePhases(); | 334 webView->updateAllLifecyclePhases(); |
342 runPendingTasks(); | 335 runPendingTasks(); |
343 | 336 |
344 webView->mainFrame() | 337 webView->mainFrame() |
345 ->document() | 338 ->document() |
346 .unwrap<Document>() | 339 .unwrap<Document>() |
347 ->body() | 340 ->body() |
348 ->getElementById("translated-plugin") | 341 ->getElementById("translated-plugin") |
349 ->focus(); | 342 ->focus(); |
350 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); | 343 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); |
351 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( | 344 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( |
352 WebClipboard::Buffer())); | 345 WebClipboard::Buffer())); |
353 } | 346 } |
354 | 347 |
355 TEST_F(WebPluginContainerTest, CopyFromContextMenu) { | 348 TEST_F(WebPluginContainerTest, CopyFromContextMenu) { |
356 URLTestHelpers::registerMockedURLFromBaseURL( | 349 registerMockedURL("plugin_container.html"); |
357 WebString::fromUTF8(m_baseURL.c_str()), | |
358 WebString::fromUTF8("plugin_container.html")); | |
359 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 350 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
360 FrameTestHelpers::WebViewHelper webViewHelper; | 351 FrameTestHelpers::WebViewHelper webViewHelper; |
361 WebView* webView = webViewHelper.initializeAndLoad( | 352 WebView* webView = webViewHelper.initializeAndLoad( |
362 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 353 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
363 DCHECK(webView); | 354 DCHECK(webView); |
364 webView->settings()->setPluginsEnabled(true); | 355 webView->settings()->setPluginsEnabled(true); |
365 webView->resize(WebSize(300, 300)); | 356 webView->resize(WebSize(300, 300)); |
366 webView->updateAllLifecyclePhases(); | 357 webView->updateAllLifecyclePhases(); |
367 runPendingTasks(); | 358 runPendingTasks(); |
368 | 359 |
(...skipping 21 matching lines...) Expand all Loading... |
390 // 3) Copy should still operate on the context node, even though the focus had | 381 // 3) Copy should still operate on the context node, even though the focus had |
391 // shifted. | 382 // shifted. |
392 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); | 383 EXPECT_TRUE(webView->mainFrame()->toWebLocalFrame()->executeCommand("Copy")); |
393 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( | 384 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText( |
394 WebClipboard::Buffer())); | 385 WebClipboard::Buffer())); |
395 } | 386 } |
396 | 387 |
397 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to | 388 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to |
398 // the clipboard. | 389 // the clipboard. |
399 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest) { | 390 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest) { |
400 URLTestHelpers::registerMockedURLFromBaseURL( | 391 registerMockedURL("plugin_container.html"); |
401 WebString::fromUTF8(m_baseURL.c_str()), | |
402 WebString::fromUTF8("plugin_container.html")); | |
403 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 392 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
404 FrameTestHelpers::WebViewHelper webViewHelper; | 393 FrameTestHelpers::WebViewHelper webViewHelper; |
405 WebView* webView = webViewHelper.initializeAndLoad( | 394 WebView* webView = webViewHelper.initializeAndLoad( |
406 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 395 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
407 DCHECK(webView); | 396 DCHECK(webView); |
408 webView->settings()->setPluginsEnabled(true); | 397 webView->settings()->setPluginsEnabled(true); |
409 webView->resize(WebSize(300, 300)); | 398 webView->resize(WebSize(300, 300)); |
410 webView->updateAllLifecyclePhases(); | 399 webView->updateAllLifecyclePhases(); |
411 runPendingTasks(); | 400 runPendingTasks(); |
412 | 401 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 WebInputEvent::Type getLastInputEventType() { return m_lastEventType; } | 458 WebInputEvent::Type getLastInputEventType() { return m_lastEventType; } |
470 | 459 |
471 IntPoint getLastMouseEventLocation() { return m_lastMouseEventLocation; } | 460 IntPoint getLastMouseEventLocation() { return m_lastMouseEventLocation; } |
472 | 461 |
473 private: | 462 private: |
474 WebInputEvent::Type m_lastEventType; | 463 WebInputEvent::Type m_lastEventType; |
475 IntPoint m_lastMouseEventLocation; | 464 IntPoint m_lastMouseEventLocation; |
476 }; | 465 }; |
477 | 466 |
478 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { | 467 TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { |
479 URLTestHelpers::registerMockedURLFromBaseURL( | 468 registerMockedURL("plugin_container.html"); |
480 WebString::fromUTF8(m_baseURL.c_str()), | |
481 WebString::fromUTF8("plugin_container.html")); | |
482 CustomPluginWebFrameClient<EventTestPlugin> | 469 CustomPluginWebFrameClient<EventTestPlugin> |
483 pluginWebFrameClient; // Must outlive webViewHelper. | 470 pluginWebFrameClient; // Must outlive webViewHelper. |
484 FrameTestHelpers::WebViewHelper webViewHelper; | 471 FrameTestHelpers::WebViewHelper webViewHelper; |
485 WebView* webView = webViewHelper.initializeAndLoad( | 472 WebView* webView = webViewHelper.initializeAndLoad( |
486 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 473 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
487 DCHECK(webView); | 474 DCHECK(webView); |
488 webView->settings()->setPluginsEnabled(true); | 475 webView->settings()->setPluginsEnabled(true); |
489 webView->resize(WebSize(300, 300)); | 476 webView->resize(WebSize(300, 300)); |
490 webView->updateAllLifecyclePhases(); | 477 webView->updateAllLifecyclePhases(); |
491 runPendingTasks(); | 478 runPendingTasks(); |
(...skipping 28 matching lines...) Expand all Loading... |
520 event.y = rect.y + rect.height / 2; | 507 event.y = rect.y + rect.height / 2; |
521 | 508 |
522 webView->handleInputEvent(WebCoalescedInputEvent(event)); | 509 webView->handleInputEvent(WebCoalescedInputEvent(event)); |
523 runPendingTasks(); | 510 runPendingTasks(); |
524 | 511 |
525 EXPECT_EQ(WebInputEvent::GestureLongPress, | 512 EXPECT_EQ(WebInputEvent::GestureLongPress, |
526 testPlugin->getLastInputEventType()); | 513 testPlugin->getLastInputEventType()); |
527 } | 514 } |
528 | 515 |
529 TEST_F(WebPluginContainerTest, MouseWheelEventTranslated) { | 516 TEST_F(WebPluginContainerTest, MouseWheelEventTranslated) { |
530 URLTestHelpers::registerMockedURLFromBaseURL( | 517 registerMockedURL("plugin_container.html"); |
531 WebString::fromUTF8(m_baseURL.c_str()), | |
532 WebString::fromUTF8("plugin_container.html")); | |
533 CustomPluginWebFrameClient<EventTestPlugin> | 518 CustomPluginWebFrameClient<EventTestPlugin> |
534 pluginWebFrameClient; // Must outlive webViewHelper. | 519 pluginWebFrameClient; // Must outlive webViewHelper. |
535 FrameTestHelpers::WebViewHelper webViewHelper; | 520 FrameTestHelpers::WebViewHelper webViewHelper; |
536 WebView* webView = webViewHelper.initializeAndLoad( | 521 WebView* webView = webViewHelper.initializeAndLoad( |
537 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 522 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
538 DCHECK(webView); | 523 DCHECK(webView); |
539 webView->settings()->setPluginsEnabled(true); | 524 webView->settings()->setPluginsEnabled(true); |
540 webView->resize(WebSize(300, 300)); | 525 webView->resize(WebSize(300, 300)); |
541 webView->updateAllLifecyclePhases(); | 526 webView->updateAllLifecyclePhases(); |
542 runPendingTasks(); | 527 runPendingTasks(); |
(...skipping 17 matching lines...) Expand all Loading... |
560 webView->handleInputEvent(WebCoalescedInputEvent(event)); | 545 webView->handleInputEvent(WebCoalescedInputEvent(event)); |
561 runPendingTasks(); | 546 runPendingTasks(); |
562 | 547 |
563 EXPECT_EQ(WebInputEvent::MouseWheel, testPlugin->getLastInputEventType()); | 548 EXPECT_EQ(WebInputEvent::MouseWheel, testPlugin->getLastInputEventType()); |
564 EXPECT_EQ(rect.width / 2, testPlugin->getLastMouseEventLocation().x()); | 549 EXPECT_EQ(rect.width / 2, testPlugin->getLastMouseEventLocation().x()); |
565 EXPECT_EQ(rect.height / 2, testPlugin->getLastMouseEventLocation().y()); | 550 EXPECT_EQ(rect.height / 2, testPlugin->getLastMouseEventLocation().y()); |
566 } | 551 } |
567 | 552 |
568 // Verify that isRectTopmost returns false when the document is detached. | 553 // Verify that isRectTopmost returns false when the document is detached. |
569 TEST_F(WebPluginContainerTest, IsRectTopmostTest) { | 554 TEST_F(WebPluginContainerTest, IsRectTopmostTest) { |
570 URLTestHelpers::registerMockedURLFromBaseURL( | 555 registerMockedURL("plugin_container.html"); |
571 WebString::fromUTF8(m_baseURL.c_str()), | |
572 WebString::fromUTF8("plugin_container.html")); | |
573 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 556 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
574 FrameTestHelpers::WebViewHelper webViewHelper; | 557 FrameTestHelpers::WebViewHelper webViewHelper; |
575 WebView* webView = webViewHelper.initializeAndLoad( | 558 WebView* webView = webViewHelper.initializeAndLoad( |
576 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 559 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
577 DCHECK(webView); | 560 DCHECK(webView); |
578 webView->settings()->setPluginsEnabled(true); | 561 webView->settings()->setPluginsEnabled(true); |
579 webView->resize(WebSize(300, 300)); | 562 webView->resize(WebSize(300, 300)); |
580 webView->updateAllLifecyclePhases(); | 563 webView->updateAllLifecyclePhases(); |
581 runPendingTasks(); | 564 runPendingTasks(); |
582 | 565 |
(...skipping 13 matching lines...) Expand all Loading... |
596 #define EXPECT_RECT_EQ(expected, actual) \ | 579 #define EXPECT_RECT_EQ(expected, actual) \ |
597 do { \ | 580 do { \ |
598 const IntRect& actualRect = actual; \ | 581 const IntRect& actualRect = actual; \ |
599 EXPECT_EQ(expected.x(), actualRect.x()); \ | 582 EXPECT_EQ(expected.x(), actualRect.x()); \ |
600 EXPECT_EQ(expected.y(), actualRect.y()); \ | 583 EXPECT_EQ(expected.y(), actualRect.y()); \ |
601 EXPECT_EQ(expected.width(), actualRect.width()); \ | 584 EXPECT_EQ(expected.width(), actualRect.width()); \ |
602 EXPECT_EQ(expected.height(), actualRect.height()); \ | 585 EXPECT_EQ(expected.height(), actualRect.height()); \ |
603 } while (false) | 586 } while (false) |
604 | 587 |
605 TEST_F(WebPluginContainerTest, ClippedRectsForIframedElement) { | 588 TEST_F(WebPluginContainerTest, ClippedRectsForIframedElement) { |
606 URLTestHelpers::registerMockedURLFromBaseURL( | 589 registerMockedURL("plugin_container.html"); |
607 WebString::fromUTF8(m_baseURL.c_str()), | 590 registerMockedURL("plugin_containing_page.html"); |
608 WebString::fromUTF8("plugin_container.html")); | |
609 URLTestHelpers::registerMockedURLFromBaseURL( | |
610 WebString::fromUTF8(m_baseURL.c_str()), | |
611 WebString::fromUTF8("plugin_containing_page.html")); | |
612 | 591 |
613 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 592 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
614 FrameTestHelpers::WebViewHelper webViewHelper; | 593 FrameTestHelpers::WebViewHelper webViewHelper; |
615 WebView* webView = webViewHelper.initializeAndLoad( | 594 WebView* webView = webViewHelper.initializeAndLoad( |
616 m_baseURL + "plugin_containing_page.html", true, &pluginWebFrameClient); | 595 m_baseURL + "plugin_containing_page.html", true, &pluginWebFrameClient); |
617 DCHECK(webView); | 596 DCHECK(webView); |
618 webView->settings()->setPluginsEnabled(true); | 597 webView->settings()->setPluginsEnabled(true); |
619 webView->resize(WebSize(300, 300)); | 598 webView->resize(WebSize(300, 300)); |
620 webView->updateAllLifecyclePhases(); | 599 webView->updateAllLifecyclePhases(); |
621 runPendingTasks(); | 600 runPendingTasks(); |
(...skipping 12 matching lines...) Expand all Loading... |
634 cutOutRects); | 613 cutOutRects); |
635 EXPECT_RECT_EQ(IntRect(20, 220, 40, 40), windowRect); | 614 EXPECT_RECT_EQ(IntRect(20, 220, 40, 40), windowRect); |
636 EXPECT_RECT_EQ(IntRect(0, 0, 40, 40), clipRect); | 615 EXPECT_RECT_EQ(IntRect(0, 0, 40, 40), clipRect); |
637 EXPECT_RECT_EQ(IntRect(0, 0, 40, 40), unobscuredRect); | 616 EXPECT_RECT_EQ(IntRect(0, 0, 40, 40), unobscuredRect); |
638 | 617 |
639 // Cause the plugin's frame to be detached. | 618 // Cause the plugin's frame to be detached. |
640 webViewHelper.reset(); | 619 webViewHelper.reset(); |
641 } | 620 } |
642 | 621 |
643 TEST_F(WebPluginContainerTest, ClippedRectsForSubpixelPositionedPlugin) { | 622 TEST_F(WebPluginContainerTest, ClippedRectsForSubpixelPositionedPlugin) { |
644 URLTestHelpers::registerMockedURLFromBaseURL( | 623 registerMockedURL("plugin_container.html"); |
645 WebString::fromUTF8(m_baseURL.c_str()), | |
646 WebString::fromUTF8("plugin_container.html")); | |
647 | 624 |
648 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. | 625 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. |
649 FrameTestHelpers::WebViewHelper webViewHelper; | 626 FrameTestHelpers::WebViewHelper webViewHelper; |
650 WebView* webView = webViewHelper.initializeAndLoad( | 627 WebView* webView = webViewHelper.initializeAndLoad( |
651 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 628 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
652 DCHECK(webView); | 629 DCHECK(webView); |
653 webView->settings()->setPluginsEnabled(true); | 630 webView->settings()->setPluginsEnabled(true); |
654 webView->resize(WebSize(300, 300)); | 631 webView->resize(WebSize(300, 300)); |
655 webView->updateAllLifecyclePhases(); | 632 webView->updateAllLifecyclePhases(); |
656 runPendingTasks(); | 633 runPendingTasks(); |
(...skipping 29 matching lines...) Expand all Loading... |
686 | 663 |
687 bool isRectTopmost() { return container()->isRectTopmost(topmostRect); } | 664 bool isRectTopmost() { return container()->isRectTopmost(topmostRect); } |
688 | 665 |
689 void destroy() override { | 666 void destroy() override { |
690 // In destroy, isRectTopmost is no longer valid. | 667 // In destroy, isRectTopmost is no longer valid. |
691 EXPECT_FALSE(container()->isRectTopmost(topmostRect)); | 668 EXPECT_FALSE(container()->isRectTopmost(topmostRect)); |
692 FakeWebPlugin::destroy(); | 669 FakeWebPlugin::destroy(); |
693 } | 670 } |
694 }; | 671 }; |
695 | 672 |
696 URLTestHelpers::registerMockedURLFromBaseURL( | 673 registerMockedURL("plugin_container.html"); |
697 WebString::fromUTF8(m_baseURL.c_str()), | |
698 WebString::fromUTF8("plugin_container.html")); | |
699 CustomPluginWebFrameClient<TopmostPlugin> | 674 CustomPluginWebFrameClient<TopmostPlugin> |
700 pluginWebFrameClient; // Must outlive webViewHelper. | 675 pluginWebFrameClient; // Must outlive webViewHelper. |
701 FrameTestHelpers::WebViewHelper webViewHelper; | 676 FrameTestHelpers::WebViewHelper webViewHelper; |
702 WebView* webView = webViewHelper.initializeAndLoad( | 677 WebView* webView = webViewHelper.initializeAndLoad( |
703 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 678 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
704 DCHECK(webView); | 679 DCHECK(webView); |
705 webView->settings()->setPluginsEnabled(true); | 680 webView->settings()->setPluginsEnabled(true); |
706 webView->resize(WebSize(300, 300)); | 681 webView->resize(WebSize(300, 300)); |
707 webView->updateAllLifecyclePhases(); | 682 webView->updateAllLifecyclePhases(); |
708 runPendingTasks(); | 683 runPendingTasks(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 } | 723 } |
749 | 724 |
750 private: | 725 private: |
751 std::unique_ptr<WebLayer> m_layer; | 726 std::unique_ptr<WebLayer> m_layer; |
752 }; | 727 }; |
753 | 728 |
754 } // namespace | 729 } // namespace |
755 | 730 |
756 TEST_F(WebPluginContainerTest, CompositedPluginSPv2) { | 731 TEST_F(WebPluginContainerTest, CompositedPluginSPv2) { |
757 ScopedSlimmingPaintV2ForTest enableSPv2(true); | 732 ScopedSlimmingPaintV2ForTest enableSPv2(true); |
758 URLTestHelpers::registerMockedURLFromBaseURL( | 733 registerMockedURL("plugin.html"); |
759 WebString::fromUTF8(m_baseURL.c_str()), | |
760 WebString::fromUTF8("plugin.html")); | |
761 CustomPluginWebFrameClient<CompositedPlugin> webFrameClient; | 734 CustomPluginWebFrameClient<CompositedPlugin> webFrameClient; |
762 FrameTestHelpers::WebViewHelper webViewHelper; | 735 FrameTestHelpers::WebViewHelper webViewHelper; |
763 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin.html", | 736 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin.html", |
764 true, &webFrameClient); | 737 true, &webFrameClient); |
765 ASSERT_TRUE(webView); | 738 ASSERT_TRUE(webView); |
766 webView->settings()->setPluginsEnabled(true); | 739 webView->settings()->setPluginsEnabled(true); |
767 webView->resize(WebSize(800, 600)); | 740 webView->resize(WebSize(800, 600)); |
768 webView->updateAllLifecyclePhases(); | 741 webView->updateAllLifecyclePhases(); |
769 runPendingTasks(); | 742 runPendingTasks(); |
770 | 743 |
(...skipping 19 matching lines...) Expand all Loading... |
790 paintController->paintArtifact().getDisplayItemList(); | 763 paintController->paintArtifact().getDisplayItemList(); |
791 ASSERT_EQ(1u, displayItems.size()); | 764 ASSERT_EQ(1u, displayItems.size()); |
792 EXPECT_EQ(element->layoutObject(), &displayItems[0].client()); | 765 EXPECT_EQ(element->layoutObject(), &displayItems[0].client()); |
793 ASSERT_EQ(DisplayItem::kForeignLayerPlugin, displayItems[0].getType()); | 766 ASSERT_EQ(DisplayItem::kForeignLayerPlugin, displayItems[0].getType()); |
794 const auto& foreignLayerDisplayItem = | 767 const auto& foreignLayerDisplayItem = |
795 static_cast<const ForeignLayerDisplayItem&>(displayItems[0]); | 768 static_cast<const ForeignLayerDisplayItem&>(displayItems[0]); |
796 EXPECT_EQ(plugin->getWebLayer()->ccLayer(), foreignLayerDisplayItem.layer()); | 769 EXPECT_EQ(plugin->getWebLayer()->ccLayer(), foreignLayerDisplayItem.layer()); |
797 } | 770 } |
798 | 771 |
799 TEST_F(WebPluginContainerTest, NeedsWheelEvents) { | 772 TEST_F(WebPluginContainerTest, NeedsWheelEvents) { |
800 URLTestHelpers::registerMockedURLFromBaseURL( | 773 registerMockedURL("plugin_container.html"); |
801 WebString::fromUTF8(m_baseURL.c_str()), | |
802 WebString::fromUTF8("plugin_container.html")); | |
803 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper | 774 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper |
804 FrameTestHelpers::WebViewHelper webViewHelper; | 775 FrameTestHelpers::WebViewHelper webViewHelper; |
805 WebViewImpl* webView = webViewHelper.initializeAndLoad( | 776 WebViewImpl* webView = webViewHelper.initializeAndLoad( |
806 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); | 777 m_baseURL + "plugin_container.html", true, &pluginWebFrameClient); |
807 DCHECK(webView); | 778 DCHECK(webView); |
808 webView->settings()->setPluginsEnabled(true); | 779 webView->settings()->setPluginsEnabled(true); |
809 webView->resize(WebSize(300, 300)); | 780 webView->resize(WebSize(300, 300)); |
810 webView->updateAllLifecyclePhases(); | 781 webView->updateAllLifecyclePhases(); |
811 runPendingTasks(); | 782 runPendingTasks(); |
812 | 783 |
813 WebElement pluginContainerOneElement = | 784 WebElement pluginContainerOneElement = |
814 webView->mainFrame()->document().getElementById( | 785 webView->mainFrame()->document().getElementById( |
815 WebString::fromUTF8("translated-plugin")); | 786 WebString::fromUTF8("translated-plugin")); |
816 pluginContainerOneElement.pluginContainer()->setWantsWheelEvents(true); | 787 pluginContainerOneElement.pluginContainer()->setWantsWheelEvents(true); |
817 | 788 |
818 runPendingTasks(); | 789 runPendingTasks(); |
819 EXPECT_TRUE( | 790 EXPECT_TRUE( |
820 webView->page()->frameHost().eventHandlerRegistry().hasEventHandlers( | 791 webView->page()->frameHost().eventHandlerRegistry().hasEventHandlers( |
821 EventHandlerRegistry::WheelEventBlocking)); | 792 EventHandlerRegistry::WheelEventBlocking)); |
822 } | 793 } |
823 | 794 |
824 } // namespace blink | 795 } // namespace blink |
OLD | NEW |