Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/undo/bookmark_undo_service.h" | 5 #include "components/undo/bookmark_undo_service.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/bookmarks/browser/bookmark_model.h" | 8 #include "components/bookmarks/browser/bookmark_model.h" |
| 9 #include "components/bookmarks/test/bookmark_test_helpers.h" | 9 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 10 #include "components/bookmarks/test/test_bookmark_client.h" | 10 #include "components/bookmarks/test/test_bookmark_client.h" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 undo_service->undo_manager()->Undo(); | 387 undo_service->undo_manager()->Undo(); |
| 388 | 388 |
| 389 ASSERT_EQ(1, model->other_node()->child_count()); | 389 ASSERT_EQ(1, model->other_node()->child_count()); |
| 390 new_folder = model->other_node()->GetChild(0); | 390 new_folder = model->other_node()->GetChild(0); |
| 391 EXPECT_EQ(1, new_folder->child_count()); | 391 EXPECT_EQ(1, new_folder->child_count()); |
| 392 node = new_folder->GetChild(0); | 392 node = new_folder->GetChild(0); |
| 393 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("bar")); | 393 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("bar")); |
| 394 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); | 394 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); |
| 395 } | 395 } |
| 396 | 396 |
| 397 TEST_F(BookmarkUndoServiceTest, UndoRemoveFolderWithSubfolders) { | |
| 398 BookmarkModel* model = GetModel(); | |
| 399 BookmarkUndoService* undo_service = GetUndoService(); | |
| 400 | |
| 401 // Setup bookmarks in the Other Bookmarks with the following structure: | |
| 402 // folder | |
| 403 // subfolder1 | |
| 404 // subfolder2 | |
| 405 // bar - http://www.bar.com | |
| 406 // This setup of multiple subfolders where the first subfolder has 0 children | |
| 407 // is designed specifically to ensure we do not crash in this scenario and | |
| 408 // that bookmarks are restored to the proper subfolder. See crbug.com/474123. | |
| 409 const BookmarkNode* new_folder; | |
| 410 const BookmarkNode* sub_folder1; | |
| 411 const BookmarkNode* sub_folder2; | |
| 412 const BookmarkNode* parent = model->other_node(); | |
| 413 new_folder = model->AddFolder(parent, 0, ASCIIToUTF16("folder")); | |
| 414 sub_folder1 = model->AddFolder(new_folder, 0, ASCIIToUTF16("subfolder1")); | |
| 415 sub_folder2 = model->AddFolder(new_folder, 1, ASCIIToUTF16("subfolder2")); | |
| 416 model->AddURL(sub_folder2, 0, ASCIIToUTF16("bar"), GURL("http://www.bar.com")) ; | |
|
sky
2015/07/20 20:01:35
nit: > 80.
Theresa
2015/07/21 00:42:54
Done.
| |
| 417 | |
| 418 model->Remove(parent->GetChild(0)); | |
| 419 | |
| 420 // Test that the undo restores the subfolders and their contents. | |
| 421 undo_service->undo_manager()->Undo(); | |
| 422 | |
| 423 ASSERT_EQ(1, model->other_node()->child_count()); | |
| 424 new_folder = model->other_node()->GetChild(0); | |
|
sky
2015/07/20 20:01:35
I think this code would be clearer if you didn't r
Theresa
2015/07/21 00:42:54
Done.
| |
| 425 EXPECT_EQ(2, new_folder->child_count()); | |
| 426 | |
| 427 sub_folder1 = new_folder->GetChild(0); | |
| 428 EXPECT_EQ(ASCIIToUTF16("subfolder1"), sub_folder1->GetTitle()); | |
| 429 EXPECT_EQ(0, sub_folder1->child_count()); | |
| 430 | |
| 431 sub_folder2 = new_folder->GetChild(1); | |
| 432 EXPECT_EQ(ASCIIToUTF16("subfolder2"), sub_folder2->GetTitle()); | |
| 433 EXPECT_EQ(1, sub_folder2->child_count()); | |
| 434 | |
| 435 const BookmarkNode* node = sub_folder2->GetChild(0); | |
| 436 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("bar")); | |
| 437 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); | |
| 438 } | |
| 439 | |
| 397 TEST_F(BookmarkUndoServiceTest, TestUpperLimit) { | 440 TEST_F(BookmarkUndoServiceTest, TestUpperLimit) { |
| 398 BookmarkModel* model = GetModel(); | 441 BookmarkModel* model = GetModel(); |
| 399 BookmarkUndoService* undo_service = GetUndoService(); | 442 BookmarkUndoService* undo_service = GetUndoService(); |
| 400 | 443 |
| 401 // This maximum is set in undo_manager.cc | 444 // This maximum is set in undo_manager.cc |
| 402 const size_t kMaxUndoGroups = 100; | 445 const size_t kMaxUndoGroups = 100; |
| 403 | 446 |
| 404 const BookmarkNode* parent = model->other_node(); | 447 const BookmarkNode* parent = model->other_node(); |
| 405 model->AddURL(parent, 0, ASCIIToUTF16("foo"), GURL("http://www.foo.com")); | 448 model->AddURL(parent, 0, ASCIIToUTF16("foo"), GURL("http://www.foo.com")); |
| 406 for (size_t i = 1; i < kMaxUndoGroups + 1; ++i) | 449 for (size_t i = 1; i < kMaxUndoGroups + 1; ++i) |
| 407 model->AddURL(parent, i, ASCIIToUTF16("bar"), GURL("http://www.bar.com")); | 450 model->AddURL(parent, i, ASCIIToUTF16("bar"), GURL("http://www.bar.com")); |
| 408 | 451 |
| 409 EXPECT_EQ(kMaxUndoGroups, undo_service->undo_manager()->undo_count()); | 452 EXPECT_EQ(kMaxUndoGroups, undo_service->undo_manager()->undo_count()); |
| 410 | 453 |
| 411 // Undo as many operations as possible. | 454 // Undo as many operations as possible. |
| 412 while (undo_service->undo_manager()->undo_count()) | 455 while (undo_service->undo_manager()->undo_count()) |
| 413 undo_service->undo_manager()->Undo(); | 456 undo_service->undo_manager()->Undo(); |
| 414 | 457 |
| 415 EXPECT_EQ(1, parent->child_count()); | 458 EXPECT_EQ(1, parent->child_count()); |
| 416 const BookmarkNode* node = model->other_node()->GetChild(0); | 459 const BookmarkNode* node = model->other_node()->GetChild(0); |
| 417 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); | 460 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); |
| 418 EXPECT_EQ(node->url(), GURL("http://www.foo.com")); | 461 EXPECT_EQ(node->url(), GURL("http://www.foo.com")); |
| 419 } | 462 } |
| 420 | 463 |
| 421 } // namespace | 464 } // namespace |
| OLD | NEW |