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

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

Issue 120503005: Merge NativeTextfieldViews into views::Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix touch drag and drop unit test. Created 6 years, 11 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
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/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 1511 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
1512 params.bounds = gfx::Rect(0, 0, 100, 100); 1512 params.bounds = gfx::Rect(0, 0, 100, 100);
1513 widget->Init(params); 1513 widget->Init(params);
1514 View* root_view = widget->GetRootView(); 1514 View* root_view = widget->GetRootView();
1515 1515
1516 Textfield* textfield = new Textfield(); 1516 Textfield* textfield = new Textfield();
1517 root_view->AddChildView(textfield); 1517 root_view->AddChildView(textfield);
1518 1518
1519 // Test setting, appending text. 1519 // Test setting, appending text.
1520 textfield->SetText(kText); 1520 textfield->SetText(kText);
1521 EXPECT_EQ(kText, textfield->text()); 1521 EXPECT_EQ(kText, textfield->GetText());
1522 textfield->AppendText(kExtraText); 1522 textfield->AppendText(kExtraText);
1523 EXPECT_EQ(kText + kExtraText, textfield->text()); 1523 EXPECT_EQ(kText + kExtraText, textfield->GetText());
1524 textfield->SetText(base::string16()); 1524 textfield->SetText(base::string16());
1525 EXPECT_EQ(kEmptyString, textfield->text()); 1525 EXPECT_EQ(kEmptyString, textfield->GetText());
1526 1526
1527 // Test selection related methods. 1527 // Test selection related methods.
1528 textfield->SetText(kText); 1528 textfield->SetText(kText);
1529 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); 1529 EXPECT_EQ(kEmptyString, textfield->GetSelectedText());
1530 textfield->SelectAll(false); 1530 textfield->SelectAll(false);
1531 EXPECT_EQ(kText, textfield->text()); 1531 EXPECT_EQ(kText, textfield->GetText());
1532 textfield->ClearSelection(); 1532 textfield->ClearSelection();
1533 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); 1533 EXPECT_EQ(kEmptyString, textfield->GetSelectedText());
1534 1534
1535 widget->CloseNow(); 1535 widget->CloseNow();
1536 } 1536 }
1537 1537
1538 // Tests that the Textfield view respond appropiately to cut/copy/paste. 1538 // Tests that the Textfield view respond appropiately to cut/copy/paste.
1539 TEST_F(ViewTest, TextfieldCutCopyPaste) { 1539 TEST_F(ViewTest, TextfieldCutCopyPaste) {
1540 const base::string16 kNormalText = ASCIIToUTF16("Normal"); 1540 const base::string16 kNormalText = ASCIIToUTF16("Normal");
1541 const base::string16 kReadOnlyText = ASCIIToUTF16("Read only"); 1541 const base::string16 kReadOnlyText = ASCIIToUTF16("Read only");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 // Text cannot be copied from an obscured field; the clipboard won't change. 1612 // Text cannot be copied from an obscured field; the clipboard won't change.
1613 EXPECT_EQ(kNormalText, result); 1613 EXPECT_EQ(kNormalText, result);
1614 1614
1615 // 1615 //
1616 // Test paste. 1616 // Test paste.
1617 // 1617 //
1618 1618
1619 // Attempting to paste kNormalText in a read-only text-field should fail. 1619 // Attempting to paste kNormalText in a read-only text-field should fail.
1620 read_only->SelectAll(false); 1620 read_only->SelectAll(false);
1621 read_only->ExecuteCommand(IDS_APP_PASTE); 1621 read_only->ExecuteCommand(IDS_APP_PASTE);
1622 EXPECT_EQ(kReadOnlyText, read_only->text()); 1622 EXPECT_EQ(kReadOnlyText, read_only->GetText());
1623 1623
1624 password->SelectAll(false); 1624 password->SelectAll(false);
1625 password->ExecuteCommand(IDS_APP_PASTE); 1625 password->ExecuteCommand(IDS_APP_PASTE);
1626 EXPECT_EQ(kNormalText, password->text()); 1626 EXPECT_EQ(kNormalText, password->GetText());
1627 1627
1628 // Copy from |read_only| to observe a change in the normal textfield text. 1628 // Copy from |read_only| to observe a change in the normal textfield text.
1629 read_only->SelectAll(false); 1629 read_only->SelectAll(false);
1630 read_only->ExecuteCommand(IDS_APP_COPY); 1630 read_only->ExecuteCommand(IDS_APP_COPY);
1631 normal->SelectAll(false); 1631 normal->SelectAll(false);
1632 normal->ExecuteCommand(IDS_APP_PASTE); 1632 normal->ExecuteCommand(IDS_APP_PASTE);
1633 EXPECT_EQ(kReadOnlyText, normal->text()); 1633 EXPECT_EQ(kReadOnlyText, normal->GetText());
1634 widget->CloseNow(); 1634 widget->CloseNow();
1635 } 1635 }
1636 1636
1637 //////////////////////////////////////////////////////////////////////////////// 1637 ////////////////////////////////////////////////////////////////////////////////
1638 // Accelerators 1638 // Accelerators
1639 //////////////////////////////////////////////////////////////////////////////// 1639 ////////////////////////////////////////////////////////////////////////////////
1640 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) { 1640 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) {
1641 accelerator_count_map_[accelerator]++; 1641 accelerator_count_map_[accelerator]++;
1642 return true; 1642 return true;
1643 } 1643 }
(...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after
3566 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); 3566 const std::vector<ui::Layer*>& child_layers_post = root_layer->children();
3567 ASSERT_EQ(3u, child_layers_post.size()); 3567 ASSERT_EQ(3u, child_layers_post.size());
3568 EXPECT_EQ(v1->layer(), child_layers_post[0]); 3568 EXPECT_EQ(v1->layer(), child_layers_post[0]);
3569 EXPECT_EQ(v2->layer(), child_layers_post[1]); 3569 EXPECT_EQ(v2->layer(), child_layers_post[1]);
3570 EXPECT_EQ(v1_old_layer, child_layers_post[2]); 3570 EXPECT_EQ(v1_old_layer, child_layers_post[2]);
3571 } 3571 }
3572 3572
3573 #endif // USE_AURA 3573 #endif // USE_AURA
3574 3574
3575 } // namespace views 3575 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698