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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "ui/base/clipboard/clipboard.h" | 10 #include "ui/base/clipboard/clipboard.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "views/test/test_views_delegate.h" | 34 #include "views/test/test_views_delegate.h" |
35 #elif defined(OS_LINUX) | 35 #elif defined(OS_LINUX) |
36 #include "views/widget/widget_gtk.h" | 36 #include "views/widget/widget_gtk.h" |
37 #include "views/window/window_gtk.h" | 37 #include "views/window/window_gtk.h" |
38 #endif | 38 #endif |
39 #if defined(TOUCH_UI) | 39 #if defined(TOUCH_UI) |
40 #include "views/touchui/gesture_manager.h" | 40 #include "views/touchui/gesture_manager.h" |
41 #endif | 41 #endif |
42 | 42 |
43 using ::testing::_; | 43 using ::testing::_; |
44 using namespace views; | |
45 | 44 |
46 namespace { | 45 namespace views { |
47 | 46 |
48 class ViewTest : public ViewsTestBase { | 47 class ViewTest : public ViewsTestBase { |
49 public: | 48 public: |
50 ViewTest() { | 49 ViewTest() { |
51 } | 50 } |
52 | 51 |
53 virtual ~ViewTest() { | 52 virtual ~ViewTest() { |
54 } | 53 } |
55 }; | 54 }; |
56 | 55 |
57 /* | |
58 | |
59 // Paints the RootView. | |
60 void PaintRootView(views::RootView* root, bool empty_paint) { | |
61 if (!empty_paint) { | |
62 root->PaintNow(); | |
63 } else { | |
64 // User isn't logged in, so that PaintNow will generate an empty rectangle. | |
65 // Invoke paint directly. | |
66 gfx::Rect paint_rect = root->GetScheduledPaintRect(); | |
67 gfx::CanvasSkia canvas(paint_rect.width(), paint_rect.height(), true); | |
68 canvas.TranslateInt(-paint_rect.x(), -paint_rect.y()); | |
69 canvas.ClipRectInt(0, 0, paint_rect.width(), paint_rect.height()); | |
70 root->Paint(&canvas); | |
71 } | |
72 } | |
73 | |
74 typedef CWinTraits<WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS> CVTWTraits; | |
75 | |
76 // A trivial window implementation that tracks whether or not it has been | |
77 // painted. This is used by the painting test to determine if paint will result | |
78 // in an empty region. | |
79 class EmptyWindow : public CWindowImpl<EmptyWindow, | |
80 CWindow, | |
81 CVTWTraits> { | |
82 public: | |
83 DECLARE_FRAME_WND_CLASS(L"Chrome_ChromeViewsEmptyWindow", 0) | |
84 | |
85 BEGIN_MSG_MAP_EX(EmptyWindow) | |
86 MSG_WM_PAINT(OnPaint) | |
87 END_MSG_MAP() | |
88 | |
89 EmptyWindow::EmptyWindow(const CRect& bounds) : empty_paint_(false) { | |
90 Create(NULL, static_cast<RECT>(bounds)); | |
91 ShowWindow(SW_SHOW); | |
92 } | |
93 | |
94 EmptyWindow::~EmptyWindow() { | |
95 ShowWindow(SW_HIDE); | |
96 DestroyWindow(); | |
97 } | |
98 | |
99 void EmptyWindow::OnPaint(HDC dc) { | |
100 PAINTSTRUCT ps; | |
101 HDC paint_dc = BeginPaint(&ps); | |
102 if (!empty_paint_ && (ps.rcPaint.top - ps.rcPaint.bottom) == 0 && | |
103 (ps.rcPaint.right - ps.rcPaint.left) == 0) { | |
104 empty_paint_ = true; | |
105 } | |
106 EndPaint(&ps); | |
107 } | |
108 | |
109 bool empty_paint() { | |
110 return empty_paint_; | |
111 } | |
112 | |
113 private: | |
114 bool empty_paint_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(EmptyWindow); | |
117 }; | |
118 */ | |
119 | |
120 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
121 // | 57 // |
122 // A view subclass for testing purpose | 58 // A view subclass for testing purpose |
123 // | 59 // |
124 //////////////////////////////////////////////////////////////////////////////// | 60 //////////////////////////////////////////////////////////////////////////////// |
125 class TestView : public View { | 61 class TestView : public View { |
126 public: | 62 public: |
127 TestView() : View() { | 63 TestView() : View() { |
128 } | 64 } |
129 | 65 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void TestView::ViewHierarchyChanged(bool is_add, View *parent, View *child) { | 194 void TestView::ViewHierarchyChanged(bool is_add, View *parent, View *child) { |
259 if (is_add) { | 195 if (is_add) { |
260 child_added_ = true; | 196 child_added_ = true; |
261 } else { | 197 } else { |
262 child_removed_ = true; | 198 child_removed_ = true; |
263 } | 199 } |
264 parent_ = parent; | 200 parent_ = parent; |
265 child_ = child; | 201 child_ = child; |
266 } | 202 } |
267 | 203 |
268 } // namespace | |
269 | |
270 TEST_F(ViewTest, AddRemoveNotifications) { | 204 TEST_F(ViewTest, AddRemoveNotifications) { |
271 TestView* v1 = new TestView(); | 205 TestView* v1 = new TestView(); |
272 v1->SetBounds(0, 0, 300, 300); | 206 v1->SetBounds(0, 0, 300, 300); |
273 | 207 |
274 TestView* v2 = new TestView(); | 208 TestView* v2 = new TestView(); |
275 v2->SetBounds(0, 0, 300, 300); | 209 v2->SetBounds(0, 0, 300, 300); |
276 | 210 |
277 TestView* v3 = new TestView(); | 211 TestView* v3 = new TestView(); |
278 v3->SetBounds(0, 0, 300, 300); | 212 v3->SetBounds(0, 0, 300, 300); |
279 | 213 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 location_.SetPoint(event.x(), event.y()); | 288 location_.SetPoint(event.x(), event.y()); |
355 } | 289 } |
356 | 290 |
357 TEST_F(ViewTest, MouseEvent) { | 291 TEST_F(ViewTest, MouseEvent) { |
358 TestView* v1 = new TestView(); | 292 TestView* v1 = new TestView(); |
359 v1->SetBounds(0, 0, 300, 300); | 293 v1->SetBounds(0, 0, 300, 300); |
360 | 294 |
361 TestView* v2 = new TestView(); | 295 TestView* v2 = new TestView(); |
362 v2->SetBounds(100, 100, 100, 100); | 296 v2->SetBounds(100, 100, 100, 100); |
363 | 297 |
364 scoped_ptr<Widget> widget(Widget::CreateWidget()); | 298 scoped_ptr<Widget> widget(new Widget); |
365 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 299 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
366 params.delete_on_destroy = false; | 300 params.delete_on_destroy = false; |
367 params.bounds = gfx::Rect(50, 50, 650, 650); | 301 params.bounds = gfx::Rect(50, 50, 650, 650); |
368 widget->Init(params); | 302 widget->Init(params); |
369 RootView* root = widget->GetRootView(); | 303 RootView* root = widget->GetRootView(); |
370 | 304 |
371 root->AddChildView(v1); | 305 root->AddChildView(v1); |
372 v1->AddChildView(v2); | 306 v1->AddChildView(v2); |
373 | 307 |
374 v1->Reset(); | 308 v1->Reset(); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 } | 528 } |
595 | 529 |
596 /* This test is disabled because it is flakey on some systems. | 530 /* This test is disabled because it is flakey on some systems. |
597 TEST_F(ViewTest, DISABLED_Painting) { | 531 TEST_F(ViewTest, DISABLED_Painting) { |
598 // Determine if InvalidateRect generates an empty paint rectangle. | 532 // Determine if InvalidateRect generates an empty paint rectangle. |
599 EmptyWindow paint_window(CRect(50, 50, 650, 650)); | 533 EmptyWindow paint_window(CRect(50, 50, 650, 650)); |
600 paint_window.RedrawWindow(CRect(0, 0, 600, 600), NULL, | 534 paint_window.RedrawWindow(CRect(0, 0, 600, 600), NULL, |
601 RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); | 535 RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); |
602 bool empty_paint = paint_window.empty_paint(); | 536 bool empty_paint = paint_window.empty_paint(); |
603 | 537 |
604 views::WidgetWin window; | 538 WidgetWin window; |
605 window.set_delete_on_destroy(false); | 539 window.set_delete_on_destroy(false); |
606 window.set_window_style(WS_OVERLAPPEDWINDOW); | 540 window.set_window_style(WS_OVERLAPPEDWINDOW); |
607 window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL); | 541 window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL); |
608 RootView* root = window.GetRootView(); | 542 RootView* root = window.GetRootView(); |
609 | 543 |
610 TestView* v1 = new TestView(); | 544 TestView* v1 = new TestView(); |
611 v1->SetBounds(0, 0, 650, 650); | 545 v1->SetBounds(0, 0, 650, 650); |
612 root->AddChildView(v1); | 546 root->AddChildView(v1); |
613 | 547 |
614 TestView* v2 = new TestView(); | 548 TestView* v2 = new TestView(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 CheckRect(v1->last_clip_, tmp_rect); | 589 CheckRect(v1->last_clip_, tmp_rect); |
656 | 590 |
657 // Make sure v4 was not painted | 591 // Make sure v4 was not painted |
658 tmp_rect.setEmpty(); | 592 tmp_rect.setEmpty(); |
659 CheckRect(v4->last_clip_, tmp_rect); | 593 CheckRect(v4->last_clip_, tmp_rect); |
660 | 594 |
661 window.DestroyWindow(); | 595 window.DestroyWindow(); |
662 } | 596 } |
663 */ | 597 */ |
664 | 598 |
| 599 #if defined(OS_WIN) |
665 TEST_F(ViewTest, RemoveNotification) { | 600 TEST_F(ViewTest, RemoveNotification) { |
666 views::ViewStorage* vs = views::ViewStorage::GetInstance(); | 601 #elif defined(TOOLKIT_USES_GTK) |
667 views::Widget* widget = Widget::CreateWidget(); | 602 // TODO(beng): stopped working with widget hierarchy split, |
668 views::RootView* root_view = widget->GetRootView(); | 603 // http://crbug.com/82364 |
| 604 TEST_F(ViewTest, DISABLED_RemoveNotification) { |
| 605 #endif |
| 606 ViewStorage* vs = ViewStorage::GetInstance(); |
| 607 Widget* widget = new Widget; |
| 608 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_WINDOW)); |
| 609 RootView* root_view = widget->GetRootView(); |
669 | 610 |
670 View* v1 = new View; | 611 View* v1 = new View; |
671 int s1 = vs->CreateStorageID(); | 612 int s1 = vs->CreateStorageID(); |
672 vs->StoreView(s1, v1); | 613 vs->StoreView(s1, v1); |
673 root_view->AddChildView(v1); | 614 root_view->AddChildView(v1); |
674 View* v11 = new View; | 615 View* v11 = new View; |
675 int s11 = vs->CreateStorageID(); | 616 int s11 = vs->CreateStorageID(); |
676 vs->StoreView(s11, v11); | 617 vs->StoreView(s11, v11); |
677 v1->AddChildView(v11); | 618 v1->AddChildView(v11); |
678 View* v111 = new View; | 619 View* v111 = new View; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 | 660 |
720 // Now try removing a view with a hierarchy of depth 1. | 661 // Now try removing a view with a hierarchy of depth 1. |
721 v11->RemoveChildView(v113); | 662 v11->RemoveChildView(v113); |
722 EXPECT_EQ(stored_views - 3, vs->view_count()); | 663 EXPECT_EQ(stored_views - 3, vs->view_count()); |
723 EXPECT_EQ(NULL, vs->RetrieveView(s113)); | 664 EXPECT_EQ(NULL, vs->RetrieveView(s113)); |
724 EXPECT_EQ(NULL, vs->RetrieveView(s1131)); | 665 EXPECT_EQ(NULL, vs->RetrieveView(s1131)); |
725 delete v113; // We won't use this one anymore. | 666 delete v113; // We won't use this one anymore. |
726 | 667 |
727 // Now remove even more. | 668 // Now remove even more. |
728 root_view->RemoveChildView(v1); | 669 root_view->RemoveChildView(v1); |
729 EXPECT_EQ(stored_views - 8, vs->view_count()); | |
730 EXPECT_EQ(NULL, vs->RetrieveView(s1)); | 670 EXPECT_EQ(NULL, vs->RetrieveView(s1)); |
731 EXPECT_EQ(NULL, vs->RetrieveView(s11)); | 671 EXPECT_EQ(NULL, vs->RetrieveView(s11)); |
732 EXPECT_EQ(NULL, vs->RetrieveView(s12)); | 672 EXPECT_EQ(NULL, vs->RetrieveView(s12)); |
733 EXPECT_EQ(NULL, vs->RetrieveView(s111)); | 673 EXPECT_EQ(NULL, vs->RetrieveView(s111)); |
734 EXPECT_EQ(NULL, vs->RetrieveView(s112)); | 674 EXPECT_EQ(NULL, vs->RetrieveView(s112)); |
735 | 675 |
736 // Put v1 back for more tests. | 676 // Put v1 back for more tests. |
737 root_view->AddChildView(v1); | 677 root_view->AddChildView(v1); |
738 vs->StoreView(s1, v1); | 678 vs->StoreView(s1, v1); |
739 | 679 |
740 // Now delete the root view (deleting the window will trigger a delete of the | 680 // Synchronously closing the window deletes the view hierarchy, which should |
741 // RootView) and make sure we are notified that the views were removed. | 681 // remove all its views from ViewStorage. |
742 delete widget; | 682 widget->CloseNow(); |
743 EXPECT_EQ(stored_views - 10, vs->view_count()); | 683 EXPECT_EQ(stored_views - 10, vs->view_count()); |
744 EXPECT_EQ(NULL, vs->RetrieveView(s1)); | 684 EXPECT_EQ(NULL, vs->RetrieveView(s1)); |
745 EXPECT_EQ(NULL, vs->RetrieveView(s12)); | 685 EXPECT_EQ(NULL, vs->RetrieveView(s12)); |
746 EXPECT_EQ(NULL, vs->RetrieveView(s11)); | 686 EXPECT_EQ(NULL, vs->RetrieveView(s11)); |
747 EXPECT_EQ(NULL, vs->RetrieveView(s12)); | 687 EXPECT_EQ(NULL, vs->RetrieveView(s12)); |
748 EXPECT_EQ(NULL, vs->RetrieveView(s21)); | 688 EXPECT_EQ(NULL, vs->RetrieveView(s21)); |
749 EXPECT_EQ(NULL, vs->RetrieveView(s111)); | 689 EXPECT_EQ(NULL, vs->RetrieveView(s111)); |
750 EXPECT_EQ(NULL, vs->RetrieveView(s112)); | 690 EXPECT_EQ(NULL, vs->RetrieveView(s112)); |
751 } | 691 } |
752 | 692 |
753 namespace { | 693 namespace { |
754 class HitTestView : public views::View { | 694 class HitTestView : public View { |
755 public: | 695 public: |
756 explicit HitTestView(bool has_hittest_mask) | 696 explicit HitTestView(bool has_hittest_mask) |
757 : has_hittest_mask_(has_hittest_mask) { | 697 : has_hittest_mask_(has_hittest_mask) { |
758 } | 698 } |
759 virtual ~HitTestView() {} | 699 virtual ~HitTestView() {} |
760 | 700 |
761 protected: | 701 protected: |
762 // Overridden from views::View: | 702 // Overridden from View: |
763 virtual bool HasHitTestMask() const { | 703 virtual bool HasHitTestMask() const { |
764 return has_hittest_mask_; | 704 return has_hittest_mask_; |
765 } | 705 } |
766 virtual void GetHitTestMask(gfx::Path* mask) const { | 706 virtual void GetHitTestMask(gfx::Path* mask) const { |
767 DCHECK(has_hittest_mask_); | 707 DCHECK(has_hittest_mask_); |
768 DCHECK(mask); | 708 DCHECK(mask); |
769 | 709 |
770 SkScalar w = SkIntToScalar(width()); | 710 SkScalar w = SkIntToScalar(width()); |
771 SkScalar h = SkIntToScalar(height()); | 711 SkScalar h = SkIntToScalar(height()); |
772 | 712 |
773 // Create a triangular mask within the bounds of this View. | 713 // Create a triangular mask within the bounds of this View. |
774 mask->moveTo(w / 2, 0); | 714 mask->moveTo(w / 2, 0); |
775 mask->lineTo(w, h); | 715 mask->lineTo(w, h); |
776 mask->lineTo(0, h); | 716 mask->lineTo(0, h); |
777 mask->close(); | 717 mask->close(); |
778 } | 718 } |
779 | 719 |
780 private: | 720 private: |
781 bool has_hittest_mask_; | 721 bool has_hittest_mask_; |
782 | 722 |
783 DISALLOW_COPY_AND_ASSIGN(HitTestView); | 723 DISALLOW_COPY_AND_ASSIGN(HitTestView); |
784 }; | 724 }; |
785 | 725 |
786 gfx::Point ConvertPointToView(views::View* view, const gfx::Point& p) { | 726 gfx::Point ConvertPointToView(View* view, const gfx::Point& p) { |
787 gfx::Point tmp(p); | 727 gfx::Point tmp(p); |
788 views::View::ConvertPointToView(view->GetRootView(), view, &tmp); | 728 View::ConvertPointToView(view->GetRootView(), view, &tmp); |
789 return tmp; | 729 return tmp; |
790 } | 730 } |
791 } | 731 } |
792 | 732 |
793 TEST_F(ViewTest, HitTestMasks) { | 733 TEST_F(ViewTest, HitTestMasks) { |
794 scoped_ptr<views::Widget> widget(Widget::CreateWidget()); | 734 Widget* widget = new Widget; |
795 views::RootView* root_view = widget->GetRootView(); | 735 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_WINDOW)); |
| 736 RootView* root_view = widget->GetRootView(); |
796 root_view->SetBounds(0, 0, 500, 500); | 737 root_view->SetBounds(0, 0, 500, 500); |
797 | 738 |
798 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); | 739 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); |
799 HitTestView* v1 = new HitTestView(false); | 740 HitTestView* v1 = new HitTestView(false); |
800 v1->SetBoundsRect(v1_bounds); | 741 v1->SetBoundsRect(v1_bounds); |
801 root_view->AddChildView(v1); | 742 root_view->AddChildView(v1); |
802 | 743 |
803 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); | 744 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); |
804 HitTestView* v2 = new HitTestView(true); | 745 HitTestView* v2 = new HitTestView(true); |
805 v2->SetBoundsRect(v2_bounds); | 746 v2->SetBoundsRect(v2_bounds); |
806 root_view->AddChildView(v2); | 747 root_view->AddChildView(v2); |
807 | 748 |
808 gfx::Point v1_centerpoint = v1_bounds.CenterPoint(); | 749 gfx::Point v1_centerpoint = v1_bounds.CenterPoint(); |
809 gfx::Point v2_centerpoint = v2_bounds.CenterPoint(); | 750 gfx::Point v2_centerpoint = v2_bounds.CenterPoint(); |
810 gfx::Point v1_origin = v1_bounds.origin(); | 751 gfx::Point v1_origin = v1_bounds.origin(); |
811 gfx::Point v2_origin = v2_bounds.origin(); | 752 gfx::Point v2_origin = v2_bounds.origin(); |
812 | 753 |
813 // Test HitTest | 754 // Test HitTest |
814 EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_centerpoint))); | 755 EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_centerpoint))); |
815 EXPECT_TRUE(v2->HitTest(ConvertPointToView(v2, v2_centerpoint))); | 756 EXPECT_TRUE(v2->HitTest(ConvertPointToView(v2, v2_centerpoint))); |
816 | 757 |
817 EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_origin))); | 758 EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_origin))); |
818 EXPECT_FALSE(v2->HitTest(ConvertPointToView(v2, v2_origin))); | 759 EXPECT_FALSE(v2->HitTest(ConvertPointToView(v2, v2_origin))); |
819 | 760 |
820 // Test GetEventHandlerForPoint | 761 // Test GetEventHandlerForPoint |
821 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint)); | 762 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint)); |
822 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint)); | 763 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint)); |
823 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin)); | 764 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin)); |
824 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin)); | 765 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin)); |
| 766 |
| 767 widget->CloseNow(); |
825 } | 768 } |
826 | 769 |
827 TEST_F(ViewTest, Textfield) { | 770 TEST_F(ViewTest, Textfield) { |
828 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop " | 771 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop " |
829 "believing it, doesn't go away."); | 772 "believing it, doesn't go away."); |
830 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!"); | 773 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!"); |
831 const string16 kEmptyString; | 774 const string16 kEmptyString; |
832 | 775 |
833 ui::Clipboard clipboard; | 776 ui::Clipboard clipboard; |
834 | 777 |
835 Widget* widget = Widget::CreateWidget(); | 778 Widget* widget = new Widget; |
836 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 779 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
837 params.bounds = gfx::Rect(0, 0, 100, 100); | 780 params.bounds = gfx::Rect(0, 0, 100, 100); |
838 widget->Init(params); | 781 widget->Init(params); |
839 RootView* root_view = widget->GetRootView(); | 782 RootView* root_view = widget->GetRootView(); |
840 | 783 |
841 Textfield* textfield = new Textfield(); | 784 Textfield* textfield = new Textfield(); |
842 root_view->AddChildView(textfield); | 785 root_view->AddChildView(textfield); |
843 | 786 |
844 // Test setting, appending text. | 787 // Test setting, appending text. |
845 textfield->SetText(kText); | 788 textfield->SetText(kText); |
846 EXPECT_EQ(kText, textfield->text()); | 789 EXPECT_EQ(kText, textfield->text()); |
847 textfield->AppendText(kExtraText); | 790 textfield->AppendText(kExtraText); |
848 EXPECT_EQ(kText + kExtraText, textfield->text()); | 791 EXPECT_EQ(kText + kExtraText, textfield->text()); |
849 textfield->SetText(string16()); | 792 textfield->SetText(string16()); |
850 EXPECT_EQ(kEmptyString, textfield->text()); | 793 EXPECT_EQ(kEmptyString, textfield->text()); |
851 | 794 |
852 // Test selection related methods. | 795 // Test selection related methods. |
853 textfield->SetText(kText); | 796 textfield->SetText(kText); |
854 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); | 797 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); |
855 textfield->SelectAll(); | 798 textfield->SelectAll(); |
856 EXPECT_EQ(kText, textfield->text()); | 799 EXPECT_EQ(kText, textfield->text()); |
857 textfield->ClearSelection(); | 800 textfield->ClearSelection(); |
858 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); | 801 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); |
| 802 |
| 803 widget->CloseNow(); |
859 } | 804 } |
860 | 805 |
861 #if defined(OS_WIN) | 806 #if defined(OS_WIN) |
862 | 807 |
863 // Tests that the Textfield view respond appropiately to cut/copy/paste. | 808 // Tests that the Textfield view respond appropiately to cut/copy/paste. |
864 TEST_F(ViewTest, TextfieldCutCopyPaste) { | 809 TEST_F(ViewTest, TextfieldCutCopyPaste) { |
865 const std::wstring kNormalText = L"Normal"; | 810 const std::wstring kNormalText = L"Normal"; |
866 const std::wstring kReadOnlyText = L"Read only"; | 811 const std::wstring kReadOnlyText = L"Read only"; |
867 const std::wstring kPasswordText = L"Password! ** Secret stuff **"; | 812 const std::wstring kPasswordText = L"Password! ** Secret stuff **"; |
868 | 813 |
869 ui::Clipboard clipboard; | 814 ui::Clipboard clipboard; |
870 | 815 |
871 Widget* widget = Widget::CreateWidget(); | 816 Widget* widget = new Widget; |
872 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 817 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
873 params.bounds = gfx::Rect(0, 0, 100, 100); | 818 params.bounds = gfx::Rect(0, 0, 100, 100); |
874 widget->Init(params); | 819 widget->Init(params); |
875 RootView* root_view = widget->GetRootView(); | 820 RootView* root_view = widget->GetRootView(); |
876 | 821 |
877 Textfield* normal = new Textfield(); | 822 Textfield* normal = new Textfield(); |
878 Textfield* read_only = new Textfield(); | 823 Textfield* read_only = new Textfield(); |
879 read_only->SetReadOnly(true); | 824 read_only->SetReadOnly(true); |
880 Textfield* password = new Textfield(Textfield::STYLE_PASSWORD); | 825 Textfield* password = new Textfield(Textfield::STYLE_PASSWORD); |
881 | 826 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 EXPECT_EQ(kNormalText, std::wstring(buffer)); | 906 EXPECT_EQ(kNormalText, std::wstring(buffer)); |
962 | 907 |
963 // Copy from read_only so the string we are pasting is not the same as the | 908 // Copy from read_only so the string we are pasting is not the same as the |
964 // current one. | 909 // current one. |
965 read_only->SelectAll(); | 910 read_only->SelectAll(); |
966 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); | 911 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); |
967 normal->SelectAll(); | 912 normal->SelectAll(); |
968 ::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0); | 913 ::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0); |
969 ::GetWindowText(normal->GetTestingHandle(), buffer, 1024); | 914 ::GetWindowText(normal->GetTestingHandle(), buffer, 1024); |
970 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); | 915 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); |
| 916 widget->CloseNow(); |
971 } | 917 } |
972 #endif | 918 #endif |
973 | 919 |
974 //////////////////////////////////////////////////////////////////////////////// | 920 //////////////////////////////////////////////////////////////////////////////// |
975 // Accelerators | 921 // Accelerators |
976 //////////////////////////////////////////////////////////////////////////////// | 922 //////////////////////////////////////////////////////////////////////////////// |
977 bool TestView::AcceleratorPressed(const Accelerator& accelerator) { | 923 bool TestView::AcceleratorPressed(const Accelerator& accelerator) { |
978 accelerator_count_map_[accelerator]++; | 924 accelerator_count_map_[accelerator]++; |
979 return true; | 925 return true; |
980 } | 926 } |
981 | 927 |
982 #if defined(OS_WIN) | 928 #if defined(OS_WIN) |
983 TEST_F(ViewTest, ActivateAccelerator) { | 929 TEST_F(ViewTest, ActivateAccelerator) { |
984 // Register a keyboard accelerator before the view is added to a window. | 930 // Register a keyboard accelerator before the view is added to a window. |
985 views::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); | 931 Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); |
986 TestView* view = new TestView(); | 932 TestView* view = new TestView(); |
987 view->Reset(); | 933 view->Reset(); |
988 view->AddAccelerator(return_accelerator); | 934 view->AddAccelerator(return_accelerator); |
989 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 935 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
990 | 936 |
991 // Create a window and add the view as its child. | 937 // Create a window and add the view as its child. |
992 scoped_ptr<Widget> widget(Widget::CreateWidget()); | 938 scoped_ptr<Widget> widget(new Widget); |
993 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 939 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
994 params.delete_on_destroy = false; | 940 params.delete_on_destroy = false; |
995 params.bounds = gfx::Rect(0, 0, 100, 100); | 941 params.bounds = gfx::Rect(0, 0, 100, 100); |
996 widget->Init(params); | 942 widget->Init(params); |
997 RootView* root = widget->GetRootView(); | 943 RootView* root = widget->GetRootView(); |
998 root->AddChildView(view); | 944 root->AddChildView(view); |
999 | 945 |
1000 // Get the focus manager. | 946 // Get the focus manager. |
1001 views::FocusManager* focus_manager = | 947 FocusManager* focus_manager = FocusManager::GetFocusManagerForNativeView( |
1002 views::FocusManager::GetFocusManagerForNativeView( | 948 widget->GetNativeView()); |
1003 widget->GetNativeView()); | |
1004 ASSERT_TRUE(focus_manager); | 949 ASSERT_TRUE(focus_manager); |
1005 | 950 |
1006 // Hit the return key and see if it takes effect. | 951 // Hit the return key and see if it takes effect. |
1007 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); | 952 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); |
1008 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 953 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
1009 | 954 |
1010 // Hit the escape key. Nothing should happen. | 955 // Hit the escape key. Nothing should happen. |
1011 views::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); | 956 Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); |
1012 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); | 957 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); |
1013 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 958 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
1014 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); | 959 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); |
1015 | 960 |
1016 // Now register the escape key and hit it again. | 961 // Now register the escape key and hit it again. |
1017 view->AddAccelerator(escape_accelerator); | 962 view->AddAccelerator(escape_accelerator); |
1018 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator)); | 963 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator)); |
1019 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 964 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
1020 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1); | 965 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1); |
1021 | 966 |
(...skipping 20 matching lines...) Expand all Loading... |
1042 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); | 987 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); |
1043 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); | 988 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); |
1044 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); | 989 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); |
1045 | 990 |
1046 widget->CloseNow(); | 991 widget->CloseNow(); |
1047 } | 992 } |
1048 #endif | 993 #endif |
1049 | 994 |
1050 #if defined(OS_WIN) | 995 #if defined(OS_WIN) |
1051 TEST_F(ViewTest, HiddenViewWithAccelerator) { | 996 TEST_F(ViewTest, HiddenViewWithAccelerator) { |
1052 views::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); | 997 Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); |
1053 TestView* view = new TestView(); | 998 TestView* view = new TestView(); |
1054 view->Reset(); | 999 view->Reset(); |
1055 view->AddAccelerator(return_accelerator); | 1000 view->AddAccelerator(return_accelerator); |
1056 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 1001 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
1057 | 1002 |
1058 scoped_ptr<Widget> widget(Widget::CreateWidget()); | 1003 scoped_ptr<Widget> widget(new Widget); |
1059 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 1004 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
1060 params.delete_on_destroy = false; | 1005 params.delete_on_destroy = false; |
1061 params.bounds = gfx::Rect(0, 0, 100, 100); | 1006 params.bounds = gfx::Rect(0, 0, 100, 100); |
1062 widget->Init(params); | 1007 widget->Init(params); |
1063 RootView* root = widget->GetRootView(); | 1008 RootView* root = widget->GetRootView(); |
1064 root->AddChildView(view); | 1009 root->AddChildView(view); |
1065 | 1010 |
1066 views::FocusManager* focus_manager = | 1011 FocusManager* focus_manager = FocusManager::GetFocusManagerForNativeView( |
1067 views::FocusManager::GetFocusManagerForNativeView( | 1012 widget->GetNativeView()); |
1068 widget->GetNativeView()); | |
1069 ASSERT_TRUE(focus_manager); | 1013 ASSERT_TRUE(focus_manager); |
1070 | 1014 |
1071 view->SetVisible(false); | 1015 view->SetVisible(false); |
1072 EXPECT_EQ(NULL, | 1016 EXPECT_EQ(NULL, |
1073 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); | 1017 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); |
1074 | 1018 |
1075 view->SetVisible(true); | 1019 view->SetVisible(true); |
1076 EXPECT_EQ(view, | 1020 EXPECT_EQ(view, |
1077 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); | 1021 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); |
1078 | 1022 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 // under the mouse. | 1094 // under the mouse. |
1151 // TODO(jcampan): http://crbug.com/10572 Disabled as it fails on the Vista build | 1095 // TODO(jcampan): http://crbug.com/10572 Disabled as it fails on the Vista build |
1152 // bot. | 1096 // bot. |
1153 // Note that this fails for a variety of reasons: | 1097 // Note that this fails for a variety of reasons: |
1154 // - focused view is apparently reset across window activations and never | 1098 // - focused view is apparently reset across window activations and never |
1155 // properly restored | 1099 // properly restored |
1156 // - this test depends on you not having any other window visible open under the | 1100 // - this test depends on you not having any other window visible open under the |
1157 // area that it opens the test windows. --beng | 1101 // area that it opens the test windows. --beng |
1158 TEST_F(ViewTest, DISABLED_RerouteMouseWheelTest) { | 1102 TEST_F(ViewTest, DISABLED_RerouteMouseWheelTest) { |
1159 TestViewWithControls* view_with_controls = new TestViewWithControls(); | 1103 TestViewWithControls* view_with_controls = new TestViewWithControls(); |
1160 views::Window* window1 = | 1104 Window* window1 = Window::CreateChromeWindow( |
1161 views::Window::CreateChromeWindow( | 1105 NULL, gfx::Rect(0, 0, 100, 100), |
1162 NULL, gfx::Rect(0, 0, 100, 100), | 1106 new SimpleWindowDelegate(view_with_controls)); |
1163 new SimpleWindowDelegate(view_with_controls)); | |
1164 window1->Show(); | 1107 window1->Show(); |
1165 ScrollView* scroll_view = new ScrollView(); | 1108 ScrollView* scroll_view = new ScrollView(); |
1166 scroll_view->SetContents(new ScrollableTestView()); | 1109 scroll_view->SetContents(new ScrollableTestView()); |
1167 views::Window* window2 = | 1110 Window* window2 = Window::CreateChromeWindow( |
1168 views::Window::CreateChromeWindow(NULL, gfx::Rect(200, 200, 100, 100), | 1111 NULL, gfx::Rect(200, 200, 100, 100), |
1169 new SimpleWindowDelegate(scroll_view)); | 1112 new SimpleWindowDelegate(scroll_view)); |
1170 window2->Show(); | 1113 window2->Show(); |
1171 EXPECT_EQ(0, scroll_view->GetVisibleRect().y()); | 1114 EXPECT_EQ(0, scroll_view->GetVisibleRect().y()); |
1172 | 1115 |
1173 // Make the window1 active, as this is what it would be in real-world. | 1116 // Make the window1 active, as this is what it would be in real-world. |
1174 window1->Activate(); | 1117 window1->Activate(); |
1175 | 1118 |
1176 // Let's send a mouse-wheel message to the different controls and check that | 1119 // Let's send a mouse-wheel message to the different controls and check that |
1177 // it is rerouted to the window under the mouse (effectively scrolling the | 1120 // it is rerouted to the window under the mouse (effectively scrolling the |
1178 // scroll-view). | 1121 // scroll-view). |
1179 | 1122 |
(...skipping 14 matching lines...) Expand all Loading... |
1194 | 1137 |
1195 // Then the text-field. | 1138 // Then the text-field. |
1196 ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), | 1139 ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), |
1197 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | 1140 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); |
1198 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); | 1141 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); |
1199 | 1142 |
1200 // Ensure we don't scroll when the mouse is not over that window. | 1143 // Ensure we don't scroll when the mouse is not over that window. |
1201 ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), | 1144 ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), |
1202 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(50, 50)); | 1145 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(50, 50)); |
1203 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); | 1146 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); |
| 1147 |
| 1148 window1->CloseNow(); |
| 1149 window2->CloseNow(); |
1204 } | 1150 } |
1205 #endif | 1151 #endif |
1206 | 1152 |
1207 //////////////////////////////////////////////////////////////////////////////// | 1153 //////////////////////////////////////////////////////////////////////////////// |
1208 // Dialogs' default button | 1154 // Dialogs' default button |
1209 //////////////////////////////////////////////////////////////////////////////// | 1155 //////////////////////////////////////////////////////////////////////////////// |
1210 | 1156 |
1211 namespace ui { | 1157 class MockMenuModel : public ui::MenuModel { |
1212 class MockMenuModel : public MenuModel { | |
1213 public: | 1158 public: |
1214 MOCK_CONST_METHOD0(HasIcons, bool()); | 1159 MOCK_CONST_METHOD0(HasIcons, bool()); |
1215 MOCK_CONST_METHOD1(GetFirstItemIndex, int(gfx::NativeMenu native_menu)); | 1160 MOCK_CONST_METHOD1(GetFirstItemIndex, int(gfx::NativeMenu native_menu)); |
1216 MOCK_CONST_METHOD0(GetItemCount, int()); | 1161 MOCK_CONST_METHOD0(GetItemCount, int()); |
1217 MOCK_CONST_METHOD1(GetTypeAt, ItemType(int index)); | 1162 MOCK_CONST_METHOD1(GetTypeAt, ItemType(int index)); |
1218 MOCK_CONST_METHOD1(GetCommandIdAt, int(int index)); | 1163 MOCK_CONST_METHOD1(GetCommandIdAt, int(int index)); |
1219 MOCK_CONST_METHOD1(GetLabelAt, string16(int index)); | 1164 MOCK_CONST_METHOD1(GetLabelAt, string16(int index)); |
1220 MOCK_CONST_METHOD1(IsItemDynamicAt, bool(int index)); | 1165 MOCK_CONST_METHOD1(IsItemDynamicAt, bool(int index)); |
1221 MOCK_CONST_METHOD1(GetLabelFontAt, const gfx::Font* (int index)); | 1166 MOCK_CONST_METHOD1(GetLabelFontAt, const gfx::Font* (int index)); |
1222 MOCK_CONST_METHOD2(GetAcceleratorAt, bool(int index, | 1167 MOCK_CONST_METHOD2(GetAcceleratorAt, bool(int index, |
1223 ui::Accelerator* accelerator)); | 1168 ui::Accelerator* accelerator)); |
1224 MOCK_CONST_METHOD1(IsItemCheckedAt, bool(int index)); | 1169 MOCK_CONST_METHOD1(IsItemCheckedAt, bool(int index)); |
1225 MOCK_CONST_METHOD1(GetGroupIdAt, int(int index)); | 1170 MOCK_CONST_METHOD1(GetGroupIdAt, int(int index)); |
1226 MOCK_METHOD2(GetIconAt, bool(int index, SkBitmap* icon)); | 1171 MOCK_METHOD2(GetIconAt, bool(int index, SkBitmap* icon)); |
1227 MOCK_CONST_METHOD1(GetButtonMenuItemAt, ButtonMenuItemModel*(int index)); | 1172 MOCK_CONST_METHOD1(GetButtonMenuItemAt, ui::ButtonMenuItemModel*(int index)); |
1228 MOCK_CONST_METHOD1(IsEnabledAt, bool(int index)); | 1173 MOCK_CONST_METHOD1(IsEnabledAt, bool(int index)); |
1229 MOCK_CONST_METHOD1(IsVisibleAt, bool(int index)); | 1174 MOCK_CONST_METHOD1(IsVisibleAt, bool(int index)); |
1230 MOCK_CONST_METHOD1(GetSubmenuModelAt, MenuModel*(int index)); | 1175 MOCK_CONST_METHOD1(GetSubmenuModelAt, MenuModel*(int index)); |
1231 MOCK_METHOD1(HighlightChangedTo, void(int index)); | 1176 MOCK_METHOD1(HighlightChangedTo, void(int index)); |
1232 MOCK_METHOD1(ActivatedAt, void(int index)); | 1177 MOCK_METHOD1(ActivatedAt, void(int index)); |
1233 MOCK_METHOD2(ActivatedAtWithDisposition, void(int index, | 1178 MOCK_METHOD2(ActivatedAtWithDisposition, void(int index, |
1234 int disposition)); | 1179 int disposition)); |
1235 MOCK_METHOD0(MenuWillShow, void()); | 1180 MOCK_METHOD0(MenuWillShow, void()); |
1236 MOCK_METHOD0(MenuClosed, void()); | 1181 MOCK_METHOD0(MenuClosed, void()); |
1237 MOCK_METHOD1(SetMenuModelDelegate, void(MenuModelDelegate* delegate)); | 1182 MOCK_METHOD1(SetMenuModelDelegate, void(ui::MenuModelDelegate* delegate)); |
1238 MOCK_METHOD3(GetModelAndIndexForCommandId, bool(int command_id, | 1183 MOCK_METHOD3(GetModelAndIndexForCommandId, bool(int command_id, |
1239 MenuModel** model, int* index)); | 1184 MenuModel** model, int* index)); |
1240 }; | 1185 }; |
1241 } | |
1242 | 1186 |
1243 class TestDialog : public DialogDelegate, public ButtonListener { | 1187 class TestDialog : public DialogDelegate, public ButtonListener { |
1244 public: | 1188 public: |
1245 explicit TestDialog(ui::MockMenuModel* mock_menu_model) | 1189 explicit TestDialog(MockMenuModel* mock_menu_model) |
1246 : contents_(NULL), | 1190 : contents_(NULL), |
1247 button1_(NULL), | 1191 button1_(NULL), |
1248 button2_(NULL), | 1192 button2_(NULL), |
1249 checkbox_(NULL), | 1193 checkbox_(NULL), |
1250 button_drop_(NULL), | 1194 button_drop_(NULL), |
1251 last_pressed_button_(NULL), | 1195 last_pressed_button_(NULL), |
1252 mock_menu_model_(mock_menu_model), | 1196 mock_menu_model_(mock_menu_model), |
1253 canceled_(false), | 1197 canceled_(false), |
1254 oked_(false) { | 1198 oked_(false) { |
1255 } | 1199 } |
1256 | 1200 |
1257 // views::DialogDelegate implementation: | 1201 // DialogDelegate implementation: |
1258 virtual int GetDefaultDialogButton() const { | 1202 virtual int GetDefaultDialogButton() const { |
1259 return MessageBoxFlags::DIALOGBUTTON_OK; | 1203 return MessageBoxFlags::DIALOGBUTTON_OK; |
1260 } | 1204 } |
1261 | 1205 |
1262 virtual View* GetContentsView() { | 1206 virtual View* GetContentsView() { |
1263 if (!contents_) { | 1207 if (!contents_) { |
1264 contents_ = new View(); | 1208 contents_ = new View(); |
1265 button1_ = new NativeButtonBase(this, L"Button1"); | 1209 button1_ = new NativeButtonBase(this, L"Button1"); |
1266 button2_ = new NativeButtonBase(this, L"Button2"); | 1210 button2_ = new NativeButtonBase(this, L"Button2"); |
1267 checkbox_ = new Checkbox(L"My checkbox"); | 1211 checkbox_ = new Checkbox(L"My checkbox"); |
(...skipping 10 matching lines...) Expand all Loading... |
1278 // buttons to our heart's content). | 1222 // buttons to our heart's content). |
1279 virtual bool Cancel() { | 1223 virtual bool Cancel() { |
1280 canceled_ = true; | 1224 canceled_ = true; |
1281 return false; | 1225 return false; |
1282 } | 1226 } |
1283 virtual bool Accept() { | 1227 virtual bool Accept() { |
1284 oked_ = true; | 1228 oked_ = true; |
1285 return false; | 1229 return false; |
1286 } | 1230 } |
1287 | 1231 |
1288 // views::ButtonListener implementation. | 1232 // ButtonListener implementation. |
1289 virtual void ButtonPressed(Button* sender, const views::Event& event) { | 1233 virtual void ButtonPressed(Button* sender, const Event& event) { |
1290 last_pressed_button_ = sender; | 1234 last_pressed_button_ = sender; |
1291 } | 1235 } |
1292 | 1236 |
1293 void ResetStates() { | 1237 void ResetStates() { |
1294 oked_ = false; | 1238 oked_ = false; |
1295 canceled_ = false; | 1239 canceled_ = false; |
1296 last_pressed_button_ = NULL; | 1240 last_pressed_button_ = NULL; |
1297 } | 1241 } |
1298 | 1242 |
1299 // Set up expectations for methods that are called when an (empty) menu is | 1243 // Set up expectations for methods that are called when an (empty) menu is |
1300 // shown from a drop down button. | 1244 // shown from a drop down button. |
1301 void ExpectShowDropMenu() { | 1245 void ExpectShowDropMenu() { |
1302 if (mock_menu_model_) { | 1246 if (mock_menu_model_) { |
1303 EXPECT_CALL(*mock_menu_model_, HasIcons()); | 1247 EXPECT_CALL(*mock_menu_model_, HasIcons()); |
1304 EXPECT_CALL(*mock_menu_model_, GetFirstItemIndex(_)); | 1248 EXPECT_CALL(*mock_menu_model_, GetFirstItemIndex(_)); |
1305 EXPECT_CALL(*mock_menu_model_, GetItemCount()); | 1249 EXPECT_CALL(*mock_menu_model_, GetItemCount()); |
1306 EXPECT_CALL(*mock_menu_model_, MenuClosed()); | 1250 EXPECT_CALL(*mock_menu_model_, MenuClosed()); |
1307 } | 1251 } |
1308 } | 1252 } |
1309 | 1253 |
1310 View* contents_; | 1254 View* contents_; |
1311 NativeButtonBase* button1_; | 1255 NativeButtonBase* button1_; |
1312 NativeButtonBase* button2_; | 1256 NativeButtonBase* button2_; |
1313 NativeButtonBase* checkbox_; | 1257 NativeButtonBase* checkbox_; |
1314 ButtonDropDown* button_drop_; | 1258 ButtonDropDown* button_drop_; |
1315 Button* last_pressed_button_; | 1259 Button* last_pressed_button_; |
1316 ui::MockMenuModel* mock_menu_model_; | 1260 MockMenuModel* mock_menu_model_; |
1317 | 1261 |
1318 bool canceled_; | 1262 bool canceled_; |
1319 bool oked_; | 1263 bool oked_; |
1320 }; | 1264 }; |
1321 | 1265 |
1322 class DefaultButtonTest : public ViewTest { | 1266 class DefaultButtonTest : public ViewTest { |
1323 public: | 1267 public: |
1324 enum ButtonID { | 1268 enum ButtonID { |
1325 OK, | 1269 OK, |
1326 CANCEL, | 1270 CANCEL, |
1327 BUTTON1, | 1271 BUTTON1, |
1328 BUTTON2 | 1272 BUTTON2 |
1329 }; | 1273 }; |
1330 | 1274 |
1331 DefaultButtonTest() | 1275 DefaultButtonTest() |
1332 : focus_manager_(NULL), | 1276 : focus_manager_(NULL), |
1333 test_dialog_(NULL), | 1277 test_dialog_(NULL), |
1334 client_view_(NULL), | 1278 client_view_(NULL), |
1335 ok_button_(NULL), | 1279 ok_button_(NULL), |
1336 cancel_button_(NULL) { | 1280 cancel_button_(NULL) { |
1337 } | 1281 } |
1338 | 1282 |
1339 virtual void SetUp() { | 1283 virtual void SetUp() { |
1340 test_dialog_ = new TestDialog(NULL); | 1284 test_dialog_ = new TestDialog(NULL); |
1341 views::Window* window = | 1285 Window* window = Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 100, 100), |
1342 views::Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 100, 100), | 1286 test_dialog_); |
1343 test_dialog_); | |
1344 window->Show(); | 1287 window->Show(); |
1345 focus_manager_ = test_dialog_->contents_->GetFocusManager(); | 1288 focus_manager_ = test_dialog_->contents_->GetFocusManager(); |
1346 ASSERT_TRUE(focus_manager_ != NULL); | 1289 ASSERT_TRUE(focus_manager_ != NULL); |
1347 client_view_ = | 1290 client_view_ = |
1348 static_cast<views::DialogClientView*>(window->client_view()); | 1291 static_cast<DialogClientView*>(window->client_view()); |
1349 ok_button_ = client_view_->ok_button(); | 1292 ok_button_ = client_view_->ok_button(); |
1350 cancel_button_ = client_view_->cancel_button(); | 1293 cancel_button_ = client_view_->cancel_button(); |
1351 } | 1294 } |
1352 | 1295 |
1353 void SimulatePressingEnterAndCheckDefaultButton(ButtonID button_id) { | 1296 void SimulatePressingEnterAndCheckDefaultButton(ButtonID button_id) { |
1354 KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0); | 1297 KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0); |
1355 focus_manager_->OnKeyEvent(event); | 1298 focus_manager_->OnKeyEvent(event); |
1356 switch (button_id) { | 1299 switch (button_id) { |
1357 case OK: | 1300 case OK: |
1358 EXPECT_TRUE(test_dialog_->oked_); | 1301 EXPECT_TRUE(test_dialog_->oked_); |
(...skipping 14 matching lines...) Expand all Loading... |
1373 case BUTTON2: | 1316 case BUTTON2: |
1374 EXPECT_FALSE(test_dialog_->oked_); | 1317 EXPECT_FALSE(test_dialog_->oked_); |
1375 EXPECT_FALSE(test_dialog_->canceled_); | 1318 EXPECT_FALSE(test_dialog_->canceled_); |
1376 EXPECT_TRUE(test_dialog_->last_pressed_button_ == | 1319 EXPECT_TRUE(test_dialog_->last_pressed_button_ == |
1377 test_dialog_->button2_); | 1320 test_dialog_->button2_); |
1378 break; | 1321 break; |
1379 } | 1322 } |
1380 test_dialog_->ResetStates(); | 1323 test_dialog_->ResetStates(); |
1381 } | 1324 } |
1382 | 1325 |
1383 views::FocusManager* focus_manager_; | 1326 FocusManager* focus_manager_; |
1384 TestDialog* test_dialog_; | 1327 TestDialog* test_dialog_; |
1385 DialogClientView* client_view_; | 1328 DialogClientView* client_view_; |
1386 views::NativeButton* ok_button_; | 1329 NativeButton* ok_button_; |
1387 views::NativeButton* cancel_button_; | 1330 NativeButton* cancel_button_; |
1388 }; | 1331 }; |
1389 | 1332 |
1390 TEST_F(DefaultButtonTest, DialogDefaultButtonTest) { | 1333 TEST_F(DefaultButtonTest, DialogDefaultButtonTest) { |
1391 // Window has just been shown, we expect the default button specified in the | 1334 // Window has just been shown, we expect the default button specified in the |
1392 // DialogDelegate. | 1335 // DialogDelegate. |
1393 EXPECT_TRUE(ok_button_->is_default()); | 1336 EXPECT_TRUE(ok_button_->is_default()); |
1394 | 1337 |
1395 // Simulate pressing enter, that should trigger the OK button. | 1338 // Simulate pressing enter, that should trigger the OK button. |
1396 SimulatePressingEnterAndCheckDefaultButton(OK); | 1339 SimulatePressingEnterAndCheckDefaultButton(OK); |
1397 | 1340 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 | 1379 |
1437 class ButtonDropDownTest : public ViewTest { | 1380 class ButtonDropDownTest : public ViewTest { |
1438 public: | 1381 public: |
1439 ButtonDropDownTest() | 1382 ButtonDropDownTest() |
1440 : test_dialog_(NULL), | 1383 : test_dialog_(NULL), |
1441 button_as_view_(NULL) { | 1384 button_as_view_(NULL) { |
1442 } | 1385 } |
1443 | 1386 |
1444 virtual void SetUp() { | 1387 virtual void SetUp() { |
1445 test_dialog_ = new TestDialog(&mock_menu_model_); | 1388 test_dialog_ = new TestDialog(&mock_menu_model_); |
1446 views::Window* window = | 1389 Window* window = Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 100, 100), |
1447 views::Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 100, 100), | 1390 test_dialog_); |
1448 test_dialog_); | |
1449 window->Show(); | 1391 window->Show(); |
1450 test_dialog_->button_drop_->SetBounds(0, 0, 100, 100); | 1392 test_dialog_->button_drop_->SetBounds(0, 0, 100, 100); |
1451 // We have to cast the button back into a View in order to invoke it's | 1393 // We have to cast the button back into a View in order to invoke it's |
1452 // OnMouseReleased method. | 1394 // OnMouseReleased method. |
1453 button_as_view_ = static_cast<View*>(test_dialog_->button_drop_); | 1395 button_as_view_ = static_cast<View*>(test_dialog_->button_drop_); |
1454 } | 1396 } |
1455 | 1397 |
1456 TestDialog* test_dialog_; | 1398 TestDialog* test_dialog_; |
1457 ui::MockMenuModel mock_menu_model_; | 1399 MockMenuModel mock_menu_model_; |
1458 // This is owned by test_dialog_. | 1400 // This is owned by test_dialog_. |
1459 View* button_as_view_; | 1401 View* button_as_view_; |
1460 | 1402 |
1461 private: | 1403 private: |
1462 DISALLOW_COPY_AND_ASSIGN(ButtonDropDownTest); | 1404 DISALLOW_COPY_AND_ASSIGN(ButtonDropDownTest); |
1463 }; | 1405 }; |
1464 | 1406 |
1465 // Ensure that regular clicks on the drop down button still work. (i.e. - the | 1407 // Ensure that regular clicks on the drop down button still work. (i.e. - the |
1466 // click events are processed and the listener gets the click) | 1408 // click events are processed and the listener gets the click) |
1467 TEST_F(ButtonDropDownTest, RegularClickTest) { | 1409 TEST_F(ButtonDropDownTest, RegularClickTest) { |
(...skipping 24 matching lines...) Expand all Loading... |
1492 //////////////////////////////////////////////////////////////////////////////// | 1434 //////////////////////////////////////////////////////////////////////////////// |
1493 // View hierarchy / Visibility changes | 1435 // View hierarchy / Visibility changes |
1494 //////////////////////////////////////////////////////////////////////////////// | 1436 //////////////////////////////////////////////////////////////////////////////// |
1495 /* | 1437 /* |
1496 TEST_F(ViewTest, ChangeVisibility) { | 1438 TEST_F(ViewTest, ChangeVisibility) { |
1497 #if defined(OS_LINUX) | 1439 #if defined(OS_LINUX) |
1498 // Make CRITICAL messages fatal | 1440 // Make CRITICAL messages fatal |
1499 // TODO(oshima): we probably should enable this for entire tests on linux. | 1441 // TODO(oshima): we probably should enable this for entire tests on linux. |
1500 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); | 1442 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); |
1501 #endif | 1443 #endif |
1502 scoped_ptr<views::Widget> window(CreateWidget()); | 1444 scoped_ptr<Widget> window(CreateWidget()); |
1503 window->Init(NULL, gfx::Rect(0, 0, 500, 300)); | 1445 window->Init(NULL, gfx::Rect(0, 0, 500, 300)); |
1504 views::RootView* root_view = window->GetRootView(); | 1446 RootView* root_view = window->GetRootView(); |
1505 NativeButtonBase* native = new NativeButtonBase(NULL, L"Native"); | 1447 NativeButtonBase* native = new NativeButtonBase(NULL, L"Native"); |
1506 | 1448 |
1507 root_view->SetContentsView(native); | 1449 root_view->SetContentsView(native); |
1508 native->SetVisible(true); | 1450 native->SetVisible(true); |
1509 | 1451 |
1510 root_view->RemoveChildView(native); | 1452 root_view->RemoveChildView(native); |
1511 native->SetVisible(false); | 1453 native->SetVisible(false); |
1512 // Change visibility to true with no widget. | 1454 // Change visibility to true with no widget. |
1513 native->SetVisible(true); | 1455 native->SetVisible(true); |
1514 | 1456 |
1515 root_view->SetContentsView(native); | 1457 root_view->SetContentsView(native); |
1516 native->SetVisible(true); | 1458 native->SetVisible(true); |
1517 } | 1459 } |
1518 */ | 1460 */ |
1519 | 1461 |
1520 //////////////////////////////////////////////////////////////////////////////// | 1462 //////////////////////////////////////////////////////////////////////////////// |
1521 // Native view hierachy | 1463 // Native view hierachy |
1522 //////////////////////////////////////////////////////////////////////////////// | 1464 //////////////////////////////////////////////////////////////////////////////// |
1523 class TestNativeViewHierarchy : public views::View { | 1465 class TestNativeViewHierarchy : public View { |
1524 public: | 1466 public: |
1525 TestNativeViewHierarchy() { | 1467 TestNativeViewHierarchy() { |
1526 } | 1468 } |
1527 | 1469 |
1528 virtual void NativeViewHierarchyChanged(bool attached, | 1470 virtual void NativeViewHierarchyChanged(bool attached, |
1529 gfx::NativeView native_view, | 1471 gfx::NativeView native_view, |
1530 RootView* root_view) { | 1472 RootView* root_view) { |
1531 NotificationInfo info; | 1473 NotificationInfo info; |
1532 info.attached = attached; | 1474 info.attached = attached; |
1533 info.native_view = native_view; | 1475 info.native_view = native_view; |
1534 info.root_view = root_view; | 1476 info.root_view = root_view; |
1535 notifications_.push_back(info); | 1477 notifications_.push_back(info); |
1536 }; | 1478 }; |
1537 struct NotificationInfo { | 1479 struct NotificationInfo { |
1538 bool attached; | 1480 bool attached; |
1539 gfx::NativeView native_view; | 1481 gfx::NativeView native_view; |
1540 RootView* root_view; | 1482 RootView* root_view; |
1541 }; | 1483 }; |
1542 static const size_t kTotalViews = 2; | 1484 static const size_t kTotalViews = 2; |
1543 std::vector<NotificationInfo> notifications_; | 1485 std::vector<NotificationInfo> notifications_; |
1544 }; | 1486 }; |
1545 | 1487 |
1546 class TestChangeNativeViewHierarchy { | 1488 class TestChangeNativeViewHierarchy { |
1547 public: | 1489 public: |
1548 explicit TestChangeNativeViewHierarchy(ViewTest *view_test) { | 1490 explicit TestChangeNativeViewHierarchy(ViewTest *view_test) { |
1549 view_test_ = view_test; | 1491 view_test_ = view_test; |
1550 native_host_ = new views::NativeViewHost(); | 1492 native_host_ = new NativeViewHost(); |
1551 host_ = Widget::CreateWidget(); | 1493 host_ = new Widget; |
1552 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 1494 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
1553 params.bounds = gfx::Rect(0, 0, 500, 300); | 1495 params.bounds = gfx::Rect(0, 0, 500, 300); |
1554 host_->Init(params); | 1496 host_->Init(params); |
1555 host_->GetRootView()->AddChildView(native_host_); | 1497 host_->GetRootView()->AddChildView(native_host_); |
1556 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) { | 1498 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) { |
1557 windows_[i] = Widget::CreateWidget(); | 1499 windows_[i] = new Widget; |
1558 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 1500 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
1559 params.parent = host_->GetNativeView(); | 1501 params.parent = host_->GetNativeView(); |
1560 params.bounds = gfx::Rect(0, 0, 500, 300); | 1502 params.bounds = gfx::Rect(0, 0, 500, 300); |
1561 windows_[i]->Init(params); | 1503 windows_[i]->Init(params); |
1562 root_views_[i] = windows_[i]->GetRootView(); | 1504 root_views_[i] = windows_[i]->GetRootView(); |
1563 test_views_[i] = new TestNativeViewHierarchy; | 1505 test_views_[i] = new TestNativeViewHierarchy; |
1564 root_views_[i]->AddChildView(test_views_[i]); | 1506 root_views_[i]->AddChildView(test_views_[i]); |
1565 } | 1507 } |
1566 } | 1508 } |
1567 | 1509 |
1568 ~TestChangeNativeViewHierarchy() { | 1510 ~TestChangeNativeViewHierarchy() { |
1569 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) { | 1511 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) { |
1570 windows_[i]->Close(); | 1512 windows_[i]->Close(); |
1571 } | 1513 } |
1572 host_->Close(); | 1514 host_->Close(); |
1573 // Will close and self-delete widgets - no need to manually delete them. | 1515 // Will close and self-delete widgets - no need to manually delete them. |
1574 view_test_->RunPendingMessages(); | 1516 view_test_->RunPendingMessages(); |
1575 } | 1517 } |
1576 | 1518 |
1577 void CheckEnumeratingNativeWidgets() { | 1519 void CheckEnumeratingNativeWidgets() { |
1578 if (!host_->GetWindow()) | 1520 if (!host_->GetContainingWindow()) |
1579 return; | 1521 return; |
1580 NativeWidget::NativeWidgets widgets; | 1522 NativeWidget::NativeWidgets widgets; |
1581 NativeWidget::GetAllNativeWidgets(host_->GetNativeView(), &widgets); | 1523 NativeWidget::GetAllNativeWidgets(host_->GetNativeView(), &widgets); |
1582 EXPECT_EQ(TestNativeViewHierarchy::kTotalViews + 1, widgets.size()); | 1524 EXPECT_EQ(TestNativeViewHierarchy::kTotalViews + 1, widgets.size()); |
1583 // Unfortunately there is no guarantee the sequence of views here so always | 1525 // Unfortunately there is no guarantee the sequence of views here so always |
1584 // go through all of them. | 1526 // go through all of them. |
1585 for (NativeWidget::NativeWidgets::iterator i = widgets.begin(); | 1527 for (NativeWidget::NativeWidgets::iterator i = widgets.begin(); |
1586 i != widgets.end(); ++i) { | 1528 i != widgets.end(); ++i) { |
1587 RootView* root_view = (*i)->GetWidget()->GetRootView(); | 1529 RootView* root_view = (*i)->GetWidget()->GetRootView(); |
1588 if (host_->GetRootView() == root_view) | 1530 if (host_->GetRootView() == root_view) |
(...skipping 25 matching lines...) Expand all Loading... |
1614 EXPECT_EQ(host_->GetNativeView(), | 1556 EXPECT_EQ(host_->GetNativeView(), |
1615 test_views_[i]->notifications_[0].native_view); | 1557 test_views_[i]->notifications_[0].native_view); |
1616 EXPECT_EQ(root_views_[i], test_views_[i]->notifications_[0].root_view); | 1558 EXPECT_EQ(root_views_[i], test_views_[i]->notifications_[0].root_view); |
1617 EXPECT_TRUE(test_views_[i]->notifications_[1].attached); | 1559 EXPECT_TRUE(test_views_[i]->notifications_[1].attached); |
1618 EXPECT_EQ(host_->GetNativeView(), | 1560 EXPECT_EQ(host_->GetNativeView(), |
1619 test_views_[i]->notifications_[1].native_view); | 1561 test_views_[i]->notifications_[1].native_view); |
1620 EXPECT_EQ(root_views_[i], test_views_[i]->notifications_[1].root_view); | 1562 EXPECT_EQ(root_views_[i], test_views_[i]->notifications_[1].root_view); |
1621 } | 1563 } |
1622 } | 1564 } |
1623 | 1565 |
1624 views::NativeViewHost* native_host_; | 1566 NativeViewHost* native_host_; |
1625 views::Widget* host_; | 1567 Widget* host_; |
1626 views::Widget* windows_[TestNativeViewHierarchy::kTotalViews]; | 1568 Widget* windows_[TestNativeViewHierarchy::kTotalViews]; |
1627 views::RootView* root_views_[TestNativeViewHierarchy::kTotalViews]; | 1569 RootView* root_views_[TestNativeViewHierarchy::kTotalViews]; |
1628 TestNativeViewHierarchy* test_views_[TestNativeViewHierarchy::kTotalViews]; | 1570 TestNativeViewHierarchy* test_views_[TestNativeViewHierarchy::kTotalViews]; |
1629 ViewTest* view_test_; | 1571 ViewTest* view_test_; |
1630 }; | 1572 }; |
1631 | 1573 |
1632 TEST_F(ViewTest, ChangeNativeViewHierarchyFindRoots) { | 1574 TEST_F(ViewTest, ChangeNativeViewHierarchyFindRoots) { |
1633 // TODO(georgey): Fix the test for Linux | 1575 // TODO(georgey): Fix the test for Linux |
1634 #if defined(OS_WIN) | 1576 #if defined(OS_WIN) |
1635 TestChangeNativeViewHierarchy test(this); | 1577 TestChangeNativeViewHierarchy test(this); |
1636 test.CheckEnumeratingNativeWidgets(); | 1578 test.CheckEnumeratingNativeWidgets(); |
1637 #endif | 1579 #endif |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 DISALLOW_COPY_AND_ASSIGN(TransformPaintView); | 1614 DISALLOW_COPY_AND_ASSIGN(TransformPaintView); |
1673 }; | 1615 }; |
1674 | 1616 |
1675 TEST_F(ViewTest, TransformPaint) { | 1617 TEST_F(ViewTest, TransformPaint) { |
1676 TransformPaintView* v1 = new TransformPaintView(); | 1618 TransformPaintView* v1 = new TransformPaintView(); |
1677 v1->SetBounds(0, 0, 500, 300); | 1619 v1->SetBounds(0, 0, 500, 300); |
1678 | 1620 |
1679 TestView* v2 = new TestView(); | 1621 TestView* v2 = new TestView(); |
1680 v2->SetBounds(100, 100, 200, 100); | 1622 v2->SetBounds(100, 100, 200, 100); |
1681 | 1623 |
1682 Widget* widget = Widget::CreateWidget(); | 1624 Widget* widget = new Widget; |
1683 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 1625 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
1684 params.bounds = gfx::Rect(50, 50, 650, 650); | 1626 params.bounds = gfx::Rect(50, 50, 650, 650); |
1685 widget->Init(params); | 1627 widget->Init(params); |
1686 widget->Show(); | 1628 widget->Show(); |
1687 RootView* root = widget->GetRootView(); | 1629 RootView* root = widget->GetRootView(); |
1688 | 1630 |
1689 root->AddChildView(v1); | 1631 root->AddChildView(v1); |
1690 v1->AddChildView(v2); | 1632 v1->AddChildView(v2); |
1691 | 1633 |
1692 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. | 1634 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. |
(...skipping 16 matching lines...) Expand all Loading... |
1709 widget->CloseNow(); | 1651 widget->CloseNow(); |
1710 } | 1652 } |
1711 | 1653 |
1712 TEST_F(ViewTest, TransformEvent) { | 1654 TEST_F(ViewTest, TransformEvent) { |
1713 TestView* v1 = new TestView(); | 1655 TestView* v1 = new TestView(); |
1714 v1->SetBounds(0, 0, 500, 300); | 1656 v1->SetBounds(0, 0, 500, 300); |
1715 | 1657 |
1716 TestView* v2 = new TestView(); | 1658 TestView* v2 = new TestView(); |
1717 v2->SetBounds(100, 100, 200, 100); | 1659 v2->SetBounds(100, 100, 200, 100); |
1718 | 1660 |
1719 Widget* widget = Widget::CreateWidget(); | 1661 Widget* widget = new Widget; |
1720 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 1662 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
1721 params.bounds = gfx::Rect(50, 50, 650, 650); | 1663 params.bounds = gfx::Rect(50, 50, 650, 650); |
1722 widget->Init(params); | 1664 widget->Init(params); |
1723 RootView* root = widget->GetRootView(); | 1665 RootView* root = widget->GetRootView(); |
1724 | 1666 |
1725 root->AddChildView(v1); | 1667 root->AddChildView(v1); |
1726 v1->AddChildView(v2); | 1668 v1->AddChildView(v2); |
1727 | 1669 |
1728 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. | 1670 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. |
1729 | 1671 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 bool received_notification_; | 1801 bool received_notification_; |
1860 | 1802 |
1861 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView); | 1803 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView); |
1862 }; | 1804 }; |
1863 | 1805 |
1864 #if defined(OS_WIN) | 1806 #if defined(OS_WIN) |
1865 // TODO(beng): This can be cross platform when widget construction/init is. | 1807 // TODO(beng): This can be cross platform when widget construction/init is. |
1866 TEST_F(ViewTest, OnVisibleBoundsChanged) { | 1808 TEST_F(ViewTest, OnVisibleBoundsChanged) { |
1867 gfx::Rect viewport_bounds(0, 0, 100, 100); | 1809 gfx::Rect viewport_bounds(0, 0, 100, 100); |
1868 | 1810 |
1869 scoped_ptr<Widget> widget(Widget::CreateWidget()); | 1811 scoped_ptr<Widget> widget(new Widget); |
1870 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 1812 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
1871 params.delete_on_destroy = false; | 1813 params.delete_on_destroy = false; |
1872 params.bounds = viewport_bounds; | 1814 params.bounds = viewport_bounds; |
1873 widget->Init(params); | 1815 widget->Init(params); |
1874 widget->GetRootView()->SetBoundsRect(viewport_bounds); | 1816 widget->GetRootView()->SetBoundsRect(viewport_bounds); |
1875 | 1817 |
1876 View* viewport = new View; | 1818 View* viewport = new View; |
1877 widget->GetRootView()->SetContentsView(viewport); | 1819 widget->GetRootView()->SetContentsView(viewport); |
1878 View* contents = new View; | 1820 View* contents = new View; |
1879 viewport->AddChildView(contents); | 1821 viewport->AddChildView(contents); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 top_view->scheduled_paint_rects_.clear(); | 1867 top_view->scheduled_paint_rects_.clear(); |
1926 child_view->SetBounds(30, 30, 20, 20); | 1868 child_view->SetBounds(30, 30, 20, 20); |
1927 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size()); | 1869 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size()); |
1928 | 1870 |
1929 // There should be 2 rects, spanning from (10, 10) to (50, 50). | 1871 // There should be 2 rects, spanning from (10, 10) to (50, 50). |
1930 gfx::Rect paint_rect = | 1872 gfx::Rect paint_rect = |
1931 top_view->scheduled_paint_rects_[0].Union( | 1873 top_view->scheduled_paint_rects_[0].Union( |
1932 top_view->scheduled_paint_rects_[1]); | 1874 top_view->scheduled_paint_rects_[1]); |
1933 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect); | 1875 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect); |
1934 } | 1876 } |
| 1877 |
| 1878 } // namespace views |
OLD | NEW |