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..ef10d055d119e0ea4f4a34d34920414b31abe35d 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,52 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { |
EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); |
} |
+// Tests that a drag-n-drop over the browser plugin in the embedder happens |
+// correctly. |
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptDragEvents) { |
+ const char* kEmbedderURL = "files/browser_plugin_dragging.html"; |
dcheng
2012/10/11 20:11:51
Nit: const char[] is preferred to const char* cons
sadrul
2012/10/11 20:41:21
Indeed. I have gone ahead and fixed all to use []
|
+ StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestAcceptDrag, true, ""); |
+ |
+ RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
+ test_embedder()->web_contents()->GetRenderViewHost()); |
+ |
+ // Get a location in the embedder outside of the plugin. |
+ base::ListValue *start, *end; |
+ base::Value* v = rvh->ExecuteJavascriptAndGetValue(string16(), |
dcheng
2012/10/11 20:11:51
Don't we need to delete the return value? Otherwis
sadrul
2012/10/11 20:41:21
You are correct. This value is indeed leaking. I h
|
+ 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)); |
+ |
+ // Get a location in the embedder that falls inside the plugin. |
+ 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"); |
dcheng
2012/10/11 20:11:51
Any particular reason this is file_url instead of
sadrul
2012/10/11 20:41:21
copy pasta :) Fixed
|
+ drop_data.url = file_url; |
+ drop_data.html_base_url = file_url; |
dcheng
2012/10/11 20:11:51
No need to set html_base_url if there's no HTML as
sadrul
2012/10/11 20:41:21
Fixed.
|
+ |
+ // Pretend that the URL is being dragged over the embedder. Start the drag |
+ // from outside the plugin, then move the drag inside the plugin and drop. |
+ // This should trigger appropriate messages from the embedder to the guest, |
+ // and end with a drop on the guest. The guest changes title when a drop |
+ // happens. |
+ 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->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), |
+ WebKit::WebDragOperationEvery, 0); |
+ rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); |
+ |
+ string16 actual_title = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(expected_title, actual_title); |
+} |
+ |
} // namespace content |