| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/clipboard/clipboard.h" | 14 #include "ui/base/clipboard/clipboard.h" |
| 15 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 15 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 16 #include "ui/base/dragdrop/drag_drop_types.h" | 16 #include "ui/base/dragdrop/drag_drop_types.h" |
| 17 #include "ui/base/keycodes/keyboard_codes.h" | 17 #include "ui/base/keycodes/keyboard_codes.h" |
| 18 #include "ui/gfx/render_text.h" |
| 18 #include "views/controls/textfield/native_textfield_views.h" | 19 #include "views/controls/textfield/native_textfield_views.h" |
| 19 #include "views/controls/textfield/textfield.h" | 20 #include "views/controls/textfield/textfield.h" |
| 20 #include "views/controls/textfield/textfield_controller.h" | 21 #include "views/controls/textfield/textfield_controller.h" |
| 21 #include "views/controls/textfield/textfield_views_model.h" | 22 #include "views/controls/textfield/textfield_views_model.h" |
| 22 #include "views/events/event.h" | 23 #include "views/events/event.h" |
| 23 #include "views/focus/focus_manager.h" | 24 #include "views/focus/focus_manager.h" |
| 24 #include "views/ime/mock_input_method.h" | 25 #include "views/ime/mock_input_method.h" |
| 25 #include "views/ime/text_input_client.h" | 26 #include "views/ime/text_input_client.h" |
| 26 #include "views/test/test_views_delegate.h" | 27 #include "views/test/test_views_delegate.h" |
| 27 #include "views/test/views_test_base.h" | 28 #include "views/test/views_test_base.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 212 |
| 212 void SendKeyEvent(ui::KeyboardCode key_code) { | 213 void SendKeyEvent(ui::KeyboardCode key_code) { |
| 213 SendKeyEvent(key_code, false, false); | 214 SendKeyEvent(key_code, false, false); |
| 214 } | 215 } |
| 215 | 216 |
| 216 View* GetFocusedView() { | 217 View* GetFocusedView() { |
| 217 return widget_->GetFocusManager()->GetFocusedView(); | 218 return widget_->GetFocusManager()->GetFocusedView(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 int GetCursorPositionX(int cursor_pos) { | 221 int GetCursorPositionX(int cursor_pos) { |
| 221 const string16 text = textfield_->text().substr(0, cursor_pos); | 222 gfx::RenderText* render_text = textfield_view_->GetRenderText(); |
| 222 return textfield_view_->GetInsets().left() + textfield_view_->text_offset_ + | 223 return render_text->GetCursorBounds(cursor_pos, false).x(); |
| 223 textfield_view_->GetFont().GetStringWidth(text); | |
| 224 } | 224 } |
| 225 | 225 |
| 226 // We need widget to populate wrapper class. | 226 // We need widget to populate wrapper class. |
| 227 Widget* widget_; | 227 Widget* widget_; |
| 228 | 228 |
| 229 TestTextfield* textfield_; | 229 TestTextfield* textfield_; |
| 230 NativeTextfieldViews* textfield_view_; | 230 NativeTextfieldViews* textfield_view_; |
| 231 TextfieldViewsModel* model_; | 231 TextfieldViewsModel* model_; |
| 232 | 232 |
| 233 // The string from Controller::ContentsChanged callback. | 233 // The string from Controller::ContentsChanged callback. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 TEST_F(NativeTextfieldViewsTest, ModelChangesTest) { | 249 TEST_F(NativeTextfieldViewsTest, ModelChangesTest) { |
| 250 InitTextfield(Textfield::STYLE_DEFAULT); | 250 InitTextfield(Textfield::STYLE_DEFAULT); |
| 251 | 251 |
| 252 // TextfieldController::ContentsChanged() shouldn't be called when changing | 252 // TextfieldController::ContentsChanged() shouldn't be called when changing |
| 253 // text programmatically. | 253 // text programmatically. |
| 254 last_contents_.clear(); | 254 last_contents_.clear(); |
| 255 textfield_->SetText(ASCIIToUTF16("this is")); | 255 textfield_->SetText(ASCIIToUTF16("this is")); |
| 256 | 256 |
| 257 EXPECT_STR_EQ("this is", model_->text()); | 257 EXPECT_STR_EQ("this is", model_->GetText()); |
| 258 EXPECT_STR_EQ("this is", textfield_->text()); | 258 EXPECT_STR_EQ("this is", textfield_->text()); |
| 259 EXPECT_TRUE(last_contents_.empty()); | 259 EXPECT_TRUE(last_contents_.empty()); |
| 260 | 260 |
| 261 textfield_->AppendText(ASCIIToUTF16(" a test")); | 261 textfield_->AppendText(ASCIIToUTF16(" a test")); |
| 262 EXPECT_STR_EQ("this is a test", model_->text()); | 262 EXPECT_STR_EQ("this is a test", model_->GetText()); |
| 263 EXPECT_STR_EQ("this is a test", textfield_->text()); | 263 EXPECT_STR_EQ("this is a test", textfield_->text()); |
| 264 EXPECT_TRUE(last_contents_.empty()); | 264 EXPECT_TRUE(last_contents_.empty()); |
| 265 | 265 |
| 266 EXPECT_EQ(string16(), textfield_->GetSelectedText()); | 266 EXPECT_EQ(string16(), textfield_->GetSelectedText()); |
| 267 textfield_->SelectAll(); | 267 textfield_->SelectAll(); |
| 268 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 268 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
| 269 EXPECT_TRUE(last_contents_.empty()); | 269 EXPECT_TRUE(last_contents_.empty()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(NativeTextfieldViewsTest, KeyTest) { | 272 TEST_F(NativeTextfieldViewsTest, KeyTest) { |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 EXPECT_STR_EQ("a23", textfield_->text()); | 1077 EXPECT_STR_EQ("a23", textfield_->text()); |
| 1078 SendKeyEvent(ui::VKEY_B); | 1078 SendKeyEvent(ui::VKEY_B); |
| 1079 EXPECT_STR_EQ("ab3", textfield_->text()); | 1079 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1080 SendKeyEvent(ui::VKEY_Z, false, true); | 1080 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1081 EXPECT_STR_EQ("123", textfield_->text()); | 1081 EXPECT_STR_EQ("123", textfield_->text()); |
| 1082 SendKeyEvent(ui::VKEY_Y, false, true); | 1082 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1083 EXPECT_STR_EQ("ab3", textfield_->text()); | 1083 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 } // namespace views | 1086 } // namespace views |
| OLD | NEW |