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