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

Side by Side Diff: views/view_unittest.cc

Issue 6881107: Rework the way Widget::Init works: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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/widget/native_widget.h » ('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) 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 namespace { 46 namespace {
47 47
48 class ViewTest : public ViewsTestBase { 48 class ViewTest : public ViewsTestBase {
49 public: 49 public:
50 ViewTest() { 50 ViewTest() {
51 } 51 }
52 52
53 virtual ~ViewTest() { 53 virtual ~ViewTest() {
54 } 54 }
55
56 Widget* CreateWidget() {
57 return Widget::CreateWidget(
58 Widget::CreateParams(Widget::CreateParams::TYPE_WINDOW));
59 }
60 }; 55 };
61 56
62 /* 57 /*
63 58
64 // Paints the RootView. 59 // Paints the RootView.
65 void PaintRootView(views::RootView* root, bool empty_paint) { 60 void PaintRootView(views::RootView* root, bool empty_paint) {
66 if (!empty_paint) { 61 if (!empty_paint) {
67 root->PaintNow(); 62 root->PaintNow();
68 } else { 63 } else {
69 // User isn't logged in, so that PaintNow will generate an empty rectangle. 64 // User isn't logged in, so that PaintNow will generate an empty rectangle.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 location_.SetPoint(event.x(), event.y()); 354 location_.SetPoint(event.x(), event.y());
360 } 355 }
361 356
362 TEST_F(ViewTest, MouseEvent) { 357 TEST_F(ViewTest, MouseEvent) {
363 TestView* v1 = new TestView(); 358 TestView* v1 = new TestView();
364 v1->SetBounds(0, 0, 300, 300); 359 v1->SetBounds(0, 0, 300, 300);
365 360
366 TestView* v2 = new TestView(); 361 TestView* v2 = new TestView();
367 v2->SetBounds(100, 100, 100, 100); 362 v2->SetBounds(100, 100, 100, 100);
368 363
369 scoped_ptr<Widget> widget(CreateWidget()); 364 scoped_ptr<Widget> widget(Widget::CreateWidget());
370 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); 365 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
371 params.delete_on_destroy = false; 366 params.delete_on_destroy = false;
372 widget->SetCreateParams(params); 367 params.bounds = gfx::Rect(50, 50, 650, 650);
373 widget->Init(NULL, gfx::Rect(50, 50, 650, 650)); 368 widget->Init(params);
374 RootView* root = widget->GetRootView(); 369 RootView* root = widget->GetRootView();
375 370
376 root->AddChildView(v1); 371 root->AddChildView(v1);
377 v1->AddChildView(v2); 372 v1->AddChildView(v2);
378 373
379 v1->Reset(); 374 v1->Reset();
380 v2->Reset(); 375 v2->Reset();
381 376
382 MouseEvent pressed(ui::ET_MOUSE_PRESSED, 377 MouseEvent pressed(ui::ET_MOUSE_PRESSED,
383 110, 378 110,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 463
469 TestView* v1 = new TestView(); 464 TestView* v1 = new TestView();
470 v1->SetBounds(0, 0, 300, 300); 465 v1->SetBounds(0, 0, 300, 300);
471 466
472 TestView* v2 = new TestView(); 467 TestView* v2 = new TestView();
473 v2->SetBounds(100, 100, 100, 100); 468 v2->SetBounds(100, 100, 100, 100);
474 469
475 TestView* v3 = new TestViewIgnoreTouch(); 470 TestView* v3 = new TestViewIgnoreTouch();
476 v3->SetBounds(0, 0, 100, 100); 471 v3->SetBounds(0, 0, 100, 100);
477 472
478 scoped_ptr<Widget> window(CreateWidget()); 473 scoped_ptr<Widget> widget(Widget::CreateWidget());
479 #if defined(OS_WIN) 474 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
480 // This code would need to be here when we support 475 params.delete_on_destroy = false;
481 // touch on windows? 476 params.bounds = gfx::Rect(50, 50, 650, 650);
482 WidgetWin* window_win = static_cast<WidgetWin*>(window.get()); 477 widget->Init(params);
483 window_win->set_delete_on_destroy(false);
484 window_win->set_window_style(WS_OVERLAPPEDWINDOW);
485 window_win->Init(NULL, gfx::Rect(50, 50, 650, 650));
486 #endif
487 RootView* root = window->GetRootView(); 478 RootView* root = window->GetRootView();
488 479
489 root->AddChildView(v1); 480 root->AddChildView(v1);
490 root->SetGestureManager(gm); 481 root->SetGestureManager(gm);
491 v1->AddChildView(v2); 482 v1->AddChildView(v2);
492 v2->AddChildView(v3); 483 v2->AddChildView(v3);
493 484
494 // |v3| completely obscures |v2|, but all the touch events on |v3| should 485 // |v3| completely obscures |v2|, but all the touch events on |v3| should
495 // reach |v2| because |v3| doesn't process any touch events. 486 // reach |v2| because |v3| doesn't process any touch events.
496 487
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED); 562 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED);
572 EXPECT_EQ(v2->location_.x(), -100); 563 EXPECT_EQ(v2->location_.x(), -100);
573 EXPECT_EQ(v2->location_.y(), -100); 564 EXPECT_EQ(v2->location_.y(), -100);
574 // Make sure v1 did not receive the event 565 // Make sure v1 did not receive the event
575 EXPECT_EQ(v1->last_touch_event_type_, 0); 566 EXPECT_EQ(v1->last_touch_event_type_, 0);
576 567
577 EXPECT_EQ(gm->last_touch_event_, 0); 568 EXPECT_EQ(gm->last_touch_event_, 0);
578 EXPECT_EQ(NULL, gm->last_view_); 569 EXPECT_EQ(NULL, gm->last_view_);
579 EXPECT_EQ(gm->previously_handled_flag_, false); 570 EXPECT_EQ(gm->previously_handled_flag_, false);
580 571
581 window->CloseNow(); 572 widget->CloseNow();
582 } 573 }
583 #endif 574 #endif
584 575
585 //////////////////////////////////////////////////////////////////////////////// 576 ////////////////////////////////////////////////////////////////////////////////
586 // Painting 577 // Painting
587 //////////////////////////////////////////////////////////////////////////////// 578 ////////////////////////////////////////////////////////////////////////////////
588 579
589 void TestView::Paint(gfx::Canvas* canvas) { 580 void TestView::Paint(gfx::Canvas* canvas) {
590 canvas->AsCanvasSkia()->getClipBounds(&last_clip_); 581 canvas->AsCanvasSkia()->getClipBounds(&last_clip_);
591 } 582 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // Make sure v4 was not painted 657 // Make sure v4 was not painted
667 tmp_rect.setEmpty(); 658 tmp_rect.setEmpty();
668 CheckRect(v4->last_clip_, tmp_rect); 659 CheckRect(v4->last_clip_, tmp_rect);
669 660
670 window.DestroyWindow(); 661 window.DestroyWindow();
671 } 662 }
672 */ 663 */
673 664
674 TEST_F(ViewTest, RemoveNotification) { 665 TEST_F(ViewTest, RemoveNotification) {
675 views::ViewStorage* vs = views::ViewStorage::GetInstance(); 666 views::ViewStorage* vs = views::ViewStorage::GetInstance();
676 views::Widget* window = CreateWidget(); 667 views::Widget* widget = Widget::CreateWidget();
677 views::RootView* root_view = window->GetRootView(); 668 views::RootView* root_view = widget->GetRootView();
678 669
679 View* v1 = new View; 670 View* v1 = new View;
680 int s1 = vs->CreateStorageID(); 671 int s1 = vs->CreateStorageID();
681 vs->StoreView(s1, v1); 672 vs->StoreView(s1, v1);
682 root_view->AddChildView(v1); 673 root_view->AddChildView(v1);
683 View* v11 = new View; 674 View* v11 = new View;
684 int s11 = vs->CreateStorageID(); 675 int s11 = vs->CreateStorageID();
685 vs->StoreView(s11, v11); 676 vs->StoreView(s11, v11);
686 v1->AddChildView(v11); 677 v1->AddChildView(v11);
687 View* v111 = new View; 678 View* v111 = new View;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 EXPECT_EQ(NULL, vs->RetrieveView(s12)); 732 EXPECT_EQ(NULL, vs->RetrieveView(s12));
742 EXPECT_EQ(NULL, vs->RetrieveView(s111)); 733 EXPECT_EQ(NULL, vs->RetrieveView(s111));
743 EXPECT_EQ(NULL, vs->RetrieveView(s112)); 734 EXPECT_EQ(NULL, vs->RetrieveView(s112));
744 735
745 // Put v1 back for more tests. 736 // Put v1 back for more tests.
746 root_view->AddChildView(v1); 737 root_view->AddChildView(v1);
747 vs->StoreView(s1, v1); 738 vs->StoreView(s1, v1);
748 739
749 // Now delete the root view (deleting the window will trigger a delete of the 740 // Now delete the root view (deleting the window will trigger a delete of the
750 // RootView) and make sure we are notified that the views were removed. 741 // RootView) and make sure we are notified that the views were removed.
751 delete window; 742 delete widget;
752 EXPECT_EQ(stored_views - 10, vs->view_count()); 743 EXPECT_EQ(stored_views - 10, vs->view_count());
753 EXPECT_EQ(NULL, vs->RetrieveView(s1)); 744 EXPECT_EQ(NULL, vs->RetrieveView(s1));
754 EXPECT_EQ(NULL, vs->RetrieveView(s12)); 745 EXPECT_EQ(NULL, vs->RetrieveView(s12));
755 EXPECT_EQ(NULL, vs->RetrieveView(s11)); 746 EXPECT_EQ(NULL, vs->RetrieveView(s11));
756 EXPECT_EQ(NULL, vs->RetrieveView(s12)); 747 EXPECT_EQ(NULL, vs->RetrieveView(s12));
757 EXPECT_EQ(NULL, vs->RetrieveView(s21)); 748 EXPECT_EQ(NULL, vs->RetrieveView(s21));
758 EXPECT_EQ(NULL, vs->RetrieveView(s111)); 749 EXPECT_EQ(NULL, vs->RetrieveView(s111));
759 EXPECT_EQ(NULL, vs->RetrieveView(s112)); 750 EXPECT_EQ(NULL, vs->RetrieveView(s112));
760 } 751 }
761 752
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 }; 784 };
794 785
795 gfx::Point ConvertPointToView(views::View* view, const gfx::Point& p) { 786 gfx::Point ConvertPointToView(views::View* view, const gfx::Point& p) {
796 gfx::Point tmp(p); 787 gfx::Point tmp(p);
797 views::View::ConvertPointToView(view->GetRootView(), view, &tmp); 788 views::View::ConvertPointToView(view->GetRootView(), view, &tmp);
798 return tmp; 789 return tmp;
799 } 790 }
800 } 791 }
801 792
802 TEST_F(ViewTest, HitTestMasks) { 793 TEST_F(ViewTest, HitTestMasks) {
803 scoped_ptr<views::Widget> window(CreateWidget()); 794 scoped_ptr<views::Widget> widget(Widget::CreateWidget());
804 views::RootView* root_view = window->GetRootView(); 795 views::RootView* root_view = widget->GetRootView();
805 root_view->SetBounds(0, 0, 500, 500); 796 root_view->SetBounds(0, 0, 500, 500);
806 797
807 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); 798 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100);
808 HitTestView* v1 = new HitTestView(false); 799 HitTestView* v1 = new HitTestView(false);
809 v1->SetBoundsRect(v1_bounds); 800 v1->SetBoundsRect(v1_bounds);
810 root_view->AddChildView(v1); 801 root_view->AddChildView(v1);
811 802
812 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); 803 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100);
813 HitTestView* v2 = new HitTestView(true); 804 HitTestView* v2 = new HitTestView(true);
814 v2->SetBoundsRect(v2_bounds); 805 v2->SetBoundsRect(v2_bounds);
(...skipping 19 matching lines...) Expand all
834 } 825 }
835 826
836 TEST_F(ViewTest, Textfield) { 827 TEST_F(ViewTest, Textfield) {
837 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop " 828 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop "
838 "believing it, doesn't go away."); 829 "believing it, doesn't go away.");
839 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!"); 830 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!");
840 const string16 kEmptyString; 831 const string16 kEmptyString;
841 832
842 ui::Clipboard clipboard; 833 ui::Clipboard clipboard;
843 834
844 Widget* window = CreateWidget(); 835 Widget* widget = Widget::CreateWidget();
845 window->Init(NULL, gfx::Rect(0, 0, 100, 100)); 836 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
846 RootView* root_view = window->GetRootView(); 837 params.bounds = gfx::Rect(0, 0, 100, 100);
838 widget->Init(params);
839 RootView* root_view = widget->GetRootView();
847 840
848 Textfield* textfield = new Textfield(); 841 Textfield* textfield = new Textfield();
849 root_view->AddChildView(textfield); 842 root_view->AddChildView(textfield);
850 843
851 // Test setting, appending text. 844 // Test setting, appending text.
852 textfield->SetText(kText); 845 textfield->SetText(kText);
853 EXPECT_EQ(kText, textfield->text()); 846 EXPECT_EQ(kText, textfield->text());
854 textfield->AppendText(kExtraText); 847 textfield->AppendText(kExtraText);
855 EXPECT_EQ(kText + kExtraText, textfield->text()); 848 EXPECT_EQ(kText + kExtraText, textfield->text());
856 textfield->SetText(string16()); 849 textfield->SetText(string16());
(...skipping 13 matching lines...) Expand all
870 // Tests that the Textfield view respond appropiately to cut/copy/paste. 863 // Tests that the Textfield view respond appropiately to cut/copy/paste.
871 TEST_F(ViewTest, TextfieldCutCopyPaste) { 864 TEST_F(ViewTest, TextfieldCutCopyPaste) {
872 views::ViewsDelegate::views_delegate = new TestViewsDelegate; 865 views::ViewsDelegate::views_delegate = new TestViewsDelegate;
873 866
874 const std::wstring kNormalText = L"Normal"; 867 const std::wstring kNormalText = L"Normal";
875 const std::wstring kReadOnlyText = L"Read only"; 868 const std::wstring kReadOnlyText = L"Read only";
876 const std::wstring kPasswordText = L"Password! ** Secret stuff **"; 869 const std::wstring kPasswordText = L"Password! ** Secret stuff **";
877 870
878 ui::Clipboard clipboard; 871 ui::Clipboard clipboard;
879 872
880 Widget* window = CreateWidget(); 873 Widget* widget = Widget::CreateWidget();
881 #if defined(OS_WIN) 874 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
882 static_cast<WidgetWin*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100)); 875 params.bounds = gfx::Rect(0, 0, 100, 100);
883 #endif 876 widget->Init(params);
884 RootView* root_view = window->GetRootView(); 877 RootView* root_view = widget->GetRootView();
885 878
886 Textfield* normal = new Textfield(); 879 Textfield* normal = new Textfield();
887 Textfield* read_only = new Textfield(); 880 Textfield* read_only = new Textfield();
888 read_only->SetReadOnly(true); 881 read_only->SetReadOnly(true);
889 Textfield* password = new Textfield(Textfield::STYLE_PASSWORD); 882 Textfield* password = new Textfield(Textfield::STYLE_PASSWORD);
890 883
891 root_view->AddChildView(normal); 884 root_view->AddChildView(normal);
892 root_view->AddChildView(read_only); 885 root_view->AddChildView(read_only);
893 root_view->AddChildView(password); 886 root_view->AddChildView(password);
894 887
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 #if defined(OS_WIN) 987 #if defined(OS_WIN)
995 TEST_F(ViewTest, ActivateAccelerator) { 988 TEST_F(ViewTest, ActivateAccelerator) {
996 // Register a keyboard accelerator before the view is added to a window. 989 // Register a keyboard accelerator before the view is added to a window.
997 views::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); 990 views::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false);
998 TestView* view = new TestView(); 991 TestView* view = new TestView();
999 view->Reset(); 992 view->Reset();
1000 view->AddAccelerator(return_accelerator); 993 view->AddAccelerator(return_accelerator);
1001 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 994 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1002 995
1003 // Create a window and add the view as its child. 996 // Create a window and add the view as its child.
1004 WidgetWin widget; 997 scoped_ptr<Widget> widget(Widget::CreateWidget());
1005 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); 998 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
1006 params.delete_on_destroy = false; 999 params.delete_on_destroy = false;
1007 widget.SetCreateParams(params); 1000 params.bounds = gfx::Rect(0, 0, 100, 100);
1008 widget.Init(NULL, gfx::Rect(0, 0, 100, 100)); 1001 widget->Init(params);
1009 RootView* root = widget.GetRootView(); 1002 RootView* root = widget->GetRootView();
1010 root->AddChildView(view); 1003 root->AddChildView(view);
1011 1004
1012 // Get the focus manager. 1005 // Get the focus manager.
1013 views::FocusManager* focus_manager = 1006 views::FocusManager* focus_manager =
1014 views::FocusManager::GetFocusManagerForNativeView(widget.GetNativeView()); 1007 views::FocusManager::GetFocusManagerForNativeView(
1008 widget->GetNativeView());
1015 ASSERT_TRUE(focus_manager); 1009 ASSERT_TRUE(focus_manager);
1016 1010
1017 // Hit the return key and see if it takes effect. 1011 // Hit the return key and see if it takes effect.
1018 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); 1012 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
1019 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); 1013 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1);
1020 1014
1021 // Hit the escape key. Nothing should happen. 1015 // Hit the escape key. Nothing should happen.
1022 views::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); 1016 views::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false);
1023 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); 1017 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator));
1024 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); 1018 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1);
(...skipping 22 matching lines...) Expand all
1047 1041
1048 // Remove all the accelerators. 1042 // Remove all the accelerators.
1049 view->ResetAccelerators(); 1043 view->ResetAccelerators();
1050 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1044 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1051 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); 1045 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2);
1052 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); 1046 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2);
1053 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); 1047 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator));
1054 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); 1048 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2);
1055 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); 1049 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2);
1056 1050
1057 widget.CloseNow(); 1051 widget->CloseNow();
1058 } 1052 }
1059 #endif 1053 #endif
1060 1054
1061 #if defined(OS_WIN) 1055 #if defined(OS_WIN)
1062 TEST_F(ViewTest, HiddenViewWithAccelerator) { 1056 TEST_F(ViewTest, HiddenViewWithAccelerator) {
1063 views::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); 1057 views::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false);
1064 TestView* view = new TestView(); 1058 TestView* view = new TestView();
1065 view->Reset(); 1059 view->Reset();
1066 view->AddAccelerator(return_accelerator); 1060 view->AddAccelerator(return_accelerator);
1067 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 1061 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1068 1062
1069 WidgetWin widget; 1063 scoped_ptr<Widget> widget(Widget::CreateWidget());
1070 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); 1064 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
1071 params.delete_on_destroy = false; 1065 params.delete_on_destroy = false;
1072 widget.SetCreateParams(params); 1066 params.bounds = gfx::Rect(0, 0, 100, 100);
1073 widget.Init(NULL, gfx::Rect(0, 0, 100, 100)); 1067 widget->Init(params);
1074 RootView* root = widget.GetRootView(); 1068 RootView* root = widget->GetRootView();
1075 root->AddChildView(view); 1069 root->AddChildView(view);
1076 1070
1077 views::FocusManager* focus_manager = 1071 views::FocusManager* focus_manager =
1078 views::FocusManager::GetFocusManagerForNativeView(widget.GetNativeView()); 1072 views::FocusManager::GetFocusManagerForNativeView(
1073 widget->GetNativeView());
1079 ASSERT_TRUE(focus_manager); 1074 ASSERT_TRUE(focus_manager);
1080 1075
1081 view->SetVisible(false); 1076 view->SetVisible(false);
1082 EXPECT_EQ(NULL, 1077 EXPECT_EQ(NULL,
1083 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); 1078 focus_manager->GetCurrentTargetForAccelerator(return_accelerator));
1084 1079
1085 view->SetVisible(true); 1080 view->SetVisible(true);
1086 EXPECT_EQ(view, 1081 EXPECT_EQ(view,
1087 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); 1082 focus_manager->GetCurrentTargetForAccelerator(return_accelerator));
1088 1083
1089 widget.CloseNow(); 1084 widget->CloseNow();
1090 } 1085 }
1091 #endif 1086 #endif
1092 1087
1093 #if defined(OS_WIN) 1088 #if defined(OS_WIN)
1094 //////////////////////////////////////////////////////////////////////////////// 1089 ////////////////////////////////////////////////////////////////////////////////
1095 // Mouse-wheel message rerouting 1090 // Mouse-wheel message rerouting
1096 //////////////////////////////////////////////////////////////////////////////// 1091 ////////////////////////////////////////////////////////////////////////////////
1097 class ButtonTest : public NativeButtonBase { 1092 class ButtonTest : public NativeButtonBase {
1098 public: 1093 public:
1099 ButtonTest(ButtonListener* listener, const std::wstring& label) 1094 ButtonTest(ButtonListener* listener, const std::wstring& label)
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 }; 1546 };
1552 static const size_t kTotalViews = 2; 1547 static const size_t kTotalViews = 2;
1553 std::vector<NotificationInfo> notifications_; 1548 std::vector<NotificationInfo> notifications_;
1554 }; 1549 };
1555 1550
1556 class TestChangeNativeViewHierarchy { 1551 class TestChangeNativeViewHierarchy {
1557 public: 1552 public:
1558 explicit TestChangeNativeViewHierarchy(ViewTest *view_test) { 1553 explicit TestChangeNativeViewHierarchy(ViewTest *view_test) {
1559 view_test_ = view_test; 1554 view_test_ = view_test;
1560 native_host_ = new views::NativeViewHost(); 1555 native_host_ = new views::NativeViewHost();
1561 host_ = view_test->CreateWidget(); 1556 host_ = Widget::CreateWidget();
1562 host_->Init(NULL, gfx::Rect(0, 0, 500, 300)); 1557 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
1558 params.bounds = gfx::Rect(0, 0, 500, 300);
1559 host_->Init(params);
1563 host_->GetRootView()->AddChildView(native_host_); 1560 host_->GetRootView()->AddChildView(native_host_);
1564 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) { 1561 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) {
1565 windows_[i] = view_test->CreateWidget(); 1562 windows_[i] = Widget::CreateWidget();
1566 windows_[i]->Init(host_->GetNativeView(), gfx::Rect(0, 0, 500, 300)); 1563 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
1564 params.parent = host_->GetNativeView();
1565 params.bounds = gfx::Rect(0, 0, 500, 300);
1566 windows_[i]->Init(params);
1567 root_views_[i] = windows_[i]->GetRootView(); 1567 root_views_[i] = windows_[i]->GetRootView();
1568 test_views_[i] = new TestNativeViewHierarchy; 1568 test_views_[i] = new TestNativeViewHierarchy;
1569 root_views_[i]->AddChildView(test_views_[i]); 1569 root_views_[i]->AddChildView(test_views_[i]);
1570 } 1570 }
1571 } 1571 }
1572 1572
1573 ~TestChangeNativeViewHierarchy() { 1573 ~TestChangeNativeViewHierarchy() {
1574 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) { 1574 for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) {
1575 windows_[i]->Close(); 1575 windows_[i]->Close();
1576 } 1576 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 DISALLOW_COPY_AND_ASSIGN(TransformPaintView); 1677 DISALLOW_COPY_AND_ASSIGN(TransformPaintView);
1678 }; 1678 };
1679 1679
1680 TEST_F(ViewTest, TransformPaint) { 1680 TEST_F(ViewTest, TransformPaint) {
1681 TransformPaintView* v1 = new TransformPaintView(); 1681 TransformPaintView* v1 = new TransformPaintView();
1682 v1->SetBounds(0, 0, 500, 300); 1682 v1->SetBounds(0, 0, 500, 300);
1683 1683
1684 TestView* v2 = new TestView(); 1684 TestView* v2 = new TestView();
1685 v2->SetBounds(100, 100, 200, 100); 1685 v2->SetBounds(100, 100, 200, 100);
1686 1686
1687 Widget* widget = CreateWidget(); 1687 Widget* widget = Widget::CreateWidget();
1688 #if defined(OS_WIN) 1688 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
1689 WidgetWin* window_win = static_cast<WidgetWin*>(widget); 1689 params.bounds = gfx::Rect(50, 50, 650, 650);
1690 window_win->set_window_style(WS_OVERLAPPEDWINDOW); 1690 widget->Init(params);
1691 window_win->Init(NULL, gfx::Rect(50, 50, 650, 650));
1692 #endif
1693 widget->Show(); 1691 widget->Show();
1694 RootView* root = widget->GetRootView(); 1692 RootView* root = widget->GetRootView();
1695 1693
1696 root->AddChildView(v1); 1694 root->AddChildView(v1);
1697 v1->AddChildView(v2); 1695 v1->AddChildView(v2);
1698 1696
1699 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 1697 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
1700 v1->ClearScheduledPaintRect(); 1698 v1->ClearScheduledPaintRect();
1701 v2->SchedulePaint(); 1699 v2->SchedulePaint();
1702 1700
(...skipping 13 matching lines...) Expand all
1716 widget->CloseNow(); 1714 widget->CloseNow();
1717 } 1715 }
1718 1716
1719 TEST_F(ViewTest, TransformEvent) { 1717 TEST_F(ViewTest, TransformEvent) {
1720 TestView* v1 = new TestView(); 1718 TestView* v1 = new TestView();
1721 v1->SetBounds(0, 0, 500, 300); 1719 v1->SetBounds(0, 0, 500, 300);
1722 1720
1723 TestView* v2 = new TestView(); 1721 TestView* v2 = new TestView();
1724 v2->SetBounds(100, 100, 200, 100); 1722 v2->SetBounds(100, 100, 200, 100);
1725 1723
1726 Widget* widget = CreateWidget(); 1724 Widget* widget = Widget::CreateWidget();
1727 #if defined(OS_WIN) 1725 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
1728 WidgetWin* window_win = static_cast<WidgetWin*>(widget); 1726 params.bounds = gfx::Rect(50, 50, 650, 650);
1729 window_win->set_window_style(WS_OVERLAPPEDWINDOW); 1727 widget->Init(params);
1730 window_win->Init(NULL, gfx::Rect(50, 50, 650, 650));
1731 #endif
1732 RootView* root = widget->GetRootView(); 1728 RootView* root = widget->GetRootView();
1733 1729
1734 root->AddChildView(v1); 1730 root->AddChildView(v1);
1735 v1->AddChildView(v2); 1731 v1->AddChildView(v2);
1736 1732
1737 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 1733 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
1738 1734
1739 // Rotate |v1| counter-clockwise. 1735 // Rotate |v1| counter-clockwise.
1740 v1->SetRotation(-90.0); 1736 v1->SetRotation(-90.0);
1741 v1->SetTranslateY(500); 1737 v1->SetTranslateY(500);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 bool received_notification_; 1864 bool received_notification_;
1869 1865
1870 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView); 1866 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView);
1871 }; 1867 };
1872 1868
1873 #if defined(OS_WIN) 1869 #if defined(OS_WIN)
1874 // TODO(beng): This can be cross platform when widget construction/init is. 1870 // TODO(beng): This can be cross platform when widget construction/init is.
1875 TEST_F(ViewTest, OnVisibleBoundsChanged) { 1871 TEST_F(ViewTest, OnVisibleBoundsChanged) {
1876 gfx::Rect viewport_bounds(0, 0, 100, 100); 1872 gfx::Rect viewport_bounds(0, 0, 100, 100);
1877 1873
1878 scoped_ptr<Widget> widget(CreateWidget()); 1874 scoped_ptr<Widget> widget(Widget::CreateWidget());
1879 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); 1875 Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
1880 params.delete_on_destroy = false; 1876 params.delete_on_destroy = false;
1881 widget->SetCreateParams(params); 1877 params.bounds = viewport_bounds;
1882 widget->Init(NULL, viewport_bounds); 1878 widget->Init(params);
1883 widget->GetRootView()->SetBoundsRect(viewport_bounds); 1879 widget->GetRootView()->SetBoundsRect(viewport_bounds);
1884 1880
1885 View* viewport = new View; 1881 View* viewport = new View;
1886 widget->GetRootView()->SetContentsView(viewport); 1882 widget->GetRootView()->SetContentsView(viewport);
1887 View* contents = new View; 1883 View* contents = new View;
1888 viewport->AddChildView(contents); 1884 viewport->AddChildView(contents);
1889 viewport->SetBoundsRect(viewport_bounds); 1885 viewport->SetBoundsRect(viewport_bounds);
1890 contents->SetBounds(0, 0, 100, 200); 1886 contents->SetBounds(0, 0, 100, 200);
1891 1887
1892 // Create a view that cares about visible bounds notifications, and position 1888 // Create a view that cares about visible bounds notifications, and position
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 top_view->scheduled_paint_rects_.clear(); 1930 top_view->scheduled_paint_rects_.clear();
1935 child_view->SetBounds(30, 30, 20, 20); 1931 child_view->SetBounds(30, 30, 20, 20);
1936 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size()); 1932 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size());
1937 1933
1938 // There should be 2 rects, spanning from (10, 10) to (50, 50). 1934 // There should be 2 rects, spanning from (10, 10) to (50, 50).
1939 gfx::Rect paint_rect = 1935 gfx::Rect paint_rect =
1940 top_view->scheduled_paint_rects_[0].Union( 1936 top_view->scheduled_paint_rects_[0].Union(
1941 top_view->scheduled_paint_rects_[1]); 1937 top_view->scheduled_paint_rects_[1]);
1942 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect); 1938 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect);
1943 } 1939 }
OLDNEW
« no previous file with comments | « views/focus/focus_manager_unittest.cc ('k') | views/widget/native_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698