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 "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <string> | 8 #include <string> |
8 | 9 |
| 10 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
14 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
15 #include "components/bookmarks/test/bookmark_test_helpers.h" | 17 #include "components/bookmarks/test/bookmark_test_helpers.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/views/controls/textfield/textfield.h" | 20 #include "ui/views/controls/textfield/textfield.h" |
19 #include "ui/views/controls/tree/tree_view.h" | 21 #include "ui/views/controls/tree/tree_view.h" |
| 22 #include "ui/views/test/test_views_delegate.h" |
20 | 23 |
21 using base::ASCIIToUTF16; | 24 using base::ASCIIToUTF16; |
22 using base::UTF8ToUTF16; | 25 using base::UTF8ToUTF16; |
23 using base::Time; | 26 using base::Time; |
24 using base::TimeDelta; | 27 using base::TimeDelta; |
25 using bookmarks::BookmarkModel; | 28 using bookmarks::BookmarkModel; |
26 using bookmarks::BookmarkNode; | 29 using bookmarks::BookmarkNode; |
27 | 30 |
28 // Base class for bookmark editor tests. Creates a BookmarkModel and populates | 31 // Base class for bookmark editor tests. Creates a BookmarkModel and populates |
29 // it with test data. | 32 // it with test data. |
30 class BookmarkEditorViewTest : public testing::Test { | 33 class BookmarkEditorViewTest : public testing::Test { |
31 public: | 34 public: |
32 BookmarkEditorViewTest() : model_(nullptr) {} | 35 BookmarkEditorViewTest() : model_(nullptr) {} |
33 | 36 |
34 void SetUp() override { | 37 void SetUp() override { |
35 profile_.reset(new TestingProfile()); | 38 profile_.reset(new TestingProfile()); |
36 profile_->CreateBookmarkModel(true); | 39 profile_->CreateBookmarkModel(true); |
37 | 40 |
| 41 views_delegate_ = base::MakeUnique<views::TestViewsDelegate>(); |
| 42 |
38 model_ = BookmarkModelFactory::GetForBrowserContext(profile_.get()); | 43 model_ = BookmarkModelFactory::GetForBrowserContext(profile_.get()); |
39 bookmarks::test::WaitForBookmarkModelToLoad(model_); | 44 bookmarks::test::WaitForBookmarkModelToLoad(model_); |
40 | 45 |
41 AddTestData(); | 46 AddTestData(); |
42 } | 47 } |
43 | 48 |
44 protected: | 49 protected: |
45 std::string base_path() const { return "file:///c:/tmp/"; } | 50 std::string base_path() const { return "file:///c:/tmp/"; } |
46 | 51 |
47 const BookmarkNode* GetNode(const std::string& name) { | 52 const BookmarkNode* GetNode(const std::string& name) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 void ExpandAndSelect() { | 111 void ExpandAndSelect() { |
107 editor_->ExpandAndSelect(); | 112 editor_->ExpandAndSelect(); |
108 } | 113 } |
109 | 114 |
110 views::TreeView* tree_view() { return editor_->tree_view_; } | 115 views::TreeView* tree_view() { return editor_->tree_view_; } |
111 | 116 |
112 content::TestBrowserThreadBundle thread_bundle_; | 117 content::TestBrowserThreadBundle thread_bundle_; |
113 | 118 |
114 BookmarkModel* model_; | 119 BookmarkModel* model_; |
115 std::unique_ptr<TestingProfile> profile_; | 120 std::unique_ptr<TestingProfile> profile_; |
| 121 std::unique_ptr<views::TestViewsDelegate> views_delegate_; |
116 | 122 |
117 private: | 123 private: |
118 // Creates the following structure: | 124 // Creates the following structure: |
119 // bookmark bar node | 125 // bookmark bar node |
120 // a | 126 // a |
121 // F1 | 127 // F1 |
122 // f1a | 128 // f1a |
123 // F11 | 129 // F11 |
124 // f11a | 130 // f11a |
125 // F2 | 131 // F2 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 ASSERT_TRUE(tree_view()->editor() != NULL); | 449 ASSERT_TRUE(tree_view()->editor() != NULL); |
444 tree_view()->editor()->SetText(ASCIIToUTF16("modified")); | 450 tree_view()->editor()->SetText(ASCIIToUTF16("modified")); |
445 ApplyEdits(); | 451 ApplyEdits(); |
446 | 452 |
447 // Verify the new folder was added and title set appropriately. | 453 // Verify the new folder was added and title set appropriately. |
448 ASSERT_EQ(1, parent->child_count()); | 454 ASSERT_EQ(1, parent->child_count()); |
449 const BookmarkNode* new_folder = parent->GetChild(0); | 455 const BookmarkNode* new_folder = parent->GetChild(0); |
450 ASSERT_TRUE(new_folder->is_folder()); | 456 ASSERT_TRUE(new_folder->is_folder()); |
451 EXPECT_EQ("modified", base::UTF16ToASCII(new_folder->GetTitle())); | 457 EXPECT_EQ("modified", base::UTF16ToASCII(new_folder->GetTitle())); |
452 } | 458 } |
OLD | NEW |