Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/singleton.h" | 6 #include "base/memory/singleton.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 10 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 12 #include "content/browser/browser_plugin/test_browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/test_browser_plugin_embedder.h" |
| 13 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" | 13 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/render_view_host_observer.h" | 19 #include "content/public/browser/render_view_host_observer.h" |
| 20 #include "content/public/browser/render_widget_host_view.h" | |
| 20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
| 22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 23 #include "content/shell/shell.h" | 24 #include "content/shell/shell.h" |
| 24 #include "content/test/content_browser_test_utils.h" | 25 #include "content/test/content_browser_test_utils.h" |
| 25 #include "content/test/content_browser_test.h" | 26 #include "content/test/content_browser_test.h" |
| 26 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 27 #include "net/test/test_server.h" | 28 #include "net/test/test_server.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 29 | 30 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 54 "function UninstallTouchHandler() { " | 55 "function UninstallTouchHandler() { " |
| 55 " document.getElementById(\"touch\").removeEventListener(\"touchstart\", " | 56 " document.getElementById(\"touch\").removeEventListener(\"touchstart\", " |
| 56 " handler);" | 57 " handler);" |
| 57 "}" | 58 "}" |
| 58 "</script></html>"; | 59 "</script></html>"; |
| 59 const char* kHTMLForGuestWithTitle = | 60 const char* kHTMLForGuestWithTitle = |
| 60 "data:text/html," | 61 "data:text/html," |
| 61 "<html><head><title>%s</title></head>" | 62 "<html><head><title>%s</title></head>" |
| 62 "<body>hello world</body>" | 63 "<body>hello world</body>" |
| 63 "</html>"; | 64 "</html>"; |
| 65 const char kHTMLForGuestAcceptDrag[] = | |
| 66 "data:text/html,<html><body>" | |
| 67 "<script>" | |
| 68 "function dropped() {" | |
| 69 " document.title = \"DROPPED\";" | |
| 70 "}" | |
| 71 "</script>" | |
| 72 "<textarea id=\"text\" style=\"width:100%; height: 100%\"" | |
| 73 " ondrop=\"dropped();\">" | |
| 74 "</textarea>" | |
| 75 "</body></html>"; | |
| 64 | 76 |
| 65 std::string GetHTMLForGuestWithTitle(const std::string& title) { | 77 std::string GetHTMLForGuestWithTitle(const std::string& title) { |
| 66 return StringPrintf(kHTMLForGuestWithTitle, title.c_str()); | 78 return StringPrintf(kHTMLForGuestWithTitle, title.c_str()); |
| 67 } | 79 } |
| 68 | 80 |
| 69 } // namespace | 81 } // namespace |
| 70 | 82 |
| 71 namespace content { | 83 namespace content { |
| 72 | 84 |
| 73 // Test factory for creating test instances of BrowserPluginEmbedder and | 85 // Test factory for creating test instances of BrowserPluginEmbedder and |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 std::string result; | 714 std::string result; |
| 703 EXPECT_TRUE(v->GetAsString(&result)); | 715 EXPECT_TRUE(v->GetAsString(&result)); |
| 704 EXPECT_EQ(redirect_url.spec().c_str(), result); | 716 EXPECT_EQ(redirect_url.spec().c_str(), result); |
| 705 | 717 |
| 706 v = rvh->ExecuteJavascriptAndGetValue( | 718 v = rvh->ExecuteJavascriptAndGetValue( |
| 707 string16(), ASCIIToUTF16("redirectNewUrl")); | 719 string16(), ASCIIToUTF16("redirectNewUrl")); |
| 708 EXPECT_TRUE(v->GetAsString(&result)); | 720 EXPECT_TRUE(v->GetAsString(&result)); |
| 709 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); | 721 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); |
| 710 } | 722 } |
| 711 | 723 |
| 724 // Tests that a drag-n-drop over the browser plugin in the embedder happens | |
| 725 // correctly. | |
| 726 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptDragEvents) { | |
| 727 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 []
| |
| 728 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestAcceptDrag, true, ""); | |
| 729 | |
| 730 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 731 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 732 | |
| 733 // Get a location in the embedder outside of the plugin. | |
| 734 base::ListValue *start, *end; | |
| 735 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
| |
| 736 ASCIIToUTF16("dragLocation()")); | |
| 737 ASSERT_TRUE(v->GetAsList(&start) && start->GetSize() == 2); | |
| 738 double start_x, start_y; | |
| 739 ASSERT_TRUE(start->GetDouble(0, &start_x) && start->GetDouble(1, &start_y)); | |
| 740 | |
| 741 // Get a location in the embedder that falls inside the plugin. | |
| 742 v = rvh->ExecuteJavascriptAndGetValue(string16(), | |
| 743 ASCIIToUTF16("dropLocation()")); | |
| 744 ASSERT_TRUE(v->GetAsList(&end) && start->GetSize() == 2); | |
| 745 double end_x, end_y; | |
| 746 ASSERT_TRUE(end->GetDouble(0, &end_x) && end->GetDouble(1, &end_y)); | |
| 747 | |
| 748 WebDropData drop_data; | |
| 749 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
| |
| 750 drop_data.url = file_url; | |
| 751 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.
| |
| 752 | |
| 753 // Pretend that the URL is being dragged over the embedder. Start the drag | |
| 754 // from outside the plugin, then move the drag inside the plugin and drop. | |
| 755 // This should trigger appropriate messages from the embedder to the guest, | |
| 756 // and end with a drop on the guest. The guest changes title when a drop | |
| 757 // happens. | |
| 758 const string16 expected_title = ASCIIToUTF16("DROPPED"); | |
| 759 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 760 expected_title); | |
| 761 | |
| 762 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), | |
| 763 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0); | |
| 764 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), | |
| 765 WebKit::WebDragOperationEvery, 0); | |
| 766 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); | |
| 767 | |
| 768 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 769 EXPECT_EQ(expected_title, actual_title); | |
| 770 } | |
| 771 | |
| 712 } // namespace content | 772 } // namespace content |
| OLD | NEW |