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 "app/os_exchange_data.h" | 5 #include "app/os_exchange_data.h" |
6 #include "app/os_exchange_data_provider_win.h" | 6 #include "app/os_exchange_data_provider_win.h" |
| 7 #include "base/message_loop.h" |
7 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
8 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 9 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 #include "chrome/browser/chrome_thread.h" |
10 #include "chrome/test/testing_profile.h" | 12 #include "chrome/test/testing_profile.h" |
11 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 typedef testing::Test BookmarkDragDataTest; | 16 class BookmarkDragDataTest : public testing::Test { |
| 17 public: |
| 18 BookmarkDragDataTest() |
| 19 : ui_thread_(ChromeThread::UI, &loop_), |
| 20 file_thread_(ChromeThread::FILE, &loop_) { } |
| 21 |
| 22 private: |
| 23 MessageLoop loop_; |
| 24 ChromeThread ui_thread_; |
| 25 ChromeThread file_thread_; |
| 26 }; |
15 | 27 |
16 namespace { | 28 namespace { |
17 | 29 |
18 OSExchangeData::Provider* CloneProvider(const OSExchangeData& data) { | 30 OSExchangeData::Provider* CloneProvider(const OSExchangeData& data) { |
19 return new OSExchangeDataProviderWin( | 31 return new OSExchangeDataProviderWin( |
20 OSExchangeDataProviderWin::GetIDataObject(data)); | 32 OSExchangeDataProviderWin::GetIDataObject(data)); |
21 } | 33 } |
22 | 34 |
23 } // namespace | 35 } // namespace |
24 | 36 |
(...skipping 27 matching lines...) Expand all Loading... |
52 EXPECT_TRUE(drag_data.elements[0].is_url); | 64 EXPECT_TRUE(drag_data.elements[0].is_url); |
53 EXPECT_TRUE(drag_data.elements[0].url == url); | 65 EXPECT_TRUE(drag_data.elements[0].url == url); |
54 EXPECT_TRUE(drag_data.elements[0].title == title); | 66 EXPECT_TRUE(drag_data.elements[0].title == title); |
55 EXPECT_EQ(0, drag_data.elements[0].children.size()); | 67 EXPECT_EQ(0, drag_data.elements[0].children.size()); |
56 } | 68 } |
57 | 69 |
58 TEST_F(BookmarkDragDataTest, URL) { | 70 TEST_F(BookmarkDragDataTest, URL) { |
59 // Write a single node representing a URL to the clipboard. | 71 // Write a single node representing a URL to the clipboard. |
60 TestingProfile profile; | 72 TestingProfile profile; |
61 profile.CreateBookmarkModel(false); | 73 profile.CreateBookmarkModel(false); |
| 74 profile.BlockUntilBookmarkModelLoaded(); |
62 profile.SetID(L"id"); | 75 profile.SetID(L"id"); |
63 BookmarkModel* model = profile.GetBookmarkModel(); | 76 BookmarkModel* model = profile.GetBookmarkModel(); |
64 const BookmarkNode* root = model->GetBookmarkBarNode(); | 77 const BookmarkNode* root = model->GetBookmarkBarNode(); |
65 GURL url(GURL("http://foo.com")); | 78 GURL url(GURL("http://foo.com")); |
66 const std::wstring title(L"blah"); | 79 const std::wstring title(L"blah"); |
67 const BookmarkNode* node = model->AddURL(root, 0, title, url); | 80 const BookmarkNode* node = model->AddURL(root, 0, title, url); |
68 BookmarkDragData drag_data(node); | 81 BookmarkDragData drag_data(node); |
69 EXPECT_TRUE(drag_data.is_valid()); | 82 EXPECT_TRUE(drag_data.is_valid()); |
70 ASSERT_EQ(1, drag_data.elements.size()); | 83 ASSERT_EQ(1, drag_data.elements.size()); |
71 EXPECT_TRUE(drag_data.elements[0].is_url); | 84 EXPECT_TRUE(drag_data.elements[0].is_url); |
(...skipping 22 matching lines...) Expand all Loading... |
94 std::wstring read_title; | 107 std::wstring read_title; |
95 EXPECT_TRUE(data2.GetURLAndTitle(&read_url, &read_title)); | 108 EXPECT_TRUE(data2.GetURLAndTitle(&read_url, &read_title)); |
96 EXPECT_TRUE(read_url == url); | 109 EXPECT_TRUE(read_url == url); |
97 EXPECT_EQ(title, read_title); | 110 EXPECT_EQ(title, read_title); |
98 } | 111 } |
99 | 112 |
100 // Tests writing a group to the clipboard. | 113 // Tests writing a group to the clipboard. |
101 TEST_F(BookmarkDragDataTest, Group) { | 114 TEST_F(BookmarkDragDataTest, Group) { |
102 TestingProfile profile; | 115 TestingProfile profile; |
103 profile.CreateBookmarkModel(false); | 116 profile.CreateBookmarkModel(false); |
| 117 profile.BlockUntilBookmarkModelLoaded(); |
104 profile.SetID(L"id"); | 118 profile.SetID(L"id"); |
105 BookmarkModel* model = profile.GetBookmarkModel(); | 119 BookmarkModel* model = profile.GetBookmarkModel(); |
106 const BookmarkNode* root = model->GetBookmarkBarNode(); | 120 const BookmarkNode* root = model->GetBookmarkBarNode(); |
107 const BookmarkNode* g1 = model->AddGroup(root, 0, L"g1"); | 121 const BookmarkNode* g1 = model->AddGroup(root, 0, L"g1"); |
108 const BookmarkNode* g11 = model->AddGroup(g1, 0, L"g11"); | 122 const BookmarkNode* g11 = model->AddGroup(g1, 0, L"g11"); |
109 const BookmarkNode* g12 = model->AddGroup(g1, 0, L"g12"); | 123 const BookmarkNode* g12 = model->AddGroup(g1, 0, L"g12"); |
110 | 124 |
111 BookmarkDragData drag_data(g12); | 125 BookmarkDragData drag_data(g12); |
112 EXPECT_TRUE(drag_data.is_valid()); | 126 EXPECT_TRUE(drag_data.is_valid()); |
113 ASSERT_EQ(1, drag_data.elements.size()); | 127 ASSERT_EQ(1, drag_data.elements.size()); |
(...skipping 19 matching lines...) Expand all Loading... |
133 // A different profile should return NULL for the node. | 147 // A different profile should return NULL for the node. |
134 TestingProfile profile2(1); | 148 TestingProfile profile2(1); |
135 EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL); | 149 EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL); |
136 } | 150 } |
137 | 151 |
138 // Tests reading/writing a folder with children. | 152 // Tests reading/writing a folder with children. |
139 TEST_F(BookmarkDragDataTest, GroupWithChild) { | 153 TEST_F(BookmarkDragDataTest, GroupWithChild) { |
140 TestingProfile profile; | 154 TestingProfile profile; |
141 profile.SetID(L"id"); | 155 profile.SetID(L"id"); |
142 profile.CreateBookmarkModel(false); | 156 profile.CreateBookmarkModel(false); |
| 157 profile.BlockUntilBookmarkModelLoaded(); |
143 BookmarkModel* model = profile.GetBookmarkModel(); | 158 BookmarkModel* model = profile.GetBookmarkModel(); |
144 const BookmarkNode* root = model->GetBookmarkBarNode(); | 159 const BookmarkNode* root = model->GetBookmarkBarNode(); |
145 const BookmarkNode* group = model->AddGroup(root, 0, L"g1"); | 160 const BookmarkNode* group = model->AddGroup(root, 0, L"g1"); |
146 | 161 |
147 GURL url(GURL("http://foo.com")); | 162 GURL url(GURL("http://foo.com")); |
148 const std::wstring title(L"blah2"); | 163 const std::wstring title(L"blah2"); |
149 | 164 |
150 model->AddURL(group, 0, title, url); | 165 model->AddURL(group, 0, title, url); |
151 | 166 |
152 BookmarkDragData drag_data(group); | 167 BookmarkDragData drag_data(group); |
(...skipping 18 matching lines...) Expand all Loading... |
171 // And make sure we get the node back. | 186 // And make sure we get the node back. |
172 const BookmarkNode* r_group = read_data.GetFirstNode(&profile); | 187 const BookmarkNode* r_group = read_data.GetFirstNode(&profile); |
173 EXPECT_TRUE(group == r_group); | 188 EXPECT_TRUE(group == r_group); |
174 } | 189 } |
175 | 190 |
176 // Tests reading/writing of multiple nodes. | 191 // Tests reading/writing of multiple nodes. |
177 TEST_F(BookmarkDragDataTest, MultipleNodes) { | 192 TEST_F(BookmarkDragDataTest, MultipleNodes) { |
178 TestingProfile profile; | 193 TestingProfile profile; |
179 profile.SetID(L"id"); | 194 profile.SetID(L"id"); |
180 profile.CreateBookmarkModel(false); | 195 profile.CreateBookmarkModel(false); |
| 196 profile.BlockUntilBookmarkModelLoaded(); |
181 BookmarkModel* model = profile.GetBookmarkModel(); | 197 BookmarkModel* model = profile.GetBookmarkModel(); |
182 const BookmarkNode* root = model->GetBookmarkBarNode(); | 198 const BookmarkNode* root = model->GetBookmarkBarNode(); |
183 const BookmarkNode* group = model->AddGroup(root, 0, L"g1"); | 199 const BookmarkNode* group = model->AddGroup(root, 0, L"g1"); |
184 | 200 |
185 GURL url(GURL("http://foo.com")); | 201 GURL url(GURL("http://foo.com")); |
186 const std::wstring title(L"blah2"); | 202 const std::wstring title(L"blah2"); |
187 | 203 |
188 const BookmarkNode* url_node = model->AddURL(group, 0, title, url); | 204 const BookmarkNode* url_node = model->AddURL(group, 0, title, url); |
189 | 205 |
190 // Write the nodes to the clipboard. | 206 // Write the nodes to the clipboard. |
(...skipping 25 matching lines...) Expand all Loading... |
216 // And make sure we get the node back. | 232 // And make sure we get the node back. |
217 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile); | 233 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile); |
218 ASSERT_EQ(2, read_nodes.size()); | 234 ASSERT_EQ(2, read_nodes.size()); |
219 EXPECT_TRUE(read_nodes[0] == group); | 235 EXPECT_TRUE(read_nodes[0] == group); |
220 EXPECT_TRUE(read_nodes[1] == url_node); | 236 EXPECT_TRUE(read_nodes[1] == url_node); |
221 | 237 |
222 // Asking for the first node should return NULL with more than one element | 238 // Asking for the first node should return NULL with more than one element |
223 // present. | 239 // present. |
224 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); | 240 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); |
225 } | 241 } |
OLD | NEW |