OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/string_split.h" | 17 #include "base/string_split.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "chrome/browser/bookmarks/bookmark_model.h" | 20 #include "chrome/browser/bookmarks/bookmark_model.h" |
21 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 21 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
22 #include "chrome/browser/bookmarks/bookmark_utils.h" | 22 #include "chrome/browser/bookmarks/bookmark_utils.h" |
23 #include "chrome/browser/history/history_notifications.h" | 23 #include "chrome/browser/history/history_notifications.h" |
24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/test/base/model_test_utils.h" | 28 #include "chrome/test/base/model_test_utils.h" |
29 #include "chrome/test/base/testing_browser_process_test.h" | |
30 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
31 #include "content/browser/browser_thread.h" | 30 #include "content/browser/browser_thread.h" |
32 #include "content/common/notification_details.h" | 31 #include "content/common/notification_details.h" |
33 #include "content/common/notification_registrar.h" | 32 #include "content/common/notification_registrar.h" |
34 #include "content/common/notification_source.h" | 33 #include "content/common/notification_source.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "ui/base/models/tree_node_iterator.h" | 35 #include "ui/base/models/tree_node_iterator.h" |
37 #include "ui/base/models/tree_node_model.h" | 36 #include "ui/base/models/tree_node_model.h" |
38 | 37 |
39 using base::Time; | 38 using base::Time; |
40 using base::TimeDelta; | 39 using base::TimeDelta; |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
44 // Helper to get a mutable bookmark node. | 43 // Helper to get a mutable bookmark node. |
45 BookmarkNode* AsMutable(const BookmarkNode* node) { | 44 BookmarkNode* AsMutable(const BookmarkNode* node) { |
46 return const_cast<BookmarkNode*>(node); | 45 return const_cast<BookmarkNode*>(node); |
47 } | 46 } |
48 | 47 |
49 void SwapDateAdded(BookmarkNode* n1, BookmarkNode* n2) { | 48 void SwapDateAdded(BookmarkNode* n1, BookmarkNode* n2) { |
50 Time tmp = n1->date_added(); | 49 Time tmp = n1->date_added(); |
51 n1->set_date_added(n2->date_added()); | 50 n1->set_date_added(n2->date_added()); |
52 n2->set_date_added(tmp); | 51 n2->set_date_added(tmp); |
53 } | 52 } |
54 | 53 |
55 class BookmarkModelTest : public TestingBrowserProcessTest, | 54 class BookmarkModelTest : public testing::Test, |
56 public BookmarkModelObserver { | 55 public BookmarkModelObserver { |
57 public: | 56 public: |
58 struct ObserverDetails { | 57 struct ObserverDetails { |
59 ObserverDetails() { | 58 ObserverDetails() { |
60 Set(NULL, NULL, -1, -1); | 59 Set(NULL, NULL, -1, -1); |
61 } | 60 } |
62 | 61 |
63 void Set(const BookmarkNode* node1, | 62 void Set(const BookmarkNode* node1, |
64 const BookmarkNode* node2, | 63 const BookmarkNode* node2, |
65 int index1, | 64 int index1, |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 model->AddFolder(bb_node, i, child->GetTitle()); | 686 model->AddFolder(bb_node, i, child->GetTitle()); |
688 PopulateBookmarkNode(child, model, new_bb_node); | 687 PopulateBookmarkNode(child, model, new_bb_node); |
689 } else { | 688 } else { |
690 model->AddURL(bb_node, i, child->GetTitle(), | 689 model->AddURL(bb_node, i, child->GetTitle(), |
691 GURL("http://" + UTF16ToASCII(child->GetTitle()))); | 690 GURL("http://" + UTF16ToASCII(child->GetTitle()))); |
692 } | 691 } |
693 } | 692 } |
694 } | 693 } |
695 | 694 |
696 // Test class that creates a BookmarkModel with a real history backend. | 695 // Test class that creates a BookmarkModel with a real history backend. |
697 class BookmarkModelTestWithProfile : public TestingBrowserProcessTest { | 696 class BookmarkModelTestWithProfile : public testing::Test { |
698 public: | 697 public: |
699 BookmarkModelTestWithProfile() | 698 BookmarkModelTestWithProfile() |
700 : ui_thread_(BrowserThread::UI, &message_loop_), | 699 : ui_thread_(BrowserThread::UI, &message_loop_), |
701 file_thread_(BrowserThread::FILE, &message_loop_) {} | 700 file_thread_(BrowserThread::FILE, &message_loop_) {} |
702 | 701 |
703 // TestingBrowserProcessTest: | 702 // testing::Test: |
704 virtual void TearDown() OVERRIDE { | 703 virtual void TearDown() OVERRIDE { |
705 profile_.reset(NULL); | 704 profile_.reset(NULL); |
706 } | 705 } |
707 | 706 |
708 protected: | 707 protected: |
709 // Verifies the contents of the bookmark bar node match the contents of the | 708 // Verifies the contents of the bookmark bar node match the contents of the |
710 // TestNode. | 709 // TestNode. |
711 void VerifyModelMatchesNode(TestNode* expected, const BookmarkNode* actual) { | 710 void VerifyModelMatchesNode(TestNode* expected, const BookmarkNode* actual) { |
712 ASSERT_EQ(expected->child_count(), actual->child_count()); | 711 ASSERT_EQ(expected->child_count(), actual->child_count()); |
713 for (int i = 0; i < expected->child_count(); ++i) { | 712 for (int i = 0; i < expected->child_count(); ++i) { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 TEST_F(BookmarkModelTest, SyncNodeVisibileWithChildren) { | 1035 TEST_F(BookmarkModelTest, SyncNodeVisibileWithChildren) { |
1037 const BookmarkNode* root = model_.synced_node(); | 1036 const BookmarkNode* root = model_.synced_node(); |
1038 const string16 title(ASCIIToUTF16("foo")); | 1037 const string16 title(ASCIIToUTF16("foo")); |
1039 const GURL url("http://foo.com"); | 1038 const GURL url("http://foo.com"); |
1040 | 1039 |
1041 model_.AddURL(root, 0, title, url); | 1040 model_.AddURL(root, 0, title, url); |
1042 EXPECT_TRUE(model_.synced_node()->IsVisible()); | 1041 EXPECT_TRUE(model_.synced_node()->IsVisible()); |
1043 } | 1042 } |
1044 | 1043 |
1045 } // namespace | 1044 } // namespace |
OLD | NEW |