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

Unified Diff: components/undo/bookmark_undo_service_test.cc

Issue 1229063002: Add BookmarkUndoServiceTest.UndoRemoveFolderWithSubfolders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't set sub_folder1* (now unused) Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/undo/bookmark_undo_service_test.cc
diff --git a/components/undo/bookmark_undo_service_test.cc b/components/undo/bookmark_undo_service_test.cc
index 2e989fda25e2dec2febfbf8b2360d44cc9d80e98..c8de6b003bd0f765c6ca54e1746aafba92a388ef 100644
--- a/components/undo/bookmark_undo_service_test.cc
+++ b/components/undo/bookmark_undo_service_test.cc
@@ -394,6 +394,49 @@ TEST_F(BookmarkUndoServiceTest, UndoRemoveFolderWithBookmarks) {
EXPECT_EQ(node->url(), GURL("http://www.bar.com"));
}
+TEST_F(BookmarkUndoServiceTest, UndoRemoveFolderWithSubfolders) {
+ BookmarkModel* model = GetModel();
+ BookmarkUndoService* undo_service = GetUndoService();
+
+ // Setup bookmarks in the Other Bookmarks with the following structure:
+ // folder
+ // subfolder1
+ // subfolder2
+ // bar - http://www.bar.com
+ // This setup of multiple subfolders where the first subfolder has 0 children
+ // is designed specifically to ensure we do not crash in this scenario and
+ // that bookmarks are restored to the proper subfolder. See crbug.com/474123.
+ const BookmarkNode* parent = model->other_node();
+ const BookmarkNode* new_folder = model->AddFolder(
+ parent, 0, ASCIIToUTF16("folder"));
+ model->AddFolder(new_folder, 0, ASCIIToUTF16("subfolder1"));
+ const BookmarkNode* sub_folder2 = model->AddFolder(
+ new_folder, 1, ASCIIToUTF16("subfolder2"));
+ model->AddURL(sub_folder2, 0, ASCIIToUTF16("bar"),
+ GURL("http://www.bar.com"));
+
+ model->Remove(parent->GetChild(0));
+
+ // Test that the undo restores the subfolders and their contents.
+ undo_service->undo_manager()->Undo();
+
+ ASSERT_EQ(1, model->other_node()->child_count());
+ const BookmarkNode* restored_new_folder = model->other_node()->GetChild(0);
+ EXPECT_EQ(2, restored_new_folder->child_count());
+
+ const BookmarkNode* restored_sub_folder1 = restored_new_folder->GetChild(0);
+ EXPECT_EQ(ASCIIToUTF16("subfolder1"), restored_sub_folder1->GetTitle());
+ EXPECT_EQ(0, restored_sub_folder1->child_count());
+
+ const BookmarkNode* restored_sub_folder2 = restored_new_folder->GetChild(1);
+ EXPECT_EQ(ASCIIToUTF16("subfolder2"), restored_sub_folder2->GetTitle());
+ EXPECT_EQ(1, restored_sub_folder2->child_count());
+
+ const BookmarkNode* node = restored_sub_folder2->GetChild(0);
+ EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("bar"));
+ EXPECT_EQ(node->url(), GURL("http://www.bar.com"));
+}
+
TEST_F(BookmarkUndoServiceTest, TestUpperLimit) {
BookmarkModel* model = GetModel();
BookmarkUndoService* undo_service = GetUndoService();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698