Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: views/view_unittest.cc

Issue 115825: Move text_field.cc and rename the class to Textfield in preparation for porti... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/focus/focus_manager_unittest.cc ('k') | views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "app/gfx/canvas.h" 5 #include "app/gfx/canvas.h"
6 #include "app/gfx/path.h" 6 #include "app/gfx/path.h"
7 #include "base/clipboard.h" 7 #include "base/clipboard.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "views/background.h" 10 #include "views/background.h"
11 #include "views/controls/button/checkbox.h" 11 #include "views/controls/button/checkbox.h"
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include "views/controls/button/native_button_win.h" 13 #include "views/controls/button/native_button_win.h"
14 #endif 14 #endif
15 #include "views/controls/scroll_view.h" 15 #include "views/controls/scroll_view.h"
16 #include "views/controls/text_field.h" 16 #include "views/controls/textfield/textfield.h"
17 #include "views/event.h" 17 #include "views/event.h"
18 #include "views/focus/view_storage.h" 18 #include "views/focus/view_storage.h"
19 #include "views/view.h" 19 #include "views/view.h"
20 #include "views/widget/root_view.h" 20 #include "views/widget/root_view.h"
21 #include "views/widget/widget_win.h" 21 #include "views/widget/widget_win.h"
22 #include "views/window/dialog_delegate.h" 22 #include "views/window/dialog_delegate.h"
23 #include "views/window/window.h" 23 #include "views/window/window.h"
24 24
25 using namespace views; 25 using namespace views;
26 26
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 EXPECT_EQ(false, v2->HitTest(ConvertPointToView(v2, v2_origin))); 586 EXPECT_EQ(false, v2->HitTest(ConvertPointToView(v2, v2_origin)));
587 587
588 // Test GetViewForPoint 588 // Test GetViewForPoint
589 EXPECT_EQ(v1, root_view->GetViewForPoint(v1_centerpoint)); 589 EXPECT_EQ(v1, root_view->GetViewForPoint(v1_centerpoint));
590 EXPECT_EQ(v2, root_view->GetViewForPoint(v2_centerpoint)); 590 EXPECT_EQ(v2, root_view->GetViewForPoint(v2_centerpoint));
591 EXPECT_EQ(v1, root_view->GetViewForPoint(v1_origin)); 591 EXPECT_EQ(v1, root_view->GetViewForPoint(v1_origin));
592 EXPECT_EQ(root_view, root_view->GetViewForPoint(v2_origin)); 592 EXPECT_EQ(root_view, root_view->GetViewForPoint(v2_origin));
593 } 593 }
594 594
595 #if defined(OS_WIN) 595 #if defined(OS_WIN)
596 // Tests that the TextField view respond appropiately to cut/copy/paste. 596 // Tests that the Textfield view respond appropiately to cut/copy/paste.
597 TEST_F(ViewTest, TextFieldCutCopyPaste) { 597 TEST_F(ViewTest, TextfieldCutCopyPaste) {
598 const std::wstring kNormalText = L"Normal"; 598 const std::wstring kNormalText = L"Normal";
599 const std::wstring kReadOnlyText = L"Read only"; 599 const std::wstring kReadOnlyText = L"Read only";
600 const std::wstring kPasswordText = L"Password! ** Secret stuff **"; 600 const std::wstring kPasswordText = L"Password! ** Secret stuff **";
601 601
602 Clipboard clipboard; 602 Clipboard clipboard;
603 603
604 WidgetWin* window = new WidgetWin; 604 WidgetWin* window = new WidgetWin;
605 window->Init(NULL, gfx::Rect(0, 0, 100, 100), true); 605 window->Init(NULL, gfx::Rect(0, 0, 100, 100), true);
606 RootView* root_view = window->GetRootView(); 606 RootView* root_view = window->GetRootView();
607 607
608 TextField* normal = new TextField(); 608 Textfield* normal = new Textfield();
609 TextField* read_only = new TextField(); 609 Textfield* read_only = new Textfield();
610 read_only->SetReadOnly(true); 610 read_only->SetReadOnly(true);
611 TextField* password = new TextField(TextField::STYLE_PASSWORD); 611 Textfield* password = new Textfield(Textfield::STYLE_PASSWORD);
612 612
613 root_view->AddChildView(normal); 613 root_view->AddChildView(normal);
614 root_view->AddChildView(read_only); 614 root_view->AddChildView(read_only);
615 root_view->AddChildView(password); 615 root_view->AddChildView(password);
616 616
617 normal->SetText(kNormalText); 617 normal->SetText(kNormalText);
618 read_only->SetText(kReadOnlyText); 618 read_only->SetText(kReadOnlyText);
619 password->SetText(kPasswordText); 619 password->SetText(kPasswordText);
620 620
621 // 621 //
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 ::SendMessage(password->GetNativeComponent(), WM_COPY, 0, 0); 668 ::SendMessage(password->GetNativeComponent(), WM_COPY, 0, 0);
669 result.clear(); 669 result.clear();
670 clipboard.ReadText(&result); 670 clipboard.ReadText(&result);
671 // We don't let you copy from a password field, clipboard should not have 671 // We don't let you copy from a password field, clipboard should not have
672 // changed. 672 // changed.
673 EXPECT_EQ(kNormalText, result); 673 EXPECT_EQ(kNormalText, result);
674 674
675 // 675 //
676 // Test Paste. 676 // Test Paste.
677 // 677 //
678 // Note that we use GetWindowText instead of TextField::GetText below as the 678 // Note that we use GetWindowText instead of Textfield::GetText below as the
679 // text in the TextField class is synced to the text of the HWND on 679 // text in the Textfield class is synced to the text of the HWND on
680 // WM_KEYDOWN messages that we are not simulating here. 680 // WM_KEYDOWN messages that we are not simulating here.
681 681
682 // Attempting to copy kNormalText in a read-only text-field should fail. 682 // Attempting to copy kNormalText in a read-only text-field should fail.
683 read_only->SelectAll(); 683 read_only->SelectAll();
684 ::SendMessage(read_only->GetNativeComponent(), WM_KEYDOWN, 0, 0); 684 ::SendMessage(read_only->GetNativeComponent(), WM_KEYDOWN, 0, 0);
685 wchar_t buffer[1024] = { 0 }; 685 wchar_t buffer[1024] = { 0 };
686 ::GetWindowText(read_only->GetNativeComponent(), buffer, 1024); 686 ::GetWindowText(read_only->GetNativeComponent(), buffer, 1024);
687 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); 687 EXPECT_EQ(kReadOnlyText, std::wstring(buffer));
688 688
689 password->SelectAll(); 689 password->SelectAll();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 virtual void Layout() { 738 virtual void Layout() {
739 SizeToPreferredSize(); 739 SizeToPreferredSize();
740 } 740 }
741 }; 741 };
742 742
743 class TestViewWithControls : public View { 743 class TestViewWithControls : public View {
744 public: 744 public:
745 TestViewWithControls() { 745 TestViewWithControls() {
746 button_ = new ButtonTest(NULL, L"Button"); 746 button_ = new ButtonTest(NULL, L"Button");
747 checkbox_ = new CheckboxTest(L"My checkbox"); 747 checkbox_ = new CheckboxTest(L"My checkbox");
748 text_field_ = new TextField(); 748 text_field_ = new Textfield();
749 AddChildView(button_); 749 AddChildView(button_);
750 AddChildView(checkbox_); 750 AddChildView(checkbox_);
751 AddChildView(text_field_); 751 AddChildView(text_field_);
752 } 752 }
753 753
754 ButtonTest* button_; 754 ButtonTest* button_;
755 CheckboxTest* checkbox_; 755 CheckboxTest* checkbox_;
756 TextField* text_field_; 756 Textfield* text_field_;
757 }; 757 };
758 758
759 class SimpleWindowDelegate : public WindowDelegate { 759 class SimpleWindowDelegate : public WindowDelegate {
760 public: 760 public:
761 SimpleWindowDelegate(View* contents) : contents_(contents) { } 761 SimpleWindowDelegate(View* contents) : contents_(contents) { }
762 762
763 virtual void DeleteDelegate() { delete this; } 763 virtual void DeleteDelegate() { delete this; }
764 764
765 virtual View* GetContentsView() { return contents_; } 765 virtual View* GetContentsView() { return contents_; }
766 766
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 SimularePressingEnterAndCheckDefaultButton(OK); 998 SimularePressingEnterAndCheckDefaultButton(OK);
999 999
1000 // Focus the cancel button. 1000 // Focus the cancel button.
1001 client_view_->FocusWillChange(NULL, cancel_button_); 1001 client_view_->FocusWillChange(NULL, cancel_button_);
1002 EXPECT_FALSE(ok_button_->is_default()); 1002 EXPECT_FALSE(ok_button_->is_default());
1003 EXPECT_TRUE(cancel_button_->is_default()); 1003 EXPECT_TRUE(cancel_button_->is_default());
1004 EXPECT_FALSE(dialog_view_->button1_->is_default()); 1004 EXPECT_FALSE(dialog_view_->button1_->is_default());
1005 EXPECT_FALSE(dialog_view_->button2_->is_default()); 1005 EXPECT_FALSE(dialog_view_->button2_->is_default());
1006 SimularePressingEnterAndCheckDefaultButton(CANCEL); 1006 SimularePressingEnterAndCheckDefaultButton(CANCEL);
1007 } 1007 }
OLDNEW
« no previous file with comments | « views/focus/focus_manager_unittest.cc ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698