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

Unified Diff: content/browser/browser_plugin/browser_plugin_host_browsertest.cc

Issue 23591016: BrowserPlugin/WebView - Move plugin lifetime to DOM (Chromium-side) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update BrowserPlugin tests to reflect new behaviour. Created 6 years, 8 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/browser/browser_plugin/browser_plugin_host_browsertest.cc
diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
index f3415cbc03c29f834ea3d24c4e2624c92df19719..e3978800fae64e78ea526b890d9797c5906b0938 100644
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
@@ -481,6 +481,88 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) {
test_guest()->WaitUntilHidden();
}
+namespace {
+
+bool IsAttributeNull(RenderFrameHost* rfh, const std::string& attribute) {
+ scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue(
+ rfh,
+ "document.getElementById('plugin').getAttribute('" + attribute + "');");
+ return value->GetType() == base::Value::TYPE_NULL;
+}
+
+} // namespace
+
+// Verifies that setting the src attribute prior to DOM attachment works, i.e.
+// that the BrowserPlugin is created without having a renderer.
+const char kHTMLForGuestLateAttach[] =
+ "data:text/html,<html><title>late attach</title>"
+ "<body>hello world</body></html>";
+
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PluginCreatedWithoutRenderer) {
+ const char kEmbedderURL[] = "/browser_plugin_embedder_late_attach.html";
+ StartBrowserPluginTest(
+ kEmbedderURL, kHTMLForGuestLateAttach, true, std::string());
+
+ // Attach the browser plugin to the dom. We don't pass this to
+ // StartBrowserPluginTest since we want it to execute after the src parameter
+ // is set.
+ ExecuteSyncJSFunction(shell()->web_contents()->GetMainFrame(),
+ "attachPlugin();");
+
+ // Verify attachment with src attribute intact.
+ EXPECT_FALSE(
+ IsAttributeNull(shell()->web_contents()->GetMainFrame(), "src"));
+
+ // Verify page loaded properly by checking title.
+ const base::string16 expected_title = ASCIIToUTF16("late attach");
+ EXPECT_EQ(expected_title, test_guest()->web_contents()->GetTitle());
+}
+
+// Verifies that browser-plugin state survives setting "display = none", i.e.
+// that the BrowserPlugin object is persisted.
+const char kHTMLForGuestPersisted[] =
+ "data:text/html,<html><title>persisted</title>"
+ "<body>hello world</body></html>";
+
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PluginPersists) {
+ const char kEmbedderURL[] = "/browser_plugin_embedder.html";
+ StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string());
+
+ const char kGuestTitle[] = "persisted";
+ const char kGuestTitleModified[] = "still persisted";
+
+ // Verify title is seen.
+ const base::string16 expected_title = ASCIIToUTF16(kGuestTitle);
+ {
+ content::TitleWatcher title_watcher(test_guest()->web_contents(),
+ expected_title);
+ ExecuteSyncJSFunction(
+ test_embedder()->web_contents()->GetMainFrame(),
+ base::StringPrintf("SetSrc('%s');", kHTMLForGuestPersisted));
+ base::string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ }
+
+ // Set display none, verify title not seen.
+ ExecuteSyncJSFunction(
+ shell()->web_contents()->GetMainFrame(),
+ "document.getElementById('plugin').style.display = 'none'");
+
+ ExecuteSyncJSFunction(
+ test_guest()->web_contents()->GetMainFrame(),
+ base::StringPrintf("document.title = '%s'", kGuestTitleModified));
+
+ // Clear display none.
+ ExecuteSyncJSFunction(
+ shell()->web_contents()->GetMainFrame(),
+ "document.getElementById('plugin').style.display = 'block'");
+
+ // The guest title should have survived the display:none.
+ const base::string16 expected_title_modified =
+ ASCIIToUTF16(kGuestTitleModified);
+ EXPECT_EQ(test_guest()->web_contents()->GetTitle(), expected_title_modified);
+}
+
// Verifies that installing/uninstalling touch-event handlers in the guest
// plugin correctly updates the touch-event handling state in the embedder.
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) {
« no previous file with comments | « no previous file | content/renderer/browser_plugin/browser_plugin.h » ('j') | content/renderer/render_frame_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698