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

Side by Side Diff: content/public/test/text_input_test_utils.h

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: Added the missing test file 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
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 #ifndef CONTENT_PUBLIC_TEST_TEXT_INPUT_TEST_UTILS_H_
6 #define CONTENT_PUBLIC_TEST_TEXT_INPUT_TEST_UTILS_H_
7
8 #include <string>
9 #include <unordered_map>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "ui/base/ime/text_input_mode.h"
14 #include "ui/base/ime/text_input_type.h"
15
16 namespace content {
17
18 class RenderWidgetHostView;
19 class RenderWidgetHostViewBase;
20 class WebContents;
21 struct TextInputState;
22
23 // Returns the |TextInputState.type| from the TextInputManager owned by
24 // |web_contents|.
25 ui::TextInputType GetTextInputTypeFromWebContents(WebContents* web_contents);
26
27 // Returns the |TextInputState.type| for all the RenderWidgetHostViews tracked
28 // by the TextInputManager which is owned by Webcontents.
29 // This is not necessarily all the RenderWidgetHostViews on the page.
30 std::unordered_map<RenderWidgetHostView*, ui::TextInputType>
31 GetTextInputTypeMapFromWebContents(WebContents* web_contents);
32
33 // This class is intended to observe the TextInputManager owned by a given
34 // WebContents.
35 class TestTextInputManagerObserver {
36 public:
37 using Callback = base::Callback<void(TestTextInputManagerObserver*)>;
38
39 virtual ~TestTextInputManagerObserver();
40
41 // static
42 static std::unique_ptr<TestTextInputManagerObserver> Create(
43 WebContents* web_contents);
44
45 // Sets a callback which is invoked when a RWHV calls UpdateTextInputManager
46 // on the TextInputManager which is being observed.
47 virtual void SetUpdateTextInputStateCalledCallback(
48 const Callback& callback) = 0;
49
50 // Returns the current |TextInputState.type| for the TextInputManager which
51 // is being observed.
52 virtual ui::TextInputType GetTextInputType() const = 0;
53
54 // Returns true if there is a focused <input> and populates |value| with
55 // |TextInputState.value| of the TextInputManager.
56 virtual bool GetTextInputValue(std::string* value) const = 0;
57
58 // Returns the RenderWidgetHostView with a focused <input> element or nullptr
59 // if none exists.
60 virtual const RenderWidgetHostView* GetActiveView() const = 0;
61
62 // Returns the RenderWidgetHostView which has most recently called
63 // TextInputManager::UpdateTextInputState on the TextInputManager which is
64 // being observed.
65 virtual const RenderWidgetHostView* GetUpdatedView() const = 0;
EhsanK 2016/05/25 16:51:07 I missed these consts. I will remove them soon in
66
67 // Returns true if a call to TextInputManager::UpdateTextInputState has led
68 // to a change in TextInputState (since the time the observer has been
69 // created).
70 virtual bool IsTextInputStateChanged() const = 0;
71
72 protected:
73 TestTextInputManagerObserver();
74 };
75
76 class RenderWidgetHostViewDestructionObserver {
77 public:
78 virtual ~RenderWidgetHostViewDestructionObserver();
79 // static
80 static std::unique_ptr<RenderWidgetHostViewDestructionObserver> Create(
81 RenderWidgetHostView* view);
82
83 virtual void Wait() = 0;
84 };
85
86 RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents);
87
88 // Helper class to create TextInputState structs on the browser side and send it
89 // to the given RenderWidgetHostView. This class can be used for faking changes
90 // in TextInputState for testing on the browser side.
91 class TextInputStateSender {
92 public:
93 explicit TextInputStateSender(RenderWidgetHostView* view);
94 virtual ~TextInputStateSender();
95
96 void Send();
97
98 void SetFromCurrentState();
99
100 // The required setter methods. These setter methods can be used to call
101 // RenderWidgetHostViewBase::TextInputStateChanged with fake, customized
102 // TextInputState. Used for unit-testing on the browser side.
103 void SetType(ui::TextInputType type);
104 void SetMode(ui::TextInputMode mode);
105 void SetFlags(int flags);
106 void SetCanComposeInline(bool can_compose_inline);
107 void SetShowImeIfNeeded(bool show_ime_if_needed);
108 void SetIsNonImeChange(bool is_non_ime_change);
109
110 private:
111 std::unique_ptr<TextInputState> text_input_state_;
112 RenderWidgetHostViewBase* const view_;
113
114 DISALLOW_COPY_AND_ASSIGN(TextInputStateSender);
115 };
116
117 // This class is intended to observe the InputMethod.
118 class TestInputMethodObserver {
119 public:
120 // Creates and returns a platform specific implementation of an
121 // InputMethodObserver.
122 // static
123 static std::unique_ptr<TestInputMethodObserver> Create(
124 WebContents* web_contents);
125
126 virtual ~TestInputMethodObserver();
127
128 virtual ui::TextInputType GetTextInputTypeFromClient() const = 0;
129
130 virtual void SetOnTextInputTypeChangedCallback(
131 const base::Closure& callback) = 0;
132 virtual void SetOnShowImeIfNeededCallback(const base::Closure& callback) = 0;
133
134 protected:
135 TestInputMethodObserver();
136 };
137
138 } // namespace content
139
140 #endif // CONTENT_PUBLIC_TEST_TEXT_INPUT_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698