| 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 <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/gtk/bookmark_editor_gtk.h" | 10 #include "chrome/browser/gtk/bookmark_editor_gtk.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 model_->AddURL(model_->other_node(), 0, L"oa", | 81 model_->AddURL(model_->other_node(), 0, L"oa", |
| 82 GURL(test_base + "oa")); | 82 GURL(test_base + "oa")); |
| 83 const BookmarkNode* of1 = | 83 const BookmarkNode* of1 = |
| 84 model_->AddGroup(model_->other_node(), 1, L"OF1"); | 84 model_->AddGroup(model_->other_node(), 1, L"OF1"); |
| 85 model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a")); | 85 model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a")); |
| 86 } | 86 } |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // Makes sure the tree model matches that of the bookmark bar model. | 89 // Makes sure the tree model matches that of the bookmark bar model. |
| 90 TEST_F(BookmarkEditorGtkTest, ModelsMatch) { | 90 TEST_F(BookmarkEditorGtkTest, ModelsMatch) { |
| 91 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, NULL, | 91 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 92 BookmarkEditor::EditDetails(), |
| 92 BookmarkEditor::SHOW_TREE, NULL); | 93 BookmarkEditor::SHOW_TREE, NULL); |
| 93 | 94 |
| 94 // The root should have two children, one for the bookmark bar node, | 95 // The root should have two children, one for the bookmark bar node, |
| 95 // the other for the 'other bookmarks' folder. | 96 // the other for the 'other bookmarks' folder. |
| 96 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 97 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 97 GtkTreeIter toplevel; | 98 GtkTreeIter toplevel; |
| 98 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel)); | 99 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel)); |
| 99 GtkTreeIter bookmark_bar_node = toplevel; | 100 GtkTreeIter bookmark_bar_node = toplevel; |
| 100 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); | 101 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); |
| 101 GtkTreeIter other_node = toplevel; | 102 GtkTreeIter other_node = toplevel; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 | 121 |
| 121 // Other node should have one child (OF1). | 122 // Other node should have one child (OF1). |
| 122 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &other_node)); | 123 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &other_node)); |
| 123 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &other_node)); | 124 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &other_node)); |
| 124 ASSERT_EQ(L"OF1", GetTitleFromTreeIter(store, &child)); | 125 ASSERT_EQ(L"OF1", GetTitleFromTreeIter(store, &child)); |
| 125 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); | 126 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); |
| 126 } | 127 } |
| 127 | 128 |
| 128 // Changes the title and makes sure parent/visual order doesn't change. | 129 // Changes the title and makes sure parent/visual order doesn't change. |
| 129 TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { | 130 TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { |
| 130 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"), | 131 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 132 BookmarkEditor::EditDetails(GetNode("a")), |
| 131 BookmarkEditor::SHOW_TREE, NULL); | 133 BookmarkEditor::SHOW_TREE, NULL); |
| 132 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); | 134 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); |
| 133 | 135 |
| 134 GtkTreeIter bookmark_bar_node; | 136 GtkTreeIter bookmark_bar_node; |
| 135 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 137 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 136 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); | 138 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); |
| 137 editor.ApplyEdits(&bookmark_bar_node); | 139 editor.ApplyEdits(&bookmark_bar_node); |
| 138 | 140 |
| 139 const BookmarkNode* bb_node = | 141 const BookmarkNode* bb_node = |
| 140 profile_->GetBookmarkModel()->GetBookmarkBarNode(); | 142 profile_->GetBookmarkModel()->GetBookmarkBarNode(); |
| 141 ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle()); | 143 ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle()); |
| 142 // The URL shouldn't have changed. | 144 // The URL shouldn't have changed. |
| 143 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL()); | 145 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL()); |
| 144 } | 146 } |
| 145 | 147 |
| 146 // Changes the url and makes sure parent/visual order doesn't change. | 148 // Changes the url and makes sure parent/visual order doesn't change. |
| 147 TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) { | 149 TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) { |
| 148 Time node_time = GetNode("a")->date_added(); | 150 Time node_time = GetNode("a")->date_added(); |
| 149 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"), | 151 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 152 BookmarkEditor::EditDetails(GetNode("a")), |
| 150 BookmarkEditor::SHOW_TREE, NULL); | 153 BookmarkEditor::SHOW_TREE, NULL); |
| 151 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), | 154 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), |
| 152 GURL(base_path() + "new_a").spec().c_str()); | 155 GURL(base_path() + "new_a").spec().c_str()); |
| 153 | 156 |
| 154 GtkTreeIter bookmark_bar_node; | 157 GtkTreeIter bookmark_bar_node; |
| 155 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 158 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 156 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); | 159 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); |
| 157 editor.ApplyEdits(&bookmark_bar_node); | 160 editor.ApplyEdits(&bookmark_bar_node); |
| 158 | 161 |
| 159 const BookmarkNode* bb_node = | 162 const BookmarkNode* bb_node = |
| 160 profile_->GetBookmarkModel()->GetBookmarkBarNode(); | 163 profile_->GetBookmarkModel()->GetBookmarkBarNode(); |
| 161 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); | 164 ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); |
| 162 // The URL should have changed. | 165 // The URL should have changed. |
| 163 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL()); | 166 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL()); |
| 164 ASSERT_TRUE(node_time == bb_node->GetChild(0)->date_added()); | 167 ASSERT_TRUE(node_time == bb_node->GetChild(0)->date_added()); |
| 165 } | 168 } |
| 166 | 169 |
| 167 // Moves 'a' to be a child of the other node. | 170 // Moves 'a' to be a child of the other node. |
| 168 TEST_F(BookmarkEditorGtkTest, ChangeParent) { | 171 TEST_F(BookmarkEditorGtkTest, ChangeParent) { |
| 169 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"), | 172 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 173 BookmarkEditor::EditDetails(GetNode("a")), |
| 170 BookmarkEditor::SHOW_TREE, NULL); | 174 BookmarkEditor::SHOW_TREE, NULL); |
| 171 | 175 |
| 172 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 176 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 173 GtkTreeIter gtk_other_node; | 177 GtkTreeIter gtk_other_node; |
| 174 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, >k_other_node)); | 178 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, >k_other_node)); |
| 175 ASSERT_TRUE(gtk_tree_model_iter_next(store, >k_other_node)); | 179 ASSERT_TRUE(gtk_tree_model_iter_next(store, >k_other_node)); |
| 176 editor.ApplyEdits(>k_other_node); | 180 editor.ApplyEdits(>k_other_node); |
| 177 | 181 |
| 178 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 182 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 179 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); | 183 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); |
| 180 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL()); | 184 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL()); |
| 181 } | 185 } |
| 182 | 186 |
| 183 // Moves 'a' to be a child of the other node. | 187 // Moves 'a' to be a child of the other node. |
| 184 // Moves 'a' to be a child of the other node and changes its url to new_a. | 188 // Moves 'a' to be a child of the other node and changes its url to new_a. |
| 185 TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) { | 189 TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) { |
| 186 Time node_time = GetNode("a")->date_added(); | 190 Time node_time = GetNode("a")->date_added(); |
| 187 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"), | 191 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 192 BookmarkEditor::EditDetails(GetNode("a")), |
| 188 BookmarkEditor::SHOW_TREE, NULL); | 193 BookmarkEditor::SHOW_TREE, NULL); |
| 189 | 194 |
| 190 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), | 195 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), |
| 191 GURL(base_path() + "new_a").spec().c_str()); | 196 GURL(base_path() + "new_a").spec().c_str()); |
| 192 | 197 |
| 193 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 198 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 194 GtkTreeIter gtk_other_node; | 199 GtkTreeIter gtk_other_node; |
| 195 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, >k_other_node)); | 200 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, >k_other_node)); |
| 196 ASSERT_TRUE(gtk_tree_model_iter_next(store, >k_other_node)); | 201 ASSERT_TRUE(gtk_tree_model_iter_next(store, >k_other_node)); |
| 197 editor.ApplyEdits(>k_other_node); | 202 editor.ApplyEdits(>k_other_node); |
| 198 | 203 |
| 199 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 204 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 200 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); | 205 ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); |
| 201 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()); |
| 202 ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added()); | 207 ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added()); |
| 203 } | 208 } |
| 204 | 209 |
| 205 // Creates a new folder and moves a node to it. | 210 // Creates a new folder and moves a node to it. |
| 206 TEST_F(BookmarkEditorGtkTest, MoveToNewParent) { | 211 TEST_F(BookmarkEditorGtkTest, MoveToNewParent) { |
| 207 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"), | 212 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 213 BookmarkEditor::EditDetails(GetNode("a")), |
| 208 BookmarkEditor::SHOW_TREE, NULL); | 214 BookmarkEditor::SHOW_TREE, NULL); |
| 209 | 215 |
| 210 GtkTreeIter bookmark_bar_node; | 216 GtkTreeIter bookmark_bar_node; |
| 211 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 217 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 212 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); | 218 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); |
| 213 | 219 |
| 214 // The bookmark bar should have 2 nodes: folder F1 and F2. | 220 // The bookmark bar should have 2 nodes: folder F1 and F2. |
| 215 GtkTreeIter f2_iter; | 221 GtkTreeIter f2_iter; |
| 216 ASSERT_EQ(2, gtk_tree_model_iter_n_children(store, &bookmark_bar_node)); | 222 ASSERT_EQ(2, gtk_tree_model_iter_n_children(store, &bookmark_bar_node)); |
| 217 ASSERT_TRUE(gtk_tree_model_iter_children(store, &f2_iter, | 223 ASSERT_TRUE(gtk_tree_model_iter_children(store, &f2_iter, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 244 ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle()); | 250 ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle()); |
| 245 | 251 |
| 246 // F21 should have one child, F211. | 252 // F21 should have one child, F211. |
| 247 const BookmarkNode* mf21 = mf2->GetChild(0); | 253 const BookmarkNode* mf21 = mf2->GetChild(0); |
| 248 ASSERT_EQ(1, mf21->GetChildCount()); | 254 ASSERT_EQ(1, mf21->GetChildCount()); |
| 249 ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle()); | 255 ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle()); |
| 250 } | 256 } |
| 251 | 257 |
| 252 // Brings up the editor, creating a new URL on the bookmark bar. | 258 // Brings up the editor, creating a new URL on the bookmark bar. |
| 253 TEST_F(BookmarkEditorGtkTest, NewURL) { | 259 TEST_F(BookmarkEditorGtkTest, NewURL) { |
| 254 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, NULL, | 260 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 261 BookmarkEditor::EditDetails(), |
| 255 BookmarkEditor::SHOW_TREE, NULL); | 262 BookmarkEditor::SHOW_TREE, NULL); |
| 256 | 263 |
| 257 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), | 264 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), |
| 258 GURL(base_path() + "a").spec().c_str()); | 265 GURL(base_path() + "a").spec().c_str()); |
| 259 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); | 266 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); |
| 260 | 267 |
| 261 GtkTreeIter bookmark_bar_node; | 268 GtkTreeIter bookmark_bar_node; |
| 262 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 269 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 263 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); | 270 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); |
| 264 editor.ApplyEdits(&bookmark_bar_node); | 271 editor.ApplyEdits(&bookmark_bar_node); |
| 265 | 272 |
| 266 const BookmarkNode* bb_node = | 273 const BookmarkNode* bb_node = |
| 267 profile_->GetBookmarkModel()->GetBookmarkBarNode(); | 274 profile_->GetBookmarkModel()->GetBookmarkBarNode(); |
| 268 ASSERT_EQ(4, bb_node->GetChildCount()); | 275 ASSERT_EQ(4, bb_node->GetChildCount()); |
| 269 | 276 |
| 270 const BookmarkNode* new_node = bb_node->GetChild(3); | 277 const BookmarkNode* new_node = bb_node->GetChild(3); |
| 271 EXPECT_EQ(L"new_a", new_node->GetTitle()); | 278 EXPECT_EQ(L"new_a", new_node->GetTitle()); |
| 272 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); | 279 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); |
| 273 } | 280 } |
| 274 | 281 |
| 275 // Brings up the editor with no tree and modifies the url. | 282 // Brings up the editor with no tree and modifies the url. |
| 276 TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) { | 283 TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) { |
| 277 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, | 284 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 278 model_->other_node()->GetChild(0), | 285 BookmarkEditor::EditDetails( |
| 286 model_->other_node()->GetChild(0)), |
| 279 BookmarkEditor::NO_TREE, NULL); | 287 BookmarkEditor::NO_TREE, NULL); |
| 280 | 288 |
| 281 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), | 289 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), |
| 282 GURL(base_path() + "a").spec().c_str()); | 290 GURL(base_path() + "a").spec().c_str()); |
| 283 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); | 291 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); |
| 284 | 292 |
| 285 editor.ApplyEdits(NULL); | 293 editor.ApplyEdits(NULL); |
| 286 | 294 |
| 287 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 295 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 288 ASSERT_EQ(2, other_node->GetChildCount()); | 296 ASSERT_EQ(2, other_node->GetChildCount()); |
| 289 | 297 |
| 290 const BookmarkNode* new_node = other_node->GetChild(0); | 298 const BookmarkNode* new_node = other_node->GetChild(0); |
| 291 | 299 |
| 292 EXPECT_EQ(L"new_a", new_node->GetTitle()); | 300 EXPECT_EQ(L"new_a", new_node->GetTitle()); |
| 293 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); | 301 EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); |
| 294 } | 302 } |
| 295 | 303 |
| 296 // Brings up the editor with no tree and modifies only the title. | 304 // Brings up the editor with no tree and modifies only the title. |
| 297 TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) { | 305 TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) { |
| 298 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, | 306 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
| 299 model_->other_node()->GetChild(0), | 307 BookmarkEditor::EditDetails( |
| 308 model_->other_node()->GetChild(0)), |
| 300 BookmarkEditor::NO_TREE, NULL); | 309 BookmarkEditor::NO_TREE, NULL); |
| 301 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); | 310 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); |
| 302 | 311 |
| 303 editor.ApplyEdits(); | 312 editor.ApplyEdits(); |
| 304 | 313 |
| 305 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 314 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
| 306 ASSERT_EQ(2, other_node->GetChildCount()); | 315 ASSERT_EQ(2, other_node->GetChildCount()); |
| 307 | 316 |
| 308 const BookmarkNode* new_node = other_node->GetChild(0); | 317 const BookmarkNode* new_node = other_node->GetChild(0); |
| 309 EXPECT_EQ(L"new_a", new_node->GetTitle()); | 318 EXPECT_EQ(L"new_a", new_node->GetTitle()); |
| 310 } | 319 } |
| OLD | NEW |