Chromium Code Reviews| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 245 |
| 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. |
|
msw
2017/03/09 21:05:45
optional nit: please fix the spelling of 'results'
yiyix
2017/03/10 20:19:29
Sorry, I missed this.
| |
| 256 // After user event, the textfield sets cursor_enabled in RenderText to true. | |
|
msw
2017/03/09 21:05:46
Move this comment to OnAfterUserAction and explain
yiyix
2017/03/10 20:19:29
As explained below, I can remove this comment now.
| |
| 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); | |
|
msw
2017/03/09 21:05:46
What is the motivation for this change? I'm not su
yiyix
2017/03/10 20:19:29
I don't need this line now. I added this line to t
| |
| 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); |
|
msw
2017/03/09 21:05:46
Should this call textfield_->SetCursorEnabled(fals
yiyix
2017/03/10 20:19:30
Done.
| |
| 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); |
|
msw
2017/03/09 21:05:46
Similarly, should this call textfield_->SetCursorE
yiyix
2017/03/10 20:19:29
In the approach I had before, the the cursor visib
| |
| 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 | |
|
msw
2017/03/09 21:05:46
nit: 'inserting'
yiyix
2017/03/10 20:19:29
Done.
| |
| 3135 // charactor in textfield. | |
|
msw
2017/03/09 21:05:46
nit: 'a character in the textfield'.
yiyix
2017/03/10 20:19:29
Done.
| |
| 3136 TEST_F(TextfieldTest, CursorVisibilityChangeAfterInserting) { | |
| 3137 InitTextfield(); | |
| 3138 | |
| 3139 test_api_->GetRenderText()->SetCursorEnabled(false); | |
|
msw
2017/03/09 21:05:46
Ditto: Should this call textfield_->SetCursorEnabl
| |
| 3140 textfield_->OnBlur(); | |
| 3141 textfield_->OnFocus(); | |
| 3142 EXPECT_FALSE(test_api_->IsCursorVisible()); | |
| 3143 SendKeyEvent('a'); | |
|
msw
2017/03/09 21:05:46
Why should inserting a character make the cursor v
yiyix
2017/03/10 20:19:29
I will remove this test case and add some new test
| |
| 3144 EXPECT_TRUE(test_api_->IsCursorVisible()); | |
| 3145 } | |
| 3146 | |
| 3147 // Verifies if the cursor visibility is changed to true from false after paste | |
|
msw
2017/03/09 21:05:46
nit: 'pasting'
yiyix
2017/03/10 20:19:30
Done.
| |
| 3148 // some text to the textfield. | |
| 3149 TEST_F(TextfieldTest, CursorVisibilityChangeAfterPaste) { | |
| 3150 InitTextfield(); | |
| 3151 | |
| 3152 test_api_->GetRenderText()->SetCursorEnabled(false); | |
|
msw
2017/03/09 21:05:46
ditto
| |
| 3153 textfield_->OnBlur(); | |
| 3154 textfield_->OnFocus(); | |
| 3155 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "abc"); | |
| 3156 textfield_->SetText(base::string16()); | |
|
msw
2017/03/09 21:05:45
Is this needed?
| |
| 3157 SendKeyEvent(ui::VKEY_V, false, true); | |
|
msw
2017/03/09 21:05:46
Ditto, can we test the omnibox instead?
yiyix
2017/03/10 20:19:30
I added a new test case in omnibox.
| |
| 3158 EXPECT_STR_EQ("abc", textfield_->text()); | |
| 3159 EXPECT_TRUE(test_api_->IsCursorVisible()); | |
| 3160 } | |
| 3161 | |
| 3132 } // namespace views | 3162 } // namespace views |
| OLD | NEW |