Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1010)

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_browsertest.cc

Issue 11368071: browser-plugin: Remove event handling code, and use CustomEvents in webkit instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = JSON.parse(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 16 matching lines...) Expand all
307 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 307 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
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(e) {"
318 " url = u.url;" 318 " url = JSON.parse(e.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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 partition_value = ExecuteScriptAndReturnString( 494 partition_value = ExecuteScriptAndReturnString(
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(e) {"
505 " url = u.url;" 505 " url = JSON.parse(e.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
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
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 (JSON.parse(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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 set_auto_size_params.b; 689 set_auto_size_params.b;
690 EXPECT_FALSE(auto_size_params.enable); 690 EXPECT_FALSE(auto_size_params.enable);
691 EXPECT_EQ(42, auto_size_params.min_size.width()); 691 EXPECT_EQ(42, auto_size_params.min_size.width());
692 EXPECT_EQ(43, auto_size_params.min_size.height()); 692 EXPECT_EQ(43, auto_size_params.min_size.height());
693 EXPECT_EQ(1337, auto_size_params.max_size.width()); 693 EXPECT_EQ(1337, auto_size_params.max_size.width());
694 EXPECT_EQ(1338, auto_size_params.max_size.height()); 694 EXPECT_EQ(1338, auto_size_params.max_size.height());
695 } 695 }
696 } 696 }
697 697
698 } // namespace content 698 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin_bindings.cc ('k') | content/test/data/browser_plugin_embedder.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698