Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / renderer / browser_plugin / browser_plugin_browsertest.cc
index 0d2ed73..f277994 100644 (file)
@@ -4,11 +4,13 @@
 
 #include "content/renderer/browser_plugin/browser_plugin_browsertest.h"
 
+#include "base/debug/leak_annotations.h"
 #include "base/files/file_path.h"
 #include "base/memory/singleton.h"
 #include "base/path_service.h"
 #include "base/pickle.h"
 #include "content/public/common/content_constants.h"
+#include "content/public/renderer/content_renderer_client.h"
 #include "content/renderer/browser_plugin/browser_plugin.h"
 #include "content/renderer/browser_plugin/browser_plugin_manager_factory.h"
 #include "content/renderer/browser_plugin/mock_browser_plugin.h"
 #include "skia/ext/platform_canvas.h"
 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
 #include "third_party/WebKit/public/web/WebInputEvent.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
 #include "third_party/WebKit/public/web/WebScriptSource.h"
 
+namespace content {
+
 namespace {
 const char kHTMLForBrowserPluginObject[] =
     "<object id='browserplugin' width='640px' height='480px'"
@@ -48,13 +53,11 @@ const char kHTMLForPartitionedPersistedPluginObject[] =
 
 std::string GetHTMLForBrowserPluginObject() {
   return base::StringPrintf(kHTMLForBrowserPluginObject,
-                            content::kBrowserPluginMimeType);
+                            kBrowserPluginMimeType);
 }
 
 }  // namespace
 
