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

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

Issue 17165004: <webview>: Partially migrate loadcommit event from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with ToT Created 7 years, 5 months 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
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/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 LoadHTML(html.c_str()); 446 LoadHTML(html.c_str());
447 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 447 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
448 BrowserPluginHostMsg_PluginDestroyed::ID)); 448 BrowserPluginHostMsg_PluginDestroyed::ID));
449 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 449 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
450 "x.parentNode.removeChild(x);"); 450 "x.parentNode.removeChild(x);");
451 ProcessPendingMessages(); 451 ProcessPendingMessages();
452 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 452 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
453 BrowserPluginHostMsg_PluginDestroyed::ID)); 453 BrowserPluginHostMsg_PluginDestroyed::ID));
454 } 454 }
455 455
456 TEST_F(BrowserPluginTest, CustomEvents) {
457 const char* kAddEventListener =
458 "var url;"
459 "function nav(e) {"
460 " url = JSON.parse(e.detail).url;"
461 "}"
462 "document.getElementById('browserplugin')."
463 " addEventListener('-internal-loadcommit', nav);";
464 const char* kRemoveEventListener =
465 "document.getElementById('browserplugin')."
466 " removeEventListener('-internal-loadcommit', nav);";
467 const char* kGetSrc =
468 "document.getElementById('browserplugin').src";
469 const char* kGoogleURL = "http://www.google.com/";
470 const char* kGoogleNewsURL = "http://news.google.com/";
471
472 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
473 ExecuteJavaScript(kAddEventListener);
474
475 MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
476 ASSERT_TRUE(browser_plugin);
477 int instance_id = browser_plugin->instance_id();
478
479 {
480 BrowserPluginMsg_LoadCommit_Params navigate_params;
481 navigate_params.is_top_level = true;
482 navigate_params.url = GURL(kGoogleURL);
483 BrowserPluginMsg_LoadCommit msg(instance_id, navigate_params);
484 browser_plugin->OnMessageReceived(msg);
485 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
486 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString(kGetSrc));
487 }
488 ExecuteJavaScript(kRemoveEventListener);
489 {
490 BrowserPluginMsg_LoadCommit_Params navigate_params;
491 navigate_params.is_top_level = false;
492 navigate_params.url = GURL(kGoogleNewsURL);
493 BrowserPluginMsg_LoadCommit msg(instance_id, navigate_params);
494 browser_plugin->OnMessageReceived(msg);
495 // The URL variable should not change because we've removed the event
496 // listener.
497 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
498 // The src attribute should not change if this is a top-level navigation.
499 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString(kGetSrc));
500 }
501 }
502
503 TEST_F(BrowserPluginTest, StopMethod) { 456 TEST_F(BrowserPluginTest, StopMethod) {
504 const char* kCallStop = 457 const char* kCallStop =
505 "document.getElementById('browserplugin').stop();"; 458 "document.getElementById('browserplugin').stop();";
506 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 459 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
507 ExecuteJavaScript(kCallStop); 460 ExecuteJavaScript(kCallStop);
508 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 461 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
509 BrowserPluginHostMsg_Stop::ID)); 462 BrowserPluginHostMsg_Stop::ID));
510 } 463 }
511 464
512 TEST_F(BrowserPluginTest, ReloadMethod) { 465 TEST_F(BrowserPluginTest, ReloadMethod) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 std::string title = ExecuteScriptAndReturnString("document.title"); 603 std::string title = ExecuteScriptAndReturnString("document.title");
651 EXPECT_STREQ( 604 EXPECT_STREQ(
652 "The object has already navigated, so its partition cannot be changed.", 605 "The object has already navigated, so its partition cannot be changed.",
653 title.c_str()); 606 title.c_str());
654 607
655 partition_value = ExecuteScriptAndReturnString( 608 partition_value = ExecuteScriptAndReturnString(
656 "document.getElementById('browserplugin').partition"); 609 "document.getElementById('browserplugin').partition");
657 EXPECT_STREQ("storage", partition_value.c_str()); 610 EXPECT_STREQ("storage", partition_value.c_str());
658 } 611 }
659 612
660 // This test verifies that we can mutate the event listener vector
661 // within an event listener.
662 TEST_F(BrowserPluginTest, RemoveEventListenerInEventListener) {
663 const char* kAddEventListener =
664 "var url;"
665 "function nav(e) {"
666 " url = JSON.parse(e.detail).url;"
667 " document.getElementById('browserplugin')."
668 " removeEventListener('-internal-loadcommit', nav);"
669 "}"
670 "document.getElementById('browserplugin')."
671 " addEventListener('-internal-loadcommit', nav);";
672 const char* kGoogleURL = "http://www.google.com/";
673 const char* kGoogleNewsURL = "http://news.google.com/";
674
675 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
676 ExecuteJavaScript(kAddEventListener);
677
678 MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
679 ASSERT_TRUE(browser_plugin);
680 int instance_id = browser_plugin->instance_id();
681
682 {
683 BrowserPluginMsg_LoadCommit_Params navigate_params;
684 navigate_params.url = GURL(kGoogleURL);
685 BrowserPluginMsg_LoadCommit msg(instance_id, navigate_params);
686 browser_plugin->OnMessageReceived(msg);
687 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
688 }
689 {
690 BrowserPluginMsg_LoadCommit_Params navigate_params;
691 navigate_params.url = GURL(kGoogleNewsURL);
692 BrowserPluginMsg_LoadCommit msg(instance_id, navigate_params);
693 browser_plugin->OnMessageReceived(msg);
694 // The URL variable should not change because we've removed the event
695 // listener.
696 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
697 }
698 }
699
700 // This test verifies that multiple event listeners fire that are registered
701 // on a single event type.
702 TEST_F(BrowserPluginTest, MultipleEventListeners) {
703 const char* kAddEventListener =
704 "var count = 0;"
705 "function nava(u) {"
706 " count++;"
707 "}"
708 "function navb(u) {"
709 " count++;"
710 "}"
711 "document.getElementById('browserplugin')."
712 " addEventListener('-internal-loadcommit', nava);"
713 "document.getElementById('browserplugin')."
714 " addEventListener('-internal-loadcommit', navb);";
715 const char* kGoogleURL = "http://www.google.com/";
716
717 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
718 ExecuteJavaScript(kAddEventListener);
719
720 MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
721 ASSERT_TRUE(browser_plugin);
722 int instance_id = browser_plugin->instance_id();
723
724 {
725 BrowserPluginMsg_LoadCommit_Params navigate_params;
726 navigate_params.url = GURL(kGoogleURL);
727 BrowserPluginMsg_LoadCommit msg(instance_id, navigate_params);
728 browser_plugin->OnMessageReceived(msg);
729 EXPECT_EQ(2, ExecuteScriptAndReturnInt("count"));
730 }
731 }
732
733 TEST_F(BrowserPluginTest, RemoveBrowserPluginOnExit) { 613 TEST_F(BrowserPluginTest, RemoveBrowserPluginOnExit) {
734 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 614 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
735 615
736 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); 616 MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
737 ASSERT_TRUE(browser_plugin); 617 ASSERT_TRUE(browser_plugin);
738 int instance_id = browser_plugin->instance_id(); 618 int instance_id = browser_plugin->instance_id();
739 619
740 const char* kAddEventListener = 620 const char* kAddEventListener =
741 "function exitListener(e) {" 621 "function exitListener(e) {"
742 " if (JSON.parse(e.detail).reason == 'killed') {" 622 " if (JSON.parse(e.detail).reason == 'killed') {"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 // These value are not populated (as an optimization) if autosize is 715 // These value are not populated (as an optimization) if autosize is
836 // disabled. 716 // disabled.
837 EXPECT_EQ(0, auto_size_params.min_size.width()); 717 EXPECT_EQ(0, auto_size_params.min_size.width());
838 EXPECT_EQ(0, auto_size_params.min_size.height()); 718 EXPECT_EQ(0, auto_size_params.min_size.height());
839 EXPECT_EQ(0, auto_size_params.max_size.width()); 719 EXPECT_EQ(0, auto_size_params.max_size.width());
840 EXPECT_EQ(0, auto_size_params.max_size.height()); 720 EXPECT_EQ(0, auto_size_params.max_size.height());
841 } 721 }
842 } 722 }
843 723
844 } // namespace content 724 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.cc ('k') | content/test/data/browser_plugin_embedder.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698