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

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 compilation Created 6 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_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.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 29 matching lines...) Expand all
57 56
58 } // namespace 57 } // namespace
59 58
60 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate { 59 class AndroidProviderBackendDelegate : public HistoryBackend::Delegate {
61 public: 60 public:
62 AndroidProviderBackendDelegate() {} 61 AndroidProviderBackendDelegate() {}
63 62
64 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} 63 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {}
65 virtual void SetInMemoryBackend( 64 virtual void SetInMemoryBackend(
66 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE {} 65 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE {}
66 virtual void NotifyFaviconChanged(const std::set<GURL>& url) OVERRIDE {
67 favicon_changed_.reset(new std::set<GURL>(url.begin(), url.end()));
68 }
67 virtual void BroadcastNotifications( 69 virtual void BroadcastNotifications(
68 int type, 70 int type,
69 scoped_ptr<HistoryDetails> details) OVERRIDE { 71 scoped_ptr<HistoryDetails> details) OVERRIDE {
70 switch (type) { 72 switch (type) {
71 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: 73 case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
72 deleted_details_.reset( 74 deleted_details_.reset(
73 static_cast<URLsDeletedDetails*>(details.release())); 75 static_cast<URLsDeletedDetails*>(details.release()));
74 break; 76 break;
75 case chrome::NOTIFICATION_FAVICON_CHANGED:
76 favicon_details_.reset(
77 static_cast<FaviconChangedDetails*>(details.release()));
78 break;
79 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: 77 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED:
80 modified_details_.reset( 78 modified_details_.reset(
81 static_cast<URLsModifiedDetails*>(details.release())); 79 static_cast<URLsModifiedDetails*>(details.release()));
82 break; 80 break;
81 default:
82 NOTREACHED() << "Unexpected notification type: " << type;
83 } 83 }
84 } 84 }
85 virtual void DBLoaded() OVERRIDE {} 85 virtual void DBLoaded() OVERRIDE {}
86 virtual void NotifyVisitDBObserversOnAddVisit( 86 virtual void NotifyVisitDBObserversOnAddVisit(
87 const history::BriefVisitInfo& info) OVERRIDE {} 87 const history::BriefVisitInfo& info) OVERRIDE {}
88 88
89 URLsDeletedDetails* deleted_details() const { 89 URLsDeletedDetails* deleted_details() const {
90 return deleted_details_.get(); 90 return deleted_details_.get();
91 } 91 }
92 92
93 URLsModifiedDetails* modified_details() const { 93 URLsModifiedDetails* modified_details() const {
94 return modified_details_.get(); 94 return modified_details_.get();
95 } 95 }
96 96
97 FaviconChangedDetails* favicon_details() const { 97 std::set<GURL>* favicon_changed() const { return favicon_changed_.get(); }
98 return favicon_details_.get();
99 }
100 98
101 void ResetDetails() { 99 void ResetDetails() {
102 deleted_details_.reset(); 100 deleted_details_.reset();
103 modified_details_.reset(); 101 modified_details_.reset();
104 favicon_details_.reset(); 102 favicon_changed_.reset();
105 } 103 }
106 104
107 private: 105 private:
108 scoped_ptr<URLsDeletedDetails> deleted_details_; 106 scoped_ptr<URLsDeletedDetails> deleted_details_;
109 scoped_ptr<URLsModifiedDetails> modified_details_; 107 scoped_ptr<URLsModifiedDetails> modified_details_;
110 scoped_ptr<FaviconChangedDetails> favicon_details_; 108 scoped_ptr<std::set<GURL>> favicon_changed_;
brettw 2014/09/02 23:23:10 Ditto on >>
sdefresne 2014/09/03 10:00:01 Done.
111 109
112 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendDelegate); 110 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendDelegate);
113 }; 111 };
114 112
115 class AndroidProviderBackendTest : public testing::Test { 113 class AndroidProviderBackendTest : public testing::Test {
116 public: 114 public:
117 AndroidProviderBackendTest() 115 AndroidProviderBackendTest()
118 : thumbnail_db_(NULL), 116 : thumbnail_db_(NULL),
119 profile_manager_( 117 profile_manager_(
120 TestingBrowserProcess::GetGlobal()), 118 TestingBrowserProcess::GetGlobal()),
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 EXPECT_FALSE(delegate_.deleted_details()); 525 EXPECT_FALSE(delegate_.deleted_details());
528 ASSERT_TRUE(delegate_.modified_details()); 526 ASSERT_TRUE(delegate_.modified_details());
529 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 527 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
530 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url()); 528 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url());
531 EXPECT_EQ(row1.last_visit_time(), 529 EXPECT_EQ(row1.last_visit_time(),
532 delegate_.modified_details()->changed_urls[0].last_visit()); 530 delegate_.modified_details()->changed_urls[0].last_visit());
533 EXPECT_EQ(row1.visit_count(), 531 EXPECT_EQ(row1.visit_count(),
534 delegate_.modified_details()->changed_urls[0].visit_count()); 532 delegate_.modified_details()->changed_urls[0].visit_count());
535 EXPECT_EQ(row1.title(), 533 EXPECT_EQ(row1.title(),
536 delegate_.modified_details()->changed_urls[0].title()); 534 delegate_.modified_details()->changed_urls[0].title());
537 EXPECT_FALSE(delegate_.favicon_details()); 535 EXPECT_FALSE(delegate_.favicon_changed());
538 content::RunAllPendingInMessageLoop(); 536 content::RunAllPendingInMessageLoop();
539 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 537 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
540 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 538 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
541 ASSERT_TRUE(child); 539 ASSERT_TRUE(child);
542 EXPECT_EQ(row1.title(), child->GetTitle()); 540 EXPECT_EQ(row1.title(), child->GetTitle());
543 EXPECT_EQ(row1.url(), child->url()); 541 EXPECT_EQ(row1.url(), child->url());
544 542
545 delegate_.ResetDetails(); 543 delegate_.ResetDetails();
546 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2)); 544 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2));
547 EXPECT_FALSE(delegate_.deleted_details()); 545 EXPECT_FALSE(delegate_.deleted_details());
548 ASSERT_TRUE(delegate_.modified_details()); 546 ASSERT_TRUE(delegate_.modified_details());
549 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 547 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
550 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url()); 548 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url());
551 EXPECT_EQ(row2.last_visit_time(), 549 EXPECT_EQ(row2.last_visit_time(),
552 delegate_.modified_details()->changed_urls[0].last_visit()); 550 delegate_.modified_details()->changed_urls[0].last_visit());
553 EXPECT_EQ(row2.title(), 551 EXPECT_EQ(row2.title(),
554 delegate_.modified_details()->changed_urls[0].title()); 552 delegate_.modified_details()->changed_urls[0].title());
555 ASSERT_TRUE(delegate_.favicon_details()); 553 ASSERT_TRUE(delegate_.favicon_changed());
556 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 554 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
557 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 555 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
558 delegate_.favicon_details()->urls.find(row2.url())); 556 delegate_.favicon_changed()->find(row2.url()));
559 557
560 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 558 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
561 projections.push_back(HistoryAndBookmarkRow::ID); 559 projections.push_back(HistoryAndBookmarkRow::ID);
562 projections.push_back(HistoryAndBookmarkRow::URL); 560 projections.push_back(HistoryAndBookmarkRow::URL);
563 projections.push_back(HistoryAndBookmarkRow::TITLE); 561 projections.push_back(HistoryAndBookmarkRow::TITLE);
564 projections.push_back(HistoryAndBookmarkRow::CREATED); 562 projections.push_back(HistoryAndBookmarkRow::CREATED);
565 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); 563 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME);
566 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); 564 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT);
567 projections.push_back(HistoryAndBookmarkRow::FAVICON); 565 projections.push_back(HistoryAndBookmarkRow::FAVICON);
568 projections.push_back(HistoryAndBookmarkRow::BOOKMARK); 566 projections.push_back(HistoryAndBookmarkRow::BOOKMARK);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 656
659 // Verify notifications 657 // Verify notifications
660 ASSERT_TRUE(delegate_.deleted_details()); 658 ASSERT_TRUE(delegate_.deleted_details());
661 EXPECT_FALSE(delegate_.modified_details()); 659 EXPECT_FALSE(delegate_.modified_details());
662 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size()); 660 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size());
663 EXPECT_EQ(row1.url(), delegate_.deleted_details()->rows[0].url()); 661 EXPECT_EQ(row1.url(), delegate_.deleted_details()->rows[0].url());
664 EXPECT_EQ(row1.last_visit_time(), 662 EXPECT_EQ(row1.last_visit_time(),
665 delegate_.deleted_details()->rows[0].last_visit()); 663 delegate_.deleted_details()->rows[0].last_visit());
666 EXPECT_EQ(row1.title(), 664 EXPECT_EQ(row1.title(),
667 delegate_.deleted_details()->rows[0].title()); 665 delegate_.deleted_details()->rows[0].title());
668 EXPECT_FALSE(delegate_.favicon_details()); 666 EXPECT_FALSE(delegate_.favicon_changed());
669 667
670 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 668 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
671 projections.push_back(HistoryAndBookmarkRow::ID); 669 projections.push_back(HistoryAndBookmarkRow::ID);
672 projections.push_back(HistoryAndBookmarkRow::URL); 670 projections.push_back(HistoryAndBookmarkRow::URL);
673 projections.push_back(HistoryAndBookmarkRow::TITLE); 671 projections.push_back(HistoryAndBookmarkRow::TITLE);
674 projections.push_back(HistoryAndBookmarkRow::CREATED); 672 projections.push_back(HistoryAndBookmarkRow::CREATED);
675 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); 673 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME);
676 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); 674 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT);
677 projections.push_back(HistoryAndBookmarkRow::FAVICON); 675 projections.push_back(HistoryAndBookmarkRow::FAVICON);
678 projections.push_back(HistoryAndBookmarkRow::BOOKMARK); 676 projections.push_back(HistoryAndBookmarkRow::BOOKMARK);
(...skipping 26 matching lines...) Expand all
705 std::vector<base::string16>(), &deleted_count)); 703 std::vector<base::string16>(), &deleted_count));
706 // Verify notifications 704 // Verify notifications
707 ASSERT_TRUE(delegate_.deleted_details()); 705 ASSERT_TRUE(delegate_.deleted_details());
708 EXPECT_FALSE(delegate_.modified_details()); 706 EXPECT_FALSE(delegate_.modified_details());
709 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size()); 707 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size());
710 EXPECT_EQ(row2.url(), delegate_.deleted_details()->rows[0].url()); 708 EXPECT_EQ(row2.url(), delegate_.deleted_details()->rows[0].url());
711 EXPECT_EQ(row2.last_visit_time(), 709 EXPECT_EQ(row2.last_visit_time(),
712 delegate_.deleted_details()->rows[0].last_visit()); 710 delegate_.deleted_details()->rows[0].last_visit());
713 EXPECT_EQ(row2.title(), 711 EXPECT_EQ(row2.title(),
714 delegate_.deleted_details()->rows[0].title()); 712 delegate_.deleted_details()->rows[0].title());
715 ASSERT_TRUE(delegate_.favicon_details()); 713 ASSERT_TRUE(delegate_.favicon_changed());
716 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 714 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
717 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 715 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
718 delegate_.favicon_details()->urls.find(row2.url())); 716 delegate_.favicon_changed()->find(row2.url()));
719 717
720 ASSERT_EQ(1, deleted_count); 718 ASSERT_EQ(1, deleted_count);
721 scoped_ptr<AndroidStatement> statement1(backend->QueryHistoryAndBookmarks( 719 scoped_ptr<AndroidStatement> statement1(backend->QueryHistoryAndBookmarks(
722 projections, std::string(), std::vector<base::string16>(), 720 projections, std::string(), std::vector<base::string16>(),
723 std::string("url ASC"))); 721 std::string("url ASC")));
724 ASSERT_FALSE(statement1->statement()->Step()); 722 ASSERT_FALSE(statement1->statement()->Step());
725 } 723 }
726 724
727 TEST_F(AndroidProviderBackendTest, IsValidHistoryAndBookmarkRow) { 725 TEST_F(AndroidProviderBackendTest, IsValidHistoryAndBookmarkRow) {
728 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 726 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 delegate_.deleted_details()->rows[0].title()); 878 delegate_.deleted_details()->rows[0].title());
881 ASSERT_TRUE(delegate_.modified_details()); 879 ASSERT_TRUE(delegate_.modified_details());
882 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 880 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
883 EXPECT_EQ(update_row1.url(), 881 EXPECT_EQ(update_row1.url(),
884 delegate_.modified_details()->changed_urls[0].url()); 882 delegate_.modified_details()->changed_urls[0].url());
885 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()), 883 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()),
886 ToDatabaseTime( 884 ToDatabaseTime(
887 delegate_.modified_details()->changed_urls[0].last_visit())); 885 delegate_.modified_details()->changed_urls[0].last_visit()));
888 EXPECT_EQ(row1.title(), 886 EXPECT_EQ(row1.title(),
889 delegate_.modified_details()->changed_urls[0].title()); 887 delegate_.modified_details()->changed_urls[0].title());
890 EXPECT_FALSE(delegate_.favicon_details()); 888 EXPECT_FALSE(delegate_.favicon_changed());
891 889
892 EXPECT_EQ(1, update_count); 890 EXPECT_EQ(1, update_count);
893 // We shouldn't find orignal url anymore. 891 // We shouldn't find orignal url anymore.
894 EXPECT_FALSE(history_db_.GetRowForURL(row1.url(), NULL)); 892 EXPECT_FALSE(history_db_.GetRowForURL(row1.url(), NULL));
895 visits.clear(); 893 visits.clear();
896 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id1, &visits)); 894 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id1, &visits));
897 EXPECT_EQ(0u, visits.size()); 895 EXPECT_EQ(0u, visits.size());
898 // Verify new URL. 896 // Verify new URL.
899 URLRow new_row; 897 URLRow new_row;
900 EXPECT_TRUE(history_db_.GetRowForURL(update_row1.url(), &new_row)); 898 EXPECT_TRUE(history_db_.GetRowForURL(update_row1.url(), &new_row));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 delegate_.deleted_details()->rows[0].title()); 938 delegate_.deleted_details()->rows[0].title());
941 ASSERT_TRUE(delegate_.modified_details()); 939 ASSERT_TRUE(delegate_.modified_details());
942 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 940 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
943 EXPECT_EQ(update_row2.url(), 941 EXPECT_EQ(update_row2.url(),
944 delegate_.modified_details()->changed_urls[0].url()); 942 delegate_.modified_details()->changed_urls[0].url());
945 EXPECT_EQ(ToDatabaseTime(update_row2.last_visit_time()), 943 EXPECT_EQ(ToDatabaseTime(update_row2.last_visit_time()),
946 ToDatabaseTime( 944 ToDatabaseTime(
947 delegate_.modified_details()->changed_urls[0].last_visit())); 945 delegate_.modified_details()->changed_urls[0].last_visit()));
948 EXPECT_EQ(update_row2.visit_count(), 946 EXPECT_EQ(update_row2.visit_count(),
949 delegate_.modified_details()->changed_urls[0].visit_count()); 947 delegate_.modified_details()->changed_urls[0].visit_count());
950 ASSERT_TRUE(delegate_.favicon_details()); 948 ASSERT_TRUE(delegate_.favicon_changed());
951 ASSERT_EQ(2u, delegate_.favicon_details()->urls.size()); 949 ASSERT_EQ(2u, delegate_.favicon_changed()->size());
952 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 950 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
953 delegate_.favicon_details()->urls.find(row2.url())); 951 delegate_.favicon_changed()->find(row2.url()));
954 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 952 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
955 delegate_.favicon_details()->urls.find(update_row2.url())); 953 delegate_.favicon_changed()->find(update_row2.url()));
956 954
957 EXPECT_EQ(1, update_count); 955 EXPECT_EQ(1, update_count);
958 // We shouldn't find orignal url anymore. 956 // We shouldn't find orignal url anymore.
959 EXPECT_FALSE(history_db_.GetRowForURL(row2.url(), NULL)); 957 EXPECT_FALSE(history_db_.GetRowForURL(row2.url(), NULL));
960 visits.clear(); 958 visits.clear();
961 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id2, &visits)); 959 EXPECT_TRUE(history_db_.GetVisitsForURL(url_id2, &visits));
962 EXPECT_EQ(0u, visits.size()); 960 EXPECT_EQ(0u, visits.size());
963 961
964 // Verify new URL. 962 // Verify new URL.
965 URLRow new_row2; 963 URLRow new_row2;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 EXPECT_FALSE(delegate_.deleted_details()); 1025 EXPECT_FALSE(delegate_.deleted_details());
1028 ASSERT_TRUE(delegate_.modified_details()); 1026 ASSERT_TRUE(delegate_.modified_details());
1029 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1027 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1030 EXPECT_EQ(row1.url(), 1028 EXPECT_EQ(row1.url(),
1031 delegate_.modified_details()->changed_urls[0].url()); 1029 delegate_.modified_details()->changed_urls[0].url());
1032 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()), 1030 EXPECT_EQ(ToDatabaseTime(row1.last_visit_time()),
1033 ToDatabaseTime( 1031 ToDatabaseTime(
1034 delegate_.modified_details()->changed_urls[0].last_visit())); 1032 delegate_.modified_details()->changed_urls[0].last_visit()));
1035 EXPECT_EQ(update_row1.visit_count(), 1033 EXPECT_EQ(update_row1.visit_count(),
1036 delegate_.modified_details()->changed_urls[0].visit_count()); 1034 delegate_.modified_details()->changed_urls[0].visit_count());
1037 EXPECT_FALSE(delegate_.favicon_details()); 1035 EXPECT_FALSE(delegate_.favicon_changed());
1038 1036
1039 // All visits should be removed, and 5 new visit insertted. 1037 // All visits should be removed, and 5 new visit insertted.
1040 URLRow new_row1; 1038 URLRow new_row1;
1041 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1)); 1039 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1));
1042 EXPECT_EQ(5, new_row1.visit_count()); 1040 EXPECT_EQ(5, new_row1.visit_count());
1043 VisitVector visits; 1041 VisitVector visits;
1044 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits)); 1042 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits));
1045 ASSERT_EQ(5u, visits.size()); 1043 ASSERT_EQ(5u, visits.size());
1046 EXPECT_EQ(row1.last_visit_time(), visits[4].visit_time); 1044 EXPECT_EQ(row1.last_visit_time(), visits[4].visit_time);
1047 EXPECT_GT(row1.last_visit_time(), visits[0].visit_time); 1045 EXPECT_GT(row1.last_visit_time(), visits[0].visit_time);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 update_args, &update_count)); 1106 update_args, &update_count));
1109 // Verify notifications, Update involves modified URL. 1107 // Verify notifications, Update involves modified URL.
1110 EXPECT_FALSE(delegate_.deleted_details()); 1108 EXPECT_FALSE(delegate_.deleted_details());
1111 ASSERT_TRUE(delegate_.modified_details()); 1109 ASSERT_TRUE(delegate_.modified_details());
1112 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1110 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1113 EXPECT_EQ(row1.url(), 1111 EXPECT_EQ(row1.url(),
1114 delegate_.modified_details()->changed_urls[0].url()); 1112 delegate_.modified_details()->changed_urls[0].url());
1115 EXPECT_EQ(ToDatabaseTime(update_row1.last_visit_time()), 1113 EXPECT_EQ(ToDatabaseTime(update_row1.last_visit_time()),
1116 ToDatabaseTime( 1114 ToDatabaseTime(
1117 delegate_.modified_details()->changed_urls[0].last_visit())); 1115 delegate_.modified_details()->changed_urls[0].last_visit()));
1118 EXPECT_FALSE(delegate_.favicon_details()); 1116 EXPECT_FALSE(delegate_.favicon_changed());
1119 1117
1120 URLRow new_row1; 1118 URLRow new_row1;
1121 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1)); 1119 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &new_row1));
1122 EXPECT_EQ(11, new_row1.visit_count()); 1120 EXPECT_EQ(11, new_row1.visit_count());
1123 EXPECT_EQ(update_row1.last_visit_time(), new_row1.last_visit()); 1121 EXPECT_EQ(update_row1.last_visit_time(), new_row1.last_visit());
1124 VisitVector visits; 1122 VisitVector visits;
1125 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits)); 1123 ASSERT_TRUE(history_db_.GetVisitsForURL(new_row1.id(), &visits));
1126 // 1 new visit insertted. 1124 // 1 new visit insertted.
1127 ASSERT_EQ(11u, visits.size()); 1125 ASSERT_EQ(11u, visits.size());
1128 EXPECT_EQ(update_row1.last_visit_time(), visits[10].visit_time); 1126 EXPECT_EQ(update_row1.last_visit_time(), visits[10].visit_time);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 std::vector<unsigned char> data; 1166 std::vector<unsigned char> data;
1169 data.push_back('1'); 1167 data.push_back('1');
1170 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data)); 1168 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data));
1171 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 1169 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
1172 delegate_.ResetDetails(); 1170 delegate_.ResetDetails();
1173 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 1171 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
1174 update_args, &update_count)); 1172 update_args, &update_count));
1175 // Verify notifications. 1173 // Verify notifications.
1176 EXPECT_FALSE(delegate_.deleted_details()); 1174 EXPECT_FALSE(delegate_.deleted_details());
1177 EXPECT_FALSE(delegate_.modified_details()); 1175 EXPECT_FALSE(delegate_.modified_details());
1178 ASSERT_TRUE(delegate_.favicon_details()); 1176 ASSERT_TRUE(delegate_.favicon_changed());
1179 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 1177 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
1180 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 1178 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
1181 delegate_.favicon_details()->urls.find(row1.url())); 1179 delegate_.favicon_changed()->find(row1.url()));
1182 1180
1183 std::vector<IconMapping> icon_mappings; 1181 std::vector<IconMapping> icon_mappings;
1184 EXPECT_TRUE(thumbnail_db_.GetIconMappingsForPageURL( 1182 EXPECT_TRUE(thumbnail_db_.GetIconMappingsForPageURL(
1185 row1.url(), favicon_base::FAVICON, &icon_mappings)); 1183 row1.url(), favicon_base::FAVICON, &icon_mappings));
1186 EXPECT_EQ(1u, icon_mappings.size()); 1184 EXPECT_EQ(1u, icon_mappings.size());
1187 std::vector<FaviconBitmap> favicon_bitmaps; 1185 std::vector<FaviconBitmap> favicon_bitmaps;
1188 EXPECT_TRUE(thumbnail_db_.GetFaviconBitmaps(icon_mappings[0].icon_id, 1186 EXPECT_TRUE(thumbnail_db_.GetFaviconBitmaps(icon_mappings[0].icon_id,
1189 &favicon_bitmaps)); 1187 &favicon_bitmaps));
1190 EXPECT_EQ(1u, favicon_bitmaps.size()); 1188 EXPECT_EQ(1u, favicon_bitmaps.size());
1191 EXPECT_TRUE(favicon_bitmaps[0].bitmap_data.get()); 1189 EXPECT_TRUE(favicon_bitmaps[0].bitmap_data.get());
1192 EXPECT_EQ(1u, favicon_bitmaps[0].bitmap_data->size()); 1190 EXPECT_EQ(1u, favicon_bitmaps[0].bitmap_data->size());
1193 EXPECT_EQ('1', *favicon_bitmaps[0].bitmap_data->front()); 1191 EXPECT_EQ('1', *favicon_bitmaps[0].bitmap_data->front());
1194 1192
1195 // Remove favicon. 1193 // Remove favicon.
1196 HistoryAndBookmarkRow update_row2; 1194 HistoryAndBookmarkRow update_row2;
1197 1195
1198 // Set favicon. 1196 // Set favicon.
1199 update_row1.set_favicon(new base::RefCountedBytes()); 1197 update_row1.set_favicon(new base::RefCountedBytes());
1200 update_args.clear(); 1198 update_args.clear();
1201 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 1199 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
1202 delegate_.ResetDetails(); 1200 delegate_.ResetDetails();
1203 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 1201 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
1204 update_args, &update_count)); 1202 update_args, &update_count));
1205 // Verify notifications. 1203 // Verify notifications.
1206 EXPECT_FALSE(delegate_.deleted_details()); 1204 EXPECT_FALSE(delegate_.deleted_details());
1207 EXPECT_FALSE(delegate_.modified_details()); 1205 EXPECT_FALSE(delegate_.modified_details());
1208 ASSERT_TRUE(delegate_.favicon_details()); 1206 ASSERT_TRUE(delegate_.favicon_changed());
1209 ASSERT_EQ(1u, delegate_.favicon_details()->urls.size()); 1207 ASSERT_EQ(1u, delegate_.favicon_changed()->size());
1210 ASSERT_TRUE(delegate_.favicon_details()->urls.end() != 1208 ASSERT_TRUE(delegate_.favicon_changed()->end() !=
1211 delegate_.favicon_details()->urls.find(row1.url())); 1209 delegate_.favicon_changed()->find(row1.url()));
1212 1210
1213 EXPECT_FALSE(thumbnail_db_.GetIconMappingsForPageURL( 1211 EXPECT_FALSE(thumbnail_db_.GetIconMappingsForPageURL(
1214 row1.url(), favicon_base::FAVICON, NULL)); 1212 row1.url(), favicon_base::FAVICON, NULL));
1215 } 1213 }
1216 1214
1217 TEST_F(AndroidProviderBackendTest, UpdateSearchTermTable) { 1215 TEST_F(AndroidProviderBackendTest, UpdateSearchTermTable) {
1218 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 1216 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
1219 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_)); 1217 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_));
1220 scoped_ptr<AndroidProviderBackend> backend( 1218 scoped_ptr<AndroidProviderBackend> backend(
1221 new AndroidProviderBackend(android_cache_db_name_, 1219 new AndroidProviderBackend(android_cache_db_name_,
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 EXPECT_EQ(row1.title(), child1->GetTitle()); 1649 EXPECT_EQ(row1.title(), child1->GetTitle());
1652 EXPECT_EQ(row1.url(), child1->url()); 1650 EXPECT_EQ(row1.url(), child1->url());
1653 1651
1654 // Verify notification 1652 // Verify notification
1655 ASSERT_TRUE(delegate_.deleted_details()); 1653 ASSERT_TRUE(delegate_.deleted_details());
1656 ASSERT_EQ(2u, delegate_.deleted_details()->rows.size()); 1654 ASSERT_EQ(2u, delegate_.deleted_details()->rows.size());
1657 EXPECT_EQ(row1.url(), 1655 EXPECT_EQ(row1.url(),
1658 delegate_.modified_details()->changed_urls[0].url()); 1656 delegate_.modified_details()->changed_urls[0].url());
1659 EXPECT_EQ(Time::UnixEpoch(), 1657 EXPECT_EQ(Time::UnixEpoch(),
1660 delegate_.modified_details()->changed_urls[0].last_visit()); 1658 delegate_.modified_details()->changed_urls[0].last_visit());
1661 EXPECT_EQ(1u, delegate_.favicon_details()->urls.size()); 1659 EXPECT_EQ(1u, delegate_.favicon_changed()->size());
1662 } 1660 }
1663 1661
1664 TEST_F(AndroidProviderBackendTest, TestMultipleNestingTransaction) { 1662 TEST_F(AndroidProviderBackendTest, TestMultipleNestingTransaction) {
1665 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); 1663 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_));
1666 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_)); 1664 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_));
1667 scoped_ptr<AndroidProviderBackend> backend( 1665 scoped_ptr<AndroidProviderBackend> backend(
1668 new AndroidProviderBackend(android_cache_db_name_, 1666 new AndroidProviderBackend(android_cache_db_name_,
1669 &history_db_, 1667 &history_db_,
1670 &thumbnail_db_, 1668 &thumbnail_db_,
1671 history_client_, 1669 history_client_,
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 EXPECT_FALSE(delegate_.deleted_details()); 1956 EXPECT_FALSE(delegate_.deleted_details());
1959 ASSERT_TRUE(delegate_.modified_details()); 1957 ASSERT_TRUE(delegate_.modified_details());
1960 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1958 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1961 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url()); 1959 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url());
1962 EXPECT_EQ(row1.last_visit_time(), 1960 EXPECT_EQ(row1.last_visit_time(),
1963 delegate_.modified_details()->changed_urls[0].last_visit()); 1961 delegate_.modified_details()->changed_urls[0].last_visit());
1964 EXPECT_EQ(row1.visit_count(), 1962 EXPECT_EQ(row1.visit_count(),
1965 delegate_.modified_details()->changed_urls[0].visit_count()); 1963 delegate_.modified_details()->changed_urls[0].visit_count());
1966 EXPECT_EQ(row1.title(), 1964 EXPECT_EQ(row1.title(),
1967 delegate_.modified_details()->changed_urls[0].title()); 1965 delegate_.modified_details()->changed_urls[0].title());
1968 EXPECT_FALSE(delegate_.favicon_details()); 1966 EXPECT_FALSE(delegate_.favicon_changed());
1969 content::RunAllPendingInMessageLoop(); 1967 content::RunAllPendingInMessageLoop();
1970 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 1968 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
1971 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 1969 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
1972 ASSERT_TRUE(child); 1970 ASSERT_TRUE(child);
1973 EXPECT_EQ(row1.title(), child->GetTitle()); 1971 EXPECT_EQ(row1.title(), child->GetTitle());
1974 EXPECT_EQ(row1.url(), child->url()); 1972 EXPECT_EQ(row1.url(), child->url());
1975 1973
1976 delegate_.ResetDetails(); 1974 delegate_.ResetDetails();
1977 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2)); 1975 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2));
1978 EXPECT_FALSE(delegate_.deleted_details()); 1976 EXPECT_FALSE(delegate_.deleted_details());
1979 ASSERT_TRUE(delegate_.modified_details()); 1977 ASSERT_TRUE(delegate_.modified_details());
1980 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 1978 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
1981 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url()); 1979 EXPECT_EQ(row2.url(), delegate_.modified_details()->changed_urls[0].url());
1982 EXPECT_EQ(row2.last_visit_time(), 1980 EXPECT_EQ(row2.last_visit_time(),
1983 delegate_.modified_details()->changed_urls[0].last_visit()); 1981 delegate_.modified_details()->changed_urls[0].last_visit());
1984 EXPECT_EQ(row2.title(), 1982 EXPECT_EQ(row2.title(),
1985 delegate_.modified_details()->changed_urls[0].title()); 1983 delegate_.modified_details()->changed_urls[0].title());
1986 // Favicon details is still false because thumbnail database wasn't 1984 // Favicon details is still false because thumbnail database wasn't
1987 // initialized, we ignore any changes of favicon. 1985 // initialized, we ignore any changes of favicon.
1988 ASSERT_FALSE(delegate_.favicon_details()); 1986 ASSERT_FALSE(delegate_.favicon_changed());
1989 } 1987 }
1990 1988
1991 TEST_F(AndroidProviderBackendTest, DeleteWithoutThumbnailDB) { 1989 TEST_F(AndroidProviderBackendTest, DeleteWithoutThumbnailDB) {
1992 HistoryAndBookmarkRow row1; 1990 HistoryAndBookmarkRow row1;
1993 row1.set_raw_url("cnn.com"); 1991 row1.set_raw_url("cnn.com");
1994 row1.set_url(GURL("http://cnn.com")); 1992 row1.set_url(GURL("http://cnn.com"));
1995 row1.set_last_visit_time(Time::Now() - TimeDelta::FromDays(1)); 1993 row1.set_last_visit_time(Time::Now() - TimeDelta::FromDays(1));
1996 row1.set_created(Time::Now() - TimeDelta::FromDays(20)); 1994 row1.set_created(Time::Now() - TimeDelta::FromDays(20));
1997 row1.set_visit_count(10); 1995 row1.set_visit_count(10);
1998 row1.set_is_bookmark(true); 1996 row1.set_is_bookmark(true);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 EXPECT_EQ(2, deleted_count); 2047 EXPECT_EQ(2, deleted_count);
2050 // Verify the rows was removed from bookmark model. 2048 // Verify the rows was removed from bookmark model.
2051 content::RunAllPendingInMessageLoop(); 2049 content::RunAllPendingInMessageLoop();
2052 ASSERT_EQ(0, bookmark_model_->mobile_node()->child_count()); 2050 ASSERT_EQ(0, bookmark_model_->mobile_node()->child_count());
2053 2051
2054 // Verify notifications 2052 // Verify notifications
2055 ASSERT_TRUE(delegate_.deleted_details()); 2053 ASSERT_TRUE(delegate_.deleted_details());
2056 EXPECT_FALSE(delegate_.modified_details()); 2054 EXPECT_FALSE(delegate_.modified_details());
2057 EXPECT_EQ(2u, delegate_.deleted_details()->rows.size()); 2055 EXPECT_EQ(2u, delegate_.deleted_details()->rows.size());
2058 // No favicon has been deleted. 2056 // No favicon has been deleted.
2059 EXPECT_FALSE(delegate_.favicon_details()); 2057 EXPECT_FALSE(delegate_.favicon_changed());
2060 2058
2061 // No row exists. 2059 // No row exists.
2062 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 2060 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
2063 projections.push_back(HistoryAndBookmarkRow::ID); 2061 projections.push_back(HistoryAndBookmarkRow::ID);
2064 projections.push_back(HistoryAndBookmarkRow::URL); 2062 projections.push_back(HistoryAndBookmarkRow::URL);
2065 projections.push_back(HistoryAndBookmarkRow::TITLE); 2063 projections.push_back(HistoryAndBookmarkRow::TITLE);
2066 projections.push_back(HistoryAndBookmarkRow::CREATED); 2064 projections.push_back(HistoryAndBookmarkRow::CREATED);
2067 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); 2065 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME);
2068 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); 2066 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT);
2069 projections.push_back(HistoryAndBookmarkRow::FAVICON); 2067 projections.push_back(HistoryAndBookmarkRow::FAVICON);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data)); 2120 update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data));
2123 update_args.push_back(UTF8ToUTF16(row1.raw_url())); 2121 update_args.push_back(UTF8ToUTF16(row1.raw_url()));
2124 delegate_.ResetDetails(); 2122 delegate_.ResetDetails();
2125 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", 2123 ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
2126 update_args, &update_count)); 2124 update_args, &update_count));
2127 // Verify notifications. 2125 // Verify notifications.
2128 EXPECT_FALSE(delegate_.deleted_details()); 2126 EXPECT_FALSE(delegate_.deleted_details());
2129 ASSERT_TRUE(delegate_.modified_details()); 2127 ASSERT_TRUE(delegate_.modified_details());
2130 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 2128 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
2131 // No favicon will be updated as thumbnail database is missing. 2129 // No favicon will be updated as thumbnail database is missing.
2132 EXPECT_FALSE(delegate_.favicon_details()); 2130 EXPECT_FALSE(delegate_.favicon_changed());
2133 } 2131 }
2134 2132
2135 } // namespace history 2133 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698