Chromium Code Reviews| Index: content/public/test/text_input_test_utils.cc |
| diff --git a/content/public/test/text_input_test_utils.cc b/content/public/test/text_input_test_utils.cc |
| index ed3e7483070dd4393ea62bfc5c8fa6e7fcfa2068..f38dbea33f58094640cb4b9c1b92f1b015237147 100644 |
| --- a/content/public/test/text_input_test_utils.cc |
| +++ b/content/public/test/text_input_test_utils.cc |
| @@ -13,6 +13,7 @@ |
| #include "content/browser/renderer_host/text_input_manager.h" |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/common/text_input_state.h" |
| +#include "content/common/view_messages.h" |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_observer.h" |
| @@ -26,6 +27,12 @@ class TextInputClient; |
| namespace content { |
| +namespace { |
| +void DefaultTextInputManagerObserverCallback(TextInputManagerTester* tester) {} |
| +TextInputManagerTester::Callback default_text_input_manager_observer_callback = |
| + base::Bind(&DefaultTextInputManagerObserverCallback); |
|
Charlie Reis
2016/06/29 20:18:37
We should not be adding new statically allocated o
EhsanK
2016/06/30 00:24:45
I understand.
In initial patches of TextInputMana
Charlie Reis
2016/06/30 20:27:21
I don't remember the objections to that approach,
EhsanK
2016/06/30 21:01:14
In that sense, I think it might look more readable
|
| +} // namespace |
| + |
| // This class is an observer of TextInputManager associated with the provided |
| // WebContents. An instance of this class is used in TextInputManagerTester to |
| // expose the required API for testing outside of content/. |
| @@ -37,7 +44,11 @@ class TextInputManagerTester::InternalObserver |
| : WebContentsObserver(web_contents), |
| tester_(tester), |
| updated_view_(nullptr), |
| - text_input_state_changed_(false) { |
| + text_input_state_changed_(false), |
| + update_text_input_state_callback_( |
| + default_text_input_manager_observer_callback), |
| + on_selection_bounds_changed_callback_( |
| + default_text_input_manager_observer_callback) { |
| text_input_manager_ = |
| static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); |
| DCHECK(!!text_input_manager_); |
| @@ -54,6 +65,11 @@ class TextInputManagerTester::InternalObserver |
| update_text_input_state_callback_ = callback; |
| } |
| + void set_on_selection_bounds_changed_callback( |
| + const TextInputManagerTester::Callback& callback) { |
| + on_selection_bounds_changed_callback_ = callback; |
| + } |
| + |
| const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } |
| bool text_input_state_changed() const { return text_input_state_changed_; } |
| @@ -71,6 +87,13 @@ class TextInputManagerTester::InternalObserver |
| update_text_input_state_callback_.Run(tester_); |
| } |
| + void OnSelectionBoundsChanged( |
| + TextInputManager* text_input_manager_, |
| + RenderWidgetHostViewBase* updated_view) override { |
| + updated_view_ = updated_view; |
| + on_selection_bounds_changed_callback_.Run(tester_); |
| + } |
| + |
| // WebContentsObserver implementation. |
| void WebContentsDestroyed() override { text_input_manager_ = nullptr; } |
| @@ -80,6 +103,7 @@ class TextInputManagerTester::InternalObserver |
| RenderWidgetHostViewBase* updated_view_; |
| bool text_input_state_changed_; |
| TextInputManagerTester::Callback update_text_input_state_callback_; |
| + TextInputManagerTester::Callback on_selection_bounds_changed_callback_; |
| DISALLOW_COPY_AND_ASSIGN(InternalObserver); |
| }; |
| @@ -226,6 +250,11 @@ void TextInputManagerTester::SetUpdateTextInputStateCalledCallback( |
| observer_->set_update_text_input_state_called_callback(callback); |
| } |
| +void TextInputManagerTester::SetOnSelectionBoundsChangedCallback( |
| + const Callback& callback) { |
| + observer_->set_on_selection_bounds_changed_callback(callback); |
| +} |
| + |
| bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { |
| DCHECK(observer_->text_input_manager()); |
| const TextInputState* state = |