| 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 21 matching lines...) Expand all Loading... |
| 32 "<script>document.querySelector('object').nonExistentAttribute;</script>"; | 32 "<script>document.querySelector('object').nonExistentAttribute;</script>"; |
| 33 | 33 |
| 34 const char kHTMLForBrowserPluginWithAllAttributes[] = | 34 const char kHTMLForBrowserPluginWithAllAttributes[] = |
| 35 "<object id='browserplugin' width='640' height='480' type='%s'" | 35 "<object id='browserplugin' width='640' height='480' type='%s'" |
| 36 " autosize maxheight='600' maxwidth='800' minheight='240'" | 36 " autosize maxheight='600' maxwidth='800' minheight='240'" |
| 37 " minwidth='320' name='Jim' partition='someid' src='foo'>"; | 37 " minwidth='320' name='Jim' partition='someid' src='foo'>"; |
| 38 | 38 |
| 39 const char kHTMLForSourcelessPluginObject[] = | 39 const char kHTMLForSourcelessPluginObject[] = |
| 40 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; | 40 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; |
| 41 | 41 |
| 42 const char kHTMLForPartitionedPluginObject[] = | |
| 43 "<object id='browserplugin' width='640px' height='480px'" | |
| 44 " src='foo' type='%s' partition='someid'>"; | |
| 45 | |
| 46 const char kHTMLForInvalidPartitionedPluginObject[] = | |
| 47 "<object id='browserplugin' width='640px' height='480px'" | |
| 48 " type='%s' partition='persist:'>"; | |
| 49 | |
| 50 const char kHTMLForPartitionedPersistedPluginObject[] = | |
| 51 "<object id='browserplugin' width='640px' height='480px'" | |
| 52 " src='foo' type='%s' partition='persist:someid'>"; | |
| 53 | |
| 54 std::string GetHTMLForBrowserPluginObject() { | 42 std::string GetHTMLForBrowserPluginObject() { |
| 55 return base::StringPrintf(kHTMLForBrowserPluginObject, | 43 return base::StringPrintf(kHTMLForBrowserPluginObject, |
| 56 kBrowserPluginMimeType); | 44 kBrowserPluginMimeType); |
| 57 } | 45 } |
| 58 | 46 |
| 59 } // namespace | 47 } // namespace |
| 60 | 48 |
| 61 class TestContentRendererClient : public ContentRendererClient { | 49 class TestContentRendererClient : public ContentRendererClient { |
| 62 public: | 50 public: |
| 63 TestContentRendererClient() : ContentRendererClient() { | 51 TestContentRendererClient() : ContentRendererClient() { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return true; | 148 return true; |
| 161 } | 149 } |
| 162 | 150 |
| 163 MockBrowserPlugin* BrowserPluginTest::GetCurrentPlugin() { | 151 MockBrowserPlugin* BrowserPluginTest::GetCurrentPlugin() { |
| 164 BrowserPluginHostMsg_Attach_Params params; | 152 BrowserPluginHostMsg_Attach_Params params; |
| 165 return GetCurrentPluginWithAttachParams(¶ms); | 153 return GetCurrentPluginWithAttachParams(¶ms); |
| 166 } | 154 } |
| 167 | 155 |
| 168 MockBrowserPlugin* BrowserPluginTest::GetCurrentPluginWithAttachParams( | 156 MockBrowserPlugin* BrowserPluginTest::GetCurrentPluginWithAttachParams( |
| 169 BrowserPluginHostMsg_Attach_Params* params) { | 157 BrowserPluginHostMsg_Attach_Params* params) { |
| 158 MockBrowserPlugin* browser_plugin = static_cast<MockBrowserPluginManager*>( |
| 159 browser_plugin_manager())->last_plugin(); |
| 160 if (!browser_plugin) |
| 161 return NULL; |
| 162 browser_plugin_manager()->AllocateInstanceID(browser_plugin); |
| 163 |
| 170 int instance_id = 0; | 164 int instance_id = 0; |
| 171 const IPC::Message* msg = | 165 const IPC::Message* msg = |
| 172 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 166 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 173 BrowserPluginHostMsg_Attach::ID); | 167 BrowserPluginHostMsg_Attach::ID); |
| 174 if (!msg) | 168 if (!msg) |
| 175 return NULL; | 169 return NULL; |
| 176 | 170 |
| 177 PickleIterator iter(*msg); | 171 PickleIterator iter(*msg); |
| 178 if (!iter.ReadInt(&instance_id)) | 172 if (!iter.ReadInt(&instance_id)) |
| 179 return NULL; | 173 return NULL; |
| 180 | 174 |
| 181 if (!IPC::ParamTraits<BrowserPluginHostMsg_Attach_Params>::Read( | 175 if (!IPC::ParamTraits<BrowserPluginHostMsg_Attach_Params>::Read( |
| 182 msg, &iter, params)) | 176 msg, &iter, params)) { |
| 183 return NULL; | 177 return NULL; |
| 178 } |
| 184 | 179 |
| 185 MockBrowserPlugin* browser_plugin = static_cast<MockBrowserPlugin*>( | 180 browser_plugin->OnAttachACK(instance_id); |
| 186 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | |
| 187 | |
| 188 BrowserPluginMsg_Attach_ACK_Params attach_ack_params; | |
| 189 browser_plugin->OnAttachACK(instance_id, attach_ack_params); | |
| 190 | |
| 191 return browser_plugin; | 181 return browser_plugin; |
| 192 } | 182 } |
| 193 | 183 |
| 194 // This test verifies that an initial resize occurs when we instantiate the | 184 // This test verifies that an initial resize occurs when we instantiate the |
| 195 // browser plugin. | 185 // browser plugin. |
| 196 TEST_F(BrowserPluginTest, InitialResize) { | 186 TEST_F(BrowserPluginTest, InitialResize) { |
| 197 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 187 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 198 // Verify that the information in Attach is correct. | 188 // Verify that the information in Attach is correct. |
| 199 BrowserPluginHostMsg_Attach_Params params; | 189 BrowserPluginHostMsg_Attach_Params params; |
| 200 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); | 190 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 221 EXPECT_EQ(600, maxHeight); | 211 EXPECT_EQ(600, maxHeight); |
| 222 int maxWidth = ExecuteScriptAndReturnInt( | 212 int maxWidth = ExecuteScriptAndReturnInt( |
| 223 "document.getElementById('browserplugin').maxwidth"); | 213 "document.getElementById('browserplugin').maxwidth"); |
| 224 EXPECT_EQ(800, maxWidth); | 214 EXPECT_EQ(800, maxWidth); |
| 225 int minHeight = ExecuteScriptAndReturnInt( | 215 int minHeight = ExecuteScriptAndReturnInt( |
| 226 "document.getElementById('browserplugin').minheight"); | 216 "document.getElementById('browserplugin').minheight"); |
| 227 EXPECT_EQ(240, minHeight); | 217 EXPECT_EQ(240, minHeight); |
| 228 int minWidth = ExecuteScriptAndReturnInt( | 218 int minWidth = ExecuteScriptAndReturnInt( |
| 229 "document.getElementById('browserplugin').minwidth"); | 219 "document.getElementById('browserplugin').minwidth"); |
| 230 EXPECT_EQ(320, minWidth); | 220 EXPECT_EQ(320, minWidth); |
| 231 std::string name = ExecuteScriptAndReturnString( | |
| 232 "document.getElementById('browserplugin').name"); | |
| 233 EXPECT_STREQ("Jim", name.c_str()); | |
| 234 std::string partition = ExecuteScriptAndReturnString( | |
| 235 "document.getElementById('browserplugin').partition"); | |
| 236 EXPECT_STREQ("someid", partition.c_str()); | |
| 237 std::string src = ExecuteScriptAndReturnString( | |
| 238 "document.getElementById('browserplugin').src"); | |
| 239 EXPECT_STREQ("foo", src.c_str()); | |
| 240 } | |
| 241 | |
| 242 // Verify that the src attribute on the browser plugin works as expected. | |
| 243 TEST_F(BrowserPluginTest, SrcAttribute) { | |
| 244 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | |
| 245 // Verify that we're reporting the correct URL to navigate to based on the | |
| 246 // src attribute. | |
| 247 { | |
| 248 BrowserPluginHostMsg_Attach_Params params; | |
| 249 MockBrowserPlugin* browser_plugin = | |
| 250 GetCurrentPluginWithAttachParams(¶ms); | |
| 251 ASSERT_TRUE(browser_plugin); | |
| 252 EXPECT_EQ("foo", params.src); | |
| 253 } | |
| 254 | |
| 255 browser_plugin_manager()->sink().ClearMessages(); | |
| 256 // Navigate to bar and observe the associated | |
| 257 // BrowserPluginHostMsg_NavigateGuest message. | |
| 258 // Verify that the src attribute is updated as well. | |
| 259 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | |
| 260 { | |
| 261 // Verify that we do not get a Attach on subsequent navigations. | |
| 262 const IPC::Message* create_msg = | |
| 263 browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
| 264 BrowserPluginHostMsg_Attach::ID); | |
| 265 ASSERT_FALSE(create_msg); | |
| 266 | |
| 267 const IPC::Message* msg = | |
| 268 browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
| 269 BrowserPluginHostMsg_NavigateGuest::ID); | |
| 270 ASSERT_TRUE(msg); | |
| 271 | |
| 272 BrowserPluginHostMsg_NavigateGuest::Param params; | |
| 273 BrowserPluginHostMsg_NavigateGuest::Read(msg, ¶ms); | |
| 274 std::string src = params.b; | |
| 275 EXPECT_EQ("bar", src); | |
| 276 std::string src_value = | |
| 277 ExecuteScriptAndReturnString( | |
| 278 "document.getElementById('browserplugin').src"); | |
| 279 EXPECT_EQ("bar", src_value); | |
| 280 } | |
| 281 } | 221 } |
| 282 | 222 |
| 283 TEST_F(BrowserPluginTest, ResizeFlowControl) { | 223 TEST_F(BrowserPluginTest, ResizeFlowControl) { |
| 284 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 224 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 285 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); | 225 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); |
| 286 ASSERT_TRUE(browser_plugin); | 226 ASSERT_TRUE(browser_plugin); |
| 287 int instance_id = browser_plugin->guest_instance_id(); | 227 int instance_id = browser_plugin->guest_instance_id(); |
| 288 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a | 228 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a |
| 289 // resize related (SetAutoSize) message. | 229 // resize related (SetAutoSize) message. |
| 290 { | 230 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 update_rect_params.view_size = gfx::Size(643, 480); | 291 update_rect_params.view_size = gfx::Size(643, 480); |
| 352 update_rect_params.scale_factor = 1.0f; | 292 update_rect_params.scale_factor = 1.0f; |
| 353 update_rect_params.is_resize_ack = true; | 293 update_rect_params.is_resize_ack = true; |
| 354 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); | 294 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); |
| 355 browser_plugin->OnMessageReceived(msg); | 295 browser_plugin->OnMessageReceived(msg); |
| 356 } | 296 } |
| 357 } | 297 } |
| 358 | 298 |
| 359 TEST_F(BrowserPluginTest, RemovePlugin) { | 299 TEST_F(BrowserPluginTest, RemovePlugin) { |
| 360 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 300 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 301 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); |
| 302 ASSERT_TRUE(browser_plugin); |
| 303 |
| 361 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 304 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 362 BrowserPluginHostMsg_PluginDestroyed::ID)); | 305 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 363 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 306 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
| 364 "x.parentNode.removeChild(x);"); | 307 "x.parentNode.removeChild(x);"); |
| 365 ProcessPendingMessages(); | 308 ProcessPendingMessages(); |
| 366 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 309 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 367 BrowserPluginHostMsg_PluginDestroyed::ID)); | 310 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 368 } | 311 } |
| 369 | 312 |
| 370 // This test verifies that PluginDestroyed messages do not get sent from a | 313 // This test verifies that PluginDestroyed messages do not get sent from a |
| 371 // BrowserPlugin that has never navigated. | 314 // BrowserPlugin that has never navigated. |
| 372 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) { | 315 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) { |
| 373 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, | 316 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, |
| 374 kBrowserPluginMimeType); | 317 kBrowserPluginMimeType); |
| 375 LoadHTML(html.c_str()); | 318 LoadHTML(html.c_str()); |
| 376 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 319 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 377 BrowserPluginHostMsg_PluginDestroyed::ID)); | 320 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 378 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 321 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
| 379 "x.parentNode.removeChild(x);"); | 322 "x.parentNode.removeChild(x);"); |
| 380 ProcessPendingMessages(); | 323 ProcessPendingMessages(); |
| 381 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 324 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 382 BrowserPluginHostMsg_PluginDestroyed::ID)); | 325 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 383 } | 326 } |
| 384 | 327 |
| 385 // Verify that the 'partition' attribute on the browser plugin is parsed | 328 // Verify that the 'partition' attribute on the browser plugin is parsed |
| 386 // correctly. | 329 // correctly. |
| 387 TEST_F(BrowserPluginTest, PartitionAttribute) { | |
| 388 std::string html = base::StringPrintf(kHTMLForPartitionedPluginObject, | |
| 389 kBrowserPluginMimeType); | |
| 390 LoadHTML(html.c_str()); | |
| 391 std::string partition_value = ExecuteScriptAndReturnString( | |
| 392 "document.getElementById('browserplugin').partition"); | |
| 393 EXPECT_STREQ("someid", partition_value.c_str()); | |
| 394 | |
| 395 html = base::StringPrintf(kHTMLForPartitionedPersistedPluginObject, | |
| 396 kBrowserPluginMimeType); | |
| 397 LoadHTML(html.c_str()); | |
| 398 partition_value = ExecuteScriptAndReturnString( | |
| 399 "document.getElementById('browserplugin').partition"); | |
| 400 EXPECT_STREQ("persist:someid", partition_value.c_str()); | |
| 401 | |
| 402 // Verify that once HTML has defined a source and partition, we cannot change | |
| 403 // the partition anymore. | |
| 404 ExecuteJavaScript( | |
| 405 "try {" | |
| 406 " document.getElementById('browserplugin').partition = 'foo';" | |
| 407 " document.title = 'success';" | |
| 408 "} catch (e) { document.title = e.message; }"); | |
| 409 std::string title = ExecuteScriptAndReturnString("document.title"); | |
| 410 EXPECT_STREQ( | |
| 411 "The object has already navigated, so its partition cannot be changed.", | |
| 412 title.c_str()); | |
| 413 | |
| 414 // Load a browser tag without 'src' defined. | |
| 415 html = base::StringPrintf(kHTMLForSourcelessPluginObject, | |
| 416 kBrowserPluginMimeType); | |
| 417 LoadHTML(html.c_str()); | |
| 418 | |
| 419 // Ensure we don't parse just "persist:" string and return exception. | |
| 420 ExecuteJavaScript( | |
| 421 "try {" | |
| 422 " document.getElementById('browserplugin').partition = 'persist:';" | |
| 423 " document.title = 'success';" | |
| 424 "} catch (e) { document.title = e.message; }"); | |
| 425 title = ExecuteScriptAndReturnString("document.title"); | |
| 426 EXPECT_STREQ("Invalid partition attribute.", title.c_str()); | |
| 427 } | |
| 428 | |
| 429 // This test verifies that BrowserPlugin enters an error state when the | |
| 430 // partition attribute is invalid. | |
| 431 TEST_F(BrowserPluginTest, InvalidPartition) { | |
| 432 std::string html = base::StringPrintf(kHTMLForInvalidPartitionedPluginObject, | |
| 433 kBrowserPluginMimeType); | |
| 434 LoadHTML(html.c_str()); | |
| 435 // Attempt to navigate with an invalid partition. | |
| 436 { | |
| 437 ExecuteJavaScript( | |
| 438 "try {" | |
| 439 " document.getElementById('browserplugin').src = 'bar';" | |
| 440 " document.title = 'success';" | |
| 441 "} catch (e) { document.title = e.message; }"); | |
| 442 std::string title = ExecuteScriptAndReturnString("document.title"); | |
| 443 EXPECT_STREQ("Invalid partition attribute.", title.c_str()); | |
| 444 // Verify that the 'src' attribute has not been updated. | |
| 445 EXPECT_EQ("", ExecuteScriptAndReturnString( | |
| 446 "document.getElementById('browserplugin').src")); | |
| 447 } | |
| 448 | |
| 449 // Verify that the BrowserPlugin accepts changes to its src attribue after | |
| 450 // setting the partition to a valid value. | |
| 451 ExecuteJavaScript( | |
| 452 "document.getElementById('browserplugin').partition = 'persist:foo'"); | |
| 453 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | |
| 454 EXPECT_EQ("bar", ExecuteScriptAndReturnString( | |
| 455 "document.getElementById('browserplugin').src")); | |
| 456 ProcessPendingMessages(); | |
| 457 // Verify that the BrowserPlugin does not 'deadlock': it can recover from | |
| 458 // the partition ID error state. | |
| 459 { | |
| 460 ExecuteJavaScript( | |
| 461 "try {" | |
| 462 " document.getElementById('browserplugin').partition = 'persist:1337';" | |
| 463 " document.title = 'success';" | |
| 464 "} catch (e) { document.title = e.message; }"); | |
| 465 std::string title = ExecuteScriptAndReturnString("document.title"); | |
| 466 EXPECT_STREQ( | |
| 467 "The object has already navigated, so its partition cannot be changed.", | |
| 468 title.c_str()); | |
| 469 ExecuteJavaScript("document.getElementById('browserplugin').src = '42'"); | |
| 470 EXPECT_EQ("42", ExecuteScriptAndReturnString( | |
| 471 "document.getElementById('browserplugin').src")); | |
| 472 } | |
| 473 } | |
| 474 | |
| 475 // Test to verify that after the first navigation, the partition attribute | |
| 476 // cannot be modified. | |
| 477 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { | |
| 478 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, | |
| 479 kBrowserPluginMimeType); | |
| 480 LoadHTML(html.c_str()); | |
| 481 | |
| 482 ExecuteJavaScript( | |
| 483 "document.getElementById('browserplugin').partition = 'storage'"); | |
| 484 std::string partition_value = ExecuteScriptAndReturnString( | |
| 485 "document.getElementById('browserplugin').partition"); | |
| 486 EXPECT_STREQ("storage", partition_value.c_str()); | |
| 487 | |
| 488 std::string src_value = ExecuteScriptAndReturnString( | |
| 489 "document.getElementById('browserplugin').src"); | |
| 490 EXPECT_STREQ("", src_value.c_str()); | |
| 491 | |
| 492 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | |
| 493 ProcessPendingMessages(); | |
| 494 { | |
| 495 BrowserPluginHostMsg_Attach_Params params; | |
| 496 MockBrowserPlugin* browser_plugin = | |
| 497 GetCurrentPluginWithAttachParams(¶ms); | |
| 498 ASSERT_TRUE(browser_plugin); | |
| 499 | |
| 500 EXPECT_STREQ("storage", params.storage_partition_id.c_str()); | |
| 501 EXPECT_FALSE(params.persist_storage); | |
| 502 EXPECT_STREQ("bar", params.src.c_str()); | |
| 503 } | |
| 504 | |
| 505 // Setting the partition should throw an exception and the value should not | |
| 506 // change. | |
| 507 ExecuteJavaScript( | |
| 508 "try {" | |
| 509 " document.getElementById('browserplugin').partition = 'someid';" | |
| 510 " document.title = 'success';" | |
| 511 "} catch (e) { document.title = e.message; }"); | |
| 512 | |
| 513 std::string title = ExecuteScriptAndReturnString("document.title"); | |
| 514 EXPECT_STREQ( | |
| 515 "The object has already navigated, so its partition cannot be changed.", | |
| 516 title.c_str()); | |
| 517 | |
| 518 partition_value = ExecuteScriptAndReturnString( | |
| 519 "document.getElementById('browserplugin').partition"); | |
| 520 EXPECT_STREQ("storage", partition_value.c_str()); | |
| 521 } | |
| 522 | |
| 523 TEST_F(BrowserPluginTest, AutoSizeAttributes) { | 330 TEST_F(BrowserPluginTest, AutoSizeAttributes) { |
| 524 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, | 331 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, |
| 525 kBrowserPluginMimeType); | 332 kBrowserPluginMimeType); |
| 526 LoadHTML(html.c_str()); | 333 LoadHTML(html.c_str()); |
| 527 const char* kSetAutoSizeParametersAndNavigate = | 334 const char* kSetAutoSizeParametersAndNavigate = |
| 528 "var browserplugin = document.getElementById('browserplugin');" | 335 "var browserplugin = document.getElementById('browserplugin');" |
| 529 "browserplugin.autosize = true;" | 336 "browserplugin.autosize = true;" |
| 530 "browserplugin.minwidth = 42;" | 337 "browserplugin.minwidth = 42;" |
| 531 "browserplugin.minheight = 43;" | 338 "browserplugin.minheight = 43;" |
| 532 "browserplugin.maxwidth = 1337;" | 339 "browserplugin.maxwidth = 1337;" |
| 533 "browserplugin.maxheight = 1338;" | 340 "browserplugin.maxheight = 1338;" |
| 534 "browserplugin.src = 'foobar';"; | 341 "browserplugin.src = 'foobar';"; |
| 535 const char* kDisableAutoSize = | 342 const char* kDisableAutoSize = |
| 536 "document.getElementById('browserplugin').removeAttribute('autosize');"; | 343 "document.getElementById('browserplugin').removeAttribute('autosize');"; |
| 537 | 344 |
| 538 int instance_id = 0; | 345 int instance_id = 0; |
| 539 // Set some autosize parameters before navigating then navigate. | 346 // Set some autosize parameters before navigating then navigate. |
| 540 // Verify that the BrowserPluginHostMsg_Attach message contains | 347 // Verify that the BrowserPluginHostMsg_Attach message contains |
| 541 // the correct autosize parameters. | 348 // the correct autosize parameters. |
| 542 ExecuteJavaScript(kSetAutoSizeParametersAndNavigate); | 349 ExecuteJavaScript(kSetAutoSizeParametersAndNavigate); |
| 543 ProcessPendingMessages(); | 350 ProcessPendingMessages(); |
| 544 | 351 |
| 545 BrowserPluginHostMsg_Attach_Params params; | 352 BrowserPluginHostMsg_Attach_Params params; |
| 546 MockBrowserPlugin* browser_plugin = | 353 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); |
| 547 GetCurrentPluginWithAttachParams(¶ms); | |
| 548 ASSERT_TRUE(browser_plugin); | 354 ASSERT_TRUE(browser_plugin); |
| 549 | 355 |
| 550 EXPECT_TRUE(params.auto_size_params.enable); | 356 EXPECT_TRUE(params.auto_size_params.enable); |
| 551 EXPECT_EQ(42, params.auto_size_params.min_size.width()); | 357 EXPECT_EQ(42, params.auto_size_params.min_size.width()); |
| 552 EXPECT_EQ(43, params.auto_size_params.min_size.height()); | 358 EXPECT_EQ(43, params.auto_size_params.min_size.height()); |
| 553 EXPECT_EQ(1337, params.auto_size_params.max_size.width()); | 359 EXPECT_EQ(1337, params.auto_size_params.max_size.width()); |
| 554 EXPECT_EQ(1338, params.auto_size_params.max_size.height()); | 360 EXPECT_EQ(1338, params.auto_size_params.max_size.height()); |
| 555 | 361 |
| 556 // Disable autosize. AutoSize state will not be sent to the guest until | 362 // Disable autosize. AutoSize state will not be sent to the guest until |
| 557 // the guest has responded to the last resize request. | 363 // the guest has responded to the last resize request. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 586 // These value are not populated (as an optimization) if autosize is | 392 // These value are not populated (as an optimization) if autosize is |
| 587 // disabled. | 393 // disabled. |
| 588 EXPECT_EQ(0, auto_size_params.min_size.width()); | 394 EXPECT_EQ(0, auto_size_params.min_size.width()); |
| 589 EXPECT_EQ(0, auto_size_params.min_size.height()); | 395 EXPECT_EQ(0, auto_size_params.min_size.height()); |
| 590 EXPECT_EQ(0, auto_size_params.max_size.width()); | 396 EXPECT_EQ(0, auto_size_params.max_size.width()); |
| 591 EXPECT_EQ(0, auto_size_params.max_size.height()); | 397 EXPECT_EQ(0, auto_size_params.max_size.height()); |
| 592 } | 398 } |
| 593 } | 399 } |
| 594 | 400 |
| 595 } // namespace content | 401 } // namespace content |
| OLD | NEW |