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

Unified Diff: content/renderer/browser_plugin/browser_plugin_browsertest.cc

Issue 10928237: Add support for parsing a 'partition' attribute on the <browser> tag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving to UTF-8 encoded strings and added test for multibyte characters. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
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..0fe1979f3742582f54cfaefe3535a3fbaec2032f 100644
--- a/content/renderer/browser_plugin/browser_plugin_browsertest.cc
+++ b/content/renderer/browser_plugin/browser_plugin_browsertest.cc
@@ -25,6 +25,17 @@ const char kHTMLForBrowserPluginObject[] =
"<object id='browserplugin' width='640px' height='480px'"
" src='foo' type='%s'>";
+const char kHTMLForSourcelessPluginObject[] =
+ "<object id='browserplugin' width='640px' height='480px' type='%s'>";
+
+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='persist:someid'>";
Charlie Reis 2012/09/18 22:09:33 Is it also worth testing one with a partition and
nasko 2012/09/18 22:56:20 If you agree with my comment about setting partiti
+
std::string GetHTMLForBrowserPluginObject() {
return StringPrintf(kHTMLForBrowserPluginObject,
content::kBrowserPluginNewMimeType);
@@ -319,4 +330,144 @@ 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_STREQ("someid", partition_value.c_str());
+
+ html = StringPrintf(kHTMLForPartitionedPersistedPluginObject,
+ content::kBrowserPluginNewMimeType);
+ LoadHTML(html.c_str());
+ partition_value = ExecuteScriptAndReturnString(
+ "document.getElementById('browserplugin').partition");
+ EXPECT_STREQ("persist:someid", partition_value.c_str());
+
+ // Verify that once HTML has defined a source and partition, we cannot change
+ // the partition anymore.
+ ExecuteJavaScript(
+ "try {"
+ " document.getElementById('browserplugin').partition = 'foo';"
+ " document.title = 'success';"
+ "} catch (e) { document.title = e.message; }");
+ std::string title = ExecuteScriptAndReturnString("document.title");
+ EXPECT_STREQ("The object has already navigated.", title.c_str());
+
+ // Load a browser tag without 'src' defined.
+ html = StringPrintf(kHTMLForSourcelessPluginObject,
+ content::kBrowserPluginNewMimeType);
+ LoadHTML(html.c_str());
+
+ // Ensure we don't parse just "persist:" string and return exception.
+ ExecuteJavaScript(
+ "try {"
+ " document.getElementById('browserplugin').partition = 'persist:';"
+ " document.title = 'success';"
+ "} catch (e) { document.title = e.message; }");
+ title = ExecuteScriptAndReturnString("document.title");
+ EXPECT_STREQ("Invalid partition attribute.", title.c_str());
+
+ // Verify we can't set the partition attribute twice.
+ ExecuteJavaScript(
+ "document.getElementById('browserplugin').partition = 'foo'");
+ partition_value = ExecuteScriptAndReturnString(
+ "document.getElementById('browserplugin').partition");
+ EXPECT_STREQ("foo", partition_value.c_str());
+
+ ExecuteJavaScript(
+ "try {"
+ " document.getElementById('browserplugin').partition = 'bar';"
+ " document.title = 'success';"
+ "} catch (e) { document.title = e.message; }");
+ title = ExecuteScriptAndReturnString("document.title");
+ EXPECT_STREQ("The partition attribute has already been set.", title.c_str());
+}
+
+// Test to verify that after the first navigation, the partition attribute
+// cannot be modified.
+TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) {
+ std::string html = StringPrintf(kHTMLForSourcelessPluginObject,
+ 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());
+ }
+
+ // Setting the partition should throw an exception and the value should not
+ // change.
+ 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.", title.c_str());
+
+ partition_value = ExecuteScriptAndReturnString(
+ "document.getElementById('browserplugin').partition");
+ EXPECT_STREQ("storage", partition_value.c_str());
+}
+
+// Test to ensure that the partition attribute can handle non-ASCII strings.
+// The test uses cyrillic and chinese strings.
+TEST_F(BrowserPluginTest, PartitionAttributeEncoding) {
+ std::string html = StringPrintf(kHTMLForSourcelessPluginObject,
+ content::kBrowserPluginNewMimeType);
+ LoadHTML(html.c_str());
+
+ // The cyrillic test string.
+ std::string cyrillic("\u0445\u0440\u043E\u043C");
+ std::string js("document.getElementById('browserplugin').partition = '");
+ js.append(cyrillic).append("'");
+
+ ExecuteJavaScript(js.c_str());
+ std::string partition_value = ExecuteScriptAndReturnString(
+ "document.getElementById('browserplugin').partition");
+ EXPECT_STREQ(cyrillic.c_str(), partition_value.c_str());
+
+ LoadHTML(html.c_str());
+
+ // A random string of chinese characters, not meant to be meaningful.
+ std::string chinese("\u94EC\u927B\U00029A72\U00009C61\U00021C56");
+ std::string persist = std::string("persist:").append(chinese);
+ js = "document.getElementById('browserplugin').partition = '";
+ js.append(persist).append("'");
+
+ ExecuteJavaScript(js.c_str());
+ partition_value = ExecuteScriptAndReturnString(
+ "document.getElementById('browserplugin').partition");
+ EXPECT_STREQ(persist.c_str(), partition_value.c_str());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698