Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / input_method / textinput_test_helper.h
blob7013a0d4eba56f048f6ed9171542667535761ee2
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/range/range.h"
12 #include "ui/gfx/rect.h"
14 namespace content {
15 class WebContents;
16 } // namespace content
18 namespace chromeos {
20 // The base class of text input testing.
21 class TextInputTestBase : public InProcessBrowserTest {
22 public:
23 TextInputTestBase() {}
24 virtual ~TextInputTestBase() {}
26 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
27 private:
28 DISALLOW_COPY_AND_ASSIGN(TextInputTestBase);
31 // Provides text input test utilities.
32 class TextInputTestHelper : public ui::InputMethodObserver {
33 public:
34 TextInputTestHelper();
35 virtual ~TextInputTestHelper();
37 // Returns the latest status notified to ui::InputMethod
38 base::string16 GetSurroundingText() const;
39 gfx::Rect GetCaretRect() const;
40 gfx::Rect GetCompositionHead() const;
41 gfx::Range GetSelectionRange() const;
42 bool GetFocusState() const;
43 ui::TextInputType GetTextInputType() const;
45 ui::TextInputClient* GetTextInputClient() const;
47 // Waiting function for each input method events. These functions runs message
48 // loop until the expected event comes.
49 void WaitForTextInputStateChanged(ui::TextInputType expected_type);
50 void WaitForFocus();
51 void WaitForBlur();
52 void WaitForCaretBoundsChanged(const gfx::Rect& expected_caret_rect,
53 const gfx::Rect& expected_composition_head);
54 void WaitForSurroundingTextChanged(const base::string16& expected_text,
55 const gfx::Range& expected_selection);
57 // Converts from string to gfx::Rect. The string should be "x,y,width,height".
58 // Returns false if the conversion failed.
59 static bool ConvertRectFromString(const std::string& str, gfx::Rect* rect);
61 // Sends mouse clicking event to DOM element which has |id| id.
62 static bool ClickElement(const std::string& id, content::WebContents* tab);
64 private:
65 enum WaitImeEventType {
66 NO_WAIT,
67 WAIT_ON_BLUR,
68 WAIT_ON_CARET_BOUNDS_CHANGED,
69 WAIT_ON_FOCUS,
70 WAIT_ON_TEXT_INPUT_TYPE_CHANGED,
73 // ui::InputMethodObserver overrides.
74 virtual void OnTextInputTypeChanged(
75 const ui::TextInputClient* client) OVERRIDE;
76 virtual void OnFocus() OVERRIDE;
77 virtual void OnBlur() OVERRIDE;
78 virtual void OnCaretBoundsChanged(const ui::TextInputClient* client) OVERRIDE;
79 virtual void OnTextInputStateChanged(
80 const ui::TextInputClient* client) OVERRIDE;
81 virtual void OnInputMethodDestroyed(
82 const ui::InputMethod* input_method) OVERRIDE;
84 // Represents waiting type of text input event.
85 WaitImeEventType waiting_type_;
87 base::string16 surrounding_text_;
88 gfx::Rect caret_rect_;
89 gfx::Rect composition_head_;
90 gfx::Range selection_range_;
91 bool focus_state_;
92 ui::TextInputType latest_text_input_type_;
94 DISALLOW_COPY_AND_ASSIGN(TextInputTestHelper);
97 } // namespace chromeos
99 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_TEXTINPUT_TEST_HELPER_H_