Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: Source/web/tests/WebPluginContainerTest.cpp

Issue 1164683007: Copy SkMetaData before painting printed plugin contents. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/web/tests/FrameTestHelpers.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 #include "platform/testing/UnitTestHelpers.h" 39 #include "platform/testing/UnitTestHelpers.h"
40 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
41 #include "public/platform/WebClipboard.h" 41 #include "public/platform/WebClipboard.h"
42 #include "public/platform/WebThread.h" 42 #include "public/platform/WebThread.h"
43 #include "public/platform/WebUnitTestSupport.h" 43 #include "public/platform/WebUnitTestSupport.h"
44 #include "public/web/WebDocument.h" 44 #include "public/web/WebDocument.h"
45 #include "public/web/WebElement.h" 45 #include "public/web/WebElement.h"
46 #include "public/web/WebFrame.h" 46 #include "public/web/WebFrame.h"
47 #include "public/web/WebFrameClient.h" 47 #include "public/web/WebFrameClient.h"
48 #include "public/web/WebPluginParams.h" 48 #include "public/web/WebPluginParams.h"
49 #include "public/web/WebPrintParams.h"
49 #include "public/web/WebSettings.h" 50 #include "public/web/WebSettings.h"
50 #include "public/web/WebView.h" 51 #include "public/web/WebView.h"
52 #include "third_party/skia/include/core/SkPictureRecorder.h"
51 #include "web/WebLocalFrameImpl.h" 53 #include "web/WebLocalFrameImpl.h"
52 #include "web/WebPluginContainerImpl.h" 54 #include "web/WebPluginContainerImpl.h"
53 #include "web/WebViewImpl.h" 55 #include "web/WebViewImpl.h"
54 #include "web/tests/FakeWebPlugin.h" 56 #include "web/tests/FakeWebPlugin.h"
55 #include "web/tests/FrameTestHelpers.h" 57 #include "web/tests/FrameTestHelpers.h"
56 #include <gtest/gtest.h> 58 #include <gtest/gtest.h>
57 59
58 using blink::testing::runPendingTasks; 60 using blink::testing::runPendingTasks;
59 using namespace blink; 61 using namespace blink;
60 62
61 namespace { 63 namespace {
62 64
63 class WebPluginContainerTest : public ::testing::Test { 65 class WebPluginContainerTest : public ::testing::Test {
64 public: 66 public:
65 WebPluginContainerTest() 67 WebPluginContainerTest()
66 : m_baseURL("http://www.test.com/") 68 : m_baseURL("http://www.test.com/")
67 { 69 {
68 } 70 }
69 71
70 virtual void TearDown() 72 virtual void TearDown()
71 { 73 {
72 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 74 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
73 } 75 }
74 76
75 protected: 77 protected:
76 std::string m_baseURL; 78 std::string m_baseURL;
77 }; 79 };
78 80
81 class TestPluginWebFrameClient;
82
79 // Subclass of FakeWebPlugin that has a selection of 'x' as plain text and 'y' a s markup text. 83 // Subclass of FakeWebPlugin that has a selection of 'x' as plain text and 'y' a s markup text.
80 class TestPlugin : public FakeWebPlugin { 84 class TestPlugin : public FakeWebPlugin {
81 public: 85 public:
82 TestPlugin(WebFrame* frame, const WebPluginParams& params) 86 TestPlugin(WebFrame* frame, const WebPluginParams& params, TestPluginWebFram eClient* testClient)
83 : FakeWebPlugin(frame, params) 87 : FakeWebPlugin(frame, params)
84 { 88 {
89 m_testClient = testClient;
85 } 90 }
86 91
87 virtual bool hasSelection() const { return true; } 92 virtual bool hasSelection() const { return true; }
88 virtual WebString selectionAsText() const { return WebString("x"); } 93 virtual WebString selectionAsText() const { return WebString("x"); }
89 virtual WebString selectionAsMarkup() const { return WebString("y"); } 94 virtual WebString selectionAsMarkup() const { return WebString("y"); }
95 virtual bool supportsPaginatedPrint() { return true; }
96 virtual int printBegin(const WebPrintParams& printParams) { return 1; }
97 virtual bool printPage(int pageNumber, WebCanvas*);
98 private:
99 TestPluginWebFrameClient* m_testClient;
90 }; 100 };
91 101
92 class TestPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient { 102 class TestPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
93 virtual WebPlugin* createPlugin(WebLocalFrame* frame, const WebPluginParams& params) override 103 virtual WebPlugin* createPlugin(WebLocalFrame* frame, const WebPluginParams& params) override
94 { 104 {
95 if (params.mimeType == WebString::fromUTF8("application/x-webkit-test-we bplugin")) 105 if (params.mimeType == WebString::fromUTF8("application/x-webkit-test-we bplugin"))
96 return new TestPlugin(frame, params); 106 return new TestPlugin(frame, params, this);
107 if (params.mimeType == WebString::fromUTF8("application/pdf"))
108 return new TestPlugin(frame, params, this);
97 return WebFrameClient::createPlugin(frame, params); 109 return WebFrameClient::createPlugin(frame, params);
98 } 110 }
111
112 public:
113 void onPrintPage() { m_printedPage = true; }
114 bool printedAtLeastOnePage() { return m_printedPage; }
115
116 private:
117 bool m_printedPage = false;
99 }; 118 };
100 119
120 bool TestPlugin::printPage(int pageNumber, WebCanvas* canvas)
121 {
122 ASSERT(m_testClient);
123 m_testClient->onPrintPage();
124 return true;
125 }
126
127
101 WebPluginContainer* getWebPluginContainer(WebView* webView, const WebString& id) 128 WebPluginContainer* getWebPluginContainer(WebView* webView, const WebString& id)
102 { 129 {
103 WebElement element = webView->mainFrame()->document().getElementById(id); 130 WebElement element = webView->mainFrame()->document().getElementById(id);
104 return element.pluginContainer(); 131 return element.pluginContainer();
105 } 132 }
106 133
107 TEST_F(WebPluginContainerTest, WindowToLocalPointTest) 134 TEST_F(WebPluginContainerTest, WindowToLocalPointTest)
108 { 135 {
109 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html")); 136 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html"));
110 FrameTestHelpers::WebViewHelper webViewHelper; 137 FrameTestHelpers::WebViewHelper webViewHelper;
(...skipping 16 matching lines...) Expand all
127 WebPluginContainer* pluginContainerTwo = getWebPluginContainer(webView, WebS tring::fromUTF8("rotated-plugin")); 154 WebPluginContainer* pluginContainerTwo = getWebPluginContainer(webView, WebS tring::fromUTF8("rotated-plugin"));
128 ASSERT(pluginContainerTwo); 155 ASSERT(pluginContainerTwo);
129 WebPoint point3 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(0, 10)) ; 156 WebPoint point3 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(0, 10)) ;
130 ASSERT_EQ(10, point3.x); 157 ASSERT_EQ(10, point3.x);
131 ASSERT_EQ(0, point3.y); 158 ASSERT_EQ(0, point3.y);
132 WebPoint point4 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(-10, 10 )); 159 WebPoint point4 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(-10, 10 ));
133 ASSERT_EQ(10, point4.x); 160 ASSERT_EQ(10, point4.x);
134 ASSERT_EQ(10, point4.y); 161 ASSERT_EQ(10, point4.y);
135 } 162 }
136 163
164 TEST_F(WebPluginContainerTest, PrintOnePage)
165 {
166 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("test.pdf"), WebString::fromUTF8("application/pdf") );
167
168 FrameTestHelpers::WebViewHelper webViewHelper;
169 TestPluginWebFrameClient* testClient = new TestPluginWebFrameClient();
170 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "test.pdf", t rue, testClient);
171 ASSERT(webView);
172 webView->layout();
173 runPendingTasks();
174 WebFrame* frame = webView->mainFrame();
175
176 WebPrintParams printParams;
177 printParams.printContentArea.width = 500;
178 printParams.printContentArea.height = 500;
179
180 frame->printBegin(printParams);
181 SkPictureRecorder recorder;
182 frame->printPage(0, recorder.beginRecording(IntRect()));
183 frame->printEnd();
184 ASSERT(testClient->printedAtLeastOnePage());
185 }
186
187 TEST_F(WebPluginContainerTest, PrintAllPages)
188 {
189 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("test.pdf"), WebString::fromUTF8("application/pdf") );
190
191 FrameTestHelpers::WebViewHelper webViewHelper;
192 TestPluginWebFrameClient* testClient = new TestPluginWebFrameClient();
193 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "test.pdf", t rue, testClient);
194 ASSERT(webView);
195 webView->layout();
196 runPendingTasks();
197 WebFrame* frame = webView->mainFrame();
198
199 WebPrintParams printParams;
200 printParams.printContentArea.width = 500;
201 printParams.printContentArea.height = 500;
202
203 frame->printBegin(printParams);
204 SkPictureRecorder recorder;
205 frame->printPagesWithBoundaries(recorder.beginRecording(IntRect()), WebSize( ));
206 frame->printEnd();
207 ASSERT(testClient->printedAtLeastOnePage());
208 }
209
137 TEST_F(WebPluginContainerTest, LocalToWindowPointTest) 210 TEST_F(WebPluginContainerTest, LocalToWindowPointTest)
138 { 211 {
139 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html")); 212 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html"));
140 FrameTestHelpers::WebViewHelper webViewHelper; 213 FrameTestHelpers::WebViewHelper webViewHelper;
141 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient()); 214 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient());
142 ASSERT(webView); 215 ASSERT(webView);
143 webView->settings()->setPluginsEnabled(true); 216 webView->settings()->setPluginsEnabled(true);
144 webView->resize(WebSize(300, 300)); 217 webView->resize(WebSize(300, 300));
145 webView->layout(); 218 webView->layout();
146 runPendingTasks(); 219 runPendingTasks();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 377
305 WebRect rect = pluginContainerImpl->element().boundsInViewportSpace(); 378 WebRect rect = pluginContainerImpl->element().boundsInViewportSpace();
306 EXPECT_TRUE(pluginContainerImpl->isRectTopmost(rect)); 379 EXPECT_TRUE(pluginContainerImpl->isRectTopmost(rect));
307 380
308 // Cause the plugin's frame to be detached. 381 // Cause the plugin's frame to be detached.
309 webViewHelper.reset(); 382 webViewHelper.reset();
310 383
311 EXPECT_FALSE(pluginContainerImpl->isRectTopmost(rect)); 384 EXPECT_FALSE(pluginContainerImpl->isRectTopmost(rect));
312 } 385 }
313 } 386 }
OLDNEW
« no previous file with comments | « Source/web/tests/FrameTestHelpers.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698