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() { | |
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* bb_node = model_->bookmark_bar_node(); | |
346 | |
347 GURL script_url = GURL("http://javascript:scripttext@example.com/"); | |
sky
2016/09/26 23:03:02
It would be nice if the tests were more similar th
elawrence
2016/09/29 21:53:03
Done.
| |
348 | |
349 CreateEditor(profile_.get(), bb_node, | |
350 BookmarkEditor::EditDetails::AddNodeInFolder( | |
351 bb_node, 1, script_url, base::string16()), | |
352 BookmarkEditorView::SHOW_TREE); | |
353 | |
354 // We expect only the trailing / to be trimmed when userinfo is present | |
355 EXPECT_EQ(ASCIIToUTF16(script_url.spec()), GetURLText() + ASCIIToUTF16("/")); | |
356 | |
357 SetTitleText(ASCIIToUTF16("EditingKeepsScheme")); | |
sky
2016/09/26 23:03:02
Make local variable (constant) so you can compare
elawrence
2016/09/29 21:53:03
Done.
| |
358 | |
359 ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); | |
360 | |
361 ASSERT_EQ(4, bb_node->child_count()); | |
362 | |
363 const BookmarkNode* new_node = bb_node->GetChild(1); | |
364 | |
365 EXPECT_EQ(ASCIIToUTF16("EditingKeepsScheme"), new_node->GetTitle()); | |
366 EXPECT_TRUE(script_url == new_node->url()); | |
367 } | |
368 | |
335 // Creates a new folder. | 369 // Creates a new folder. |
336 TEST_F(BookmarkEditorViewTest, NewFolder) { | 370 TEST_F(BookmarkEditorViewTest, NewFolder) { |
337 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 371 const BookmarkNode* bb_node = model_->bookmark_bar_node(); |
338 BookmarkEditor::EditDetails details = | 372 BookmarkEditor::EditDetails details = |
339 BookmarkEditor::EditDetails::AddFolder(bb_node, 1); | 373 BookmarkEditor::EditDetails::AddFolder(bb_node, 1); |
340 details.urls.push_back(std::make_pair(GURL(base_path() + "x"), | 374 details.urls.push_back(std::make_pair(GURL(base_path() + "x"), |
341 ASCIIToUTF16("z"))); | 375 ASCIIToUTF16("z"))); |
342 CreateEditor(profile_.get(), bb_node, details, BookmarkEditorView::SHOW_TREE); | 376 CreateEditor(profile_.get(), bb_node, details, BookmarkEditorView::SHOW_TREE); |
343 | 377 |
344 // The url field shouldn't be visible. | 378 // 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); | 442 ASSERT_TRUE(tree_view()->editor() != NULL); |
409 tree_view()->editor()->SetText(ASCIIToUTF16("modified")); | 443 tree_view()->editor()->SetText(ASCIIToUTF16("modified")); |
410 ApplyEdits(); | 444 ApplyEdits(); |
411 | 445 |
412 // Verify the new folder was added and title set appropriately. | 446 // Verify the new folder was added and title set appropriately. |
413 ASSERT_EQ(1, parent->child_count()); | 447 ASSERT_EQ(1, parent->child_count()); |
414 const BookmarkNode* new_folder = parent->GetChild(0); | 448 const BookmarkNode* new_folder = parent->GetChild(0); |
415 ASSERT_TRUE(new_folder->is_folder()); | 449 ASSERT_TRUE(new_folder->is_folder()); |
416 EXPECT_EQ("modified", base::UTF16ToASCII(new_folder->GetTitle())); | 450 EXPECT_EQ("modified", base::UTF16ToASCII(new_folder->GetTitle())); |
417 } | 451 } |
OLD | NEW |