| Index: ui/views/controls/textfield/textfield_unittest.cc
|
| diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc
|
| index affd8dc47159c6d0273660df2bac6fd74e2163d5..e5570f2f0281de4f3d9ab51abf24cc0258e105d6 100644
|
| --- a/ui/views/controls/textfield/textfield_unittest.cc
|
| +++ b/ui/views/controls/textfield/textfield_unittest.cc
|
| @@ -256,62 +256,6 @@ void MockInputMethod::ClearComposition() {
|
| result_text_.clear();
|
| }
|
|
|
| -// A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults.
|
| -class TestTextfield : public views::Textfield {
|
| - public:
|
| - TestTextfield()
|
| - : Textfield(),
|
| - key_handled_(false),
|
| - key_received_(false),
|
| - weak_ptr_factory_(this) {}
|
| -
|
| - bool OnKeyPressed(const ui::KeyEvent& e) override {
|
| - key_received_ = true;
|
| -
|
| - // Since OnKeyPressed() might destroy |this|, get a weak pointer and
|
| - // verify it isn't null before writing the bool value to key_handled_.
|
| - base::WeakPtr<TestTextfield> textfield(weak_ptr_factory_.GetWeakPtr());
|
| - bool key = views::Textfield::OnKeyPressed(e);
|
| -
|
| - if (!textfield)
|
| - return key;
|
| -
|
| - key_handled_ = key;
|
| -
|
| - return key_handled_;
|
| - }
|
| -
|
| - bool OnKeyReleased(const ui::KeyEvent& e) override {
|
| - key_received_ = true;
|
| - key_handled_ = views::Textfield::OnKeyReleased(e);
|
| - EXPECT_FALSE(key_handled_); // Textfield doesn't override OnKeyReleased.
|
| - return key_handled_;
|
| - }
|
| -
|
| - // ui::TextInputClient overrides:
|
| - void InsertChar(const ui::KeyEvent& e) override {
|
| - views::Textfield::InsertChar(e);
|
| -#if defined(OS_MACOSX)
|
| - // On Mac, characters are inserted directly rather than attempting to get a
|
| - // unicode character from the ui::KeyEvent (which isn't always possible).
|
| - key_received_ = true;
|
| -#endif
|
| - }
|
| -
|
| - bool key_handled() const { return key_handled_; }
|
| - bool key_received() const { return key_received_; }
|
| -
|
| - void clear() { key_received_ = key_handled_ = false; }
|
| -
|
| - private:
|
| - bool key_handled_;
|
| - bool key_received_;
|
| -
|
| - base::WeakPtrFactory<TestTextfield> weak_ptr_factory_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(TestTextfield);
|
| -};
|
| -
|
| // Convenience to make constructing a GestureEvent simpler.
|
| class GestureEventForTest : public ui::GestureEvent {
|
| public:
|
| @@ -360,6 +304,64 @@ void SetClipboardText(ui::ClipboardType type, const std::string& text) {
|
|
|
| namespace views {
|
|
|
| +// A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults.
|
| +class TestTextfield : public views::Textfield {
|
| + public:
|
| + TestTextfield()
|
| + : Textfield(),
|
| + key_handled_(false),
|
| + key_received_(false),
|
| + weak_ptr_factory_(this) {}
|
| +
|
| + // ui::TextInputClient overrides:
|
| + void InsertChar(const ui::KeyEvent& e) override {
|
| + views::Textfield::InsertChar(e);
|
| +#if defined(OS_MACOSX)
|
| + // On Mac, characters are inserted directly rather than attempting to get a
|
| + // unicode character from the ui::KeyEvent (which isn't always possible).
|
| + key_received_ = true;
|
| +#endif
|
| + }
|
| +
|
| + bool key_handled() const { return key_handled_; }
|
| + bool key_received() const { return key_received_; }
|
| +
|
| + void clear() { key_received_ = key_handled_ = false; }
|
| +
|
| + private:
|
| + bool OnKeyPressed(const ui::KeyEvent& e) override {
|
| + key_received_ = true;
|
| +
|
| + // Since OnKeyPressed() might destroy |this|, get a weak pointer and
|
| + // verify it isn't null before writing the bool value to key_handled_.
|
| + base::WeakPtr<TestTextfield> textfield(weak_ptr_factory_.GetWeakPtr());
|
| + bool key = views::Textfield::OnKeyPressed(e);
|
| +
|
| + if (!textfield)
|
| + return key;
|
| +
|
| + key_handled_ = key;
|
| +
|
| + return key_handled_;
|
| + }
|
| +
|
| + bool OnKeyReleased(const ui::KeyEvent& e) override {
|
| + key_received_ = true;
|
| + key_handled_ = views::Textfield::OnKeyReleased(e);
|
| +
|
| + // Currently Textfield::OnKeyReleased always returns false.
|
| + EXPECT_FALSE(key_handled_);
|
| + return key_handled_;
|
| + }
|
| +
|
| + bool key_handled_;
|
| + bool key_received_;
|
| +
|
| + base::WeakPtrFactory<TestTextfield> weak_ptr_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestTextfield);
|
| +};
|
| +
|
| class TextfieldTest : public ViewsTestBase, public TextfieldController {
|
| public:
|
| TextfieldTest()
|
|
|