OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 <initializer_list> | |
6 #include <vector> | |
7 | |
5 #include "base/command_line.h" | 8 #include "base/command_line.h" |
6 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
8 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
9 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
10 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
14 #include "content/public/browser/render_process_host.h" | |
11 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
12 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
13 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
14 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
19 #include "content/public/test/text_input_test_utils.h" | |
15 #include "net/dns/mock_host_resolver.h" | 20 #include "net/dns/mock_host_resolver.h" |
16 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
22 #include "ui/base/ime/text_input_client.h" | |
23 #include "ui/base/ime/text_input_mode.h" | |
24 #include "ui/base/ime/text_input_type.h" | |
25 | |
17 #include "url/gurl.h" | 26 #include "url/gurl.h" |
18 | 27 |
19 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { | 28 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { |
20 public: | 29 public: |
21 SitePerProcessInteractiveBrowserTest() {} | 30 SitePerProcessInteractiveBrowserTest() {} |
22 ~SitePerProcessInteractiveBrowserTest() override {} | 31 ~SitePerProcessInteractiveBrowserTest() override {} |
23 | 32 |
24 void SetUpCommandLine(base::CommandLine* command_line) override { | 33 void SetUpCommandLine(base::CommandLine* command_line) override { |
25 content::IsolateAllSitesForTesting(command_line); | 34 content::IsolateAllSitesForTesting(command_line); |
26 } | 35 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); | 234 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); |
226 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 235 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); |
227 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); | 236 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); |
228 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); | 237 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); |
229 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 238 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
230 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); | 239 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); |
231 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); | 240 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); |
232 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 241 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
233 } | 242 } |
234 | 243 |
244 // TODO(ekaramad): After fixing crbug.com/578168 for all platforms, the | |
245 // following tests should be activated for other platforms, e.g., Mac and | |
246 // Android (crbug.com/602723). | |
247 #ifdef USE_AURA | |
248 /////////////////////////////////////////////////////////////////////////////// | |
249 // TextInputManager and IME Tests | |
250 // | |
251 // The following tests verify the correctness of TextInputState tracking on the | |
252 // browser side. They also make sure the IME logic works correctly. The baseline | |
253 // for comparison is the default functionality in the non-OOPIF case (i.e., the | |
254 // legacy implementation in RWHV's other than RWHVCF.). | |
255 | |
256 // TextInputManager Observers | |
257 // Observing the |TextInputState.value|. | |
258 class TextInputManagerObserverBase { | |
259 public: | |
260 explicit TextInputManagerObserverBase(content::WebContents* web_contents) | |
261 : success_(false) { | |
262 test_observer_ = | |
263 content::TestTextInputManagerObserver::Create(web_contents); | |
264 } | |
265 | |
266 virtual ~TextInputManagerObserverBase() {} | |
267 | |
268 void Wait() { | |
269 if (success_) | |
270 return; | |
271 message_loop_runner_ = new content::MessageLoopRunner(); | |
272 message_loop_runner_->Run(); | |
273 } | |
274 | |
275 bool success() const { return success_; } | |
276 | |
277 protected: | |
278 base::Closure on_success() { | |
279 return base::Bind(&TextInputManagerObserverBase::OnSuccess, | |
280 base::Unretained(this)); | |
281 } | |
282 | |
283 content::TestTextInputManagerObserver* observer() { | |
284 return test_observer_.get(); | |
285 } | |
286 | |
287 private: | |
288 void OnSuccess() { | |
289 success_ = true; | |
290 if (message_loop_runner_ && message_loop_runner_->loop_running()) | |
291 message_loop_runner_->Quit(); | |
292 } | |
293 | |
294 std::unique_ptr<content::TestTextInputManagerObserver> test_observer_; | |
295 bool success_; | |
296 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
297 | |
298 DISALLOW_COPY_AND_ASSIGN(TextInputManagerObserverBase); | |
299 }; | |
300 | |
301 // This class observers the TextInputManager for updated |TextInputState.value|. | |
302 class TextInputManagerValueObserver : public TextInputManagerObserverBase { | |
303 public: | |
304 explicit TextInputManagerValueObserver(content::WebContents* web_contents, | |
305 const std::string& expected_value) | |
306 : TextInputManagerObserverBase(web_contents), | |
307 expected_value_(expected_value) { | |
308 observer()->SetUpdateCallback(base::Bind( | |
309 &TextInputManagerValueObserver::VerifyValue, base::Unretained(this))); | |
310 } | |
311 | |
312 private: | |
313 void VerifyValue(content::TestTextInputManagerObserver* observer) { | |
314 std::string value; | |
315 if (observer->GetTextInputValue(value) && expected_value_ == value) | |
316 on_success().Run(); | |
317 } | |
318 | |
319 std::string expected_value_; | |
320 }; | |
321 | |
322 // This class observers the TextInputManager for updated |TextInputState.type|. | |
323 class TextInputManagerTypeObserver : public TextInputManagerObserverBase { | |
324 public: | |
325 explicit TextInputManagerTypeObserver(content::WebContents* web_contents, | |
326 ui::TextInputType expected_type) | |
327 : TextInputManagerObserverBase(web_contents), | |
328 expected_type_(expected_type) { | |
329 observer()->SetUpdateCallback(base::Bind( | |
330 &TextInputManagerTypeObserver::VerifyType, base::Unretained(this))); | |
331 } | |
332 | |
333 private: | |
334 void VerifyType(content::TestTextInputManagerObserver* observer) { | |
335 if (expected_type_ == observer->GetTextInputType()) | |
336 on_success().Run(); | |
337 } | |
338 | |
339 ui::TextInputType expected_type_; | |
340 }; | |
341 | |
342 // An observer class which observes the TextInputManager until the first time | |
343 // the TextInputManager detects a change in TextInputState. | |
344 class TextInputManagerChangeObserver : public TextInputManagerObserverBase { | |
345 public: | |
346 explicit TextInputManagerChangeObserver(content::WebContents* web_contents) | |
347 : TextInputManagerObserverBase(web_contents) { | |
348 observer()->SetUpdateCallback(base::Bind( | |
349 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this))); | |
350 } | |
351 | |
352 private: | |
353 void VerifyChange(content::TestTextInputManagerObserver* observer) { | |
354 if (observer->IsTextInputStateChanged()) | |
355 on_success().Run(); | |
356 } | |
357 }; | |
358 | |
359 // Main class for all TextInputState and IME related tests. | |
360 class TextInputInteractiveBrowserTest | |
361 : public SitePerProcessInteractiveBrowserTest { | |
362 protected: | |
363 content::WebContents* active_contents() { | |
364 return browser()->tab_strip_model()->GetActiveWebContents(); | |
365 } | |
366 | |
367 // static | |
368 // Adds an <input> field to a given frame by executing javascript code. | |
369 // The input can be added as the first element or the last element of | |
370 // |document.body|. | |
371 static void AddInputFieldToFrame(content::RenderFrameHost* rfh, | |
372 const std::string& type, | |
373 const std::string& value, | |
374 bool append_as_first_child) { | |
375 std::string script = base::StringPrintf( | |
376 "var input = document.createElement('input');" | |
377 "input.setAttribute('type', '%s');" | |
378 "input.setAttribute('value', '%s');" | |
379 "if (%s && !!document.body.firstChild) {" | |
380 " document.body.insertBefore(input, document.body.firstChild);" | |
381 "} else {" | |
382 " document.body.appendChild(input);" | |
383 "}", | |
384 type.c_str(), value.c_str(), append_as_first_child ? "true" : "false"); | |
385 EXPECT_TRUE(ExecuteScript(rfh, script)); | |
386 } | |
387 | |
388 // Uses 'cross_site_iframe_factory.html'. The main frame's domain is | |
389 // 'a.com'. | |
390 void CreateIframePage(const std::string& structure) { | |
391 std::string path = base::StringPrintf("/cross_site_iframe_factory.html?%s", | |
392 structure.c_str()); | |
393 GURL main_url(embedded_test_server()->GetURL("a.com", path)); | |
394 ui_test_utils::NavigateToURL(browser(), main_url); | |
395 } | |
396 | |
397 // Recrusively uses ChildFrameAt(frame, i) to get the i-th child frame | |
398 // inside | |
399 // frame. | |
400 // For example, for 'a(b(c, d(e)))', [0] returns b, and [0, 1, 0] returns e; | |
401 content::RenderFrameHost* GetFrame(std::initializer_list<size_t> list) { | |
dcheng
2016/05/10 20:33:41
Just have this take a std::vector<size_t>. You can
EhsanK
2016/05/11 01:54:03
Done.
| |
402 std::vector<size_t> indices(list); | |
403 content::RenderFrameHost* current = active_contents()->GetMainFrame(); | |
404 for (size_t i = 0; i < indices.size(); ++i) | |
dcheng
2016/05/10 20:33:41
for (int index : indices)
EhsanK
2016/05/11 01:54:03
Should I still use size_t or just plain int?
dcheng
2016/05/11 17:12:33
Ah, sorry, use the appropriate type.
EhsanK
2016/05/12 00:26:48
Acknowledged.
| |
405 current = ChildFrameAt(current, indices[i]); | |
406 return current; | |
407 } | |
408 }; | |
409 | |
410 // The following test loads a page with multiple nested <iframe> elements which | |
411 // are in or out of process with the main frame. Then an <input> field is added | |
412 // to every single frame on the frame tree where the input's value is distinctly | |
413 // selected for each frame. The test then creates a sequence of tab presses and | |
414 // verifies that after eahc key press, the right TextInputState is observed. | |
415 IN_PROC_BROWSER_TEST_F(TextInputInteractiveBrowserTest, | |
416 TrackStateWhenSwitchingFocusedFrames) { | |
417 CreateIframePage("a(a,b,c(a,b,d(e, f)),g)"); | |
418 std::vector<std::string> values({"main", "node_a", "node_b", "node_c", | |
419 "node_c_a", "node_c_b", "node_c_d", | |
420 "node_c_d_e", "node_c_d_f", "node_g"}); | |
421 std::vector<content::RenderFrameHost*> frames( | |
dcheng
2016/05/10 20:33:41
As far as I can tell, Google style is:
auto frames
EhsanK
2016/05/11 01:54:02
Done.
| |
422 {GetFrame({}), GetFrame({0}), GetFrame({1}), GetFrame({2}), | |
423 GetFrame({2, 0}), GetFrame({2, 1}), GetFrame({2, 2}), | |
424 GetFrame({2, 2, 0}), GetFrame({2, 2, 1}), GetFrame({3})}); | |
425 | |
426 for (size_t i = 0; i < frames.size(); ++i) | |
427 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
428 | |
429 for (size_t i = 0; i < frames.size(); ++i) { | |
430 TextInputManagerValueObserver observer(active_contents(), values[i]); | |
431 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, | |
432 false); | |
433 observer.Wait(); | |
434 } | |
435 } | |
436 | |
437 // The following test loads a page with two OOPIFs. An <input> is added to | |
438 // both frames and tab key is faked until the one in the second OOPIF is | |
439 // focused. Then, the renderer process for both frames are crashed. The test | |
440 // verifies that the TextInputManager stop tracking the RWHVs as well as | |
441 // properly resetting the TextInputState after the second (active) RWHV goes | |
442 // away. | |
443 IN_PROC_BROWSER_TEST_F(TextInputInteractiveBrowserTest, | |
444 StopTrackingCrashedChildFrame) { | |
445 CreateIframePage("a(b, c)"); | |
446 std::vector<std::string> values({"node_b", "node_c"}); | |
447 std::vector<content::RenderFrameHost*> frames({GetFrame({0}), GetFrame({1})}); | |
448 | |
449 for (size_t i = 0; i < frames.size(); ++i) | |
450 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
451 | |
452 for (size_t i = 0; i < frames.size(); ++i) { | |
453 TextInputManagerValueObserver observer(active_contents(), values[i]); | |
454 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, | |
455 false); | |
456 observer.Wait(); | |
457 } | |
458 | |
459 // Verify that we are tracking the TextInputState from the first frame. | |
460 content::RenderWidgetHostView* first_view = frames[0]->GetView(); | |
461 std::unordered_map<const content::RenderWidgetHostView*, ui::TextInputType> | |
462 type_map = content::TestTextInputManagerObserver::GetTextInputTypeMap( | |
463 active_contents()); | |
464 EXPECT_EQ(1UL, type_map.count(first_view)); | |
465 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, type_map[first_view]); | |
466 | |
467 // Now that the second frame's <input> is focused, we crash the first frame | |
468 // and observe that text input state is updated for the view. | |
469 std::unique_ptr<content::RenderWidgetHostViewDestructionObserver> | |
470 destruction_observer = | |
471 content::RenderWidgetHostViewDestructionObserver::Create(first_view); | |
472 frames[0]->GetProcess()->Shutdown(0, false); | |
473 destruction_observer->Wait(); | |
474 | |
475 // Verifying that the TextInputManager has smaller cleaned the memory | |
476 // allocated to the view. | |
477 type_map = content::TestTextInputManagerObserver::GetTextInputTypeMap( | |
478 active_contents()); | |
479 EXPECT_EQ(0UL, type_map.count(first_view)); | |
480 | |
481 // Now crash the second <iframe> which has an active view. | |
482 content::RenderWidgetHostView* second_view = frames[1]->GetView(); | |
483 TextInputManagerChangeObserver change_observer(active_contents()); | |
484 frames[1]->GetProcess()->Shutdown(0, false); | |
485 change_observer.Wait(); | |
486 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
487 content::GetTextInputTypeFromWebContents(active_contents())); | |
488 EXPECT_FALSE(!!content::GetActiveViewFromWebContents(active_contents())); | |
489 type_map = content::TestTextInputManagerObserver::GetTextInputTypeMap( | |
490 active_contents()); | |
491 EXPECT_EQ(0UL, type_map.count(second_view)); | |
492 } | |
493 | |
494 // The following test loads a page with two child frames; one in process and one | |
495 // out of process with main frame. The test inserts an <input> inside each frame | |
496 // and focuses the first frame and observes the TextInputManager setting the | |
497 // state to ui::TEXT_INPUT_TYPE_TEXT. Then, the frame is detached and the test | |
498 // observes that the state type is reset to ui::TEXT_INPUT_TYPE_NONE. The same | |
499 // sequence of actions is then performed on the out of process frame. | |
500 IN_PROC_BROWSER_TEST_F(TextInputInteractiveBrowserTest, | |
501 ResetStateAfterFrameDetached) { | |
502 CreateIframePage("a(a, b)"); | |
503 std::vector<content::RenderFrameHost*> frames({GetFrame({0}), GetFrame({1})}); | |
504 | |
505 for (size_t i = 0; i < frames.size(); ++i) | |
506 AddInputFieldToFrame(frames[i], "text", "", true); | |
507 | |
508 // Press tab key to focus the <input> in the first frame. | |
509 TextInputManagerTypeObserver type_observer_text_a(active_contents(), | |
510 ui::TEXT_INPUT_TYPE_TEXT); | |
511 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
512 type_observer_text_a.Wait(); | |
513 | |
514 // Detach first frame and observe |TextInputState.type| resetting to | |
515 // ui::TEXT_INPUT_TYPE_NONE. | |
516 TextInputManagerTypeObserver type_observer_none_a(active_contents(), | |
517 ui::TEXT_INPUT_TYPE_NONE); | |
518 EXPECT_TRUE(ExecuteScript( | |
519 frames[0], "document.body.removeChild(document.body.firstChild);")); | |
520 type_observer_none_a.Wait(); | |
521 | |
522 // Press tab to focus the <input> in the second frame. | |
523 TextInputManagerTypeObserver type_observer_text_b(active_contents(), | |
524 ui::TEXT_INPUT_TYPE_TEXT); | |
525 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
526 type_observer_text_b.Wait(); | |
527 | |
528 // Detach first frame and observe |TextInputState.type| resetting to | |
529 // ui::TEXT_INPUT_TYPE_NONE. | |
530 TextInputManagerTypeObserver type_observer_none_b(active_contents(), | |
531 ui::TEXT_INPUT_TYPE_NONE); | |
532 EXPECT_TRUE(ExecuteScript( | |
533 frames[1], "document.body.removeChild(document.body.firstChild);")); | |
534 type_observer_none_b.Wait(); | |
535 } | |
536 | |
537 // This test creates a page with one OOPIF and adds an <input> to it. Then, the | |
538 // <input> is focused and the test verfies that the |TextInputState.type| is set | |
539 // to ui::TEXT_INPUT_TYPE_TEXT. Next, the child frame is navigated away and the | |
540 // test verifies that |TextInputState.type| resets to ui::TEXT_INPUT_TYPE_NONE. | |
541 IN_PROC_BROWSER_TEST_F(TextInputInteractiveBrowserTest, | |
542 ResetStateAfterChildNavigation) { | |
543 CreateIframePage("a(b)"); | |
544 content::RenderFrameHost* main_frame = GetFrame({}); | |
545 content::RenderFrameHost* child_frame = GetFrame({0}); | |
546 | |
547 AddInputFieldToFrame(child_frame, "text", "child", false); | |
548 | |
549 // Focus <input> in child frame and verify the |TextInputState.value|. | |
550 TextInputManagerValueObserver child_set_state_observer(active_contents(), | |
551 "child"); | |
552 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
553 child_set_state_observer.Wait(); | |
554 | |
555 // Navigate the child frame to about:blank and verify that TextInputManager | |
556 // correctly sets its |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. | |
557 TextInputManagerTypeObserver child_reset_state_observer( | |
558 active_contents(), ui::TEXT_INPUT_TYPE_NONE); | |
559 EXPECT_TRUE(ExecuteScript( | |
560 main_frame, "document.querySelector('iframe').src = 'about:blank'")); | |
561 child_reset_state_observer.Wait(); | |
562 } | |
563 | |
564 // This test creates a blank page and adds an <input> to it. Then, the <input> | |
565 // is focused and the test verfies that the |TextInputState.type| is set to | |
566 // ui::TEXT_INPUT_TYPE_TEXT. Next, the browser is navigated away and the test | |
567 // verifies that |TextInputState.type| resets to ui::TEXT_INPUT_TYPE_NONE. | |
568 IN_PROC_BROWSER_TEST_F(TextInputInteractiveBrowserTest, | |
569 ResetStateAfterBrowserNavigation) { | |
570 CreateIframePage("a()"); | |
571 content::RenderFrameHost* main_frame = GetFrame({}); | |
572 AddInputFieldToFrame(main_frame, "text", "", false); | |
573 | |
574 TextInputManagerTypeObserver set_state_observer(active_contents(), | |
575 ui::TEXT_INPUT_TYPE_TEXT); | |
576 SimulateKeyPress(active_contents(), ui::VKEY_TAB, false, false, false, false); | |
577 set_state_observer.Wait(); | |
578 | |
579 TextInputManagerTypeObserver reset_state_observer(active_contents(), | |
580 ui::TEXT_INPUT_TYPE_NONE); | |
581 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
582 reset_state_observer.Wait(); | |
583 } | |
584 #endif // USE_AURA | |
585 | |
586 // TODO(ekaramad): The following tests are specifically written for Aura and are | |
587 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | |
588 // (crbug.com/602723). | |
589 #ifdef USE_AURA | |
590 // Observes current input method for state changes. | |
591 class InputMethodObserverBase { | |
592 public: | |
593 explicit InputMethodObserverBase(content::WebContents* web_contents) | |
594 : success_(false), | |
595 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { | |
596 } | |
597 | |
598 void Wait() { | |
599 if (success_) | |
600 return; | |
601 message_loop_runner_ = new content::MessageLoopRunner(); | |
602 message_loop_runner_->Run(); | |
603 } | |
604 | |
605 bool success() const { return success_; } | |
606 | |
607 protected: | |
608 content::TestInputMethodObserver* test_observer() { | |
609 return test_observer_.get(); | |
610 } | |
611 | |
612 const base::Closure success_closure() { | |
613 return base::Bind(&InputMethodObserverBase::OnSuccess, | |
614 base::Unretained(this)); | |
615 } | |
616 | |
617 private: | |
618 void OnSuccess() { | |
619 success_ = true; | |
620 if (message_loop_runner_ && message_loop_runner_->loop_running()) | |
621 message_loop_runner_->Quit(); | |
622 } | |
623 | |
624 bool success_; | |
625 std::unique_ptr<content::TestInputMethodObserver> test_observer_; | |
626 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
627 | |
628 DISALLOW_COPY_AND_ASSIGN(InputMethodObserverBase); | |
629 }; | |
630 | |
631 class InputMethodObserverForShowIme : public InputMethodObserverBase { | |
632 public: | |
633 explicit InputMethodObserverForShowIme(content::WebContents* web_contents) | |
634 : InputMethodObserverBase(web_contents) { | |
635 test_observer()->SetOnShowImeIfNeededCallback(success_closure()); | |
636 } | |
637 }; | |
638 | |
639 // This test verifies that the IME for Aura is shown if and only if the current | |
640 // client's |TextInputState.type| is not ui::TEXT_INPUT_TYPE_NONE and the flag | |
641 // |TextInputState.show_ime_if_needed| is true. This should happen even. | |
642 // TODO(ekaramad): This test is actually a unit test and should be moved to some | |
643 // place more appropriate. | |
644 IN_PROC_BROWSER_TEST_F(TextInputInteractiveBrowserTest, | |
645 CorrectlyShowImeIfNeeded) { | |
646 // We only need the <iframe> page to create RWHV. | |
647 CreateIframePage("a()"); | |
648 content::RenderFrameHost* main_frame = GetFrame({}); | |
649 content::RenderWidgetHostView* view = main_frame->GetView(); | |
650 content::WebContents* web_contents = active_contents(); | |
651 | |
652 content::TextInputStateSender sender(view); | |
653 | |
654 auto send_and_check_show_ime = [&sender, &web_contents]() { | |
655 InputMethodObserverForShowIme observer(web_contents); | |
656 sender.Send(); | |
657 return observer.success(); | |
658 }; | |
659 | |
660 // Sending an empty state should not trigger ime. | |
661 EXPECT_FALSE(send_and_check_show_ime()); | |
662 | |
663 // Set |TextInputState.type| to text. Expect no IME. | |
664 sender.SetType(ui::TEXT_INPUT_TYPE_TEXT); | |
665 EXPECT_FALSE(send_and_check_show_ime()); | |
666 | |
667 // Set |TextInputState.show_ime_if_needed| to true. Expect IME. | |
668 sender.SetShowImeIfNeeded(true); | |
669 EXPECT_TRUE(send_and_check_show_ime()); | |
670 | |
671 // Send the same message. Expect IME (no change). | |
672 EXPECT_TRUE(send_and_check_show_ime()); | |
673 | |
674 // Reset |TextInputState.show_ime_if_needed|. Expect no IME. | |
675 sender.SetShowImeIfNeeded(false); | |
676 EXPECT_FALSE(send_and_check_show_ime()); | |
677 | |
678 // Setting an irrelevant field. Expect no IME. | |
679 sender.SetMode(ui::TEXT_INPUT_MODE_LATIN); | |
680 EXPECT_FALSE(send_and_check_show_ime()); | |
681 | |
682 // Set |TextInputState.show_ime_if_needed|. Expect IME. | |
683 sender.SetShowImeIfNeeded(true); | |
684 EXPECT_TRUE(send_and_check_show_ime()); | |
685 | |
686 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | |
687 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | |
688 EXPECT_FALSE(send_and_check_show_ime()); | |
689 } | |
690 #endif // USE_AURA | |
OLD | NEW |