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

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

Issue 8142026: Revert 104076 - Change std::wstring to string16 for views::Link (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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/examples/examples_main.cc ('k') | views/widget/tooltip_manager_views.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) 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "third_party/skia/include/core/SkColor.h" 9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 content_view_->AddChildView(left_container_); 490 content_view_->AddChildView(left_container_);
491 left_container_->SetBounds(10, 35, 250, 200); 491 left_container_->SetBounds(10, 35, 250, 200);
492 492
493 int label_x = 5; 493 int label_x = 5;
494 int label_width = 50; 494 int label_width = 50;
495 int label_height = 15; 495 int label_height = 15;
496 int text_field_width = 150; 496 int text_field_width = 150;
497 int y = 10; 497 int y = 10;
498 int gap_between_labels = 10; 498 int gap_between_labels = 10;
499 499
500 Label* label = new Label(ASCIIToUTF16("Apple:")); 500 Label* label = new Label(L"Apple:");
501 label->set_id(kAppleLabelID); 501 label->set_id(kAppleLabelID);
502 left_container_->AddChildView(label); 502 left_container_->AddChildView(label);
503 label->SetBounds(label_x, y, label_width, label_height); 503 label->SetBounds(label_x, y, label_width, label_height);
504 504
505 Textfield* text_field = new Textfield(); 505 Textfield* text_field = new Textfield();
506 text_field->set_id(kAppleTextfieldID); 506 text_field->set_id(kAppleTextfieldID);
507 left_container_->AddChildView(text_field); 507 left_container_->AddChildView(text_field);
508 text_field->SetBounds(label_x + label_width + 5, y, 508 text_field->SetBounds(label_x + label_width + 5, y,
509 text_field_width, label_height); 509 text_field_width, label_height);
510 510
511 y += label_height + gap_between_labels; 511 y += label_height + gap_between_labels;
512 512
513 label = new Label(ASCIIToUTF16("Orange:")); 513 label = new Label(L"Orange:");
514 label->set_id(kOrangeLabelID); 514 label->set_id(kOrangeLabelID);
515 left_container_->AddChildView(label); 515 left_container_->AddChildView(label);
516 label->SetBounds(label_x, y, label_width, label_height); 516 label->SetBounds(label_x, y, label_width, label_height);
517 517
518 text_field = new Textfield(); 518 text_field = new Textfield();
519 text_field->set_id(kOrangeTextfieldID); 519 text_field->set_id(kOrangeTextfieldID);
520 left_container_->AddChildView(text_field); 520 left_container_->AddChildView(text_field);
521 text_field->SetBounds(label_x + label_width + 5, y, 521 text_field->SetBounds(label_x + label_width + 5, y,
522 text_field_width, label_height); 522 text_field_width, label_height);
523 523
524 y += label_height + gap_between_labels; 524 y += label_height + gap_between_labels;
525 525
526 label = new Label(ASCIIToUTF16("Banana:")); 526 label = new Label(L"Banana:");
527 label->set_id(kBananaLabelID); 527 label->set_id(kBananaLabelID);
528 left_container_->AddChildView(label); 528 left_container_->AddChildView(label);
529 label->SetBounds(label_x, y, label_width, label_height); 529 label->SetBounds(label_x, y, label_width, label_height);
530 530
531 text_field = new Textfield(); 531 text_field = new Textfield();
532 text_field->set_id(kBananaTextfieldID); 532 text_field->set_id(kBananaTextfieldID);
533 left_container_->AddChildView(text_field); 533 left_container_->AddChildView(text_field);
534 text_field->SetBounds(label_x + label_width + 5, y, 534 text_field->SetBounds(label_x + label_width + 5, y,
535 text_field_width, label_height); 535 text_field_width, label_height);
536 536
537 y += label_height + gap_between_labels; 537 y += label_height + gap_between_labels;
538 538
539 label = new Label(ASCIIToUTF16("Kiwi:")); 539 label = new Label(L"Kiwi:");
540 label->set_id(kKiwiLabelID); 540 label->set_id(kKiwiLabelID);
541 left_container_->AddChildView(label); 541 left_container_->AddChildView(label);
542 label->SetBounds(label_x, y, label_width, label_height); 542 label->SetBounds(label_x, y, label_width, label_height);
543 543
544 text_field = new Textfield(); 544 text_field = new Textfield();
545 text_field->set_id(kKiwiTextfieldID); 545 text_field->set_id(kKiwiTextfieldID);
546 left_container_->AddChildView(text_field); 546 left_container_->AddChildView(text_field);
547 text_field->SetBounds(label_x + label_width + 5, y, 547 text_field->SetBounds(label_x + label_width + 5, y,
548 text_field_width, label_height); 548 text_field_width, label_height);
549 549
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 scroll_view->set_id(kScrollViewID); 609 scroll_view->set_id(kScrollViewID);
610 inner_container->AddChildView(scroll_view); 610 inner_container->AddChildView(scroll_view);
611 scroll_view->SetBounds(1, 1, 148, 178); 611 scroll_view->SetBounds(1, 1, 148, 178);
612 612
613 View* scroll_content = new View(); 613 View* scroll_content = new View();
614 scroll_content->SetBounds(0, 0, 200, 200); 614 scroll_content->SetBounds(0, 0, 200, 200);
615 scroll_content->set_background( 615 scroll_content->set_background(
616 Background::CreateSolidBackground(200, 200, 200)); 616 Background::CreateSolidBackground(200, 200, 200));
617 scroll_view->SetContents(scroll_content); 617 scroll_view->SetContents(scroll_content);
618 618
619 static const char* const kTitles[] = { 619 static const wchar_t* const kTitles[] = {
620 "Rosetta", "Stupeur et tremblement", "The diner game", 620 L"Rosetta", L"Stupeur et tremblement", L"The diner game",
621 "Ridicule", "Le placard", "Les Visiteurs", "Amelie", 621 L"Ridicule", L"Le placard", L"Les Visiteurs", L"Amelie",
622 "Joyeux Noel", "Camping", "Brice de Nice", 622 L"Joyeux Noel", L"Camping", L"Brice de Nice",
623 "Taxi", "Asterix" 623 L"Taxi", L"Asterix"
624 }; 624 };
625 625
626 static const int kIDs[] = { 626 static const int kIDs[] = {
627 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID, 627 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID,
628 kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, kAmelieLinkID, 628 kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, kAmelieLinkID,
629 kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID, 629 kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID,
630 kTaxiLinkID, kAsterixLinkID 630 kTaxiLinkID, kAsterixLinkID
631 }; 631 };
632 632
633 DCHECK(arraysize(kTitles) == arraysize(kIDs)); 633 DCHECK(arraysize(kTitles) == arraysize(kIDs));
634 634
635 y = 5; 635 y = 5;
636 for (size_t i = 0; i < arraysize(kTitles); ++i) { 636 for (size_t i = 0; i < arraysize(kTitles); ++i) {
637 Link* link = new Link(ASCIIToUTF16(kTitles[i])); 637 Link* link = new Link(kTitles[i]);
638 link->SetHorizontalAlignment(Label::ALIGN_LEFT); 638 link->SetHorizontalAlignment(Label::ALIGN_LEFT);
639 link->set_id(kIDs[i]); 639 link->set_id(kIDs[i]);
640 scroll_content->AddChildView(link); 640 scroll_content->AddChildView(link);
641 link->SetBounds(5, y, 300, 15); 641 link->SetBounds(5, y, 300, 15);
642 y += 15; 642 y += 15;
643 } 643 }
644 644
645 y = 250; 645 y = 250;
646 int width = 60; 646 int width = 60;
647 button = new NativeTextButton(NULL, L"OK"); 647 button = new NativeTextButton(NULL, L"OK");
(...skipping 26 matching lines...) Expand all
674 cb = new Checkbox(L"Italic"); 674 cb = new Checkbox(L"Italic");
675 contents->AddChildView(cb); 675 contents->AddChildView(cb);
676 cb->SetBounds(70, 10, 50, 20); 676 cb->SetBounds(70, 10, 50, 20);
677 cb->set_id(kItalicCheckBoxID); 677 cb->set_id(kItalicCheckBoxID);
678 678
679 cb = new Checkbox(L"Underlined"); 679 cb = new Checkbox(L"Underlined");
680 contents->AddChildView(cb); 680 contents->AddChildView(cb);
681 cb->SetBounds(130, 10, 70, 20); 681 cb->SetBounds(130, 10, 70, 20);
682 cb->set_id(kUnderlinedCheckBoxID); 682 cb->set_id(kUnderlinedCheckBoxID);
683 683
684 Link* link = new Link(ASCIIToUTF16("Help")); 684 Link* link = new Link(L"Help");
685 contents->AddChildView(link); 685 contents->AddChildView(link);
686 link->SetBounds(10, 35, 70, 10); 686 link->SetBounds(10, 35, 70, 10);
687 link->set_id(kStyleHelpLinkID); 687 link->set_id(kStyleHelpLinkID);
688 688
689 text_field = new Textfield(); 689 text_field = new Textfield();
690 contents->AddChildView(text_field); 690 contents->AddChildView(text_field);
691 text_field->SetBounds(10, 50, 100, 20); 691 text_field->SetBounds(10, 50, 100, 20);
692 text_field->set_id(kStyleTextEditID); 692 text_field->set_id(kStyleTextEditID);
693 693
694 style_tab_ = new TabbedPane(); 694 style_tab_ = new TabbedPane();
695 style_tab_->set_id(kStyleContainerID); 695 style_tab_->set_id(kStyleContainerID);
696 content_view_->AddChildView(style_tab_); 696 content_view_->AddChildView(style_tab_);
697 style_tab_->SetBounds(10, y, 210, 100); 697 style_tab_->SetBounds(10, y, 210, 100);
698 style_tab_->AddTab(ASCIIToUTF16("Style"), contents); 698 style_tab_->AddTab(ASCIIToUTF16("Style"), contents);
699 style_tab_->AddTab(ASCIIToUTF16("Other"), new View()); 699 style_tab_->AddTab(ASCIIToUTF16("Other"), new View());
700 700
701 // Right bottom box with search. 701 // Right bottom box with search.
702 contents = new View(); 702 contents = new View();
703 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); 703 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE));
704 text_field = new Textfield(); 704 text_field = new Textfield();
705 contents->AddChildView(text_field); 705 contents->AddChildView(text_field);
706 text_field->SetBounds(10, 10, 100, 20); 706 text_field->SetBounds(10, 10, 100, 20);
707 text_field->set_id(kSearchTextfieldID); 707 text_field->set_id(kSearchTextfieldID);
708 708
709 button = new NativeTextButton(NULL, L"Search"); 709 button = new NativeTextButton(NULL, L"Search");
710 contents->AddChildView(button); 710 contents->AddChildView(button);
711 button->SetBounds(112, 5, 60, 30); 711 button->SetBounds(112, 5, 60, 30);
712 button->set_id(kSearchButtonID); 712 button->set_id(kSearchButtonID);
713 713
714 link = new Link(ASCIIToUTF16("Help")); 714 link = new Link(L"Help");
715 link->SetHorizontalAlignment(Label::ALIGN_LEFT); 715 link->SetHorizontalAlignment(Label::ALIGN_LEFT);
716 link->set_id(kHelpLinkID); 716 link->set_id(kHelpLinkID);
717 contents->AddChildView(link); 717 contents->AddChildView(link);
718 link->SetBounds(175, 10, 30, 20); 718 link->SetBounds(175, 10, 30, 20);
719 719
720 search_border_view_ = new BorderView(contents); 720 search_border_view_ = new BorderView(contents);
721 search_border_view_->set_id(kSearchContainerID); 721 search_border_view_->set_id(kSearchContainerID);
722 722
723 content_view_->AddChildView(search_border_view_); 723 content_view_->AddChildView(search_border_view_);
724 search_border_view_->SetBounds(300, y, 240, 50); 724 search_border_view_->SetBounds(300, y, 240, 50);
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 FindViewByID(kBroccoliButtonID)->RequestFocus(); 1276 FindViewByID(kBroccoliButtonID)->RequestFocus();
1277 for (int i = 0; i < 3; ++i) { 1277 for (int i = 0; i < 3; ++i) {
1278 for (int j = arraysize(kRightTraversalIDs) - 1; j >= 0; --j) { 1278 for (int j = arraysize(kRightTraversalIDs) - 1; j >= 0; --j) {
1279 GetFocusManager()->AdvanceFocus(true); 1279 GetFocusManager()->AdvanceFocus(true);
1280 View* focused_view = GetFocusManager()->GetFocusedView(); 1280 View* focused_view = GetFocusManager()->GetFocusedView();
1281 EXPECT_TRUE(focused_view != NULL); 1281 EXPECT_TRUE(focused_view != NULL);
1282 if (focused_view) 1282 if (focused_view)
1283 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); 1283 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id());
1284 } 1284 }
1285 } 1285 }
1286
1286 } 1287 }
1287 1288
1288 // Counts accelerator calls. 1289 // Counts accelerator calls.
1289 class TestAcceleratorTarget : public AcceleratorTarget { 1290 class TestAcceleratorTarget : public AcceleratorTarget {
1290 public: 1291 public:
1291 explicit TestAcceleratorTarget(bool process_accelerator) 1292 explicit TestAcceleratorTarget(bool process_accelerator)
1292 : accelerator_count_(0), process_accelerator_(process_accelerator) {} 1293 : accelerator_count_(0), process_accelerator_(process_accelerator) {}
1293 1294
1294 virtual bool AcceleratorPressed(const Accelerator& accelerator) { 1295 virtual bool AcceleratorPressed(const Accelerator& accelerator) {
1295 ++accelerator_count_; 1296 ++accelerator_count_;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); 1444 focus_manager->GetCurrentTargetForAccelerator(return_accelerator));
1444 1445
1445 // Hitting the return key again; nothing should happen. 1446 // Hitting the return key again; nothing should happen.
1446 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1447 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1447 EXPECT_EQ(target.accelerator_count(), 1); 1448 EXPECT_EQ(target.accelerator_count(), 1);
1448 } 1449 }
1449 1450
1450 class MessageTrackingView : public View { 1451 class MessageTrackingView : public View {
1451 public: 1452 public:
1452 MessageTrackingView() : accelerator_pressed_(false) { 1453 MessageTrackingView() : accelerator_pressed_(false) {
1453 } 1454 }
1454 1455
1455 virtual bool OnKeyPressed(const KeyEvent& e) { 1456 virtual bool OnKeyPressed(const KeyEvent& e) {
1456 keys_pressed_.push_back(e.key_code()); 1457 keys_pressed_.push_back(e.key_code());
1457 return true; 1458 return true;
1458 } 1459 }
1459 1460
1460 virtual bool OnKeyReleased(const KeyEvent& e) { 1461 virtual bool OnKeyReleased(const KeyEvent& e) {
1461 keys_released_.push_back(e.key_code()); 1462 keys_released_.push_back(e.key_code());
1462 return true; 1463 return true;
1463 } 1464 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 } 1657 }
1657 1658
1658 DtorTrackVector* dtor_tracker_; 1659 DtorTrackVector* dtor_tracker_;
1659 1660
1660 private: 1661 private:
1661 DISALLOW_COPY_AND_ASSIGN(FocusManagerDtorTracked); 1662 DISALLOW_COPY_AND_ASSIGN(FocusManagerDtorTracked);
1662 }; 1663 };
1663 1664
1664 class TestFocusManagerFactory : public FocusManagerFactory { 1665 class TestFocusManagerFactory : public FocusManagerFactory {
1665 public: 1666 public:
1666 explicit TestFocusManagerFactory(DtorTrackVector* dtor_tracker) 1667 TestFocusManagerFactory(DtorTrackVector* dtor_tracker)
1667 : dtor_tracker_(dtor_tracker) { 1668 : dtor_tracker_(dtor_tracker) {
1668 } 1669 }
1669 1670
1670 FocusManager* CreateFocusManager(Widget* widget) OVERRIDE { 1671 FocusManager* CreateFocusManager(Widget* widget) OVERRIDE {
1671 return new FocusManagerDtorTracked(widget, dtor_tracker_); 1672 return new FocusManagerDtorTracked(widget, dtor_tracker_);
1672 } 1673 }
1673 1674
1674 private: 1675 private:
1675 DtorTrackVector* dtor_tracker_; 1676 DtorTrackVector* dtor_tracker_;
1676 DISALLOW_COPY_AND_ASSIGN(TestFocusManagerFactory); 1677 DISALLOW_COPY_AND_ASSIGN(TestFocusManagerFactory);
1677 }; 1678 };
1678 1679
1679 class NativeButtonDtorTracked : public NativeTextButton { 1680 class NativeButtonDtorTracked : public NativeTextButton {
1680 public: 1681 public:
1681 NativeButtonDtorTracked(const std::wstring& text, 1682 NativeButtonDtorTracked(const std::wstring& text,
1682 DtorTrackVector* dtor_tracker) 1683 DtorTrackVector* dtor_tracker)
1683 : NativeTextButton(NULL, text), 1684 : NativeTextButton(NULL, text),
1684 dtor_tracker_(dtor_tracker) { 1685 dtor_tracker_(dtor_tracker) {
1685 }; 1686 };
1686 virtual ~NativeButtonDtorTracked() { 1687 virtual ~NativeButtonDtorTracked() {
1687 dtor_tracker_->push_back("NativeButtonDtorTracked"); 1688 dtor_tracker_->push_back("NativeButtonDtorTracked");
1688 } 1689 }
1689 1690
1690 DtorTrackVector* dtor_tracker_; 1691 DtorTrackVector* dtor_tracker_;
1691 }; 1692 };
1692 1693
1693 class WindowDtorTracked : public Widget { 1694 class WindowDtorTracked : public Widget {
1694 public: 1695 public:
1695 explicit WindowDtorTracked(DtorTrackVector* dtor_tracker) 1696 WindowDtorTracked(DtorTrackVector* dtor_tracker)
1696 : dtor_tracker_(dtor_tracker) { 1697 : dtor_tracker_(dtor_tracker) {
1697 } 1698 }
1698 1699
1699 virtual ~WindowDtorTracked() { 1700 virtual ~WindowDtorTracked() {
1700 dtor_tracker_->push_back("WindowDtorTracked"); 1701 dtor_tracker_->push_back("WindowDtorTracked");
1701 } 1702 }
1702 1703
1703 DtorTrackVector* dtor_tracker_; 1704 DtorTrackVector* dtor_tracker_;
1704 }; 1705 };
1705 1706
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); 1749 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size()));
1749 1750
1750 // Focus manager should be the last one to destruct. 1751 // Focus manager should be the last one to destruct.
1751 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); 1752 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str());
1752 1753
1753 // Clear window_ so that we don't try to close it again. 1754 // Clear window_ so that we don't try to close it again.
1754 window_ = NULL; 1755 window_ = NULL;
1755 } 1756 }
1756 1757
1757 } // namespace views 1758 } // namespace views
OLDNEW
« no previous file with comments | « views/examples/examples_main.cc ('k') | views/widget/tooltip_manager_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698