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" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using base::ASCIIToUTF16; | 13 using base::ASCIIToUTF16; |
14 using bookmarks::BookmarkModel; | 14 using bookmarks::BookmarkModel; |
15 using bookmarks::BookmarkNode; | 15 using bookmarks::BookmarkNode; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class BookmarkUndoServiceTest : public testing::Test { | 19 class BookmarkUndoServiceTest : public testing::Test { |
20 public: | 20 public: |
21 BookmarkUndoServiceTest(); | 21 BookmarkUndoServiceTest(); |
22 | 22 |
23 void SetUp() override; | 23 void SetUp() override; |
24 void TearDown() override; | 24 void TearDown() override; |
25 | 25 |
26 BookmarkModel* GetModel(); | 26 BookmarkModel* GetModel(); |
27 BookmarkUndoService* GetUndoService(); | 27 BookmarkUndoService* GetUndoService(); |
28 | 28 |
29 private: | 29 private: |
30 scoped_ptr<bookmarks::TestBookmarkClient> test_bookmark_client_; | |
31 scoped_ptr<bookmarks::BookmarkModel> bookmark_model_; | 30 scoped_ptr<bookmarks::BookmarkModel> bookmark_model_; |
32 scoped_ptr<BookmarkUndoService> bookmark_undo_service_; | 31 scoped_ptr<BookmarkUndoService> bookmark_undo_service_; |
33 | 32 |
34 DISALLOW_COPY_AND_ASSIGN(BookmarkUndoServiceTest); | 33 DISALLOW_COPY_AND_ASSIGN(BookmarkUndoServiceTest); |
35 }; | 34 }; |
36 | 35 |
37 BookmarkUndoServiceTest::BookmarkUndoServiceTest() {} | 36 BookmarkUndoServiceTest::BookmarkUndoServiceTest() {} |
38 | 37 |
39 void BookmarkUndoServiceTest::SetUp() { | 38 void BookmarkUndoServiceTest::SetUp() { |
40 DCHECK(!test_bookmark_client_); | |
41 DCHECK(!bookmark_model_); | 39 DCHECK(!bookmark_model_); |
42 DCHECK(!bookmark_undo_service_); | 40 DCHECK(!bookmark_undo_service_); |
43 test_bookmark_client_.reset(new bookmarks::TestBookmarkClient); | 41 bookmark_model_ = bookmarks::TestBookmarkClient::CreateModel(); |
44 bookmark_model_ = test_bookmark_client_->CreateModel(); | |
45 bookmark_undo_service_.reset(new BookmarkUndoService); | 42 bookmark_undo_service_.reset(new BookmarkUndoService); |
46 bookmark_undo_service_->Start(bookmark_model_.get()); | 43 bookmark_undo_service_->Start(bookmark_model_.get()); |
47 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model_.get()); | 44 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model_.get()); |
48 } | 45 } |
49 | 46 |
50 BookmarkModel* BookmarkUndoServiceTest::GetModel() { | 47 BookmarkModel* BookmarkUndoServiceTest::GetModel() { |
51 return bookmark_model_.get(); | 48 return bookmark_model_.get(); |
52 } | 49 } |
53 | 50 |
54 BookmarkUndoService* BookmarkUndoServiceTest::GetUndoService() { | 51 BookmarkUndoService* BookmarkUndoServiceTest::GetUndoService() { |
55 return bookmark_undo_service_.get(); | 52 return bookmark_undo_service_.get(); |
56 } | 53 } |
57 | 54 |
58 void BookmarkUndoServiceTest::TearDown() { | 55 void BookmarkUndoServiceTest::TearDown() { |
59 // Implement two-phase KeyedService shutdown for test KeyedServices. | 56 // Implement two-phase KeyedService shutdown for test KeyedServices. |
60 bookmark_undo_service_->Shutdown(); | 57 bookmark_undo_service_->Shutdown(); |
61 bookmark_model_->Shutdown(); | 58 bookmark_model_->Shutdown(); |
62 test_bookmark_client_->Shutdown(); | |
63 bookmark_undo_service_.reset(); | 59 bookmark_undo_service_.reset(); |
64 bookmark_model_.reset(); | 60 bookmark_model_.reset(); |
65 test_bookmark_client_.reset(); | |
66 } | 61 } |
67 | 62 |
68 TEST_F(BookmarkUndoServiceTest, AddBookmark) { | 63 TEST_F(BookmarkUndoServiceTest, AddBookmark) { |
69 BookmarkModel* model = GetModel(); | 64 BookmarkModel* model = GetModel(); |
70 BookmarkUndoService* undo_service = GetUndoService(); | 65 BookmarkUndoService* undo_service = GetUndoService(); |
71 | 66 |
72 const BookmarkNode* parent = model->other_node(); | 67 const BookmarkNode* parent = model->other_node(); |
73 model->AddURL(parent, 0, ASCIIToUTF16("foo"), GURL("http://www.bar.com")); | 68 model->AddURL(parent, 0, ASCIIToUTF16("foo"), GURL("http://www.bar.com")); |
74 | 69 |
75 // Undo bookmark creation and test for no bookmarks. | 70 // Undo bookmark creation and test for no bookmarks. |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 while (undo_service->undo_manager()->undo_count()) | 407 while (undo_service->undo_manager()->undo_count()) |
413 undo_service->undo_manager()->Undo(); | 408 undo_service->undo_manager()->Undo(); |
414 | 409 |
415 EXPECT_EQ(1, parent->child_count()); | 410 EXPECT_EQ(1, parent->child_count()); |
416 const BookmarkNode* node = model->other_node()->GetChild(0); | 411 const BookmarkNode* node = model->other_node()->GetChild(0); |
417 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); | 412 EXPECT_EQ(node->GetTitle(), ASCIIToUTF16("foo")); |
418 EXPECT_EQ(node->url(), GURL("http://www.foo.com")); | 413 EXPECT_EQ(node->url(), GURL("http://www.foo.com")); |
419 } | 414 } |
420 | 415 |
421 } // namespace | 416 } // namespace |
OLD | NEW |