| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // a | 63 // a |
| 64 // F1 | 64 // F1 |
| 65 // f1a | 65 // f1a |
| 66 // F11 | 66 // F11 |
| 67 // f11a | 67 // f11a |
| 68 // F2 | 68 // F2 |
| 69 // other node | 69 // other node |
| 70 // oa | 70 // oa |
| 71 // OF1 | 71 // OF1 |
| 72 // of1a | 72 // of1a |
| 73 // synced node | 73 // mobile node |
| 74 // sa | 74 // sa |
| 75 void AddTestData() { | 75 void AddTestData() { |
| 76 std::string test_base = base_path(); | 76 std::string test_base = base_path(); |
| 77 | 77 |
| 78 model_->AddURL(model_->bookmark_bar_node(), 0, ASCIIToUTF16("a"), | 78 model_->AddURL(model_->bookmark_bar_node(), 0, ASCIIToUTF16("a"), |
| 79 GURL(test_base + "a")); | 79 GURL(test_base + "a")); |
| 80 const BookmarkNode* f1 = | 80 const BookmarkNode* f1 = |
| 81 model_->AddFolder(model_->bookmark_bar_node(), 1, ASCIIToUTF16("F1")); | 81 model_->AddFolder(model_->bookmark_bar_node(), 1, ASCIIToUTF16("F1")); |
| 82 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); | 82 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); |
| 83 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); | 83 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); |
| 84 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); | 84 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); |
| 85 model_->AddFolder(model_->bookmark_bar_node(), 2, ASCIIToUTF16("F2")); | 85 model_->AddFolder(model_->bookmark_bar_node(), 2, ASCIIToUTF16("F2")); |
| 86 | 86 |
| 87 // Children of the other node. | 87 // Children of the other node. |
| 88 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("oa"), | 88 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("oa"), |
| 89 GURL(test_base + "oa")); | 89 GURL(test_base + "oa")); |
| 90 const BookmarkNode* of1 = | 90 const BookmarkNode* of1 = |
| 91 model_->AddFolder(model_->other_node(), 1, ASCIIToUTF16("OF1")); | 91 model_->AddFolder(model_->other_node(), 1, ASCIIToUTF16("OF1")); |
| 92 model_->AddURL(of1, 0, ASCIIToUTF16("of1a"), GURL(test_base + "of1a")); | 92 model_->AddURL(of1, 0, ASCIIToUTF16("of1a"), GURL(test_base + "of1a")); |
| 93 | 93 |
| 94 // Children of the synced node. | 94 // Children of the mobile node. |
| 95 model_->AddURL(model_->synced_node(), 0, ASCIIToUTF16("sa"), | 95 model_->AddURL(model_->mobile_node(), 0, ASCIIToUTF16("sa"), |
| 96 GURL(test_base + "sa")); | 96 GURL(test_base + "sa")); |
| 97 } | 97 } |
| 98 | 98 |
| 99 MessageLoopForUI message_loop_; | 99 MessageLoopForUI message_loop_; |
| 100 content::TestBrowserThread ui_thread_; | 100 content::TestBrowserThread ui_thread_; |
| 101 content::TestBrowserThread file_thread_; | 101 content::TestBrowserThread file_thread_; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 // Makes sure the tree model matches that of the bookmark bar model. | 104 // Makes sure the tree model matches that of the bookmark bar model. |
| 105 TEST_F(BookmarkEditorGtkTest, ModelsMatch) { | 105 TEST_F(BookmarkEditorGtkTest, ModelsMatch) { |
| 106 BookmarkEditorGtk editor( | 106 BookmarkEditorGtk editor( |
| 107 NULL, | 107 NULL, |
| 108 profile_.get(), | 108 profile_.get(), |
| 109 NULL, | 109 NULL, |
| 110 BookmarkEditor::EditDetails::AddNodeInFolder(NULL, -1), | 110 BookmarkEditor::EditDetails::AddNodeInFolder(NULL, -1), |
| 111 BookmarkEditor::SHOW_TREE); | 111 BookmarkEditor::SHOW_TREE); |
| 112 | 112 |
| 113 // The root should have two or three children, one for the bookmark bar node, | 113 // The root should have two or three children, one for the bookmark bar node, |
| 114 // another for the 'other bookmarks' folder, and depending on the visib | 114 // another for the 'other bookmarks' folder, and depending on the visib |
| 115 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 115 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
| 116 GtkTreeIter toplevel; | 116 GtkTreeIter toplevel; |
| 117 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel)); | 117 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel)); |
| 118 GtkTreeIter bookmark_bar_node = toplevel; | 118 GtkTreeIter bookmark_bar_node = toplevel; |
| 119 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); | 119 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); |
| 120 GtkTreeIter other_node = toplevel; | 120 GtkTreeIter other_node = toplevel; |
| 121 if (model_->synced_node()->IsVisible()) { | 121 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); |
| 122 // If we have a synced node, then the iterator should find one element after | 122 ASSERT_FALSE(gtk_tree_model_iter_next(store, &toplevel)); |
| 123 // "other bookmarks" | |
| 124 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); | |
| 125 ASSERT_FALSE(gtk_tree_model_iter_next(store, &toplevel)); | |
| 126 } else { | |
| 127 ASSERT_FALSE(gtk_tree_model_iter_next(store, &toplevel)); | |
| 128 } | |
| 129 | 123 |
| 130 // The bookmark bar should have 2 nodes: folder F1 and F2. | 124 // The bookmark bar should have 2 nodes: folder F1 and F2. |
| 131 GtkTreeIter f1_iter; | 125 GtkTreeIter f1_iter; |
| 132 GtkTreeIter child; | 126 GtkTreeIter child; |
| 133 ASSERT_EQ(2, gtk_tree_model_iter_n_children(store, &bookmark_bar_node)); | 127 ASSERT_EQ(2, gtk_tree_model_iter_n_children(store, &bookmark_bar_node)); |
| 134 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &bookmark_bar_node)); | 128 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &bookmark_bar_node)); |
| 135 f1_iter = child; | 129 f1_iter = child; |
| 136 ASSERT_EQ("F1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); | 130 ASSERT_EQ("F1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); |
| 137 ASSERT_TRUE(gtk_tree_model_iter_next(store, &child)); | 131 ASSERT_TRUE(gtk_tree_model_iter_next(store, &child)); |
| 138 ASSERT_EQ("F2", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); | 132 ASSERT_EQ("F2", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); | 328 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); |
| 335 | 329 |
| 336 editor.ApplyEdits(); | 330 editor.ApplyEdits(); |
| 337 | 331 |
| 338 const BookmarkNode* other_node = model_->other_node(); | 332 const BookmarkNode* other_node = model_->other_node(); |
| 339 ASSERT_EQ(2, other_node->child_count()); | 333 ASSERT_EQ(2, other_node->child_count()); |
| 340 | 334 |
| 341 const BookmarkNode* new_node = other_node->GetChild(0); | 335 const BookmarkNode* new_node = other_node->GetChild(0); |
| 342 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); | 336 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); |
| 343 } | 337 } |
| OLD | NEW |