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

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

Issue 1308663004: Don't leak TestPluginWebFrameClient in WebPluginContainerTests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: more Created 5 years, 3 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 | « no previous file | 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 WebPluginContainer* getWebPluginContainer(WebView* webView, const WebString& id) 125 WebPluginContainer* getWebPluginContainer(WebView* webView, const WebString& id)
126 { 126 {
127 WebElement element = webView->mainFrame()->document().getElementById(id); 127 WebElement element = webView->mainFrame()->document().getElementById(id);
128 return element.pluginContainer(); 128 return element.pluginContainer();
129 } 129 }
130 130
131 TEST_F(WebPluginContainerTest, WindowToLocalPointTest) 131 TEST_F(WebPluginContainerTest, WindowToLocalPointTest)
132 { 132 {
133 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html")); 133 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html"));
134 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper .
134 FrameTestHelpers::WebViewHelper webViewHelper; 135 FrameTestHelpers::WebViewHelper webViewHelper;
135 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient()); 136 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, &pluginWebFrameClient);
136 ASSERT(webView); 137 ASSERT(webView);
137 webView->settings()->setPluginsEnabled(true); 138 webView->settings()->setPluginsEnabled(true);
138 webView->resize(WebSize(300, 300)); 139 webView->resize(WebSize(300, 300));
139 webView->layout(); 140 webView->layout();
140 runPendingTasks(); 141 runPendingTasks();
141 142
142 WebPluginContainer* pluginContainerOne = getWebPluginContainer(webView, WebS tring::fromUTF8("translated-plugin")); 143 WebPluginContainer* pluginContainerOne = getWebPluginContainer(webView, WebS tring::fromUTF8("translated-plugin"));
143 ASSERT(pluginContainerOne); 144 ASSERT(pluginContainerOne);
144 WebPoint point1 = pluginContainerOne->rootFrameToLocalPoint(WebPoint(10, 10) ); 145 WebPoint point1 = pluginContainerOne->rootFrameToLocalPoint(WebPoint(10, 10) );
145 ASSERT_EQ(0, point1.x); 146 ASSERT_EQ(0, point1.x);
146 ASSERT_EQ(0, point1.y); 147 ASSERT_EQ(0, point1.y);
147 WebPoint point2 = pluginContainerOne->rootFrameToLocalPoint(WebPoint(100, 10 0)); 148 WebPoint point2 = pluginContainerOne->rootFrameToLocalPoint(WebPoint(100, 10 0));
148 ASSERT_EQ(90, point2.x); 149 ASSERT_EQ(90, point2.x);
149 ASSERT_EQ(90, point2.y); 150 ASSERT_EQ(90, point2.y);
150 151
151 WebPluginContainer* pluginContainerTwo = getWebPluginContainer(webView, WebS tring::fromUTF8("rotated-plugin")); 152 WebPluginContainer* pluginContainerTwo = getWebPluginContainer(webView, WebS tring::fromUTF8("rotated-plugin"));
152 ASSERT(pluginContainerTwo); 153 ASSERT(pluginContainerTwo);
153 WebPoint point3 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(0, 10)) ; 154 WebPoint point3 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(0, 10)) ;
154 ASSERT_EQ(10, point3.x); 155 ASSERT_EQ(10, point3.x);
155 ASSERT_EQ(0, point3.y); 156 ASSERT_EQ(0, point3.y);
156 WebPoint point4 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(-10, 10 )); 157 WebPoint point4 = pluginContainerTwo->rootFrameToLocalPoint(WebPoint(-10, 10 ));
157 ASSERT_EQ(10, point4.x); 158 ASSERT_EQ(10, point4.x);
158 ASSERT_EQ(10, point4.y); 159 ASSERT_EQ(10, point4.y);
159 } 160 }
160 161
161 TEST_F(WebPluginContainerTest, PrintOnePage) 162 TEST_F(WebPluginContainerTest, PrintOnePage)
162 { 163 {
163 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("test.pdf"), WebString::fromUTF8("application/pdf") ); 164 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("test.pdf"), WebString::fromUTF8("application/pdf") );
164 165
166 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper .
165 FrameTestHelpers::WebViewHelper webViewHelper; 167 FrameTestHelpers::WebViewHelper webViewHelper;
166 TestPluginWebFrameClient* testClient = new TestPluginWebFrameClient(); 168 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "test.pdf", t rue, &pluginWebFrameClient);
167 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "test.pdf", t rue, testClient);
168 ASSERT(webView); 169 ASSERT(webView);
169 webView->layout(); 170 webView->layout();
170 runPendingTasks(); 171 runPendingTasks();
171 WebFrame* frame = webView->mainFrame(); 172 WebFrame* frame = webView->mainFrame();
172 173
173 WebPrintParams printParams; 174 WebPrintParams printParams;
174 printParams.printContentArea.width = 500; 175 printParams.printContentArea.width = 500;
175 printParams.printContentArea.height = 500; 176 printParams.printContentArea.height = 500;
176 177
177 frame->printBegin(printParams); 178 frame->printBegin(printParams);
178 SkPictureRecorder recorder; 179 SkPictureRecorder recorder;
179 frame->printPage(0, recorder.beginRecording(IntRect())); 180 frame->printPage(0, recorder.beginRecording(IntRect()));
180 frame->printEnd(); 181 frame->printEnd();
181 ASSERT(testClient->printedAtLeastOnePage()); 182 ASSERT(pluginWebFrameClient.printedAtLeastOnePage());
182 } 183 }
183 184
184 TEST_F(WebPluginContainerTest, PrintAllPages) 185 TEST_F(WebPluginContainerTest, PrintAllPages)
185 { 186 {
186 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("test.pdf"), WebString::fromUTF8("application/pdf") ); 187 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("test.pdf"), WebString::fromUTF8("application/pdf") );
187 188
189 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper .
188 FrameTestHelpers::WebViewHelper webViewHelper; 190 FrameTestHelpers::WebViewHelper webViewHelper;
189 TestPluginWebFrameClient* testClient = new TestPluginWebFrameClient(); 191 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "test.pdf", t rue, &pluginWebFrameClient);
190 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "test.pdf", t rue, testClient);
191 ASSERT(webView); 192 ASSERT(webView);
192 webView->layout(); 193 webView->layout();
193 runPendingTasks(); 194 runPendingTasks();
194 WebFrame* frame = webView->mainFrame(); 195 WebFrame* frame = webView->mainFrame();
195 196
196 WebPrintParams printParams; 197 WebPrintParams printParams;
197 printParams.printContentArea.width = 500; 198 printParams.printContentArea.width = 500;
198 printParams.printContentArea.height = 500; 199 printParams.printContentArea.height = 500;
199 200
200 frame->printBegin(printParams); 201 frame->printBegin(printParams);
201 SkPictureRecorder recorder; 202 SkPictureRecorder recorder;
202 frame->printPagesWithBoundaries(recorder.beginRecording(IntRect()), WebSize( )); 203 frame->printPagesWithBoundaries(recorder.beginRecording(IntRect()), WebSize( ));
203 frame->printEnd(); 204 frame->printEnd();
204 ASSERT(testClient->printedAtLeastOnePage()); 205 ASSERT(pluginWebFrameClient.printedAtLeastOnePage());
205 } 206 }
206 207
207 TEST_F(WebPluginContainerTest, LocalToWindowPointTest) 208 TEST_F(WebPluginContainerTest, LocalToWindowPointTest)
208 { 209 {
209 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html")); 210 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html"));
210 FrameTestHelpers::WebViewHelper webViewHelper; 211 FrameTestHelpers::WebViewHelper webViewHelper;
211 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient()); 212 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient());
212 ASSERT(webView); 213 ASSERT(webView);
213 webView->settings()->setPluginsEnabled(true); 214 webView->settings()->setPluginsEnabled(true);
214 webView->resize(WebSize(300, 300)); 215 webView->resize(WebSize(300, 300));
(...skipping 16 matching lines...) Expand all
231 ASSERT_EQ(10, point3.y); 232 ASSERT_EQ(10, point3.y);
232 WebPoint point4 = pluginContainerTwo->localToRootFramePoint(WebPoint(10, 10) ); 233 WebPoint point4 = pluginContainerTwo->localToRootFramePoint(WebPoint(10, 10) );
233 ASSERT_EQ(-10, point4.x); 234 ASSERT_EQ(-10, point4.x);
234 ASSERT_EQ(10, point4.y); 235 ASSERT_EQ(10, point4.y);
235 } 236 }
236 237
237 // Verifies executing the command 'Copy' results in copying to the clipboard. 238 // Verifies executing the command 'Copy' results in copying to the clipboard.
238 TEST_F(WebPluginContainerTest, Copy) 239 TEST_F(WebPluginContainerTest, Copy)
239 { 240 {
240 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html")); 241 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html"));
242 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper .
241 FrameTestHelpers::WebViewHelper webViewHelper; 243 FrameTestHelpers::WebViewHelper webViewHelper;
242 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient()); 244 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, &pluginWebFrameClient);
243 ASSERT(webView); 245 ASSERT(webView);
244 webView->settings()->setPluginsEnabled(true); 246 webView->settings()->setPluginsEnabled(true);
245 webView->resize(WebSize(300, 300)); 247 webView->resize(WebSize(300, 300));
246 webView->layout(); 248 webView->layout();
247 runPendingTasks(); 249 runPendingTasks();
248 250
249 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE lementById(WebString::fromUTF8("translated-plugin")); 251 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE lementById(WebString::fromUTF8("translated-plugin"));
250 EXPECT_TRUE(webView->mainFrame()->executeCommand("Copy", pluginContainerOne Element)); 252 EXPECT_TRUE(webView->mainFrame()->executeCommand("Copy", pluginContainerOne Element));
251 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We bClipboard::Buffer())); 253 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We bClipboard::Buffer()));
252 } 254 }
253 255
254 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to 256 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to
255 // the clipboard. 257 // the clipboard.
256 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest) 258 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest)
257 { 259 {
258 URLTestHelpers::registerMockedURLFromBaseURL( 260 URLTestHelpers::registerMockedURLFromBaseURL(
259 WebString::fromUTF8(m_baseURL.c_str()), 261 WebString::fromUTF8(m_baseURL.c_str()),
260 WebString::fromUTF8("plugin_container.html")); 262 WebString::fromUTF8("plugin_container.html"));
263 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper .
261 FrameTestHelpers::WebViewHelper webViewHelper; 264 FrameTestHelpers::WebViewHelper webViewHelper;
262 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient()); 265 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, &pluginWebFrameClient);
263 ASSERT(webView); 266 ASSERT(webView);
264 webView->settings()->setPluginsEnabled(true); 267 webView->settings()->setPluginsEnabled(true);
265 webView->resize(WebSize(300, 300)); 268 webView->resize(WebSize(300, 300));
266 webView->layout(); 269 webView->layout();
267 runPendingTasks(); 270 runPendingTasks();
268 271
269 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE lementById(WebString::fromUTF8("translated-plugin")); 272 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE lementById(WebString::fromUTF8("translated-plugin"));
270 PlatformEvent::Modifiers modifierKey = PlatformEvent::CtrlKey; 273 PlatformEvent::Modifiers modifierKey = PlatformEvent::CtrlKey;
271 #if OS(MACOSX) 274 #if OS(MACOSX)
272 modifierKey = PlatformEvent::MetaKey; 275 modifierKey = PlatformEvent::MetaKey;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 webView->handleInputEvent(event); 356 webView->handleInputEvent(event);
354 runPendingTasks(); 357 runPendingTasks();
355 358
356 EXPECT_EQ(WebInputEvent::GestureLongPress, testPlugin->getLastInputEventType ()); 359 EXPECT_EQ(WebInputEvent::GestureLongPress, testPlugin->getLastInputEventType ());
357 } 360 }
358 361
359 // Verify that isRectTopmost returns false when the document is detached. 362 // Verify that isRectTopmost returns false when the document is detached.
360 TEST_F(WebPluginContainerTest, IsRectTopmostTest) 363 TEST_F(WebPluginContainerTest, IsRectTopmostTest)
361 { 364 {
362 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html")); 365 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("plugin_container.html"));
366 TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper .
363 FrameTestHelpers::WebViewHelper webViewHelper; 367 FrameTestHelpers::WebViewHelper webViewHelper;
364 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, new TestPluginWebFrameClient()); 368 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta iner.html", true, &pluginWebFrameClient);
365 ASSERT(webView); 369 ASSERT(webView);
366 webView->settings()->setPluginsEnabled(true); 370 webView->settings()->setPluginsEnabled(true);
367 webView->resize(WebSize(300, 300)); 371 webView->resize(WebSize(300, 300));
368 webView->layout(); 372 webView->layout();
369 runPendingTasks(); 373 runPendingTasks();
370 374
371 RefPtrWillBeRawPtr<WebPluginContainerImpl> pluginContainerImpl = 375 RefPtrWillBeRawPtr<WebPluginContainerImpl> pluginContainerImpl =
372 toWebPluginContainerImpl(getWebPluginContainer(webView, WebString::fromU TF8("translated-plugin"))); 376 toWebPluginContainerImpl(getWebPluginContainer(webView, WebString::fromU TF8("translated-plugin")));
373 pluginContainerImpl->setFrameRect(IntRect(0, 0, 300, 300)); 377 pluginContainerImpl->setFrameRect(IntRect(0, 0, 300, 300));
374 378
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 TopmostPlugin* testPlugin = static_cast<TopmostPlugin*>(pluginContainerImpl- >plugin()); 433 TopmostPlugin* testPlugin = static_cast<TopmostPlugin*>(pluginContainerImpl- >plugin());
430 EXPECT_TRUE(testPlugin->isRectTopmost()); 434 EXPECT_TRUE(testPlugin->isRectTopmost());
431 435
432 // Cause the plugin's frame to be detached. 436 // Cause the plugin's frame to be detached.
433 webViewHelper.reset(); 437 webViewHelper.reset();
434 438
435 EXPECT_FALSE(pluginContainerImpl->isRectTopmost(topmostRect)); 439 EXPECT_FALSE(pluginContainerImpl->isRectTopmost(topmostRect));
436 } 440 }
437 441
438 } // namespace blink 442 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698