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

Side by Side Diff: chrome/browser/views/bookmark_editor_view_unittest.cc

Issue 1912: Renames BoomarkBarModel to BookmarkModel. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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) 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 #include "base/string_util.h" 5 #include "base/string_util.h"
6 #include "chrome/browser/bookmarks/bookmark_bar_model.h" 6 #include "chrome/browser/bookmarks/bookmark_model.h"
7 #include "chrome/browser/profile.h" 7 #include "chrome/browser/profile.h"
8 #include "chrome/browser/views/bookmark_editor_view.h" 8 #include "chrome/browser/views/bookmark_editor_view.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "chrome/common/pref_service.h" 10 #include "chrome/common/pref_service.h"
11 #include "chrome/test/testing_profile.h" 11 #include "chrome/test/testing_profile.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 // Base class for bookmark editor tests. Creates a BookmarkBarModel and 14 // Base class for bookmark editor tests. Creates a BookmarkModel and populates
15 // populates it with test data. 15 // it with test data.
16 class BookmarkEditorViewTest : public testing::Test { 16 class BookmarkEditorViewTest : public testing::Test {
17 public: 17 public:
18 BookmarkEditorViewTest() : model_(NULL) { 18 BookmarkEditorViewTest() : model_(NULL) {
19 } 19 }
20 20
21 virtual void SetUp() { 21 virtual void SetUp() {
22 profile_.reset(new TestingProfile()); 22 profile_.reset(new TestingProfile());
23 profile_->set_has_history_service(true); 23 profile_->set_has_history_service(true);
24 profile_->CreateBookmarkBarModel(true); 24 profile_->CreateBookmarkModel(true);
25 25
26 model_ = profile_->GetBookmarkBarModel(); 26 model_ = profile_->GetBookmarkModel();
27 27
28 AddTestData(); 28 AddTestData();
29 } 29 }
30 30
31 virtual void TearDown() { 31 virtual void TearDown() {
32 } 32 }
33 33
34 protected: 34 protected:
35 MessageLoopForUI message_loop_; 35 MessageLoopForUI message_loop_;
36 BookmarkBarModel* model_; 36 BookmarkModel* model_;
37 scoped_ptr<TestingProfile> profile_; 37 scoped_ptr<TestingProfile> profile_;
38 38
39 std::string base_path() const { return "file:///c:/tmp/"; } 39 std::string base_path() const { return "file:///c:/tmp/"; }
40 40
41 private: 41 private:
42 // Creates the following structure: 42 // Creates the following structure:
43 // bookmark bar node 43 // bookmark bar node
44 // a 44 // a
45 // F1 45 // F1
46 // f1a 46 // f1a
47 // F11 47 // F11
48 // f11a 48 // f11a
49 // F2 49 // F2
50 // other node 50 // other node
51 // oa 51 // oa
52 // OF1 52 // OF1
53 // of1a 53 // of1a
54 void AddTestData() { 54 void AddTestData() {
55 std::string test_base = base_path(); 55 std::string test_base = base_path();
56 56
57 model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a", 57 model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a",
58 GURL(test_base + "a")); 58 GURL(test_base + "a"));
59 BookmarkBarNode* f1 = 59 BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1");
60 model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1");
61 model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); 60 model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a"));
62 BookmarkBarNode* f11 = model_->AddGroup(f1, 1, L"F11"); 61 BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11");
63 model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); 62 model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a"));
64 model_->AddGroup(model_->GetBookmarkBarNode(), 2, L"F2"); 63 model_->AddGroup(model_->GetBookmarkBarNode(), 2, L"F2");
65 64
66 // Children of the other node. 65 // Children of the other node.
67 model_->AddURL(model_->other_node(), 0, L"oa", 66 model_->AddURL(model_->other_node(), 0, L"oa",
68 GURL(test_base + "oa")); 67 GURL(test_base + "oa"));
69 BookmarkBarNode* of1 = 68 BookmarkNode* of1 = model_->AddGroup(model_->other_node(), 1, L"OF1");
70 model_->AddGroup(model_->other_node(), 1, L"OF1");
71 model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a")); 69 model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a"));
72 } 70 }
73 }; 71 };
74 72
75 // Makes sure the tree model matches that of the bookmark bar model. 73 // Makes sure the tree model matches that of the bookmark bar model.
76 TEST_F(BookmarkEditorViewTest, ModelsMatch) { 74 TEST_F(BookmarkEditorViewTest, ModelsMatch) {
77 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "xxx"), 75 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "xxx"),
78 L"xxx"); 76 L"xxx");
79 BookmarkEditorView::BookmarkNode* editor_root = editor.tree_model_->GetRoot(); 77 BookmarkEditorView::EditorNode* editor_root = editor.tree_model_->GetRoot();
80 // The root should have two children, one for the bookmark bar node, 78 // The root should have two children, one for the bookmark bar node,
81 // the other for the 'other bookmarks' folder. 79 // the other for the 'other bookmarks' folder.
82 ASSERT_EQ(2, editor_root->GetChildCount()); 80 ASSERT_EQ(2, editor_root->GetChildCount());
83 81
84 BookmarkEditorView::BookmarkNode* bb_node = editor_root->GetChild(0); 82 BookmarkEditorView::EditorNode* bb_node = editor_root->GetChild(0);
85 // The root should have 2 nodes: folder F1 and F2. 83 // The root should have 2 nodes: folder F1 and F2.
86 ASSERT_EQ(2, bb_node->GetChildCount()); 84 ASSERT_EQ(2, bb_node->GetChildCount());
87 ASSERT_EQ(L"F1", bb_node->GetChild(0)->GetTitle()); 85 ASSERT_EQ(L"F1", bb_node->GetChild(0)->GetTitle());
88 ASSERT_EQ(L"F2", bb_node->GetChild(1)->GetTitle()); 86 ASSERT_EQ(L"F2", bb_node->GetChild(1)->GetTitle());
89 87
90 // F1 should have one child, F11 88 // F1 should have one child, F11
91 ASSERT_EQ(1, bb_node->GetChild(0)->GetChildCount()); 89 ASSERT_EQ(1, bb_node->GetChild(0)->GetChildCount());
92 ASSERT_EQ(L"F11", bb_node->GetChild(0)->GetChild(0)->GetTitle()); 90 ASSERT_EQ(L"F11", bb_node->GetChild(0)->GetChild(0)->GetTitle());
93 91
94 BookmarkEditorView::BookmarkNode* other_node = editor_root->GetChild(1); 92 BookmarkEditorView::EditorNode* other_node = editor_root->GetChild(1);
95 // Other node should have one child (OF1). 93 // Other node should have one child (OF1).
96 ASSERT_EQ(1, other_node->GetChildCount()); 94 ASSERT_EQ(1, other_node->GetChildCount());
97 ASSERT_EQ(L"OF1", other_node->GetChild(0)->GetTitle()); 95 ASSERT_EQ(L"OF1", other_node->GetChild(0)->GetTitle());
98 } 96 }
99 97
100 // Changes the title and makes sure parent/visual order doesn't change. 98 // Changes the title and makes sure parent/visual order doesn't change.
101 TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { 99 TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) {
102 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"new_a"); 100 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"new_a");
103 101
104 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); 102 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0));
105 103
106 BookmarkBarNode* bb_node = 104 BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
107 profile_->GetBookmarkBarModel()->GetBookmarkBarNode();
108 ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle()); 105 ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle());
109 // The URL shouldn't have changed. 106 // The URL shouldn't have changed.
110 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL()); 107 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL());
111 } 108 }
112 109
113 // Changes the url and makes sure parent/visual order doesn't change. 110 // Changes the url and makes sure parent/visual order doesn't change.
114 TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { 111 TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) {
115 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a"); 112 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a");
116 113
117 editor.url_tf_.SetText(UTF8ToWide(GURL(base_path() + "new_a").spec())); 114 editor.url_tf_.SetText(UTF8ToWide(GURL(base_path() + "new_a").spec()));
118 115
119 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); 116 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0));
120 117
121 BookmarkBarNode* bb_node = 118 BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
122 profile_->GetBookmarkBarModel()->GetBookmarkBarNode();
123 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); 119 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle());
124 // The URL should have changed. 120 // The URL should have changed.
125 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL()); 121 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL());
126 } 122 }
127 123
128 // Moves 'a' to be a child of the other node. 124 // Moves 'a' to be a child of the other node.
129 TEST_F(BookmarkEditorViewTest, ChangeParent) { 125 TEST_F(BookmarkEditorViewTest, ChangeParent) {
130 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a"); 126 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a");
131 127
132 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(1)); 128 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(1));
133 129
134 BookmarkBarNode* other_node = profile_->GetBookmarkBarModel()->other_node(); 130 BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
135 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); 131 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle());
136 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL()); 132 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL());
137 } 133 }
138 134
139 // Changes the URL to a URL that is already starred. 135 // Changes the URL to a URL that is already starred.
140 TEST_F(BookmarkEditorViewTest, ChangeURLToExistingURL) { 136 TEST_F(BookmarkEditorViewTest, ChangeURLToExistingURL) {
141 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a"); 137 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a");
142 138
143 editor.url_tf_.SetText(UTF8ToWide(GURL(base_path() + "f1a").spec())); 139 editor.url_tf_.SetText(UTF8ToWide(GURL(base_path() + "f1a").spec()));
144 140
145 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); 141 editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0));
146 142
147 // Position shouldn't have changed. 143 // Position shouldn't have changed.
148 BookmarkBarNode* bb_node = 144 BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
149 profile_->GetBookmarkBarModel()->GetBookmarkBarNode();
150 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); 145 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle());
151 // The URL should have changed. 146 // The URL should have changed.
152 ASSERT_TRUE(GURL(base_path() + "f1a") == bb_node->GetChild(0)->GetURL()); 147 ASSERT_TRUE(GURL(base_path() + "f1a") == bb_node->GetChild(0)->GetURL());
153 148
154 // And F1 should have one last child (f1a was removed from it). 149 // And F1 should have one last child (f1a was removed from it).
155 ASSERT_EQ(1, bb_node->GetChild(1)->GetChildCount()); 150 ASSERT_EQ(1, bb_node->GetChild(1)->GetChildCount());
156 ASSERT_NE(L"f1a", bb_node->GetChild(1)->GetChild(0)->GetTitle()); 151 ASSERT_NE(L"f1a", bb_node->GetChild(1)->GetChild(0)->GetTitle());
157 } 152 }
158 153
159 // Creates a new folder and moves a node to it. 154 // Creates a new folder and moves a node to it.
160 TEST_F(BookmarkEditorViewTest, MoveToNewParent) { 155 TEST_F(BookmarkEditorViewTest, MoveToNewParent) {
161 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a"); 156 BookmarkEditorView editor(profile_.get(), GURL(base_path() + "a"), L"a");
162 157
163 // Create two nodes: "F21" as a child of "F2" and "F211" as a child of "F21". 158 // Create two nodes: "F21" as a child of "F2" and "F211" as a child of "F21".
164 BookmarkEditorView::BookmarkNode* f2 = 159 BookmarkEditorView::EditorNode* f2 =
165 editor.tree_model_->GetRoot()->GetChild(0)->GetChild(1); 160 editor.tree_model_->GetRoot()->GetChild(0)->GetChild(1);
166 BookmarkEditorView::BookmarkNode* f21 = editor.AddNewGroup(f2); 161 BookmarkEditorView::EditorNode* f21 = editor.AddNewGroup(f2);
167 f21->SetTitle(L"F21"); 162 f21->SetTitle(L"F21");
168 BookmarkEditorView::BookmarkNode* f211 = editor.AddNewGroup(f21); 163 BookmarkEditorView::EditorNode* f211 = editor.AddNewGroup(f21);
169 f211->SetTitle(L"F211"); 164 f211->SetTitle(L"F211");
170 165
171 // Parent the node to "F21". 166 // Parent the node to "F21".
172 editor.ApplyEdits(f2); 167 editor.ApplyEdits(f2);
173 168
174 BookmarkBarNode* bb_node = 169 BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode();
175 profile_->GetBookmarkBarModel()->GetBookmarkBarNode(); 170 BookmarkNode* mf2 = bb_node->GetChild(1);
176 BookmarkBarNode* mf2 = bb_node->GetChild(1);
177 171
178 // F2 in the model should have two children now: F21 and the node edited. 172 // F2 in the model should have two children now: F21 and the node edited.
179 ASSERT_EQ(2, mf2->GetChildCount()); 173 ASSERT_EQ(2, mf2->GetChildCount());
180 // F21 should be first. 174 // F21 should be first.
181 ASSERT_EQ(L"F21", mf2->GetChild(0)->GetTitle()); 175 ASSERT_EQ(L"F21", mf2->GetChild(0)->GetTitle());
182 // Then a. 176 // Then a.
183 ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle()); 177 ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle());
184 178
185 // F21 should have one child, F211. 179 // F21 should have one child, F211.
186 BookmarkBarNode* mf21 = mf2->GetChild(0); 180 BookmarkNode* mf21 = mf2->GetChild(0);
187 ASSERT_EQ(1, mf21->GetChildCount()); 181 ASSERT_EQ(1, mf21->GetChildCount());
188 ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle()); 182 ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle());
189 } 183 }
190 184
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698