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