OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <vector> | |
6 | |
7 #include "base/command_line.h" | |
8 #include "chrome/browser/ui/browser.h" | |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
10 #include "chrome/test/base/in_process_browser_test.h" | |
11 #include "chrome/test/base/ui_test_utils.h" | |
12 #include "content/public/browser/render_frame_host.h" | |
13 #include "content/public/browser/render_process_host.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "content/public/test/browser_test_utils.h" | |
16 #include "content/public/test/content_browser_test_utils.h" | |
17 #include "content/public/test/test_utils.h" | |
18 #include "content/public/test/text_input_test_utils.h" | |
19 #include "net/dns/mock_host_resolver.h" | |
20 #include "net/test/embedded_test_server/embedded_test_server.h" | |
21 #include "ui/base/ime/text_input_client.h" | |
22 #include "ui/base/ime/text_input_mode.h" | |
23 #include "ui/base/ime/text_input_type.h" | |
24 | |
25 #include "url/gurl.h" | |
26 | |
27 // TODO(ekaramad): After fixing crbug.com/578168 for all platforms, the | |
28 // following tests should be activated for other platforms, e.g., Mac and | |
29 // Android (crbug.com/602723). | |
30 #ifdef USE_AURA | |
sky
2016/06/03 22:38:49
That bug is close to 3 months old. Who knows how l
EhsanK
2016/06/06 22:35:05
The intention was to activate the tests on Mac/And
| |
31 /////////////////////////////////////////////////////////////////////////////// | |
32 // TextInputManager and IME Tests | |
33 // | |
34 // The following tests verify the correctness of TextInputState tracking on the | |
35 // browser side. They also make sure the IME logic works correctly. The baseline | |
36 // for comparison is the default functionality in the non-OOPIF case (i.e., the | |
37 // legacy implementation in RWHV's other than RWHVCF). | |
38 // These tests live outside content/ because they rely on being part of the | |
sky
2016/06/03 22:38:49
Why not have interactive ui tests include this fil
Charlie Reis
2016/06/03 23:03:35
I didn't realize that was possible. Interactive U
EhsanK
2016/06/06 22:35:05
As per our offline discussion and the fact that I
| |
39 // interactive UI test framework (to avoid flakiness). | |
40 | |
41 namespace { | |
42 | |
43 // TextInputManager Observers | |
44 | |
45 // A base class for observing the TextInputManager owned by the given | |
46 // WebContents. Subclasses could observe the TextInputManager for different | |
47 // changes. The class wraps a public tester which accepts callbacks that | |
48 // are run after specific changes in TextInputManager. Different observers can | |
49 // be subclassed from this by providing their specific callback methods. | |
50 class TextInputManagerObserverBase { | |
51 public: | |
52 explicit TextInputManagerObserverBase(content::WebContents* web_contents) | |
53 : tester_(new content::TextInputManagerTester(web_contents)), | |
54 success_(false) {} | |
55 | |
56 virtual ~TextInputManagerObserverBase() {} | |
57 | |
58 // Wait for derived class's definition of success. | |
59 void Wait() { | |
60 if (success_) | |
61 return; | |
62 message_loop_runner_ = new content::MessageLoopRunner(); | |
63 message_loop_runner_->Run(); | |
64 } | |
65 | |
66 bool success() const { return success_; } | |
67 | |
68 protected: | |
69 content::TextInputManagerTester* tester() { return tester_.get(); } | |
70 | |
71 void OnSuccess() { | |
72 success_ = true; | |
73 if (message_loop_runner_) | |
74 message_loop_runner_->Quit(); | |
75 } | |
76 | |
77 private: | |
78 std::unique_ptr<content::TextInputManagerTester> tester_; | |
79 bool success_; | |
80 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(TextInputManagerObserverBase); | |
83 }; | |
84 | |
85 // This class observes TextInputManager for changes in |TextInputState.value|. | |
86 class TextInputManagerValueObserver : public TextInputManagerObserverBase { | |
87 public: | |
88 TextInputManagerValueObserver(content::WebContents* web_contents, | |
89 const std::string& expected_value) | |
90 : TextInputManagerObserverBase(web_contents), | |
91 expected_value_(expected_value) { | |
92 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | |
93 &TextInputManagerValueObserver::VerifyValue, base::Unretained(this))); | |
94 } | |
95 | |
96 private: | |
97 void VerifyValue(content::TextInputManagerTester* text_input_manager_tester) { | |
98 ASSERT_EQ(tester(), text_input_manager_tester); | |
99 std::string value; | |
100 if (tester()->GetTextInputValue(&value) && expected_value_ == value) | |
101 OnSuccess(); | |
102 } | |
103 | |
104 std::string expected_value_; | |
105 }; | |
106 | |
107 // This class observes TextInputManager for changes in |TextInputState.type|. | |
108 class TextInputManagerTypeObserver : public TextInputManagerObserverBase { | |
109 public: | |
110 TextInputManagerTypeObserver(content::WebContents* web_contents, | |
111 ui::TextInputType expected_type) | |
112 : TextInputManagerObserverBase(web_contents), | |
113 expected_type_(expected_type) { | |
114 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | |
115 &TextInputManagerTypeObserver::VerifyType, base::Unretained(this))); | |
116 } | |
117 | |
118 private: | |
119 void VerifyType(content::TextInputManagerTester* text_input_manager_tester) { | |
120 ASSERT_EQ(tester(), text_input_manager_tester); | |
121 ui::TextInputType type = | |
122 tester()->GetTextInputType(&type) ? type : ui::TEXT_INPUT_TYPE_NONE; | |
123 if (expected_type_ == type) | |
124 OnSuccess(); | |
125 } | |
126 | |
127 ui::TextInputType expected_type_; | |
128 }; | |
129 | |
130 // This class observes TextInputManager for the first change in TextInputState. | |
131 class TextInputManagerChangeObserver : public TextInputManagerObserverBase { | |
132 public: | |
133 explicit TextInputManagerChangeObserver(content::WebContents* web_contents) | |
134 : TextInputManagerObserverBase(web_contents) { | |
135 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | |
136 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this))); | |
137 } | |
138 | |
139 private: | |
140 void VerifyChange( | |
141 content::TextInputManagerTester* text_input_manager_tester) { | |
142 ASSERT_EQ(tester(), text_input_manager_tester); | |
143 if (tester()->IsTextInputStateChanged()) | |
144 OnSuccess(); | |
145 } | |
146 }; | |
147 | |
148 // This class observes |TextInputState.type| for a specific RWHV. | |
149 class ViewTextInputTypeObserver : public TextInputManagerObserverBase { | |
150 public: | |
151 explicit ViewTextInputTypeObserver(content::WebContents* web_contents, | |
152 content::RenderWidgetHostView* rwhv, | |
153 ui::TextInputType expected_type) | |
154 : TextInputManagerObserverBase(web_contents), | |
155 web_contents_(web_contents), | |
156 view_(rwhv), | |
157 expected_type_(expected_type) { | |
158 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | |
159 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this))); | |
160 } | |
161 | |
162 private: | |
163 void VerifyType(content::TextInputManagerTester* tester) { | |
164 ui::TextInputType type; | |
165 if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) | |
166 return; | |
167 if (expected_type_ == type) | |
168 OnSuccess(); | |
169 } | |
170 | |
171 content::WebContents* web_contents_; | |
172 content::RenderWidgetHostView* view_; | |
173 ui::TextInputType expected_type_; | |
174 }; | |
175 | |
176 } // namespace | |
177 | |
178 // Main class for all TextInputState and IME related tests. | |
179 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { | |
180 public: | |
181 SitePerProcessTextInputManagerTest() {} | |
182 ~SitePerProcessTextInputManagerTest() override {} | |
183 | |
184 void SetUpCommandLine(base::CommandLine* command_line) override { | |
185 content::IsolateAllSitesForTesting(command_line); | |
186 } | |
187 | |
188 void SetUpOnMainThread() override { | |
189 host_resolver()->AddRule("*", "127.0.0.1"); | |
190 | |
191 // Add content/test/data 'cross_site_iframe_factory.html'. | |
192 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); | |
193 | |
194 ASSERT_TRUE(embedded_test_server()->Start()); | |
195 } | |
196 | |
197 protected: | |
198 content::WebContents* active_contents() { | |
199 return browser()->tab_strip_model()->GetActiveWebContents(); | |
200 } | |
201 | |
202 // static | |
203 // Adds an <input> field to a given frame by executing javascript code. | |
204 // The input can be added as the first element or the last element of | |
205 // |document.body|. | |
206 static void AddInputFieldToFrame(content::RenderFrameHost* rfh, | |
207 const std::string& type, | |
208 const std::string& value, | |
209 bool append_as_first_child) { | |
210 std::string script = base::StringPrintf( | |
211 "var input = document.createElement('input');" | |
212 "input.setAttribute('type', '%s');" | |
213 "input.setAttribute('value', '%s');" | |
214 "document.body.%s;", | |
215 type.c_str(), value.c_str(), | |
216 append_as_first_child ? "insertBefore(input, document.body.firstChild)" | |
217 : "appendChild(input)"); | |
218 EXPECT_TRUE(ExecuteScript(rfh, script)); | |
219 } | |
220 | |
221 // Uses 'cross_site_iframe_factory.html'. The main frame's domain is | |
222 // 'a.com'. | |
223 void CreateIframePage(const std::string& structure) { | |
224 std::string path = base::StringPrintf("/cross_site_iframe_factory.html?%s", | |
225 structure.c_str()); | |
226 GURL main_url(embedded_test_server()->GetURL("a.com", path)); | |
227 ui_test_utils::NavigateToURL(browser(), main_url); | |
228 } | |
229 | |
230 // Iteratively uses ChildFrameAt(frame, i) to get the i-th child frame | |
231 // inside frame. For example, for 'a(b(c, d(e)))', [0] returns b, and | |
232 // [0, 1, 0] returns e; | |
233 content::RenderFrameHost* GetFrame(const std::vector<size_t>& indices) { | |
234 content::RenderFrameHost* current = active_contents()->GetMainFrame(); | |
235 for (size_t index : indices) | |
236 current = ChildFrameAt(current, index); | |
237 return current; | |
238 } | |
239 | |
240 private: | |
241 DISALLOW_COPY_AND_ASSIGN(SitePerProcessTextInputManagerTest); | |
242 }; | |
243 | |
244 // The following test loads a page with multiple nested <iframe> elements which | |
245 // are in or out of process with the main frame. Then an <input> field with | |
246 // unique value is added to every single frame on the frame tree. The test then | |
247 // creates a sequence of tab presses and verifies that after each key press, the | |
248 // TextInputState.value reflects that of the focused input, i.e., the | |
249 // TextInputManager is correctly tracking TextInputState across frames. | |
250 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
251 TrackStateWhenSwitchingFocusedFrames) { | |
252 CreateIframePage("a(a,b,c(a,b,d(e, f)),g)"); | |
253 std::vector<std::string> values{ | |
254 "main", "node_a", "node_b", "node_c", "node_c_a", | |
255 "node_c_b", "node_c_d", "node_c_d_e", "node_c_d_f", "node_g"}; | |
256 | |
257 // TODO(ekaramad): This should not be needed and uniform initialization should | |
258 // work. However, in some bots, this is failing. | |
259 using vector = std::vector<size_t>; | |
260 | |
261 std::vector<content::RenderFrameHost*> frames{ | |
262 GetFrame(vector{}), GetFrame(vector{0}), | |
263 GetFrame(vector{1}), GetFrame(vector{2}), | |
264 GetFrame(vector{2, 0}), GetFrame(vector{2, 1}), | |
265 GetFrame(vector{2, 2}), GetFrame(vector{2, 2, 0}), | |
266 GetFrame(vector{2, 2, 1}), GetFrame(vector{3})}; | |
267 | |
268 for (size_t i = 0; i < frames.size(); ++i) | |
269 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
270 | |
271 for (size_t i = 0; i < frames.size(); ++i) { | |
272 TextInputManagerValueObserver observer(active_contents(), values[i]); | |
273 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, | |
274 false); | |
275 observer.Wait(); | |
276 } | |
277 } | |
278 | |
279 // The following test loads a page with two OOPIFs. An <input> is added to both | |
280 // frames and tab key is pressed until the one in the second OOPIF is focused. | |
281 // Then, the renderer processes for both frames are crashed. The test verifies | |
282 // that the TextInputManager stops tracking the RWHVs as well as properly | |
283 // resets the TextInputState after the second (active) RWHV goes away. | |
284 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
285 StopTrackingCrashedChildFrame) { | |
286 CreateIframePage("a(b, c)"); | |
287 std::vector<std::string> values{"node_b", "node_c"}; | |
288 using vector = std::vector<size_t>; | |
289 std::vector<content::RenderFrameHost*> frames{GetFrame(vector{0}), | |
290 GetFrame(vector{1})}; | |
291 | |
292 for (size_t i = 0; i < frames.size(); ++i) | |
293 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
294 | |
295 // Tab into both inputs and make sure we correctly receive their | |
296 // TextInputState. For the second tab two IPCs arrive: one from the first | |
297 // frame to set the state to none, and another one from the second frame to | |
298 // set it to TEXT. To avoid the race between them, we shall also observe the | |
299 // first frame setting its state to NONE after the second tab. | |
300 ViewTextInputTypeObserver view_type_observer( | |
301 active_contents(), frames[0]->GetView(), ui::TEXT_INPUT_TYPE_NONE); | |
302 | |
303 for (size_t i = 0; i < frames.size(); ++i) { | |
304 TextInputManagerValueObserver observer(active_contents(), values[i]); | |
305 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, | |
306 false); | |
307 observer.Wait(); | |
308 } | |
309 | |
310 // Make sure that the first view has set its TextInputState.type to NONE. | |
311 view_type_observer.Wait(); | |
312 | |
313 // Verify that we are tracking the TextInputState from the first frame. | |
314 content::RenderWidgetHostView* first_view = frames[0]->GetView(); | |
315 ui::TextInputType first_view_type; | |
316 EXPECT_TRUE(content::GetTextInputTypeForView(active_contents(), first_view, | |
317 &first_view_type)); | |
318 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, first_view_type); | |
319 | |
320 // Now that the second frame's <input> is focused, we crash the first frame | |
321 // and observe that text input state is updated for the view. | |
322 std::unique_ptr<content::TestRenderWidgetHostViewDestructionObserver> | |
323 destruction_observer( | |
324 new content::TestRenderWidgetHostViewDestructionObserver(first_view)); | |
325 frames[0]->GetProcess()->Shutdown(0, false); | |
326 destruction_observer->Wait(); | |
327 | |
328 // Verifying that the TextInputManager is no longer tracking TextInputState | |
329 // for |first_view|. Note that |first_view| is now a dangling pointer. | |
330 EXPECT_FALSE(content::GetTextInputTypeForView(active_contents(), first_view, | |
331 &first_view_type)); | |
332 | |
333 // Now crash the second <iframe> which has an active view. | |
334 content::RenderWidgetHostView* second_view = frames[1]->GetView(); | |
335 TextInputManagerChangeObserver change_observer(active_contents()); | |
336 frames[1]->GetProcess()->Shutdown(0, false); | |
337 change_observer.Wait(); | |
338 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
339 content::GetTextInputTypeFromWebContents(active_contents())); | |
340 EXPECT_FALSE(!!content::GetActiveViewFromWebContents(active_contents())); | |
341 ui::TextInputType second_view_type; | |
342 EXPECT_FALSE(content::GetTextInputTypeForView(active_contents(), second_view, | |
343 &second_view_type)); | |
344 } | |
345 | |
346 // The following test loads a page with two child frames: one in process and one | |
347 // out of process with main frame. The test inserts an <input> inside each frame | |
348 // and focuses the first frame and observes the TextInputManager setting the | |
349 // state to ui::TEXT_INPUT_TYPE_TEXT. Then, the frame is detached and the test | |
350 // observes that the state type is reset to ui::TEXT_INPUT_TYPE_NONE. The same | |
351 // sequence of actions is then performed on the out of process frame. | |
352 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
353 ResetStateAfterFrameDetached) { | |
354 CreateIframePage("a(a, b)"); | |
355 using vector = std::vector<size_t>; | |
356 std::vector<content::RenderFrameHost*> frames{GetFrame(vector{0}), | |
357 GetFrame(vector{1})}; | |
358 | |
359 for (size_t i = 0; i < frames.size(); ++i) | |
360 AddInputFieldToFrame(frames[i], "text", "", true); | |
361 | |
362 // Press tab key to focus the <input> in the first frame. | |
363 TextInputManagerTypeObserver type_observer_text_a(active_contents(), | |
364 ui::TEXT_INPUT_TYPE_TEXT); | |
365 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
366 type_observer_text_a.Wait(); | |
367 | |
368 std::string remove_first_iframe_script = | |
369 "var frame = document.querySelector('iframe');" | |
370 "frame.parentNode.removeChild(frame);"; | |
371 // Detach first frame and observe |TextInputState.type| resetting to | |
372 // ui::TEXT_INPUT_TYPE_NONE. | |
373 TextInputManagerTypeObserver type_observer_none_a(active_contents(), | |
374 ui::TEXT_INPUT_TYPE_NONE); | |
375 EXPECT_TRUE(ExecuteScript(active_contents(), remove_first_iframe_script)); | |
376 type_observer_none_a.Wait(); | |
377 | |
378 // Press tab to focus the <input> in the second frame. | |
379 TextInputManagerTypeObserver type_observer_text_b(active_contents(), | |
380 ui::TEXT_INPUT_TYPE_TEXT); | |
381 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
382 type_observer_text_b.Wait(); | |
383 | |
384 // Detach first frame and observe |TextInputState.type| resetting to | |
385 // ui::TEXT_INPUT_TYPE_NONE. | |
386 TextInputManagerTypeObserver type_observer_none_b(active_contents(), | |
387 ui::TEXT_INPUT_TYPE_NONE); | |
388 EXPECT_TRUE(ExecuteScript(active_contents(), remove_first_iframe_script)); | |
389 type_observer_none_b.Wait(); | |
390 } | |
391 | |
392 // This test creates a page with one OOPIF and adds an <input> to it. Then, the | |
393 // <input> is focused and the test verfies that the |TextInputState.type| is set | |
394 // to ui::TEXT_INPUT_TYPE_TEXT. Next, the child frame is navigated away and the | |
395 // test verifies that |TextInputState.type| resets to ui::TEXT_INPUT_TYPE_NONE. | |
396 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
397 ResetStateAfterChildNavigation) { | |
398 CreateIframePage("a(b)"); | |
399 using vector = std::vector<size_t>; | |
400 content::RenderFrameHost* main_frame = GetFrame(vector{}); | |
401 content::RenderFrameHost* child_frame = GetFrame(vector{0}); | |
402 | |
403 AddInputFieldToFrame(child_frame, "text", "child", false); | |
404 | |
405 // Focus <input> in child frame and verify the |TextInputState.value|. | |
406 TextInputManagerValueObserver child_set_state_observer(active_contents(), | |
407 "child"); | |
408 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
409 child_set_state_observer.Wait(); | |
410 | |
411 // Navigate the child frame to about:blank and verify that TextInputManager | |
412 // correctly sets its |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. | |
413 TextInputManagerTypeObserver child_reset_state_observer( | |
414 active_contents(), ui::TEXT_INPUT_TYPE_NONE); | |
415 EXPECT_TRUE(ExecuteScript( | |
416 main_frame, "document.querySelector('iframe').src = 'about:blank'")); | |
417 child_reset_state_observer.Wait(); | |
418 } | |
419 | |
420 // This test creates a blank page and adds an <input> to it. Then, the <input> | |
421 // is focused and the test verfies that the |TextInputState.type| is set to | |
422 // ui::TEXT_INPUT_TYPE_TEXT. Next, the browser is navigated away and the test | |
423 // verifies that |TextInputState.type| resets to ui::TEXT_INPUT_TYPE_NONE. | |
424 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
425 ResetStateAfterBrowserNavigation) { | |
426 CreateIframePage("a()"); | |
427 content::RenderFrameHost* main_frame = GetFrame(std::vector<size_t>{}); | |
428 AddInputFieldToFrame(main_frame, "text", "", false); | |
429 | |
430 TextInputManagerTypeObserver set_state_observer(active_contents(), | |
431 ui::TEXT_INPUT_TYPE_TEXT); | |
432 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
433 set_state_observer.Wait(); | |
434 | |
435 TextInputManagerTypeObserver reset_state_observer(active_contents(), | |
436 ui::TEXT_INPUT_TYPE_NONE); | |
437 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
438 reset_state_observer.Wait(); | |
439 } | |
440 #endif // USE_AURA | |
441 | |
442 // TODO(ekaramad): The following tests are specifically written for Aura and are | |
443 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | |
444 // (crbug.com/602723). | |
445 #ifdef USE_AURA | |
446 // Observes current input method for state changes. | |
447 class InputMethodObserverBase { | |
448 public: | |
449 explicit InputMethodObserverBase(content::WebContents* web_contents) | |
450 : success_(false), | |
451 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { | |
452 } | |
453 | |
454 void Wait() { | |
455 if (success_) | |
456 return; | |
457 message_loop_runner_ = new content::MessageLoopRunner(); | |
458 message_loop_runner_->Run(); | |
459 } | |
460 | |
461 bool success() const { return success_; } | |
462 | |
463 protected: | |
464 content::TestInputMethodObserver* test_observer() { | |
465 return test_observer_.get(); | |
466 } | |
467 | |
468 const base::Closure success_closure() { | |
469 return base::Bind(&InputMethodObserverBase::OnSuccess, | |
470 base::Unretained(this)); | |
471 } | |
472 | |
473 private: | |
474 void OnSuccess() { | |
475 success_ = true; | |
476 if (message_loop_runner_) | |
477 message_loop_runner_->Quit(); | |
478 } | |
479 | |
480 bool success_; | |
481 std::unique_ptr<content::TestInputMethodObserver> test_observer_; | |
482 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
483 | |
484 DISALLOW_COPY_AND_ASSIGN(InputMethodObserverBase); | |
485 }; | |
486 | |
487 class InputMethodObserverForShowIme : public InputMethodObserverBase { | |
488 public: | |
489 explicit InputMethodObserverForShowIme(content::WebContents* web_contents) | |
490 : InputMethodObserverBase(web_contents) { | |
491 test_observer()->SetOnShowImeIfNeededCallback(success_closure()); | |
492 } | |
493 }; | |
494 | |
495 // This test verifies that the IME for Aura is shown if and only if the current | |
496 // client's |TextInputState.type| is not ui::TEXT_INPUT_TYPE_NONE and the flag | |
497 // |TextInputState.show_ime_if_needed| is true. This should happen even when | |
498 // the TextInputState has not changed (according to the platform), e.g., in | |
499 // aura when receiving two consecutive updates with same |TextInputState.type|. | |
500 // TODO(ekaramad): This test is actually a unit test not necessarily an OOPIF | |
501 // test. We should move it to somewhere more relevant. | |
502 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
503 CorrectlyShowImeIfNeeded) { | |
504 // We only need the <iframe> page to create RWHV. | |
505 CreateIframePage("a()"); | |
506 content::RenderFrameHost* main_frame = GetFrame(std::vector<size_t>{}); | |
507 content::RenderWidgetHostView* view = main_frame->GetView(); | |
508 content::WebContents* web_contents = active_contents(); | |
509 | |
510 content::TextInputStateSender sender(view); | |
511 | |
512 auto send_and_check_show_ime = [&sender, &web_contents]() { | |
513 InputMethodObserverForShowIme observer(web_contents); | |
514 sender.Send(); | |
515 return observer.success(); | |
516 }; | |
517 | |
518 // Sending an empty state should not trigger ime. | |
519 EXPECT_FALSE(send_and_check_show_ime()); | |
520 | |
521 // Set |TextInputState.type| to text. Expect no IME. | |
522 sender.SetType(ui::TEXT_INPUT_TYPE_TEXT); | |
523 EXPECT_FALSE(send_and_check_show_ime()); | |
524 | |
525 // Set |TextInputState.show_ime_if_needed| to true. Expect IME. | |
526 sender.SetShowImeIfNeeded(true); | |
527 EXPECT_TRUE(send_and_check_show_ime()); | |
528 | |
529 // Send the same message. Expect IME (no change). | |
530 EXPECT_TRUE(send_and_check_show_ime()); | |
531 | |
532 // Reset |TextInputState.show_ime_if_needed|. Expect no IME. | |
533 sender.SetShowImeIfNeeded(false); | |
534 EXPECT_FALSE(send_and_check_show_ime()); | |
535 | |
536 // Setting an irrelevant field. Expect no IME. | |
537 sender.SetMode(ui::TEXT_INPUT_MODE_LATIN); | |
538 EXPECT_FALSE(send_and_check_show_ime()); | |
539 | |
540 // Set |TextInputState.show_ime_if_needed|. Expect IME. | |
541 sender.SetShowImeIfNeeded(true); | |
542 EXPECT_TRUE(send_and_check_show_ime()); | |
543 | |
544 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | |
545 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | |
546 EXPECT_FALSE(send_and_check_show_ime()); | |
547 } | |
548 #endif // USE_AURA | |
OLD | NEW |