| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 137 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); |
| 138 EXPECT_EQ(640, params.view_size.width()); | 138 EXPECT_EQ(640, params.view_size.width()); |
| 139 EXPECT_EQ(480, params.view_size.height()); | 139 EXPECT_EQ(480, params.view_size.height()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 MockBrowserPlugin* browser_plugin = | 142 MockBrowserPlugin* browser_plugin = |
| 143 static_cast<MockBrowserPlugin*>( | 143 static_cast<MockBrowserPlugin*>( |
| 144 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 144 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 145 ASSERT_TRUE(browser_plugin); | 145 ASSERT_TRUE(browser_plugin); |
| 146 // Now the browser plugin is expecting a UpdateRect resize. | 146 // Now the browser plugin is expecting a UpdateRect resize. |
| 147 EXPECT_TRUE(browser_plugin->pending_damage_buffer_); | 147 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); |
| 148 | 148 |
| 149 // Send the BrowserPlugin an UpdateRect equal to its container size with | 149 // Send the BrowserPlugin an UpdateRect equal to its container size with |
| 150 // the same damage buffer. That should clear |pending_damage_buffer_|. | 150 // the same damage buffer. That should clear |pending_damage_buffer_|. |
| 151 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 151 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
| 152 update_rect_params.damage_buffer_identifier = | 152 update_rect_params.damage_buffer_sequence_id = |
| 153 #if defined(OS_MACOSX) | 153 browser_plugin->damage_buffer_sequence_id_; |
| 154 browser_plugin->pending_damage_buffer_->id(); | |
| 155 #else | |
| 156 browser_plugin->pending_damage_buffer_->handle(); | |
| 157 #endif | |
| 158 update_rect_params.view_size = gfx::Size(640, 480); | 154 update_rect_params.view_size = gfx::Size(640, 480); |
| 159 update_rect_params.scale_factor = 1.0f; | 155 update_rect_params.scale_factor = 1.0f; |
| 160 update_rect_params.is_resize_ack = true; | 156 update_rect_params.is_resize_ack = true; |
| 161 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); | 157 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); |
| 162 browser_plugin->OnMessageReceived(msg); | 158 browser_plugin->OnMessageReceived(msg); |
| 163 EXPECT_FALSE(browser_plugin->pending_damage_buffer_); | 159 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); |
| 164 } | 160 } |
| 165 | 161 |
| 166 // Verify that the src attribute on the browser plugin works as expected. | 162 // Verify that the src attribute on the browser plugin works as expected. |
| 167 TEST_F(BrowserPluginTest, SrcAttribute) { | 163 TEST_F(BrowserPluginTest, SrcAttribute) { |
| 168 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 164 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 169 // Verify that we're reporting the correct URL to navigate to based on the | 165 // Verify that we're reporting the correct URL to navigate to based on the |
| 170 // src attribute. | 166 // src attribute. |
| 171 { | 167 { |
| 172 // Ensure we get a CreateGuest on the initial navigation. | 168 // Ensure we get a CreateGuest on the initial navigation. |
| 173 const IPC::Message* create_msg = | 169 const IPC::Message* create_msg = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 const IPC::Message* nav_msg = | 220 const IPC::Message* nav_msg = |
| 225 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 221 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 226 BrowserPluginHostMsg_NavigateGuest::ID); | 222 BrowserPluginHostMsg_NavigateGuest::ID); |
| 227 ASSERT_TRUE(nav_msg); | 223 ASSERT_TRUE(nav_msg); |
| 228 BrowserPluginHostMsg_NavigateGuest::Read(nav_msg, &instance_id, &src); | 224 BrowserPluginHostMsg_NavigateGuest::Read(nav_msg, &instance_id, &src); |
| 229 } | 225 } |
| 230 MockBrowserPlugin* browser_plugin = | 226 MockBrowserPlugin* browser_plugin = |
| 231 static_cast<MockBrowserPlugin*>( | 227 static_cast<MockBrowserPlugin*>( |
| 232 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 228 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 233 ASSERT_TRUE(browser_plugin); | 229 ASSERT_TRUE(browser_plugin); |
| 234 EXPECT_TRUE(browser_plugin->pending_damage_buffer_); | 230 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); |
| 235 // Send an UpdateRect to the BrowserPlugin to make it use the pending damage | 231 // Send an UpdateRect to the BrowserPlugin to make it use the pending damage |
| 236 // buffer. | 232 // buffer. |
| 237 { | 233 { |
| 238 // We send a stale UpdateRect to the BrowserPlugin. | 234 // We send a stale UpdateRect to the BrowserPlugin. |
| 239 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 235 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
| 240 update_rect_params.view_size = gfx::Size(640, 480); | 236 update_rect_params.view_size = gfx::Size(640, 480); |
| 241 update_rect_params.scale_factor = 1.0f; | 237 update_rect_params.scale_factor = 1.0f; |
| 242 update_rect_params.is_resize_ack = true; | 238 update_rect_params.is_resize_ack = true; |
| 243 // By sending the damage buffer handle back to BrowserPlugin on UpdateRect, | 239 // By sending |damage_buffer_sequence_id| back to BrowserPlugin on |
| 244 // then the BrowserPlugin knows that the browser process has received and | 240 // UpdateRect, then the BrowserPlugin knows that the browser process has |
| 245 // has begun to use the pending_damage_buffer. | 241 // received and has begun to use the |pending_damage_buffer_|. |
| 246 update_rect_params.damage_buffer_identifier = | 242 update_rect_params.damage_buffer_sequence_id = |
| 247 #if defined(OS_MACOSX) | 243 browser_plugin->damage_buffer_sequence_id_; |
| 248 browser_plugin->pending_damage_buffer_->id(); | |
| 249 #else | |
| 250 browser_plugin->pending_damage_buffer_->handle(); | |
| 251 #endif | |
| 252 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); | 244 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); |
| 253 browser_plugin->OnMessageReceived(msg); | 245 browser_plugin->OnMessageReceived(msg); |
| 254 EXPECT_EQ(NULL, browser_plugin->pending_damage_buffer_); | 246 EXPECT_EQ(NULL, browser_plugin->pending_damage_buffer_.get()); |
| 255 } | 247 } |
| 256 | 248 |
| 257 browser_plugin_manager()->sink().ClearMessages(); | 249 browser_plugin_manager()->sink().ClearMessages(); |
| 258 | 250 |
| 259 // Resize the browser plugin three times. | 251 // Resize the browser plugin three times. |
| 260 ExecuteJavaScript("document.getElementById('browserplugin').width = '641px'"); | 252 ExecuteJavaScript("document.getElementById('browserplugin').width = '641px'"); |
| 261 ProcessPendingMessages(); | 253 ProcessPendingMessages(); |
| 262 ExecuteJavaScript("document.getElementById('browserplugin').width = '642px'"); | 254 ExecuteJavaScript("document.getElementById('browserplugin').width = '642px'"); |
| 263 ProcessPendingMessages(); | 255 ProcessPendingMessages(); |
| 264 ExecuteJavaScript("document.getElementById('browserplugin').width = '643px'"); | 256 ExecuteJavaScript("document.getElementById('browserplugin').width = '643px'"); |
| 265 ProcessPendingMessages(); | 257 ProcessPendingMessages(); |
| 266 | 258 |
| 267 // Expect to see one messsage in the sink. BrowserPlugin will not issue | 259 // Expect to see one messsage in the sink. BrowserPlugin will not issue |
| 268 // subsequent resize requests until the first request is satisfied by the | 260 // subsequent resize requests until the first request is satisfied by the |
| 269 // guest. | 261 // guest. |
| 270 EXPECT_EQ(1u, browser_plugin_manager()->sink().message_count()); | 262 EXPECT_EQ(1u, browser_plugin_manager()->sink().message_count()); |
| 271 const IPC::Message* msg = | 263 const IPC::Message* msg = |
| 272 browser_plugin_manager()->sink().GetFirstMessageMatching( | 264 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 273 BrowserPluginHostMsg_ResizeGuest::ID); | 265 BrowserPluginHostMsg_ResizeGuest::ID); |
| 274 ASSERT_TRUE(msg); | 266 ASSERT_TRUE(msg); |
| 275 BrowserPluginHostMsg_ResizeGuest_Params params; | 267 BrowserPluginHostMsg_ResizeGuest_Params params; |
| 276 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 268 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); |
| 277 EXPECT_EQ(641, params.view_size.width()); | 269 EXPECT_EQ(641, params.view_size.width()); |
| 278 EXPECT_EQ(480, params.view_size.height()); | 270 EXPECT_EQ(480, params.view_size.height()); |
| 279 // This indicates that the BrowserPlugin has sent out a previous resize | 271 // This indicates that the BrowserPlugin has sent out a previous resize |
| 280 // request but has not yet received an UpdateRect for that request. | 272 // request but has not yet received an UpdateRect for that request. |
| 281 EXPECT_TRUE(browser_plugin->pending_damage_buffer_); | 273 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); |
| 282 | 274 |
| 283 { | 275 { |
| 284 // We send a stale UpdateRect to the BrowserPlugin. | 276 // We send a stale UpdateRect to the BrowserPlugin. |
| 285 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 277 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
| 286 update_rect_params.view_size = gfx::Size(641, 480); | 278 update_rect_params.view_size = gfx::Size(641, 480); |
| 287 update_rect_params.scale_factor = 1.0f; | 279 update_rect_params.scale_factor = 1.0f; |
| 288 update_rect_params.is_resize_ack = true; | 280 update_rect_params.is_resize_ack = true; |
| 289 update_rect_params.damage_buffer_identifier = | 281 update_rect_params.damage_buffer_sequence_id = |
| 290 #if defined(OS_MACOSX) | 282 browser_plugin->damage_buffer_sequence_id_; |
| 291 browser_plugin->pending_damage_buffer_->id(); | |
| 292 #else | |
| 293 browser_plugin->pending_damage_buffer_->handle(); | |
| 294 #endif | |
| 295 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); | 283 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); |
| 296 browser_plugin->OnMessageReceived(msg); | 284 browser_plugin->OnMessageReceived(msg); |
| 297 // This tells us that the BrowserPlugin is still expecting another | 285 // This tells us that the BrowserPlugin is still expecting another |
| 298 // UpdateRect with the most recent size. | 286 // UpdateRect with the most recent size. |
| 299 EXPECT_TRUE(browser_plugin->pending_damage_buffer_); | 287 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); |
| 300 } | 288 } |
| 301 // Send the BrowserPlugin another UpdateRect, but this time with a size | 289 // Send the BrowserPlugin another UpdateRect, but this time with a size |
| 302 // that matches the size of the container. | 290 // that matches the size of the container. |
| 303 { | 291 { |
| 304 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 292 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
| 305 update_rect_params.view_size = gfx::Size(643, 480); | 293 update_rect_params.view_size = gfx::Size(643, 480); |
| 306 update_rect_params.scale_factor = 1.0f; | 294 update_rect_params.scale_factor = 1.0f; |
| 307 update_rect_params.is_resize_ack = true; | 295 update_rect_params.is_resize_ack = true; |
| 308 update_rect_params.damage_buffer_identifier = | 296 update_rect_params.damage_buffer_sequence_id = |
| 309 #if defined(OS_MACOSX) | 297 browser_plugin->damage_buffer_sequence_id_; |
| 310 browser_plugin->pending_damage_buffer_->id(); | |
| 311 #else | |
| 312 browser_plugin->pending_damage_buffer_->handle(); | |
| 313 #endif | |
| 314 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); | 298 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); |
| 315 browser_plugin->OnMessageReceived(msg); | 299 browser_plugin->OnMessageReceived(msg); |
| 316 // The BrowserPlugin has finally received an UpdateRect that satisifes | 300 // The BrowserPlugin has finally received an UpdateRect that satisifes |
| 317 // its current size, and so it is happy. | 301 // its current size, and so it is happy. |
| 318 EXPECT_FALSE(browser_plugin->pending_damage_buffer_); | 302 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); |
| 319 } | 303 } |
| 320 } | 304 } |
| 321 | 305 |
| 322 TEST_F(BrowserPluginTest, GuestCrash) { | 306 TEST_F(BrowserPluginTest, GuestCrash) { |
| 323 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 307 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 324 | 308 |
| 325 // Grab the BrowserPlugin's instance ID from its resize message. | 309 // Grab the BrowserPlugin's instance ID from its resize message. |
| 326 int instance_id = 0; | 310 int instance_id = 0; |
| 327 { | 311 { |
| 328 const IPC::Message* msg = | 312 const IPC::Message* msg = |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 EXPECT_EQ(42, params.auto_size_params.min_size.width()); | 788 EXPECT_EQ(42, params.auto_size_params.min_size.width()); |
| 805 EXPECT_EQ(43, params.auto_size_params.min_size.height()); | 789 EXPECT_EQ(43, params.auto_size_params.min_size.height()); |
| 806 EXPECT_EQ(1337, params.auto_size_params.max_size.width()); | 790 EXPECT_EQ(1337, params.auto_size_params.max_size.width()); |
| 807 EXPECT_EQ(1338, params.auto_size_params.max_size.height()); | 791 EXPECT_EQ(1338, params.auto_size_params.max_size.height()); |
| 808 } | 792 } |
| 809 // Verify that we are waiting for the browser process to grab the new | 793 // Verify that we are waiting for the browser process to grab the new |
| 810 // damage buffer. | 794 // damage buffer. |
| 811 MockBrowserPlugin* browser_plugin = | 795 MockBrowserPlugin* browser_plugin = |
| 812 static_cast<MockBrowserPlugin*>( | 796 static_cast<MockBrowserPlugin*>( |
| 813 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 797 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 814 EXPECT_TRUE(browser_plugin->pending_damage_buffer_); | 798 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); |
| 815 // Disable autosize. AutoSize state will not be sent to the guest until | 799 // Disable autosize. AutoSize state will not be sent to the guest until |
| 816 // the guest has responded to the last resize request. | 800 // the guest has responded to the last resize request. |
| 817 ExecuteJavaScript(kDisableAutoSize); | 801 ExecuteJavaScript(kDisableAutoSize); |
| 818 ProcessPendingMessages(); | 802 ProcessPendingMessages(); |
| 819 | 803 |
| 820 const IPC::Message* auto_size_msg = | 804 const IPC::Message* auto_size_msg = |
| 821 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 805 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 822 BrowserPluginHostMsg_SetAutoSize::ID); | 806 BrowserPluginHostMsg_SetAutoSize::ID); |
| 823 EXPECT_FALSE(auto_size_msg); | 807 EXPECT_FALSE(auto_size_msg); |
| 824 | 808 |
| 825 // Send the BrowserPlugin an UpdateRect equal to its |max_size| with | 809 // Send the BrowserPlugin an UpdateRect equal to its |max_size| with |
| 826 // the same damage buffer. | 810 // the same damage buffer. |
| 827 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 811 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
| 828 update_rect_params.damage_buffer_identifier = | 812 update_rect_params.damage_buffer_sequence_id = |
| 829 #if defined(OS_MACOSX) | 813 browser_plugin->damage_buffer_sequence_id_; |
| 830 browser_plugin->pending_damage_buffer_->id(); | |
| 831 #else | |
| 832 browser_plugin->pending_damage_buffer_->handle(); | |
| 833 #endif | |
| 834 update_rect_params.view_size = gfx::Size(1337, 1338); | 814 update_rect_params.view_size = gfx::Size(1337, 1338); |
| 835 update_rect_params.scale_factor = 1.0f; | 815 update_rect_params.scale_factor = 1.0f; |
| 836 update_rect_params.is_resize_ack = true; | 816 update_rect_params.is_resize_ack = true; |
| 837 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); | 817 BrowserPluginMsg_UpdateRect msg(0, instance_id, 0, update_rect_params); |
| 838 browser_plugin->OnMessageReceived(msg); | 818 browser_plugin->OnMessageReceived(msg); |
| 839 | 819 |
| 840 // Verify that the autosize state has been updated. | 820 // Verify that the autosize state has been updated. |
| 841 { | 821 { |
| 842 const IPC::Message* auto_size_msg = | 822 const IPC::Message* auto_size_msg = |
| 843 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 823 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 855 &resize_params); | 835 &resize_params); |
| 856 EXPECT_FALSE(auto_size_params.enable); | 836 EXPECT_FALSE(auto_size_params.enable); |
| 857 EXPECT_EQ(42, auto_size_params.min_size.width()); | 837 EXPECT_EQ(42, auto_size_params.min_size.width()); |
| 858 EXPECT_EQ(43, auto_size_params.min_size.height()); | 838 EXPECT_EQ(43, auto_size_params.min_size.height()); |
| 859 EXPECT_EQ(1337, auto_size_params.max_size.width()); | 839 EXPECT_EQ(1337, auto_size_params.max_size.width()); |
| 860 EXPECT_EQ(1338, auto_size_params.max_size.height()); | 840 EXPECT_EQ(1338, auto_size_params.max_size.height()); |
| 861 } | 841 } |
| 862 } | 842 } |
| 863 | 843 |
| 864 } // namespace content | 844 } // namespace content |
| OLD | NEW |