| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 12 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 14 #include "content/browser/browser_plugin/test_browser_plugin_embedder.h" | 14 #include "content/browser/browser_plugin/test_browser_plugin_embedder.h" |
| 15 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" | 15 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" |
| 16 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" | 16 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" |
| 17 #include "content/browser/browser_plugin/test_browser_plugin_guest_manager.h" | 17 #include "content/browser/browser_plugin/test_browser_plugin_guest_manager.h" |
| 18 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 20 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
| 21 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 24 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
| 25 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
| 26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/common/drop_data.h" | 28 #include "content/public/common/drop_data.h" |
| 28 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 30 #include "content/public/test/browser_test_utils.h" |
| 30 #include "content/public/test/test_utils.h" | 31 #include "content/public/test/test_utils.h" |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 804 |
| 804 // Attempt a navigation to chrome-guest://abc123, which is a valid URL. But it | 805 // Attempt a navigation to chrome-guest://abc123, which is a valid URL. But it |
| 805 // should be blocked because the scheme isn't web-safe or a pseudo-scheme. | 806 // should be blocked because the scheme isn't web-safe or a pseudo-scheme. |
| 806 ExecuteSyncJSFunction( | 807 ExecuteSyncJSFunction( |
| 807 test_embedder()->web_contents()->GetRenderViewHost(), | 808 test_embedder()->web_contents()->GetRenderViewHost(), |
| 808 base::StringPrintf("SetSrc('%s://abc123');", kGuestScheme)); | 809 base::StringPrintf("SetSrc('%s://abc123');", kGuestScheme)); |
| 809 EXPECT_TRUE(delegate->load_aborted()); | 810 EXPECT_TRUE(delegate->load_aborted()); |
| 810 EXPECT_TRUE(delegate->load_aborted_url().is_valid()); | 811 EXPECT_TRUE(delegate->load_aborted_url().is_valid()); |
| 811 } | 812 } |
| 812 | 813 |
| 813 | |
| 814 // Tests involving the threaded compositor. | 814 // Tests involving the threaded compositor. |
| 815 class BrowserPluginThreadedCompositorTest : public BrowserPluginHostTest { | 815 class BrowserPluginThreadedCompositorTest : public BrowserPluginHostTest { |
| 816 public: | 816 public: |
| 817 BrowserPluginThreadedCompositorTest() {} | 817 BrowserPluginThreadedCompositorTest() {} |
| 818 virtual ~BrowserPluginThreadedCompositorTest() {} | 818 virtual ~BrowserPluginThreadedCompositorTest() {} |
| 819 | 819 |
| 820 protected: | 820 protected: |
| 821 virtual void SetUpCommandLine(CommandLine* cmd) OVERRIDE { | 821 virtual void SetUpCommandLine(CommandLine* cmd) OVERRIDE { |
| 822 BrowserPluginHostTest::SetUpCommandLine(cmd); | 822 BrowserPluginHostTest::SetUpCommandLine(cmd); |
| 823 cmd->AppendSwitch(switches::kEnableThreadedCompositing); | 823 cmd->AppendSwitch(switches::kEnableThreadedCompositing); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 while (!result) { | 918 while (!result) { |
| 919 base::RunLoop loop; | 919 base::RunLoop loop; |
| 920 guest_widget_host->CopyFromBackingStore(gfx::Rect(), | 920 guest_widget_host->CopyFromBackingStore(gfx::Rect(), |
| 921 guest_widget_host->GetView()->GetViewBounds().size(), | 921 guest_widget_host->GetView()->GetViewBounds().size(), |
| 922 base::Bind(&CompareSkBitmapAndRun, loop.QuitClosure(), expected_bitmap, | 922 base::Bind(&CompareSkBitmapAndRun, loop.QuitClosure(), expected_bitmap, |
| 923 &result)); | 923 &result)); |
| 924 loop.Run(); | 924 loop.Run(); |
| 925 } | 925 } |
| 926 } | 926 } |
| 927 | 927 |
| 928 // Tests input method. |
| 929 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, InputMethod) { |
| 930 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
| 931 const char kGuestHTML[] = "data:text/html," |
| 932 "<html><body><input id=\"input1\">" |
| 933 "<input id=\"input2\"></body>" |
| 934 "<script>" |
| 935 "var i = document.getElementById(\"input1\");" |
| 936 "i.oninput = function() {" |
| 937 " document.title = i.value;" |
| 938 "}" |
| 939 "</script>" |
| 940 "</html>"; |
| 941 StartBrowserPluginTest(kEmbedderURL, kGuestHTML, true, |
| 942 "document.getElementById(\"plugin\").focus();"); |
| 943 |
| 944 RenderViewHostImpl* embedder_rvh = static_cast<RenderViewHostImpl*>( |
| 945 test_embedder()->web_contents()->GetRenderViewHost()); |
| 946 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 947 test_guest()->web_contents()->GetRenderViewHost()); |
| 948 |
| 949 std::vector<blink::WebCompositionUnderline> underlines; |
| 950 |
| 951 // An input field in browser plugin guest gets focus and given some user |
| 952 // input via IME. |
| 953 { |
| 954 ExecuteSyncJSFunction(guest_rvh, |
| 955 "document.getElementById('input1').focus();"); |
| 956 string16 expected_title = UTF8ToUTF16("InputTest123"); |
| 957 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 958 expected_title); |
| 959 embedder_rvh->Send( |
| 960 new ViewMsg_ImeSetComposition( |
| 961 test_embedder()->web_contents()->GetRoutingID(), |
| 962 expected_title, |
| 963 underlines, |
| 964 12, 12)); |
| 965 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 966 EXPECT_EQ(expected_title, actual_title); |
| 967 } |
| 968 // A composition is committed via IME. |
| 969 { |
| 970 string16 expected_title = UTF8ToUTF16("InputTest456"); |
| 971 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 972 expected_title); |
| 973 embedder_rvh->Send( |
| 974 new ViewMsg_ImeConfirmComposition( |
| 975 test_embedder()->web_contents()->GetRoutingID(), |
| 976 expected_title, |
| 977 gfx::Range(), |
| 978 true)); |
| 979 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 980 EXPECT_EQ(expected_title, actual_title); |
| 981 } |
| 982 // IME composition starts, but focus moves out, then the composition will |
| 983 // be committed and get cancel msg. |
| 984 { |
| 985 ExecuteSyncJSFunction(guest_rvh, |
| 986 "document.getElementById('input1').value = '';"); |
| 987 string16 composition = UTF8ToUTF16("InputTest789"); |
| 988 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 989 composition); |
| 990 embedder_rvh->Send( |
| 991 new ViewMsg_ImeSetComposition( |
| 992 test_embedder()->web_contents()->GetRoutingID(), |
| 993 composition, |
| 994 underlines, |
| 995 12, 12)); |
| 996 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 997 EXPECT_EQ(composition, actual_title); |
| 998 // Moving focus causes IME cancel, and the composition will be committed |
| 999 // in input1, not in input2. |
| 1000 ExecuteSyncJSFunction(guest_rvh, |
| 1001 "document.getElementById('input2').focus();"); |
| 1002 test_guest()->WaitForImeCancel(); |
| 1003 scoped_ptr<base::Value> value = |
| 1004 content::ExecuteScriptAndGetValue( |
| 1005 guest_rvh, "document.getElementById('input1').value"); |
| 1006 std::string result; |
| 1007 ASSERT_TRUE(value->GetAsString(&result)); |
| 1008 EXPECT_EQ(UTF16ToUTF8(composition), result); |
| 1009 } |
| 1010 // Tests ExtendSelectionAndDelete message works in browser_plugin. |
| 1011 { |
| 1012 // Set 'InputTestABC' in input1 and put caret at 6 (after 'T'). |
| 1013 ExecuteSyncJSFunction(guest_rvh, |
| 1014 "var i = document.getElementById('input1');" |
| 1015 "i.focus();" |
| 1016 "i.value = 'InputTestABC';" |
| 1017 "i.selectionStart=6;" |
| 1018 "i.selectionEnd=6;"); |
| 1019 string16 expected_value = UTF8ToUTF16("InputABC"); |
| 1020 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 1021 expected_value); |
| 1022 // Delete 'Test' in 'InputTestABC', as the caret is after 'T': |
| 1023 // delete before 1 character ('T') and after 3 characters ('est'). |
| 1024 embedder_rvh->Send( |
| 1025 new ViewMsg_ExtendSelectionAndDelete( |
| 1026 test_embedder()->web_contents()->GetRoutingID(), |
| 1027 1, 3)); |
| 1028 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 1029 EXPECT_EQ(expected_value, actual_title); |
| 1030 scoped_ptr<base::Value> value = |
| 1031 content::ExecuteScriptAndGetValue( |
| 1032 guest_rvh, "document.getElementById('input1').value"); |
| 1033 std::string actual_value; |
| 1034 ASSERT_TRUE(value->GetAsString(&actual_value)); |
| 1035 EXPECT_EQ(UTF16ToUTF8(expected_value), actual_value); |
| 1036 } |
| 1037 } |
| 1038 |
| 928 } // namespace content | 1039 } // namespace content |
| OLD | NEW |