content/renderer/browser_plugin/browser_plugin_browsertest.cc
// This test verifies that we can mutate the event listener vector
// within an event listener.
This test verifies that we can mutate the event listener vector
within an event listener.
This test verifies that we can mutate the event listener vector within an event listener .
TEST_F(BrowserPluginTest, RemoveEventListenerInEventListener) {
  const char* kAddEventListener =
    "var url;"
    "function nav(e) {"
    "  url = JSON.parse(e.detail).url;"
    "  document.getElementById('browserplugin')."
    "      removeEventListener('-internal-loadcommit', nav);"
    "}"
    "document.getElementById('browserplugin')."
    "    addEventListener('-internal-loadcommit', nav);";
  const char* kGoogleURL = "http://www.google.com/";
  const char* kGoogleNewsURL = "http://news.google.com/";
  const char* kGetProcessID =
      "document.getElementById('browserplugin').getProcessId()";
  LoadHTML(GetHTMLForBrowserPluginObject().c_str());
  ExecuteJavaScript(kAddEventListener);
  const IPC::Message* msg =
      browser_plugin_manager()->sink().GetFirstMessageMatching(
          BrowserPluginHostMsg_ResizeGuest::ID);
  ASSERT_TRUE(msg);
  int instance_id = 0;
  BrowserPluginHostMsg_ResizeGuest_Params params;
  BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params);
  MockBrowserPlugin* browser_plugin =
      static_cast<MockBrowserPlugin*>(
          browser_plugin_manager()->GetBrowserPlugin(instance_id));
  ASSERT_TRUE(browser_plugin);
  {
    BrowserPluginMsg_LoadCommit_Params navigate_params;
    navigate_params.url = GURL(kGoogleURL);
    navigate_params.process_id = 1337;
    BrowserPluginMsg_LoadCommit msg(0, instance_id, navigate_params);
    browser_plugin->OnMessageReceived(msg);
    EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
    EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
  }
  {
    BrowserPluginMsg_LoadCommit_Params navigate_params;
    navigate_params.url = GURL(kGoogleNewsURL);
    navigate_params.process_id = 42;
    BrowserPluginMsg_LoadCommit msg(0, instance_id, navigate_params);
    browser_plugin->OnMessageReceived(msg);
    EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
    EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID));
  }
}
TEST_F ( BrowserPluginTest , RemoveEventListenerInEventListener ) { const char * kAddEventListener = " " " " " " " " " " " " " " " " ; const char * kGoogleURL = " " ; const char * kGoogleNewsURL = " " ; const char * kGetProcessID = " " ; LoadHTML ( GetHTMLForBrowserPluginObject ( ) . c_str ( ) ) ; ExecuteJavaScript ( kAddEventListener ) ; const IPC :: Message * msg = browser_plugin_manager ( ) -> sink ( ) . GetFirstMessageMatching ( BrowserPluginHostMsg_ResizeGuest :: ID ) ; ASSERT_TRUE ( msg ) ; int instance_id = 0 ; BrowserPluginHostMsg_ResizeGuest_Params params ; BrowserPluginHostMsg_ResizeGuest :: Read ( msg , & instance_id , & params ) ; MockBrowserPlugin * browser_plugin = static_cast < MockBrowserPlugin * > ( browser_plugin_manager ( ) -> GetBrowserPlugin ( instance_id ) ) ; ASSERT_TRUE ( browser_plugin ) ; { BrowserPluginMsg_LoadCommit_Params navigate_params ; navigate_params . url = GURL ( kGoogleURL ) ; navigate_params . process_id = 1337 ; BrowserPluginMsg_LoadCommit msg ( 0 , instance_id , navigate_params ) ; browser_plugin -> OnMessageReceived ( msg ) ; EXPECT_EQ ( kGoogleURL , ExecuteScriptAndReturnString ( " " ) ) ; EXPECT_EQ ( 1337 , ExecuteScriptAndReturnInt ( kGetProcessID ) ) ; } { BrowserPluginMsg_LoadCommit_Params navigate_params ; navigate_params . url = GURL ( kGoogleNewsURL ) ; navigate_params . process_id = 42 ; BrowserPluginMsg_LoadCommit msg ( 0 , instance_id , navigate_params ) ; browser_plugin -> OnMessageReceived ( msg ) ; EXPECT_EQ ( kGoogleURL , ExecuteScriptAndReturnString ( " " ) ) ; EXPECT_EQ ( 42 , ExecuteScriptAndReturnInt ( kGetProcessID ) ) ; } }
This test verifies that we can mutate the event listener vector
within an event listener.
This test verifies that we can mutate the event listener vector within an event listener .
// Grab the BrowserPlugin's instance ID from its resize message. // The URL variable should not change because we've removed the event // listener.