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 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)
| |
725 const char* kEmbedderURL = "files/browser_plugin_dragging.html"; | |
726 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestAcceptDrag, true, ""); | |
727 | |
728 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
729 test_embedder()->web_contents()->GetRenderViewHost()); | |
730 | |
731 base::ListValue *start, *end; | |
732 base::Value* v = rvh->ExecuteJavascriptAndGetValue(string16(), | |
733 ASCIIToUTF16("dragLocation()")); | |
734 ASSERT_TRUE(v->GetAsList(&start) && start->GetSize() == 2); | |
735 double start_x, start_y; | |
736 ASSERT_TRUE(start->GetDouble(0, &start_x) && start->GetDouble(1, &start_y)); | |
737 | |
738 v = rvh->ExecuteJavascriptAndGetValue(string16(), | |
739 ASCIIToUTF16("dropLocation()")); | |
740 ASSERT_TRUE(v->GetAsList(&end) && start->GetSize() == 2); | |
741 double end_x, end_y; | |
742 ASSERT_TRUE(end->GetDouble(0, &end_x) && end->GetDouble(1, &end_y)); | |
743 | |
744 WebDropData drop_data; | |
745 GURL file_url = GURL("https://www.domain.com/index.html"); | |
746 drop_data.url = file_url; | |
747 drop_data.html_base_url = file_url; | |
748 | |
749 const string16 expected_title = ASCIIToUTF16("DROPPED"); | |
750 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
751 expected_title); | |
752 | |
753 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), | |
754 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0); | |
755 rvh->DragSourceMovedTo(start_x, start_y, start_x, start_y); | |
756 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), | |
757 WebKit::WebDragOperationEvery, 0); | |
758 rvh->DragSourceMovedTo(end_x, end_y, end_x, end_y); | |
759 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); | |
760 rvh->DragSourceEndedAt(end_x, end_y, end_x, end_y, | |
761 WebKit::WebDragOperationEvery); | |
762 rvh->DragSourceSystemDragEnded(); | |
763 | |
764 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
765 EXPECT_EQ(expected_title, actual_title); | |
766 } | |
767 | |
712 } // namespace content | 768 } // namespace content |
OLD | NEW |