OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/enhanced_bookmarks/metadata_accessor.h" | 5 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
9 #include "components/bookmarks/browser/bookmark_model.h" | 12 #include "components/bookmarks/browser/bookmark_model.h" |
| 13 #include "components/bookmarks/browser/bookmark_node.h" |
10 #include "components/bookmarks/test/test_bookmark_client.h" | 14 #include "components/bookmarks/test/test_bookmark_client.h" |
11 #include "components/enhanced_bookmarks/proto/metadata.pb.h" | 15 #include "components/enhanced_bookmarks/proto/metadata.pb.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" |
13 | 18 |
14 namespace { | 19 namespace { |
15 | 20 |
16 using namespace image::collections; | |
17 | |
18 const std::string BOOKMARK_URL("http://example.com/index.html"); | 21 const std::string BOOKMARK_URL("http://example.com/index.html"); |
19 | 22 |
20 class MetadataAccessorTest : public testing::Test { | 23 class EnhancedBookmarkModelTest : public testing::Test { |
21 public: | 24 public: |
22 MetadataAccessorTest() {} | 25 EnhancedBookmarkModelTest() {} |
23 virtual ~MetadataAccessorTest() {} | 26 virtual ~EnhancedBookmarkModelTest() {} |
| 27 |
| 28 virtual void SetUp() OVERRIDE { |
| 29 test::TestBookmarkClient bookmark_client; |
| 30 bookmark_model_.reset(bookmark_client.CreateModel().release()); |
| 31 model_.reset(new enhanced_bookmarks::EnhancedBookmarkModel( |
| 32 bookmark_model_.get(), "v1.0")); |
| 33 } |
| 34 |
| 35 virtual void TearDown() OVERRIDE { |
| 36 model_.reset(); |
| 37 bookmark_model_.reset(); |
| 38 } |
24 | 39 |
25 protected: | 40 protected: |
26 DISALLOW_COPY_AND_ASSIGN(MetadataAccessorTest); | 41 const BookmarkNode* AddBookmark() { |
| 42 return AddBookmark("Some title", bookmark_model_->other_node()); |
| 43 } |
27 | 44 |
28 // Adds a bookmark as the subnode at index 0 to other_node. | 45 const BookmarkNode* AddFolder() { |
29 // |name| should be ASCII encoded. | 46 return AddFolder("Some title", bookmark_model_->other_node()); |
30 // Returns the newly added bookmark. | |
31 const BookmarkNode* AddBookmark(BookmarkModel* model, std::string name) { | |
32 return model->AddURL(model->other_node(), | |
33 0, // index. | |
34 base::ASCIIToUTF16(name), | |
35 GURL(BOOKMARK_URL)); | |
36 } | 47 } |
| 48 |
| 49 const BookmarkNode* AddBookmark(const std::string& name, |
| 50 const BookmarkNode* parent) { |
| 51 return bookmark_model_->AddURL(parent, |
| 52 0, // index. |
| 53 base::ASCIIToUTF16(name), |
| 54 GURL(BOOKMARK_URL)); |
| 55 } |
| 56 |
| 57 const BookmarkNode* AddFolder(const std::string& name, |
| 58 const BookmarkNode* parent) { |
| 59 return bookmark_model_->AddFolder(parent, 0, base::ASCIIToUTF16(name)); |
| 60 } |
| 61 |
| 62 std::string GetVersionForNode(const BookmarkNode* node) { |
| 63 std::string version; |
| 64 if (!node->GetMetaInfo("stars.version", &version)) |
| 65 return std::string(); |
| 66 return version; |
| 67 } |
| 68 |
| 69 scoped_ptr<BookmarkModel> bookmark_model_; |
| 70 scoped_ptr<enhanced_bookmarks::EnhancedBookmarkModel> model_; |
| 71 |
| 72 private: |
| 73 DISALLOW_COPY_AND_ASSIGN(EnhancedBookmarkModelTest); |
37 }; | 74 }; |
38 | 75 |
39 TEST_F(MetadataAccessorTest, TestEmptySnippet) { | 76 TEST_F(EnhancedBookmarkModelTest, TestEmptySnippet) { |
40 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 77 const BookmarkNode* node = AddBookmark(); |
41 | 78 |
42 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 79 std::string snippet(model_->GetSnippet(node)); |
43 CHECK_EQ(snippet, ""); | 80 EXPECT_EQ(snippet, ""); |
44 }; | 81 }; |
45 | 82 |
46 TEST_F(MetadataAccessorTest, TestSnippet) { | 83 TEST_F(EnhancedBookmarkModelTest, TestSnippet) { |
47 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 84 const BookmarkNode* node = AddBookmark(); |
48 | 85 |
49 // Binary serialize the protobuf. | 86 // Binary serialize the protobuf. |
50 PageData data; | 87 image::collections::PageData data; |
51 data.set_snippet("I'm happy!"); | 88 data.set_snippet("I'm happy!"); |
52 ASSERT_TRUE(data.IsInitialized()); | 89 ASSERT_TRUE(data.IsInitialized()); |
53 std::string output; | 90 std::string output; |
54 bool result = data.SerializeToString(&output); | 91 bool result = data.SerializeToString(&output); |
55 ASSERT_TRUE(result); | 92 ASSERT_TRUE(result); |
56 | 93 |
57 // base64 encode the output. | 94 // base64 encode the output. |
58 std::string encoded; | 95 std::string encoded; |
59 base::Base64Encode(output, &encoded); | 96 base::Base64Encode(output, &encoded); |
60 node->SetMetaInfo(enhanced_bookmarks::kPageDataKey, encoded); | 97 bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", encoded); |
61 | 98 |
62 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 99 std::string snippet(model_->GetSnippet(node)); |
63 CHECK_EQ(snippet, "I'm happy!"); | 100 EXPECT_EQ(snippet, "I'm happy!"); |
64 }; | 101 } |
65 | 102 |
66 TEST_F(MetadataAccessorTest, TestBadEncodingSnippet) { | 103 TEST_F(EnhancedBookmarkModelTest, TestBadEncodingSnippet) { |
67 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 104 const BookmarkNode* node = AddBookmark(); |
68 | 105 |
69 // Binary serialize the protobuf. | 106 // Binary serialize the protobuf. |
70 PageData data; | 107 image::collections::PageData data; |
71 data.set_snippet("You are happy!"); | 108 data.set_snippet("You are happy!"); |
72 ASSERT_TRUE(data.IsInitialized()); | 109 ASSERT_TRUE(data.IsInitialized()); |
73 std::string output; | 110 std::string output; |
74 bool result = data.SerializeToString(&output); | 111 bool result = data.SerializeToString(&output); |
75 ASSERT_TRUE(result); | 112 ASSERT_TRUE(result); |
76 | 113 |
77 // don't base 64 encode the output. | 114 // don't base 64 encode the output. |
78 node->SetMetaInfo(enhanced_bookmarks::kPageDataKey, output); | 115 bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", output); |
79 | 116 |
80 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 117 std::string snippet(model_->GetSnippet(node)); |
81 CHECK_EQ(snippet, ""); | 118 EXPECT_EQ(snippet, ""); |
82 }; | 119 } |
83 | 120 |
84 TEST_F(MetadataAccessorTest, TestOriginalImage) { | 121 TEST_F(EnhancedBookmarkModelTest, TestOriginalImage) { |
85 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 122 const BookmarkNode* node = AddBookmark(); |
86 | 123 |
87 ImageData data; | 124 image::collections::ImageData data; |
88 // Intentionally make raw pointer. | 125 // Intentionally make raw pointer. |
89 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 126 image::collections::ImageData_ImageInfo* info = |
| 127 new image::collections::ImageData_ImageInfo; |
90 info->set_url("http://example.com/foobar"); | 128 info->set_url("http://example.com/foobar"); |
91 info->set_width(15); | 129 info->set_width(15); |
92 info->set_height(55); | 130 info->set_height(55); |
93 // This method consumes the pointer. | 131 // This method consumes the pointer. |
94 data.set_allocated_original_info(info); | 132 data.set_allocated_original_info(info); |
95 | 133 |
96 std::string output; | 134 std::string output; |
97 bool result = data.SerializePartialToString(&output); | 135 bool result = data.SerializePartialToString(&output); |
98 ASSERT_TRUE(result); | 136 ASSERT_TRUE(result); |
99 | 137 |
100 // base64 encode the output. | 138 // base64 encode the output. |
101 std::string encoded; | 139 std::string encoded; |
102 base::Base64Encode(output, &encoded); | 140 base::Base64Encode(output, &encoded); |
103 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 141 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
104 | 142 |
105 GURL url; | 143 GURL url; |
106 int width; | 144 int width; |
107 int height; | 145 int height; |
108 result = enhanced_bookmarks::OriginalImageFromBookmark( | 146 result = model_->GetOriginalImage(node, &url, &width, &height); |
109 node.get(), &url, &width, &height); | |
110 ASSERT_TRUE(result); | 147 ASSERT_TRUE(result); |
111 CHECK_EQ(url, GURL("http://example.com/foobar")); | 148 EXPECT_EQ(url, GURL("http://example.com/foobar")); |
112 CHECK_EQ(width, 15); | 149 EXPECT_EQ(width, 15); |
113 CHECK_EQ(height, 55); | 150 EXPECT_EQ(height, 55); |
114 }; | 151 } |
115 | 152 |
116 TEST_F(MetadataAccessorTest, TestThumbnailImage) { | 153 TEST_F(EnhancedBookmarkModelTest, TestThumbnailImage) { |
117 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 154 const BookmarkNode* node = AddBookmark(); |
118 | 155 |
119 ImageData data; | 156 image::collections::ImageData data; |
120 // Intentionally make raw pointer. | 157 // Intentionally make raw pointer. |
121 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 158 image::collections::ImageData_ImageInfo* info = |
| 159 new image::collections::ImageData_ImageInfo; |
122 info->set_url("http://example.com/foobar"); | 160 info->set_url("http://example.com/foobar"); |
123 info->set_width(15); | 161 info->set_width(15); |
124 info->set_height(55); | 162 info->set_height(55); |
125 // This method consumes the pointer. | 163 // This method consumes the pointer. |
126 data.set_allocated_thumbnail_info(info); | 164 data.set_allocated_thumbnail_info(info); |
127 | 165 |
128 std::string output; | 166 std::string output; |
129 bool result = data.SerializePartialToString(&output); | 167 bool result = data.SerializePartialToString(&output); |
130 ASSERT_TRUE(result); | 168 ASSERT_TRUE(result); |
131 | 169 |
132 // base64 encode the output. | 170 // base64 encode the output. |
133 std::string encoded; | 171 std::string encoded; |
134 base::Base64Encode(output, &encoded); | 172 base::Base64Encode(output, &encoded); |
135 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 173 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
136 | 174 |
137 GURL url; | 175 GURL url; |
138 int width; | 176 int width; |
139 int height; | 177 int height; |
140 result = enhanced_bookmarks::ThumbnailImageFromBookmark( | 178 result = model_->GetThumbnailImage(node, &url, &width, &height); |
141 node.get(), &url, &width, &height); | |
142 ASSERT_TRUE(result); | 179 ASSERT_TRUE(result); |
143 CHECK_EQ(url, GURL("http://example.com/foobar")); | 180 EXPECT_EQ(url, GURL("http://example.com/foobar")); |
144 CHECK_EQ(width, 15); | 181 EXPECT_EQ(width, 15); |
145 CHECK_EQ(height, 55); | 182 EXPECT_EQ(height, 55); |
146 }; | 183 } |
147 | 184 |
148 TEST_F(MetadataAccessorTest, TestOriginalImageMissingDimensions) { | 185 TEST_F(EnhancedBookmarkModelTest, TestOriginalImageMissingDimensions) { |
149 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 186 const BookmarkNode* node = AddBookmark(); |
150 | 187 |
151 ImageData data; | 188 image::collections::ImageData data; |
152 // Intentionally make raw pointer. | 189 // Intentionally make raw pointer. |
153 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 190 image::collections::ImageData_ImageInfo* info = |
| 191 new image::collections::ImageData_ImageInfo; |
154 info->set_url("http://example.com/foobar"); | 192 info->set_url("http://example.com/foobar"); |
155 // This method consumes the pointer. | 193 // This method consumes the pointer. |
156 data.set_allocated_original_info(info); | 194 data.set_allocated_original_info(info); |
157 | 195 |
158 std::string output; | 196 std::string output; |
159 bool result = data.SerializePartialToString(&output); | 197 bool result = data.SerializePartialToString(&output); |
160 ASSERT_TRUE(result); | 198 ASSERT_TRUE(result); |
161 | 199 |
162 // base64 encode the output. | 200 // base64 encode the output. |
163 std::string encoded; | 201 std::string encoded; |
164 base::Base64Encode(output, &encoded); | 202 base::Base64Encode(output, &encoded); |
165 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 203 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
166 | 204 |
167 GURL url; | 205 GURL url; |
168 int width; | 206 int width; |
169 int height; | 207 int height; |
170 result = enhanced_bookmarks::OriginalImageFromBookmark( | 208 result = model_->GetOriginalImage(node, &url, &width, &height); |
171 node.get(), &url, &width, &height); | |
172 ASSERT_FALSE(result); | 209 ASSERT_FALSE(result); |
173 }; | 210 } |
174 | 211 |
175 TEST_F(MetadataAccessorTest, TestOriginalImageBadUrl) { | 212 TEST_F(EnhancedBookmarkModelTest, TestOriginalImageBadUrl) { |
176 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 213 const BookmarkNode* node = AddBookmark(); |
177 | 214 |
178 ImageData data; | 215 image::collections::ImageData data; |
179 // Intentionally make raw pointer. | 216 // Intentionally make raw pointer. |
180 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 217 image::collections::ImageData_ImageInfo* info = |
| 218 new image::collections::ImageData_ImageInfo; |
181 info->set_url("asdf. 13r"); | 219 info->set_url("asdf. 13r"); |
182 info->set_width(15); | 220 info->set_width(15); |
183 info->set_height(55); | 221 info->set_height(55); |
184 // This method consumes the pointer. | 222 // This method consumes the pointer. |
185 data.set_allocated_original_info(info); | 223 data.set_allocated_original_info(info); |
186 | 224 |
187 std::string output; | 225 std::string output; |
188 bool result = data.SerializePartialToString(&output); | 226 bool result = data.SerializePartialToString(&output); |
189 ASSERT_TRUE(result); | 227 ASSERT_TRUE(result); |
190 | 228 |
191 // base64 encode the output. | 229 // base64 encode the output. |
192 std::string encoded; | 230 std::string encoded; |
193 base::Base64Encode(output, &encoded); | 231 base::Base64Encode(output, &encoded); |
194 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 232 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
195 | 233 |
196 GURL url; | 234 GURL url; |
197 int width; | 235 int width; |
198 int height; | 236 int height; |
199 result = enhanced_bookmarks::OriginalImageFromBookmark( | 237 result = model_->GetOriginalImage(node, &url, &width, &height); |
200 node.get(), &url, &width, &height); | |
201 ASSERT_FALSE(result); | 238 ASSERT_FALSE(result); |
202 }; | 239 } |
203 | 240 |
204 TEST_F(MetadataAccessorTest, TestEncodeDecode) { | 241 TEST_F(EnhancedBookmarkModelTest, TestEncodeDecode) { |
205 test::TestBookmarkClient bookmark_client; | 242 const BookmarkNode* node = AddBookmark(); |
206 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
207 const BookmarkNode* node = | |
208 bookmark_model->AddURL(bookmark_model->other_node(), | |
209 0, // index. | |
210 base::ASCIIToUTF16("whatever"), | |
211 GURL(BOOKMARK_URL)); | |
212 | 243 |
213 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( | 244 bool result = |
214 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); | 245 model_->SetOriginalImage(node, GURL("http://example.com/i.jpg"), 22, 33); |
215 ASSERT_TRUE(result); | 246 ASSERT_TRUE(result); |
216 | 247 |
217 GURL url; | 248 GURL url; |
218 int width; | 249 int width; |
219 int height; | 250 int height; |
220 result = enhanced_bookmarks::OriginalImageFromBookmark( | 251 result = model_->GetOriginalImage(node, &url, &width, &height); |
221 node, &url, &width, &height); | |
222 ASSERT_TRUE(result); | 252 ASSERT_TRUE(result); |
223 CHECK_EQ(url, GURL("http://example.com/i.jpg")); | 253 EXPECT_EQ(url, GURL("http://example.com/i.jpg")); |
224 CHECK_EQ(width, 22); | 254 EXPECT_EQ(width, 22); |
225 CHECK_EQ(height, 33); | 255 EXPECT_EQ(height, 33); |
226 }; | 256 EXPECT_EQ("v1.0", GetVersionForNode(node)); |
| 257 } |
227 | 258 |
228 TEST_F(MetadataAccessorTest, TestDoubleEncodeDecode) { | 259 TEST_F(EnhancedBookmarkModelTest, TestDoubleEncodeDecode) { |
229 test::TestBookmarkClient bookmark_client; | 260 const BookmarkNode* node = AddBookmark(); |
230 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
231 const BookmarkNode* node = | |
232 bookmark_model->AddURL(bookmark_model->other_node(), | |
233 0, // index. | |
234 base::ASCIIToUTF16("whatever"), | |
235 GURL(BOOKMARK_URL)); | |
236 | 261 |
237 // Encode some information. | 262 // Encode some information. |
238 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( | 263 bool result = |
239 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); | 264 model_->SetOriginalImage(node, GURL("http://example.com/i.jpg"), 22, 33); |
240 ASSERT_TRUE(result); | 265 ASSERT_TRUE(result); |
241 // Encode some different information. | 266 // Encode some different information. |
242 result = enhanced_bookmarks::SetOriginalImageForBookmark( | 267 result = |
243 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 33, 44); | 268 model_->SetOriginalImage(node, GURL("http://example.com/i.jpg"), 33, 44); |
244 ASSERT_TRUE(result); | 269 ASSERT_TRUE(result); |
245 | 270 |
246 GURL url; | 271 GURL url; |
247 int width; | 272 int width; |
248 int height; | 273 int height; |
249 result = enhanced_bookmarks::OriginalImageFromBookmark( | 274 result = model_->GetOriginalImage(node, &url, &width, &height); |
250 node, &url, &width, &height); | |
251 ASSERT_TRUE(result); | 275 ASSERT_TRUE(result); |
252 CHECK_EQ(url, GURL("http://example.com/i.jpg")); | 276 EXPECT_EQ(url, GURL("http://example.com/i.jpg")); |
253 CHECK_EQ(width, 33); | 277 EXPECT_EQ(width, 33); |
254 CHECK_EQ(height, 44); | 278 EXPECT_EQ(height, 44); |
255 }; | 279 EXPECT_EQ("v1.0", GetVersionForNode(node)); |
256 | |
257 TEST_F(MetadataAccessorTest, TestThumbnail) { | |
258 test::TestBookmarkClient bookmark_client; | |
259 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
260 const BookmarkNode* node = | |
261 bookmark_model->AddURL(bookmark_model->other_node(), | |
262 0, // index. | |
263 base::ASCIIToUTF16("whatever"), | |
264 GURL(BOOKMARK_URL)); | |
265 | |
266 // Encode some information. | |
267 ASSERT_TRUE(enhanced_bookmarks::SetAllImagesForBookmark( | |
268 bookmark_model.get(), | |
269 node, | |
270 GURL(), | |
271 0, | |
272 0, | |
273 GURL("http://google.com/img/thumb.jpg"), | |
274 33, | |
275 44)); | |
276 GURL url; | |
277 int width; | |
278 int height; | |
279 bool result = enhanced_bookmarks::ThumbnailImageFromBookmark( | |
280 node, &url, &width, &height); | |
281 ASSERT_TRUE(result); | |
282 CHECK_EQ(url, GURL("http://google.com/img/thumb.jpg")); | |
283 CHECK_EQ(width, 33); | |
284 CHECK_EQ(height, 44); | |
285 }; | |
286 | |
287 TEST_F(MetadataAccessorTest, TestRemoteId) { | |
288 test::TestBookmarkClient bookmark_client; | |
289 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
290 const BookmarkNode* node = AddBookmark(bookmark_model.get(), "Aga Khan"); | |
291 | |
292 // First call creates the UUID, second call should return the same. | |
293 ASSERT_EQ( | |
294 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node), | |
295 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node)); | |
296 } | 280 } |
297 | 281 |
298 TEST_F(MetadataAccessorTest, TestEmptyDescription) { | 282 TEST_F(EnhancedBookmarkModelTest, TestRemoteId) { |
299 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 283 const BookmarkNode* node = AddBookmark(); |
| 284 const BookmarkNode* folder_node = AddFolder(); |
300 | 285 |
301 std::string description( | 286 std::string remote_id = model_->GetRemoteId(node); |
302 enhanced_bookmarks::DescriptionFromBookmark(node.get())); | 287 // First call creates the UUID, second call should return the same. |
303 CHECK_EQ(description, ""); | 288 EXPECT_EQ(remote_id, model_->GetRemoteId(node)); |
| 289 |
| 290 // Verify that the remote id starts with the correct prefix. |
| 291 EXPECT_TRUE(StartsWithASCII(remote_id, "ebc_", true)); |
| 292 std::string folder_remote_id = model_->GetRemoteId(folder_node); |
| 293 EXPECT_TRUE(StartsWithASCII(folder_remote_id, "ebf_", true)); |
| 294 |
| 295 // Verifiy version field was set. |
| 296 EXPECT_EQ("v1.0", GetVersionForNode(node)); |
| 297 EXPECT_EQ("v1.0", GetVersionForNode(folder_node)); |
304 } | 298 } |
305 | 299 |
306 TEST_F(MetadataAccessorTest, TestDescription) { | 300 TEST_F(EnhancedBookmarkModelTest, TestEmptyDescription) { |
307 test::TestBookmarkClient bookmark_client; | 301 const BookmarkNode* node = AddBookmark(); |
308 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | 302 |
309 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 303 std::string description(model_->GetDescription(node)); |
| 304 EXPECT_EQ(description, ""); |
| 305 } |
| 306 |
| 307 TEST_F(EnhancedBookmarkModelTest, TestDescription) { |
| 308 const BookmarkNode* node = AddBookmark(); |
310 const std::string description("This is the most useful description of all."); | 309 const std::string description("This is the most useful description of all."); |
311 | 310 |
312 // Set the description. | 311 // Set the description. |
313 enhanced_bookmarks::SetDescriptionForBookmark( | 312 model_->SetDescription(node, description); |
314 bookmark_model.get(), node.get(), description); | |
315 | 313 |
316 // Check the description is the one that was set. | 314 // Check the description is the one that was set. |
317 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), | 315 EXPECT_EQ(model_->GetDescription(node), description); |
318 description); | 316 EXPECT_EQ("v1.0", GetVersionForNode(node)); |
319 } | 317 } |
320 | 318 |
321 // If there is no notes field, the description should fall back on the snippet. | 319 // If there is no notes field, the description should fall back on the snippet. |
322 TEST_F(MetadataAccessorTest, TestDescriptionFallback) { | 320 TEST_F(EnhancedBookmarkModelTest, TestDescriptionFallback) { |
323 test::TestBookmarkClient bookmark_client; | 321 const BookmarkNode* node = AddBookmark(); |
324 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
325 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | |
326 | 322 |
327 // Binary serialize the protobuf. | 323 // Binary serialize the protobuf. |
328 PageData data; | 324 image::collections::PageData data; |
329 data.set_snippet("Joe Bar Team"); | 325 data.set_snippet("Joe Bar Team"); |
330 ASSERT_TRUE(data.IsInitialized()); | 326 ASSERT_TRUE(data.IsInitialized()); |
331 std::string output; | 327 std::string output; |
332 bool result = data.SerializeToString(&output); | 328 bool result = data.SerializeToString(&output); |
333 ASSERT_TRUE(result); | 329 ASSERT_TRUE(result); |
334 | 330 |
335 // base64 encode the output. | 331 // base64 encode the output. |
336 std::string encoded; | 332 std::string encoded; |
337 base::Base64Encode(output, &encoded); | 333 base::Base64Encode(output, &encoded); |
338 node->SetMetaInfo(enhanced_bookmarks::kPageDataKey, encoded); | 334 bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", encoded); |
339 | 335 |
340 // The snippet is used as the description. | 336 // The snippet is used as the description. |
341 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 337 std::string snippet(model_->GetSnippet(node)); |
342 CHECK_EQ("Joe Bar Team", | 338 EXPECT_EQ("Joe Bar Team", model_->GetDescription(node)); |
343 enhanced_bookmarks::DescriptionFromBookmark(node.get())); | |
344 | 339 |
345 // Set the description. | 340 // Set the description. |
346 const std::string description("This is the most useful description of all."); | 341 const std::string description("This is the most useful description of all."); |
347 enhanced_bookmarks::SetDescriptionForBookmark( | 342 model_->SetDescription(node, description); |
348 bookmark_model.get(), node.get(), description); | |
349 | 343 |
350 // Check the description is the one that was set. | 344 // Check the description is the one that was set. |
351 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), | 345 EXPECT_EQ(model_->GetDescription(node), description); |
352 description); | |
353 } | 346 } |
| 347 |
| 348 // Makes sure that the stars.version field is set every time |
| 349 // EnhancedBookmarkModel makes a change to a node. |
| 350 TEST_F(EnhancedBookmarkModelTest, TestVersionField) { |
| 351 const BookmarkNode* node = AddBookmark(); |
| 352 EXPECT_EQ("", GetVersionForNode(node)); |
| 353 |
| 354 model_->SetDescription(node, "foo"); |
| 355 EXPECT_EQ("v1.0", GetVersionForNode(node)); |
| 356 |
| 357 // Add a suffix to the version to set. |
| 358 model_->SetVersionSuffix("alpha"); |
| 359 |
| 360 model_->SetDescription(node, "foo"); |
| 361 // Since the description didn't actually change, the version field should |
| 362 // not either. |
| 363 EXPECT_EQ("v1.0", GetVersionForNode(node)); |
| 364 |
| 365 model_->SetDescription(node, "bar"); |
| 366 EXPECT_EQ("v1.0/alpha", GetVersionForNode(node)); |
| 367 } |
| 368 |
| 369 // Verifies that the stars.userEdit field is set appropriately when editing a |
| 370 // node. |
| 371 TEST_F(EnhancedBookmarkModelTest, TestUserEdit) { |
| 372 const BookmarkNode* node = AddBookmark(); |
| 373 |
| 374 model_->SetDescription(node, "foo"); |
| 375 std::string user_edit; |
| 376 ASSERT_TRUE(node->GetMetaInfo("stars.userEdit", &user_edit)); |
| 377 EXPECT_EQ("true", user_edit); |
| 378 } |
| 379 |
354 } // namespace | 380 } // namespace |
OLD | NEW |