OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 void SetTitleText(const base::string16& title) { | 67 void SetTitleText(const base::string16& title) { |
68 editor_->title_tf_->SetText(title); | 68 editor_->title_tf_->SetText(title); |
69 } | 69 } |
70 | 70 |
71 void SetURLText(const base::string16& text) { | 71 void SetURLText(const base::string16& text) { |
72 if (editor_->details_.type != BookmarkEditor::EditDetails::NEW_FOLDER) | 72 if (editor_->details_.type != BookmarkEditor::EditDetails::NEW_FOLDER) |
73 editor_->url_tf_->SetText(text); | 73 editor_->url_tf_->SetText(text); |
74 } | 74 } |
75 | 75 |
| 76 base::string16 GetURLText() const { |
| 77 if (editor_->details_.type != BookmarkEditor::EditDetails::NEW_FOLDER) |
| 78 return editor_->url_tf_->text(); |
| 79 |
| 80 return base::string16(); |
| 81 } |
| 82 |
76 void ApplyEdits() { | 83 void ApplyEdits() { |
77 editor_->ApplyEdits(); | 84 editor_->ApplyEdits(); |
78 } | 85 } |
79 | 86 |
80 void ApplyEdits(BookmarkEditorView::EditorNode* node) { | 87 void ApplyEdits(BookmarkEditorView::EditorNode* node) { |
81 editor_->ApplyEdits(node); | 88 editor_->ApplyEdits(node); |
82 } | 89 } |
83 | 90 |
84 BookmarkEditorView::EditorNode* AddNewFolder( | 91 BookmarkEditorView::EditorNode* AddNewFolder( |
85 BookmarkEditorView::EditorNode* parent) { | 92 BookmarkEditorView::EditorNode* parent) { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 ApplyEdits(NULL); | 332 ApplyEdits(NULL); |
326 | 333 |
327 const BookmarkNode* other_node = model_->other_node(); | 334 const BookmarkNode* other_node = model_->other_node(); |
328 ASSERT_EQ(2, other_node->child_count()); | 335 ASSERT_EQ(2, other_node->child_count()); |
329 | 336 |
330 const BookmarkNode* new_node = other_node->GetChild(0); | 337 const BookmarkNode* new_node = other_node->GetChild(0); |
331 | 338 |
332 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); | 339 EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); |
333 } | 340 } |
334 | 341 |
| 342 // Edits the bookmark and ensures resulting URL keeps the same scheme, even |
| 343 // when userinfo is present in the URL |
| 344 TEST_F(BookmarkEditorViewTest, EditKeepsScheme) { |
| 345 const BookmarkNode* kBBNode = model_->bookmark_bar_node(); |
| 346 |
| 347 const GURL kUrl = GURL("http://javascript:scripttext@example.com/"); |
| 348 |
| 349 CreateEditor(profile_.get(), kBBNode, |
| 350 BookmarkEditor::EditDetails::AddNodeInFolder(kBBNode, 1, kUrl, |
| 351 base::string16()), |
| 352 BookmarkEditorView::SHOW_TREE); |
| 353 |
| 354 // We expect only the trailing / to be trimmed when userinfo is present |
| 355 EXPECT_EQ(ASCIIToUTF16(kUrl.spec()), GetURLText() + ASCIIToUTF16("/")); |
| 356 |
| 357 const base::string16& kTitle = ASCIIToUTF16("EditingKeepsScheme"); |
| 358 SetTitleText(kTitle); |
| 359 |
| 360 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); |
| 361 |
| 362 ASSERT_EQ(4, kBBNode->child_count()); |
| 363 |
| 364 const BookmarkNode* kNewNode = kBBNode->GetChild(1); |
| 365 |
| 366 EXPECT_EQ(kTitle, kNewNode->GetTitle()); |
| 367 EXPECT_EQ(kUrl, kNewNode->url()); |
| 368 } |
| 369 |
335 // Creates a new folder. | 370 // Creates a new folder. |
336 TEST_F(BookmarkEditorViewTest, NewFolder) { | 371 TEST_F(BookmarkEditorViewTest, NewFolder) { |
337 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 372 const BookmarkNode* bb_node = model_->bookmark_bar_node(); |
338 BookmarkEditor::EditDetails details = | 373 BookmarkEditor::EditDetails details = |
339 BookmarkEditor::EditDetails::AddFolder(bb_node, 1); | 374 BookmarkEditor::EditDetails::AddFolder(bb_node, 1); |
340 details.urls.push_back(std::make_pair(GURL(base_path() + "x"), | 375 details.urls.push_back(std::make_pair(GURL(base_path() + "x"), |
341 ASCIIToUTF16("z"))); | 376 ASCIIToUTF16("z"))); |
342 CreateEditor(profile_.get(), bb_node, details, BookmarkEditorView::SHOW_TREE); | 377 CreateEditor(profile_.get(), bb_node, details, BookmarkEditorView::SHOW_TREE); |
343 | 378 |
344 // The url field shouldn't be visible. | 379 // The url field shouldn't be visible. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 ASSERT_TRUE(tree_view()->editor() != NULL); | 443 ASSERT_TRUE(tree_view()->editor() != NULL); |
409 tree_view()->editor()->SetText(ASCIIToUTF16("modified")); | 444 tree_view()->editor()->SetText(ASCIIToUTF16("modified")); |
410 ApplyEdits(); | 445 ApplyEdits(); |
411 | 446 |
412 // Verify the new folder was added and title set appropriately. | 447 // Verify the new folder was added and title set appropriately. |
413 ASSERT_EQ(1, parent->child_count()); | 448 ASSERT_EQ(1, parent->child_count()); |
414 const BookmarkNode* new_folder = parent->GetChild(0); | 449 const BookmarkNode* new_folder = parent->GetChild(0); |
415 ASSERT_TRUE(new_folder->is_folder()); | 450 ASSERT_TRUE(new_folder->is_folder()); |
416 EXPECT_EQ("modified", base::UTF16ToASCII(new_folder->GetTitle())); | 451 EXPECT_EQ("modified", base::UTF16ToASCII(new_folder->GetTitle())); |
417 } | 452 } |
OLD | NEW |