• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_TEXTINPUT_TEST_HELPER_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_TEXTINPUT_TEST_HELPER_H_
7 
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"
13 
14 namespace content {
15 class WebContents;
16 }  // namespace content
17 
18 namespace chromeos {
19 
20 // The base class of text input testing.
21 class TextInputTestBase : public InProcessBrowserTest {
22  public:
TextInputTestBase()23   TextInputTestBase() {}
~TextInputTestBase()24   virtual ~TextInputTestBase() {}
25 
26   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
27  private:
28   DISALLOW_COPY_AND_ASSIGN(TextInputTestBase);
29 };
30 
31 // Provides text input test utilities.
32 class TextInputTestHelper : public ui::InputMethodObserver {
33  public:
34   TextInputTestHelper();
35   virtual ~TextInputTestHelper();
36 
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;
44 
45   ui::TextInputClient* GetTextInputClient() const;
46 
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);
56 
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);
60 
61   // Sends mouse clicking event to DOM element which has |id| id.
62   static bool ClickElement(const std::string& id, content::WebContents* tab);
63 
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,
71   };
72 
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 OnShowImeIfNeeded() OVERRIDE;
82   virtual void OnInputMethodDestroyed(
83       const ui::InputMethod* input_method) OVERRIDE;
84 
85   // Represents waiting type of text input event.
86   WaitImeEventType waiting_type_;
87 
88   base::string16 surrounding_text_;
89   gfx::Rect caret_rect_;
90   gfx::Rect composition_head_;
91   gfx::Range selection_range_;
92   bool focus_state_;
93   ui::TextInputType latest_text_input_type_;
94 
95   DISALLOW_COPY_AND_ASSIGN(TextInputTestHelper);
96 };
97 
98 } // namespace chromeos
99 
100 #endif  // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_TEXTINPUT_TEST_HELPER_H_
101