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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_TEXTINPUT_TEST_HELPER_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_TEXTINPUT_TEST_HELPER_H_
8 #include "chrome/test/base/in_process_browser_test.h"
9 #include "ui/base/ime/mock_input_method.h"
10 #include "ui/base/ime/text_input_client.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/range/range.h"
16 } // namespace content
20 // The base class of text input testing.
21 class TextInputTestBase
: public InProcessBrowserTest
{
23 TextInputTestBase() {}
24 ~TextInputTestBase() override
{}
26 void SetUpInProcessBrowserTestFixture() override
;
29 DISALLOW_COPY_AND_ASSIGN(TextInputTestBase
);
32 // Provides text input test utilities.
33 class TextInputTestHelper
: public ui::InputMethodObserver
{
35 TextInputTestHelper();
36 ~TextInputTestHelper() override
;
38 // Returns the latest status notified to ui::InputMethod
39 base::string16
GetSurroundingText() const;
40 gfx::Rect
GetCaretRect() const;
41 gfx::Rect
GetCompositionHead() const;
42 gfx::Range
GetSelectionRange() const;
43 bool GetFocusState() const;
44 ui::TextInputType
GetTextInputType() const;
46 ui::TextInputClient
* GetTextInputClient() const;
48 // Waiting function for each input method events. These functions runs message
49 // loop until the expected event comes.
50 void WaitForTextInputStateChanged(ui::TextInputType expected_type
);
53 void WaitForCaretBoundsChanged(const gfx::Rect
& expected_caret_rect
,
54 const gfx::Rect
& expected_composition_head
);
55 void WaitForSurroundingTextChanged(const base::string16
& expected_text
,
56 const gfx::Range
& expected_selection
);
58 // Converts from string to gfx::Rect. The string should be "x,y,width,height".
59 // Returns false if the conversion failed.
60 static bool ConvertRectFromString(const std::string
& str
, gfx::Rect
* rect
);
62 // Sends mouse clicking event to DOM element which has |id| id.
63 static bool ClickElement(const std::string
& id
, content::WebContents
* tab
);
66 enum WaitImeEventType
{
69 WAIT_ON_CARET_BOUNDS_CHANGED
,
71 WAIT_ON_TEXT_INPUT_TYPE_CHANGED
,
74 // ui::InputMethodObserver overrides.
75 void OnTextInputTypeChanged(const ui::TextInputClient
* client
) override
;
76 void OnFocus() override
;
77 void OnBlur() override
;
78 void OnCaretBoundsChanged(const ui::TextInputClient
* client
) override
;
79 void OnTextInputStateChanged(const ui::TextInputClient
* client
) override
;
80 void OnShowImeIfNeeded() override
;
81 void OnInputMethodDestroyed(const ui::InputMethod
* input_method
) override
;
83 // Represents waiting type of text input event.
84 WaitImeEventType waiting_type_
;
86 base::string16 surrounding_text_
;
87 gfx::Rect caret_rect_
;
88 gfx::Rect composition_head_
;
89 gfx::Range selection_range_
;
91 ui::TextInputType latest_text_input_type_
;
93 DISALLOW_COPY_AND_ASSIGN(TextInputTestHelper
);
96 } // namespace chromeos
98 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_TEXTINPUT_TEST_HELPER_H_