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

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

Issue 299753011: Move allocate instance id to chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: HasPermission function moved Created 6 years, 6 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 b7eb6164361b892aa77fe4de8dcc7f1df8a47dca..7eee4b9cb4b95eba6b0de27141fe302a164e7f4e 100644
--- a/content/renderer/browser_plugin/browser_plugin_browsertest.cc
+++ b/content/renderer/browser_plugin/browser_plugin_browsertest.cc
@@ -39,18 +39,6 @@ const char kHTMLForBrowserPluginWithAllAttributes[] =
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 kHTMLForInvalidPartitionedPluginObject[] =
- "<object id='browserplugin' width='640px' height='480px'"
- " type='%s' partition='persist:'>";
-
-const char kHTMLForPartitionedPersistedPluginObject[] =
- "<object id='browserplugin' width='640px' height='480px'"
- " src='foo' type='%s' partition='persist:someid'>";
-
std::string GetHTMLForBrowserPluginObject() {
return base::StringPrintf(kHTMLForBrowserPluginObject,
kBrowserPluginMimeType);
@@ -167,6 +155,12 @@ MockBrowserPlugin* BrowserPluginTest::GetCurrentPlugin() {
MockBrowserPlugin* BrowserPluginTest::GetCurrentPluginWithAttachParams(
BrowserPluginHostMsg_Attach_Params* params) {
+ MockBrowserPlugin* browser_plugin = static_cast<MockBrowserPluginManager*>(
+ browser_plugin_manager())->last_plugin();
+ if (!browser_plugin)
+ return NULL;
+ browser_plugin_manager()->AllocateInstanceID(browser_plugin);
+
int instance_id = 0;
const IPC::Message* msg =
browser_plugin_manager()->sink().GetUniqueMessageMatching(
@@ -179,15 +173,11 @@ MockBrowserPlugin* BrowserPluginTest::GetCurrentPluginWithAttachParams(
return NULL;
if (!IPC::ParamTraits<BrowserPluginHostMsg_Attach_Params>::Read(
- msg, &iter, params))
+ msg, &iter, params)) {
return NULL;
+ }
- MockBrowserPlugin* browser_plugin = static_cast<MockBrowserPlugin*>(
- browser_plugin_manager()->GetBrowserPlugin(instance_id));
-
- BrowserPluginMsg_Attach_ACK_Params attach_ack_params;
- browser_plugin->OnAttachACK(instance_id, attach_ack_params);
-
+ browser_plugin->OnAttachACK(instance_id);
return browser_plugin;
}
@@ -228,56 +218,6 @@ TEST_F(BrowserPluginTest, ParseAllAttributes) {
int minWidth = ExecuteScriptAndReturnInt(
"document.getElementById('browserplugin').minwidth");
EXPECT_EQ(320, minWidth);
- std::string name = ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').name");
- EXPECT_STREQ("Jim", name.c_str());
- std::string partition = ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').partition");
- EXPECT_STREQ("someid", partition.c_str());
- std::string src = ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').src");
- EXPECT_STREQ("foo", src.c_str());
-}
-
-// Verify that the src attribute on the browser plugin works as expected.
-TEST_F(BrowserPluginTest, SrcAttribute) {
- LoadHTML(GetHTMLForBrowserPluginObject().c_str());
- // Verify that we're reporting the correct URL to navigate to based on the
- // src attribute.
- {
- BrowserPluginHostMsg_Attach_Params params;
- MockBrowserPlugin* browser_plugin =
- GetCurrentPluginWithAttachParams(&params);
- ASSERT_TRUE(browser_plugin);
- EXPECT_EQ("foo", params.src);
- }
-
- browser_plugin_manager()->sink().ClearMessages();
- // Navigate to bar and observe the associated
- // BrowserPluginHostMsg_NavigateGuest message.
- // Verify that the src attribute is updated as well.
- ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'");
- {
- // Verify that we do not get a Attach on subsequent navigations.
- const IPC::Message* create_msg =
- browser_plugin_manager()->sink().GetUniqueMessageMatching(
- BrowserPluginHostMsg_Attach::ID);
- ASSERT_FALSE(create_msg);
-
- const IPC::Message* msg =
- browser_plugin_manager()->sink().GetUniqueMessageMatching(
- BrowserPluginHostMsg_NavigateGuest::ID);
- ASSERT_TRUE(msg);
-
- BrowserPluginHostMsg_NavigateGuest::Param params;
- BrowserPluginHostMsg_NavigateGuest::Read(msg, &params);
- std::string src = params.b;
- EXPECT_EQ("bar", src);
- std::string src_value =
- ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').src");
- EXPECT_EQ("bar", src_value);
- }
}
TEST_F(BrowserPluginTest, ResizeFlowControl) {
@@ -358,6 +298,9 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
TEST_F(BrowserPluginTest, RemovePlugin) {
LoadHTML(GetHTMLForBrowserPluginObject().c_str());
+ MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
+ ASSERT_TRUE(browser_plugin);
+
EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
BrowserPluginHostMsg_PluginDestroyed::ID));
ExecuteJavaScript("x = document.getElementById('browserplugin'); "
@@ -384,142 +327,6 @@ TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) {
// Verify that the 'partition' attribute on the browser plugin is parsed
// correctly.
-TEST_F(BrowserPluginTest, PartitionAttribute) {
- std::string html = base::StringPrintf(kHTMLForPartitionedPluginObject,
- kBrowserPluginMimeType);
- LoadHTML(html.c_str());
- std::string partition_value = ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').partition");
- EXPECT_STREQ("someid", partition_value.c_str());
-
- html = base::StringPrintf(kHTMLForPartitionedPersistedPluginObject,
- kBrowserPluginMimeType);
- 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, so its partition cannot be changed.",
- title.c_str());
-
- // Load a browser tag without 'src' defined.
- html = base::StringPrintf(kHTMLForSourcelessPluginObject,
- kBrowserPluginMimeType);
- 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());
-}
-
-// This test verifies that BrowserPlugin enters an error state when the
-// partition attribute is invalid.
-TEST_F(BrowserPluginTest, InvalidPartition) {
- std::string html = base::StringPrintf(kHTMLForInvalidPartitionedPluginObject,
- kBrowserPluginMimeType);
- LoadHTML(html.c_str());
- // Attempt to navigate with an invalid partition.
- {
- ExecuteJavaScript(
- "try {"
- " document.getElementById('browserplugin').src = 'bar';"
- " document.title = 'success';"
- "} catch (e) { document.title = e.message; }");
- std::string title = ExecuteScriptAndReturnString("document.title");
- EXPECT_STREQ("Invalid partition attribute.", title.c_str());
- // Verify that the 'src' attribute has not been updated.
- EXPECT_EQ("", ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').src"));
- }
-
- // Verify that the BrowserPlugin accepts changes to its src attribue after
- // setting the partition to a valid value.
- ExecuteJavaScript(
- "document.getElementById('browserplugin').partition = 'persist:foo'");
- ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'");
- EXPECT_EQ("bar", ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').src"));
- ProcessPendingMessages();
- // Verify that the BrowserPlugin does not 'deadlock': it can recover from
- // the partition ID error state.
- {
- ExecuteJavaScript(
- "try {"
- " document.getElementById('browserplugin').partition = 'persist:1337';"
- " 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());
- ExecuteJavaScript("document.getElementById('browserplugin').src = '42'");
- EXPECT_EQ("42", ExecuteScriptAndReturnString(
- "document.getElementById('browserplugin').src"));
- }
-}
-
-// Test to verify that after the first navigation, the partition attribute
-// cannot be modified.
-TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) {
- std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
- 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'");
- ProcessPendingMessages();
- {
- BrowserPluginHostMsg_Attach_Params params;
- MockBrowserPlugin* browser_plugin =
- GetCurrentPluginWithAttachParams(&params);
- ASSERT_TRUE(browser_plugin);
-
- EXPECT_STREQ("storage", params.storage_partition_id.c_str());
- EXPECT_FALSE(params.persist_storage);
- EXPECT_STREQ("bar", params.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, 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, AutoSizeAttributes) {
std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
kBrowserPluginMimeType);
@@ -543,8 +350,7 @@ TEST_F(BrowserPluginTest, AutoSizeAttributes) {
ProcessPendingMessages();
BrowserPluginHostMsg_Attach_Params params;
- MockBrowserPlugin* browser_plugin =
- GetCurrentPluginWithAttachParams(&params);
+ MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(&params);
ASSERT_TRUE(browser_plugin);
EXPECT_TRUE(params.auto_size_params.enable);
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin_bindings.cc ('k') | content/renderer/browser_plugin/browser_plugin_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698