| 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/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "content/common/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin_messages.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 browser_plugin->UpdateRect(0, update_rect_params); | 126 browser_plugin->UpdateRect(0, update_rect_params); |
| 127 EXPECT_FALSE(browser_plugin->resize_pending_); | 127 EXPECT_FALSE(browser_plugin->resize_pending_); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Verify that the src attribute on the browser plugin works as expected. | 130 // Verify that the src attribute on the browser plugin works as expected. |
| 131 TEST_F(BrowserPluginTest, SrcAttribute) { | 131 TEST_F(BrowserPluginTest, SrcAttribute) { |
| 132 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 132 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 133 // Verify that we're reporting the correct URL to navigate to based on the | 133 // Verify that we're reporting the correct URL to navigate to based on the |
| 134 // src attribute. | 134 // src attribute. |
| 135 { | 135 { |
| 136 // Ensure we get a CreateGuest on the initial navigation. |
| 137 const IPC::Message* create_msg = |
| 138 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 139 BrowserPluginHostMsg_CreateGuest::ID); |
| 140 ASSERT_TRUE(create_msg); |
| 141 |
| 136 const IPC::Message* msg = | 142 const IPC::Message* msg = |
| 137 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 143 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 138 BrowserPluginHostMsg_NavigateGuest::ID); | 144 BrowserPluginHostMsg_NavigateGuest::ID); |
| 139 ASSERT_TRUE(msg); | 145 ASSERT_TRUE(msg); |
| 140 | 146 |
| 141 int instance_id; | 147 int instance_id; |
| 142 std::string src; | 148 std::string src; |
| 143 BrowserPluginHostMsg_ResizeGuest_Params resize_params; | 149 BrowserPluginHostMsg_ResizeGuest_Params resize_params; |
| 144 BrowserPluginHostMsg_NavigateGuest::Read( | 150 BrowserPluginHostMsg_NavigateGuest::Read( |
| 145 msg, | 151 msg, |
| 146 &instance_id, | 152 &instance_id, |
| 147 &src, | 153 &src, |
| 148 &resize_params); | 154 &resize_params); |
| 149 EXPECT_EQ("foo", src); | 155 EXPECT_EQ("foo", src); |
| 150 } | 156 } |
| 151 | 157 |
| 152 browser_plugin_manager()->sink().ClearMessages(); | 158 browser_plugin_manager()->sink().ClearMessages(); |
| 153 // Navigate to bar and observe the associated | 159 // Navigate to bar and observe the associated |
| 154 // BrowserPluginHostMsg_NavigateGuest message. | 160 // BrowserPluginHostMsg_NavigateGuest message. |
| 155 // Verify that the src attribute is updated as well. | 161 // Verify that the src attribute is updated as well. |
| 156 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | 162 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 157 { | 163 { |
| 164 // Verify that we do not get a CreateGuest on subsequent navigations. |
| 165 const IPC::Message* create_msg = |
| 166 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 167 BrowserPluginHostMsg_CreateGuest::ID); |
| 168 ASSERT_FALSE(create_msg); |
| 169 |
| 158 const IPC::Message* msg = | 170 const IPC::Message* msg = |
| 159 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 171 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 160 BrowserPluginHostMsg_NavigateGuest::ID); | 172 BrowserPluginHostMsg_NavigateGuest::ID); |
| 161 ASSERT_TRUE(msg); | 173 ASSERT_TRUE(msg); |
| 162 | 174 |
| 163 int instance_id; | 175 int instance_id; |
| 164 std::string src; | 176 std::string src; |
| 165 BrowserPluginHostMsg_ResizeGuest_Params resize_params; | 177 BrowserPluginHostMsg_ResizeGuest_Params resize_params; |
| 166 BrowserPluginHostMsg_NavigateGuest::Read( | 178 BrowserPluginHostMsg_NavigateGuest::Read( |
| 167 msg, | 179 msg, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 std::string partition_value = ExecuteScriptAndReturnString( | 431 std::string partition_value = ExecuteScriptAndReturnString( |
| 420 "document.getElementById('browserplugin').partition"); | 432 "document.getElementById('browserplugin').partition"); |
| 421 EXPECT_STREQ("storage", partition_value.c_str()); | 433 EXPECT_STREQ("storage", partition_value.c_str()); |
| 422 | 434 |
| 423 std::string src_value = ExecuteScriptAndReturnString( | 435 std::string src_value = ExecuteScriptAndReturnString( |
| 424 "document.getElementById('browserplugin').src"); | 436 "document.getElementById('browserplugin').src"); |
| 425 EXPECT_STREQ("", src_value.c_str()); | 437 EXPECT_STREQ("", src_value.c_str()); |
| 426 | 438 |
| 427 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | 439 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 428 { | 440 { |
| 441 const IPC::Message* create_msg = |
| 442 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 443 BrowserPluginHostMsg_CreateGuest::ID); |
| 444 ASSERT_TRUE(create_msg); |
| 445 |
| 446 int create_instance_id; |
| 447 std::string storage_partition; |
| 448 bool persist_storage = true; |
| 449 BrowserPluginHostMsg_CreateGuest::Read( |
| 450 create_msg, |
| 451 &create_instance_id, |
| 452 &storage_partition, |
| 453 &persist_storage); |
| 454 EXPECT_STREQ("storage", storage_partition.c_str()); |
| 455 EXPECT_FALSE(persist_storage); |
| 456 |
| 429 const IPC::Message* msg = | 457 const IPC::Message* msg = |
| 430 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 458 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 431 BrowserPluginHostMsg_NavigateGuest::ID); | 459 BrowserPluginHostMsg_NavigateGuest::ID); |
| 432 ASSERT_TRUE(msg); | 460 ASSERT_TRUE(msg); |
| 433 | 461 |
| 434 int instance_id; | 462 int instance_id; |
| 435 std::string src; | 463 std::string src; |
| 436 BrowserPluginHostMsg_ResizeGuest_Params resize_params; | 464 BrowserPluginHostMsg_ResizeGuest_Params resize_params; |
| 437 BrowserPluginHostMsg_NavigateGuest::Read( | 465 BrowserPluginHostMsg_NavigateGuest::Read( |
| 438 msg, | 466 msg, |
| 439 &instance_id, | 467 &instance_id, |
| 440 &src, | 468 &src, |
| 441 &resize_params); | 469 &resize_params); |
| 442 EXPECT_STREQ("bar", src.c_str()); | 470 EXPECT_STREQ("bar", src.c_str()); |
| 471 EXPECT_EQ(create_instance_id, instance_id); |
| 443 } | 472 } |
| 444 | 473 |
| 445 // Setting the partition should throw an exception and the value should not | 474 // Setting the partition should throw an exception and the value should not |
| 446 // change. | 475 // change. |
| 447 ExecuteJavaScript( | 476 ExecuteJavaScript( |
| 448 "try {" | 477 "try {" |
| 449 " document.getElementById('browserplugin').partition = 'someid';" | 478 " document.getElementById('browserplugin').partition = 'someid';" |
| 450 " document.title = 'success';" | 479 " document.title = 'success';" |
| 451 "} catch (e) { document.title = e.message; }"); | 480 "} catch (e) { document.title = e.message; }"); |
| 452 | 481 |
| 453 std::string title = ExecuteScriptAndReturnString("document.title"); | 482 std::string title = ExecuteScriptAndReturnString("document.title"); |
| 454 EXPECT_STREQ( | 483 EXPECT_STREQ( |
| 455 "The object has already navigated, so its partition cannot be changed.", | 484 "The object has already navigated, so its partition cannot be changed.", |
| 456 title.c_str()); | 485 title.c_str()); |
| 457 | 486 |
| 458 partition_value = ExecuteScriptAndReturnString( | 487 partition_value = ExecuteScriptAndReturnString( |
| 459 "document.getElementById('browserplugin').partition"); | 488 "document.getElementById('browserplugin').partition"); |
| 460 EXPECT_STREQ("storage", partition_value.c_str()); | 489 EXPECT_STREQ("storage", partition_value.c_str()); |
| 461 } | 490 } |
| 462 | 491 |
| 463 } // namespace content | 492 } // namespace content |
| OLD | NEW |