| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); | 83 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Test that a bookmark removal action can be undone and redone. | 86 // Test that a bookmark removal action can be undone and redone. |
| 87 TEST_F(BookmarkUndoServiceTest, UndoBookmarkRemove) { | 87 TEST_F(BookmarkUndoServiceTest, UndoBookmarkRemove) { |
| 88 BookmarkModel* model = GetModel(); | 88 BookmarkModel* model = GetModel(); |
| 89 BookmarkUndoService* undo_service = GetUndoService(); | 89 BookmarkUndoService* undo_service = GetUndoService(); |
| 90 | 90 |
| 91 const BookmarkNode* parent = model->other_node(); | 91 const BookmarkNode* parent = model->other_node(); |
| 92 model->AddURL(parent, 0, ASCIIToUTF16("foo"), GURL("http://www.bar.com")); | 92 model->AddURL(parent, 0, ASCIIToUTF16("foo"), GURL("http://www.bar.com")); |
| 93 model->Remove(parent, 0); | 93 model->Remove(parent, parent->GetChild(0)); |
| 94 | 94 |
| 95 EXPECT_EQ(2U, undo_service->undo_manager()->undo_count()); | 95 EXPECT_EQ(2U, undo_service->undo_manager()->undo_count()); |
| 96 EXPECT_EQ(0U, undo_service->undo_manager()->redo_count()); | 96 EXPECT_EQ(0U, undo_service->undo_manager()->redo_count()); |
| 97 | 97 |
| 98 // Undo the deletion of the only bookmark and check the bookmark values. | 98 // Undo the deletion of the only bookmark and check the bookmark values. |
| 99 undo_service->undo_manager()->Undo(); | 99 undo_service->undo_manager()->Undo(); |
| 100 EXPECT_EQ(1, model->other_node()->child_count()); | 100 EXPECT_EQ(1, model->other_node()->child_count()); |
| 101 const BookmarkNode* node = parent->GetChild(0); | 101 const BookmarkNode* node = parent->GetChild(0); |
| 102 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); | 102 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); |
| 103 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); | 103 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // bookmark identifiers. | 225 // bookmark identifiers. |
| 226 TEST_F(BookmarkUndoServiceTest, UndoBookmarkRenameDelete) { | 226 TEST_F(BookmarkUndoServiceTest, UndoBookmarkRenameDelete) { |
| 227 BookmarkModel* model = GetModel(); | 227 BookmarkModel* model = GetModel(); |
| 228 BookmarkUndoService* undo_service = GetUndoService(); | 228 BookmarkUndoService* undo_service = GetUndoService(); |
| 229 | 229 |
| 230 const BookmarkNode* f1 = model->AddFolder(model->other_node(), | 230 const BookmarkNode* f1 = model->AddFolder(model->other_node(), |
| 231 0, | 231 0, |
| 232 ASCIIToUTF16("folder")); | 232 ASCIIToUTF16("folder")); |
| 233 model->AddURL(f1, 0, ASCIIToUTF16("foo"), GURL("http://www.foo.com")); | 233 model->AddURL(f1, 0, ASCIIToUTF16("foo"), GURL("http://www.foo.com")); |
| 234 model->SetTitle(f1, ASCIIToUTF16("Renamed")); | 234 model->SetTitle(f1, ASCIIToUTF16("Renamed")); |
| 235 model->Remove(model->other_node(), 0); | 235 model->Remove(model->other_node(), model->other_node()->GetChild(0)); |
| 236 | 236 |
| 237 // Undo the folder removal and ensure the folder and bookmark were restored. | 237 // Undo the folder removal and ensure the folder and bookmark were restored. |
| 238 undo_service->undo_manager()->Undo(); | 238 undo_service->undo_manager()->Undo(); |
| 239 ASSERT_EQ(1, model->other_node()->child_count()); | 239 ASSERT_EQ(1, model->other_node()->child_count()); |
| 240 ASSERT_EQ(1, model->other_node()->GetChild(0)->child_count()); | 240 ASSERT_EQ(1, model->other_node()->GetChild(0)->child_count()); |
| 241 const BookmarkNode* node = model->other_node()->GetChild(0); | 241 const BookmarkNode* node = model->other_node()->GetChild(0); |
| 242 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("Renamed")); | 242 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("Renamed")); |
| 243 | 243 |
| 244 node = model->other_node()->GetChild(0)->GetChild(0); | 244 node = model->other_node()->GetChild(0)->GetChild(0); |
| 245 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); | 245 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 TEST_F(BookmarkUndoServiceTest, UndoRemoveFolderWithBookmarks) { | 359 TEST_F(BookmarkUndoServiceTest, UndoRemoveFolderWithBookmarks) { |
| 360 BookmarkModel* model = GetModel(); | 360 BookmarkModel* model = GetModel(); |
| 361 BookmarkUndoService* undo_service = GetUndoService(); | 361 BookmarkUndoService* undo_service = GetUndoService(); |
| 362 | 362 |
| 363 // Setup bookmarks in the Other Bookmarks. | 363 // Setup bookmarks in the Other Bookmarks. |
| 364 const BookmarkNode* new_folder; | 364 const BookmarkNode* new_folder; |
| 365 const BookmarkNode* parent = model->other_node(); | 365 const BookmarkNode* parent = model->other_node(); |
| 366 new_folder = model->AddFolder(parent, 0, ASCIIToUTF16("folder")); | 366 new_folder = model->AddFolder(parent, 0, ASCIIToUTF16("folder")); |
| 367 model->AddURL(new_folder, 0, ASCIIToUTF16("bar"), GURL("http://www.bar.com")); | 367 model->AddURL(new_folder, 0, ASCIIToUTF16("bar"), GURL("http://www.bar.com")); |
| 368 | 368 |
| 369 model->Remove(parent, 0); | 369 model->Remove(parent, parent->GetChild(0)); |
| 370 | 370 |
| 371 // Test that the undo restores the bookmark and folder. | 371 // Test that the undo restores the bookmark and folder. |
| 372 undo_service->undo_manager()->Undo(); | 372 undo_service->undo_manager()->Undo(); |
| 373 | 373 |
| 374 ASSERT_EQ(1, model->other_node()->child_count()); | 374 ASSERT_EQ(1, model->other_node()->child_count()); |
| 375 new_folder = model->other_node()->GetChild(0); | 375 new_folder = model->other_node()->GetChild(0); |
| 376 EXPECT_EQ(1, new_folder->child_count()); | 376 EXPECT_EQ(1, new_folder->child_count()); |
| 377 const BookmarkNode* node = new_folder->GetChild(0); | 377 const BookmarkNode* node = new_folder->GetChild(0); |
| 378 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("bar")); | 378 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("bar")); |
| 379 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); | 379 EXPECT_EQ(node->url(), GURL("http://www.bar.com")); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 while (undo_service->undo_manager()->undo_count()) | 412 while (undo_service->undo_manager()->undo_count()) |
| 413 undo_service->undo_manager()->Undo(); | 413 undo_service->undo_manager()->Undo(); |
| 414 | 414 |
| 415 EXPECT_EQ(1, parent->child_count()); | 415 EXPECT_EQ(1, parent->child_count()); |
| 416 const BookmarkNode* node = model->other_node()->GetChild(0); | 416 const BookmarkNode* node = model->other_node()->GetChild(0); |
| 417 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); | 417 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); |
| 418 EXPECT_EQ(node->url(), GURL("http://www.foo.com")); | 418 EXPECT_EQ(node->url(), GURL("http://www.foo.com")); |
| 419 } | 419 } |
| 420 | 420 |
| 421 } // namespace | 421 } // namespace |
| OLD | NEW |