OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/message_loop.h" |
5 #include "base/string_util.h" | 6 #include "base/string_util.h" |
6 #include "chrome/browser/bookmarks/bookmark_folder_tree_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_folder_tree_model.h" |
| 8 #include "chrome/browser/chrome_thread.h" |
7 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
8 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "views/controls/tree/tree_view.h" | 12 #include "views/controls/tree/tree_view.h" |
11 | 13 |
12 // Base class for bookmark model tests. | 14 // Base class for bookmark model tests. |
13 // Initial state of the bookmark model is as follows: | 15 // Initial state of the bookmark model is as follows: |
14 // bb | 16 // bb |
15 // url1 | 17 // url1 |
16 // f1 | 18 // f1 |
17 // f11 | 19 // f11 |
18 // o | 20 // o |
19 // url2 | 21 // url2 |
20 // f2 | 22 // f2 |
21 // url3 | 23 // url3 |
22 // a1 | 24 // a1 |
23 // g1 | 25 // g1 |
24 class BookmarkFolderTreeModelTest : public testing::Test, | 26 class BookmarkFolderTreeModelTest : public testing::Test, |
25 public TreeModelObserver { | 27 public TreeModelObserver { |
26 public: | 28 public: |
27 BookmarkFolderTreeModelTest() | 29 BookmarkFolderTreeModelTest() |
28 : url1_("http://1"), | 30 : url1_("http://1"), |
29 url2_("http://2"), | 31 url2_("http://2"), |
30 url3_("http://3"), | 32 url3_("http://3"), |
31 added_count_(0), | 33 added_count_(0), |
32 removed_count_(0), | 34 removed_count_(0), |
33 changed_count_(0), | 35 changed_count_(0), |
34 reordered_count_(0) { | 36 reordered_count_(0), |
| 37 ui_thread_(ChromeThread::UI, &loop_), |
| 38 file_thread_(ChromeThread::FILE, &loop_) { |
35 } | 39 } |
36 | 40 |
37 virtual void SetUp() { | 41 virtual void SetUp() { |
38 profile_.reset(new TestingProfile()); | 42 profile_.reset(new TestingProfile()); |
39 profile_->CreateBookmarkModel(true); | 43 profile_->CreateBookmarkModel(true); |
| 44 profile_->BlockUntilBookmarkModelLoaded(); |
40 // Populate with some default data. | 45 // Populate with some default data. |
41 const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode(); | 46 const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode(); |
42 bookmark_model()->AddURL(bb, 0, L"url1", url1_); | 47 bookmark_model()->AddURL(bb, 0, L"url1", url1_); |
43 const BookmarkNode* f1 = bookmark_model()->AddGroup(bb, 1, L"f1"); | 48 const BookmarkNode* f1 = bookmark_model()->AddGroup(bb, 1, L"f1"); |
44 bookmark_model()->AddGroup(f1, 0, L"f11"); | 49 bookmark_model()->AddGroup(f1, 0, L"f11"); |
45 | 50 |
46 const BookmarkNode* other = bookmark_model()->other_node(); | 51 const BookmarkNode* other = bookmark_model()->other_node(); |
47 bookmark_model()->AddURL(other, 0, L"url2", url2_); | 52 bookmark_model()->AddURL(other, 0, L"url2", url2_); |
48 bookmark_model()->AddGroup(other, 1, L"f2"); | 53 bookmark_model()->AddGroup(other, 1, L"f2"); |
49 bookmark_model()->AddURL(other, 2, L"url3", url3_); | 54 bookmark_model()->AddURL(other, 2, L"url3", url3_); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const GURL url1_; | 110 const GURL url1_; |
106 const GURL url2_; | 111 const GURL url2_; |
107 const GURL url3_; | 112 const GURL url3_; |
108 | 113 |
109 private: | 114 private: |
110 int changed_count_; | 115 int changed_count_; |
111 int added_count_; | 116 int added_count_; |
112 int removed_count_; | 117 int removed_count_; |
113 int reordered_count_; | 118 int reordered_count_; |
114 scoped_ptr<TestingProfile> profile_; | 119 scoped_ptr<TestingProfile> profile_; |
| 120 MessageLoop loop_; |
| 121 ChromeThread ui_thread_; |
| 122 ChromeThread file_thread_; |
115 }; | 123 }; |
116 | 124 |
117 // Verifies the root node has 4 nodes, and the contents of the bookmark bar | 125 // Verifies the root node has 4 nodes, and the contents of the bookmark bar |
118 // and other folders matches the initial state. | 126 // and other folders matches the initial state. |
119 TEST_F(BookmarkFolderTreeModelTest, InitialState) { | 127 TEST_F(BookmarkFolderTreeModelTest, InitialState) { |
120 // Verify the first 4 nodes. | 128 // Verify the first 4 nodes. |
121 TreeModelNode* root = model_->GetRoot(); | 129 TreeModelNode* root = model_->GetRoot(); |
122 ASSERT_EQ(4, model_->GetChildCount(root)); | 130 ASSERT_EQ(4, model_->GetChildCount(root)); |
123 EXPECT_EQ(BookmarkFolderTreeModel::BOOKMARK, | 131 EXPECT_EQ(BookmarkFolderTreeModel::BOOKMARK, |
124 model_->GetNodeType(model_->GetChild(root, 0))); | 132 model_->GetNodeType(model_->GetChild(root, 0))); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 VerifyAndClearObserverCounts(0, 0, 0, 1); | 217 VerifyAndClearObserverCounts(0, 0, 0, 1); |
210 | 218 |
211 // Make sure the resulting order matches. | 219 // Make sure the resulting order matches. |
212 FolderNode* other_folder_node = | 220 FolderNode* other_folder_node = |
213 model_->GetFolderNodeForBookmarkNode(bookmark_model()->other_node()); | 221 model_->GetFolderNodeForBookmarkNode(bookmark_model()->other_node()); |
214 ASSERT_EQ(3, other_folder_node->GetChildCount()); | 222 ASSERT_EQ(3, other_folder_node->GetChildCount()); |
215 EXPECT_TRUE(other_folder_node->GetChild(0)->GetTitle() == L"a1"); | 223 EXPECT_TRUE(other_folder_node->GetChild(0)->GetTitle() == L"a1"); |
216 EXPECT_TRUE(other_folder_node->GetChild(1)->GetTitle() == L"f2"); | 224 EXPECT_TRUE(other_folder_node->GetChild(1)->GetTitle() == L"f2"); |
217 EXPECT_TRUE(other_folder_node->GetChild(2)->GetTitle() == L"g1"); | 225 EXPECT_TRUE(other_folder_node->GetChild(2)->GetTitle() == L"g1"); |
218 } | 226 } |
OLD | NEW |