| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 166 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 167 // Verify that the information in Attach is correct. | 167 // Verify that the information in Attach is correct. |
| 168 BrowserPluginHostMsg_Attach_Params params; | 168 BrowserPluginHostMsg_Attach_Params params; |
| 169 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); | 169 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); |
| 170 | 170 |
| 171 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); | 171 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); |
| 172 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); | 172 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); |
| 173 ASSERT_TRUE(browser_plugin); | 173 ASSERT_TRUE(browser_plugin); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST_F(BrowserPluginTest, ResizeFlowControl) { | |
| 177 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | |
| 178 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); | |
| 179 ASSERT_TRUE(browser_plugin); | |
| 180 int instance_id = browser_plugin->browser_plugin_instance_id(); | |
| 181 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a | |
| 182 // resize related (SetAutoSize) message. | |
| 183 { | |
| 184 // We send a stale UpdateRect to the BrowserPlugin. | |
| 185 BrowserPluginMsg_UpdateRect_Params update_rect_params; | |
| 186 update_rect_params.view_size = gfx::Size(640, 480); | |
| 187 update_rect_params.is_resize_ack = true; | |
| 188 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | |
| 189 browser_plugin->OnMessageReceived(msg); | |
| 190 } | |
| 191 | |
| 192 browser_plugin_manager()->sink().ClearMessages(); | |
| 193 | |
| 194 // Resize the browser plugin three times. | |
| 195 | |
| 196 ExecuteJavaScript("document.getElementById('browserplugin').width = '641px'"); | |
| 197 GetMainFrame()->view()->layout(); | |
| 198 ProcessPendingMessages(); | |
| 199 | |
| 200 ExecuteJavaScript("document.getElementById('browserplugin').width = '642px'"); | |
| 201 GetMainFrame()->view()->layout(); | |
| 202 ProcessPendingMessages(); | |
| 203 | |
| 204 ExecuteJavaScript("document.getElementById('browserplugin').width = '643px'"); | |
| 205 GetMainFrame()->view()->layout(); | |
| 206 ProcessPendingMessages(); | |
| 207 | |
| 208 // Expect to see one resize messsage in the sink. BrowserPlugin will not issue | |
| 209 // subsequent resize requests until the first request is satisfied by the | |
| 210 // guest. The rest of the messages could be | |
| 211 // BrowserPluginHostMsg_UpdateGeometry msgs. | |
| 212 EXPECT_LE(1u, browser_plugin_manager()->sink().message_count()); | |
| 213 for (size_t i = 0; i < browser_plugin_manager()->sink().message_count(); | |
| 214 ++i) { | |
| 215 const IPC::Message* msg = browser_plugin_manager()->sink().GetMessageAt(i); | |
| 216 if (msg->type() != BrowserPluginHostMsg_ResizeGuest::ID) | |
| 217 EXPECT_EQ(msg->type(), BrowserPluginHostMsg_UpdateGeometry::ID); | |
| 218 } | |
| 219 const IPC::Message* msg = | |
| 220 browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
| 221 BrowserPluginHostMsg_ResizeGuest::ID); | |
| 222 ASSERT_TRUE(msg); | |
| 223 BrowserPluginHostMsg_ResizeGuest::Param param; | |
| 224 BrowserPluginHostMsg_ResizeGuest::Read(msg, ¶m); | |
| 225 instance_id = param.a; | |
| 226 BrowserPluginHostMsg_ResizeGuest_Params params = param.b; | |
| 227 EXPECT_EQ(641, params.view_size.width()); | |
| 228 EXPECT_EQ(480, params.view_size.height()); | |
| 229 | |
| 230 { | |
| 231 // We send a stale UpdateRect to the BrowserPlugin. | |
| 232 BrowserPluginMsg_UpdateRect_Params update_rect_params; | |
| 233 update_rect_params.view_size = gfx::Size(641, 480); | |
| 234 update_rect_params.is_resize_ack = true; | |
| 235 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | |
| 236 browser_plugin->OnMessageReceived(msg); | |
| 237 } | |
| 238 // Send the BrowserPlugin another UpdateRect, but this time with a size | |
| 239 // that matches the size of the container. | |
| 240 { | |
| 241 BrowserPluginMsg_UpdateRect_Params update_rect_params; | |
| 242 update_rect_params.view_size = gfx::Size(643, 480); | |
| 243 update_rect_params.is_resize_ack = true; | |
| 244 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | |
| 245 browser_plugin->OnMessageReceived(msg); | |
| 246 } | |
| 247 } | |
| 248 | |
| 249 TEST_F(BrowserPluginTest, RemovePlugin) { | 176 TEST_F(BrowserPluginTest, RemovePlugin) { |
| 250 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 177 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 251 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); | 178 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); |
| 252 ASSERT_TRUE(browser_plugin); | 179 ASSERT_TRUE(browser_plugin); |
| 253 | 180 |
| 254 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 181 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 255 BrowserPluginHostMsg_PluginDestroyed::ID)); | 182 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 256 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 183 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
| 257 "x.parentNode.removeChild(x);"); | 184 "x.parentNode.removeChild(x);"); |
| 258 ProcessPendingMessages(); | 185 ProcessPendingMessages(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 269 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 196 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 270 BrowserPluginHostMsg_PluginDestroyed::ID)); | 197 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 271 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 198 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
| 272 "x.parentNode.removeChild(x);"); | 199 "x.parentNode.removeChild(x);"); |
| 273 ProcessPendingMessages(); | 200 ProcessPendingMessages(); |
| 274 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 201 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 275 BrowserPluginHostMsg_PluginDestroyed::ID)); | 202 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 276 } | 203 } |
| 277 | 204 |
| 278 } // namespace content | 205 } // namespace content |
| OLD | NEW |