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/strings/utf_string_conversions.h" | |
5 #include "content/common/resize_params.h" | 6 #include "content/common/resize_params.h" |
6 #include "content/public/test/render_view_test.h" | 7 #include "content/public/test/render_view_test.h" |
7 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
8 #include "content/renderer/render_widget.h" | 9 #include "content/renderer/render_widget.h" |
9 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 10 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
10 #include "third_party/WebKit/public/web/WebInputMethodController.h" | 11 #include "third_party/WebKit/public/web/WebInputMethodController.h" |
12 #include "ui/base/ime/text_input_type.h" | |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 class RenderWidgetTest : public RenderViewTest { | 16 class RenderWidgetTest : public RenderViewTest { |
15 protected: | 17 protected: |
16 RenderWidget* widget() { | 18 RenderWidget* widget() { |
17 return static_cast<RenderViewImpl*>(view_)->GetWidget(); | 19 return static_cast<RenderViewImpl*>(view_)->GetWidget(); |
18 } | 20 } |
19 | 21 |
20 void OnResize(const ResizeParams& params) { | 22 void OnResize(const ResizeParams& params) { |
21 widget()->OnResize(params); | 23 widget()->OnResize(params); |
22 } | 24 } |
23 | 25 |
24 void GetCompositionRange(gfx::Range* range) { | 26 void GetCompositionRange(gfx::Range* range) { |
25 widget()->GetCompositionRange(range); | 27 widget()->GetCompositionRange(range); |
26 } | 28 } |
27 | 29 |
28 bool next_paint_is_resize_ack() { | 30 bool next_paint_is_resize_ack() { |
29 return widget()->next_paint_is_resize_ack(); | 31 return widget()->next_paint_is_resize_ack(); |
30 } | 32 } |
33 | |
34 blink::WebInputMethodController* GetInputMethodController() { | |
35 return widget()->GetInputMethodController(); | |
36 } | |
37 | |
38 void CommitText(std::string text) { | |
39 widget()->OnImeCommitText(base::UTF8ToUTF16(text), | |
40 gfx::Range::InvalidRange(), 0); | |
41 } | |
42 | |
43 ui::TextInputType GetTextInputType() { return widget()->GetTextInputType(); } | |
44 | |
45 void SetFocus(bool focused) { widget()->OnSetFocus(focused); } | |
31 }; | 46 }; |
32 | 47 |
33 TEST_F(RenderWidgetTest, OnResize) { | 48 TEST_F(RenderWidgetTest, OnResize) { |
34 // The initial bounds is empty, so setting it to the same thing should do | 49 // The initial bounds is empty, so setting it to the same thing should do |
35 // nothing. | 50 // nothing. |
36 ResizeParams resize_params; | 51 ResizeParams resize_params; |
37 resize_params.screen_info = ScreenInfo(); | 52 resize_params.screen_info = ScreenInfo(); |
38 resize_params.new_size = gfx::Size(); | 53 resize_params.new_size = gfx::Size(); |
39 resize_params.physical_backing_size = gfx::Size(); | 54 resize_params.physical_backing_size = gfx::Size(); |
40 resize_params.top_controls_height = 0.f; | 55 resize_params.top_controls_height = 0.f; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 TEST_F(RenderWidgetTest, GetCompositionRangeInvalid) { | 149 TEST_F(RenderWidgetTest, GetCompositionRangeInvalid) { |
135 LoadHTML("<div>NOT EDITABLE</div>"); | 150 LoadHTML("<div>NOT EDITABLE</div>"); |
136 gfx::Range range; | 151 gfx::Range range; |
137 GetCompositionRange(&range); | 152 GetCompositionRange(&range); |
138 // If this test ever starts failing, one likely outcome is that WebRange | 153 // If this test ever starts failing, one likely outcome is that WebRange |
139 // and gfx::Range::InvalidRange are no longer expressed in the same | 154 // and gfx::Range::InvalidRange are no longer expressed in the same |
140 // values of start/end. | 155 // values of start/end. |
141 EXPECT_FALSE(range.IsValid()); | 156 EXPECT_FALSE(range.IsValid()); |
142 } | 157 } |
143 | 158 |
159 // This test verifies that WebInputMethodController always exists as long as | |
160 // there is a focused frame inside the page, but, IME events are only executed | |
161 // if there is also page focus. | |
162 TEST_F(RenderWidgetTest, PageFocusIme) { | |
163 LoadHTML( | |
164 "<input/>" | |
165 " <script> document.querySelector('input').focus(); </script>"); | |
166 | |
167 // Give initial focus to the widget. | |
168 SetFocus(true); | |
169 | |
170 // We must have an active WebInputMethodController. | |
171 EXPECT_TRUE(GetInputMethodController()); | |
172 | |
173 // Verify the text input type. | |
174 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
175 | |
176 // Commit some text. | |
177 std::string text = "hello"; | |
178 CommitText(text); | |
179 | |
180 // The text should be committed since there is page focus in the beginning. | |
181 EXPECT_EQ(text, GetInputMethodController()->textInputInfo().value.utf8()); | |
182 | |
183 // Drop focus. | |
184 SetFocus(false); | |
185 | |
186 // We must still have an active WebInputMethodController. | |
187 EXPECT_TRUE(GetInputMethodController()); | |
188 | |
189 // The text input type should not change. | |
190 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
191 | |
192 // Commit the text again. | |
193 text = " world"; | |
194 CommitText(text); | |
195 | |
196 // This time is should not work since |m_imeAcceptEvents| is not set. | |
197 EXPECT_EQ("hello", GetInputMethodController()->textInputInfo().value.utf8()); | |
198 | |
199 // No give focus back again and commit text. | |
wjmaclean
2017/01/05 21:24:57
s/No/Now/ ?
EhsanK
2017/01/05 21:46:43
Now. Done. Thanks!
| |
200 SetFocus(true); | |
201 CommitText(text); | |
202 EXPECT_EQ("hello world", | |
203 GetInputMethodController()->textInputInfo().value.utf8()); | |
204 } | |
205 | |
144 } // namespace content | 206 } // namespace content |
OLD | NEW |