| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 bool MockInputMethod::HasComposition() { | 246 bool MockInputMethod::HasComposition() { |
| 247 return composition_.text.length() || result_text_.length(); | 247 return composition_.text.length() || result_text_.length(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void MockInputMethod::ClearComposition() { | 250 void MockInputMethod::ClearComposition() { |
| 251 composition_.Clear(); | 251 composition_.Clear(); |
| 252 result_text_.clear(); | 252 result_text_.clear(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults. | 255 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults. |
| 256 // After user event, the textfield sets cursor_enabled in RenderText to true. |
| 256 class TestTextfield : public views::Textfield { | 257 class TestTextfield : public views::Textfield { |
| 257 public: | 258 public: |
| 258 TestTextfield() | 259 TestTextfield() |
| 259 : Textfield(), | 260 : Textfield(), |
| 260 key_handled_(false), | 261 key_handled_(false), |
| 261 key_received_(false), | 262 key_received_(false), |
| 262 weak_ptr_factory_(this) {} | 263 weak_ptr_factory_(this) {} |
| 263 | 264 |
| 264 // ui::TextInputClient overrides: | 265 // ui::TextInputClient overrides: |
| 265 void InsertChar(const ui::KeyEvent& e) override { | 266 void InsertChar(const ui::KeyEvent& e) override { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // paste action did not change the content. So |new_contents| may match | 390 // paste action did not change the content. So |new_contents| may match |
| 390 // |last_contents_|. For more info, see http://crbug.com/79002 | 391 // |last_contents_|. For more info, see http://crbug.com/79002 |
| 391 last_contents_ = new_contents; | 392 last_contents_ = new_contents; |
| 392 } | 393 } |
| 393 | 394 |
| 394 void OnBeforeUserAction(Textfield* sender) override { | 395 void OnBeforeUserAction(Textfield* sender) override { |
| 395 ++on_before_user_action_; | 396 ++on_before_user_action_; |
| 396 } | 397 } |
| 397 | 398 |
| 398 void OnAfterUserAction(Textfield* sender) override { | 399 void OnAfterUserAction(Textfield* sender) override { |
| 400 textfield_->SetCursorEnabled(true); |
| 399 ++on_after_user_action_; | 401 ++on_after_user_action_; |
| 400 } | 402 } |
| 401 | 403 |
| 402 void OnAfterCutOrCopy(ui::ClipboardType clipboard_type) override { | 404 void OnAfterCutOrCopy(ui::ClipboardType clipboard_type) override { |
| 403 copied_to_clipboard_ = clipboard_type; | 405 copied_to_clipboard_ = clipboard_type; |
| 404 } | 406 } |
| 405 | 407 |
| 406 void InitTextfield() { | 408 void InitTextfield() { |
| 407 InitTextfields(1); | 409 InitTextfields(1); |
| 408 } | 410 } |
| (...skipping 2696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3105 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 3107 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 3106 ui::AXNodeData node_data_protected; | 3108 ui::AXNodeData node_data_protected; |
| 3107 node_data_protected.state = 0; | 3109 node_data_protected.state = 0; |
| 3108 textfield_->GetAccessibleNodeData(&node_data_protected); | 3110 textfield_->GetAccessibleNodeData(&node_data_protected); |
| 3109 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); | 3111 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); |
| 3110 EXPECT_EQ(ASCIIToUTF16("********"), | 3112 EXPECT_EQ(ASCIIToUTF16("********"), |
| 3111 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); | 3113 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); |
| 3112 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 3114 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 3113 } | 3115 } |
| 3114 | 3116 |
| 3115 // Test if the cursor visibility is controlled by |cursor_enabled_| in | 3117 // Verifies if the cursor visibility is controlled by |cursor_enabled_| in |
| 3116 // RenderText. | 3118 // RenderText. |
| 3117 TEST_F(TextfieldTest, CursorVisibility) { | 3119 TEST_F(TextfieldTest, CursorVisibility) { |
| 3118 InitTextfield(); | 3120 InitTextfield(); |
| 3119 gfx::RenderText* render_text = test_api_->GetRenderText(); | 3121 gfx::RenderText* render_text = test_api_->GetRenderText(); |
| 3120 | 3122 |
| 3121 render_text->SetCursorEnabled(false); | 3123 render_text->SetCursorEnabled(false); |
| 3122 textfield_->OnBlur(); | 3124 textfield_->OnBlur(); |
| 3123 textfield_->OnFocus(); | 3125 textfield_->OnFocus(); |
| 3124 EXPECT_FALSE(test_api_->IsCursorVisible()); | 3126 EXPECT_FALSE(test_api_->IsCursorVisible()); |
| 3125 | 3127 |
| 3126 render_text->SetCursorEnabled(true); | 3128 render_text->SetCursorEnabled(true); |
| 3127 textfield_->OnBlur(); | 3129 textfield_->OnBlur(); |
| 3128 textfield_->OnFocus(); | 3130 textfield_->OnFocus(); |
| 3129 EXPECT_TRUE(test_api_->IsCursorVisible()); | 3131 EXPECT_TRUE(test_api_->IsCursorVisible()); |
| 3130 } | 3132 } |
| 3131 | 3133 |
| 3134 // Verifies if the cursor visibility is changed to true from false after insert |
| 3135 // charactor in textfield. |
| 3136 TEST_F(TextfieldTest, CursorVisibilityChangeAfterInserting) { |
| 3137 InitTextfield(); |
| 3138 |
| 3139 test_api_->GetRenderText()->SetCursorEnabled(false); |
| 3140 textfield_->OnBlur(); |
| 3141 textfield_->OnFocus(); |
| 3142 EXPECT_FALSE(test_api_->IsCursorVisible()); |
| 3143 SendKeyEvent('a'); |
| 3144 EXPECT_TRUE(test_api_->IsCursorVisible()); |
| 3145 |
| 3146 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "abc"); |
| 3147 textfield_->SetText(base::string16()); |
| 3148 SendKeyEvent(ui::VKEY_V, false, true); |
| 3149 EXPECT_STR_EQ("abc", textfield_->text()); |
| 3150 EXPECT_TRUE(test_api_->IsCursorVisible()); |
| 3151 } |
| 3152 |
| 3153 // Verifies if the cursor visibility is changed to true from false after paste |
| 3154 // some text to the textfield. |
| 3155 TEST_F(TextfieldTest, CursorVisibilityChangeAfterPaste) { |
| 3156 InitTextfield(); |
| 3157 |
| 3158 test_api_->GetRenderText()->SetCursorEnabled(false); |
| 3159 textfield_->OnBlur(); |
| 3160 textfield_->OnFocus(); |
| 3161 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "abc"); |
| 3162 textfield_->SetText(base::string16()); |
| 3163 SendKeyEvent(ui::VKEY_V, false, true); |
| 3164 EXPECT_STR_EQ("abc", textfield_->text()); |
| 3165 EXPECT_TRUE(test_api_->IsCursorVisible()); |
| 3166 } |
| 3167 |
| 3132 } // namespace views | 3168 } // namespace views |
| OLD | NEW |