| OLD | NEW |
| 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 "ui/views/controls/tree/tree_view.h" | 5 #include "ui/views/controls/tree/tree_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 std::string GetSelectedNodeTitle(); | 55 std::string GetSelectedNodeTitle(); |
| 56 | 56 |
| 57 std::string GetEditingNodeTitle(); | 57 std::string GetEditingNodeTitle(); |
| 58 | 58 |
| 59 TestNode* GetNodeByTitle(const std::string& title); | 59 TestNode* GetNodeByTitle(const std::string& title); |
| 60 | 60 |
| 61 void IncrementSelection(bool next); | 61 void IncrementSelection(bool next); |
| 62 void CollapseOrSelectParent(); | 62 void CollapseOrSelectParent(); |
| 63 void ExpandOrSelectChild(); | 63 void ExpandOrSelectChild(); |
| 64 int GetRowCount(); | 64 int GetRowCount(); |
| 65 PrefixSelector* selector() { return tree_.selector_.get(); } | 65 PrefixSelector* selector() { return tree_.GetPrefixSelector(); } |
| 66 | 66 |
| 67 ui::TreeNodeModel<TestNode > model_; | 67 ui::TreeNodeModel<TestNode > model_; |
| 68 TreeView tree_; | 68 TreeView tree_; |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 std::string InternalNodeAsString(TreeView::InternalNode* node); | 71 std::string InternalNodeAsString(TreeView::InternalNode* node); |
| 72 | 72 |
| 73 TestNode* GetNodeByTitleImpl(TestNode* node, const base::string16& title); | 73 TestNode* GetNodeByTitleImpl(TestNode* node, const base::string16& title); |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(TreeViewTest); | 75 DISALLOW_COPY_AND_ASSIGN(TreeViewTest); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 EXPECT_EQ("b1", GetSelectedNodeTitle()); | 385 EXPECT_EQ("b1", GetSelectedNodeTitle()); |
| 386 ExpandOrSelectChild(); | 386 ExpandOrSelectChild(); |
| 387 EXPECT_EQ("root [a b [b1] c]", TreeViewContentsAsString()); | 387 EXPECT_EQ("root [a b [b1] c]", TreeViewContentsAsString()); |
| 388 EXPECT_EQ("b1", GetSelectedNodeTitle()); | 388 EXPECT_EQ("b1", GetSelectedNodeTitle()); |
| 389 } | 389 } |
| 390 | 390 |
| 391 // Verify selection is properly updated on each keystroke. | 391 // Verify selection is properly updated on each keystroke. |
| 392 TEST_F(TreeViewTest, SelectOnKeyStroke) { | 392 TEST_F(TreeViewTest, SelectOnKeyStroke) { |
| 393 tree_.SetModel(&model_); | 393 tree_.SetModel(&model_); |
| 394 tree_.ExpandAll(model_.GetRoot()); | 394 tree_.ExpandAll(model_.GetRoot()); |
| 395 tree_.GetTextInputClient(); | |
| 396 selector()->InsertText(ASCIIToUTF16("b")); | 395 selector()->InsertText(ASCIIToUTF16("b")); |
| 397 EXPECT_EQ("b", GetSelectedNodeTitle()); | 396 EXPECT_EQ("b", GetSelectedNodeTitle()); |
| 398 selector()->InsertText(ASCIIToUTF16("1")); | 397 selector()->InsertText(ASCIIToUTF16("1")); |
| 399 EXPECT_EQ("b1", GetSelectedNodeTitle()); | 398 EXPECT_EQ("b1", GetSelectedNodeTitle()); |
| 400 | 399 |
| 401 // Invoke OnViewBlur() to reset time. | 400 // Invoke OnViewBlur() to reset time. |
| 402 selector()->OnViewBlur(); | 401 selector()->OnViewBlur(); |
| 403 selector()->InsertText(ASCIIToUTF16("z")); | 402 selector()->InsertText(ASCIIToUTF16("z")); |
| 404 EXPECT_EQ("b1", GetSelectedNodeTitle()); | 403 EXPECT_EQ("b1", GetSelectedNodeTitle()); |
| 405 | 404 |
| 406 selector()->OnViewBlur(); | 405 selector()->OnViewBlur(); |
| 407 selector()->InsertText(ASCIIToUTF16("a")); | 406 selector()->InsertText(ASCIIToUTF16("a")); |
| 408 EXPECT_EQ("a", GetSelectedNodeTitle()); | 407 EXPECT_EQ("a", GetSelectedNodeTitle()); |
| 409 } | 408 } |
| 410 | 409 |
| 411 // Verifies edits are committed when focus is lost. | 410 // Verifies edits are committed when focus is lost. |
| 412 TEST_F(TreeViewTest, CommitOnFocusLost) { | 411 TEST_F(TreeViewTest, CommitOnFocusLost) { |
| 413 tree_.SetModel(&model_); | 412 tree_.SetModel(&model_); |
| 414 | 413 |
| 415 tree_.SetSelectedNode(GetNodeByTitle("root")); | 414 tree_.SetSelectedNode(GetNodeByTitle("root")); |
| 416 ExpandOrSelectChild(); | 415 ExpandOrSelectChild(); |
| 417 tree_.SetEditable(true); | 416 tree_.SetEditable(true); |
| 418 tree_.StartEditing(GetNodeByTitle("a")); | 417 tree_.StartEditing(GetNodeByTitle("a")); |
| 419 tree_.editor()->SetText(ASCIIToUTF16("a changed")); | 418 tree_.editor()->SetText(ASCIIToUTF16("a changed")); |
| 420 tree_.OnDidChangeFocus(NULL, NULL); | 419 tree_.OnDidChangeFocus(NULL, NULL); |
| 421 EXPECT_TRUE(GetNodeByTitle("a changed") != NULL); | 420 EXPECT_TRUE(GetNodeByTitle("a changed") != NULL); |
| 422 } | 421 } |
| 423 | 422 |
| 424 } // namespace views | 423 } // namespace views |
| OLD | NEW |