-namespace content {
-
 class TestContentRendererClient : public ContentRendererClient {
  public:
   TestContentRendererClient() : ContentRendererClient() {
@@ -97,8 +100,6 @@ BrowserPluginTest::BrowserPluginTest() {}
 BrowserPluginTest::~BrowserPluginTest() {}
 
 void BrowserPluginTest::SetUp() {
-  test_content_renderer_client_.reset(new TestContentRendererClient);
-  SetRendererClientForTesting(test_content_renderer_client_.get());
   BrowserPluginManager::set_factory_for_testing(
       TestBrowserPluginManagerFactory::GetInstance());
   content::RenderViewTest::SetUp();
@@ -107,8 +108,16 @@ void BrowserPluginTest::SetUp() {
 void BrowserPluginTest::TearDown() {
   BrowserPluginManager::set_factory_for_testing(
       TestBrowserPluginManagerFactory::GetInstance());
-  content::RenderViewTest::TearDown();
-  test_content_renderer_client_.reset();
+#if defined(LEAK_SANITIZER)
+  // Do this before shutting down V8 in RenderViewTest::TearDown().
+  // http://crbug.com/328552
+  __lsan_do_leak_check();
+#endif
+  RenderViewTest::TearDown();
+}
+
+ContentRendererClient* BrowserPluginTest::CreateContentRendererClient() {
+  return new TestContentRendererClient;
 }
 
 std::string BrowserPluginTest::ExecuteScriptAndReturnString(
@@ -183,11 +192,7 @@ MockBrowserPlugin* BrowserPluginTest::GetCurrentPluginWithAttachParams(
 }
 
 // This test verifies that an initial resize occurs when we instantiate the
-// browser plugin. This test also verifies that the browser plugin is waiting
-// for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and
-// we observe an UpdateRect_ACK, with the |pending_damage_buffer_| reset,
-// indiciating that the BrowserPlugin is not waiting for any more UpdateRects to
-// satisfy its resize request.
+// browser plugin.
 TEST_F(BrowserPluginTest, InitialResize) {
   LoadHTML(GetHTMLForBrowserPluginObject().c_str());
   // Verify that the information in Attach is correct.
@@ -197,22 +202,6 @@ TEST_F(BrowserPluginTest, InitialResize) {
   EXPECT_EQ(640, params.resize_guest_params.view_rect.width());
   EXPECT_EQ(480, params.resize_guest_params.view_rect.height());
   ASSERT_TRUE(browser_plugin);
-  // Now the browser plugin is expecting a UpdateRect resize.
-  int instance_id = browser_plugin->guest_instance_id();
-  EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
-
-  // Send the BrowserPlugin an UpdateRect equal to its container size with
-  // the same damage buffer. That should clear |pending_damage_buffer_|.
-  BrowserPluginMsg_UpdateRect_Params update_rect_params;
-  update_rect_params.damage_buffer_sequence_id =
-      browser_plugin->damage_buffer_sequence_id_;
-  update_rect_params.view_size = gfx::Size(640, 480);
-  update_rect_params.scale_factor = 1.0f;
-  update_rect_params.is_resize_ack = true;
-  update_rect_params.needs_ack = true;
-  BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
-  browser_plugin->OnMessageReceived(msg);
-  EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get());
 }
 
 // This test verifies that all attributes (present at the time of writing) are
@@ -220,7 +209,7 @@ TEST_F(BrowserPluginTest, InitialResize) {
 // correct behavior.
 TEST_F(BrowserPluginTest, ParseAllAttributes) {
   std::string html = base::StringPrintf(kHTMLForBrowserPluginWithAllAttributes,
-                                        content::kBrowserPluginMimeType);
+                                        kBrowserPluginMimeType);
   LoadHTML(html.c_str());
   bool result;
   bool has_value = ExecuteScriptAndReturnBool(
@@ -296,24 +285,16 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
   MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
   ASSERT_TRUE(browser_plugin);
   int instance_id = browser_plugin->guest_instance_id();
-  EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
-  // Send an UpdateRect to the BrowserPlugin to make it use the pending damage
-  // buffer.
+  // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a
+  // resize related (SetAutoSize) message.
   {
     // We send a stale UpdateRect to the BrowserPlugin.
     BrowserPluginMsg_UpdateRect_Params update_rect_params;
     update_rect_params.view_size = gfx::Size(640, 480);
     update_rect_params.scale_factor = 1.0f;
     update_rect_params.is_resize_ack = true;
-    update_rect_params.needs_ack = true;
-    // By sending |damage_buffer_sequence_id| back to BrowserPlugin on
-    // UpdateRect, then the BrowserPlugin knows that the browser process has
-    // received and has begun to use the |pending_damage_buffer_|.
-    update_rect_params.damage_buffer_sequence_id =
-        browser_plugin->damage_buffer_sequence_id_;
     BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
     browser_plugin->OnMessageReceived(msg);
-    EXPECT_EQ(NULL, browser_plugin->pending_damage_buffer_.get());
   }
 
   browser_plugin_manager()->sink().ClearMessages();
@@ -351,9 +332,6 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
   BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params);
   EXPECT_EQ(641, params.view_rect.width());
   EXPECT_EQ(480, params.view_rect.height());
-  // This indicates that the BrowserPlugin has sent out a previous resize
-  // request but has not yet received an UpdateRect for that request.
-  EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
 
   {
     // We send a stale UpdateRect to the BrowserPlugin.
@@ -361,14 +339,8 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
     update_rect_params.view_size = gfx::Size(641, 480);
     update_rect_params.scale_factor = 1.0f;
     update_rect_params.is_resize_ack = true;
-    update_rect_params.needs_ack = true;
-    update_rect_params.damage_buffer_sequence_id =
-        browser_plugin->damage_buffer_sequence_id_;
     BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
     browser_plugin->OnMessageReceived(msg);
-    // This tells us that the BrowserPlugin is still expecting another
-    // UpdateRect with the most recent size.
-    EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
   }
   // Send the BrowserPlugin another UpdateRect, but this time with a size
   // that matches the size of the container.
@@ -377,14 +349,8 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
     update_rect_params.view_size = gfx::Size(643, 480);
     update_rect_params.scale_factor = 1.0f;
     update_rect_params.is_resize_ack = true;
-    update_rect_params.needs_ack = true;
-    update_rect_params.damage_buffer_sequence_id =
-        browser_plugin->damage_buffer_sequence_id_;
     BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
     browser_plugin->OnMessageReceived(msg);
-    // The BrowserPlugin has finally received an UpdateRect that satisifes
-    // its current size, and so it is happy.
-    EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get());
   }
 }
 
@@ -403,7 +369,7 @@ TEST_F(BrowserPluginTest, RemovePlugin) {
 // BrowserPlugin that has never navigated.
 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) {
   std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
-                                        content::kBrowserPluginMimeType);
+                                        kBrowserPluginMimeType);
   LoadHTML(html.c_str());
   EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
       BrowserPluginHostMsg_PluginDestroyed::ID));
@@ -418,14 +384,14 @@ TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) {
 // correctly.
 TEST_F(BrowserPluginTest, PartitionAttribute) {
   std::string html = base::StringPrintf(kHTMLForPartitionedPluginObject,
-                                        content::kBrowserPluginMimeType);
+                                        kBrowserPluginMimeType);
   LoadHTML(html.c_str());
   std::string partition_value = ExecuteScriptAndReturnString(
       "document.getElementById('browserplugin').partition");
   EXPECT_STREQ("someid", partition_value.c_str());
 
   html = base::StringPrintf(kHTMLForPartitionedPersistedPluginObject,
-                            content::kBrowserPluginMimeType);
+                            kBrowserPluginMimeType);
   LoadHTML(html.c_str());
   partition_value = ExecuteScriptAndReturnString(
       "document.getElementById('browserplugin').partition");
