| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 // This test verifies that an initial resize occurs when we instantiate the | 119 // This test verifies that an initial resize occurs when we instantiate the |
| 120 // browser plugin. This test also verifies that the browser plugin is waiting | 120 // browser plugin. This test also verifies that the browser plugin is waiting |
| 121 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and | 121 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and |
| 122 // we observe an UpdateRect_ACK, with the |pending_damage_buffer_| reset, | 122 // we observe an UpdateRect_ACK, with the |pending_damage_buffer_| reset, |
| 123 // indiciating that the BrowserPlugin is not waiting for any more UpdateRects to | 123 // indiciating that the BrowserPlugin is not waiting for any more UpdateRects to |
| 124 // satisfy its resize request. | 124 // satisfy its resize request. |
| 125 TEST_F(BrowserPluginTest, InitialResize) { | 125 TEST_F(BrowserPluginTest, InitialResize) { |
| 126 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 126 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 127 // Verify that the information based on ResizeGuest is correct, and | 127 // Verify that the information in CreateGuest is correct. |
| 128 // use its TransportDIB::Id to paint. | |
| 129 int instance_id = 0; | 128 int instance_id = 0; |
| 130 { | 129 { |
| 131 const IPC::Message* msg = | 130 const IPC::Message* msg = |
| 132 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 131 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 133 BrowserPluginHostMsg_ResizeGuest::ID); | 132 BrowserPluginHostMsg_CreateGuest::ID); |
| 134 ASSERT_TRUE(msg); | 133 ASSERT_TRUE(msg); |
| 135 BrowserPluginHostMsg_ResizeGuest_Params params; | 134 BrowserPluginHostMsg_CreateGuest_Params params; |
| 136 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 135 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 137 EXPECT_EQ(640, params.view_size.width()); | 136 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); |
| 138 EXPECT_EQ(480, params.view_size.height()); | 137 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); |
| 139 } | 138 } |
| 140 | 139 |
| 141 MockBrowserPlugin* browser_plugin = | 140 MockBrowserPlugin* browser_plugin = |
| 142 static_cast<MockBrowserPlugin*>( | 141 static_cast<MockBrowserPlugin*>( |
| 143 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 142 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 144 ASSERT_TRUE(browser_plugin); | 143 ASSERT_TRUE(browser_plugin); |
| 145 // Now the browser plugin is expecting a UpdateRect resize. | 144 // Now the browser plugin is expecting a UpdateRect resize. |
| 146 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); | 145 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); |
| 147 | 146 |
| 148 // Send the BrowserPlugin an UpdateRect equal to its container size with | 147 // Send the BrowserPlugin an UpdateRect equal to its container size with |
| (...skipping 10 matching lines...) Expand all Loading... |
| 159 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); | 158 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); |
| 160 } | 159 } |
| 161 | 160 |
| 162 // Verify that the src attribute on the browser plugin works as expected. | 161 // Verify that the src attribute on the browser plugin works as expected. |
| 163 TEST_F(BrowserPluginTest, SrcAttribute) { | 162 TEST_F(BrowserPluginTest, SrcAttribute) { |
| 164 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 163 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 165 // Verify that we're reporting the correct URL to navigate to based on the | 164 // Verify that we're reporting the correct URL to navigate to based on the |
| 166 // src attribute. | 165 // src attribute. |
| 167 { | 166 { |
| 168 // Ensure we get a CreateGuest on the initial navigation. | 167 // Ensure we get a CreateGuest on the initial navigation. |
| 169 const IPC::Message* create_msg = | |
| 170 browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
| 171 BrowserPluginHostMsg_CreateGuest::ID); | |
| 172 ASSERT_TRUE(create_msg); | |
| 173 | |
| 174 const IPC::Message* msg = | 168 const IPC::Message* msg = |
| 175 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 169 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 176 BrowserPluginHostMsg_NavigateGuest::ID); | 170 BrowserPluginHostMsg_CreateGuest::ID); |
| 177 ASSERT_TRUE(msg); | 171 ASSERT_TRUE(msg); |
| 178 | 172 |
| 179 int instance_id = 0; | 173 int instance_id = 0; |
| 180 std::string src; | 174 BrowserPluginHostMsg_CreateGuest_Params params; |
| 181 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src); | 175 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 182 EXPECT_EQ("foo", src); | 176 EXPECT_EQ("foo", params.src); |
| 183 } | 177 } |
| 184 | 178 |
| 185 browser_plugin_manager()->sink().ClearMessages(); | 179 browser_plugin_manager()->sink().ClearMessages(); |
| 186 // Navigate to bar and observe the associated | 180 // Navigate to bar and observe the associated |
| 187 // BrowserPluginHostMsg_NavigateGuest message. | 181 // BrowserPluginHostMsg_NavigateGuest message. |
| 188 // Verify that the src attribute is updated as well. | 182 // Verify that the src attribute is updated as well. |
| 189 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | 183 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 190 { | 184 { |
| 191 // Verify that we do not get a CreateGuest on subsequent navigations. | 185 // Verify that we do not get a CreateGuest on subsequent navigations. |
| 192 const IPC::Message* create_msg = | 186 const IPC::Message* create_msg = |
| 193 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 187 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 194 BrowserPluginHostMsg_CreateGuest::ID); | 188 BrowserPluginHostMsg_CreateGuest::ID); |
| 195 ASSERT_FALSE(create_msg); | 189 ASSERT_FALSE(create_msg); |
| 196 | 190 |
| 197 const IPC::Message* msg = | 191 const IPC::Message* msg = |
| 198 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 192 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 199 BrowserPluginHostMsg_NavigateGuest::ID); | 193 BrowserPluginHostMsg_NavigateGuest::ID); |
| 200 ASSERT_TRUE(msg); | 194 ASSERT_TRUE(msg); |
| 201 | 195 |
| 202 int instance_id = 0; | 196 int instance_id = 0; |
| 203 std::string src; | 197 std::string src; |
| 204 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src); | 198 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src); |
| 205 EXPECT_EQ("bar", src); | 199 EXPECT_EQ("bar", src); |
| 206 std::string src_value = | 200 std::string src_value = |
| 207 ExecuteScriptAndReturnString( | 201 ExecuteScriptAndReturnString( |
| 208 "document.getElementById('browserplugin').src"); | 202 "document.getElementById('browserplugin').src"); |
| 209 EXPECT_EQ("bar", src_value); | 203 EXPECT_EQ("bar", src_value); |
| 210 } | 204 } |
| 211 } | 205 } |
| 212 | 206 |
| 213 TEST_F(BrowserPluginTest, ResizeFlowControl) { | 207 TEST_F(BrowserPluginTest, ResizeFlowControl) { |
| 214 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 208 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 215 int instance_id = 0; | 209 int instance_id = 0; |
| 216 { | 210 { |
| 217 // Ensure we get a NavigateGuest on the initial navigation and grab the | 211 // Ensure we get a CreateGuest on the initial navigation and grab the |
| 218 // BrowserPlugin's instance_id from there. | 212 // BrowserPlugin's instance_id from there. |
| 219 std::string src; | 213 const IPC::Message* msg = |
| 220 const IPC::Message* nav_msg = | 214 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 221 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 215 BrowserPluginHostMsg_CreateGuest::ID); |
| 222 BrowserPluginHostMsg_NavigateGuest::ID); | 216 ASSERT_TRUE(msg); |
| 223 ASSERT_TRUE(nav_msg); | 217 BrowserPluginHostMsg_CreateGuest_Params params; |
| 224 BrowserPluginHostMsg_NavigateGuest::Read(nav_msg, &instance_id, &src); | 218 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 225 } | 219 } |
| 226 MockBrowserPlugin* browser_plugin = | 220 MockBrowserPlugin* browser_plugin = |
| 227 static_cast<MockBrowserPlugin*>( | 221 static_cast<MockBrowserPlugin*>( |
| 228 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 222 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 229 ASSERT_TRUE(browser_plugin); | 223 ASSERT_TRUE(browser_plugin); |
| 230 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); | 224 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); |
| 231 // Send an UpdateRect to the BrowserPlugin to make it use the pending damage | 225 // Send an UpdateRect to the BrowserPlugin to make it use the pending damage |
| 232 // buffer. | 226 // buffer. |
| 233 { | 227 { |
| 234 // We send a stale UpdateRect to the BrowserPlugin. | 228 // We send a stale UpdateRect to the BrowserPlugin. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 browser_plugin->OnMessageReceived(msg); | 296 browser_plugin->OnMessageReceived(msg); |
| 303 // The BrowserPlugin has finally received an UpdateRect that satisifes | 297 // The BrowserPlugin has finally received an UpdateRect that satisifes |
| 304 // its current size, and so it is happy. | 298 // its current size, and so it is happy. |
| 305 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); | 299 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); |
| 306 } | 300 } |
| 307 } | 301 } |
| 308 | 302 |
| 309 TEST_F(BrowserPluginTest, GuestCrash) { | 303 TEST_F(BrowserPluginTest, GuestCrash) { |
| 310 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 304 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 311 | 305 |
| 312 // Grab the BrowserPlugin's instance ID from its resize message. | 306 // Grab the BrowserPlugin's instance ID from its CreateGuest message. |
| 313 int instance_id = 0; | 307 int instance_id = 0; |
| 314 { | 308 { |
| 315 const IPC::Message* msg = | 309 const IPC::Message* msg = |
| 316 browser_plugin_manager()->sink().GetFirstMessageMatching( | 310 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 317 BrowserPluginHostMsg_ResizeGuest::ID); | 311 BrowserPluginHostMsg_CreateGuest::ID); |
| 318 ASSERT_TRUE(msg); | 312 ASSERT_TRUE(msg); |
| 319 BrowserPluginHostMsg_ResizeGuest_Params params; | 313 BrowserPluginHostMsg_CreateGuest_Params params; |
| 320 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 314 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 321 } | 315 } |
| 322 MockBrowserPlugin* browser_plugin = | 316 MockBrowserPlugin* browser_plugin = |
| 323 static_cast<MockBrowserPlugin*>( | 317 static_cast<MockBrowserPlugin*>( |
| 324 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 318 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 325 ASSERT_TRUE(browser_plugin); | 319 ASSERT_TRUE(browser_plugin); |
| 326 | 320 |
| 327 WebKit::WebCursorInfo cursor_info; | 321 WebKit::WebCursorInfo cursor_info; |
| 328 // Send an event and verify that the event is deported. | 322 // Send an event and verify that the event is deported. |
| 329 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), | 323 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), |
| 330 cursor_info); | 324 cursor_info); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 367 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 374 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 368 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 375 BrowserPluginHostMsg_PluginDestroyed::ID)); | 369 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 376 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 370 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
| 377 "x.parentNode.removeChild(x);"); | 371 "x.parentNode.removeChild(x);"); |
| 378 ProcessPendingMessages(); | 372 ProcessPendingMessages(); |
| 379 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 373 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 380 BrowserPluginHostMsg_PluginDestroyed::ID)); | 374 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 381 } | 375 } |
| 382 | 376 |
| 377 // This test verifies that PluginDestroyed messages do not get sent from a |
| 378 // BrowserPlugin that has never navigated. |
| 379 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) { |
| 380 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, |
| 381 content::kBrowserPluginMimeType); |
| 382 LoadHTML(html.c_str()); |
| 383 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 384 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 385 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
| 386 "x.parentNode.removeChild(x);"); |
| 387 ProcessPendingMessages(); |
| 388 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 389 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 390 } |
| 391 |
| 383 TEST_F(BrowserPluginTest, CustomEvents) { | 392 TEST_F(BrowserPluginTest, CustomEvents) { |
| 384 const char* kAddEventListener = | 393 const char* kAddEventListener = |
| 385 "var url;" | 394 "var url;" |
| 386 "function nav(e) {" | 395 "function nav(e) {" |
| 387 " url = JSON.parse(e.detail).url;" | 396 " url = JSON.parse(e.detail).url;" |
| 388 "}" | 397 "}" |
| 389 "document.getElementById('browserplugin')." | 398 "document.getElementById('browserplugin')." |
| 390 " addEventListener('-internal-loadcommit', nav);"; | 399 " addEventListener('-internal-loadcommit', nav);"; |
| 391 const char* kRemoveEventListener = | 400 const char* kRemoveEventListener = |
| 392 "document.getElementById('browserplugin')." | 401 "document.getElementById('browserplugin')." |
| 393 " removeEventListener('-internal-loadcommit', nav);"; | 402 " removeEventListener('-internal-loadcommit', nav);"; |
| 394 const char* kGetProcessID = | 403 const char* kGetProcessID = |
| 395 "document.getElementById('browserplugin').getProcessId()"; | 404 "document.getElementById('browserplugin').getProcessId()"; |
| 396 const char* kGetSrc = | 405 const char* kGetSrc = |
| 397 "document.getElementById('browserplugin').src"; | 406 "document.getElementById('browserplugin').src"; |
| 398 const char* kGoogleURL = "http://www.google.com/"; | 407 const char* kGoogleURL = "http://www.google.com/"; |
| 399 const char* kGoogleNewsURL = "http://news.google.com/"; | 408 const char* kGoogleNewsURL = "http://news.google.com/"; |
| 400 | 409 |
| 401 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 410 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 402 ExecuteJavaScript(kAddEventListener); | 411 ExecuteJavaScript(kAddEventListener); |
| 403 // Grab the BrowserPlugin's instance ID from its resize message. | 412 // Grab the BrowserPlugin's instance ID from its resize message. |
| 404 const IPC::Message* msg = | 413 const IPC::Message* msg = |
| 405 browser_plugin_manager()->sink().GetFirstMessageMatching( | 414 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 406 BrowserPluginHostMsg_ResizeGuest::ID); | 415 BrowserPluginHostMsg_CreateGuest::ID); |
| 407 ASSERT_TRUE(msg); | 416 ASSERT_TRUE(msg); |
| 408 int instance_id = 0; | 417 int instance_id = 0; |
| 409 BrowserPluginHostMsg_ResizeGuest_Params params; | 418 BrowserPluginHostMsg_CreateGuest_Params params; |
| 410 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 419 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 411 | 420 |
| 412 MockBrowserPlugin* browser_plugin = | 421 MockBrowserPlugin* browser_plugin = |
| 413 static_cast<MockBrowserPlugin*>( | 422 static_cast<MockBrowserPlugin*>( |
| 414 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 423 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 415 ASSERT_TRUE(browser_plugin); | 424 ASSERT_TRUE(browser_plugin); |
| 416 | 425 |
| 417 { | 426 { |
| 418 BrowserPluginMsg_LoadCommit_Params navigate_params; | 427 BrowserPluginMsg_LoadCommit_Params navigate_params; |
| 419 navigate_params.is_top_level = true; | 428 navigate_params.is_top_level = true; |
| 420 navigate_params.url = GURL(kGoogleURL); | 429 navigate_params.url = GURL(kGoogleURL); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 "document.getElementById('browserplugin').src")); | 534 "document.getElementById('browserplugin').src")); |
| 526 } | 535 } |
| 527 | 536 |
| 528 // Verify that the BrowserPlugin accepts changes to its src attribue after | 537 // Verify that the BrowserPlugin accepts changes to its src attribue after |
| 529 // setting the partition to a valid value. | 538 // setting the partition to a valid value. |
| 530 ExecuteJavaScript( | 539 ExecuteJavaScript( |
| 531 "document.getElementById('browserplugin').partition = 'persist:foo'"); | 540 "document.getElementById('browserplugin').partition = 'persist:foo'"); |
| 532 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | 541 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 533 EXPECT_EQ("bar", ExecuteScriptAndReturnString( | 542 EXPECT_EQ("bar", ExecuteScriptAndReturnString( |
| 534 "document.getElementById('browserplugin').src")); | 543 "document.getElementById('browserplugin').src")); |
| 544 ProcessPendingMessages(); |
| 535 // Verify that the BrowserPlugin does not 'deadlock': it can recover from | 545 // Verify that the BrowserPlugin does not 'deadlock': it can recover from |
| 536 // the partition ID error state. | 546 // the partition ID error state. |
| 537 { | 547 { |
| 538 ExecuteJavaScript( | 548 ExecuteJavaScript( |
| 539 "try {" | 549 "try {" |
| 540 " document.getElementById('browserplugin').partition = 'persist:1337';" | 550 " document.getElementById('browserplugin').partition = 'persist:1337';" |
| 541 " document.title = 'success';" | 551 " document.title = 'success';" |
| 542 "} catch (e) { document.title = e.message; }"); | 552 "} catch (e) { document.title = e.message; }"); |
| 543 std::string title = ExecuteScriptAndReturnString("document.title"); | 553 std::string title = ExecuteScriptAndReturnString("document.title"); |
| 544 EXPECT_STREQ( | 554 EXPECT_STREQ( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 561 "document.getElementById('browserplugin').partition = 'storage'"); | 571 "document.getElementById('browserplugin').partition = 'storage'"); |
| 562 std::string partition_value = ExecuteScriptAndReturnString( | 572 std::string partition_value = ExecuteScriptAndReturnString( |
| 563 "document.getElementById('browserplugin').partition"); | 573 "document.getElementById('browserplugin').partition"); |
| 564 EXPECT_STREQ("storage", partition_value.c_str()); | 574 EXPECT_STREQ("storage", partition_value.c_str()); |
| 565 | 575 |
| 566 std::string src_value = ExecuteScriptAndReturnString( | 576 std::string src_value = ExecuteScriptAndReturnString( |
| 567 "document.getElementById('browserplugin').src"); | 577 "document.getElementById('browserplugin').src"); |
| 568 EXPECT_STREQ("", src_value.c_str()); | 578 EXPECT_STREQ("", src_value.c_str()); |
| 569 | 579 |
| 570 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | 580 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 581 ProcessPendingMessages(); |
| 571 { | 582 { |
| 572 const IPC::Message* create_msg = | 583 const IPC::Message* create_msg = |
| 573 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 584 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 574 BrowserPluginHostMsg_CreateGuest::ID); | 585 BrowserPluginHostMsg_CreateGuest::ID); |
| 575 ASSERT_TRUE(create_msg); | 586 ASSERT_TRUE(create_msg); |
| 576 | 587 |
| 577 int create_instance_id = 0; | 588 int create_instance_id = 0; |
| 578 BrowserPluginHostMsg_CreateGuest_Params params; | 589 BrowserPluginHostMsg_CreateGuest_Params params; |
| 579 BrowserPluginHostMsg_CreateGuest::Read( | 590 BrowserPluginHostMsg_CreateGuest::Read( |
| 580 create_msg, | 591 create_msg, |
| 581 &create_instance_id, | 592 &create_instance_id, |
| 582 ¶ms); | 593 ¶ms); |
| 583 EXPECT_STREQ("storage", params.storage_partition_id.c_str()); | 594 EXPECT_STREQ("storage", params.storage_partition_id.c_str()); |
| 584 EXPECT_FALSE(params.persist_storage); | 595 EXPECT_FALSE(params.persist_storage); |
| 585 | 596 EXPECT_STREQ("bar", params.src.c_str()); |
| 586 const IPC::Message* msg = | |
| 587 browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
| 588 BrowserPluginHostMsg_NavigateGuest::ID); | |
| 589 ASSERT_TRUE(msg); | |
| 590 | |
| 591 int instance_id = 0; | |
| 592 std::string src; | |
| 593 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src); | |
| 594 EXPECT_STREQ("bar", src.c_str()); | |
| 595 EXPECT_EQ(create_instance_id, instance_id); | |
| 596 } | 597 } |
| 597 | 598 |
| 598 // Setting the partition should throw an exception and the value should not | 599 // Setting the partition should throw an exception and the value should not |
| 599 // change. | 600 // change. |
| 600 ExecuteJavaScript( | 601 ExecuteJavaScript( |
| 601 "try {" | 602 "try {" |
| 602 " document.getElementById('browserplugin').partition = 'someid';" | 603 " document.getElementById('browserplugin').partition = 'someid';" |
| 603 " document.title = 'success';" | 604 " document.title = 'success';" |
| 604 "} catch (e) { document.title = e.message; }"); | 605 "} catch (e) { document.title = e.message; }"); |
| 605 | 606 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 625 "}" | 626 "}" |
| 626 "document.getElementById('browserplugin')." | 627 "document.getElementById('browserplugin')." |
| 627 " addEventListener('-internal-loadcommit', nav);"; | 628 " addEventListener('-internal-loadcommit', nav);"; |
| 628 const char* kGoogleURL = "http://www.google.com/"; | 629 const char* kGoogleURL = "http://www.google.com/"; |
| 629 const char* kGoogleNewsURL = "http://news.google.com/"; | 630 const char* kGoogleNewsURL = "http://news.google.com/"; |
| 630 const char* kGetProcessID = | 631 const char* kGetProcessID = |
| 631 "document.getElementById('browserplugin').getProcessId()"; | 632 "document.getElementById('browserplugin').getProcessId()"; |
| 632 | 633 |
| 633 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 634 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 634 ExecuteJavaScript(kAddEventListener); | 635 ExecuteJavaScript(kAddEventListener); |
| 635 // Grab the BrowserPlugin's instance ID from its resize message. | 636 // Grab the BrowserPlugin's instance ID from its CreateGuest message. |
| 636 const IPC::Message* msg = | 637 const IPC::Message* msg = |
| 637 browser_plugin_manager()->sink().GetFirstMessageMatching( | 638 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 638 BrowserPluginHostMsg_ResizeGuest::ID); | 639 BrowserPluginHostMsg_CreateGuest::ID); |
| 639 ASSERT_TRUE(msg); | 640 ASSERT_TRUE(msg); |
| 640 int instance_id = 0; | 641 int instance_id = 0; |
| 641 BrowserPluginHostMsg_ResizeGuest_Params params; | 642 BrowserPluginHostMsg_CreateGuest_Params params; |
| 642 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 643 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 643 | 644 |
| 644 MockBrowserPlugin* browser_plugin = | 645 MockBrowserPlugin* browser_plugin = |
| 645 static_cast<MockBrowserPlugin*>( | 646 static_cast<MockBrowserPlugin*>( |
| 646 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 647 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 647 ASSERT_TRUE(browser_plugin); | 648 ASSERT_TRUE(browser_plugin); |
| 648 | 649 |
| 649 { | 650 { |
| 650 BrowserPluginMsg_LoadCommit_Params navigate_params; | 651 BrowserPluginMsg_LoadCommit_Params navigate_params; |
| 651 navigate_params.url = GURL(kGoogleURL); | 652 navigate_params.url = GURL(kGoogleURL); |
| 652 navigate_params.process_id = 1337; | 653 navigate_params.process_id = 1337; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 682 "document.getElementById('browserplugin')." | 683 "document.getElementById('browserplugin')." |
| 683 " addEventListener('-internal-loadcommit', nava);" | 684 " addEventListener('-internal-loadcommit', nava);" |
| 684 "document.getElementById('browserplugin')." | 685 "document.getElementById('browserplugin')." |
| 685 " addEventListener('-internal-loadcommit', navb);"; | 686 " addEventListener('-internal-loadcommit', navb);"; |
| 686 const char* kGoogleURL = "http://www.google.com/"; | 687 const char* kGoogleURL = "http://www.google.com/"; |
| 687 const char* kGetProcessID = | 688 const char* kGetProcessID = |
| 688 "document.getElementById('browserplugin').getProcessId()"; | 689 "document.getElementById('browserplugin').getProcessId()"; |
| 689 | 690 |
| 690 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 691 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 691 ExecuteJavaScript(kAddEventListener); | 692 ExecuteJavaScript(kAddEventListener); |
| 692 // Grab the BrowserPlugin's instance ID from its resize message. | 693 // Grab the BrowserPlugin's instance ID from its CreateGuest message. |
| 693 const IPC::Message* msg = | 694 const IPC::Message* msg = |
| 694 browser_plugin_manager()->sink().GetFirstMessageMatching( | 695 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 695 BrowserPluginHostMsg_ResizeGuest::ID); | 696 BrowserPluginHostMsg_CreateGuest::ID); |
| 696 ASSERT_TRUE(msg); | 697 ASSERT_TRUE(msg); |
| 697 int instance_id = 0; | 698 int instance_id = 0; |
| 698 BrowserPluginHostMsg_ResizeGuest_Params params; | 699 BrowserPluginHostMsg_CreateGuest_Params params; |
| 699 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 700 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 700 | 701 |
| 701 MockBrowserPlugin* browser_plugin = | 702 MockBrowserPlugin* browser_plugin = |
| 702 static_cast<MockBrowserPlugin*>( | 703 static_cast<MockBrowserPlugin*>( |
| 703 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 704 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 704 ASSERT_TRUE(browser_plugin); | 705 ASSERT_TRUE(browser_plugin); |
| 705 | 706 |
| 706 { | 707 { |
| 707 BrowserPluginMsg_LoadCommit_Params navigate_params; | 708 BrowserPluginMsg_LoadCommit_Params navigate_params; |
| 708 navigate_params.url = GURL(kGoogleURL); | 709 navigate_params.url = GURL(kGoogleURL); |
| 709 navigate_params.process_id = 1337; | 710 navigate_params.process_id = 1337; |
| 710 BrowserPluginMsg_LoadCommit msg(0, instance_id, navigate_params); | 711 BrowserPluginMsg_LoadCommit msg(0, instance_id, navigate_params); |
| 711 browser_plugin->OnMessageReceived(msg); | 712 browser_plugin->OnMessageReceived(msg); |
| 712 EXPECT_EQ(2, ExecuteScriptAndReturnInt("count")); | 713 EXPECT_EQ(2, ExecuteScriptAndReturnInt("count")); |
| 713 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID)); | 714 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID)); |
| 714 } | 715 } |
| 715 } | 716 } |
| 716 | 717 |
| 717 TEST_F(BrowserPluginTest, RemoveBrowserPluginOnExit) { | 718 TEST_F(BrowserPluginTest, RemoveBrowserPluginOnExit) { |
| 718 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 719 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 719 | 720 |
| 720 // Grab the BrowserPlugin's instance ID from its resize message. | 721 // Grab the BrowserPlugin's instance ID from its CreateGuest message. |
| 721 int instance_id = 0; | 722 int instance_id = 0; |
| 722 { | 723 { |
| 723 const IPC::Message* msg = | 724 const IPC::Message* msg = |
| 724 browser_plugin_manager()->sink().GetFirstMessageMatching( | 725 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 725 BrowserPluginHostMsg_ResizeGuest::ID); | 726 BrowserPluginHostMsg_CreateGuest::ID); |
| 726 ASSERT_TRUE(msg); | 727 ASSERT_TRUE(msg); |
| 727 BrowserPluginHostMsg_ResizeGuest_Params params; | 728 BrowserPluginHostMsg_CreateGuest_Params params; |
| 728 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, ¶ms); | 729 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, ¶ms); |
| 729 } | 730 } |
| 730 | 731 |
| 731 MockBrowserPlugin* browser_plugin = | 732 MockBrowserPlugin* browser_plugin = |
| 732 static_cast<MockBrowserPlugin*>( | 733 static_cast<MockBrowserPlugin*>( |
| 733 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 734 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 734 ASSERT_TRUE(browser_plugin); | 735 ASSERT_TRUE(browser_plugin); |
| 735 | 736 |
| 736 const char* kAddEventListener = | 737 const char* kAddEventListener = |
| 737 "function exitListener(e) {" | 738 "function exitListener(e) {" |
| 738 " if (JSON.parse(e.detail).reason == 'killed') {" | 739 " if (JSON.parse(e.detail).reason == 'killed') {" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 &resize_params); | 838 &resize_params); |
| 838 EXPECT_FALSE(auto_size_params.enable); | 839 EXPECT_FALSE(auto_size_params.enable); |
| 839 EXPECT_EQ(42, auto_size_params.min_size.width()); | 840 EXPECT_EQ(42, auto_size_params.min_size.width()); |
| 840 EXPECT_EQ(43, auto_size_params.min_size.height()); | 841 EXPECT_EQ(43, auto_size_params.min_size.height()); |
| 841 EXPECT_EQ(1337, auto_size_params.max_size.width()); | 842 EXPECT_EQ(1337, auto_size_params.max_size.width()); |
| 842 EXPECT_EQ(1338, auto_size_params.max_size.height()); | 843 EXPECT_EQ(1338, auto_size_params.max_size.height()); |
| 843 } | 844 } |
| 844 } | 845 } |
| 845 | 846 |
| 846 } // namespace content | 847 } // namespace content |
| OLD | NEW |