OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/history/android/android_provider_backend.h" | 5 #include "chrome/browser/history/android/android_provider_backend.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 bookmark_(false), | 42 bookmark_(false), |
43 favicon_id_(0) { | 43 favicon_id_(0) { |
44 } | 44 } |
45 URLID url_id_; | 45 URLID url_id_; |
46 Time create_time_; | 46 Time create_time_; |
47 Time last_visit_time_; | 47 Time last_visit_time_; |
48 bool bookmark_; | 48 bool bookmark_; |
49 FaviconID favicon_id_; | 49 FaviconID favicon_id_; |
50 }; | 50 }; |
51 | 51 |
| 52 const gfx::Size kFaviconRegularSize = gfx::Size(16, 16); |
| 53 |
52 } // namespace | 54 } // namespace |
53 | 55 |
54 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate { | 56 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate { |
55 public: | 57 public: |
56 AndroidProviderBackendDelegate() {} | 58 AndroidProviderBackendDelegate() {} |
57 | 59 |
58 virtual void NotifyProfileError(int backend_id, | 60 virtual void NotifyProfileError(int backend_id, |
59 sql::InitStatus init_status) OVERRIDE {} | 61 sql::InitStatus init_status) OVERRIDE {} |
60 virtual void SetInMemoryBackend(int backend_id, | 62 virtual void SetInMemoryBackend(int backend_id, |
61 InMemoryHistoryBackend* backend) OVERRIDE {} | 63 InMemoryHistoryBackend* backend) OVERRIDE {} |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 url_id1 = url_row.id(); | 243 url_id1 = url_row.id(); |
242 ASSERT_TRUE(history_backend->GetURL(url2, &url_row)); | 244 ASSERT_TRUE(history_backend->GetURL(url2, &url_row)); |
243 url_id2 = url_row.id(); | 245 url_id2 = url_row.id(); |
244 | 246 |
245 // Set favicon to url2. | 247 // Set favicon to url2. |
246 std::vector<unsigned char> data; | 248 std::vector<unsigned char> data; |
247 data.push_back('1'); | 249 data.push_back('1'); |
248 history_backend->SetFavicon(url2, | 250 history_backend->SetFavicon(url2, |
249 GURL(), | 251 GURL(), |
250 new base::RefCountedBytes(data), | 252 new base::RefCountedBytes(data), |
| 253 kFaviconRegularSize, |
251 FAVICON); | 254 FAVICON); |
252 history_backend->Closing(); | 255 history_backend->Closing(); |
253 } | 256 } |
254 | 257 |
255 // The history_db_name and thumbnail_db_name files should be created by | 258 // The history_db_name and thumbnail_db_name files should be created by |
256 // HistoryBackend. We need to open the same database files. | 259 // HistoryBackend. We need to open the same database files. |
257 ASSERT_TRUE(file_util::PathExists(history_db_name_)); | 260 ASSERT_TRUE(file_util::PathExists(history_db_name_)); |
258 ASSERT_TRUE(file_util::PathExists(thumbnail_db_name_)); | 261 ASSERT_TRUE(file_util::PathExists(thumbnail_db_name_)); |
259 | 262 |
260 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); | 263 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 url_id2 = url_row.id(); | 370 url_id2 = url_row.id(); |
368 url_row.set_title(title2); | 371 url_row.set_title(title2); |
369 ASSERT_TRUE(history_backend->UpdateURL(url_id2, url_row)); | 372 ASSERT_TRUE(history_backend->UpdateURL(url_id2, url_row)); |
370 | 373 |
371 // Set favicon to url2. | 374 // Set favicon to url2. |
372 std::vector<unsigned char> data; | 375 std::vector<unsigned char> data; |
373 data.push_back('1'); | 376 data.push_back('1'); |
374 history_backend->SetFavicon(url2, | 377 history_backend->SetFavicon(url2, |
375 GURL(), | 378 GURL(), |
376 new base::RefCountedBytes(data), | 379 new base::RefCountedBytes(data), |
| 380 kFaviconRegularSize, |
377 FAVICON); | 381 FAVICON); |
378 history_backend->Closing(); | 382 history_backend->Closing(); |
379 } | 383 } |
380 | 384 |
381 // The history_db_name and thumbnail_db_name files should be created by | 385 // The history_db_name and thumbnail_db_name files should be created by |
382 // HistoryBackend. We need to open the same database files. | 386 // HistoryBackend. We need to open the same database files. |
383 ASSERT_TRUE(file_util::PathExists(history_db_name_)); | 387 ASSERT_TRUE(file_util::PathExists(history_db_name_)); |
384 ASSERT_TRUE(file_util::PathExists(thumbnail_db_name_)); | 388 ASSERT_TRUE(file_util::PathExists(thumbnail_db_name_)); |
385 | 389 |
386 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); | 390 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", | 1122 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", |
1119 update_args, &update_count)); | 1123 update_args, &update_count)); |
1120 // Verify notifications. | 1124 // Verify notifications. |
1121 EXPECT_FALSE(delegate_.deleted_details()); | 1125 EXPECT_FALSE(delegate_.deleted_details()); |
1122 EXPECT_FALSE(delegate_.modified_details()); | 1126 EXPECT_FALSE(delegate_.modified_details()); |
1123 ASSERT_TRUE(delegate_.favicon_details()); | 1127 ASSERT_TRUE(delegate_.favicon_details()); |
1124 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); | 1128 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); |
1125 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != | 1129 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != |
1126 delegate_.favicon_details()->urls.find(row1.url())); | 1130 delegate_.favicon_details()->urls.find(row1.url())); |
1127 | 1131 |
1128 IconMapping icon_mapping; | 1132 std::vector<IconMapping> icon_mappings; |
1129 EXPECT_TRUE(thumbnail_db_.GetIconMappingForPageURL(row1.url(), FAVICON, | 1133 EXPECT_TRUE(thumbnail_db_.GetIconMappingsForPageURL(row1.url(), FAVICON, |
1130 &icon_mapping)); | 1134 &icon_mappings)); |
| 1135 EXPECT_EQ(1u, icon_mappings.size()); |
1131 Time last_updated; | 1136 Time last_updated; |
1132 std::vector<unsigned char> png_icon_data; | 1137 std::vector<unsigned char> png_icon_data; |
1133 EXPECT_TRUE(thumbnail_db_.GetFavicon(icon_mapping.icon_id, &last_updated, | 1138 EXPECT_TRUE(thumbnail_db_.GetFavicon(icon_mappings[0].icon_id, &last_updated, |
1134 &png_icon_data, NULL, NULL)); | 1139 &png_icon_data, NULL, NULL, NULL)); |
1135 EXPECT_EQ(data, png_icon_data); | 1140 EXPECT_EQ(data, png_icon_data); |
1136 | 1141 |
1137 // Remove favicon. | 1142 // Remove favicon. |
1138 HistoryAndBookmarkRow update_row2; | 1143 HistoryAndBookmarkRow update_row2; |
1139 | 1144 |
1140 // Set favicon. | 1145 // Set favicon. |
1141 update_row1.set_favicon(std::vector<unsigned char>()); | 1146 update_row1.set_favicon(std::vector<unsigned char>()); |
1142 update_args.clear(); | 1147 update_args.clear(); |
1143 update_args.push_back(UTF8ToUTF16(row1.raw_url())); | 1148 update_args.push_back(UTF8ToUTF16(row1.raw_url())); |
1144 delegate_.ResetDetails(); | 1149 delegate_.ResetDetails(); |
1145 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", | 1150 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", |
1146 update_args, &update_count)); | 1151 update_args, &update_count)); |
1147 // Verify notifications. | 1152 // Verify notifications. |
1148 EXPECT_FALSE(delegate_.deleted_details()); | 1153 EXPECT_FALSE(delegate_.deleted_details()); |
1149 EXPECT_FALSE(delegate_.modified_details()); | 1154 EXPECT_FALSE(delegate_.modified_details()); |
1150 ASSERT_TRUE(delegate_.favicon_details()); | 1155 ASSERT_TRUE(delegate_.favicon_details()); |
1151 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); | 1156 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); |
1152 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != | 1157 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != |
1153 delegate_.favicon_details()->urls.find(row1.url())); | 1158 delegate_.favicon_details()->urls.find(row1.url())); |
1154 | 1159 |
1155 EXPECT_FALSE(thumbnail_db_.GetIconMappingForPageURL(row1.url(), FAVICON, | 1160 EXPECT_FALSE(thumbnail_db_.GetIconMappingsForPageURL(row1.url(), FAVICON, |
1156 NULL)); | 1161 NULL)); |
1157 } | 1162 } |
1158 | 1163 |
1159 TEST_F(AndroidProviderBackendTest, UpdateSearchTermTable) { | 1164 TEST_F(AndroidProviderBackendTest, UpdateSearchTermTable) { |
1160 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); | 1165 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); |
1161 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, | 1166 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, |
1162 &history_db_)); | 1167 &history_db_)); |
1163 scoped_ptr<AndroidProviderBackend> backend( | 1168 scoped_ptr<AndroidProviderBackend> backend( |
1164 new AndroidProviderBackend(android_cache_db_name_, &history_db_, | 1169 new AndroidProviderBackend(android_cache_db_name_, &history_db_, |
1165 &thumbnail_db_, bookmark_model_, &delegate_)); | 1170 &thumbnail_db_, bookmark_model_, &delegate_)); |
1166 // Insert a keyword search item to verify if the update succeeds. | 1171 // Insert a keyword search item to verify if the update succeeds. |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 // Query by folder=1, the row2 should returned. | 1730 // Query by folder=1, the row2 should returned. |
1726 statement.reset(backend->QueryHistoryAndBookmarks( | 1731 statement.reset(backend->QueryHistoryAndBookmarks( |
1727 projections, std::string("folder=1"), std::vector<string16>(), | 1732 projections, std::string("folder=1"), std::vector<string16>(), |
1728 std::string("url ASC"))); | 1733 std::string("url ASC"))); |
1729 ASSERT_TRUE(statement->statement()->Step()); | 1734 ASSERT_TRUE(statement->statement()->Step()); |
1730 EXPECT_EQ(row2.url(), GURL(statement->statement()->ColumnString(0))); | 1735 EXPECT_EQ(row2.url(), GURL(statement->statement()->ColumnString(0))); |
1731 EXPECT_FALSE(statement->statement()->Step()); | 1736 EXPECT_FALSE(statement->statement()->Step()); |
1732 } | 1737 } |
1733 | 1738 |
1734 } // namespace history | 1739 } // namespace history |
OLD | NEW |