OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/chromeos/input_method/textinput_test_helper.h" | 6 #include "chrome/browser/chromeos/input_method/textinput_test_helper.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
9 #include "chrome/test/base/interactive_test_utils.h" | 9 #include "chrome/test/base/interactive_test_utils.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 ASSERT_TRUE(content::ExecuteScript( | 31 ASSERT_TRUE(content::ExecuteScript( |
32 tab, | 32 tab, |
33 "document.getElementById('text_id').focus()")); | 33 "document.getElementById('text_id').focus()")); |
34 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); | 34 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); |
35 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); | 35 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); |
36 | 36 |
37 const string16 sample_text1 = UTF8ToUTF16("abcde"); | 37 const string16 sample_text1 = UTF8ToUTF16("abcde"); |
38 const string16 sample_text2 = UTF8ToUTF16("fghij"); | 38 const string16 sample_text2 = UTF8ToUTF16("fghij"); |
39 const string16 surrounding_text2 = sample_text1 + sample_text2; | 39 const string16 surrounding_text2 = sample_text1 + sample_text2; |
40 ui::Range expected_range1(5, 5); | 40 gfx::Range expected_range1(5, 5); |
41 ui::Range expected_range2(10, 10); | 41 gfx::Range expected_range2(10, 10); |
42 | 42 |
43 ASSERT_TRUE(helper.GetTextInputClient()); | 43 ASSERT_TRUE(helper.GetTextInputClient()); |
44 | 44 |
45 helper.GetTextInputClient()->InsertText(sample_text1); | 45 helper.GetTextInputClient()->InsertText(sample_text1); |
46 helper.WaitForSurroundingTextChanged(sample_text1, expected_range1); | 46 helper.WaitForSurroundingTextChanged(sample_text1, expected_range1); |
47 EXPECT_EQ(sample_text1, helper.GetSurroundingText()); | 47 EXPECT_EQ(sample_text1, helper.GetSurroundingText()); |
48 EXPECT_EQ(expected_range1, helper.GetSelectionRange()); | 48 EXPECT_EQ(expected_range1, helper.GetSelectionRange()); |
49 | 49 |
50 helper.GetTextInputClient()->InsertText(sample_text2); | 50 helper.GetTextInputClient()->InsertText(sample_text2); |
51 helper.WaitForSurroundingTextChanged(surrounding_text2, expected_range2); | 51 helper.WaitForSurroundingTextChanged(surrounding_text2, expected_range2); |
(...skipping 13 matching lines...) Expand all Loading... |
65 content::WebContents* tab = | 65 content::WebContents* tab = |
66 browser()->tab_strip_model()->GetActiveWebContents(); | 66 browser()->tab_strip_model()->GetActiveWebContents(); |
67 | 67 |
68 ASSERT_TRUE(content::ExecuteScript( | 68 ASSERT_TRUE(content::ExecuteScript( |
69 tab, | 69 tab, |
70 "document.getElementById('text_id').focus()")); | 70 "document.getElementById('text_id').focus()")); |
71 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); | 71 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); |
72 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); | 72 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); |
73 | 73 |
74 const string16 sample_text = UTF8ToUTF16("abcde"); | 74 const string16 sample_text = UTF8ToUTF16("abcde"); |
75 ui::Range expected_range(5, 5); | 75 gfx::Range expected_range(5, 5); |
76 | 76 |
77 ui::CompositionText composition_text; | 77 ui::CompositionText composition_text; |
78 composition_text.text = sample_text; | 78 composition_text.text = sample_text; |
79 composition_text.selection.set_start(expected_range.length()); | 79 composition_text.selection.set_start(expected_range.length()); |
80 composition_text.selection.set_end(expected_range.length()); | 80 composition_text.selection.set_end(expected_range.length()); |
81 | 81 |
82 ASSERT_TRUE(helper.GetTextInputClient()); | 82 ASSERT_TRUE(helper.GetTextInputClient()); |
83 helper.GetTextInputClient()->SetCompositionText(composition_text); | 83 helper.GetTextInputClient()->SetCompositionText(composition_text); |
84 ASSERT_TRUE(helper.GetTextInputClient()->HasCompositionText()); | 84 ASSERT_TRUE(helper.GetTextInputClient()->HasCompositionText()); |
85 // TODO(nona): Make sure there is no IPC from renderer. | 85 // TODO(nona): Make sure there is no IPC from renderer. |
(...skipping 10 matching lines...) Expand all Loading... |
96 FocusToTextContainingTextAreaByClickingCase) { | 96 FocusToTextContainingTextAreaByClickingCase) { |
97 TextInputTestHelper helper; | 97 TextInputTestHelper helper; |
98 GURL url = ui_test_utils::GetTestUrl( | 98 GURL url = ui_test_utils::GetTestUrl( |
99 base::FilePath(FILE_PATH_LITERAL("textinput")), | 99 base::FilePath(FILE_PATH_LITERAL("textinput")), |
100 base::FilePath(FILE_PATH_LITERAL("textarea_with_preset_text.html"))); | 100 base::FilePath(FILE_PATH_LITERAL("textarea_with_preset_text.html"))); |
101 ui_test_utils::NavigateToURL(browser(), url); | 101 ui_test_utils::NavigateToURL(browser(), url); |
102 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); | 102 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); |
103 | 103 |
104 content::WebContents* tab = | 104 content::WebContents* tab = |
105 browser()->tab_strip_model()->GetActiveWebContents(); | 105 browser()->tab_strip_model()->GetActiveWebContents(); |
106 const ui::Range zero_range(0, 0); | 106 const gfx::Range zero_range(0, 0); |
107 | 107 |
108 // We expect no surrounding texts. | 108 // We expect no surrounding texts. |
109 helper.ClickElement("empty_textarea", tab); | 109 helper.ClickElement("empty_textarea", tab); |
110 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); | 110 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); |
111 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); | 111 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); |
112 helper.WaitForSurroundingTextChanged(UTF8ToUTF16(""), zero_range); | 112 helper.WaitForSurroundingTextChanged(UTF8ToUTF16(""), zero_range); |
113 EXPECT_TRUE(helper.GetSurroundingText().empty()); | 113 EXPECT_TRUE(helper.GetSurroundingText().empty()); |
114 EXPECT_EQ(zero_range, helper.GetSelectionRange()); | 114 EXPECT_EQ(zero_range, helper.GetSelectionRange()); |
115 | 115 |
116 // Click textarea containing text, so expecting new surrounding text comes. | 116 // Click textarea containing text, so expecting new surrounding text comes. |
117 helper.ClickElement("filled_textarea", tab); | 117 helper.ClickElement("filled_textarea", tab); |
118 const string16 expected_text = UTF8ToUTF16("abcde"); | 118 const string16 expected_text = UTF8ToUTF16("abcde"); |
119 const ui::Range expected_range(5, 5); | 119 const gfx::Range expected_range(5, 5); |
120 helper.WaitForSurroundingTextChanged(expected_text, expected_range); | 120 helper.WaitForSurroundingTextChanged(expected_text, expected_range); |
121 EXPECT_EQ(expected_text, helper.GetSurroundingText()); | 121 EXPECT_EQ(expected_text, helper.GetSurroundingText()); |
122 EXPECT_EQ(expected_range, helper.GetSelectionRange()); | 122 EXPECT_EQ(expected_range, helper.GetSelectionRange()); |
123 | 123 |
124 // Then, back to empty text area: expecting empty string. | 124 // Then, back to empty text area: expecting empty string. |
125 helper.ClickElement("empty_textarea", tab); | 125 helper.ClickElement("empty_textarea", tab); |
126 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); | 126 helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); |
127 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); | 127 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); |
128 helper.WaitForSurroundingTextChanged(UTF8ToUTF16(""), zero_range); | 128 helper.WaitForSurroundingTextChanged(UTF8ToUTF16(""), zero_range); |
129 EXPECT_TRUE(helper.GetSurroundingText().empty()); | 129 EXPECT_TRUE(helper.GetSurroundingText().empty()); |
130 EXPECT_EQ(zero_range, helper.GetSelectionRange()); | 130 EXPECT_EQ(zero_range, helper.GetSelectionRange()); |
131 } | 131 } |
132 | 132 |
133 // TODO(nona): Add test for JavaScript focusing to textarea containing text. | 133 // TODO(nona): Add test for JavaScript focusing to textarea containing text. |
134 // TODO(nona): Add test for text changing by JavaScript. | 134 // TODO(nona): Add test for text changing by JavaScript. |
135 // TODO(nona): Add test for onload focusing to textarea containing text. | 135 // TODO(nona): Add test for onload focusing to textarea containing text. |
136 } // namespace chromeos | 136 } // namespace chromeos |
OLD | NEW |