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

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

Issue 484213002: Refactor HistoryService to not send NOTIFICATION_FAVICON_CHANGED (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android unit tests Created 6 years, 3 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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/favicon/favicon_changed_details.h"
18 #include "chrome/browser/history/android/android_time.h" 17 #include "chrome/browser/history/android/android_time.h"
19 #include "chrome/browser/history/chrome_history_client.h" 18 #include "chrome/browser/history/chrome_history_client.h"
20 #include "chrome/browser/history/chrome_history_client_factory.h" 19 #include "chrome/browser/history/chrome_history_client_factory.h"
21 #include "chrome/browser/history/history_backend.h" 20 #include "chrome/browser/history/history_backend.h"
22 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
24 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/testing_profile_manager.h" 25 #include "chrome/test/base/testing_profile_manager.h"
27 #include "components/bookmarks/browser/bookmark_model.h" 26 #include "components/bookmarks/browser/bookmark_model.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 65
67 } // namespace 66 } // namespace
68 67
69 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate { 68 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate {
70 public: 69 public:
71 AndroidProviderBackendDelegate() {} 70 AndroidProviderBackendDelegate() {}
72 71
73 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} 72 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {}
74 virtual void SetInMemoryBackend( 73 virtual void SetInMemoryBackend(
75 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE {} 74 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE {}
75 virtual void NotifyFaviconChanged(const std::set<GURL>& url) OVERRIDE {
76 favicon_changed_.reset(new std::set<GURL>(url.begin(), url.end()));
77 }
76 virtual void BroadcastNotifications( 78 virtual void BroadcastNotifications(
77 int type, 79 int type,
78 scoped_ptr<HistoryDetails> details) OVERRIDE { 80 scoped_ptr<HistoryDetails> details) OVERRIDE {
79 switch (type) { 81 switch (type) {
80 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: 82 case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
81 deleted_details_.reset( 83 deleted_details_.reset(
82 static_cast<URLsDeletedDetails*>(details.release())); 84 static_cast<URLsDeletedDetails*>(details.release()));
83 break; 85 break;
84 case chrome::NOTIFICATION_FAVICON_CHANGED:
85 favicon_details_.reset(
86 static_cast<FaviconChangedDetails*>(details.release()));
87 break;
88 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: 86 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED:
89 modified_details_.reset( 87 modified_details_.reset(
90 static_cast<URLsModifiedDetails*>(details.release())); 88 static_cast<URLsModifiedDetails*>(details.release()));
91 break; 89 break;
92 } 90 }
93 } 91 }
94 virtual void DBLoaded() OVERRIDE {} 92 virtual void DBLoaded() OVERRIDE {}
95 virtual void NotifyVisitDBObserversOnAddVisit( 93 virtual void NotifyVisitDBObserversOnAddVisit(
96 const history::BriefVisitInfo& info) OVERRIDE {} 94 const history::BriefVisitInfo& info) OVERRIDE {}
97 95
98 URLsDeletedDetails* deleted_details() const { 96 URLsDeletedDetails* deleted_details() const {
99 return deleted_details_.get(); 97 return deleted_details_.get();
100 } 98 }
101 99
102 URLsModifiedDetails* modified_details() const { 100 URLsModifiedDetails* modified_details() const {
103 return modified_details_.get(); 101 return modified_details_.get();
104 } 102 }
105 103
106 FaviconChangedDetails* favicon_details() const { 104 std::set<GURL>* favicon_changed() const { return favicon_changed_.get(); }
107 return favicon_details_.get();
108 }
109 105
110 void ResetDetails() { 106 void ResetDetails() {
111 deleted_details_.reset(); 107 deleted_details_.reset();
112 modified_details_.reset(); 108 modified_details_.reset();
113 favicon_details_.reset(); 109 favicon_changed_.reset();
114 } 110 }
115 111
116 private: 112 private:
117 scoped_ptr<URLsDeletedDetails> deleted_details_; 113 scoped_ptr<URLsDeletedDetails> deleted_details_;
118 scoped_ptr<URLsModifiedDetails> modified_details_; 114 scoped_ptr<URLsModifiedDetails> modified_details_;
119 scoped_ptr<FaviconChangedDetails> favicon_details_; 115 scoped_ptr<std::set<GURL> > favicon_changed_;
120 116
121 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendDelegate); 117 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendDelegate);
122 }; 118 };
123 119
124 class AndroidProviderBackendTest : public testing::Test { 120 class AndroidProviderBackendTest : public testing::Test {
125 public: 121 public:
126 AndroidProviderBackendTest() 122 AndroidProviderBackendTest()
127 : thumbnail_db_(NULL), 123 : thumbnail_db_(NULL),
128 profile_manager_( 124 profile_manager_(
129 TestingBrowserProcess::GetGlobal()), 125 TestingBrowserProcess::GetGlobal()),
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 EXPECT_FALSE(delegate_.deleted_details()); 514 EXPECT_FALSE(delegate_.deleted_details());
519 ASSERT_TRUE(delegate_.modified_details()); 515 ASSERT_TRUE(delegate_.modified_details());
520 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 516 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
521 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url()); 517 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url());
522 EXPECT_EQ(row1.last_visit_time(), 518 EXPECT_EQ(row1.last_visit_time(),
523 delegate_.modified_details()->changed_urls[0].last_visit()); 519 delegate_.modified_details()->changed_urls[0].last_visit());
524 EXPECT_EQ(row1.visit_count(), 520 EXPECT_EQ(row1.visit_count(),
525 delegate_.modified_details()->changed_urls[0].visit_count()); 521 delegate_.modified_details()->changed_urls[0].visit_count());
526 EXPECT_EQ(row1.title(), 522 EXPECT_EQ(row1.title(),
527 delegate_.modified_details()->changed_urls[0].title()); 523 delegate_.modified_details()->changed_urls[0].title());
528 EXPECT_FALSE(delegate_.favicon_details()); 524 EXPECT_FALSE(delegate_.favicon_changed());
529 content::RunAllPendingInMessageLoop(); 525 content::RunAllPendingInMessageLoop();
530 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 526 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
531 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 527 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
532 ASSERT_TRUE(child); 528 ASSERT_TRUE(child);
533 EXPECT_EQ(row1.title(), child->GetTitle()); 529 EXPECT_EQ(row1.title(), child->GetTitle());
534 EXPECT_EQ(row1.url(), child->url()); 530 EXPECT_EQ(row1.url(), child->url());
535 531
536 delegate_.ResetDetails(); 532 delegate_.ResetDetails();
537 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2)); 533 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2));
538 EXPECT_FALSE(delegate_.deleted_details()); 534 EXPECT_FALSE(delegate_.deleted_details());
539 ASSERT_TRUE(delegate_.modified_details()); 535 ASSERT_TRUE(delegate_.modified_details());
540 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 536 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
541 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url()); 537 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url());
542 EXPECT_EQ(row2.last_visit_time(), 538 EXPECT_EQ(row2.last_visit_time(),
543 delegate_.modified_details()->changed_urls[0].last_visit()); 539 delegate_.modified_details()->changed_urls[0].last_visit());
544 EXPECT_EQ(row2.title(), 540 EXPECT_EQ(row2.title(),
545 delegate_.modified_details()->changed_urls[0].title()); 541 delegate_.modified_details()->changed_urls[0].title());
546 ASSERT_TRUE(delegate_.favicon_details()); 542 ASSERT_TRUE(delegate_.favicon_changed());
547 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 543 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
548 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 544 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
549 delegate_.favicon_details()->urls.find(row2.url())); 545 delegate_.favicon_changed()->find(row2.url()));
550 546
551 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 547 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
552 projections.push_back(HistoryAndBookmarkRow::ID); 548 projections.push_back(HistoryAndBookmarkRow::ID);
553 projections.push_back(HistoryAndBookmarkRow::URL); 549 projections.push_back(HistoryAndBookmarkRow::URL);
554 projections.push_back(HistoryAndBookmarkRow::TITLE); 550 projections.push_back(HistoryAndBookmarkRow::TITLE);
555 projections.push_back(HistoryAndBookmarkRow::CREATED); 551 projections.push_back(HistoryAndBookmarkRow::CREATED);
556 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); 552 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME);
557 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); 553 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT);
558 projections.push_back(HistoryAndBookmarkRow::FAVICON); 554 projections.push_back(HistoryAndBookmarkRow::FAVICON);
559 projections.push_back(HistoryAndBookmarkRow::BOOKMARK); 555 projections.push_back(HistoryAndBookmarkRow::BOOKMARK);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 645
650 // Verify notifications 646 // Verify notifications
651 ASSERT_TRUE(delegate_.deleted_details()); 647 ASSERT_TRUE(delegate_.deleted_details());
652 EXPECT_FALSE(delegate_.modified_details()); 648 EXPECT_FALSE(delegate_.modified_details());
653 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size()); 649 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size());
654 EXPECT_EQ(row1.url(), delegate_.deleted_details()->rows[0].url()); 650 EXPECT_EQ(row1.url(), delegate_.deleted_details()->rows[0].url());
655 EXPECT_EQ(row1.last_visit_time(), 651 EXPECT_EQ(row1.last_visit_time(),
656 delegate_.deleted_details()->rows[0].last_visit()); 652 delegate_.deleted_details()->rows[0].last_visit());
657 EXPECT_EQ(row1.title(), 653 EXPECT_EQ(row1.title(),
658 delegate_.deleted_details()->rows[0].title()); 654 delegate_.deleted_details()->rows[0].title());
659 EXPECT_FALSE(delegate_.favicon_details()); 655 EXPECT_FALSE(delegate_.favicon_changed());
660 656
661 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 657 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
662 projections.push_back(HistoryAndBookmarkRow::ID); 658 projections.push_back(HistoryAndBookmarkRow::ID);
663 projections.push_back(HistoryAndBookmarkRow::URL); 659 projections.push_back(HistoryAndBookmarkRow::URL);
664 projections.push_back(HistoryAndBookmarkRow::TITLE); 660 projections.push_back(HistoryAndBookmarkRow::TITLE);
665 projections.push_back(HistoryAndBookmarkRow::CREATED); 661 projections.push_back(HistoryAndBookmarkRow::CREATED);
666 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); 662 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME);
667 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); 663 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT);
668 projections.push_back(HistoryAndBookmarkRow::FAVICON); 664 projections.push_back(HistoryAndBookmarkRow::FAVICON);
669 projections.push_back(HistoryAndBookmarkRow::BOOKMARK); 665 projections.push_back(HistoryAndBookmarkRow::BOOKMARK);
(...skipping 26 matching lines...) Expand all
696 std::vector<base::string16>(), &deleted_count)); 692 std::vector<base::string16>(), &deleted_count));
697 // Verify notifications 693 // Verify notifications
698 ASSERT_TRUE(delegate_.deleted_details()); 694 ASSERT_TRUE(delegate_.deleted_details());
699 EXPECT_FALSE(delegate_.modified_details()); 695 EXPECT_FALSE(delegate_.modified_details());
700 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size()); 696 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size());
701 EXPECT_EQ(row2.url(), delegate_.deleted_details()->rows[0].url()); 697 EXPECT_EQ(row2.url(), delegate_.deleted_details()->rows[0].url());
702 EXPECT_EQ(row2.last_visit_time(), 698 EXPECT_EQ(row2.last_visit_time(),
703 delegate_.deleted_details()->rows[0].last_visit()); 699 delegate_.deleted_details()->rows[0].last_visit());
704 EXPECT_EQ(row2.title(), 700 EXPECT_EQ(row2.title(),
705 delegate_.deleted_details()->rows[0].title()); 701 delegate_.deleted_details()->rows[0].title());
706 ASSERT_TRUE(delegate_.favicon_details()); 702 ASSERT_TRUE(delegate_.favicon_changed());
707 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 703 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
708 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 704 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
709 delegate_.favicon_details()->urls.find(row2.url())); 705 delegate_.favicon_changed()->find(row2.url()));
710 706
711 ASSERT_EQ(1, deleted_count); 707 ASSERT_EQ(1, deleted_count);
712 scoped_ptr<AndroidStatement> statement1(backend->QueryHistoryAndBookmarks( 708 scoped_ptr<AndroidStatement> statement1(backend->QueryHistoryAndBookmarks(
713 projections, std::string(), std::vector<base::string16>(), 709 projections, std::string(), std::vector<base::string16>(),
714 std::string("url ASC"))); 710 std::string("url ASC")));
715 ASSERT_FALSE(statement1->statement()->Step()); 711 ASSERT_FALSE(statement1->statement()->Step());
716 } 712 }
717 713
718 TEST_F(AndroidProviderBackendTest, IsValidHistoryAndBookmarkRow) { 714 TEST_F(AndroidProviderBackendTest, IsValidHistoryAndBookmarkRow) {
719 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 715 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 delegate_.deleted_details()->rows[0].title()); 867 delegate_.deleted_details()->rows[0].title());
872 ASSERT_TRUE(delegate_.modified_details()); 868 ASSERT_TRUE(delegate_.modified_details());
873 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 869 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
874 EXPECT_EQ(update_row1.url(), 870 EXPECT_EQ(update_row1.url(),
875 delegate_.modified_details()->changed_urls[0].url()); 871 delegate_.modified_details()->changed_urls[0].url());
876 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()), 872 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()),
877 ToDatabaseTime( 873 ToDatabaseTime(
878 delegate_.modified_details()->changed_urls[0].last_visit())); 874 delegate_.modified_details()->changed_urls[0].last_visit()));
879 EXPECT_EQ(row1.title(), 875 EXPECT_EQ(row1.title(),
880 delegate_.modified_details()->changed_urls[0].title()); 876 delegate_.modified_details()->changed_urls[0].title());
881 EXPECT_FALSE(delegate_.favicon_details()); 877 EXPECT_FALSE(delegate_.favicon_changed());
882 878
883 EXPECT_EQ(1, update_count); 879 EXPECT_EQ(1, update_count);
884 // We shouldn't find orignal url anymore. 880 // We shouldn't find orignal url anymore.
885 EXPECT_FALSE(history_db_.GetRowForURL(row1.url(), NULL)); 881 EXPECT_FALSE(history_db_.GetRowForURL(row1.url(), NULL));
886 visits.clear(); 882 visits.clear();
887 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id1, &visits)); 883 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id1, &visits));
888 EXPECT_EQ(0u, visits.size()); 884 EXPECT_EQ(0u, visits.size());
889 // Verify new URL. 885 // Verify new URL.
890 URLRow new_row; 886 URLRow new_row;
891 EXPECT_TRUE(history_db_.GetRowForURL(update_row1.url(), &new_row)); 887 EXPECT_TRUE(history_db_.GetRowForURL(update_row1.url(), &new_row));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 delegate_.deleted_details()->rows[0].title()); 927 delegate_.deleted_details()->rows[0].title());
932 ASSERT_TRUE(delegate_.modified_details()); 928 ASSERT_TRUE(delegate_.modified_details());
933 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 929 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
934 EXPECT_EQ(update_row2.url(), 930 EXPECT_EQ(update_row2.url(),
935 delegate_.modified_details()->changed_urls[0].url()); 931 delegate_.modified_details()->changed_urls[0].url());
936 EXPECT_EQ(ToDatabaseTime(update_row2.last_visit_time()), 932 EXPECT_EQ(ToDatabaseTime(update_row2.last_visit_time()),
937 ToDatabaseTime( 933 ToDatabaseTime(
938 delegate_.modified_details()->changed_urls[0].last_visit())); 934 delegate_.modified_details()->changed_urls[0].last_visit()));
939 EXPECT_EQ(update_row2.visit_count(), 935 EXPECT_EQ(update_row2.visit_count(),
940 delegate_.modified_details()->changed_urls[0].visit_count()); 936 delegate_.modified_details()->changed_urls[0].visit_count());
941 ASSERT_TRUE(delegate_.favicon_details()); 937 ASSERT_TRUE(delegate_.favicon_changed());
942 ASSERT_EQ(2u, delegate_.favicon_details()->urls.size()); 938 ASSERT_EQ(2u, delegate_.favicon_changed()->size());
943 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 939 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
944 delegate_.favicon_details()->urls.find(row2.url())); 940 delegate_.favicon_changed()->find(row2.url()));
945 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 941 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
946 delegate_.favicon_details()->urls.find(update_row2.url())); 942 delegate_.favicon_changed()->find(update_row2.url()));
947 943
948 EXPECT_EQ(1, update_count); 944 EXPECT_EQ(1, update_count);
949 // We shouldn't find orignal url anymore. 945 // We shouldn't find orignal url anymore.
950 EXPECT_FALSE(history_db_.GetRowForURL(row2.url(), NULL)); 946 EXPECT_FALSE(history_db_.GetRowForURL(row2.url(), NULL));
951 visits.clear(); 947 visits.clear();
952 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id2, &visits)); 948 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id2, &visits));
953 EXPECT_EQ(0u, visits.size()); 949 EXPECT_EQ(0u, visits.size());
954 950
955 // Verify new URL. 951 // Verify new URL.
956 URLRow new_row2; 952 URLRow new_row2;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 EXPECT_FALSE(delegate_.deleted_details()); 1014 EXPECT_FALSE(delegate_.deleted_details());
1019 ASSERT_TRUE(delegate_.modified_details()); 1015 ASSERT_TRUE(delegate_.modified_details());
1020 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1016 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1021 EXPECT_EQ(row1.url(), 1017 EXPECT_EQ(row1.url(),
1022 delegate_.modified_details()->changed_urls[0].url()); 1018 delegate_.modified_details()->changed_urls[0].url());
1023 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()), 1019 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()),
1024 ToDatabaseTime( 1020 ToDatabaseTime(
1025 delegate_.modified_details()->changed_urls[0].last_visit())); 1021 delegate_.modified_details()->changed_urls[0].last_visit()));
1026 EXPECT_EQ(update_row1.visit_count(), 1022 EXPECT_EQ(update_row1.visit_count(),
1027 delegate_.modified_details()->changed_urls[0].visit_count()); 1023 delegate_.modified_details()->changed_urls[0].visit_count());
1028 EXPECT_FALSE(delegate_.favicon_details()); 1024 EXPECT_FALSE(delegate_.favicon_changed());
1029 1025
1030 // All visits should be removed, and 5 new visit insertted. 1026 // All visits should be removed, and 5 new visit insertted.
1031 URLRow new_row1; 1027 URLRow new_row1;
1032 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1)); 1028 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1));
1033 EXPECT_EQ(5, new_row1.visit_count()); 1029 EXPECT_EQ(5, new_row1.visit_count());
1034 VisitVector visits; 1030 VisitVector visits;
1035 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits)); 1031 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits));
1036 ASSERT_EQ(5u, visits.size()); 1032 ASSERT_EQ(5u, visits.size());
1037 EXPECT_EQ(row1.last_visit_time(), visits[4].visit_time); 1033 EXPECT_EQ(row1.last_visit_time(), visits[4].visit_time);
1038 EXPECT_GT(row1.last_visit_time(), visits[0].visit_time); 1034 EXPECT_GT(row1.last_visit_time(), visits[0].visit_time);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 update_args, &update_count)); 1095 update_args, &update_count));
1100 // Verify notifications, Update involves modified URL. 1096 // Verify notifications, Update involves modified URL.
1101 EXPECT_FALSE(delegate_.deleted_details()); 1097 EXPECT_FALSE(delegate_.deleted_details());
1102 ASSERT_TRUE(delegate_.modified_details()); 1098 ASSERT_TRUE(delegate_.modified_details());
1103 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1099 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1104 EXPECT_EQ(row1.url(), 1100 EXPECT_EQ(row1.url(),
1105 delegate_.modified_details()->changed_urls[0].url()); 1101 delegate_.modified_details()->changed_urls[0].url());
1106 EXPECT_EQ(ToDatabaseTime(update_row1.last_visit_time()), 1102 EXPECT_EQ(ToDatabaseTime(update_row1.last_visit_time()),
1107 ToDatabaseTime( 1103 ToDatabaseTime(
1108 delegate_.modified_details()->changed_urls[0].last_visit())); 1104 delegate_.modified_details()->changed_urls[0].last_visit()));
1109 EXPECT_FALSE(delegate_.favicon_details()); 1105 EXPECT_FALSE(delegate_.favicon_changed());
1110 1106
1111 URLRow new_row1; 1107 URLRow new_row1;
1112 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1)); 1108 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1));
1113 EXPECT_EQ(11, new_row1.visit_count()); 1109 EXPECT_EQ(11, new_row1.visit_count());
1114 EXPECT_EQ(update_row1.last_visit_time(), new_row1.last_visit()); 1110 EXPECT_EQ(update_row1.last_visit_time(), new_row1.last_visit());
1115 VisitVector visits; 1111 VisitVector visits;
1116 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits)); 1112 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits));
1117 // 1 new visit insertted. 1113 // 1 new visit insertted.
1118 ASSERT_EQ(11u, visits.size()); 1114 ASSERT_EQ(11u, visits.size());
1119 EXPECT_EQ(update_row1.last_visit_time(), visits[10].visit_time); 1115 EXPECT_EQ(update_row1.last_visit_time(), visits[10].visit_time);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 std::vector<unsigned char> data; 1155 std::vector<unsigned char> data;
1160 data.push_back('1'); 1156 data.push_back('1');
1161 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data)); 1157 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data));
1162 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 1158 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
1163 delegate_.ResetDetails(); 1159 delegate_.ResetDetails();
1164 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 1160 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
1165 update_args, &update_count)); 1161 update_args, &update_count));
1166 // Verify notifications. 1162 // Verify notifications.
1167 EXPECT_FALSE(delegate_.deleted_details()); 1163 EXPECT_FALSE(delegate_.deleted_details());
1168 EXPECT_FALSE(delegate_.modified_details()); 1164 EXPECT_FALSE(delegate_.modified_details());
1169 ASSERT_TRUE(delegate_.favicon_details()); 1165 ASSERT_TRUE(delegate_.favicon_changed());
1170 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 1166 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
1171 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 1167 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
1172 delegate_.favicon_details()->urls.find(row1.url())); 1168 delegate_.favicon_changed()->find(row1.url()));
1173 1169
1174 std::vector<IconMapping> icon_mappings; 1170 std::vector<IconMapping> icon_mappings;
1175 EXPECT_TRUE(thumbnail_db_.GetIconMappingsForPageURL( 1171 EXPECT_TRUE(thumbnail_db_.GetIconMappingsForPageURL(
1176 row1.url(), favicon_base::FAVICON, &icon_mappings)); 1172 row1.url(), favicon_base::FAVICON, &icon_mappings));
1177 EXPECT_EQ(1u, icon_mappings.size()); 1173 EXPECT_EQ(1u, icon_mappings.size());
1178 std::vector<FaviconBitmap> favicon_bitmaps; 1174 std::vector<FaviconBitmap> favicon_bitmaps;
1179 EXPECT_TRUE(thumbnail_db_.GetFaviconBitmaps(icon_mappings[0].icon_id, 1175 EXPECT_TRUE(thumbnail_db_.GetFaviconBitmaps(icon_mappings[0].icon_id,
1180 &favicon_bitmaps)); 1176 &favicon_bitmaps));
1181 EXPECT_EQ(1u, favicon_bitmaps.size()); 1177 EXPECT_EQ(1u, favicon_bitmaps.size());
1182 EXPECT_TRUE(favicon_bitmaps[0].bitmap_data.get()); 1178 EXPECT_TRUE(favicon_bitmaps[0].bitmap_data.get());
1183 EXPECT_EQ(1u, favicon_bitmaps[0].bitmap_data->size()); 1179 EXPECT_EQ(1u, favicon_bitmaps[0].bitmap_data->size());
1184 EXPECT_EQ('1', *favicon_bitmaps[0].bitmap_data->front()); 1180 EXPECT_EQ('1', *favicon_bitmaps[0].bitmap_data->front());
1185 1181
1186 // Remove favicon. 1182 // Remove favicon.
1187 HistoryAndBookmarkRow update_row2; 1183 HistoryAndBookmarkRow update_row2;
1188 1184
1189 // Set favicon. 1185 // Set favicon.
1190 update_row1.set_favicon(new base::RefCountedBytes()); 1186 update_row1.set_favicon(new base::RefCountedBytes());
1191 update_args.clear(); 1187 update_args.clear();
1192 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 1188 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
1193 delegate_.ResetDetails(); 1189 delegate_.ResetDetails();
1194 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 1190 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
1195 update_args, &update_count)); 1191 update_args, &update_count));
1196 // Verify notifications. 1192 // Verify notifications.
1197 EXPECT_FALSE(delegate_.deleted_details()); 1193 EXPECT_FALSE(delegate_.deleted_details());
1198 EXPECT_FALSE(delegate_.modified_details()); 1194 EXPECT_FALSE(delegate_.modified_details());
1199 ASSERT_TRUE(delegate_.favicon_details()); 1195 ASSERT_TRUE(delegate_.favicon_changed());
1200 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 1196 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
1201 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 1197 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
1202 delegate_.favicon_details()->urls.find(row1.url())); 1198 delegate_.favicon_changed()->find(row1.url()));
1203 1199
1204 EXPECT_FALSE(thumbnail_db_.GetIconMappingsForPageURL( 1200 EXPECT_FALSE(thumbnail_db_.GetIconMappingsForPageURL(
1205 row1.url(), favicon_base::FAVICON, NULL)); 1201 row1.url(), favicon_base::FAVICON, NULL));
1206 } 1202 }
1207 1203
1208 TEST_F(AndroidProviderBackendTest, UpdateSearchTermTable) { 1204 TEST_F(AndroidProviderBackendTest, UpdateSearchTermTable) {
1209 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 1205 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
1210 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_)); 1206 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_));
1211 scoped_ptr<AndroidProviderBackend> backend( 1207 scoped_ptr<AndroidProviderBackend> backend(
1212 new AndroidProviderBackend(android_cache_db_name_, 1208 new AndroidProviderBackend(android_cache_db_name_,
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 EXPECT_EQ(row1.title(), child1->GetTitle()); 1638 EXPECT_EQ(row1.title(), child1->GetTitle());
1643 EXPECT_EQ(row1.url(), child1->url()); 1639 EXPECT_EQ(row1.url(), child1->url());
1644 1640
1645 // Verify notification 1641 // Verify notification
1646 ASSERT_TRUE(delegate_.deleted_details()); 1642 ASSERT_TRUE(delegate_.deleted_details());
1647 ASSERT_EQ(2u, delegate_.deleted_details()->rows.size()); 1643 ASSERT_EQ(2u, delegate_.deleted_details()->rows.size());
1648 EXPECT_EQ(row1.url(), 1644 EXPECT_EQ(row1.url(),
1649 delegate_.modified_details()->changed_urls[0].url()); 1645 delegate_.modified_details()->changed_urls[0].url());
1650 EXPECT_EQ(Time::UnixEpoch(), 1646 EXPECT_EQ(Time::UnixEpoch(),
1651 delegate_.modified_details()->changed_urls[0].last_visit()); 1647 delegate_.modified_details()->changed_urls[0].last_visit());
1652 EXPECT_EQ(1u, delegate_.favicon_details()->urls.size()); 1648 EXPECT_EQ(1u, delegate_.favicon_changed()->size());
1653 } 1649 }
1654 1650
1655 TEST_F(AndroidProviderBackendTest, TestMultipleNestingTransaction) { 1651 TEST_F(AndroidProviderBackendTest, TestMultipleNestingTransaction) {
1656 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 1652 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
1657 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_)); 1653 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_));
1658 scoped_ptr<AndroidProviderBackend> backend( 1654 scoped_ptr<AndroidProviderBackend> backend(
1659 new AndroidProviderBackend(android_cache_db_name_, 1655 new AndroidProviderBackend(android_cache_db_name_,
1660 &history_db_, 1656 &history_db_,
1661 &thumbnail_db_, 1657 &thumbnail_db_,
1662 history_client_, 1658 history_client_,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 EXPECT_FALSE(delegate_.deleted_details()); 1936 EXPECT_FALSE(delegate_.deleted_details());
1941 ASSERT_TRUE(delegate_.modified_details()); 1937 ASSERT_TRUE(delegate_.modified_details());
1942 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1938 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1943 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url()); 1939 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url());
1944 EXPECT_EQ(row1.last_visit_time(), 1940 EXPECT_EQ(row1.last_visit_time(),
1945 delegate_.modified_details()->changed_urls[0].last_visit()); 1941 delegate_.modified_details()->changed_urls[0].last_visit());
1946 EXPECT_EQ(row1.visit_count(), 1942 EXPECT_EQ(row1.visit_count(),
1947 delegate_.modified_details()->changed_urls[0].visit_count()); 1943 delegate_.modified_details()->changed_urls[0].visit_count());
1948 EXPECT_EQ(row1.title(), 1944 EXPECT_EQ(row1.title(),
1949 delegate_.modified_details()->changed_urls[0].title()); 1945 delegate_.modified_details()->changed_urls[0].title());
1950 EXPECT_FALSE(delegate_.favicon_details()); 1946 EXPECT_FALSE(delegate_.favicon_changed());
1951 content::RunAllPendingInMessageLoop(); 1947 content::RunAllPendingInMessageLoop();
1952 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 1948 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
1953 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 1949 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
1954 ASSERT_TRUE(child); 1950 ASSERT_TRUE(child);
1955 EXPECT_EQ(row1.title(), child->GetTitle()); 1951 EXPECT_EQ(row1.title(), child->GetTitle());
1956 EXPECT_EQ(row1.url(), child->url()); 1952 EXPECT_EQ(row1.url(), child->url());
1957 1953
1958 delegate_.ResetDetails(); 1954 delegate_.ResetDetails();
1959 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2)); 1955 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2));
1960 EXPECT_FALSE(delegate_.deleted_details()); 1956 EXPECT_FALSE(delegate_.deleted_details());
1961 ASSERT_TRUE(delegate_.modified_details()); 1957 ASSERT_TRUE(delegate_.modified_details());
1962 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1958 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1963 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url()); 1959 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url());
1964 EXPECT_EQ(row2.last_visit_time(), 1960 EXPECT_EQ(row2.last_visit_time(),
1965 delegate_.modified_details()->changed_urls[0].last_visit()); 1961 delegate_.modified_details()->changed_urls[0].last_visit());
1966 EXPECT_EQ(row2.title(), 1962 EXPECT_EQ(row2.title(),
1967 delegate_.modified_details()->changed_urls[0].title()); 1963 delegate_.modified_details()->changed_urls[0].title());
1968 // Favicon details is still false because thumbnail database wasn't 1964 // Favicon details is still false because thumbnail database wasn't
1969 // initialized, we ignore any changes of favicon. 1965 // initialized, we ignore any changes of favicon.
1970 ASSERT_FALSE(delegate_.favicon_details()); 1966 ASSERT_FALSE(delegate_.favicon_changed());
1971 } 1967 }
1972 1968
1973 TEST_F(AndroidProviderBackendTest, DeleteWithoutThumbnailDB) { 1969 TEST_F(AndroidProviderBackendTest, DeleteWithoutThumbnailDB) {
1974 HistoryAndBookmarkRow row1; 1970 HistoryAndBookmarkRow row1;
1975 row1.set_raw_url("cnn.com"); 1971 row1.set_raw_url("cnn.com");
1976 row1.set_url(GURL("http://cnn.com")); 1972 row1.set_url(GURL("http://cnn.com"));
1977 row1.set_last_visit_time(Time::Now() - TimeDelta::FromDays(1)); 1973 row1.set_last_visit_time(Time::Now() - TimeDelta::FromDays(1));
1978 row1.set_created(Time::Now() - TimeDelta::FromDays(20)); 1974 row1.set_created(Time::Now() - TimeDelta::FromDays(20));
1979 row1.set_visit_count(10); 1975 row1.set_visit_count(10);
1980 row1.set_is_bookmark(true); 1976 row1.set_is_bookmark(true);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 EXPECT_EQ(2, deleted_count); 2027 EXPECT_EQ(2, deleted_count);
2032 // Verify the rows was removed from bookmark model. 2028 // Verify the rows was removed from bookmark model.
2033 content::RunAllPendingInMessageLoop(); 2029 content::RunAllPendingInMessageLoop();
2034 ASSERT_EQ(0, bookmark_model_->mobile_node()->child_count()); 2030 ASSERT_EQ(0, bookmark_model_->mobile_node()->child_count());
2035 2031
2036 // Verify notifications 2032 // Verify notifications
2037 ASSERT_TRUE(delegate_.deleted_details()); 2033 ASSERT_TRUE(delegate_.deleted_details());
2038 EXPECT_FALSE(delegate_.modified_details()); 2034 EXPECT_FALSE(delegate_.modified_details());
2039 EXPECT_EQ(2u, delegate_.deleted_details()->rows.size()); 2035 EXPECT_EQ(2u, delegate_.deleted_details()->rows.size());
2040 // No favicon has been deleted. 2036 // No favicon has been deleted.
2041 EXPECT_FALSE(delegate_.favicon_details()); 2037 EXPECT_FALSE(delegate_.favicon_changed());
2042 2038
2043 // No row exists. 2039 // No row exists.
2044 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 2040 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
2045 projections.push_back(HistoryAndBookmarkRow::ID); 2041 projections.push_back(HistoryAndBookmarkRow::ID);
2046 projections.push_back(HistoryAndBookmarkRow::URL); 2042 projections.push_back(HistoryAndBookmarkRow::URL);
2047 projections.push_back(HistoryAndBookmarkRow::TITLE); 2043 projections.push_back(HistoryAndBookmarkRow::TITLE);
2048 projections.push_back(HistoryAndBookmarkRow::CREATED); 2044 projections.push_back(HistoryAndBookmarkRow::CREATED);
2049 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); 2045 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME);
2050 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); 2046 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT);
2051 projections.push_back(HistoryAndBookmarkRow::FAVICON); 2047 projections.push_back(HistoryAndBookmarkRow::FAVICON);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data)); 2100 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data));
2105 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 2101 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
2106 delegate_.ResetDetails(); 2102 delegate_.ResetDetails();
2107 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 2103 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
2108 update_args, &update_count)); 2104 update_args, &update_count));
2109 // Verify notifications. 2105 // Verify notifications.
2110 EXPECT_FALSE(delegate_.deleted_details()); 2106 EXPECT_FALSE(delegate_.deleted_details());
2111 ASSERT_TRUE(delegate_.modified_details()); 2107 ASSERT_TRUE(delegate_.modified_details());
2112 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 2108 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
2113 // No favicon will be updated as thumbnail database is missing. 2109 // No favicon will be updated as thumbnail database is missing.
2114 EXPECT_FALSE(delegate_.favicon_details()); 2110 EXPECT_FALSE(delegate_.favicon_changed());
2115 } 2111 }
2116 2112
2117 } // namespace history 2113 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/android/android_provider_backend.cc ('k') | chrome/browser/history/history_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698