OLD | NEW |
1 // Copyright (c) 2010 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 "app/os_exchange_data.h" | |
6 #include "app/os_exchange_data_provider_win.h" | |
7 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
8 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
9 #include "base/string16.h" | 7 #include "base/string16.h" |
10 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 9 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
12 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
13 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
14 #include "chrome/test/testing_profile.h" | 12 #include "chrome/test/testing_profile.h" |
15 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/base/dragdrop/os_exchange_data.h" |
| 16 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
17 | 17 |
18 class BookmarkNodeDataTest : public testing::Test { | 18 class BookmarkNodeDataTest : public testing::Test { |
19 public: | 19 public: |
20 BookmarkNodeDataTest() | 20 BookmarkNodeDataTest() |
21 : ui_thread_(BrowserThread::UI, &loop_), | 21 : ui_thread_(BrowserThread::UI, &loop_), |
22 file_thread_(BrowserThread::FILE, &loop_) { } | 22 file_thread_(BrowserThread::FILE, &loop_) { } |
23 | 23 |
24 private: | 24 private: |
25 MessageLoop loop_; | 25 MessageLoop loop_; |
26 BrowserThread ui_thread_; | 26 BrowserThread ui_thread_; |
27 BrowserThread file_thread_; | 27 BrowserThread file_thread_; |
28 }; | 28 }; |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 OSExchangeData::Provider* CloneProvider(const OSExchangeData& data) { | 32 ui::OSExchangeData::Provider* CloneProvider(const ui::OSExchangeData& data) { |
33 return new OSExchangeDataProviderWin( | 33 return new ui::OSExchangeDataProviderWin( |
34 OSExchangeDataProviderWin::GetIDataObject(data)); | 34 ui::OSExchangeDataProviderWin::GetIDataObject(data)); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 // Makes sure BookmarkNodeData is initially invalid. | 39 // Makes sure BookmarkNodeData is initially invalid. |
40 TEST_F(BookmarkNodeDataTest, InitialState) { | 40 TEST_F(BookmarkNodeDataTest, InitialState) { |
41 BookmarkNodeData data; | 41 BookmarkNodeData data; |
42 EXPECT_FALSE(data.is_valid()); | 42 EXPECT_FALSE(data.is_valid()); |
43 } | 43 } |
44 | 44 |
45 // Makes sure reading bogus data leaves the BookmarkNodeData invalid. | 45 // Makes sure reading bogus data leaves the BookmarkNodeData invalid. |
46 TEST_F(BookmarkNodeDataTest, BogusRead) { | 46 TEST_F(BookmarkNodeDataTest, BogusRead) { |
47 OSExchangeData data; | 47 ui::OSExchangeData data; |
48 BookmarkNodeData drag_data; | 48 BookmarkNodeData drag_data; |
49 EXPECT_FALSE(drag_data.Read(OSExchangeData(CloneProvider(data)))); | 49 EXPECT_FALSE(drag_data.Read(ui::OSExchangeData(CloneProvider(data)))); |
50 EXPECT_FALSE(drag_data.is_valid()); | 50 EXPECT_FALSE(drag_data.is_valid()); |
51 } | 51 } |
52 | 52 |
53 // Writes a URL to the clipboard and make sure BookmarkNodeData can correctly | 53 // Writes a URL to the clipboard and make sure BookmarkNodeData can correctly |
54 // read it. | 54 // read it. |
55 TEST_F(BookmarkNodeDataTest, JustURL) { | 55 TEST_F(BookmarkNodeDataTest, JustURL) { |
56 const GURL url("http://google.com"); | 56 const GURL url("http://google.com"); |
57 const std::wstring title(L"title"); | 57 const std::wstring title(L"title"); |
58 | 58 |
59 OSExchangeData data; | 59 ui::OSExchangeData data; |
60 data.SetURL(url, title); | 60 data.SetURL(url, title); |
61 | 61 |
62 BookmarkNodeData drag_data; | 62 BookmarkNodeData drag_data; |
63 EXPECT_TRUE(drag_data.Read(OSExchangeData(CloneProvider(data)))); | 63 EXPECT_TRUE(drag_data.Read(ui::OSExchangeData(CloneProvider(data)))); |
64 EXPECT_TRUE(drag_data.is_valid()); | 64 EXPECT_TRUE(drag_data.is_valid()); |
65 ASSERT_EQ(1, drag_data.elements.size()); | 65 ASSERT_EQ(1, drag_data.elements.size()); |
66 EXPECT_TRUE(drag_data.elements[0].is_url); | 66 EXPECT_TRUE(drag_data.elements[0].is_url); |
67 EXPECT_EQ(url, drag_data.elements[0].url); | 67 EXPECT_EQ(url, drag_data.elements[0].url); |
68 EXPECT_EQ(title, drag_data.elements[0].title); | 68 EXPECT_EQ(title, drag_data.elements[0].title); |
69 EXPECT_EQ(0, drag_data.elements[0].children.size()); | 69 EXPECT_EQ(0, drag_data.elements[0].children.size()); |
70 } | 70 } |
71 | 71 |
72 TEST_F(BookmarkNodeDataTest, URL) { | 72 TEST_F(BookmarkNodeDataTest, URL) { |
73 // Write a single node representing a URL to the clipboard. | 73 // Write a single node representing a URL to the clipboard. |
74 TestingProfile profile; | 74 TestingProfile profile; |
75 profile.CreateBookmarkModel(false); | 75 profile.CreateBookmarkModel(false); |
76 profile.BlockUntilBookmarkModelLoaded(); | 76 profile.BlockUntilBookmarkModelLoaded(); |
77 profile.SetID(L"id"); | 77 profile.SetID(L"id"); |
78 BookmarkModel* model = profile.GetBookmarkModel(); | 78 BookmarkModel* model = profile.GetBookmarkModel(); |
79 const BookmarkNode* root = model->GetBookmarkBarNode(); | 79 const BookmarkNode* root = model->GetBookmarkBarNode(); |
80 GURL url(GURL("http://foo.com")); | 80 GURL url(GURL("http://foo.com")); |
81 const string16 title(ASCIIToUTF16("blah")); | 81 const string16 title(ASCIIToUTF16("blah")); |
82 const BookmarkNode* node = model->AddURL(root, 0, title, url); | 82 const BookmarkNode* node = model->AddURL(root, 0, title, url); |
83 BookmarkNodeData drag_data(node); | 83 BookmarkNodeData drag_data(node); |
84 EXPECT_TRUE(drag_data.is_valid()); | 84 EXPECT_TRUE(drag_data.is_valid()); |
85 ASSERT_EQ(1, drag_data.elements.size()); | 85 ASSERT_EQ(1, drag_data.elements.size()); |
86 EXPECT_TRUE(drag_data.elements[0].is_url); | 86 EXPECT_TRUE(drag_data.elements[0].is_url); |
87 EXPECT_EQ(url, drag_data.elements[0].url); | 87 EXPECT_EQ(url, drag_data.elements[0].url); |
88 EXPECT_EQ(title, WideToUTF16Hack(drag_data.elements[0].title)); | 88 EXPECT_EQ(title, WideToUTF16Hack(drag_data.elements[0].title)); |
89 OSExchangeData data; | 89 ui::OSExchangeData data; |
90 drag_data.Write(&profile, &data); | 90 drag_data.Write(&profile, &data); |
91 | 91 |
92 // Now read the data back in. | 92 // Now read the data back in. |
93 OSExchangeData data2(CloneProvider(data)); | 93 ui::OSExchangeData data2(CloneProvider(data)); |
94 BookmarkNodeData read_data; | 94 BookmarkNodeData read_data; |
95 EXPECT_TRUE(read_data.Read(data2)); | 95 EXPECT_TRUE(read_data.Read(data2)); |
96 EXPECT_TRUE(read_data.is_valid()); | 96 EXPECT_TRUE(read_data.is_valid()); |
97 ASSERT_EQ(1, read_data.elements.size()); | 97 ASSERT_EQ(1, read_data.elements.size()); |
98 EXPECT_TRUE(read_data.elements[0].is_url); | 98 EXPECT_TRUE(read_data.elements[0].is_url); |
99 EXPECT_EQ(url, read_data.elements[0].url); | 99 EXPECT_EQ(url, read_data.elements[0].url); |
100 EXPECT_EQ(title, read_data.elements[0].title); | 100 EXPECT_EQ(title, read_data.elements[0].title); |
101 EXPECT_TRUE(read_data.GetFirstNode(&profile) == node); | 101 EXPECT_TRUE(read_data.GetFirstNode(&profile) == node); |
102 | 102 |
103 // Make sure asking for the node with a different profile returns NULL. | 103 // Make sure asking for the node with a different profile returns NULL. |
(...skipping 19 matching lines...) Expand all Loading... |
123 const BookmarkNode* g1 = model->AddGroup(root, 0, ASCIIToUTF16("g1")); | 123 const BookmarkNode* g1 = model->AddGroup(root, 0, ASCIIToUTF16("g1")); |
124 const BookmarkNode* g11 = model->AddGroup(g1, 0, ASCIIToUTF16("g11")); | 124 const BookmarkNode* g11 = model->AddGroup(g1, 0, ASCIIToUTF16("g11")); |
125 const BookmarkNode* g12 = model->AddGroup(g1, 0, ASCIIToUTF16("g12")); | 125 const BookmarkNode* g12 = model->AddGroup(g1, 0, ASCIIToUTF16("g12")); |
126 | 126 |
127 BookmarkNodeData drag_data(g12); | 127 BookmarkNodeData drag_data(g12); |
128 EXPECT_TRUE(drag_data.is_valid()); | 128 EXPECT_TRUE(drag_data.is_valid()); |
129 ASSERT_EQ(1, drag_data.elements.size()); | 129 ASSERT_EQ(1, drag_data.elements.size()); |
130 EXPECT_EQ(g12->GetTitle(), WideToUTF16Hack(drag_data.elements[0].title)); | 130 EXPECT_EQ(g12->GetTitle(), WideToUTF16Hack(drag_data.elements[0].title)); |
131 EXPECT_FALSE(drag_data.elements[0].is_url); | 131 EXPECT_FALSE(drag_data.elements[0].is_url); |
132 | 132 |
133 OSExchangeData data; | 133 ui::OSExchangeData data; |
134 drag_data.Write(&profile, &data); | 134 drag_data.Write(&profile, &data); |
135 | 135 |
136 // Now read the data back in. | 136 // Now read the data back in. |
137 OSExchangeData data2(CloneProvider(data)); | 137 ui::OSExchangeData data2(CloneProvider(data)); |
138 BookmarkNodeData read_data; | 138 BookmarkNodeData read_data; |
139 EXPECT_TRUE(read_data.Read(data2)); | 139 EXPECT_TRUE(read_data.Read(data2)); |
140 EXPECT_TRUE(read_data.is_valid()); | 140 EXPECT_TRUE(read_data.is_valid()); |
141 ASSERT_EQ(1, read_data.elements.size()); | 141 ASSERT_EQ(1, read_data.elements.size()); |
142 EXPECT_EQ(g12->GetTitle(), WideToUTF16Hack(read_data.elements[0].title)); | 142 EXPECT_EQ(g12->GetTitle(), WideToUTF16Hack(read_data.elements[0].title)); |
143 EXPECT_FALSE(read_data.elements[0].is_url); | 143 EXPECT_FALSE(read_data.elements[0].is_url); |
144 | 144 |
145 // We should get back the same node when asking for the same profile. | 145 // We should get back the same node when asking for the same profile. |
146 const BookmarkNode* r_g12 = read_data.GetFirstNode(&profile); | 146 const BookmarkNode* r_g12 = read_data.GetFirstNode(&profile); |
147 EXPECT_TRUE(g12 == r_g12); | 147 EXPECT_TRUE(g12 == r_g12); |
(...skipping 13 matching lines...) Expand all Loading... |
161 const BookmarkNode* root = model->GetBookmarkBarNode(); | 161 const BookmarkNode* root = model->GetBookmarkBarNode(); |
162 const BookmarkNode* group = model->AddGroup(root, 0, ASCIIToUTF16("g1")); | 162 const BookmarkNode* group = model->AddGroup(root, 0, ASCIIToUTF16("g1")); |
163 | 163 |
164 GURL url(GURL("http://foo.com")); | 164 GURL url(GURL("http://foo.com")); |
165 const string16 title(ASCIIToUTF16("blah2")); | 165 const string16 title(ASCIIToUTF16("blah2")); |
166 | 166 |
167 model->AddURL(group, 0, title, url); | 167 model->AddURL(group, 0, title, url); |
168 | 168 |
169 BookmarkNodeData drag_data(group); | 169 BookmarkNodeData drag_data(group); |
170 | 170 |
171 OSExchangeData data; | 171 ui::OSExchangeData data; |
172 drag_data.Write(&profile, &data); | 172 drag_data.Write(&profile, &data); |
173 | 173 |
174 // Now read the data back in. | 174 // Now read the data back in. |
175 OSExchangeData data2(CloneProvider(data)); | 175 ui::OSExchangeData data2(CloneProvider(data)); |
176 BookmarkNodeData read_data; | 176 BookmarkNodeData read_data; |
177 EXPECT_TRUE(read_data.Read(data2)); | 177 EXPECT_TRUE(read_data.Read(data2)); |
178 ASSERT_EQ(1, read_data.elements.size()); | 178 ASSERT_EQ(1, read_data.elements.size()); |
179 ASSERT_EQ(1, read_data.elements[0].children.size()); | 179 ASSERT_EQ(1, read_data.elements[0].children.size()); |
180 const BookmarkNodeData::Element& read_child = | 180 const BookmarkNodeData::Element& read_child = |
181 read_data.elements[0].children[0]; | 181 read_data.elements[0].children[0]; |
182 | 182 |
183 EXPECT_TRUE(read_child.is_url); | 183 EXPECT_TRUE(read_child.is_url); |
184 EXPECT_EQ(title, WideToUTF16Hack(read_child.title)); | 184 EXPECT_EQ(title, WideToUTF16Hack(read_child.title)); |
185 EXPECT_EQ(url, read_child.url); | 185 EXPECT_EQ(url, read_child.url); |
(...skipping 17 matching lines...) Expand all Loading... |
203 GURL url(GURL("http://foo.com")); | 203 GURL url(GURL("http://foo.com")); |
204 const string16 title(ASCIIToUTF16("blah2")); | 204 const string16 title(ASCIIToUTF16("blah2")); |
205 | 205 |
206 const BookmarkNode* url_node = model->AddURL(group, 0, title, url); | 206 const BookmarkNode* url_node = model->AddURL(group, 0, title, url); |
207 | 207 |
208 // Write the nodes to the clipboard. | 208 // Write the nodes to the clipboard. |
209 std::vector<const BookmarkNode*> nodes; | 209 std::vector<const BookmarkNode*> nodes; |
210 nodes.push_back(group); | 210 nodes.push_back(group); |
211 nodes.push_back(url_node); | 211 nodes.push_back(url_node); |
212 BookmarkNodeData drag_data(nodes); | 212 BookmarkNodeData drag_data(nodes); |
213 OSExchangeData data; | 213 ui::OSExchangeData data; |
214 drag_data.Write(&profile, &data); | 214 drag_data.Write(&profile, &data); |
215 | 215 |
216 // Read the data back in. | 216 // Read the data back in. |
217 OSExchangeData data2(CloneProvider(data)); | 217 ui::OSExchangeData data2(CloneProvider(data)); |
218 BookmarkNodeData read_data; | 218 BookmarkNodeData read_data; |
219 EXPECT_TRUE(read_data.Read(data2)); | 219 EXPECT_TRUE(read_data.Read(data2)); |
220 EXPECT_TRUE(read_data.is_valid()); | 220 EXPECT_TRUE(read_data.is_valid()); |
221 ASSERT_EQ(2, read_data.elements.size()); | 221 ASSERT_EQ(2, read_data.elements.size()); |
222 ASSERT_EQ(1, read_data.elements[0].children.size()); | 222 ASSERT_EQ(1, read_data.elements[0].children.size()); |
223 | 223 |
224 const BookmarkNodeData::Element& read_group = read_data.elements[0]; | 224 const BookmarkNodeData::Element& read_group = read_data.elements[0]; |
225 EXPECT_FALSE(read_group.is_url); | 225 EXPECT_FALSE(read_group.is_url); |
226 EXPECT_EQ(L"g1", read_group.title); | 226 EXPECT_EQ(L"g1", read_group.title); |
227 EXPECT_EQ(1, read_group.children.size()); | 227 EXPECT_EQ(1, read_group.children.size()); |
228 | 228 |
229 const BookmarkNodeData::Element& read_url = read_data.elements[1]; | 229 const BookmarkNodeData::Element& read_url = read_data.elements[1]; |
230 EXPECT_TRUE(read_url.is_url); | 230 EXPECT_TRUE(read_url.is_url); |
231 EXPECT_EQ(title, WideToUTF16Hack(read_url.title)); | 231 EXPECT_EQ(title, WideToUTF16Hack(read_url.title)); |
232 EXPECT_EQ(0, read_url.children.size()); | 232 EXPECT_EQ(0, read_url.children.size()); |
233 | 233 |
234 // And make sure we get the node back. | 234 // And make sure we get the node back. |
235 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile); | 235 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile); |
236 ASSERT_EQ(2, read_nodes.size()); | 236 ASSERT_EQ(2, read_nodes.size()); |
237 EXPECT_TRUE(read_nodes[0] == group); | 237 EXPECT_TRUE(read_nodes[0] == group); |
238 EXPECT_TRUE(read_nodes[1] == url_node); | 238 EXPECT_TRUE(read_nodes[1] == url_node); |
239 | 239 |
240 // Asking for the first node should return NULL with more than one element | 240 // Asking for the first node should return NULL with more than one element |
241 // present. | 241 // present. |
242 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); | 242 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); |
243 } | 243 } |
OLD | NEW |