Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk_unittest.cc

Issue 7670041: Add --use-more-webui runtime flag to toggle WebUI replacements for native dialogs. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merge with trunk. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 // Children of the synced node. 95 // Children of the synced node.
96 model_->AddURL(model_->synced_node(), 0, ASCIIToUTF16("sa"), 96 model_->AddURL(model_->synced_node(), 0, ASCIIToUTF16("sa"),
97 GURL(test_base + "sa")); 97 GURL(test_base + "sa"));
98 } 98 }
99 }; 99 };
100 100
101 // 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.
102 TEST_F(BookmarkEditorGtkTest, ModelsMatch) { 102 TEST_F(BookmarkEditorGtkTest, ModelsMatch) {
103 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 103 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
104 BookmarkEditor::EditDetails(), 104 BookmarkEditor::EditDetails::AddNodeInFolder(NULL),
105 BookmarkEditor::SHOW_TREE); 105 BookmarkEditor::SHOW_TREE);
106 106
107 // The root should have two or three children, one for the bookmark bar node, 107 // The root should have two or three children, one for the bookmark bar node,
108 // another for the 'other bookmarks' folder, and depending on the visib 108 // another for the 'other bookmarks' folder, and depending on the visib
109 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); 109 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
110 GtkTreeIter toplevel; 110 GtkTreeIter toplevel;
111 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel)); 111 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &toplevel));
112 GtkTreeIter bookmark_bar_node = toplevel; 112 GtkTreeIter bookmark_bar_node = toplevel;
113 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel)); 113 ASSERT_TRUE(gtk_tree_model_iter_next(store, &toplevel));
114 GtkTreeIter other_node = toplevel; 114 GtkTreeIter other_node = toplevel;
(...skipping 26 matching lines...) Expand all
141 // Other node should have one child (OF1). 141 // Other node should have one child (OF1).
142 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &other_node)); 142 ASSERT_EQ(1, gtk_tree_model_iter_n_children(store, &other_node));
143 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &other_node)); 143 ASSERT_TRUE(gtk_tree_model_iter_children(store, &child, &other_node));
144 ASSERT_EQ("OF1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child))); 144 ASSERT_EQ("OF1", UTF16ToUTF8(GetTitleFromTreeIter(store, &child)));
145 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child)); 145 ASSERT_FALSE(gtk_tree_model_iter_next(store, &child));
146 } 146 }
147 147
148 // Changes the title and makes sure parent/visual order doesn't change. 148 // Changes the title and makes sure parent/visual order doesn't change.
149 TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { 149 TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) {
150 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 150 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
151 BookmarkEditor::EditDetails(GetNode("a")), 151 BookmarkEditor::EditDetails::EditNode(GetNode("a")),
152 BookmarkEditor::SHOW_TREE); 152 BookmarkEditor::SHOW_TREE);
153 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); 153 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a");
154 154
155 GtkTreeIter bookmark_bar_node; 155 GtkTreeIter bookmark_bar_node;
156 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); 156 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
157 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); 157 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node));
158 editor.ApplyEdits(&bookmark_bar_node); 158 editor.ApplyEdits(&bookmark_bar_node);
159 159
160 const BookmarkNode* bb_node = 160 const BookmarkNode* bb_node =
161 profile_->GetBookmarkModel()->bookmark_bar_node(); 161 profile_->GetBookmarkModel()->bookmark_bar_node();
162 ASSERT_EQ(ASCIIToUTF16("new_a"), bb_node->GetChild(0)->GetTitle()); 162 ASSERT_EQ(ASCIIToUTF16("new_a"), bb_node->GetChild(0)->GetTitle());
163 // The URL shouldn't have changed. 163 // The URL shouldn't have changed.
164 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->url()); 164 ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->url());
165 } 165 }
166 166
167 // Changes the url and makes sure parent/visual order doesn't change. 167 // Changes the url and makes sure parent/visual order doesn't change.
168 TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) { 168 TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) {
169 Time node_time = GetNode("a")->date_added(); 169 Time node_time = GetNode("a")->date_added();
170 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 170 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
171 BookmarkEditor::EditDetails(GetNode("a")), 171 BookmarkEditor::EditDetails::EditNode(GetNode("a")),
172 BookmarkEditor::SHOW_TREE); 172 BookmarkEditor::SHOW_TREE);
173 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), 173 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
174 GURL(base_path() + "new_a").spec().c_str()); 174 GURL(base_path() + "new_a").spec().c_str());
175 175
176 GtkTreeIter bookmark_bar_node; 176 GtkTreeIter bookmark_bar_node;
177 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); 177 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
178 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); 178 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node));
179 editor.ApplyEdits(&bookmark_bar_node); 179 editor.ApplyEdits(&bookmark_bar_node);
180 180
181 const BookmarkNode* bb_node = 181 const BookmarkNode* bb_node =
182 profile_->GetBookmarkModel()->bookmark_bar_node(); 182 profile_->GetBookmarkModel()->bookmark_bar_node();
183 ASSERT_EQ(ASCIIToUTF16("a"), bb_node->GetChild(0)->GetTitle()); 183 ASSERT_EQ(ASCIIToUTF16("a"), bb_node->GetChild(0)->GetTitle());
184 // The URL should have changed. 184 // The URL should have changed.
185 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->url()); 185 ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->url());
186 ASSERT_TRUE(node_time == bb_node->GetChild(0)->date_added()); 186 ASSERT_TRUE(node_time == bb_node->GetChild(0)->date_added());
187 } 187 }
188 188
189 // Moves 'a' to be a child of the other node. 189 // Moves 'a' to be a child of the other node.
190 TEST_F(BookmarkEditorGtkTest, ChangeParent) { 190 TEST_F(BookmarkEditorGtkTest, ChangeParent) {
191 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 191 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
192 BookmarkEditor::EditDetails(GetNode("a")), 192 BookmarkEditor::EditDetails::EditNode(GetNode("a")),
193 BookmarkEditor::SHOW_TREE); 193 BookmarkEditor::SHOW_TREE);
194 194
195 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); 195 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
196 GtkTreeIter gtk_other_node; 196 GtkTreeIter gtk_other_node;
197 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &gtk_other_node)); 197 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &gtk_other_node));
198 ASSERT_TRUE(gtk_tree_model_iter_next(store, &gtk_other_node)); 198 ASSERT_TRUE(gtk_tree_model_iter_next(store, &gtk_other_node));
199 editor.ApplyEdits(&gtk_other_node); 199 editor.ApplyEdits(&gtk_other_node);
200 200
201 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); 201 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
202 ASSERT_EQ(ASCIIToUTF16("a"), other_node->GetChild(2)->GetTitle()); 202 ASSERT_EQ(ASCIIToUTF16("a"), other_node->GetChild(2)->GetTitle());
203 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->url()); 203 ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->url());
204 } 204 }
205 205
206 // Moves 'a' to be a child of the other node. 206 // Moves 'a' to be a child of the other node.
207 // Moves 'a' to be a child of the other node and changes its url to new_a. 207 // Moves 'a' to be a child of the other node and changes its url to new_a.
208 TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) { 208 TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) {
209 Time node_time = GetNode("a")->date_added(); 209 Time node_time = GetNode("a")->date_added();
210 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 210 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
211 BookmarkEditor::EditDetails(GetNode("a")), 211 BookmarkEditor::EditDetails::EditNode(GetNode("a")),
212 BookmarkEditor::SHOW_TREE); 212 BookmarkEditor::SHOW_TREE);
213 213
214 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), 214 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
215 GURL(base_path() + "new_a").spec().c_str()); 215 GURL(base_path() + "new_a").spec().c_str());
216 216
217 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); 217 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
218 GtkTreeIter gtk_other_node; 218 GtkTreeIter gtk_other_node;
219 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &gtk_other_node)); 219 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &gtk_other_node));
220 ASSERT_TRUE(gtk_tree_model_iter_next(store, &gtk_other_node)); 220 ASSERT_TRUE(gtk_tree_model_iter_next(store, &gtk_other_node));
221 editor.ApplyEdits(&gtk_other_node); 221 editor.ApplyEdits(&gtk_other_node);
222 222
223 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); 223 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
224 ASSERT_EQ(ASCIIToUTF16("a"), other_node->GetChild(2)->GetTitle()); 224 ASSERT_EQ(ASCIIToUTF16("a"), other_node->GetChild(2)->GetTitle());
225 ASSERT_TRUE(GURL(base_path() + "new_a") == other_node->GetChild(2)->url()); 225 ASSERT_TRUE(GURL(base_path() + "new_a") == other_node->GetChild(2)->url());
226 ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added()); 226 ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added());
227 } 227 }
228 228
229 // Creates a new folder and moves a node to it. 229 // Creates a new folder and moves a node to it.
230 TEST_F(BookmarkEditorGtkTest, MoveToNewParent) { 230 TEST_F(BookmarkEditorGtkTest, MoveToNewParent) {
231 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 231 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
232 BookmarkEditor::EditDetails(GetNode("a")), 232 BookmarkEditor::EditDetails::EditNode(GetNode("a")),
233 BookmarkEditor::SHOW_TREE); 233 BookmarkEditor::SHOW_TREE);
234 234
235 GtkTreeIter bookmark_bar_node; 235 GtkTreeIter bookmark_bar_node;
236 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); 236 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
237 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); 237 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node));
238 238
239 // The bookmark bar should have 2 nodes: folder F1 and F2. 239 // The bookmark bar should have 2 nodes: folder F1 and F2.
240 GtkTreeIter f2_iter; 240 GtkTreeIter f2_iter;
241 ASSERT_EQ(2, gtk_tree_model_iter_n_children(store, &bookmark_bar_node)); 241 ASSERT_EQ(2, gtk_tree_model_iter_n_children(store, &bookmark_bar_node));
242 ASSERT_TRUE(gtk_tree_model_iter_children(store, &f2_iter, 242 ASSERT_TRUE(gtk_tree_model_iter_children(store, &f2_iter,
(...skipping 27 matching lines...) Expand all
270 270
271 // F21 should have one child, F211. 271 // F21 should have one child, F211.
272 const BookmarkNode* mf21 = mf2->GetChild(0); 272 const BookmarkNode* mf21 = mf2->GetChild(0);
273 ASSERT_EQ(1, mf21->child_count()); 273 ASSERT_EQ(1, mf21->child_count());
274 ASSERT_EQ(ASCIIToUTF16("F211"), mf21->GetChild(0)->GetTitle()); 274 ASSERT_EQ(ASCIIToUTF16("F211"), mf21->GetChild(0)->GetTitle());
275 } 275 }
276 276
277 // Brings up the editor, creating a new URL on the bookmark bar. 277 // Brings up the editor, creating a new URL on the bookmark bar.
278 TEST_F(BookmarkEditorGtkTest, NewURL) { 278 TEST_F(BookmarkEditorGtkTest, NewURL) {
279 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 279 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
280 BookmarkEditor::EditDetails(), 280 BookmarkEditor::EditDetails::AddNodeInFolder(NULL),
281 BookmarkEditor::SHOW_TREE); 281 BookmarkEditor::SHOW_TREE);
282 282
283 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), 283 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
284 GURL(base_path() + "a").spec().c_str()); 284 GURL(base_path() + "a").spec().c_str());
285 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); 285 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a");
286 286
287 GtkTreeIter bookmark_bar_node; 287 GtkTreeIter bookmark_bar_node;
288 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_); 288 GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
289 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); 289 ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node));
290 editor.ApplyEdits(&bookmark_bar_node); 290 editor.ApplyEdits(&bookmark_bar_node);
291 291
292 const BookmarkNode* bb_node = 292 const BookmarkNode* bb_node =
293 profile_->GetBookmarkModel()->bookmark_bar_node(); 293 profile_->GetBookmarkModel()->bookmark_bar_node();
294 ASSERT_EQ(4, bb_node->child_count()); 294 ASSERT_EQ(4, bb_node->child_count());
295 295
296 const BookmarkNode* new_node = bb_node->GetChild(3); 296 const BookmarkNode* new_node = bb_node->GetChild(3);
297 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); 297 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle());
298 EXPECT_TRUE(GURL(base_path() + "a") == new_node->url()); 298 EXPECT_TRUE(GURL(base_path() + "a") == new_node->url());
299 } 299 }
300 300
301 // Brings up the editor with no tree and modifies the url. 301 // Brings up the editor with no tree and modifies the url.
302 TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) { 302 TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) {
303 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 303 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
304 BookmarkEditor::EditDetails( 304 BookmarkEditor::EditDetails::EditNode(
305 model_->other_node()->GetChild(0)), 305 model_->other_node()->GetChild(0)),
306 BookmarkEditor::NO_TREE); 306 BookmarkEditor::NO_TREE);
307 307
308 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), 308 gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
309 GURL(base_path() + "a").spec().c_str()); 309 GURL(base_path() + "a").spec().c_str());
310 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); 310 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a");
311 311
312 editor.ApplyEdits(NULL); 312 editor.ApplyEdits(NULL);
313 313
314 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); 314 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
315 ASSERT_EQ(2, other_node->child_count()); 315 ASSERT_EQ(2, other_node->child_count());
316 316
317 const BookmarkNode* new_node = other_node->GetChild(0); 317 const BookmarkNode* new_node = other_node->GetChild(0);
318 318
319 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); 319 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle());
320 EXPECT_TRUE(GURL(base_path() + "a") == new_node->url()); 320 EXPECT_TRUE(GURL(base_path() + "a") == new_node->url());
321 } 321 }
322 322
323 // Brings up the editor with no tree and modifies only the title. 323 // Brings up the editor with no tree and modifies only the title.
324 TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) { 324 TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) {
325 BookmarkEditorGtk editor(NULL, profile_.get(), NULL, 325 BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
326 BookmarkEditor::EditDetails( 326 BookmarkEditor::EditDetails::EditNode(
327 model_->other_node()->GetChild(0)), 327 model_->other_node()->GetChild(0)),
328 BookmarkEditor::NO_TREE); 328 BookmarkEditor::NO_TREE);
329 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a"); 329 gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a");
330 330
331 editor.ApplyEdits(); 331 editor.ApplyEdits();
332 332
333 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); 333 const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node();
334 ASSERT_EQ(2, other_node->child_count()); 334 ASSERT_EQ(2, other_node->child_count());
335 335
336 const BookmarkNode* new_node = other_node->GetChild(0); 336 const BookmarkNode* new_node = other_node->GetChild(0);
337 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); 337 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle());
338 } 338 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/bookmarks/bookmark_editor_gtk.cc ('k') | chrome/browser/ui/gtk/certificate_viewer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698