Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/history/android/android_provider_backend_unittest.cc

Issue 10831341: Change HistoryAndBookmarkRow favicon_ field to be scoped_refptr<base::RefCountedMemory> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 row1.set_title(UTF8ToUTF16("cnn")); 490 row1.set_title(UTF8ToUTF16("cnn"));
491 491
492 HistoryAndBookmarkRow row2; 492 HistoryAndBookmarkRow row2;
493 row2.set_raw_url("http://www.example.com"); 493 row2.set_raw_url("http://www.example.com");
494 row2.set_url(GURL("http://www.example.com")); 494 row2.set_url(GURL("http://www.example.com"));
495 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 495 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
496 row2.set_is_bookmark(false); 496 row2.set_is_bookmark(false);
497 row2.set_title(UTF8ToUTF16("example")); 497 row2.set_title(UTF8ToUTF16("example"));
498 std::vector<unsigned char> data; 498 std::vector<unsigned char> data;
499 data.push_back('1'); 499 data.push_back('1');
500 row2.set_favicon(data); 500 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
501 501
502 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); 502 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
503 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, 503 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
504 &history_db_)); 504 &history_db_));
505 scoped_ptr<AndroidProviderBackend> backend( 505 scoped_ptr<AndroidProviderBackend> backend(
506 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 506 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
507 &thumbnail_db_, bookmark_model_, &delegate_)); 507 &thumbnail_db_, bookmark_model_, &delegate_));
508 508
509 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row1)); 509 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row1));
510 EXPECT_FALSE(delegate_.deleted_details()); 510 EXPECT_FALSE(delegate_.deleted_details());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 row1.set_title(UTF8ToUTF16("cnn")); 599 row1.set_title(UTF8ToUTF16("cnn"));
600 600
601 HistoryAndBookmarkRow row2; 601 HistoryAndBookmarkRow row2;
602 row2.set_raw_url("http://www.example.com"); 602 row2.set_raw_url("http://www.example.com");
603 row2.set_url(GURL("http://www.example.com")); 603 row2.set_url(GURL("http://www.example.com"));
604 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 604 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
605 row2.set_is_bookmark(false); 605 row2.set_is_bookmark(false);
606 row2.set_title(UTF8ToUTF16("example")); 606 row2.set_title(UTF8ToUTF16("example"));
607 std::vector<unsigned char> data; 607 std::vector<unsigned char> data;
608 data.push_back('1'); 608 data.push_back('1');
609 row2.set_favicon(data); 609 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
610 610
611 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); 611 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
612 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, 612 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
613 &history_db_)); 613 &history_db_));
614 614
615 scoped_ptr<AndroidProviderBackend> backend( 615 scoped_ptr<AndroidProviderBackend> backend(
616 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 616 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
617 &thumbnail_db_, bookmark_model_, &delegate_)); 617 &thumbnail_db_, bookmark_model_, &delegate_));
618 618
619 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row1)); 619 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row1));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 row1.set_title(UTF8ToUTF16("cnn")); 788 row1.set_title(UTF8ToUTF16("cnn"));
789 789
790 HistoryAndBookmarkRow row2; 790 HistoryAndBookmarkRow row2;
791 row2.set_raw_url("http://www.example.com"); 791 row2.set_raw_url("http://www.example.com");
792 row2.set_url(GURL("http://www.example.com")); 792 row2.set_url(GURL("http://www.example.com"));
793 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 793 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
794 row2.set_is_bookmark(false); 794 row2.set_is_bookmark(false);
795 row2.set_title(UTF8ToUTF16("example")); 795 row2.set_title(UTF8ToUTF16("example"));
796 std::vector<unsigned char> data; 796 std::vector<unsigned char> data;
797 data.push_back('1'); 797 data.push_back('1');
798 row2.set_favicon(data); 798 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
799 799
800 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); 800 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
801 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, 801 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
802 &history_db_)); 802 &history_db_));
803 scoped_ptr<AndroidProviderBackend> backend( 803 scoped_ptr<AndroidProviderBackend> backend(
804 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 804 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
805 &thumbnail_db_, bookmark_model_, &delegate_)); 805 &thumbnail_db_, bookmark_model_, &delegate_));
806 806
807 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 807 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
808 ASSERT_TRUE(id1); 808 ASSERT_TRUE(id1);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 row1.set_title(UTF8ToUTF16("cnn")); 968 row1.set_title(UTF8ToUTF16("cnn"));
969 969
970 HistoryAndBookmarkRow row2; 970 HistoryAndBookmarkRow row2;
971 row2.set_raw_url("http://www.example.com"); 971 row2.set_raw_url("http://www.example.com");
972 row2.set_url(GURL("http://www.example.com")); 972 row2.set_url(GURL("http://www.example.com"));
973 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 973 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
974 row2.set_is_bookmark(false); 974 row2.set_is_bookmark(false);
975 row2.set_title(UTF8ToUTF16("example")); 975 row2.set_title(UTF8ToUTF16("example"));
976 std::vector<unsigned char> data; 976 std::vector<unsigned char> data;
977 data.push_back('1'); 977 data.push_back('1');
978 row2.set_favicon(data); 978 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
979 979
980 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); 980 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
981 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, 981 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
982 &history_db_)); 982 &history_db_));
983 scoped_ptr<AndroidProviderBackend> backend( 983 scoped_ptr<AndroidProviderBackend> backend(
984 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 984 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
985 &thumbnail_db_, bookmark_model_, &delegate_)); 985 &thumbnail_db_, bookmark_model_, &delegate_));
986 986
987 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 987 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
988 ASSERT_TRUE(id1); 988 ASSERT_TRUE(id1);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 row1.set_title(UTF8ToUTF16("cnn")); 1049 row1.set_title(UTF8ToUTF16("cnn"));
1050 1050
1051 HistoryAndBookmarkRow row2; 1051 HistoryAndBookmarkRow row2;
1052 row2.set_raw_url("http://www.example.com"); 1052 row2.set_raw_url("http://www.example.com");
1053 row2.set_url(GURL("http://www.example.com")); 1053 row2.set_url(GURL("http://www.example.com"));
1054 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 1054 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
1055 row2.set_is_bookmark(false); 1055 row2.set_is_bookmark(false);
1056 row2.set_title(UTF8ToUTF16("example")); 1056 row2.set_title(UTF8ToUTF16("example"));
1057 std::vector<unsigned char> data; 1057 std::vector<unsigned char> data;
1058 data.push_back('1'); 1058 data.push_back('1');
1059 row2.set_favicon(data); 1059 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
1060 1060
1061 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); 1061 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
1062 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, 1062 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
1063 &history_db_)); 1063 &history_db_));
1064 scoped_ptr<AndroidProviderBackend> backend( 1064 scoped_ptr<AndroidProviderBackend> backend(
1065 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 1065 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
1066 &thumbnail_db_, bookmark_model_, &delegate_)); 1066 &thumbnail_db_, bookmark_model_, &delegate_));
1067 1067
1068 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 1068 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
1069 ASSERT_TRUE(id1); 1069 ASSERT_TRUE(id1);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 ASSERT_TRUE(id1); 1131 ASSERT_TRUE(id1);
1132 1132
1133 int update_count; 1133 int update_count;
1134 std::vector<string16> update_args; 1134 std::vector<string16> update_args;
1135 // Update the last visit time to a value greater than current one. 1135 // Update the last visit time to a value greater than current one.
1136 HistoryAndBookmarkRow update_row1; 1136 HistoryAndBookmarkRow update_row1;
1137 1137
1138 // Set favicon. 1138 // Set favicon.
1139 std::vector<unsigned char> data; 1139 std::vector<unsigned char> data;
1140 data.push_back('1'); 1140 data.push_back('1');
1141 update_row1.set_favicon(data); 1141 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data));
1142 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 1142 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
1143 delegate_.ResetDetails(); 1143 delegate_.ResetDetails();
1144 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 1144 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
1145 update_args, &update_count)); 1145 update_args, &update_count));
1146 // Verify notifications. 1146 // Verify notifications.
1147 EXPECT_FALSE(delegate_.deleted_details()); 1147 EXPECT_FALSE(delegate_.deleted_details());
1148 EXPECT_FALSE(delegate_.modified_details()); 1148 EXPECT_FALSE(delegate_.modified_details());
1149 ASSERT_TRUE(delegate_.favicon_details()); 1149 ASSERT_TRUE(delegate_.favicon_details());
1150 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 1150 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size());
1151 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 1151 ASSERT_TRUE(delegate_.favicon_details()->urls.end() !=
1152 delegate_.favicon_details()->urls.find(row1.url())); 1152 delegate_.favicon_details()->urls.find(row1.url()));
1153 1153
1154 IconMapping icon_mapping; 1154 IconMapping icon_mapping;
1155 EXPECT_TRUE(thumbnail_db_.GetIconMappingForPageURL(row1.url(), FAVICON, 1155 EXPECT_TRUE(thumbnail_db_.GetIconMappingForPageURL(row1.url(), FAVICON,
1156 &icon_mapping)); 1156 &icon_mapping));
1157 Time last_updated; 1157 Time last_updated;
1158 std::vector<unsigned char> png_icon_data; 1158 std::vector<unsigned char> png_icon_data;
1159 EXPECT_TRUE(thumbnail_db_.GetFavicon(icon_mapping.icon_id, &last_updated, 1159 EXPECT_TRUE(thumbnail_db_.GetFavicon(icon_mapping.icon_id, &last_updated,
1160 &png_icon_data, NULL, NULL)); 1160 &png_icon_data, NULL, NULL));
1161 EXPECT_EQ(data, png_icon_data); 1161 EXPECT_EQ(data, png_icon_data);
1162 1162
1163 // Remove favicon. 1163 // Remove favicon.
1164 HistoryAndBookmarkRow update_row2; 1164 HistoryAndBookmarkRow update_row2;
1165 1165
1166 // Set favicon. 1166 // Set favicon.
1167 update_row1.set_favicon(std::vector<unsigned char>()); 1167 update_row1.set_favicon(new base::RefCountedBytes());
1168 update_args.clear(); 1168 update_args.clear();
1169 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 1169 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
1170 delegate_.ResetDetails(); 1170 delegate_.ResetDetails();
1171 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 1171 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
1172 update_args, &update_count)); 1172 update_args, &update_count));
1173 // Verify notifications. 1173 // Verify notifications.
1174 EXPECT_FALSE(delegate_.deleted_details()); 1174 EXPECT_FALSE(delegate_.deleted_details());
1175 EXPECT_FALSE(delegate_.modified_details()); 1175 EXPECT_FALSE(delegate_.modified_details());
1176 ASSERT_TRUE(delegate_.favicon_details()); 1176 ASSERT_TRUE(delegate_.favicon_details());
1177 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 1177 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size());
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 row1.set_title(UTF8ToUTF16("cnn")); 1554 row1.set_title(UTF8ToUTF16("cnn"));
1555 1555
1556 HistoryAndBookmarkRow row2; 1556 HistoryAndBookmarkRow row2;
1557 row2.set_raw_url("http://www.example.com"); 1557 row2.set_raw_url("http://www.example.com");
1558 row2.set_url(GURL("http://www.example.com")); 1558 row2.set_url(GURL("http://www.example.com"));
1559 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 1559 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
1560 row2.set_is_bookmark(false); 1560 row2.set_is_bookmark(false);
1561 row2.set_title(UTF8ToUTF16("example")); 1561 row2.set_title(UTF8ToUTF16("example"));
1562 std::vector<unsigned char> data; 1562 std::vector<unsigned char> data;
1563 data.push_back('1'); 1563 data.push_back('1');
1564 row2.set_favicon(data); 1564 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
1565 1565
1566 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); 1566 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
1567 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, 1567 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
1568 &history_db_)); 1568 &history_db_));
1569 scoped_ptr<AndroidProviderBackend> backend( 1569 scoped_ptr<AndroidProviderBackend> backend(
1570 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 1570 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
1571 &thumbnail_db_, bookmark_model_, &delegate_)); 1571 &thumbnail_db_, bookmark_model_, &delegate_));
1572 1572
1573 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 1573 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
1574 ASSERT_TRUE(id1); 1574 ASSERT_TRUE(id1);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 row1.set_title(UTF8ToUTF16("cnn")); 1721 row1.set_title(UTF8ToUTF16("cnn"));
1722 1722
1723 HistoryAndBookmarkRow row2; 1723 HistoryAndBookmarkRow row2;
1724 row2.set_raw_url("http://www.example.com"); 1724 row2.set_raw_url("http://www.example.com");
1725 row2.set_url(GURL("http://www.example.com")); 1725 row2.set_url(GURL("http://www.example.com"));
1726 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 1726 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
1727 row2.set_is_bookmark(false); 1727 row2.set_is_bookmark(false);
1728 row2.set_title(UTF8ToUTF16("example")); 1728 row2.set_title(UTF8ToUTF16("example"));
1729 std::vector<unsigned char> data; 1729 std::vector<unsigned char> data;
1730 data.push_back('1'); 1730 data.push_back('1');
1731 row2.set_favicon(data); 1731 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
1732 1732
1733 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 1733 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
1734 ASSERT_TRUE(id1); 1734 ASSERT_TRUE(id1);
1735 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2); 1735 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2);
1736 ASSERT_TRUE(id2); 1736 ASSERT_TRUE(id2);
1737 content::RunAllPendingInMessageLoop(); 1737 content::RunAllPendingInMessageLoop();
1738 1738
1739 // Query by folder=0, the row1 should returned. 1739 // Query by folder=0, the row1 should returned.
1740 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 1740 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
1741 1741
1742 projections.push_back(HistoryAndBookmarkRow::URL); 1742 projections.push_back(HistoryAndBookmarkRow::URL);
1743 1743
1744 scoped_ptr<AndroidStatement> statement(backend->QueryHistoryAndBookmarks( 1744 scoped_ptr<AndroidStatement> statement(backend->QueryHistoryAndBookmarks(
1745 projections, std::string("folder=0"), std::vector<string16>(), 1745 projections, std::string("folder=0"), std::vector<string16>(),
1746 std::string("url ASC"))); 1746 std::string("url ASC")));
1747 ASSERT_TRUE(statement->statement()->Step()); 1747 ASSERT_TRUE(statement->statement()->Step());
1748 EXPECT_EQ(row1.raw_url(), statement->statement()->ColumnString(0)); 1748 EXPECT_EQ(row1.raw_url(), statement->statement()->ColumnString(0));
1749 EXPECT_FALSE(statement->statement()->Step()); 1749 EXPECT_FALSE(statement->statement()->Step());
1750 1750
1751 // Query by folder=1, the row2 should returned. 1751 // Query by folder=1, the row2 should returned.
1752 statement.reset(backend->QueryHistoryAndBookmarks( 1752 statement.reset(backend->QueryHistoryAndBookmarks(
1753 projections, std::string("folder=1"), std::vector<string16>(), 1753 projections, std::string("folder=1"), std::vector<string16>(),
1754 std::string("url ASC"))); 1754 std::string("url ASC")));
1755 ASSERT_TRUE(statement->statement()->Step()); 1755 ASSERT_TRUE(statement->statement()->Step());
1756 EXPECT_EQ(row2.url(), GURL(statement->statement()->ColumnString(0))); 1756 EXPECT_EQ(row2.url(), GURL(statement->statement()->ColumnString(0)));
1757 EXPECT_FALSE(statement->statement()->Step()); 1757 EXPECT_FALSE(statement->statement()->Step());
1758 } 1758 }
1759 1759
1760 } // namespace history 1760 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/android/android_provider_backend.cc ('k') | chrome/browser/history/android/favicon_sql_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698