| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 TEST_F(ThumbnailDatabaseTest, GetFaviconAfterMigrationToTopSites) { | 113 TEST_F(ThumbnailDatabaseTest, GetFaviconAfterMigrationToTopSites) { |
| 114 ThumbnailDatabase db; | 114 ThumbnailDatabase db; |
| 115 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 115 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 116 db.BeginTransaction(); | 116 db.BeginTransaction(); |
| 117 | 117 |
| 118 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 118 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 119 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 119 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 120 | 120 |
| 121 GURL url("http://google.com"); | 121 GURL url("http://google.com"); |
| 122 FavIconID id = db.AddFavIcon(url, FAV_ICON); | 122 FaviconID id = db.AddFavIcon(url, FAV_ICON); |
| 123 base::Time time = base::Time::Now(); | 123 base::Time time = base::Time::Now(); |
| 124 db.SetFavicon(id, favicon, time); | 124 db.SetFavicon(id, favicon, time); |
| 125 EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); | 125 EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); |
| 126 | 126 |
| 127 base::Time time_out; | 127 base::Time time_out; |
| 128 std::vector<unsigned char> favicon_out; | 128 std::vector<unsigned char> favicon_out; |
| 129 GURL url_out; | 129 GURL url_out; |
| 130 EXPECT_TRUE(db.GetFavicon(id, &time_out, &favicon_out, &url_out)); | 130 EXPECT_TRUE(db.GetFavicon(id, &time_out, &favicon_out, &url_out)); |
| 131 EXPECT_EQ(url, url_out); | 131 EXPECT_EQ(url, url_out); |
| 132 EXPECT_EQ(time.ToTimeT(), time_out.ToTimeT()); | 132 EXPECT_EQ(time.ToTimeT(), time_out.ToTimeT()); |
| 133 ASSERT_EQ(data.size(), favicon_out.size()); | 133 ASSERT_EQ(data.size(), favicon_out.size()); |
| 134 EXPECT_TRUE(std::equal(data.begin(), | 134 EXPECT_TRUE(std::equal(data.begin(), |
| 135 data.end(), | 135 data.end(), |
| 136 favicon_out.begin())); | 136 favicon_out.begin())); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(ThumbnailDatabaseTest, AddIconMapping) { | 139 TEST_F(ThumbnailDatabaseTest, AddIconMapping) { |
| 140 ThumbnailDatabase db; | 140 ThumbnailDatabase db; |
| 141 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 141 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 142 db.BeginTransaction(); | 142 db.BeginTransaction(); |
| 143 | 143 |
| 144 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 144 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 145 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 145 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 146 | 146 |
| 147 GURL url("http://google.com"); | 147 GURL url("http://google.com"); |
| 148 FavIconID id = db.AddFavIcon(url, TOUCH_ICON); | 148 FaviconID id = db.AddFavIcon(url, TOUCH_ICON); |
| 149 EXPECT_NE(0, id); | 149 EXPECT_NE(0, id); |
| 150 base::Time time = base::Time::Now(); | 150 base::Time time = base::Time::Now(); |
| 151 db.SetFavicon(id, favicon, time); | 151 db.SetFavicon(id, favicon, time); |
| 152 | 152 |
| 153 EXPECT_NE(0, db.AddIconMapping(url, id)); | 153 EXPECT_NE(0, db.AddIconMapping(url, id)); |
| 154 std::vector<IconMapping> icon_mapping; | 154 std::vector<IconMapping> icon_mapping; |
| 155 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 155 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 156 EXPECT_EQ(1u, icon_mapping.size()); | 156 EXPECT_EQ(1u, icon_mapping.size()); |
| 157 EXPECT_EQ(url, icon_mapping.front().page_url); | 157 EXPECT_EQ(url, icon_mapping.front().page_url); |
| 158 EXPECT_EQ(id, icon_mapping.front().icon_id); | 158 EXPECT_EQ(id, icon_mapping.front().icon_id); |
| 159 } | 159 } |
| 160 | 160 |
| 161 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { | 161 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { |
| 162 ThumbnailDatabase db; | 162 ThumbnailDatabase db; |
| 163 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 163 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 164 db.BeginTransaction(); | 164 db.BeginTransaction(); |
| 165 | 165 |
| 166 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 166 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 167 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 167 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 168 | 168 |
| 169 GURL url("http://google.com"); | 169 GURL url("http://google.com"); |
| 170 FavIconID id = db.AddFavIcon(url, TOUCH_ICON); | 170 FaviconID id = db.AddFavIcon(url, TOUCH_ICON); |
| 171 base::Time time = base::Time::Now(); | 171 base::Time time = base::Time::Now(); |
| 172 db.SetFavicon(id, favicon, time); | 172 db.SetFavicon(id, favicon, time); |
| 173 | 173 |
| 174 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); | 174 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); |
| 175 std::vector<IconMapping> icon_mapping; | 175 std::vector<IconMapping> icon_mapping; |
| 176 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 176 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 177 ASSERT_EQ(1u, icon_mapping.size()); | 177 ASSERT_EQ(1u, icon_mapping.size()); |
| 178 EXPECT_EQ(url, icon_mapping.front().page_url); | 178 EXPECT_EQ(url, icon_mapping.front().page_url); |
| 179 EXPECT_EQ(id, icon_mapping.front().icon_id); | 179 EXPECT_EQ(id, icon_mapping.front().icon_id); |
| 180 | 180 |
| 181 GURL url1("http://www.google.com/"); | 181 GURL url1("http://www.google.com/"); |
| 182 FavIconID new_id = db.AddFavIcon(url1, TOUCH_ICON); | 182 FaviconID new_id = db.AddFavIcon(url1, TOUCH_ICON); |
| 183 EXPECT_TRUE(db.UpdateIconMapping(icon_mapping.front().mapping_id, new_id)); | 183 EXPECT_TRUE(db.UpdateIconMapping(icon_mapping.front().mapping_id, new_id)); |
| 184 | 184 |
| 185 icon_mapping.clear(); | 185 icon_mapping.clear(); |
| 186 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 186 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 187 ASSERT_EQ(1u, icon_mapping.size()); | 187 ASSERT_EQ(1u, icon_mapping.size()); |
| 188 EXPECT_EQ(url, icon_mapping.front().page_url); | 188 EXPECT_EQ(url, icon_mapping.front().page_url); |
| 189 EXPECT_EQ(new_id, icon_mapping.front().icon_id); | 189 EXPECT_EQ(new_id, icon_mapping.front().icon_id); |
| 190 EXPECT_NE(id, icon_mapping.front().icon_id); | 190 EXPECT_NE(id, icon_mapping.front().icon_id); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) { | 193 TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) { |
| 194 ThumbnailDatabase db; | 194 ThumbnailDatabase db; |
| 195 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 195 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 196 db.BeginTransaction(); | 196 db.BeginTransaction(); |
| 197 | 197 |
| 198 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 198 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 199 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 199 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 200 | 200 |
| 201 GURL url("http://google.com"); | 201 GURL url("http://google.com"); |
| 202 FavIconID id = db.AddFavIcon(url, TOUCH_ICON); | 202 FaviconID id = db.AddFavIcon(url, TOUCH_ICON); |
| 203 base::Time time = base::Time::Now(); | 203 base::Time time = base::Time::Now(); |
| 204 db.SetFavicon(id, favicon, time); | 204 db.SetFavicon(id, favicon, time); |
| 205 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); | 205 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); |
| 206 | 206 |
| 207 FavIconID id2 = db.AddFavIcon(url, FAV_ICON); | 207 FaviconID id2 = db.AddFavIcon(url, FAV_ICON); |
| 208 db.SetFavicon(id2, favicon, time); | 208 db.SetFavicon(id2, favicon, time); |
| 209 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); | 209 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); |
| 210 ASSERT_NE(id, id2); | 210 ASSERT_NE(id, id2); |
| 211 | 211 |
| 212 std::vector<IconMapping> icon_mapping; | 212 std::vector<IconMapping> icon_mapping; |
| 213 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 213 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 214 ASSERT_EQ(2u, icon_mapping.size()); | 214 ASSERT_EQ(2u, icon_mapping.size()); |
| 215 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); | 215 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); |
| 216 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAV_ICON, NULL)); | 216 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAV_ICON, NULL)); |
| 217 | 217 |
| 218 db.DeleteIconMappings(url); | 218 db.DeleteIconMappings(url); |
| 219 | 219 |
| 220 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); | 220 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); |
| 221 EXPECT_FALSE(db.GetIconMappingForPageURL(url, FAV_ICON, NULL)); | 221 EXPECT_FALSE(db.GetIconMappingForPageURL(url, FAV_ICON, NULL)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { | 224 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { |
| 225 ThumbnailDatabase db; | 225 ThumbnailDatabase db; |
| 226 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 226 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 227 db.BeginTransaction(); | 227 db.BeginTransaction(); |
| 228 | 228 |
| 229 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 229 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 230 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 230 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 231 | 231 |
| 232 GURL url("http://google.com"); | 232 GURL url("http://google.com"); |
| 233 | 233 |
| 234 FavIconID id1 = db.AddFavIcon(url, TOUCH_ICON); | 234 FaviconID id1 = db.AddFavIcon(url, TOUCH_ICON); |
| 235 base::Time time = base::Time::Now(); | 235 base::Time time = base::Time::Now(); |
| 236 db.SetFavicon(id1, favicon, time); | 236 db.SetFavicon(id1, favicon, time); |
| 237 EXPECT_TRUE(0 < db.AddIconMapping(url, id1)); | 237 EXPECT_TRUE(0 < db.AddIconMapping(url, id1)); |
| 238 | 238 |
| 239 FavIconID id2 = db.AddFavIcon(url, FAV_ICON); | 239 FaviconID id2 = db.AddFavIcon(url, FAV_ICON); |
| 240 EXPECT_NE(id1, id2); | 240 EXPECT_NE(id1, id2); |
| 241 db.SetFavicon(id2, favicon, time); | 241 db.SetFavicon(id2, favicon, time); |
| 242 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); | 242 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); |
| 243 | 243 |
| 244 std::vector<IconMapping> icon_mapping; | 244 std::vector<IconMapping> icon_mapping; |
| 245 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 245 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 246 ASSERT_EQ(2u, icon_mapping.size()); | 246 ASSERT_EQ(2u, icon_mapping.size()); |
| 247 EXPECT_NE(icon_mapping[0].icon_id, icon_mapping[1].icon_id); | 247 EXPECT_NE(icon_mapping[0].icon_id, icon_mapping[1].icon_id); |
| 248 EXPECT_TRUE(icon_mapping[0].icon_id == id1 && icon_mapping[1].icon_id == id2); | 248 EXPECT_TRUE(icon_mapping[0].icon_id == id1 && icon_mapping[1].icon_id == id2); |
| 249 } | 249 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 268 "last_updated INTEGER DEFAULT 0," | 268 "last_updated INTEGER DEFAULT 0," |
| 269 "image_data BLOB)"); | 269 "image_data BLOB)"); |
| 270 EXPECT_TRUE(db.db_.Execute(sql.c_str())); | 270 EXPECT_TRUE(db.db_.Execute(sql.c_str())); |
| 271 | 271 |
| 272 EXPECT_TRUE(db.UpgradeToVersion4()); | 272 EXPECT_TRUE(db.UpgradeToVersion4()); |
| 273 | 273 |
| 274 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 274 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 275 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 275 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 276 | 276 |
| 277 GURL url("http://google.com"); | 277 GURL url("http://google.com"); |
| 278 FavIconID id = db.AddFavIcon(url, TOUCH_ICON); | 278 FaviconID id = db.AddFavIcon(url, TOUCH_ICON); |
| 279 base::Time time = base::Time::Now(); | 279 base::Time time = base::Time::Now(); |
| 280 db.SetFavicon(id, favicon, time); | 280 db.SetFavicon(id, favicon, time); |
| 281 | 281 |
| 282 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); | 282 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); |
| 283 IconMapping icon_mapping; | 283 IconMapping icon_mapping; |
| 284 EXPECT_TRUE(db.GetIconMappingForPageURL(url, TOUCH_ICON, &icon_mapping)); | 284 EXPECT_TRUE(db.GetIconMappingForPageURL(url, TOUCH_ICON, &icon_mapping)); |
| 285 EXPECT_EQ(url, icon_mapping.page_url); | 285 EXPECT_EQ(url, icon_mapping.page_url); |
| 286 EXPECT_EQ(id, icon_mapping.icon_id); | 286 EXPECT_EQ(id, icon_mapping.icon_id); |
| 287 } | 287 } |
| 288 | 288 |
| 289 TEST_F(ThumbnailDatabaseTest, TemporayIconMapping) { | 289 TEST_F(ThumbnailDatabaseTest, TemporayIconMapping) { |
| 290 ThumbnailDatabase db; | 290 ThumbnailDatabase db; |
| 291 | 291 |
| 292 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 292 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 293 | 293 |
| 294 db.BeginTransaction(); | 294 db.BeginTransaction(); |
| 295 | 295 |
| 296 EXPECT_TRUE(db.InitTemporaryIconMappingTable()); | 296 EXPECT_TRUE(db.InitTemporaryIconMappingTable()); |
| 297 | 297 |
| 298 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 298 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 299 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 299 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 300 | 300 |
| 301 GURL url("http://google.com"); | 301 GURL url("http://google.com"); |
| 302 FavIconID id = db.AddFavIcon(url, FAV_ICON); | 302 FaviconID id = db.AddFavIcon(url, FAV_ICON); |
| 303 base::Time time = base::Time::Now(); | 303 base::Time time = base::Time::Now(); |
| 304 db.SetFavicon(id, favicon, time); | 304 db.SetFavicon(id, favicon, time); |
| 305 | 305 |
| 306 db.AddToTemporaryIconMappingTable(url, id); | 306 db.AddToTemporaryIconMappingTable(url, id); |
| 307 db.CommitTemporaryIconMappingTable(); | 307 db.CommitTemporaryIconMappingTable(); |
| 308 IconMapping icon_mapping; | 308 IconMapping icon_mapping; |
| 309 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAV_ICON, &icon_mapping)); | 309 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAV_ICON, &icon_mapping)); |
| 310 EXPECT_EQ(id, icon_mapping.icon_id); | 310 EXPECT_EQ(id, icon_mapping.icon_id); |
| 311 EXPECT_EQ(url, icon_mapping.page_url); | 311 EXPECT_EQ(url, icon_mapping.page_url); |
| 312 } | 312 } |
| 313 | 313 |
| 314 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { | 314 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { |
| 315 ThumbnailDatabase db; | 315 ThumbnailDatabase db; |
| 316 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 316 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 317 db.BeginTransaction(); | 317 db.BeginTransaction(); |
| 318 | 318 |
| 319 // Add a favicon | 319 // Add a favicon |
| 320 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 320 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 321 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 321 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 322 | 322 |
| 323 GURL url("http://google.com"); | 323 GURL url("http://google.com"); |
| 324 FavIconID id = db.AddFavIcon(url, FAV_ICON); | 324 FaviconID id = db.AddFavIcon(url, FAV_ICON); |
| 325 base::Time time = base::Time::Now(); | 325 base::Time time = base::Time::Now(); |
| 326 db.SetFavicon(id, favicon, time); | 326 db.SetFavicon(id, favicon, time); |
| 327 | 327 |
| 328 EXPECT_NE(0, db.AddIconMapping(url, id)); | 328 EXPECT_NE(0, db.AddIconMapping(url, id)); |
| 329 std::vector<IconMapping> icon_mapping; | 329 std::vector<IconMapping> icon_mapping; |
| 330 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 330 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 331 | 331 |
| 332 EXPECT_EQ(url, icon_mapping.front().page_url); | 332 EXPECT_EQ(url, icon_mapping.front().page_url); |
| 333 EXPECT_EQ(id, icon_mapping.front().icon_id); | 333 EXPECT_EQ(id, icon_mapping.front().icon_id); |
| 334 EXPECT_EQ(FAV_ICON, icon_mapping.front().icon_type); | 334 EXPECT_EQ(FAV_ICON, icon_mapping.front().icon_type); |
| 335 | 335 |
| 336 // Add a touch icon | 336 // Add a touch icon |
| 337 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); | 337 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); |
| 338 scoped_refptr<RefCountedBytes> favicon2(new RefCountedBytes(data)); | 338 scoped_refptr<RefCountedBytes> favicon2(new RefCountedBytes(data)); |
| 339 | 339 |
| 340 FavIconID id2 = db.AddFavIcon(url, TOUCH_ICON); | 340 FaviconID id2 = db.AddFavIcon(url, TOUCH_ICON); |
| 341 db.SetFavicon(id2, favicon2, time); | 341 db.SetFavicon(id2, favicon2, time); |
| 342 EXPECT_NE(0, db.AddIconMapping(url, id2)); | 342 EXPECT_NE(0, db.AddIconMapping(url, id2)); |
| 343 | 343 |
| 344 icon_mapping.clear(); | 344 icon_mapping.clear(); |
| 345 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 345 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 346 | 346 |
| 347 EXPECT_EQ(url, icon_mapping.front().page_url); | 347 EXPECT_EQ(url, icon_mapping.front().page_url); |
| 348 EXPECT_EQ(id2, icon_mapping.front().icon_id); | 348 EXPECT_EQ(id2, icon_mapping.front().icon_id); |
| 349 EXPECT_EQ(TOUCH_ICON, icon_mapping.front().icon_type); | 349 EXPECT_EQ(TOUCH_ICON, icon_mapping.front().icon_type); |
| 350 | 350 |
| 351 // Add a touch precomposed icon | 351 // Add a touch precomposed icon |
| 352 scoped_refptr<RefCountedBytes> favicon3(new RefCountedBytes(data2)); | 352 scoped_refptr<RefCountedBytes> favicon3(new RefCountedBytes(data2)); |
| 353 | 353 |
| 354 FavIconID id3 = db.AddFavIcon(url, TOUCH_PRECOMPOSED_ICON); | 354 FaviconID id3 = db.AddFavIcon(url, TOUCH_PRECOMPOSED_ICON); |
| 355 db.SetFavicon(id3, favicon3, time); | 355 db.SetFavicon(id3, favicon3, time); |
| 356 EXPECT_NE(0, db.AddIconMapping(url, id3)); | 356 EXPECT_NE(0, db.AddIconMapping(url, id3)); |
| 357 | 357 |
| 358 icon_mapping.clear(); | 358 icon_mapping.clear(); |
| 359 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 359 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 360 | 360 |
| 361 EXPECT_EQ(url, icon_mapping.front().page_url); | 361 EXPECT_EQ(url, icon_mapping.front().page_url); |
| 362 EXPECT_EQ(id3, icon_mapping.front().icon_id); | 362 EXPECT_EQ(id3, icon_mapping.front().icon_id); |
| 363 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mapping.front().icon_type); | 363 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mapping.front().icon_type); |
| 364 } | 364 } |
| 365 | 365 |
| 366 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { | 366 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { |
| 367 ThumbnailDatabase db; | 367 ThumbnailDatabase db; |
| 368 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 368 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 369 db.BeginTransaction(); | 369 db.BeginTransaction(); |
| 370 | 370 |
| 371 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 371 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 372 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 372 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
| 373 | 373 |
| 374 // Add a favicon which will have icon_mappings | 374 // Add a favicon which will have icon_mappings |
| 375 FavIconID id1 = db.AddFavIcon(GURL("http://google.com"), FAV_ICON); | 375 FaviconID id1 = db.AddFavIcon(GURL("http://google.com"), FAV_ICON); |
| 376 EXPECT_NE(id1, 0); | 376 EXPECT_NE(id1, 0); |
| 377 base::Time time = base::Time::Now(); | 377 base::Time time = base::Time::Now(); |
| 378 db.SetFavicon(id1, favicon, time); | 378 db.SetFavicon(id1, favicon, time); |
| 379 | 379 |
| 380 // Add another type of favicon | 380 // Add another type of favicon |
| 381 FavIconID id2 = db.AddFavIcon(GURL("http://www.google.com/icon"), TOUCH_ICON); | 381 FaviconID id2 = db.AddFavIcon(GURL("http://www.google.com/icon"), TOUCH_ICON); |
| 382 EXPECT_NE(id2, 0); | 382 EXPECT_NE(id2, 0); |
| 383 time = base::Time::Now(); | 383 time = base::Time::Now(); |
| 384 db.SetFavicon(id2, favicon, time); | 384 db.SetFavicon(id2, favicon, time); |
| 385 | 385 |
| 386 // Add 3rd favicon | 386 // Add 3rd favicon |
| 387 FavIconID id3 = db.AddFavIcon(GURL("http://www.google.com/icon"), TOUCH_ICON); | 387 FaviconID id3 = db.AddFavIcon(GURL("http://www.google.com/icon"), TOUCH_ICON); |
| 388 EXPECT_NE(id3, 0); | 388 EXPECT_NE(id3, 0); |
| 389 time = base::Time::Now(); | 389 time = base::Time::Now(); |
| 390 db.SetFavicon(id3, favicon, time); | 390 db.SetFavicon(id3, favicon, time); |
| 391 | 391 |
| 392 // Add 2 icon mapping | 392 // Add 2 icon mapping |
| 393 GURL page_url("http://www.google.com"); | 393 GURL page_url("http://www.google.com"); |
| 394 EXPECT_TRUE(db.AddIconMapping(page_url, id1)); | 394 EXPECT_TRUE(db.AddIconMapping(page_url, id1)); |
| 395 EXPECT_TRUE(db.AddIconMapping(page_url, id2)); | 395 EXPECT_TRUE(db.AddIconMapping(page_url, id2)); |
| 396 | 396 |
| 397 EXPECT_TRUE(db.HasMappingFor(id1)); | 397 EXPECT_TRUE(db.HasMappingFor(id1)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 ASSERT_TRUE(db.GetFavicon( | 453 ASSERT_TRUE(db.GetFavicon( |
| 454 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url)); | 454 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url)); |
| 455 EXPECT_EQ(icon2, out_icon_url); | 455 EXPECT_EQ(icon2, out_icon_url); |
| 456 | 456 |
| 457 // Test a page without icon | 457 // Test a page without icon |
| 458 GURL page_url4 = GURL("http://www.google.com/blank.html"); | 458 GURL page_url4 = GURL("http://www.google.com/blank.html"); |
| 459 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); | 459 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 } // namespace history | 462 } // namespace history |
| OLD | NEW |