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

Side by Side Diff: views/focus/focus_manager_unittest.cc

Issue 115825: Move text_field.cc and rename the class to Textfield in preparation for porti... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/textfield.cc ('k') | views/view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Disabled right now as this won't work on BuildBots right now as this test 5 // Disabled right now as this won't work on BuildBots right now as this test
6 // require the box it runs on to be unlocked (and no screen-savers). 6 // require the box it runs on to be unlocked (and no screen-savers).
7 // The test actually simulates mouse and key events, so if the screen is locked, 7 // The test actually simulates mouse and key events, so if the screen is locked,
8 // the events don't go to the Chrome window. 8 // the events don't go to the Chrome window.
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "base/gfx/rect.h" 12 #include "base/gfx/rect.h"
13 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
14 #include "views/background.h" 14 #include "views/background.h"
15 #include "views/border.h" 15 #include "views/border.h"
16 #include "views/controls/button/checkbox.h" 16 #include "views/controls/button/checkbox.h"
17 #include "views/controls/button/native_button.h" 17 #include "views/controls/button/native_button.h"
18 #include "views/controls/button/radio_button.h" 18 #include "views/controls/button/radio_button.h"
19 #include "views/controls/label.h" 19 #include "views/controls/label.h"
20 #include "views/controls/link.h" 20 #include "views/controls/link.h"
21 #include "views/controls/scroll_view.h" 21 #include "views/controls/scroll_view.h"
22 #include "views/controls/tabbed_pane.h" 22 #include "views/controls/tabbed_pane.h"
23 #include "views/controls/text_field.h" 23 #include "views/controls/textfield/textfield.h"
24 #include "views/widget/accelerator_handler.h" 24 #include "views/widget/accelerator_handler.h"
25 #include "views/widget/root_view.h" 25 #include "views/widget/root_view.h"
26 #include "views/widget/widget_win.h" 26 #include "views/widget/widget_win.h"
27 #include "views/window/window.h" 27 #include "views/window/window.h"
28 #include "views/window/window_delegate.h" 28 #include "views/window/window_delegate.h"
29 29
30 30
31 31
32 namespace { 32 namespace {
33 33
34 static const int kWindowWidth = 600; 34 static const int kWindowWidth = 600;
35 static const int kWindowHeight = 500; 35 static const int kWindowHeight = 500;
36 36
37 static int count = 1; 37 static int count = 1;
38 38
39 static const int kTopCheckBoxID = count++; // 1 39 static const int kTopCheckBoxID = count++; // 1
40 static const int kLeftContainerID = count++; 40 static const int kLeftContainerID = count++;
41 static const int kAppleLabelID = count++; 41 static const int kAppleLabelID = count++;
42 static const int kAppleTextFieldID = count++; 42 static const int kAppleTextfieldID = count++;
43 static const int kOrangeLabelID = count++; // 5 43 static const int kOrangeLabelID = count++; // 5
44 static const int kOrangeTextFieldID = count++; 44 static const int kOrangeTextfieldID = count++;
45 static const int kBananaLabelID = count++; 45 static const int kBananaLabelID = count++;
46 static const int kBananaTextFieldID = count++; 46 static const int kBananaTextfieldID = count++;
47 static const int kKiwiLabelID = count++; 47 static const int kKiwiLabelID = count++;
48 static const int kKiwiTextFieldID = count++; // 10 48 static const int kKiwiTextfieldID = count++; // 10
49 static const int kFruitButtonID = count++; 49 static const int kFruitButtonID = count++;
50 static const int kFruitCheckBoxID = count++; 50 static const int kFruitCheckBoxID = count++;
51 51
52 static const int kRightContainerID = count++; 52 static const int kRightContainerID = count++;
53 static const int kAsparagusButtonID = count++; 53 static const int kAsparagusButtonID = count++;
54 static const int kBroccoliButtonID = count++; // 15 54 static const int kBroccoliButtonID = count++; // 15
55 static const int kCauliflowerButtonID = count++; 55 static const int kCauliflowerButtonID = count++;
56 56
57 static const int kInnerContainerID = count++; 57 static const int kInnerContainerID = count++;
58 static const int kScrollViewID = count++; 58 static const int kScrollViewID = count++;
(...skipping 14 matching lines...) Expand all
73 static const int kOKButtonID = count++; 73 static const int kOKButtonID = count++;
74 static const int kCancelButtonID = count++; 74 static const int kCancelButtonID = count++;
75 static const int kHelpButtonID = count++; 75 static const int kHelpButtonID = count++;
76 76
77 static const int kStyleContainerID = count++; // 35 77 static const int kStyleContainerID = count++; // 35
78 static const int kBoldCheckBoxID = count++; 78 static const int kBoldCheckBoxID = count++;
79 static const int kItalicCheckBoxID = count++; 79 static const int kItalicCheckBoxID = count++;
80 static const int kUnderlinedCheckBoxID = count++; 80 static const int kUnderlinedCheckBoxID = count++;
81 81
82 static const int kSearchContainerID = count++; 82 static const int kSearchContainerID = count++;
83 static const int kSearchTextFieldID = count++; // 40 83 static const int kSearchTextfieldID = count++; // 40
84 static const int kSearchButtonID = count++; 84 static const int kSearchButtonID = count++;
85 static const int kHelpLinkID = count++; 85 static const int kHelpLinkID = count++;
86 86
87 static const int kThumbnailContainerID = count++; 87 static const int kThumbnailContainerID = count++;
88 static const int kThumbnailStarID = count++; 88 static const int kThumbnailStarID = count++;
89 static const int kThumbnailSuperStarID = count++; 89 static const int kThumbnailSuperStarID = count++;
90 90
91 class FocusManagerTest; 91 class FocusManagerTest;
92 92
93 // BorderView is a NativeControl that creates a tab control as its child and 93 // BorderView is a NativeControl that creates a tab control as its child and
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 int label_height = 15; 264 int label_height = 15;
265 int text_field_width = 150; 265 int text_field_width = 150;
266 int y = 10; 266 int y = 10;
267 int gap_between_labels = 10; 267 int gap_between_labels = 10;
268 268
269 views::Label* label = new views::Label(L"Apple:"); 269 views::Label* label = new views::Label(L"Apple:");
270 label->SetID(kAppleLabelID); 270 label->SetID(kAppleLabelID);
271 left_container->AddChildView(label); 271 left_container->AddChildView(label);
272 label->SetBounds(label_x, y, label_width, label_height); 272 label->SetBounds(label_x, y, label_width, label_height);
273 273
274 views::TextField* text_field = new views::TextField(); 274 views::Textfield* text_field = new views::Textfield();
275 text_field->SetID(kAppleTextFieldID); 275 text_field->SetID(kAppleTextfieldID);
276 left_container->AddChildView(text_field); 276 left_container->AddChildView(text_field);
277 text_field->SetBounds(label_x + label_width + 5, y, 277 text_field->SetBounds(label_x + label_width + 5, y,
278 text_field_width, label_height); 278 text_field_width, label_height);
279 279
280 y += label_height + gap_between_labels; 280 y += label_height + gap_between_labels;
281 281
282 label = new views::Label(L"Orange:"); 282 label = new views::Label(L"Orange:");
283 label->SetID(kOrangeLabelID); 283 label->SetID(kOrangeLabelID);
284 left_container->AddChildView(label); 284 left_container->AddChildView(label);
285 label->SetBounds(label_x, y, label_width, label_height); 285 label->SetBounds(label_x, y, label_width, label_height);
286 286
287 text_field = new views::TextField(); 287 text_field = new views::Textfield();
288 text_field->SetID(kOrangeTextFieldID); 288 text_field->SetID(kOrangeTextfieldID);
289 left_container->AddChildView(text_field); 289 left_container->AddChildView(text_field);
290 text_field->SetBounds(label_x + label_width + 5, y, 290 text_field->SetBounds(label_x + label_width + 5, y,
291 text_field_width, label_height); 291 text_field_width, label_height);
292 292
293 y += label_height + gap_between_labels; 293 y += label_height + gap_between_labels;
294 294
295 label = new views::Label(L"Banana:"); 295 label = new views::Label(L"Banana:");
296 label->SetID(kBananaLabelID); 296 label->SetID(kBananaLabelID);
297 left_container->AddChildView(label); 297 left_container->AddChildView(label);
298 label->SetBounds(label_x, y, label_width, label_height); 298 label->SetBounds(label_x, y, label_width, label_height);
299 299
300 text_field = new views::TextField(); 300 text_field = new views::Textfield();
301 text_field->SetID(kBananaTextFieldID); 301 text_field->SetID(kBananaTextfieldID);
302 left_container->AddChildView(text_field); 302 left_container->AddChildView(text_field);
303 text_field->SetBounds(label_x + label_width + 5, y, 303 text_field->SetBounds(label_x + label_width + 5, y,
304 text_field_width, label_height); 304 text_field_width, label_height);
305 305
306 y += label_height + gap_between_labels; 306 y += label_height + gap_between_labels;
307 307
308 label = new views::Label(L"Kiwi:"); 308 label = new views::Label(L"Kiwi:");
309 label->SetID(kKiwiLabelID); 309 label->SetID(kKiwiLabelID);
310 left_container->AddChildView(label); 310 left_container->AddChildView(label);
311 label->SetBounds(label_x, y, label_width, label_height); 311 label->SetBounds(label_x, y, label_width, label_height);
312 312
313 text_field = new views::TextField(); 313 text_field = new views::Textfield();
314 text_field->SetID(kKiwiTextFieldID); 314 text_field->SetID(kKiwiTextfieldID);
315 left_container->AddChildView(text_field); 315 left_container->AddChildView(text_field);
316 text_field->SetBounds(label_x + label_width + 5, y, 316 text_field->SetBounds(label_x + label_width + 5, y,
317 text_field_width, label_height); 317 text_field_width, label_height);
318 318
319 y += label_height + gap_between_labels; 319 y += label_height + gap_between_labels;
320 320
321 views::NativeButton* button = new views::NativeButton(NULL, L"Click me"); 321 views::NativeButton* button = new views::NativeButton(NULL, L"Click me");
322 button->SetBounds(label_x, y + 10, 50, 20); 322 button->SetBounds(label_x, y + 10, 50, 20);
323 button->SetID(kFruitButtonID); 323 button->SetID(kFruitButtonID);
324 left_container->AddChildView(button); 324 left_container->AddChildView(button);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 style_tab_->SetID(kStyleContainerID); 450 style_tab_->SetID(kStyleContainerID);
451 contents_->AddChildView(style_tab_); 451 contents_->AddChildView(style_tab_);
452 style_tab_->SetBounds(10, y, 210, 50); 452 style_tab_->SetBounds(10, y, 210, 50);
453 style_tab_->AddTab(L"Style", contents); 453 style_tab_->AddTab(L"Style", contents);
454 style_tab_->AddTab(L"Other", new views::View()); 454 style_tab_->AddTab(L"Other", new views::View());
455 455
456 // Right bottom box with search. 456 // Right bottom box with search.
457 contents = new views::View(); 457 contents = new views::View();
458 contents->set_background( 458 contents->set_background(
459 views::Background::CreateSolidBackground(SK_ColorWHITE)); 459 views::Background::CreateSolidBackground(SK_ColorWHITE));
460 text_field = new views::TextField(); 460 text_field = new views::Textfield();
461 contents->AddChildView(text_field); 461 contents->AddChildView(text_field);
462 text_field->SetBounds(10, 10, 100, 20); 462 text_field->SetBounds(10, 10, 100, 20);
463 text_field->SetID(kSearchTextFieldID); 463 text_field->SetID(kSearchTextfieldID);
464 464
465 button = new views::NativeButton(NULL, L"Search"); 465 button = new views::NativeButton(NULL, L"Search");
466 contents->AddChildView(button); 466 contents->AddChildView(button);
467 button->SetBounds(115, 10, 50, 20); 467 button->SetBounds(115, 10, 50, 20);
468 button->SetID(kSearchButtonID); 468 button->SetID(kSearchButtonID);
469 469
470 views::Link* link = new views::Link(L"Help"); 470 views::Link* link = new views::Link(L"Help");
471 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 471 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
472 link->SetID(kHelpLinkID); 472 link->SetID(kHelpLinkID);
473 contents->AddChildView(link); 473 contents->AddChildView(link);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 message_loop_.RunAllPending(); 527 message_loop_.RunAllPending();
528 OleUninitialize(); 528 OleUninitialize();
529 } 529 }
530 530
531 //////////////////////////////////////////////////////////////////////////////// 531 ////////////////////////////////////////////////////////////////////////////////
532 // The tests 532 // The tests
533 //////////////////////////////////////////////////////////////////////////////// 533 ////////////////////////////////////////////////////////////////////////////////
534 534
535 535
536 TEST_F(FocusManagerTest, NormalTraversal) { 536 TEST_F(FocusManagerTest, NormalTraversal) {
537 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextFieldID, 537 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID,
538 kOrangeTextFieldID, kBananaTextFieldID, kKiwiTextFieldID, 538 kOrangeTextfieldID, kBananaTextfieldID, kKiwiTextfieldID,
539 kFruitButtonID, kFruitCheckBoxID, kAsparagusButtonID, kRosettaLinkID, 539 kFruitButtonID, kFruitCheckBoxID, kAsparagusButtonID, kRosettaLinkID,
540 kStupeurEtTremblementLinkID, 540 kStupeurEtTremblementLinkID,
541 kDinerGameLinkID, kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, 541 kDinerGameLinkID, kRidiculeLinkID, kClosetLinkID, kVisitingLinkID,
542 kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID, 542 kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID,
543 kTaxiLinkID, kAsterixLinkID, kOKButtonID, kCancelButtonID, kHelpButtonID, 543 kTaxiLinkID, kAsterixLinkID, kOKButtonID, kCancelButtonID, kHelpButtonID,
544 kStyleContainerID, kBoldCheckBoxID, kItalicCheckBoxID, 544 kStyleContainerID, kBoldCheckBoxID, kItalicCheckBoxID,
545 kUnderlinedCheckBoxID, kSearchTextFieldID, kSearchButtonID, kHelpLinkID, 545 kUnderlinedCheckBoxID, kSearchTextfieldID, kSearchButtonID, kHelpLinkID,
546 kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID }; 546 kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID };
547 547
548 // Uncomment the following line if you want to test manually the UI of this 548 // Uncomment the following line if you want to test manually the UI of this
549 // test. 549 // test.
550 // MessageLoop::current()->Run(new views::AcceleratorHandler()); 550 // MessageLoop::current()->Run(new views::AcceleratorHandler());
551 551
552 views::FocusManager* focus_manager = 552 views::FocusManager* focus_manager =
553 views::FocusManager::GetFocusManager(test_window_->GetNativeView()); 553 views::FocusManager::GetFocusManager(test_window_->GetNativeView());
554 // Let's traverse the whole focus hierarchy (several times, to make sure it 554 // Let's traverse the whole focus hierarchy (several times, to make sure it
555 // loops OK). 555 // loops OK).
(...skipping 22 matching lines...) Expand all
578 EXPECT_TRUE(focused_view != NULL); 578 EXPECT_TRUE(focused_view != NULL);
579 if (focused_view) 579 if (focused_view)
580 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID()); 580 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
581 } 581 }
582 } 582 }
583 */ 583 */
584 } 584 }
585 585
586 TEST_F(FocusManagerTest, TraversalWithNonEnabledViews) { 586 TEST_F(FocusManagerTest, TraversalWithNonEnabledViews) {
587 const int kMainContentsDisabledIDs[] = { 587 const int kMainContentsDisabledIDs[] = {
588 kBananaTextFieldID, kFruitCheckBoxID, kAsparagusButtonID, 588 kBananaTextfieldID, kFruitCheckBoxID, kAsparagusButtonID,
589 kCauliflowerButtonID, kClosetLinkID, kVisitingLinkID, kBriceDeNiceLinkID, 589 kCauliflowerButtonID, kClosetLinkID, kVisitingLinkID, kBriceDeNiceLinkID,
590 kTaxiLinkID, kAsterixLinkID, kHelpButtonID }; 590 kTaxiLinkID, kAsterixLinkID, kHelpButtonID };
591 591
592 const int kStyleContentsDisabledIDs[] = { kBoldCheckBoxID }; 592 const int kStyleContentsDisabledIDs[] = { kBoldCheckBoxID };
593 593
594 const int kSearchContentsDisabledIDs[] = { kSearchTextFieldID, kHelpLinkID }; 594 const int kSearchContentsDisabledIDs[] = { kSearchTextfieldID, kHelpLinkID };
595 595
596 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextFieldID, 596 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID,
597 kOrangeTextFieldID, kKiwiTextFieldID, kFruitButtonID, kBroccoliButtonID, 597 kOrangeTextfieldID, kKiwiTextfieldID, kFruitButtonID, kBroccoliButtonID,
598 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID, 598 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID,
599 kRidiculeLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, 599 kRidiculeLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID,
600 kOKButtonID, kCancelButtonID, kStyleContainerID, 600 kOKButtonID, kCancelButtonID, kStyleContainerID,
601 kItalicCheckBoxID, kUnderlinedCheckBoxID, kSearchButtonID, 601 kItalicCheckBoxID, kUnderlinedCheckBoxID, kSearchButtonID,
602 kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID }; 602 kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID };
603 603
604 // Let's disable some views. 604 // Let's disable some views.
605 views::RootView* root_view = test_window_->GetContentsRootView(); 605 views::RootView* root_view = test_window_->GetContentsRootView();
606 for (int i = 0; i < arraysize(kMainContentsDisabledIDs); i++) { 606 for (int i = 0; i < arraysize(kMainContentsDisabledIDs); i++) {
607 views::View* v = root_view->GetViewByID(kMainContentsDisabledIDs[i]); 607 views::View* v = root_view->GetViewByID(kMainContentsDisabledIDs[i]);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 focused_view = focus_manager->GetFocusedView(); 657 focused_view = focus_manager->GetFocusedView();
658 EXPECT_TRUE(focused_view != NULL); 658 EXPECT_TRUE(focused_view != NULL);
659 if (focused_view) 659 if (focused_view)
660 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID()); 660 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
661 } 661 }
662 } 662 }
663 */ 663 */
664 } 664 }
665 665
666 } 666 }
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield.cc ('k') | views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698