| OLD | NEW |
| 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_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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 BookmarkNode* GetMutableNode(const std::string& name) { | 48 BookmarkNode* GetMutableNode(const std::string& name) { |
| 49 return const_cast<BookmarkNode*>(GetNode(name)); | 49 return const_cast<BookmarkNode*>(GetNode(name)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 BookmarkEditorView::EditorTreeModel* editor_tree_model() { | 52 BookmarkEditorView::EditorTreeModel* editor_tree_model() { |
| 53 return editor_->tree_model_.get(); | 53 return editor_->tree_model_.get(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void CreateEditor(Profile* profile, | 56 void CreateEditor(Profile* profile, |
| 57 const BookmarkNode* parent, | 57 const BookmarkNode* parent, |
| 58 const BookmarkNode* node, | 58 const BookmarkEditor::EditDetails& details, |
| 59 BookmarkEditor::Configuration configuration, | 59 BookmarkEditor::Configuration configuration, |
| 60 BookmarkEditor::Handler* handler) { | 60 BookmarkEditor::Handler* handler) { |
| 61 editor_.reset(new BookmarkEditorView(profile, parent, node, configuration, | 61 editor_.reset(new BookmarkEditorView(profile, parent, details, |
| 62 handler)); | 62 configuration, handler)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void SetTitleText(const std::wstring& title) { | 65 void SetTitleText(const std::wstring& title) { |
| 66 editor_->title_tf_.SetText(title); | 66 editor_->title_tf_.SetText(title); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void SetURLText(const std::wstring& text) { | 69 void SetURLText(const std::wstring& text) { |
| 70 editor_->url_tf_.SetText(text); | 70 editor_->url_tf_.SetText(text); |
| 71 } | 71 } |
| 72 | 72 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 const BookmarkNode* of1 = | 114 const BookmarkNode* of1 = |
| 115 model_->AddGroup(model_->other_node(), 1, L"OF1"); | 115 model_->AddGroup(model_->other_node(), 1, L"OF1"); |
| 116 model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a")); | 116 model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a")); |
| 117 } | 117 } |
| 118 | 118 |
| 119 scoped_ptr<BookmarkEditorView> editor_; | 119 scoped_ptr<BookmarkEditorView> editor_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 // Makes sure the tree model matches that of the bookmark bar model. | 122 // Makes sure the tree model matches that of the bookmark bar model. |
| 123 TEST_F(BookmarkEditorViewTest, ModelsMatch) { | 123 TEST_F(BookmarkEditorViewTest, ModelsMatch) { |
| 124 CreateEditor(profile_.get(), NULL, NULL, BookmarkEditorView::SHOW_TREE, | 124 CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(), |
| 125 NULL); | 125 BookmarkEditorView::SHOW_TREE, NULL); |
| 126 BookmarkEditorView::EditorNode* editor_root = editor_tree_model()->GetRoot(); | 126 BookmarkEditorView::EditorNode* editor_root = editor_tree_model()->GetRoot(); |
| 127 // The root should have two children, one for the bookmark bar node, | 127 // The root should have two children, one for the bookmark bar node, |
| 128 // the other for the 'other bookmarks' folder. | 128 // the other for the 'other bookmarks' folder. |
| 129 ASSERT_EQ(2, editor_root->GetChildCount()); | 129 ASSERT_EQ(2, editor_root->GetChildCount()); |
| 130 | 130 |
| 131 BookmarkEditorView::EditorNode* bb_node = editor_root->GetChild(0); | 131 BookmarkEditorView::EditorNode* bb_node = editor_root->GetChild(0); |
| 132 // The root should have 2 nodes: folder F1 and F2. | 132 // The root should have 2 nodes: folder F1 and F2. |
| 133 ASSERT_EQ(2, bb_node->GetChildCount()); | 133 ASSERT_EQ(2, bb_node->GetChildCount()); |
| 134 ASSERT_EQ(L"F1", bb_node->GetChild(0)->GetTitle()); | 134 ASSERT_EQ(L"F1", bb_node->GetChild(0)->GetTitle()); |
| 135 ASSERT_EQ(L"F2", bb_node->GetChild(1)->GetTitle()); | 135 ASSERT_EQ(L"F2", bb_node->GetChild(1)->GetTitle()); |
| 136 | 136 |
| 137 // F1 should have one child, F11 | 137 // F1 should have one child, F11 |
| 138 ASSERT_EQ(1, bb_node->GetChild(0)->GetChildCount()); | 138 ASSERT_EQ(1, bb_node->GetChild(0)->GetChildCount()); |
| 139 ASSERT_EQ(L"F11", bb_node->GetChild(0)->GetChild(0)->GetTitle()); | 139 ASSERT_EQ(L"F11", bb_node->GetChild(0)->GetChild(0)->GetTitle()); |
| 140 | 140 |
| 141 BookmarkEditorView::EditorNode* other_node = editor_root->GetChild(1); | 141 BookmarkEditorView::EditorNode* other_node = editor_root->GetChild(1); |
| 142 // Other node should have one child (OF1). | 142 // Other node should have one child (OF1). |
| 143 ASSERT_EQ(1, other_node->GetChildCount()); | 143 ASSERT_EQ(1, other_node->GetChildCount()); |
| 144 ASSERT_EQ(L"OF1", other_node->GetChild(0)->GetTitle()); | 144 ASSERT_EQ(L"OF1", other_node->GetChild(0)->GetTitle()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Changes the title and makes sure parent/visual order doesn't change. | 147 // Changes the title and makes sure parent/visual order doesn't change. |
| 148 TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { | 148 TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { |
| 149 CreateEditor(profile_.get(), NULL, GetNode("a"), | 149 CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), |
| 150 BookmarkEditorView::SHOW_TREE, NULL); | 150 BookmarkEditorView::SHOW_TREE, NULL); |
| 151 SetTitleText(L"new_a"); | 151 SetTitleText(L"new_a"); |
| 152 | 152 |
| 153 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); | 153 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); |
| 154 | 154 |
| 155 const BookmarkNode* bb_node = | 155 const BookmarkNode* bb_node = |
| 156 profile_->GetBookmarkModel()->GetBookmarkBarNode(); | 156 profile_->GetBookmarkModel()->GetBookmarkBarNode(); |
| 157 ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle()); | 157 ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle()); |
| 158 // The URL shouldn't have changed. | 158 // The URL shouldn't have changed. |
| 159 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL()); | 159 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL()); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Changes the url and makes sure parent/visual order doesn't change. | 162 // Changes the url and makes sure parent/visual order doesn't change. |
| 163 TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { | 163 TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { |
| 164 Time node_time = Time::Now() + TimeDelta::FromDays(2); | 164 Time node_time = Time::Now() + TimeDelta::FromDays(2); |
| 165 GetMutableNode("a")->set_date_added(node_time); | 165 GetMutableNode("a")->set_date_added(node_time); |
| 166 CreateEditor(profile_.get(), NULL, GetNode("a"), | 166 CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), |
| 167 BookmarkEditorView::SHOW_TREE, NULL); | 167 BookmarkEditorView::SHOW_TREE, NULL); |
| 168 | 168 |
| 169 SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec())); | 169 SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec())); |
| 170 | 170 |
| 171 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); | 171 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); |
| 172 | 172 |
| 173 const BookmarkNode* bb_node = | 173 const BookmarkNode* bb_node = |
| 174 profile_->GetBookmarkModel()->GetBookmarkBarNode(); | 174 profile_->GetBookmarkModel()->GetBookmarkBarNode(); |
| 175 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); | 175 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); |
| 176 // The URL should have changed. | 176 // The URL should have changed. |
| 177 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL()); | 177 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL()); |
| 178 ASSERT_TRUE(node_time == bb_node->GetChild(0)->date_added()); | 178 ASSERT_TRUE(node_time == bb_node->GetChild(0)->date_added()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Moves 'a' to be a child of the other node. | 181 // Moves 'a' to be a child of the other node. |
| 182 TEST_F(BookmarkEditorViewTest, ChangeParent) { | 182 TEST_F(BookmarkEditorViewTest, ChangeParent) { |
| 183 CreateEditor(profile_.get(), NULL, GetNode("a"), | 183 CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), |
| 184 BookmarkEditorView::SHOW_TREE, NULL); | 184 BookmarkEditorView::SHOW_TREE, NULL); |
| 185 | 185 |
| 186 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); | 186 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); |
| 187 | 187 |
| 188 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 188 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 189 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); | 189 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); |
| 190 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL()); | 190 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Moves 'a' to be a child of the other node and changes its url to new_a. | 193 // Moves 'a' to be a child of the other node and changes its url to new_a. |
| 194 TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) { | 194 TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) { |
| 195 Time node_time = Time::Now() + TimeDelta::FromDays(2); | 195 Time node_time = Time::Now() + TimeDelta::FromDays(2); |
| 196 GetMutableNode("a")->set_date_added(node_time); | 196 GetMutableNode("a")->set_date_added(node_time); |
| 197 CreateEditor(profile_.get(), NULL, GetNode("a"), | 197 CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), |
| 198 BookmarkEditorView::SHOW_TREE, NULL); | 198 BookmarkEditorView::SHOW_TREE, NULL); |
| 199 | 199 |
| 200 SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec())); | 200 SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec())); |
| 201 | 201 |
| 202 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); | 202 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); |
| 203 | 203 |
| 204 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 204 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 205 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); | 205 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); |
| 206 ASSERT_TRUE(GURL(base_path() + "new_a") == other_node->GetChild(2)->GetURL()); | 206 ASSERT_TRUE(GURL(base_path() + "new_a") == other_node->GetChild(2)->GetURL()); |
| 207 ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added()); | 207 ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Creates a new folder and moves a node to it. | 210 // Creates a new folder and moves a node to it. |
| 211 TEST_F(BookmarkEditorViewTest, MoveToNewParent) { | 211 TEST_F(BookmarkEditorViewTest, MoveToNewParent) { |
| 212 CreateEditor(profile_.get(), NULL, GetNode("a"), | 212 CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")), |
| 213 BookmarkEditorView::SHOW_TREE, NULL); | 213 BookmarkEditorView::SHOW_TREE, NULL); |
| 214 | 214 |
| 215 // Create two nodes: "F21" as a child of "F2" and "F211" as a child of "F21". | 215 // Create two nodes: "F21" as a child of "F2" and "F211" as a child of "F21". |
| 216 BookmarkEditorView::EditorNode* f2 = | 216 BookmarkEditorView::EditorNode* f2 = |
| 217 editor_tree_model()->GetRoot()->GetChild(0)->GetChild(1); | 217 editor_tree_model()->GetRoot()->GetChild(0)->GetChild(1); |
| 218 BookmarkEditorView::EditorNode* f21 = AddNewGroup(f2); | 218 BookmarkEditorView::EditorNode* f21 = AddNewGroup(f2); |
| 219 f21->SetTitle(L"F21"); | 219 f21->SetTitle(L"F21"); |
| 220 BookmarkEditorView::EditorNode* f211 = AddNewGroup(f21); | 220 BookmarkEditorView::EditorNode* f211 = AddNewGroup(f21); |
| 221 f211->SetTitle(L"F211"); | 221 f211->SetTitle(L"F211"); |
| 222 | 222 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 235 ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle()); | 235 ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle()); |
| 236 | 236 |
| 237 // F21 should have one child, F211. | 237 // F21 should have one child, F211. |
| 238 const BookmarkNode* mf21 = mf2->GetChild(0); | 238 const BookmarkNode* mf21 = mf2->GetChild(0); |
| 239 ASSERT_EQ(1, mf21->GetChildCount()); | 239 ASSERT_EQ(1, mf21->GetChildCount()); |
| 240 ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle()); | 240 ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle()); |
| 241 } | 241 } |
| 242 | 242 |
| 243 // Brings up the editor, creating a new URL on the bookmark bar. | 243 // Brings up the editor, creating a new URL on the bookmark bar. |
| 244 TEST_F(BookmarkEditorViewTest, NewURL) { | 244 TEST_F(BookmarkEditorViewTest, NewURL) { |
| 245 CreateEditor(profile_.get(), NULL, NULL, BookmarkEditorView::SHOW_TREE, | 245 CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(), |
| 246 NULL); | 246 BookmarkEditorView::SHOW_TREE, NULL); |
| 247 | 247 |
| 248 SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); | 248 SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); |
| 249 SetTitleText(L"new_a"); | 249 SetTitleText(L"new_a"); |
| 250 | 250 |
| 251 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); | 251 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); |
| 252 | 252 |
| 253 const BookmarkNode* bb_node = | 253 const BookmarkNode* bb_node = |
| 254 profile_->GetBookmarkModel()->GetBookmarkBarNode(); | 254 profile_->GetBookmarkModel()->GetBookmarkBarNode(); |
| 255 ASSERT_EQ(4, bb_node->GetChildCount()); | 255 ASSERT_EQ(4, bb_node->GetChildCount()); |
| 256 | 256 |
| 257 const BookmarkNode* new_node = bb_node->GetChild(3); | 257 const BookmarkNode* new_node = bb_node->GetChild(3); |
| 258 | 258 |
| 259 EXPECT_EQ(L"new_a", new_node->GetTitle()); | 259 EXPECT_EQ(L"new_a", new_node->GetTitle()); |
| 260 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); | 260 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 // Brings up the editor with no tree and modifies the url. | 263 // Brings up the editor with no tree and modifies the url. |
| 264 TEST_F(BookmarkEditorViewTest, ChangeURLNoTree) { | 264 TEST_F(BookmarkEditorViewTest, ChangeURLNoTree) { |
| 265 CreateEditor(profile_.get(), NULL, model_->other_node()->GetChild(0), | 265 CreateEditor(profile_.get(), NULL, |
| 266 BookmarkEditor::EditDetails(model_->other_node()->GetChild(0)), |
| 266 BookmarkEditorView::NO_TREE, NULL); | 267 BookmarkEditorView::NO_TREE, NULL); |
| 267 | 268 |
| 268 SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); | 269 SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); |
| 269 SetTitleText(L"new_a"); | 270 SetTitleText(L"new_a"); |
| 270 | 271 |
| 271 ApplyEdits(NULL); | 272 ApplyEdits(NULL); |
| 272 | 273 |
| 273 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 274 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 274 ASSERT_EQ(2, other_node->GetChildCount()); | 275 ASSERT_EQ(2, other_node->GetChildCount()); |
| 275 | 276 |
| 276 const BookmarkNode* new_node = other_node->GetChild(0); | 277 const BookmarkNode* new_node = other_node->GetChild(0); |
| 277 | 278 |
| 278 EXPECT_EQ(L"new_a", new_node->GetTitle()); | 279 EXPECT_EQ(L"new_a", new_node->GetTitle()); |
| 279 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); | 280 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); |
| 280 } | 281 } |
| 281 | 282 |
| 282 // Brings up the editor with no tree and modifies only the title. | 283 // Brings up the editor with no tree and modifies only the title. |
| 283 TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) { | 284 TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) { |
| 284 CreateEditor(profile_.get(), NULL, model_->other_node()->GetChild(0), | 285 CreateEditor(profile_.get(), NULL, |
| 286 BookmarkEditor::EditDetails(model_->other_node()->GetChild(0)), |
| 285 BookmarkEditorView::NO_TREE, NULL); | 287 BookmarkEditorView::NO_TREE, NULL); |
| 286 | 288 |
| 287 SetTitleText(L"new_a"); | 289 SetTitleText(L"new_a"); |
| 288 | 290 |
| 289 ApplyEdits(NULL); | 291 ApplyEdits(NULL); |
| 290 | 292 |
| 291 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 293 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 292 ASSERT_EQ(2, other_node->GetChildCount()); | 294 ASSERT_EQ(2, other_node->GetChildCount()); |
| 293 | 295 |
| 294 const BookmarkNode* new_node = other_node->GetChild(0); | 296 const BookmarkNode* new_node = other_node->GetChild(0); |
| 295 | 297 |
| 296 EXPECT_EQ(L"new_a", new_node->GetTitle()); | 298 EXPECT_EQ(L"new_a", new_node->GetTitle()); |
| 297 } | 299 } |
| 298 | 300 |
| 299 // Modifies the title of a folder. | 301 // Creates a new folder. |
| 300 TEST_F(BookmarkEditorViewTest, ModifyFolderTitle) { | 302 TEST_F(BookmarkEditorViewTest, NewFolder) { |
| 301 int64 start_id = model_->GetBookmarkBarNode()->GetChild(2)->id(); | 303 BookmarkEditor::EditDetails details; |
| 302 CreateEditor(profile_.get(), NULL, model_->GetBookmarkBarNode()->GetChild(2), | 304 details.urls.push_back(std::make_pair(GURL(base_path() + "x"), L"z")); |
| 303 BookmarkEditorView::SHOW_TREE, NULL); | 305 details.type = BookmarkEditor::EditDetails::NEW_FOLDER; |
| 306 CreateEditor(profile_.get(), model_->GetBookmarkBarNode(), |
| 307 details, BookmarkEditorView::SHOW_TREE, NULL); |
| 304 | 308 |
| 305 // The url field shouldn't be visible. | 309 // The url field shouldn't be visible. |
| 306 EXPECT_FALSE(URLTFHasParent()); | 310 EXPECT_FALSE(URLTFHasParent()); |
| 307 SetTitleText(L"new_F"); | 311 SetTitleText(L"new_F"); |
| 308 | 312 |
| 309 // Make sure the tree isn't showing the folder we're editing. | |
| 310 EXPECT_EQ(1, editor_tree_model()->GetRoot()->GetChild(0)->GetChildCount()); | |
| 311 | |
| 312 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); | 313 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); |
| 313 | 314 |
| 314 // Make sure the folder we edited is still there. | 315 // Make sure the folder was created. |
| 315 ASSERT_EQ(3, model_->GetBookmarkBarNode()->GetChildCount()); | 316 ASSERT_EQ(4, model_->GetBookmarkBarNode()->GetChildCount()); |
| 316 EXPECT_EQ(start_id, model_->GetBookmarkBarNode()->GetChild(2)->id()); | 317 const BookmarkNode* new_node = |
| 317 EXPECT_TRUE(model_->GetBookmarkBarNode()->GetChild(2)->is_folder()); | 318 model_->GetBookmarkBarNode()->GetChild(3); |
| 318 EXPECT_EQ(L"new_F", model_->GetBookmarkBarNode()->GetChild(2)->GetTitle()); | 319 EXPECT_EQ(BookmarkNode::FOLDER, new_node->GetType()); |
| 320 EXPECT_EQ(L"new_F", new_node->GetTitle()); |
| 321 // The node should have one child. |
| 322 ASSERT_EQ(1, new_node->GetChildCount()); |
| 323 const BookmarkNode* new_child = new_node->GetChild(0); |
| 324 // Make sure the child url/title match. |
| 325 EXPECT_EQ(BookmarkNode::URL, new_child->GetType()); |
| 326 EXPECT_EQ(details.urls[0].second, new_child->GetTitle()); |
| 327 EXPECT_TRUE(details.urls[0].first == new_child->GetURL()); |
| 319 } | 328 } |
| 320 | 329 |
| 321 // Moves a folder. | 330 // Creates a new folder and selects a different folder for the folder to appear |
| 331 // in then the editor is initially created showing. |
| 322 TEST_F(BookmarkEditorViewTest, MoveFolder) { | 332 TEST_F(BookmarkEditorViewTest, MoveFolder) { |
| 323 const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(2); | 333 BookmarkEditor::EditDetails details; |
| 324 int64 start_id = node->id(); | 334 details.urls.push_back(std::make_pair(GURL(base_path() + "x"), L"z")); |
| 325 CreateEditor(profile_.get(), NULL, node, BookmarkEditorView::SHOW_TREE, NULL); | 335 details.type = BookmarkEditor::EditDetails::NEW_FOLDER; |
| 336 CreateEditor(profile_.get(), model_->GetBookmarkBarNode(), |
| 337 details, BookmarkEditorView::SHOW_TREE, NULL); |
| 326 | 338 |
| 327 SetTitleText(L"new_F"); | 339 SetTitleText(L"new_F"); |
| 328 | 340 |
| 329 // Moves to the 'other' folder. | 341 // Create the folder in the 'other' folder. |
| 330 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); | 342 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); |
| 331 | 343 |
| 332 // Make sure the folder we edited is still there. | 344 // Make sure the folder we edited is still there. |
| 333 ASSERT_EQ(3, model_->other_node()->GetChildCount()); | 345 ASSERT_EQ(3, model_->other_node()->GetChildCount()); |
| 334 EXPECT_EQ(node, model_->other_node()->GetChild(2)); | 346 const BookmarkNode* new_node = model_->other_node()->GetChild(2); |
| 335 EXPECT_TRUE(node->is_folder()); | 347 EXPECT_EQ(BookmarkNode::FOLDER, new_node->GetType()); |
| 336 EXPECT_EQ(L"new_F", node->GetTitle()); | 348 EXPECT_EQ(L"new_F", new_node->GetTitle()); |
| 349 // The node should have one child. |
| 350 ASSERT_EQ(1, new_node->GetChildCount()); |
| 351 const BookmarkNode* new_child = new_node->GetChild(0); |
| 352 // Make sure the child url/title match. |
| 353 EXPECT_EQ(BookmarkNode::URL, new_child->GetType()); |
| 354 EXPECT_EQ(details.urls[0].second, new_child->GetTitle()); |
| 355 EXPECT_TRUE(details.urls[0].first == new_child->GetURL()); |
| 337 } | 356 } |
| 338 | |
| 339 // Moves a folder under a new folder. | |
| 340 TEST_F(BookmarkEditorViewTest, MoveFolderNewParent) { | |
| 341 const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(2); | |
| 342 CreateEditor(profile_.get(), NULL, node, BookmarkEditorView::SHOW_TREE, NULL); | |
| 343 | |
| 344 BookmarkEditorView::EditorNode* other = | |
| 345 editor_tree_model()->GetRoot()->GetChild(1); | |
| 346 BookmarkEditorView::EditorNode* new_f = AddNewGroup(other); | |
| 347 new_f->SetTitle(L"new_f"); | |
| 348 | |
| 349 ApplyEdits(new_f); | |
| 350 | |
| 351 // Make sure the folder we edited is still there. | |
| 352 ASSERT_EQ(3, model_->other_node()->GetChildCount()); | |
| 353 const BookmarkNode* new_folder = model_->other_node()->GetChild(2); | |
| 354 EXPECT_EQ(L"new_f", new_folder->GetTitle()); | |
| 355 ASSERT_EQ(1, new_folder->GetChildCount()); | |
| 356 ASSERT_EQ(node, new_folder->GetChild(0)); | |
| 357 } | |
| OLD | NEW |