@@ -445,7 +411,7 @@ TEST_F(BrowserPluginTest, PartitionAttribute) {
 
   // Load a browser tag without 'src' defined.
   html = base::StringPrintf(kHTMLForSourcelessPluginObject,
-                            content::kBrowserPluginMimeType);
+                            kBrowserPluginMimeType);
   LoadHTML(html.c_str());
 
   // Ensure we don't parse just "persist:" string and return exception.
@@ -462,7 +428,7 @@ TEST_F(BrowserPluginTest, PartitionAttribute) {
 // partition attribute is invalid.
 TEST_F(BrowserPluginTest, InvalidPartition) {
   std::string html = base::StringPrintf(kHTMLForInvalidPartitionedPluginObject,
-                                        content::kBrowserPluginMimeType);
+                                        kBrowserPluginMimeType);
   LoadHTML(html.c_str());
   // Attempt to navigate with an invalid partition.
   {
@@ -508,7 +474,7 @@ TEST_F(BrowserPluginTest, InvalidPartition) {
 // cannot be modified.
 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) {
   std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
-                                        content::kBrowserPluginMimeType);
+                                        kBrowserPluginMimeType);
   LoadHTML(html.c_str());
 
   ExecuteJavaScript(
@@ -554,7 +520,7 @@ TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) {
 
 TEST_F(BrowserPluginTest, AutoSizeAttributes) {
   std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
-                                        content::kBrowserPluginMimeType);
+                                        kBrowserPluginMimeType);
   LoadHTML(html.c_str());
   const char* kSetAutoSizeParametersAndNavigate =
     "var browserplugin = document.getElementById('browserplugin');"
@@ -585,9 +551,6 @@ TEST_F(BrowserPluginTest, AutoSizeAttributes) {
   EXPECT_EQ(1337, params.auto_size_params.max_size.width());
   EXPECT_EQ(1338, params.auto_size_params.max_size.height());
 
-  // Verify that we are waiting for the browser process to grab the new
-  // damage buffer.
-  EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
   // Disable autosize. AutoSize state will not be sent to the guest until
   // the guest has responded to the last resize request.
   ExecuteJavaScript(kDisableAutoSize);
@@ -598,34 +561,28 @@ TEST_F(BrowserPluginTest, AutoSizeAttributes) {
       BrowserPluginHostMsg_SetAutoSize::ID);
   EXPECT_FALSE(auto_size_msg);
 
-  // Send the BrowserPlugin an UpdateRect equal to its |max_size| with
-  // the same damage buffer.
+  // Send the BrowserPlugin an UpdateRect equal to its |max_size|.
   BrowserPluginMsg_UpdateRect_Params update_rect_params;
-  update_rect_params.damage_buffer_sequence_id =
-      browser_plugin->damage_buffer_sequence_id_;
   update_rect_params.view_size = gfx::Size(1337, 1338);
   update_rect_params.scale_factor = 1.0f;
   update_rect_params.is_resize_ack = true;
-  update_rect_params.needs_ack = true;
   BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
   browser_plugin->OnMessageReceived(msg);
 
   // Verify that the autosize state has been updated.
   {
     const IPC::Message* auto_size_msg =
-    browser_plugin_manager()->sink().GetUniqueMessageMatching(
-        BrowserPluginHostMsg_UpdateRect_ACK::ID);
+        browser_plugin_manager()->sink().GetUniqueMessageMatching(
+            BrowserPluginHostMsg_SetAutoSize::ID);
     ASSERT_TRUE(auto_size_msg);
 
     int instance_id = 0;
-    bool needs_ack = false;
     BrowserPluginHostMsg_AutoSize_Params auto_size_params;
     BrowserPluginHostMsg_ResizeGuest_Params resize_params;
-    BrowserPluginHostMsg_UpdateRect_ACK::Read(auto_size_msg,
-                                              &instance_id,
-                                              &needs_ack,
-                                              &auto_size_params,
-                                              &resize_params);
+    BrowserPluginHostMsg_SetAutoSize::Read(auto_size_msg,
+                                           &instance_id,
+                                           &auto_size_params,
+                                           &resize_params);
     EXPECT_FALSE(auto_size_params.enable);
     // These value are not populated (as an optimization) if autosize is
     // disabled.