| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "content/shell/browser/shell.h" | 32 #include "content/shell/browser/shell.h" |
| 33 #include "content/test/content_browser_test.h" | 33 #include "content/test/content_browser_test.h" |
| 34 #include "content/test/content_browser_test_utils.h" | 34 #include "content/test/content_browser_test_utils.h" |
| 35 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
| 36 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 37 #include "net/test/embedded_test_server/http_request.h" | 37 #include "net/test/embedded_test_server/http_request.h" |
| 38 #include "net/test/embedded_test_server/http_response.h" | 38 #include "net/test/embedded_test_server/http_response.h" |
| 39 #include "net/test/spawned_test_server/spawned_test_server.h" | 39 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 40 #include "third_party/WebKit/public/web/WebInputEvent.h" | 40 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 41 | 41 |
| 42 using base::ASCIIToUTF16; |
| 42 using blink::WebInputEvent; | 43 using blink::WebInputEvent; |
| 43 using blink::WebMouseEvent; | 44 using blink::WebMouseEvent; |
| 44 using content::BrowserPluginEmbedder; | 45 using content::BrowserPluginEmbedder; |
| 45 using content::BrowserPluginGuest; | 46 using content::BrowserPluginGuest; |
| 46 using content::BrowserPluginHostFactory; | 47 using content::BrowserPluginHostFactory; |
| 47 using content::WebContentsImpl; | 48 using content::WebContentsImpl; |
| 48 | 49 |
| 49 const char kHTMLForGuest[] = | 50 const char kHTMLForGuest[] = |
| 50 "data:text/html,<html><body>hello world</body></html>"; | 51 "data:text/html,<html><body>hello world</body></html>"; |
| 51 | 52 |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 947 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 947 test_guest()->web_contents()->GetRenderViewHost()); | 948 test_guest()->web_contents()->GetRenderViewHost()); |
| 948 | 949 |
| 949 std::vector<blink::WebCompositionUnderline> underlines; | 950 std::vector<blink::WebCompositionUnderline> underlines; |
| 950 | 951 |
| 951 // An input field in browser plugin guest gets focus and given some user | 952 // An input field in browser plugin guest gets focus and given some user |
| 952 // input via IME. | 953 // input via IME. |
| 953 { | 954 { |
| 954 ExecuteSyncJSFunction(guest_rvh, | 955 ExecuteSyncJSFunction(guest_rvh, |
| 955 "document.getElementById('input1').focus();"); | 956 "document.getElementById('input1').focus();"); |
| 956 base::string16 expected_title = UTF8ToUTF16("InputTest123"); | 957 base::string16 expected_title = base::UTF8ToUTF16("InputTest123"); |
| 957 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 958 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 958 expected_title); | 959 expected_title); |
| 959 embedder_rvh->Send( | 960 embedder_rvh->Send( |
| 960 new ViewMsg_ImeSetComposition( | 961 new ViewMsg_ImeSetComposition( |
| 961 test_embedder()->web_contents()->GetRoutingID(), | 962 test_embedder()->web_contents()->GetRoutingID(), |
| 962 expected_title, | 963 expected_title, |
| 963 underlines, | 964 underlines, |
| 964 12, 12)); | 965 12, 12)); |
| 965 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 966 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 966 EXPECT_EQ(expected_title, actual_title); | 967 EXPECT_EQ(expected_title, actual_title); |
| 967 } | 968 } |
| 968 // A composition is committed via IME. | 969 // A composition is committed via IME. |
| 969 { | 970 { |
| 970 base::string16 expected_title = UTF8ToUTF16("InputTest456"); | 971 base::string16 expected_title = base::UTF8ToUTF16("InputTest456"); |
| 971 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 972 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 972 expected_title); | 973 expected_title); |
| 973 embedder_rvh->Send( | 974 embedder_rvh->Send( |
| 974 new ViewMsg_ImeConfirmComposition( | 975 new ViewMsg_ImeConfirmComposition( |
| 975 test_embedder()->web_contents()->GetRoutingID(), | 976 test_embedder()->web_contents()->GetRoutingID(), |
| 976 expected_title, | 977 expected_title, |
| 977 gfx::Range(), | 978 gfx::Range(), |
| 978 true)); | 979 true)); |
| 979 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 980 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 980 EXPECT_EQ(expected_title, actual_title); | 981 EXPECT_EQ(expected_title, actual_title); |
| 981 } | 982 } |
| 982 // IME composition starts, but focus moves out, then the composition will | 983 // IME composition starts, but focus moves out, then the composition will |
| 983 // be committed and get cancel msg. | 984 // be committed and get cancel msg. |
| 984 { | 985 { |
| 985 ExecuteSyncJSFunction(guest_rvh, | 986 ExecuteSyncJSFunction(guest_rvh, |
| 986 "document.getElementById('input1').value = '';"); | 987 "document.getElementById('input1').value = '';"); |
| 987 base::string16 composition = UTF8ToUTF16("InputTest789"); | 988 base::string16 composition = base::UTF8ToUTF16("InputTest789"); |
| 988 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 989 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 989 composition); | 990 composition); |
| 990 embedder_rvh->Send( | 991 embedder_rvh->Send( |
| 991 new ViewMsg_ImeSetComposition( | 992 new ViewMsg_ImeSetComposition( |
| 992 test_embedder()->web_contents()->GetRoutingID(), | 993 test_embedder()->web_contents()->GetRoutingID(), |
| 993 composition, | 994 composition, |
| 994 underlines, | 995 underlines, |
| 995 12, 12)); | 996 12, 12)); |
| 996 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 997 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 997 EXPECT_EQ(composition, actual_title); | 998 EXPECT_EQ(composition, actual_title); |
| 998 // Moving focus causes IME cancel, and the composition will be committed | 999 // Moving focus causes IME cancel, and the composition will be committed |
| 999 // in input1, not in input2. | 1000 // in input1, not in input2. |
| 1000 ExecuteSyncJSFunction(guest_rvh, | 1001 ExecuteSyncJSFunction(guest_rvh, |
| 1001 "document.getElementById('input2').focus();"); | 1002 "document.getElementById('input2').focus();"); |
| 1002 test_guest()->WaitForImeCancel(); | 1003 test_guest()->WaitForImeCancel(); |
| 1003 scoped_ptr<base::Value> value = | 1004 scoped_ptr<base::Value> value = |
| 1004 content::ExecuteScriptAndGetValue( | 1005 content::ExecuteScriptAndGetValue( |
| 1005 guest_rvh, "document.getElementById('input1').value"); | 1006 guest_rvh, "document.getElementById('input1').value"); |
| 1006 std::string result; | 1007 std::string result; |
| 1007 ASSERT_TRUE(value->GetAsString(&result)); | 1008 ASSERT_TRUE(value->GetAsString(&result)); |
| 1008 EXPECT_EQ(UTF16ToUTF8(composition), result); | 1009 EXPECT_EQ(base::UTF16ToUTF8(composition), result); |
| 1009 } | 1010 } |
| 1010 // Tests ExtendSelectionAndDelete message works in browser_plugin. | 1011 // Tests ExtendSelectionAndDelete message works in browser_plugin. |
| 1011 { | 1012 { |
| 1012 // Set 'InputTestABC' in input1 and put caret at 6 (after 'T'). | 1013 // Set 'InputTestABC' in input1 and put caret at 6 (after 'T'). |
| 1013 ExecuteSyncJSFunction(guest_rvh, | 1014 ExecuteSyncJSFunction(guest_rvh, |
| 1014 "var i = document.getElementById('input1');" | 1015 "var i = document.getElementById('input1');" |
| 1015 "i.focus();" | 1016 "i.focus();" |
| 1016 "i.value = 'InputTestABC';" | 1017 "i.value = 'InputTestABC';" |
| 1017 "i.selectionStart=6;" | 1018 "i.selectionStart=6;" |
| 1018 "i.selectionEnd=6;"); | 1019 "i.selectionEnd=6;"); |
| 1019 base::string16 expected_value = UTF8ToUTF16("InputABC"); | 1020 base::string16 expected_value = base::UTF8ToUTF16("InputABC"); |
| 1020 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 1021 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 1021 expected_value); | 1022 expected_value); |
| 1022 // Delete 'Test' in 'InputTestABC', as the caret is after 'T': | 1023 // Delete 'Test' in 'InputTestABC', as the caret is after 'T': |
| 1023 // delete before 1 character ('T') and after 3 characters ('est'). | 1024 // delete before 1 character ('T') and after 3 characters ('est'). |
| 1024 embedder_rvh->Send( | 1025 embedder_rvh->Send( |
| 1025 new ViewMsg_ExtendSelectionAndDelete( | 1026 new ViewMsg_ExtendSelectionAndDelete( |
| 1026 test_embedder()->web_contents()->GetRoutingID(), | 1027 test_embedder()->web_contents()->GetRoutingID(), |
| 1027 1, 3)); | 1028 1, 3)); |
| 1028 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 1029 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 1029 EXPECT_EQ(expected_value, actual_title); | 1030 EXPECT_EQ(expected_value, actual_title); |
| 1030 scoped_ptr<base::Value> value = | 1031 scoped_ptr<base::Value> value = |
| 1031 content::ExecuteScriptAndGetValue( | 1032 content::ExecuteScriptAndGetValue( |
| 1032 guest_rvh, "document.getElementById('input1').value"); | 1033 guest_rvh, "document.getElementById('input1').value"); |
| 1033 std::string actual_value; | 1034 std::string actual_value; |
| 1034 ASSERT_TRUE(value->GetAsString(&actual_value)); | 1035 ASSERT_TRUE(value->GetAsString(&actual_value)); |
| 1035 EXPECT_EQ(UTF16ToUTF8(expected_value), actual_value); | 1036 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); |
| 1036 } | 1037 } |
| 1037 } | 1038 } |
| 1038 | 1039 |
| 1039 } // namespace content | 1040 } // namespace content |
| OLD | NEW |