| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Send an event and verify that the event is deported. | 267 // Send an event and verify that the event is deported. |
| 268 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), | 268 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), |
| 269 cursor_info); | 269 cursor_info); |
| 270 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 270 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 271 BrowserPluginHostMsg_HandleInputEvent::ID)); | 271 BrowserPluginHostMsg_HandleInputEvent::ID)); |
| 272 browser_plugin_manager()->sink().ClearMessages(); | 272 browser_plugin_manager()->sink().ClearMessages(); |
| 273 | 273 |
| 274 const char* kAddEventListener = | 274 const char* kAddEventListener = |
| 275 "var msg;" | 275 "var msg;" |
| 276 "function exitListener(e) {" | 276 "function exitListener(e) {" |
| 277 " msg = e.type;" | 277 " msg = e.detail.reason;" |
| 278 "}" | 278 "}" |
| 279 "document.getElementById('browserplugin')." | 279 "document.getElementById('browserplugin')." |
| 280 " addEventListener('exit', exitListener);"; | 280 " addEventListener('-internal-exit', exitListener);"; |
| 281 | 281 |
| 282 ExecuteJavaScript(kAddEventListener); | 282 ExecuteJavaScript(kAddEventListener); |
| 283 | 283 |
| 284 // Pretend that the guest has terminated normally. | 284 // Pretend that the guest has terminated normally. |
| 285 browser_plugin->GuestGone(0, base::TERMINATION_STATUS_NORMAL_TERMINATION); | 285 browser_plugin->GuestGone(0, base::TERMINATION_STATUS_NORMAL_TERMINATION); |
| 286 | 286 |
| 287 // Verify that our event listener has fired. | 287 // Verify that our event listener has fired. |
| 288 EXPECT_EQ("normal", ExecuteScriptAndReturnString("msg")); | 288 EXPECT_EQ("normal", ExecuteScriptAndReturnString("msg")); |
| 289 | 289 |
| 290 // Pretend that the guest has crashed. | 290 // Pretend that the guest has crashed. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 308 "x.parentNode.removeChild(x);"); | 308 "x.parentNode.removeChild(x);"); |
| 309 ProcessPendingMessages(); | 309 ProcessPendingMessages(); |
| 310 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 310 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 311 BrowserPluginHostMsg_PluginDestroyed::ID)); | 311 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 312 } | 312 } |
| 313 | 313 |
| 314 TEST_F(BrowserPluginTest, CustomEvents) { | 314 TEST_F(BrowserPluginTest, CustomEvents) { |
| 315 const char* kAddEventListener = | 315 const char* kAddEventListener = |
| 316 "var url;" | 316 "var url;" |
| 317 "function nav(u) {" | 317 "function nav(u) {" |
| 318 " url = u.url;" | 318 " url = u.detail.url;" |
| 319 "}" | 319 "}" |
| 320 "document.getElementById('browserplugin')." | 320 "document.getElementById('browserplugin')." |
| 321 " addEventListener('loadcommit', nav);"; | 321 " addEventListener('-internal-loadcommit', nav);"; |
| 322 const char* kRemoveEventListener = | 322 const char* kRemoveEventListener = |
| 323 "document.getElementById('browserplugin')." | 323 "document.getElementById('browserplugin')." |
| 324 " removeEventListener('loadcommit', nav);"; | 324 " removeEventListener('-internal-loadcommit', nav);"; |
| 325 const char* kGetProcessID = | 325 const char* kGetProcessID = |
| 326 "document.getElementById('browserplugin').getProcessId()"; | 326 "document.getElementById('browserplugin').getProcessId()"; |
| 327 const char* kGoogleURL = "http://www.google.com/"; | 327 const char* kGoogleURL = "http://www.google.com/"; |
| 328 const char* kGoogleNewsURL = "http://news.google.com/"; | 328 const char* kGoogleNewsURL = "http://news.google.com/"; |
| 329 | 329 |
| 330 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 330 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 331 ExecuteJavaScript(kAddEventListener); | 331 ExecuteJavaScript(kAddEventListener); |
| 332 // Grab the BrowserPlugin's instance ID from its resize message. | 332 // Grab the BrowserPlugin's instance ID from its resize message. |
| 333 const IPC::Message* msg = | 333 const IPC::Message* msg = |
| 334 browser_plugin_manager()->sink().GetFirstMessageMatching( | 334 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 "document.getElementById('browserplugin').partition"); | 495 "document.getElementById('browserplugin').partition"); |
| 496 EXPECT_STREQ("storage", partition_value.c_str()); | 496 EXPECT_STREQ("storage", partition_value.c_str()); |
| 497 } | 497 } |
| 498 | 498 |
| 499 // This test verifies that we can mutate the event listener vector | 499 // This test verifies that we can mutate the event listener vector |
| 500 // within an event listener. | 500 // within an event listener. |
| 501 TEST_F(BrowserPluginTest, RemoveEventListenerInEventListener) { | 501 TEST_F(BrowserPluginTest, RemoveEventListenerInEventListener) { |
| 502 const char* kAddEventListener = | 502 const char* kAddEventListener = |
| 503 "var url;" | 503 "var url;" |
| 504 "function nav(u) {" | 504 "function nav(u) {" |
| 505 " url = u.url;" | 505 " url = u.detail.url;" |
| 506 " document.getElementById('browserplugin')." | 506 " document.getElementById('browserplugin')." |
| 507 " removeEventListener('loadcommit', nav);" | 507 " removeEventListener('-internal-loadcommit', nav);" |
| 508 "}" | 508 "}" |
| 509 "document.getElementById('browserplugin')." | 509 "document.getElementById('browserplugin')." |
| 510 " addEventListener('loadcommit', nav);"; | 510 " addEventListener('-internal-loadcommit', nav);"; |
| 511 const char* kGoogleURL = "http://www.google.com/"; | 511 const char* kGoogleURL = "http://www.google.com/"; |
| 512 const char* kGoogleNewsURL = "http://news.google.com/"; | 512 const char* kGoogleNewsURL = "http://news.google.com/"; |
| 513 const char* kGetProcessID = | 513 const char* kGetProcessID = |
| 514 "document.getElementById('browserplugin').getProcessId()"; | 514 "document.getElementById('browserplugin').getProcessId()"; |
| 515 | 515 |
| 516 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 516 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 517 ExecuteJavaScript(kAddEventListener); | 517 ExecuteJavaScript(kAddEventListener); |
| 518 // Grab the BrowserPlugin's instance ID from its resize message. | 518 // Grab the BrowserPlugin's instance ID from its resize message. |
| 519 const IPC::Message* msg = | 519 const IPC::Message* msg = |
| 520 browser_plugin_manager()->sink().GetFirstMessageMatching( | 520 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 TEST_F(BrowserPluginTest, MultipleEventListeners) { | 555 TEST_F(BrowserPluginTest, MultipleEventListeners) { |
| 556 const char* kAddEventListener = | 556 const char* kAddEventListener = |
| 557 "var count = 0;" | 557 "var count = 0;" |
| 558 "function nava(u) {" | 558 "function nava(u) {" |
| 559 " count++;" | 559 " count++;" |
| 560 "}" | 560 "}" |
| 561 "function navb(u) {" | 561 "function navb(u) {" |
| 562 " count++;" | 562 " count++;" |
| 563 "}" | 563 "}" |
| 564 "document.getElementById('browserplugin')." | 564 "document.getElementById('browserplugin')." |
| 565 " addEventListener('loadcommit', nava);" | 565 " addEventListener('-internal-loadcommit', nava);" |
| 566 "document.getElementById('browserplugin')." | 566 "document.getElementById('browserplugin')." |
| 567 " addEventListener('loadcommit', navb);"; | 567 " addEventListener('-internal-loadcommit', navb);"; |
| 568 const char* kGoogleURL = "http://www.google.com/"; | 568 const char* kGoogleURL = "http://www.google.com/"; |
| 569 const char* kGetProcessID = | 569 const char* kGetProcessID = |
| 570 "document.getElementById('browserplugin').getProcessId()"; | 570 "document.getElementById('browserplugin').getProcessId()"; |
| 571 | 571 |
| 572 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 572 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 573 ExecuteJavaScript(kAddEventListener); | 573 ExecuteJavaScript(kAddEventListener); |
| 574 // Grab the BrowserPlugin's instance ID from its resize message. | 574 // Grab the BrowserPlugin's instance ID from its resize message. |
| 575 const IPC::Message* msg = | 575 const IPC::Message* msg = |
| 576 browser_plugin_manager()->sink().GetFirstMessageMatching( | 576 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 577 BrowserPluginHostMsg_ResizeGuest::ID); | 577 BrowserPluginHostMsg_ResizeGuest::ID); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); | 609 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); |
| 610 int instance_id = resize_params.a; | 610 int instance_id = resize_params.a; |
| 611 | 611 |
| 612 MockBrowserPlugin* browser_plugin = | 612 MockBrowserPlugin* browser_plugin = |
| 613 static_cast<MockBrowserPlugin*>( | 613 static_cast<MockBrowserPlugin*>( |
| 614 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 614 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 615 ASSERT_TRUE(browser_plugin); | 615 ASSERT_TRUE(browser_plugin); |
| 616 | 616 |
| 617 const char* kAddEventListener = | 617 const char* kAddEventListener = |
| 618 "function exitListener(e) {" | 618 "function exitListener(e) {" |
| 619 " if (e.type == 'killed') {" | 619 " if (e.detail.reason == 'killed') {" |
| 620 " var bp = document.getElementById('browserplugin');" | 620 " var bp = document.getElementById('browserplugin');" |
| 621 " bp.parentNode.removeChild(bp);" | 621 " bp.parentNode.removeChild(bp);" |
| 622 " }" | 622 " }" |
| 623 "}" | 623 "}" |
| 624 "document.getElementById('browserplugin')." | 624 "document.getElementById('browserplugin')." |
| 625 " addEventListener('exit', exitListener);"; | 625 " addEventListener('-internal-exit', exitListener);"; |
| 626 | 626 |
| 627 ExecuteJavaScript(kAddEventListener); | 627 ExecuteJavaScript(kAddEventListener); |
| 628 | 628 |
| 629 // Pretend that the guest has crashed. | 629 // Pretend that the guest has crashed. |
| 630 browser_plugin->GuestGone(0, base::TERMINATION_STATUS_PROCESS_WAS_KILLED); | 630 browser_plugin->GuestGone(0, base::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
| 631 | 631 |
| 632 ProcessPendingMessages(); | 632 ProcessPendingMessages(); |
| 633 | 633 |
| 634 EXPECT_EQ(NULL, browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 634 EXPECT_EQ(NULL, browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 635 } | 635 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 ¶ms); | 690 ¶ms); |
| 691 EXPECT_FALSE(params.enable); | 691 EXPECT_FALSE(params.enable); |
| 692 EXPECT_EQ(42, params.min_width); | 692 EXPECT_EQ(42, params.min_width); |
| 693 EXPECT_EQ(43, params.min_height); | 693 EXPECT_EQ(43, params.min_height); |
| 694 EXPECT_EQ(1337, params.max_width); | 694 EXPECT_EQ(1337, params.max_width); |
| 695 EXPECT_EQ(1338, params.max_height); | 695 EXPECT_EQ(1338, params.max_height); |
| 696 } | 696 } |
| 697 } | 697 } |
| 698 | 698 |
| 699 } // namespace content | 699 } // namespace content |
| OLD | NEW |