Index: content/public/test/text_input_test_utils.h |
diff --git a/content/public/test/text_input_test_utils.h b/content/public/test/text_input_test_utils.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..478ef44bdb09dd5181e04a33a0667e19a8861ab6 |
--- /dev/null |
+++ b/content/public/test/text_input_test_utils.h |
@@ -0,0 +1,140 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_PUBLIC_TEST_TEXT_INPUT_TEST_UTILS_H_ |
+#define CONTENT_PUBLIC_TEST_TEXT_INPUT_TEST_UTILS_H_ |
+ |
+#include <string> |
+#include <unordered_map> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "ui/base/ime/text_input_mode.h" |
+#include "ui/base/ime/text_input_type.h" |
+ |
+namespace content { |
+ |
+class RenderWidgetHostView; |
+class RenderWidgetHostViewBase; |
+class WebContents; |
+struct TextInputState; |
+ |
+// Returns the |TextInputState.type| from the TextInputManager owned by |
+// |web_contents|. |
+ui::TextInputType GetTextInputTypeFromWebContents(WebContents* web_contents); |
+ |
+// Returns the |TextInputState.type| for all the RenderWidgetHostViews tracked |
+// by the TextInputManager which is owned by Webcontents. |
+// This is not necessarily all the RenderWidgetHostViews on the page. |
+std::unordered_map<RenderWidgetHostView*, ui::TextInputType> |
+GetTextInputTypeMapFromWebContents(WebContents* web_contents); |
+ |
+// This class is intended to observe the TextInputManager owned by a given |
+// WebContents. |
+class TestTextInputManagerObserver { |
+ public: |
+ using Callback = base::Callback<void(TestTextInputManagerObserver*)>; |
+ |
+ virtual ~TestTextInputManagerObserver(); |
+ |
+ // static |
+ static std::unique_ptr<TestTextInputManagerObserver> Create( |
+ WebContents* web_contents); |
+ |
+ // Sets a callback which is invoked when a RWHV calls UpdateTextInputManager |
Charlie Reis
2016/05/26 06:22:05
UpdateTextInputState?
EhsanK
2016/05/30 15:06:09
Acknowledged.
|
+ // on the TextInputManager which is being observed. |
+ virtual void SetUpdateTextInputStateCalledCallback( |
+ const Callback& callback) = 0; |
+ |
+ // Returns the current |TextInputState.type| for the TextInputManager which |
+ // is being observed. |
+ virtual ui::TextInputType GetTextInputType() = 0; |
+ |
+ // Returns true if there is a focused <input> and populates |value| with |
+ // |TextInputState.value| of the TextInputManager. |
+ virtual bool GetTextInputValue(std::string* value) = 0; |
+ |
+ // Returns the RenderWidgetHostView with a focused <input> element or nullptr |
+ // if none exists. |
+ virtual const RenderWidgetHostView* GetActiveView() = 0; |
+ |
+ // Returns the RenderWidgetHostView which has most recently called |
+ // TextInputManager::UpdateTextInputState on the TextInputManager which is |
+ // being observed. |
+ virtual const RenderWidgetHostView* GetUpdatedView() = 0; |
+ |
+ // Returns true if a call to TextInputManager::UpdateTextInputState has led |
+ // to a change in TextInputState (since the time the observer has been |
+ // created). |
+ virtual bool IsTextInputStateChanged() = 0; |
+ |
+ protected: |
+ TestTextInputManagerObserver(); |
+}; |
+ |
+class RenderWidgetHostViewDestructionObserver { |
Charlie Reis
2016/05/26 06:22:05
nit: Add comment. (This is a requirement for publ
EhsanK
2016/05/30 15:06:09
Acknowledged.
|
+ public: |
+ virtual ~RenderWidgetHostViewDestructionObserver(); |
+ // static |
+ static std::unique_ptr<RenderWidgetHostViewDestructionObserver> Create( |
+ RenderWidgetHostView* view); |
+ |
+ virtual void Wait() = 0; |
+}; |
+ |
+RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents); |
Charlie Reis
2016/05/26 06:22:05
nit: Add comment, and maybe move up with the other
EhsanK
2016/05/30 15:06:09
Acknowledged.
|
+ |
+// Helper class to create TextInputState structs on the browser side and send it |
+// to the given RenderWidgetHostView. This class can be used for faking changes |
+// in TextInputState for testing on the browser side. |
+class TextInputStateSender { |
+ public: |
+ explicit TextInputStateSender(RenderWidgetHostView* view); |
+ virtual ~TextInputStateSender(); |
+ |
+ void Send(); |
+ |
+ void SetFromCurrentState(); |
+ |
+ // The required setter methods. These setter methods can be used to call |
+ // RenderWidgetHostViewBase::TextInputStateChanged with fake, customized |
+ // TextInputState. Used for unit-testing on the browser side. |
+ void SetType(ui::TextInputType type); |
+ void SetMode(ui::TextInputMode mode); |
+ void SetFlags(int flags); |
+ void SetCanComposeInline(bool can_compose_inline); |
+ void SetShowImeIfNeeded(bool show_ime_if_needed); |
+ void SetIsNonImeChange(bool is_non_ime_change); |
+ |
+ private: |
+ std::unique_ptr<TextInputState> text_input_state_; |
+ RenderWidgetHostViewBase* const view_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TextInputStateSender); |
+}; |
+ |
+// This class is intended to observe the InputMethod. |
+class TestInputMethodObserver { |
+ public: |
+ // Creates and returns a platform specific implementation of an |
+ // InputMethodObserver. |
+ // static |
Charlie Reis
2016/05/26 06:22:05
nit: Move static comment above the real comment, a
EhsanK
2016/05/30 15:06:09
Acknowledged.
|
+ static std::unique_ptr<TestInputMethodObserver> Create( |
+ WebContents* web_contents); |
+ |
+ virtual ~TestInputMethodObserver(); |
+ |
+ virtual ui::TextInputType GetTextInputTypeFromClient() const = 0; |
Charlie Reis
2016/05/26 06:22:05
No const.
EhsanK
2016/05/30 15:06:09
Done.
|
+ |
+ virtual void SetOnTextInputTypeChangedCallback( |
+ const base::Closure& callback) = 0; |
+ virtual void SetOnShowImeIfNeededCallback(const base::Closure& callback) = 0; |
+ |
+ protected: |
+ TestInputMethodObserver(); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_PUBLIC_TEST_TEXT_INPUT_TEST_UTILS_H_ |