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/command_line.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
12 #include "chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk.h" | 13 #include "chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk.h" |
13 #include "chrome/browser/ui/gtk/bookmarks/bookmark_tree_model.h" | 14 #include "chrome/browser/ui/gtk/bookmarks/bookmark_tree_model.h" |
| 15 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/test/testing_profile.h" | 16 #include "chrome/test/testing_profile.h" |
15 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
18 using base::Time; | 20 using base::Time; |
19 using base::TimeDelta; | 21 using base::TimeDelta; |
20 using bookmark_utils::GetTitleFromTreeIter; | 22 using bookmark_utils::GetTitleFromTreeIter; |
21 | 23 |
22 // Base class for bookmark editor tests. This class is a copy from | 24 // Base class for bookmark editor tests. This class is a copy from |
23 // bookmark_editor_view_unittest.cc, and all the tests in this file are | 25 // bookmark_editor_view_unittest.cc, and all the tests in this file are |
24 // GTK-ifications of the corresponding views tests. Testing here is really | 26 // GTK-ifications of the corresponding views tests. Testing here is really |
25 // important because on Linux, we make round trip copies from chrome's | 27 // important because on Linux, we make round trip copies from chrome's |
26 // BookmarkModel class to GTK's native GtkTreeStore. | 28 // BookmarkModel class to GTK's native GtkTreeStore. |
27 class BookmarkEditorGtkTest : public testing::Test { | 29 class BookmarkEditorGtkTest : public testing::Test { |
28 public: | 30 public: |
29 BookmarkEditorGtkTest() | 31 BookmarkEditorGtkTest() |
30 : ui_thread_(BrowserThread::UI, &message_loop_), | 32 : ui_thread_(BrowserThread::UI, &message_loop_), |
31 file_thread_(BrowserThread::FILE, &message_loop_), | 33 file_thread_(BrowserThread::FILE, &message_loop_), |
32 model_(NULL) { | 34 model_(NULL) { |
33 } | 35 } |
34 | 36 |
35 virtual void SetUp() { | 37 virtual void SetUp() { |
| 38 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 39 switches::kEnableSyncedBookmarksFolder); |
36 profile_.reset(new TestingProfile()); | 40 profile_.reset(new TestingProfile()); |
37 profile_->CreateBookmarkModel(true); | 41 profile_->CreateBookmarkModel(true); |
38 profile_->BlockUntilBookmarkModelLoaded(); | 42 profile_->BlockUntilBookmarkModelLoaded(); |
39 | 43 |
40 model_ = profile_->GetBookmarkModel(); | 44 model_ = profile_->GetBookmarkModel(); |
41 | 45 |
42 AddTestData(); | 46 AddTestData(); |
43 } | 47 } |
44 | 48 |
45 virtual void TearDown() { | 49 virtual void TearDown() { |
(...skipping 18 matching lines...) Expand all Loading... |
64 // a | 68 // a |
65 // F1 | 69 // F1 |
66 // f1a | 70 // f1a |
67 // F11 | 71 // F11 |
68 // f11a | 72 // f11a |
69 // F2 | 73 // F2 |
70 // other node | 74 // other node |
71 // oa | 75 // oa |
72 // OF1 | 76 // OF1 |
73 // of1a | 77 // of1a |
| 78 // synced node |
| 79 // sa |
74 void AddTestData() { | 80 void AddTestData() { |
75 std::string test_base = base_path(); | 81 std::string test_base = base_path(); |
76 | 82 |
77 model_->AddURL(model_->GetBookmarkBarNode(), 0, ASCIIToUTF16("a"), | 83 model_->AddURL(model_->GetBookmarkBarNode(), 0, ASCIIToUTF16("a"), |
78 GURL(test_base + "a")); | 84 GURL(test_base + "a")); |
79 const BookmarkNode* f1 = | 85 const BookmarkNode* f1 = |
80 model_->AddFolder(model_->GetBookmarkBarNode(), 1, ASCIIToUTF16("F1")); | 86 model_->AddFolder(model_->GetBookmarkBarNode(), 1, ASCIIToUTF16("F1")); |
81 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); | 87 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); |
82 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); | 88 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); |
83 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); | 89 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); |
84 model_->AddFolder(model_->GetBookmarkBarNode(), 2, ASCIIToUTF16("F2")); | 90 model_->AddFolder(model_->GetBookmarkBarNode(), 2, ASCIIToUTF16("F2")); |
85 | 91 |
86 // Children of the other node. | 92 // Children of the other node. |
87 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("oa"), | 93 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("oa"), |
88 GURL(test_base + "oa")); | 94 GURL(test_base + "oa")); |
89 const BookmarkNode* of1 = | 95 const BookmarkNode* of1 = |
90 model_->AddFolder(model_->other_node(), 1, ASCIIToUTF16("OF1")); | 96 model_->AddFolder(model_->other_node(), 1, ASCIIToUTF16("OF1")); |
91 model_->AddURL(of1, 0, ASCIIToUTF16("of1a"), GURL(test_base + "of1a")); | 97 model_->AddURL(of1, 0, ASCIIToUTF16("of1a"), GURL(test_base + "of1a")); |
| 98 |
| 99 // Children of the synced node. |
| 100 model_->AddURL(model_->synced_node(), 0, ASCIIToUTF16("sa"), |
| 101 GURL(test_base + "sa")); |
92 } | 102 } |
93 }; | 103 }; |
94 | 104 |
95 // Makes sure the tree model matches that of the bookmark bar model. | 105 // Makes sure the tree model matches that of the bookmark bar model. |
96 TEST_F(BookmarkEditorGtkTest, ModelsMatch) { | 106 TEST_F(BookmarkEditorGtkTest, ModelsMatch) { |
97 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, | 107 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
98 BookmarkEditor::EditDetails(), | 108 BookmarkEditor::EditDetails(), |
99 BookmarkEditor::SHOW_TREE); | 109 BookmarkEditor::SHOW_TREE); |
100 | 110 |
101 // The root should have two children, one for the bookmark bar node, | 111 // The root should have two children, one for the bookmark bar node, |
102 // the other for the 'other bookmarks' folder. | 112 // the other for the 'other bookmarks' folder. |
103 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); | 113 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); |
104 GtkTreeIter toplevel; | 114 GtkTreeIter toplevel; |
105 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel)); | 115 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel)); |
106 GtkTreeIter bookmark_bar_node = toplevel; | 116 GtkTreeIter bookmark_bar_node = toplevel; |
107 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); | 117 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); |
108 GtkTreeIter other_node = toplevel; | 118 GtkTreeIter other_node = toplevel; |
| 119 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); |
| 120 GtkTreeIter synced_node = toplevel; |
109 ASSERT_FALSE(gtk_tree_model_iter_next(store, &toplevel)); | 121 ASSERT_FALSE(gtk_tree_model_iter_next(store, &toplevel)); |
110 | 122 |
111 // The bookmark bar should have 2 nodes: folder F1 and F2. | 123 // The bookmark bar should have 2 nodes: folder F1 and F2. |
112 GtkTreeIter f1_iter; | 124 GtkTreeIter f1_iter; |
113 GtkTreeIter child; | 125 GtkTreeIter child; |
114 ASSERT_EQ(2, gtk_tree_model_iter_n_children(store, &bookmark_bar_node)); | 126 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)); | 127 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &bookmark_bar_node)); |
116 f1_iter = child; | 128 f1_iter = child; |
117 ASSERT_EQ("F1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); | 129 ASSERT_EQ("F1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); |
118 ASSERT_TRUE(gtk_tree_model_iter_next(store, &child)); | 130 ASSERT_TRUE(gtk_tree_model_iter_next(store, &child)); |
119 ASSERT_EQ("F2", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); | 131 ASSERT_EQ("F2", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); |
120 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); | 132 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); |
121 | 133 |
122 // F1 should have one child, F11 | 134 // F1 should have one child, F11 |
123 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &f1_iter)); | 135 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &f1_iter)); |
124 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &f1_iter)); | 136 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &f1_iter)); |
125 ASSERT_EQ("F11", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); | 137 ASSERT_EQ("F11", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); |
126 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); | 138 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); |
127 | 139 |
128 // Other node should have one child (OF1). | 140 // Other node should have one child (OF1). |
129 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &other_node)); | 141 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &other_node)); |
130 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &other_node)); | 142 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &other_node)); |
131 ASSERT_EQ("OF1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); | 143 ASSERT_EQ("OF1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); |
132 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); | 144 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); |
| 145 |
| 146 // Synced node should have one child (sa). |
| 147 ASSERT_EQ(0, gtk_tree_model_iter_n_children(store, &synced_node)); |
133 } | 148 } |
134 | 149 |
135 // Changes the title and makes sure parent/visual order doesn't change. | 150 // Changes the title and makes sure parent/visual order doesn't change. |
136 TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { | 151 TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { |
137 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, | 152 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, |
138 BookmarkEditor::EditDetails(GetNode("a")), | 153 BookmarkEditor::EditDetails(GetNode("a")), |
139 BookmarkEditor::SHOW_TREE); | 154 BookmarkEditor::SHOW_TREE); |
140 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); | 155 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); |
141 | 156 |
142 GtkTreeIter bookmark_bar_node; | 157 GtkTreeIter bookmark_bar_node; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); | 331 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); |
317 | 332 |
318 editor.ApplyEdits(); | 333 editor.ApplyEdits(); |
319 | 334 |
320 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); | 335 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); |
321 ASSERT_EQ(2, other_node->child_count()); | 336 ASSERT_EQ(2, other_node->child_count()); |
322 | 337 |
323 const BookmarkNode* new_node = other_node->GetChild(0); | 338 const BookmarkNode* new_node = other_node->GetChild(0); |
324 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); | 339 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); |
325 } | 340 } |
OLD | NEW |