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/debug/leak_annotations.h" | 7 #include "base/debug/leak_annotations.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 MockBrowserPlugin* browser_plugin = static_cast<MockBrowserPlugin*>( | 185 MockBrowserPlugin* browser_plugin = static_cast<MockBrowserPlugin*>( |
186 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 186 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
187 | 187 |
188 BrowserPluginMsg_Attach_ACK_Params attach_ack_params; | 188 BrowserPluginMsg_Attach_ACK_Params attach_ack_params; |
189 browser_plugin->OnAttachACK(instance_id, attach_ack_params); | 189 browser_plugin->OnAttachACK(instance_id, attach_ack_params); |
190 | 190 |
191 return browser_plugin; | 191 return browser_plugin; |
192 } | 192 } |
193 | 193 |
194 // This test verifies that an initial resize occurs when we instantiate the | 194 // This test verifies that an initial resize occurs when we instantiate the |
195 // browser plugin. This test also verifies that the browser plugin is waiting | 195 // browser plugin. |
196 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and | |
197 // we observe an UpdateRect_ACK, with the |pending_damage_buffer_| reset, | |
198 // indiciating that the BrowserPlugin is not waiting for any more UpdateRects to | |
199 // satisfy its resize request. | |
200 TEST_F(BrowserPluginTest, InitialResize) { | 196 TEST_F(BrowserPluginTest, InitialResize) { |
201 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 197 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
202 // Verify that the information in Attach is correct. | 198 // Verify that the information in Attach is correct. |
203 BrowserPluginHostMsg_Attach_Params params; | 199 BrowserPluginHostMsg_Attach_Params params; |
204 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); | 200 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); |
205 | 201 |
206 EXPECT_EQ(640, params.resize_guest_params.view_rect.width()); | 202 EXPECT_EQ(640, params.resize_guest_params.view_rect.width()); |
207 EXPECT_EQ(480, params.resize_guest_params.view_rect.height()); | 203 EXPECT_EQ(480, params.resize_guest_params.view_rect.height()); |
208 ASSERT_TRUE(browser_plugin); | 204 ASSERT_TRUE(browser_plugin); |
209 // Now the browser plugin is expecting a UpdateRect resize. | |
210 int instance_id = browser_plugin->guest_instance_id(); | |
211 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); | |
212 | |
213 // Send the BrowserPlugin an UpdateRect equal to its container size with | |
214 // the same damage buffer. That should clear |pending_damage_buffer_|. | |
215 BrowserPluginMsg_UpdateRect_Params update_rect_params; | |
216 update_rect_params.damage_buffer_sequence_id = | |
217 browser_plugin->damage_buffer_sequence_id_; | |
218 update_rect_params.view_size = gfx::Size(640, 480); | |
219 update_rect_params.scale_factor = 1.0f; | |
220 update_rect_params.is_resize_ack = true; | |
221 update_rect_params.needs_ack = true; | |
222 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | |
223 browser_plugin->OnMessageReceived(msg); | |
224 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); | |
225 } | 205 } |
226 | 206 |
227 // This test verifies that all attributes (present at the time of writing) are | 207 // This test verifies that all attributes (present at the time of writing) are |
228 // parsed on initialization. However, this test does minimal checking of | 208 // parsed on initialization. However, this test does minimal checking of |
229 // correct behavior. | 209 // correct behavior. |
230 TEST_F(BrowserPluginTest, ParseAllAttributes) { | 210 TEST_F(BrowserPluginTest, ParseAllAttributes) { |
231 std::string html = base::StringPrintf(kHTMLForBrowserPluginWithAllAttributes, | 211 std::string html = base::StringPrintf(kHTMLForBrowserPluginWithAllAttributes, |
232 kBrowserPluginMimeType); | 212 kBrowserPluginMimeType); |
233 LoadHTML(html.c_str()); | 213 LoadHTML(html.c_str()); |
234 bool result; | 214 bool result; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 "document.getElementById('browserplugin').src"); | 278 "document.getElementById('browserplugin').src"); |
299 EXPECT_EQ("bar", src_value); | 279 EXPECT_EQ("bar", src_value); |
300 } | 280 } |
301 } | 281 } |
302 | 282 |
303 TEST_F(BrowserPluginTest, ResizeFlowControl) { | 283 TEST_F(BrowserPluginTest, ResizeFlowControl) { |
304 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 284 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
305 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); | 285 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); |
306 ASSERT_TRUE(browser_plugin); | 286 ASSERT_TRUE(browser_plugin); |
307 int instance_id = browser_plugin->guest_instance_id(); | 287 int instance_id = browser_plugin->guest_instance_id(); |
308 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); | 288 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a |
309 // Send an UpdateRect to the BrowserPlugin to make it use the pending damage | 289 // resize related (SetAutoSize) message. |
310 // buffer. | |
311 { | 290 { |
312 // We send a stale UpdateRect to the BrowserPlugin. | 291 // We send a stale UpdateRect to the BrowserPlugin. |
313 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 292 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
314 update_rect_params.view_size = gfx::Size(640, 480); | 293 update_rect_params.view_size = gfx::Size(640, 480); |
315 update_rect_params.scale_factor = 1.0f; | 294 update_rect_params.scale_factor = 1.0f; |
316 update_rect_params.is_resize_ack = true; | 295 update_rect_params.is_resize_ack = true; |
317 update_rect_params.needs_ack = true; | |
318 // By sending |damage_buffer_sequence_id| back to BrowserPlugin on | |
319 // UpdateRect, then the BrowserPlugin knows that the browser process has | |
320 // received and has begun to use the |pending_damage_buffer_|. | |
321 update_rect_params.damage_buffer_sequence_id = | |
322 browser_plugin->damage_buffer_sequence_id_; | |
323 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | 296 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); |
324 browser_plugin->OnMessageReceived(msg); | 297 browser_plugin->OnMessageReceived(msg); |
325 EXPECT_EQ(NULL, browser_plugin->pending_damage_buffer_.get()); | |
326 } | 298 } |
327 | 299 |
328 browser_plugin_manager()->sink().ClearMessages(); | 300 browser_plugin_manager()->sink().ClearMessages(); |
329 | 301 |
330 // Resize the browser plugin three times. | 302 // Resize the browser plugin three times. |
331 | 303 |
332 ExecuteJavaScript("document.getElementById('browserplugin').width = '641px'"); | 304 ExecuteJavaScript("document.getElementById('browserplugin').width = '641px'"); |
333 GetMainFrame()->view()->layout(); | 305 GetMainFrame()->view()->layout(); |
334 ProcessPendingMessages(); | 306 ProcessPendingMessages(); |
335 | 307 |
(...skipping 17 matching lines...) Expand all Loading... |
353 EXPECT_EQ(msg->type(), BrowserPluginHostMsg_UpdateGeometry::ID); | 325 EXPECT_EQ(msg->type(), BrowserPluginHostMsg_UpdateGeometry::ID); |
354 } | 326 } |
355 const IPC::Message* msg = | 327 const IPC::Message* msg = |
356 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 328 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
357 BrowserPluginHostMsg_ResizeGuest::ID); | 329 BrowserPluginHostMsg_ResizeGuest::ID); |
358 ASSERT_TRUE(msg); | 330 ASSERT_TRUE(msg); |
359 BrowserPluginHostMsg_ResizeGuest_Params params; | 331 BrowserPluginHostMsg_ResizeGuest_Params params; |
360 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 332 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); |
361 EXPECT_EQ(641, params.view_rect.width()); | 333 EXPECT_EQ(641, params.view_rect.width()); |
362 EXPECT_EQ(480, params.view_rect.height()); | 334 EXPECT_EQ(480, params.view_rect.height()); |
363 // This indicates that the BrowserPlugin has sent out a previous resize | |
364 // request but has not yet received an UpdateRect for that request. | |
365 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); | |
366 | 335 |
367 { | 336 { |
368 // We send a stale UpdateRect to the BrowserPlugin. | 337 // We send a stale UpdateRect to the BrowserPlugin. |
369 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 338 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
370 update_rect_params.view_size = gfx::Size(641, 480); | 339 update_rect_params.view_size = gfx::Size(641, 480); |
371 update_rect_params.scale_factor = 1.0f; | 340 update_rect_params.scale_factor = 1.0f; |
372 update_rect_params.is_resize_ack = true; | 341 update_rect_params.is_resize_ack = true; |
373 update_rect_params.needs_ack = true; | |
374 update_rect_params.damage_buffer_sequence_id = | |
375 browser_plugin->damage_buffer_sequence_id_; | |
376 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | 342 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); |
377 browser_plugin->OnMessageReceived(msg); | 343 browser_plugin->OnMessageReceived(msg); |
378 // This tells us that the BrowserPlugin is still expecting another | |
379 // UpdateRect with the most recent size. | |
380 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); | |
381 } | 344 } |
382 // Send the BrowserPlugin another UpdateRect, but this time with a size | 345 // Send the BrowserPlugin another UpdateRect, but this time with a size |
383 // that matches the size of the container. | 346 // that matches the size of the container. |
384 { | 347 { |
385 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 348 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
386 update_rect_params.view_size = gfx::Size(643, 480); | 349 update_rect_params.view_size = gfx::Size(643, 480); |
387 update_rect_params.scale_factor = 1.0f; | 350 update_rect_params.scale_factor = 1.0f; |
388 update_rect_params.is_resize_ack = true; | 351 update_rect_params.is_resize_ack = true; |
389 update_rect_params.needs_ack = true; | |
390 update_rect_params.damage_buffer_sequence_id = | |
391 browser_plugin->damage_buffer_sequence_id_; | |
392 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | 352 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); |
393 browser_plugin->OnMessageReceived(msg); | 353 browser_plugin->OnMessageReceived(msg); |
394 // The BrowserPlugin has finally received an UpdateRect that satisifes | |
395 // its current size, and so it is happy. | |
396 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); | |
397 } | 354 } |
398 } | 355 } |
399 | 356 |
400 TEST_F(BrowserPluginTest, RemovePlugin) { | 357 TEST_F(BrowserPluginTest, RemovePlugin) { |
401 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 358 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
402 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 359 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
403 BrowserPluginHostMsg_PluginDestroyed::ID)); | 360 BrowserPluginHostMsg_PluginDestroyed::ID)); |
404 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 361 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
405 "x.parentNode.removeChild(x);"); | 362 "x.parentNode.removeChild(x);"); |
406 ProcessPendingMessages(); | 363 ProcessPendingMessages(); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 MockBrowserPlugin* browser_plugin = | 544 MockBrowserPlugin* browser_plugin = |
588 GetCurrentPluginWithAttachParams(¶ms); | 545 GetCurrentPluginWithAttachParams(¶ms); |
589 ASSERT_TRUE(browser_plugin); | 546 ASSERT_TRUE(browser_plugin); |
590 | 547 |
591 EXPECT_TRUE(params.auto_size_params.enable); | 548 EXPECT_TRUE(params.auto_size_params.enable); |
592 EXPECT_EQ(42, params.auto_size_params.min_size.width()); | 549 EXPECT_EQ(42, params.auto_size_params.min_size.width()); |
593 EXPECT_EQ(43, params.auto_size_params.min_size.height()); | 550 EXPECT_EQ(43, params.auto_size_params.min_size.height()); |
594 EXPECT_EQ(1337, params.auto_size_params.max_size.width()); | 551 EXPECT_EQ(1337, params.auto_size_params.max_size.width()); |
595 EXPECT_EQ(1338, params.auto_size_params.max_size.height()); | 552 EXPECT_EQ(1338, params.auto_size_params.max_size.height()); |
596 | 553 |
597 // Verify that we are waiting for the browser process to grab the new | |
598 // damage buffer. | |
599 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); | |
600 // Disable autosize. AutoSize state will not be sent to the guest until | 554 // Disable autosize. AutoSize state will not be sent to the guest until |
601 // the guest has responded to the last resize request. | 555 // the guest has responded to the last resize request. |
602 ExecuteJavaScript(kDisableAutoSize); | 556 ExecuteJavaScript(kDisableAutoSize); |
603 ProcessPendingMessages(); | 557 ProcessPendingMessages(); |
604 | 558 |
605 const IPC::Message* auto_size_msg = | 559 const IPC::Message* auto_size_msg = |
606 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 560 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
607 BrowserPluginHostMsg_SetAutoSize::ID); | 561 BrowserPluginHostMsg_SetAutoSize::ID); |
608 EXPECT_FALSE(auto_size_msg); | 562 EXPECT_FALSE(auto_size_msg); |
609 | 563 |
610 // Send the BrowserPlugin an UpdateRect equal to its |max_size| with | 564 // Send the BrowserPlugin an UpdateRect equal to its |max_size|. |
611 // the same damage buffer. | |
612 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 565 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
613 update_rect_params.damage_buffer_sequence_id = | |
614 browser_plugin->damage_buffer_sequence_id_; | |
615 update_rect_params.view_size = gfx::Size(1337, 1338); | 566 update_rect_params.view_size = gfx::Size(1337, 1338); |
616 update_rect_params.scale_factor = 1.0f; | 567 update_rect_params.scale_factor = 1.0f; |
617 update_rect_params.is_resize_ack = true; | 568 update_rect_params.is_resize_ack = true; |
618 update_rect_params.needs_ack = true; | |
619 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | 569 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); |
620 browser_plugin->OnMessageReceived(msg); | 570 browser_plugin->OnMessageReceived(msg); |
621 | 571 |
622 // Verify that the autosize state has been updated. | 572 // Verify that the autosize state has been updated. |
623 { | 573 { |
624 const IPC::Message* auto_size_msg = | 574 const IPC::Message* auto_size_msg = |
625 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 575 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
626 BrowserPluginHostMsg_UpdateRect_ACK::ID); | 576 BrowserPluginHostMsg_SetAutoSize::ID); |
627 ASSERT_TRUE(auto_size_msg); | 577 ASSERT_TRUE(auto_size_msg); |
628 | 578 |
629 int instance_id = 0; | 579 int instance_id = 0; |
630 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 580 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
631 BrowserPluginHostMsg_ResizeGuest_Params resize_params; | 581 BrowserPluginHostMsg_ResizeGuest_Params resize_params; |
632 BrowserPluginHostMsg_UpdateRect_ACK::Read(auto_size_msg, | 582 BrowserPluginHostMsg_SetAutoSize::Read(auto_size_msg, |
633 &instance_id, | 583 &instance_id, |
634 &auto_size_params, | 584 &auto_size_params, |
635 &resize_params); | 585 &resize_params); |
636 EXPECT_FALSE(auto_size_params.enable); | 586 EXPECT_FALSE(auto_size_params.enable); |
637 // These value are not populated (as an optimization) if autosize is | 587 // These value are not populated (as an optimization) if autosize is |
638 // disabled. | 588 // disabled. |
639 EXPECT_EQ(0, auto_size_params.min_size.width()); | 589 EXPECT_EQ(0, auto_size_params.min_size.width()); |
640 EXPECT_EQ(0, auto_size_params.min_size.height()); | 590 EXPECT_EQ(0, auto_size_params.min_size.height()); |
641 EXPECT_EQ(0, auto_size_params.max_size.width()); | 591 EXPECT_EQ(0, auto_size_params.max_size.width()); |
642 EXPECT_EQ(0, auto_size_params.max_size.height()); | 592 EXPECT_EQ(0, auto_size_params.max_size.height()); |
643 } | 593 } |
644 } | 594 } |
645 | 595 |
646 } // namespace content | 596 } // namespace content |
OLD | NEW |