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

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

Issue 11088043: browser-plugin: Allow accepting drag-n-drop events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 8 years, 2 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 703a4f9e894ce006e34f8cb50df369202d02aa0e..a0eb83e3d68b8d138c7ccd0a62a91a308371fd6e 100644
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
@@ -17,6 +17,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host_observer.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
@@ -61,6 +62,17 @@ const char* kHTMLForGuestWithTitle =
"<html><head><title>%s</title></head>"
"<body>hello world</body>"
"</html>";
+const char kHTMLForGuestAcceptDrag[] =
+ "data:text/html,<html><body>"
+ "<script>"
+ "function dropped() {"
+ " document.title = \"DROPPED\";"
+ "}"
+ "</script>"
+ "<textarea id=\"text\" style=\"width:100%; height: 100%\""
+ " ondrop=\"dropped();\">"
+ "</textarea>"
+ "</body></html>";
std::string GetHTMLForGuestWithTitle(const std::string& title) {
return StringPrintf(kHTMLForGuestWithTitle, title.c_str());
@@ -709,4 +721,48 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) {
EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result);
}
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptDragEvents) {
Fady Samuel 2012/10/11 17:57:09 What's happening here is not obvious to me. Please
sadrul 2012/10/11 18:31:18 Added comments (and simplified the test a bit too)
+ const char* kEmbedderURL = "files/browser_plugin_dragging.html";
+ StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestAcceptDrag, true, "");
+
+ RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
+ test_embedder()->web_contents()->GetRenderViewHost());
+
+ base::ListValue *start, *end;
+ base::Value* v = rvh->ExecuteJavascriptAndGetValue(string16(),
+ ASCIIToUTF16("dragLocation()"));
+ ASSERT_TRUE(v->GetAsList(&start) && start->GetSize() == 2);
+ double start_x, start_y;
+ ASSERT_TRUE(start->GetDouble(0, &start_x) && start->GetDouble(1, &start_y));
+
+ v = rvh->ExecuteJavascriptAndGetValue(string16(),
+ ASCIIToUTF16("dropLocation()"));
+ ASSERT_TRUE(v->GetAsList(&end) && start->GetSize() == 2);
+ double end_x, end_y;
+ ASSERT_TRUE(end->GetDouble(0, &end_x) && end->GetDouble(1, &end_y));
+
+ WebDropData drop_data;
+ GURL file_url = GURL("https://www.domain.com/index.html");
+ drop_data.url = file_url;
+ drop_data.html_base_url = file_url;
+
+ const string16 expected_title = ASCIIToUTF16("DROPPED");
+ content::TitleWatcher title_watcher(test_guest()->web_contents(),
+ expected_title);
+
+ rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y),
+ gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0);
+ rvh->DragSourceMovedTo(start_x, start_y, start_x, start_y);
+ rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y),
+ WebKit::WebDragOperationEvery, 0);
+ rvh->DragSourceMovedTo(end_x, end_y, end_x, end_y);
+ rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0);
+ rvh->DragSourceEndedAt(end_x, end_y, end_x, end_y,
+ WebKit::WebDragOperationEvery);
+ rvh->DragSourceSystemDragEnded();
+
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698