Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc

Issue 1948343002: [reland] Browser Side Text Input State Tracking for OOPIF (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing sky@ comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
sky 2016/06/07 19:44:45 nit: remove newline.
EhsanK 2016/06/08 14:24:28 Done.
25 #include "url/gurl.h"
26
27 // TODO(ekaramad): The following tests are only active on aura platforms. After
28 // fixing crbug.com/578168 for all platforms, the following tests should be
29 // activated for other platforms, e.g., Mac and Android (crbug.com/602723).
30
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
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_;
sky 2016/06/07 19:44:45 nit const
EhsanK 2016/06/08 14:24:28 Done.
105 };
sky 2016/06/07 19:44:44 nit: DISALLOW...
EhsanK 2016/06/08 14:24:28 Done.
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_;
sky 2016/06/07 19:44:45 const and DISALLOW...
EhsanK 2016/06/08 14:24:27 Done.
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 };
sky 2016/06/07 19:44:45 DISALLOW..
EhsanK 2016/06/08 14:24:27 Done.
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_;
sky 2016/06/07 19:44:44 const and DISALLOW
EhsanK 2016/06/08 14:24:27 Done.
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>;
sky 2016/06/07 19:44:45 nit: vector -> Vector
EhsanK 2016/06/08 14:24:27 Acknowledged.
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>;
sky 2016/06/07 19:44:45 Vector. And as you have this in each test put it a
EhsanK 2016/06/08 14:24:28 Acknowledged.
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
441 // TODO(ekaramad): The following tests are specifically written for Aura and are
442 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
443 // (crbug.com/602723).
444
445 // Observes current input method for state changes.
446 class InputMethodObserverBase {
447 public:
448 explicit InputMethodObserverBase(content::WebContents* web_contents)
449 : success_(false),
450 test_observer_(content::TestInputMethodObserver::Create(web_contents)) {
451 }
452
453 void Wait() {
454 if (success_)
455 return;
456 message_loop_runner_ = new content::MessageLoopRunner();
457 message_loop_runner_->Run();
458 }
459
460 bool success() const { return success_; }
461
462 protected:
463 content::TestInputMethodObserver* test_observer() {
464 return test_observer_.get();
465 }
466
467 const base::Closure success_closure() {
468 return base::Bind(&InputMethodObserverBase::OnSuccess,
469 base::Unretained(this));
470 }
471
472 private:
473 void OnSuccess() {
474 success_ = true;
475 if (message_loop_runner_)
476 message_loop_runner_->Quit();
477 }
478
479 bool success_;
480 std::unique_ptr<content::TestInputMethodObserver> test_observer_;
481 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
482
483 DISALLOW_COPY_AND_ASSIGN(InputMethodObserverBase);
484 };
485
486 class InputMethodObserverForShowIme : public InputMethodObserverBase {
487 public:
488 explicit InputMethodObserverForShowIme(content::WebContents* web_contents)
489 : InputMethodObserverBase(web_contents) {
490 test_observer()->SetOnShowImeIfNeededCallback(success_closure());
491 }
492 };
sky 2016/06/07 19:44:45 private: DISALLOW..
EhsanK 2016/06/08 14:24:27 Done.
493
494 // This test verifies that the IME for Aura is shown if and only if the current
495 // client's |TextInputState.type| is not ui::TEXT_INPUT_TYPE_NONE and the flag
496 // |TextInputState.show_ime_if_needed| is true. This should happen even when
497 // the TextInputState has not changed (according to the platform), e.g., in
498 // aura when receiving two consecutive updates with same |TextInputState.type|.
499 // TODO(ekaramad): This test is actually a unit test not necessarily an OOPIF
500 // test. We should move it to somewhere more relevant.
501 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
502 CorrectlyShowImeIfNeeded) {
503 // We only need the <iframe> page to create RWHV.
504 CreateIframePage("a()");
505 content::RenderFrameHost* main_frame = GetFrame(std::vector<size_t>{});
506 content::RenderWidgetHostView* view = main_frame->GetView();
507 content::WebContents* web_contents = active_contents();
508
509 content::TextInputStateSender sender(view);
510
511 auto send_and_check_show_ime = [&sender, &web_contents]() {
512 InputMethodObserverForShowIme observer(web_contents);
513 sender.Send();
514 return observer.success();
515 };
516
517 // Sending an empty state should not trigger ime.
518 EXPECT_FALSE(send_and_check_show_ime());
519
520 // Set |TextInputState.type| to text. Expect no IME.
521 sender.SetType(ui::TEXT_INPUT_TYPE_TEXT);
522 EXPECT_FALSE(send_and_check_show_ime());
523
524 // Set |TextInputState.show_ime_if_needed| to true. Expect IME.
525 sender.SetShowImeIfNeeded(true);
526 EXPECT_TRUE(send_and_check_show_ime());
527
528 // Send the same message. Expect IME (no change).
529 EXPECT_TRUE(send_and_check_show_ime());
530
531 // Reset |TextInputState.show_ime_if_needed|. Expect no IME.
532 sender.SetShowImeIfNeeded(false);
533 EXPECT_FALSE(send_and_check_show_ime());
534
535 // Setting an irrelevant field. Expect no IME.
536 sender.SetMode(ui::TEXT_INPUT_MODE_LATIN);
537 EXPECT_FALSE(send_and_check_show_ime());
538
539 // Set |TextInputState.show_ime_if_needed|. Expect IME.
540 sender.SetShowImeIfNeeded(true);
541 EXPECT_TRUE(send_and_check_show_ime());
542
543 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
544 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
545 EXPECT_FALSE(send_and_check_show_ime());
546 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698