Index: content/renderer/browser_plugin/browser_plugin_browsertest.cc |
diff --git a/content/renderer/browser_plugin/browser_plugin_browsertest.cc b/content/renderer/browser_plugin/browser_plugin_browsertest.cc |
index 7afdd9a8102c0d1f173f0c5d72d52d93b2981c1e..e977fd1338fdde61efc7b370936aadbbdc33d36b 100644 |
--- a/content/renderer/browser_plugin/browser_plugin_browsertest.cc |
+++ b/content/renderer/browser_plugin/browser_plugin_browsertest.cc |
@@ -30,6 +30,14 @@ std::string GetHTMLForBrowserPluginObject() { |
content::kBrowserPluginNewMimeType); |
} |
+const char kHTMLForPartitionedPluginObject[] = |
+ "<object id='browserplugin' width='640px' height='480px'" |
+ " src='foo' type='%s' partition='someid'>"; |
+ |
+const char kHTMLForPartitionedPersistedPluginObject[] = |
+ "<object id='browserplugin' width='640px' height='480px'" |
+ " src='foo' type='%s' partition='someid' persist>"; |
+ |
} |
namespace content { |
@@ -64,6 +72,18 @@ std::string BrowserPluginTest::ExecuteScriptAndReturnString( |
return str.get(); |
} |
+bool BrowserPluginTest::ExecuteScriptAndReturnBool( |
+ const std::string& script, |
+ bool& result) { |
+ v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( |
+ WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); |
+ if (value.IsEmpty() || !value->IsBoolean()) |
+ return false; |
+ |
+ result = value->BooleanValue(); |
+ return true; |
+} |
+ |
// This test verifies that an initial resize occurs when we instantiate the |
// browser plugin. This test also verifies that the browser plugin is waiting |
// for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and |
@@ -319,4 +339,105 @@ TEST_F(BrowserPluginTest, CustomEvents) { |
EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
} |
+// Verify that the 'partition' attribute on the browser plugin is parsed |
+// correctly. |
+TEST_F(BrowserPluginTest, PartitionAttribute) { |
+ std::string html = StringPrintf(kHTMLForPartitionedPluginObject, |
+ content::kBrowserPluginNewMimeType); |
+ LoadHTML(html.c_str()); |
+ |
+ std::string partition_value = ExecuteScriptAndReturnString( |
+ "document.getElementById('browserplugin').partition"); |
+ EXPECT_EQ("someid", partition_value); |
+ |
+ // Ensure that setting the partition attribute, once it has been set, has |
+ // no effect. |
+ ExecuteJavaScript( |
+ "document.getElementById('browserplugin').partition = 'bar'"); |
+ |
+ partition_value = ExecuteScriptAndReturnString( |
+ "document.getElementById('browserplugin').partition"); |
+ EXPECT_EQ("someid", partition_value); |
+} |
+ |
+// Verify that the 'persist' attribute on the browser plugin is parsed |
+// correctly. |
+TEST_F(BrowserPluginTest, PersistAttribute) { |
+ std::string html = StringPrintf(kHTMLForPartitionedPersistedPluginObject, |
+ content::kBrowserPluginNewMimeType); |
+ LoadHTML(html.c_str()); |
+ |
+ bool persist_value = false; |
+ // Check that the value has been properly parsed. |
+ EXPECT_TRUE(ExecuteScriptAndReturnBool( |
+ "document.getElementById('browserplugin').persist", persist_value)); |
+ EXPECT_TRUE(persist_value); |
+ |
+ // Ensure that setting the value, once it is initialized, has no effect. |
+ ExecuteJavaScript( |
+ "document.getElementById('browserplugin').persist = false"); |
+ EXPECT_TRUE(ExecuteScriptAndReturnBool( |
+ "document.getElementById('browserplugin').persist", persist_value)); |
+ EXPECT_TRUE(persist_value); |
+ |
+ // Verify that missing persist attribute defaults to false. |
+ html = StringPrintf(kHTMLForPartitionedPluginObject, |
+ content::kBrowserPluginNewMimeType); |
+ LoadHTML(html.c_str()); |
+ |
+ EXPECT_TRUE(ExecuteScriptAndReturnBool( |
+ "document.getElementById('browserplugin').persist", persist_value)); |
+ EXPECT_FALSE(persist_value); |
+} |
+ |
+// Test to verify that after the first navigation, the partition and persist |
+// properties cannot be modified. |
+TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { |
+ const char kHtml[] = |
+ "<object id='browserplugin' width='640px' height='480px' type='%s'>"; |
+ std::string html = StringPrintf(kHtml, content::kBrowserPluginNewMimeType); |
+ 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* msg = |
+ browser_plugin_manager()->sink().GetUniqueMessageMatching( |
+ BrowserPluginHostMsg_NavigateOrCreateGuest::ID); |
+ ASSERT_TRUE(msg); |
+ |
+ int instance_id; |
+ long long frame_id; |
+ std::string src; |
+ BrowserPluginHostMsg_NavigateOrCreateGuest::Read( |
+ msg, |
+ &instance_id, |
+ &frame_id, |
+ &src); |
+ EXPECT_STREQ("bar", src.c_str()); |
+ } |
+ |
+ ExecuteJavaScript( |
+ "document.getElementById('browserplugin').partition = 'someid'"); |
+ partition_value = ExecuteScriptAndReturnString( |
+ "document.getElementById('browserplugin').partition"); |
+ EXPECT_STREQ("storage", partition_value.c_str()); |
+ |
+ bool persist_value = false; |
+ ExecuteJavaScript( |
+ "document.getElementById('browserplugin').persist = true"); |
+ EXPECT_TRUE(ExecuteScriptAndReturnBool( |
+ "document.getElementById('browserplugin').persist", persist_value)); |
+ EXPECT_FALSE(persist_value); |
+} |
+ |
} // namespace content |