content/renderer/browser_plugin/browser_plugin_browsertest.cc
// Test to verify that after the first navigation, the partition attribute
// cannot be modified.
Test to verify that after the first navigation, the partition attribute
cannot be modified.
Test to verify that after the first navigation the partition attribute cannot be modified .
TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) {
  std::string html = StringPrintf(kHTMLForSourcelessPluginObject,
                                  content::kBrowserPluginMimeType);
  LoadHTML(html.c_str());
  ExecuteJavaScript(
      "document.getElementById('browserplugin').partition = 'storage'");
  std::string partition_value = ExecuteScriptAndReturnString(
      "document.getElementById('browserplugin').partition");
  EXPECT_STREQ("storage", partition_value.c_str());
  std::string src_value = ExecuteScriptAndReturnString(
      "document.getElementById('browserplugin').src");
  EXPECT_STREQ("", src_value.c_str());
  ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'");
  {
    const IPC::Message* create_msg =
    browser_plugin_manager()->sink().GetUniqueMessageMatching(
        BrowserPluginHostMsg_CreateGuest::ID);
    ASSERT_TRUE(create_msg);
    int create_instance_id = 0;
    BrowserPluginHostMsg_CreateGuest_Params params;
    BrowserPluginHostMsg_CreateGuest::Read(
        create_msg,
        &create_instance_id,
        &params);
    EXPECT_STREQ("storage", params.storage_partition_id.c_str());
    EXPECT_FALSE(params.persist_storage);
    const IPC::Message* msg =
        browser_plugin_manager()->sink().GetUniqueMessageMatching(
            BrowserPluginHostMsg_NavigateGuest::ID);
    ASSERT_TRUE(msg);
    int instance_id = 0;
    std::string src;
    BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src);
    EXPECT_STREQ("bar", src.c_str());
    EXPECT_EQ(create_instance_id, instance_id);
  }
  ExecuteJavaScript(
      "try {"
      "  document.getElementById('browserplugin').partition = 'someid';"
      "  document.title = 'success';"
      "} catch (e) { document.title = e.message; }");
  std::string title = ExecuteScriptAndReturnString("document.title");
  EXPECT_STREQ(
      "The object has already navigated, so its partition cannot be changed.",
      title.c_str());
  partition_value = ExecuteScriptAndReturnString(
      "document.getElementById('browserplugin').partition");
  EXPECT_STREQ("storage", partition_value.c_str());
}
TEST_F ( BrowserPluginTest , ImmutableAttributesAfterNavigation ) { std :: string html = StringPrintf ( kHTMLForSourcelessPluginObject , content :: kBrowserPluginMimeType ) ; LoadHTML ( html . c_str ( ) ) ; ExecuteJavaScript ( " " ) ; std :: string partition_value = ExecuteScriptAndReturnString ( " " ) ; EXPECT_STREQ ( " " , partition_value . c_str ( ) ) ; std :: string src_value = ExecuteScriptAndReturnString ( " " ) ; EXPECT_STREQ ( " " , src_value . c_str ( ) ) ; ExecuteJavaScript ( " " ) ; { const IPC :: Message * create_msg = browser_plugin_manager ( ) -> sink ( ) . GetUniqueMessageMatching ( BrowserPluginHostMsg_CreateGuest :: ID ) ; ASSERT_TRUE ( create_msg ) ; int create_instance_id = 0 ; BrowserPluginHostMsg_CreateGuest_Params params ; BrowserPluginHostMsg_CreateGuest :: Read ( create_msg , & create_instance_id , & params ) ; EXPECT_STREQ ( " " , params . storage_partition_id . c_str ( ) ) ; EXPECT_FALSE ( params . persist_storage ) ; const IPC :: Message * msg = browser_plugin_manager ( ) -> sink ( ) . GetUniqueMessageMatching ( BrowserPluginHostMsg_NavigateGuest :: ID ) ; ASSERT_TRUE ( msg ) ; int instance_id = 0 ; std :: string src ; BrowserPluginHostMsg_NavigateGuest :: Read ( msg , & instance_id , & src ) ; EXPECT_STREQ ( " " , src . c_str ( ) ) ; EXPECT_EQ ( create_instance_id , instance_id ) ; } ExecuteJavaScript ( " " " " " " " " ) ; std :: string title = ExecuteScriptAndReturnString ( " " ) ; EXPECT_STREQ ( " " , title . c_str ( ) ) ; partition_value = ExecuteScriptAndReturnString ( " " ) ; EXPECT_STREQ ( " " , partition_value . c_str ( ) ) ; }
Test to verify that after the first navigation, the partition attribute
cannot be modified.
Test to verify that after the first navigation the partition attribute cannot be modified .
// Setting the partition should throw an exception and the value should not // change.