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

Side by Side Diff: ui/views/view_unittest.cc

Issue 11416251: Desktop aura: Continue threading context through views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix erroneously removed line from NWWin tests. Created 8 years 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 | « ui/views/test/views_test_base.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 383 }
384 384
385 TEST_F(ViewTest, MouseEvent) { 385 TEST_F(ViewTest, MouseEvent) {
386 TestView* v1 = new TestView(); 386 TestView* v1 = new TestView();
387 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); 387 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
388 388
389 TestView* v2 = new TestView(); 389 TestView* v2 = new TestView();
390 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); 390 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
391 391
392 scoped_ptr<Widget> widget(new Widget); 392 scoped_ptr<Widget> widget(new Widget);
393 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 393 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
394 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
395 params.bounds = gfx::Rect(50, 50, 650, 650); 394 params.bounds = gfx::Rect(50, 50, 650, 650);
396 widget->Init(params); 395 widget->Init(params);
397 internal::RootView* root = 396 internal::RootView* root =
398 static_cast<internal::RootView*>(widget->GetRootView()); 397 static_cast<internal::RootView*>(widget->GetRootView());
399 398
400 root->AddChildView(v1); 399 root->AddChildView(v1);
401 v1->AddChildView(v2); 400 v1->AddChildView(v2);
402 401
403 v1->Reset(); 402 v1->Reset();
404 v2->Reset(); 403 v2->Reset();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 TestView* v1 = new TestView(); 444 TestView* v1 = new TestView();
446 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); 445 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
447 446
448 TestView* v2 = new TestView(); 447 TestView* v2 = new TestView();
449 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); 448 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
450 449
451 v1->Reset(); 450 v1->Reset();
452 v2->Reset(); 451 v2->Reset();
453 452
454 scoped_ptr<Widget> widget(new Widget); 453 scoped_ptr<Widget> widget(new Widget);
455 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 454 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
456 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
457 params.bounds = gfx::Rect(50, 50, 650, 650); 455 params.bounds = gfx::Rect(50, 50, 650, 650);
458 widget->Init(params); 456 widget->Init(params);
459 View* root = widget->GetRootView(); 457 View* root = widget->GetRootView();
460 458
461 root->AddChildView(v1); 459 root->AddChildView(v1);
462 v1->AddChildView(v2); 460 v1->AddChildView(v2);
463 461
464 v2->delete_on_pressed_ = true; 462 v2->delete_on_pressed_ = true;
465 gfx::Point point(110, 120); 463 gfx::Point point(110, 120);
466 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, 464 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 TestView* v1 = new TestView(); 499 TestView* v1 = new TestView();
502 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); 500 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
503 501
504 TestView* v2 = new TestView(); 502 TestView* v2 = new TestView();
505 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); 503 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
506 504
507 TestView* v3 = new TestViewIgnoreTouch(); 505 TestView* v3 = new TestViewIgnoreTouch();
508 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 506 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100));
509 507
510 scoped_ptr<Widget> widget(new Widget()); 508 scoped_ptr<Widget> widget(new Widget());
511 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 509 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
512 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
513 params.bounds = gfx::Rect(50, 50, 650, 650); 510 params.bounds = gfx::Rect(50, 50, 650, 650);
514 widget->Init(params); 511 widget->Init(params);
515 internal::RootView* root = 512 internal::RootView* root =
516 static_cast<internal::RootView*>(widget->GetRootView()); 513 static_cast<internal::RootView*>(widget->GetRootView());
517 514
518 root->AddChildView(v1); 515 root->AddChildView(v1);
519 v1->AddChildView(v2); 516 v1->AddChildView(v2);
520 v2->AddChildView(v3); 517 v2->AddChildView(v3);
521 518
522 // |v3| completely obscures |v2|, but all the touch events on |v3| should 519 // |v3| completely obscures |v2|, but all the touch events on |v3| should
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 TestView* v1 = new TestViewConsumeGesture(); 598 TestView* v1 = new TestViewConsumeGesture();
602 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); 599 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
603 600
604 TestView* v2 = new TestViewConsumeGesture(); 601 TestView* v2 = new TestViewConsumeGesture();
605 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); 602 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
606 603
607 TestView* v3 = new TestViewIgnoreGesture(); 604 TestView* v3 = new TestViewIgnoreGesture();
608 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 605 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100));
609 606
610 scoped_ptr<Widget> widget(new Widget()); 607 scoped_ptr<Widget> widget(new Widget());
611 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 608 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
612 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
613 params.bounds = gfx::Rect(50, 50, 650, 650); 609 params.bounds = gfx::Rect(50, 50, 650, 650);
614 widget->Init(params); 610 widget->Init(params);
615 internal::RootView* root = 611 internal::RootView* root =
616 static_cast<internal::RootView*>(widget->GetRootView()); 612 static_cast<internal::RootView*>(widget->GetRootView());
617 613
618 root->AddChildView(v1); 614 root->AddChildView(v1);
619 v1->AddChildView(v2); 615 v1->AddChildView(v2);
620 v2->AddChildView(v3); 616 v2->AddChildView(v3);
621 617
622 // |v3| completely obscures |v2|, but all the gesture events on |v3| should 618 // |v3| completely obscures |v2|, but all the gesture events on |v3| should
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 TestView* v1 = new TestViewConsumeGesture(); 663 TestView* v1 = new TestViewConsumeGesture();
668 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); 664 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
669 665
670 TestView* v2 = new TestViewIgnoreScrollGestures(); 666 TestView* v2 = new TestViewIgnoreScrollGestures();
671 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); 667 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
672 668
673 TestView* v3 = new TestViewIgnoreGesture(); 669 TestView* v3 = new TestViewIgnoreGesture();
674 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 670 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100));
675 671
676 scoped_ptr<Widget> widget(new Widget()); 672 scoped_ptr<Widget> widget(new Widget());
677 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 673 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
678 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
679 params.bounds = gfx::Rect(50, 50, 650, 650); 674 params.bounds = gfx::Rect(50, 50, 650, 650);
680 widget->Init(params); 675 widget->Init(params);
681 internal::RootView* root = 676 internal::RootView* root =
682 static_cast<internal::RootView*>(widget->GetRootView()); 677 static_cast<internal::RootView*>(widget->GetRootView());
683 678
684 root->AddChildView(v1); 679 root->AddChildView(v1);
685 v1->AddChildView(v2); 680 v1->AddChildView(v2);
686 v2->AddChildView(v3); 681 v2->AddChildView(v3);
687 682
688 // |v3| completely obscures |v2|, but all the gesture events on |v3| should 683 // |v3| completely obscures |v2|, but all the gesture events on |v3| should
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 void RotateClockwise(gfx::Transform* transform) { 971 void RotateClockwise(gfx::Transform* transform) {
977 transform->matrix().set3x3( 0, 1, 0, 972 transform->matrix().set3x3( 0, 1, 0,
978 -1, 0, 0, 973 -1, 0, 0,
979 0, 0, 1); 974 0, 0, 1);
980 } 975 }
981 976
982 } // namespace 977 } // namespace
983 978
984 TEST_F(ViewTest, HitTestMasks) { 979 TEST_F(ViewTest, HitTestMasks) {
985 Widget* widget = new Widget; 980 Widget* widget = new Widget;
986 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP)); 981 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
982 widget->Init(params);
987 View* root_view = widget->GetRootView(); 983 View* root_view = widget->GetRootView();
988 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); 984 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
989 985
990 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); 986 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100);
991 HitTestView* v1 = new HitTestView(false); 987 HitTestView* v1 = new HitTestView(false);
992 v1->SetBoundsRect(v1_bounds); 988 v1->SetBoundsRect(v1_bounds);
993 root_view->AddChildView(v1); 989 root_view->AddChildView(v1);
994 990
995 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); 991 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100);
996 HitTestView* v2 = new HitTestView(true); 992 HitTestView* v2 = new HitTestView(true);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint)); 1028 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint));
1033 1029
1034 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin)); 1030 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin));
1035 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin)); 1031 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin));
1036 1032
1037 widget->CloseNow(); 1033 widget->CloseNow();
1038 } 1034 }
1039 1035
1040 TEST_F(ViewTest, NotifyEnterExitOnChild) { 1036 TEST_F(ViewTest, NotifyEnterExitOnChild) {
1041 Widget* widget = new Widget; 1037 Widget* widget = new Widget;
1042 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP)); 1038 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1039 widget->Init(params);
1043 View* root_view = widget->GetRootView(); 1040 View* root_view = widget->GetRootView();
1044 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); 1041 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
1045 1042
1046 // Have this hierarchy of views (the coords here are in root coord): 1043 // Have this hierarchy of views (the coords here are in root coord):
1047 // v1 (0, 0, 100, 100) 1044 // v1 (0, 0, 100, 100)
1048 // - v11 (0, 0, 20, 30) 1045 // - v11 (0, 0, 20, 30)
1049 // - v111 (5, 5, 5, 15) 1046 // - v111 (5, 5, 5, 15)
1050 // - v12 (50, 10, 30, 90) 1047 // - v12 (50, 10, 30, 90)
1051 // - v121 (60, 20, 10, 10) 1048 // - v121 (60, 20, 10, 10)
1052 // v2 (105, 0, 100, 100) 1049 // v2 (105, 0, 100, 100)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 widget->CloseNow(); 1164 widget->CloseNow();
1168 } 1165 }
1169 1166
1170 TEST_F(ViewTest, Textfield) { 1167 TEST_F(ViewTest, Textfield) {
1171 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop " 1168 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop "
1172 "believing it, doesn't go away."); 1169 "believing it, doesn't go away.");
1173 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!"); 1170 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!");
1174 const string16 kEmptyString; 1171 const string16 kEmptyString;
1175 1172
1176 Widget* widget = new Widget; 1173 Widget* widget = new Widget;
1177 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 1174 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1178 params.bounds = gfx::Rect(0, 0, 100, 100); 1175 params.bounds = gfx::Rect(0, 0, 100, 100);
1179 widget->Init(params); 1176 widget->Init(params);
1180 View* root_view = widget->GetRootView(); 1177 View* root_view = widget->GetRootView();
1181 1178
1182 Textfield* textfield = new Textfield(); 1179 Textfield* textfield = new Textfield();
1183 root_view->AddChildView(textfield); 1180 root_view->AddChildView(textfield);
1184 1181
1185 // Test setting, appending text. 1182 // Test setting, appending text.
1186 textfield->SetText(kText); 1183 textfield->SetText(kText);
1187 EXPECT_EQ(kText, textfield->text()); 1184 EXPECT_EQ(kText, textfield->text());
(...skipping 17 matching lines...) Expand all
1205 1202
1206 // Tests that the Textfield view respond appropiately to cut/copy/paste. 1203 // Tests that the Textfield view respond appropiately to cut/copy/paste.
1207 TEST_F(ViewTest, TextfieldCutCopyPaste) { 1204 TEST_F(ViewTest, TextfieldCutCopyPaste) {
1208 const string16 kNormalText = ASCIIToUTF16("Normal"); 1205 const string16 kNormalText = ASCIIToUTF16("Normal");
1209 const string16 kReadOnlyText = ASCIIToUTF16("Read only"); 1206 const string16 kReadOnlyText = ASCIIToUTF16("Read only");
1210 const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **"); 1207 const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **");
1211 1208
1212 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); 1209 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1213 1210
1214 Widget* widget = new Widget; 1211 Widget* widget = new Widget;
1215 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 1212 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1216 params.bounds = gfx::Rect(0, 0, 100, 100); 1213 params.bounds = gfx::Rect(0, 0, 100, 100);
1217 widget->Init(params); 1214 widget->Init(params);
1218 View* root_view = widget->GetRootView(); 1215 View* root_view = widget->GetRootView();
1219 1216
1220 Textfield* normal = new Textfield(); 1217 Textfield* normal = new Textfield();
1221 Textfield* read_only = new Textfield(); 1218 Textfield* read_only = new Textfield();
1222 read_only->SetReadOnly(true); 1219 read_only->SetReadOnly(true);
1223 Textfield* password = new Textfield(Textfield::STYLE_OBSCURED); 1220 Textfield* password = new Textfield(Textfield::STYLE_OBSCURED);
1224 1221
1225 root_view->AddChildView(normal); 1222 root_view->AddChildView(normal);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 TEST_F(ViewTest, ActivateAccelerator) { 1324 TEST_F(ViewTest, ActivateAccelerator) {
1328 // Register a keyboard accelerator before the view is added to a window. 1325 // Register a keyboard accelerator before the view is added to a window.
1329 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1326 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1330 TestView* view = new TestView(); 1327 TestView* view = new TestView();
1331 view->Reset(); 1328 view->Reset();
1332 view->AddAccelerator(return_accelerator); 1329 view->AddAccelerator(return_accelerator);
1333 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 1330 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1334 1331
1335 // Create a window and add the view as its child. 1332 // Create a window and add the view as its child.
1336 scoped_ptr<Widget> widget(new Widget); 1333 scoped_ptr<Widget> widget(new Widget);
1337 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 1334 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1338 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1339 params.bounds = gfx::Rect(0, 0, 100, 100); 1335 params.bounds = gfx::Rect(0, 0, 100, 100);
1340 widget->Init(params); 1336 widget->Init(params);
1341 View* root = widget->GetRootView(); 1337 View* root = widget->GetRootView();
1342 root->AddChildView(view); 1338 root->AddChildView(view);
1343 widget->Show(); 1339 widget->Show();
1344 1340
1345 // Get the focus manager. 1341 // Get the focus manager.
1346 FocusManager* focus_manager = widget->GetFocusManager(); 1342 FocusManager* focus_manager = widget->GetFocusManager();
1347 ASSERT_TRUE(focus_manager); 1343 ASSERT_TRUE(focus_manager);
1348 1344
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 1388
1393 #if defined(OS_WIN) && !defined(USE_AURA) 1389 #if defined(OS_WIN) && !defined(USE_AURA)
1394 TEST_F(ViewTest, HiddenViewWithAccelerator) { 1390 TEST_F(ViewTest, HiddenViewWithAccelerator) {
1395 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1391 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1396 TestView* view = new TestView(); 1392 TestView* view = new TestView();
1397 view->Reset(); 1393 view->Reset();
1398 view->AddAccelerator(return_accelerator); 1394 view->AddAccelerator(return_accelerator);
1399 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 1395 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1400 1396
1401 scoped_ptr<Widget> widget(new Widget); 1397 scoped_ptr<Widget> widget(new Widget);
1402 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 1398 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1403 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1404 params.bounds = gfx::Rect(0, 0, 100, 100); 1399 params.bounds = gfx::Rect(0, 0, 100, 100);
1405 widget->Init(params); 1400 widget->Init(params);
1406 View* root = widget->GetRootView(); 1401 View* root = widget->GetRootView();
1407 root->AddChildView(view); 1402 root->AddChildView(view);
1408 widget->Show(); 1403 widget->Show();
1409 1404
1410 FocusManager* focus_manager = widget->GetFocusManager(); 1405 FocusManager* focus_manager = widget->GetFocusManager();
1411 ASSERT_TRUE(focus_manager); 1406 ASSERT_TRUE(focus_manager);
1412 1407
1413 view->SetVisible(false); 1408 view->SetVisible(false);
1414 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1409 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1415 1410
1416 view->SetVisible(true); 1411 view->SetVisible(true);
1417 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); 1412 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
1418 1413
1419 widget->CloseNow(); 1414 widget->CloseNow();
1420 } 1415 }
1421 #endif 1416 #endif
1422 1417
1423 #if defined(OS_WIN) && !defined(USE_AURA) 1418 #if defined(OS_WIN) && !defined(USE_AURA)
1424 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) { 1419 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) {
1425 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1420 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1426 TestView* view = new TestView(); 1421 TestView* view = new TestView();
1427 view->Reset(); 1422 view->Reset();
1428 view->AddAccelerator(return_accelerator); 1423 view->AddAccelerator(return_accelerator);
1429 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 1424 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
1430 1425
1431 scoped_ptr<Widget> widget(new Widget); 1426 scoped_ptr<Widget> widget(new Widget);
1432 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 1427 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1433 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1434 params.bounds = gfx::Rect(0, 0, 100, 100); 1428 params.bounds = gfx::Rect(0, 0, 100, 100);
1435 widget->Init(params); 1429 widget->Init(params);
1436 View* root = widget->GetRootView(); 1430 View* root = widget->GetRootView();
1437 root->AddChildView(view); 1431 root->AddChildView(view);
1438 1432
1439 FocusManager* focus_manager = widget->GetFocusManager(); 1433 FocusManager* focus_manager = widget->GetFocusManager();
1440 ASSERT_TRUE(focus_manager); 1434 ASSERT_TRUE(focus_manager);
1441 1435
1442 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1436 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1443 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); 1437 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 : focus_manager_(NULL), 1687 : focus_manager_(NULL),
1694 test_dialog_(NULL), 1688 test_dialog_(NULL),
1695 client_view_(NULL), 1689 client_view_(NULL),
1696 ok_button_(NULL), 1690 ok_button_(NULL),
1697 cancel_button_(NULL) { 1691 cancel_button_(NULL) {
1698 } 1692 }
1699 1693
1700 virtual void SetUp() OVERRIDE { 1694 virtual void SetUp() OVERRIDE {
1701 ViewTest::SetUp(); 1695 ViewTest::SetUp();
1702 test_dialog_ = new TestDialog(NULL); 1696 test_dialog_ = new TestDialog(NULL);
1703 Widget* window = 1697
1704 Widget::CreateWindowWithBounds(test_dialog_, gfx::Rect(0, 0, 100, 100)); 1698 Widget* window = new Widget;
1699 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
1700 params.delegate = test_dialog_;
1701 params.bounds = gfx::Rect(0, 0, 100, 100);
1702 window->Init(params);
1703
1705 test_dialog_->widget_ = window; 1704 test_dialog_->widget_ = window;
1706 window->Show(); 1705 window->Show();
1707 focus_manager_ = test_dialog_->contents_->GetFocusManager(); 1706 focus_manager_ = test_dialog_->contents_->GetFocusManager();
1708 ASSERT_TRUE(focus_manager_ != NULL); 1707 ASSERT_TRUE(focus_manager_ != NULL);
1709 client_view_ = 1708 client_view_ =
1710 static_cast<DialogClientView*>(window->client_view()); 1709 static_cast<DialogClientView*>(window->client_view());
1711 ok_button_ = client_view_->ok_button(); 1710 ok_button_ = client_view_->ok_button();
1712 cancel_button_ = client_view_->cancel_button(); 1711 cancel_button_ = client_view_->cancel_button();
1713 } 1712 }
1714 1713
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 class ButtonDropDownTest : public ViewTest { 1803 class ButtonDropDownTest : public ViewTest {
1805 public: 1804 public:
1806 ButtonDropDownTest() 1805 ButtonDropDownTest()
1807 : test_dialog_(NULL), 1806 : test_dialog_(NULL),
1808 button_as_view_(NULL) { 1807 button_as_view_(NULL) {
1809 } 1808 }
1810 1809
1811 virtual void SetUp() OVERRIDE { 1810 virtual void SetUp() OVERRIDE {
1812 ViewTest::SetUp(); 1811 ViewTest::SetUp();
1813 test_dialog_ = new TestDialog(new MockMenuModel()); 1812 test_dialog_ = new TestDialog(new MockMenuModel());
1814 Widget* window = 1813
1815 Widget::CreateWindowWithBounds(test_dialog_, gfx::Rect(0, 0, 100, 100)); 1814 Widget* window = new Widget;
1815 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
1816 params.delegate = test_dialog_;
1817 params.bounds = gfx::Rect(0, 0, 100, 100);
1818 window->Init(params);
1819
1816 test_dialog_->widget_ = window; 1820 test_dialog_->widget_ = window;
1817 window->Show(); 1821 window->Show();
1818 test_dialog_->button_drop_->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 1822 test_dialog_->button_drop_->SetBoundsRect(gfx::Rect(0, 0, 100, 100));
1819 // We have to cast the button back into a View in order to invoke it's 1823 // We have to cast the button back into a View in order to invoke it's
1820 // OnMouseReleased method. 1824 // OnMouseReleased method.
1821 button_as_view_ = static_cast<View*>(test_dialog_->button_drop_); 1825 button_as_view_ = static_cast<View*>(test_dialog_->button_drop_);
1822 } 1826 }
1823 1827
1824 virtual void TearDown() OVERRIDE { 1828 virtual void TearDown() OVERRIDE {
1825 test_dialog_->TearDown(); 1829 test_dialog_->TearDown();
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 }; 2035 };
2032 2036
2033 TEST_F(ViewTest, TransformPaint) { 2037 TEST_F(ViewTest, TransformPaint) {
2034 TransformPaintView* v1 = new TransformPaintView(); 2038 TransformPaintView* v1 = new TransformPaintView();
2035 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300)); 2039 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300));
2036 2040
2037 TestView* v2 = new TestView(); 2041 TestView* v2 = new TestView();
2038 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100)); 2042 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100));
2039 2043
2040 Widget* widget = new Widget; 2044 Widget* widget = new Widget;
2041 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2045 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2042 params.bounds = gfx::Rect(50, 50, 650, 650); 2046 params.bounds = gfx::Rect(50, 50, 650, 650);
2043 widget->Init(params); 2047 widget->Init(params);
2044 widget->Show(); 2048 widget->Show();
2045 View* root = widget->GetRootView(); 2049 View* root = widget->GetRootView();
2046 2050
2047 root->AddChildView(v1); 2051 root->AddChildView(v1);
2048 v1->AddChildView(v2); 2052 v1->AddChildView(v2);
2049 2053
2050 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 2054 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
2051 v1->ClearScheduledPaintRect(); 2055 v1->ClearScheduledPaintRect();
(...skipping 18 matching lines...) Expand all
2070 } 2074 }
2071 2075
2072 TEST_F(ViewTest, TransformEvent) { 2076 TEST_F(ViewTest, TransformEvent) {
2073 TestView* v1 = new TestView(); 2077 TestView* v1 = new TestView();
2074 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300)); 2078 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300));
2075 2079
2076 TestView* v2 = new TestView(); 2080 TestView* v2 = new TestView();
2077 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100)); 2081 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100));
2078 2082
2079 Widget* widget = new Widget; 2083 Widget* widget = new Widget;
2080 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2084 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2081 params.bounds = gfx::Rect(50, 50, 650, 650); 2085 params.bounds = gfx::Rect(50, 50, 650, 650);
2082 widget->Init(params); 2086 widget->Init(params);
2083 View* root = widget->GetRootView(); 2087 View* root = widget->GetRootView();
2084 2088
2085 root->AddChildView(v1); 2089 root->AddChildView(v1);
2086 v1->AddChildView(v2); 2090 v1->AddChildView(v2);
2087 2091
2088 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 2092 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
2089 2093
2090 // Rotate |v1| counter-clockwise. 2094 // Rotate |v1| counter-clockwise.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 2211
2208 root->OnMouseReleased(released); 2212 root->OnMouseReleased(released);
2209 2213
2210 widget->CloseNow(); 2214 widget->CloseNow();
2211 } 2215 }
2212 2216
2213 TEST_F(ViewTest, TransformVisibleBound) { 2217 TEST_F(ViewTest, TransformVisibleBound) {
2214 gfx::Rect viewport_bounds(0, 0, 100, 100); 2218 gfx::Rect viewport_bounds(0, 0, 100, 100);
2215 2219
2216 scoped_ptr<Widget> widget(new Widget); 2220 scoped_ptr<Widget> widget(new Widget);
2217 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2221 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2218 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2219 params.bounds = viewport_bounds; 2222 params.bounds = viewport_bounds;
2220 widget->Init(params); 2223 widget->Init(params);
2221 widget->GetRootView()->SetBoundsRect(viewport_bounds); 2224 widget->GetRootView()->SetBoundsRect(viewport_bounds);
2222 2225
2223 View* viewport = new View; 2226 View* viewport = new View;
2224 widget->SetContentsView(viewport); 2227 widget->SetContentsView(viewport);
2225 View* contents = new View; 2228 View* contents = new View;
2226 viewport->AddChildView(contents); 2229 viewport->AddChildView(contents);
2227 viewport->SetBoundsRect(viewport_bounds); 2230 viewport->SetBoundsRect(viewport_bounds);
2228 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); 2231 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 2269
2267 bool received_notification_; 2270 bool received_notification_;
2268 2271
2269 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView); 2272 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView);
2270 }; 2273 };
2271 2274
2272 TEST_F(ViewTest, OnVisibleBoundsChanged) { 2275 TEST_F(ViewTest, OnVisibleBoundsChanged) {
2273 gfx::Rect viewport_bounds(0, 0, 100, 100); 2276 gfx::Rect viewport_bounds(0, 0, 100, 100);
2274 2277
2275 scoped_ptr<Widget> widget(new Widget); 2278 scoped_ptr<Widget> widget(new Widget);
2276 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2279 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2277 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2278 params.bounds = viewport_bounds; 2280 params.bounds = viewport_bounds;
2279 widget->Init(params); 2281 widget->Init(params);
2280 widget->GetRootView()->SetBoundsRect(viewport_bounds); 2282 widget->GetRootView()->SetBoundsRect(viewport_bounds);
2281 2283
2282 View* viewport = new View; 2284 View* viewport = new View;
2283 widget->SetContentsView(viewport); 2285 widget->SetContentsView(viewport);
2284 View* contents = new View; 2286 View* contents = new View;
2285 viewport->AddChildView(contents); 2287 viewport->AddChildView(contents);
2286 viewport->SetBoundsRect(viewport_bounds); 2288 viewport->SetBoundsRect(viewport_bounds);
2287 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); 2289 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 gfx::Point point(6, 18); 2443 gfx::Point point(6, 18);
2442 View::ConvertPointToTarget(&top_view, child, &point); 2444 View::ConvertPointToTarget(&top_view, child, &point);
2443 EXPECT_EQ(-1, point.x()); 2445 EXPECT_EQ(-1, point.x());
2444 EXPECT_EQ(-1, point.y()); 2446 EXPECT_EQ(-1, point.y());
2445 } 2447 }
2446 } 2448 }
2447 2449
2448 // Tests conversion methods for rectangles. 2450 // Tests conversion methods for rectangles.
2449 TEST_F(ViewTest, ConvertRectWithTransform) { 2451 TEST_F(ViewTest, ConvertRectWithTransform) {
2450 scoped_ptr<Widget> widget(new Widget); 2452 scoped_ptr<Widget> widget(new Widget);
2451 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2453 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2452 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2453 params.bounds = gfx::Rect(50, 50, 650, 650); 2454 params.bounds = gfx::Rect(50, 50, 650, 650);
2454 widget->Init(params); 2455 widget->Init(params);
2455 View* root = widget->GetRootView(); 2456 View* root = widget->GetRootView();
2456 2457
2457 TestView* v1 = new TestView; 2458 TestView* v1 = new TestView;
2458 TestView* v2 = new TestView; 2459 TestView* v2 = new TestView;
2459 root->AddChildView(v1); 2460 root->AddChildView(v1);
2460 v1->AddChildView(v2); 2461 v1->AddChildView(v2);
2461 2462
2462 v1->SetBoundsRect(gfx::Rect(10, 10, 500, 500)); 2463 v1->SetBoundsRect(gfx::Rect(10, 10, 500, 500));
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
2913 widget()->CalculateOffsetToAncestorWithLayer(&root_layer); 2914 widget()->CalculateOffsetToAncestorWithLayer(&root_layer);
2914 return root_layer; 2915 return root_layer;
2915 } 2916 }
2916 2917
2917 virtual void SetUp() OVERRIDE { 2918 virtual void SetUp() OVERRIDE {
2918 ViewTest::SetUp(); 2919 ViewTest::SetUp();
2919 old_use_acceleration_ = View::get_use_acceleration_when_possible(); 2920 old_use_acceleration_ = View::get_use_acceleration_when_possible();
2920 View::set_use_acceleration_when_possible(true); 2921 View::set_use_acceleration_when_possible(true);
2921 2922
2922 widget_ = new Widget; 2923 widget_ = new Widget;
2923 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2924 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2924 params.bounds = gfx::Rect(50, 50, 200, 200); 2925 params.bounds = gfx::Rect(50, 50, 200, 200);
2925 widget_->Init(params); 2926 widget_->Init(params);
2926 widget_->Show(); 2927 widget_->Show();
2927 widget_->GetRootView()->SetBounds(0, 0, 200, 200); 2928 widget_->GetRootView()->SetBounds(0, 0, 200, 200);
2928 } 2929 }
2929 2930
2930 virtual void TearDown() OVERRIDE { 2931 virtual void TearDown() OVERRIDE {
2931 View::set_use_acceleration_when_possible(old_use_acceleration_); 2932 View::set_use_acceleration_when_possible(old_use_acceleration_);
2932 widget_->CloseNow(); 2933 widget_->CloseNow();
2933 ViewsTestBase::TearDown(); 2934 ViewsTestBase::TearDown();
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
3389 // Set to non default value. 3390 // Set to non default value.
3390 v->layer()->set_scale_content(false); 3391 v->layer()->set_scale_content(false);
3391 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); 3392 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer());
3392 ui::Layer* new_layer = v->layer(); 3393 ui::Layer* new_layer = v->layer();
3393 EXPECT_FALSE(new_layer->scale_content()); 3394 EXPECT_FALSE(new_layer->scale_content());
3394 } 3395 }
3395 3396
3396 #endif // USE_AURA 3397 #endif // USE_AURA
3397 3398
3398 } // namespace views 3399 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/test/views_test_base.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698