| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 322 |
| 323 // views::TextfieldController: | 323 // views::TextfieldController: |
| 324 bool HandleKeyEvent(views::Textfield* sender, | 324 bool HandleKeyEvent(views::Textfield* sender, |
| 325 const ui::KeyEvent& key_event) override { | 325 const ui::KeyEvent& key_event) override { |
| 326 target_->OnBlur(); | 326 target_->OnBlur(); |
| 327 target_.reset(); | 327 target_.reset(); |
| 328 return false; | 328 return false; |
| 329 } | 329 } |
| 330 | 330 |
| 331 private: | 331 private: |
| 332 scoped_ptr<views::Textfield> target_; | 332 std::unique_ptr<views::Textfield> target_; |
| 333 }; | 333 }; |
| 334 | 334 |
| 335 base::string16 GetClipboardText(ui::ClipboardType type) { | 335 base::string16 GetClipboardText(ui::ClipboardType type) { |
| 336 base::string16 text; | 336 base::string16 text; |
| 337 ui::Clipboard::GetForCurrentThread()->ReadText(type, &text); | 337 ui::Clipboard::GetForCurrentThread()->ReadText(type, &text); |
| 338 return text; | 338 return text; |
| 339 } | 339 } |
| 340 | 340 |
| 341 void SetClipboardText(ui::ClipboardType type, const std::string& text) { | 341 void SetClipboardText(ui::ClipboardType type, const std::string& text) { |
| 342 ui::ScopedClipboardWriter(type).WriteText(ASCIIToUTF16(text)); | 342 ui::ScopedClipboardWriter(type).WriteText(ASCIIToUTF16(text)); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 menu->IsEnabledAt(4 /* PASTE */)); | 631 menu->IsEnabledAt(4 /* PASTE */)); |
| 632 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 632 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
| 633 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); | 633 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); |
| 634 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); | 634 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); |
| 635 } | 635 } |
| 636 | 636 |
| 637 // We need widget to populate wrapper class. | 637 // We need widget to populate wrapper class. |
| 638 Widget* widget_; | 638 Widget* widget_; |
| 639 | 639 |
| 640 TestTextfield* textfield_; | 640 TestTextfield* textfield_; |
| 641 scoped_ptr<TextfieldTestApi> test_api_; | 641 std::unique_ptr<TextfieldTestApi> test_api_; |
| 642 TextfieldModel* model_; | 642 TextfieldModel* model_; |
| 643 | 643 |
| 644 // The string from Controller::ContentsChanged callback. | 644 // The string from Controller::ContentsChanged callback. |
| 645 base::string16 last_contents_; | 645 base::string16 last_contents_; |
| 646 | 646 |
| 647 // For testing input method related behaviors. | 647 // For testing input method related behaviors. |
| 648 MockInputMethod* input_method_; | 648 MockInputMethod* input_method_; |
| 649 | 649 |
| 650 // Indicates how many times OnBeforeUserAction() is called. | 650 // Indicates how many times OnBeforeUserAction() is called. |
| 651 int on_before_user_action_; | 651 int on_before_user_action_; |
| 652 | 652 |
| 653 // Indicates how many times OnAfterUserAction() is called. | 653 // Indicates how many times OnAfterUserAction() is called. |
| 654 int on_after_user_action_; | 654 int on_after_user_action_; |
| 655 | 655 |
| 656 private: | 656 private: |
| 657 ui::ClipboardType copied_to_clipboard_; | 657 ui::ClipboardType copied_to_clipboard_; |
| 658 scoped_ptr<ui::test::EventGenerator> event_generator_; | 658 std::unique_ptr<ui::test::EventGenerator> event_generator_; |
| 659 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); | 659 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); |
| 660 }; | 660 }; |
| 661 | 661 |
| 662 TEST_F(TextfieldTest, ModelChangesTest) { | 662 TEST_F(TextfieldTest, ModelChangesTest) { |
| 663 InitTextfield(); | 663 InitTextfield(); |
| 664 | 664 |
| 665 // TextfieldController::ContentsChanged() shouldn't be called when changing | 665 // TextfieldController::ContentsChanged() shouldn't be called when changing |
| 666 // text programmatically. | 666 // text programmatically. |
| 667 last_contents_.clear(); | 667 last_contents_.clear(); |
| 668 textfield_->SetText(ASCIIToUTF16("this is")); | 668 textfield_->SetText(ASCIIToUTF16("this is")); |
| (...skipping 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2569 | 2569 |
| 2570 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2570 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2571 ui::AXViewState state_protected; | 2571 ui::AXViewState state_protected; |
| 2572 textfield_->GetAccessibleState(&state_protected); | 2572 textfield_->GetAccessibleState(&state_protected); |
| 2573 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2573 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2574 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2574 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2575 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2575 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2576 } | 2576 } |
| 2577 | 2577 |
| 2578 } // namespace views | 2578 } // namespace views |
| OLD | NEW |