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

Side by Side Diff: chrome/browser/sync/profile_sync_service_typed_url_unittest.cc

Issue 631253002: Refactor sending NOTIFICATION_HISTORY_URL_VISITED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests on Android Created 6 years, 2 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
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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 MOCK_METHOD3(AddVisits, bool(const GURL& url, 99 MOCK_METHOD3(AddVisits, bool(const GURL& url,
100 const std::vector<history::VisitInfo>& visits, 100 const std::vector<history::VisitInfo>& visits,
101 history::VisitSource visit_source)); 101 history::VisitSource visit_source));
102 MOCK_METHOD1(RemoveVisits, bool(const history::VisitVector& visits)); 102 MOCK_METHOD1(RemoveVisits, bool(const history::VisitVector& visits));
103 MOCK_METHOD2(GetURL, bool(const GURL& url_id, history::URLRow* url_row)); 103 MOCK_METHOD2(GetURL, bool(const GURL& url_id, history::URLRow* url_row));
104 MOCK_METHOD2(SetPageTitle, void(const GURL& url, 104 MOCK_METHOD2(SetPageTitle, void(const GURL& url,
105 const base::string16& title)); 105 const base::string16& title));
106 MOCK_METHOD1(DeleteURL, void(const GURL& url)); 106 MOCK_METHOD1(DeleteURL, void(const GURL& url));
107 107
108 private: 108 private:
109 friend class ProfileSyncServiceTypedUrlTest;
110
109 virtual ~HistoryBackendMock() {} 111 virtual ~HistoryBackendMock() {}
110 }; 112 };
111 113
112 class HistoryServiceMock : public HistoryService { 114 class HistoryServiceMock : public HistoryService {
113 public: 115 public:
114 HistoryServiceMock(history::HistoryClient* client, Profile* profile) 116 HistoryServiceMock(history::HistoryClient* client, Profile* profile)
115 : HistoryService(client, profile), backend_(NULL) {} 117 : HistoryService(client, profile), backend_(NULL) {}
116 118
117 virtual void ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, 119 virtual void ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task,
118 base::CancelableTaskTracker* tracker) override { 120 base::CancelableTaskTracker* tracker) override {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 320 }
319 } 321 }
320 322
321 void SetIdleChangeProcessorExpectations() { 323 void SetIdleChangeProcessorExpectations() {
322 EXPECT_CALL((*history_backend_.get()), SetPageTitle(_, _)).Times(0); 324 EXPECT_CALL((*history_backend_.get()), SetPageTitle(_, _)).Times(0);
323 EXPECT_CALL((*history_backend_.get()), UpdateURL(_, _)).Times(0); 325 EXPECT_CALL((*history_backend_.get()), UpdateURL(_, _)).Times(0);
324 EXPECT_CALL((*history_backend_.get()), GetURL(_, _)).Times(0); 326 EXPECT_CALL((*history_backend_.get()), GetURL(_, _)).Times(0);
325 EXPECT_CALL((*history_backend_.get()), DeleteURL(_)).Times(0); 327 EXPECT_CALL((*history_backend_.get()), DeleteURL(_)).Times(0);
326 } 328 }
327 329
330 void SendNotificationAddVisit(ui::PageTransition transition,
331 const history::URLRow& row) {
332 base::Time visit_time;
333 history::RedirectList redirects;
334 history_thread_->task_runner()->PostTaskAndReply(
335 FROM_HERE,
336 base::Bind(&HistoryBackendMock::NotifyAddVisit,
337 base::Unretained(history_backend_.get()),
338 transition,
339 row,
340 redirects,
341 visit_time),
342 base::Bind(&base::MessageLoop::QuitNow,
343 base::Unretained(base::MessageLoop::current())));
344 base::MessageLoop::current()->Run();
345 }
346
328 static bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) { 347 static bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) {
329 // Only verify the fields we explicitly sync (i.e. don't verify typed_count 348 // Only verify the fields we explicitly sync (i.e. don't verify typed_count
330 // or visit_count because we rely on the history DB to manage those values 349 // or visit_count because we rely on the history DB to manage those values
331 // and they are left unchanged by HistoryBackendMock). 350 // and they are left unchanged by HistoryBackendMock).
332 return (lhs.url().spec().compare(rhs.url().spec()) == 0) && 351 return (lhs.url().spec().compare(rhs.url().spec()) == 0) &&
333 (lhs.title().compare(rhs.title()) == 0) && 352 (lhs.title().compare(rhs.title()) == 0) &&
334 (lhs.last_visit() == rhs.last_visit()) && 353 (lhs.last_visit() == rhs.last_visit()) &&
335 (lhs.hidden() == rhs.hidden()); 354 (lhs.hidden() == rhs.hidden());
336 } 355 }
337 356
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 714
696 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). 715 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)).
697 WillOnce(Return(true)); 716 WillOnce(Return(true));
698 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)). 717 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)).
699 WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); 718 WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true)));
700 719
701 SetIdleChangeProcessorExpectations(); 720 SetIdleChangeProcessorExpectations();
702 CreateRootHelper create_root(this, syncer::TYPED_URLS); 721 CreateRootHelper create_root(this, syncer::TYPED_URLS);
703 StartSyncService(create_root.callback()); 722 StartSyncService(create_root.callback());
704 723
705 history::URLVisitedDetails details; 724 SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, added_entry);
706 details.row = added_entry;
707 details.transition = ui::PAGE_TRANSITION_TYPED;
708 scoped_refptr<ThreadNotifier> notifier(
709 new ThreadNotifier(history_thread_.get()));
710 notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
711 content::Source<Profile>(profile_),
712 content::Details<history::URLVisitedDetails>(&details));
713 725
714 history::URLRows new_sync_entries; 726 history::URLRows new_sync_entries;
715 GetTypedUrlsFromSyncDB(&new_sync_entries); 727 GetTypedUrlsFromSyncDB(&new_sync_entries);
716 ASSERT_EQ(1U, new_sync_entries.size()); 728 ASSERT_EQ(1U, new_sync_entries.size());
717 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); 729 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0]));
718 } 730 }
719 731
720 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdateFromVisit) { 732 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdateFromVisit) {
721 history::VisitVector original_visits; 733 history::VisitVector original_visits;
722 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry", 734 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry",
(...skipping 11 matching lines...) Expand all
734 StartSyncService(create_root.callback()); 746 StartSyncService(create_root.callback());
735 747
736 history::VisitVector updated_visits; 748 history::VisitVector updated_visits;
737 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", 749 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry",
738 7, 17, false, 750 7, 17, false,
739 &updated_visits)); 751 &updated_visits));
740 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)). 752 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)).
741 WillOnce(DoAll(SetArgumentPointee<2>(updated_visits), 753 WillOnce(DoAll(SetArgumentPointee<2>(updated_visits),
742 Return(true))); 754 Return(true)));
743 755
744 history::URLVisitedDetails details; 756 SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, updated_entry);
745 details.row = updated_entry;
746 details.transition = ui::PAGE_TRANSITION_TYPED;
747 scoped_refptr<ThreadNotifier> notifier(
748 new ThreadNotifier(history_thread_.get()));
749 notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
750 content::Source<Profile>(profile_),
751 content::Details<history::URLVisitedDetails>(&details));
752 757
753 history::URLRows new_sync_entries; 758 history::URLRows new_sync_entries;
754 GetTypedUrlsFromSyncDB(&new_sync_entries); 759 GetTypedUrlsFromSyncDB(&new_sync_entries);
755 ASSERT_EQ(1U, new_sync_entries.size()); 760 ASSERT_EQ(1U, new_sync_entries.size());
756 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0])); 761 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0]));
757 } 762 }
758 763
759 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) { 764 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) {
760 history::VisitVector original_visits; 765 history::VisitVector original_visits;
761 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry", 766 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry",
(...skipping 11 matching lines...) Expand all
773 StartSyncService(create_root.callback()); 778 StartSyncService(create_root.callback());
774 history::URLRows new_sync_entries; 779 history::URLRows new_sync_entries;
775 GetTypedUrlsFromSyncDB(&new_sync_entries); 780 GetTypedUrlsFromSyncDB(&new_sync_entries);
776 ASSERT_EQ(1U, new_sync_entries.size()); 781 ASSERT_EQ(1U, new_sync_entries.size());
777 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); 782 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0]));
778 783
779 history::VisitVector updated_visits; 784 history::VisitVector updated_visits;
780 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", 785 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry",
781 7, 15, false, 786 7, 15, false,
782 &updated_visits)); 787 &updated_visits));
783 history::URLVisitedDetails details;
784 details.row = updated_entry;
785 788
786 // Should ignore this change because it's not TYPED. 789 // Should ignore this change because it's not TYPED.
787 details.transition = ui::PAGE_TRANSITION_RELOAD; 790 SendNotificationAddVisit(ui::PAGE_TRANSITION_RELOAD, updated_entry);
788 scoped_refptr<ThreadNotifier> notifier(
789 new ThreadNotifier(history_thread_.get()));
790 notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
791 content::Source<Profile>(profile_),
792 content::Details<history::URLVisitedDetails>(&details));
793
794 GetTypedUrlsFromSyncDB(&new_sync_entries); 791 GetTypedUrlsFromSyncDB(&new_sync_entries);
795 792
796 // Should be no changes to the sync DB from this notification. 793 // Should be no changes to the sync DB from this notification.
797 ASSERT_EQ(1U, new_sync_entries.size()); 794 ASSERT_EQ(1U, new_sync_entries.size());
798 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); 795 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0]));
799 796
800 // Now, try updating it with a large number of visits not divisible by 10 797 // Now, try updating it with a large number of visits not divisible by 10
801 // (should ignore this visit). 798 // (should ignore this visit).
802 history::URLRow twelve_visits(MakeTypedUrlEntry("http://mine.com", "entry", 799 history::URLRow twelve_visits(MakeTypedUrlEntry("http://mine.com", "entry",
803 12, 15, false, 800 12, 15, false,
804 &updated_visits)); 801 &updated_visits));
805 details.row = twelve_visits; 802 SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, twelve_visits);
806 details.transition = ui::PAGE_TRANSITION_TYPED;
807 notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
808 content::Source<Profile>(profile_),
809 content::Details<history::URLVisitedDetails>(&details));
810 GetTypedUrlsFromSyncDB(&new_sync_entries); 803 GetTypedUrlsFromSyncDB(&new_sync_entries);
804
811 // Should be no changes to the sync DB from this notification. 805 // Should be no changes to the sync DB from this notification.
812 ASSERT_EQ(1U, new_sync_entries.size()); 806 ASSERT_EQ(1U, new_sync_entries.size());
813 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); 807 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0]));
814 808
815 // Now, try updating it with a large number of visits that is divisible by 10 809 // Now, try updating it with a large number of visits that is divisible by 10
816 // (should *not* be ignored). 810 // (should *not* be ignored).
817 history::URLRow twenty_visits(MakeTypedUrlEntry("http://mine.com", "entry", 811 history::URLRow twenty_visits(MakeTypedUrlEntry("http://mine.com", "entry",
818 20, 15, false, 812 20, 15, false,
819 &updated_visits)); 813 &updated_visits));
820 details.row = twenty_visits; 814 SendNotificationAddVisit(ui::PAGE_TRANSITION_TYPED, twenty_visits);
821 details.transition = ui::PAGE_TRANSITION_TYPED;
822 notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
823 content::Source<Profile>(profile_),
824 content::Details<history::URLVisitedDetails>(&details));
825 GetTypedUrlsFromSyncDB(&new_sync_entries); 815 GetTypedUrlsFromSyncDB(&new_sync_entries);
816
826 ASSERT_EQ(1U, new_sync_entries.size()); 817 ASSERT_EQ(1U, new_sync_entries.size());
827 EXPECT_TRUE(URLsEqual(twenty_visits, new_sync_entries[0])); 818 EXPECT_TRUE(URLsEqual(twenty_visits, new_sync_entries[0]));
828 } 819 }
829 820
830 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemove) { 821 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemove) {
831 history::VisitVector original_visits1; 822 history::VisitVector original_visits1;
832 history::URLRow original_entry1(MakeTypedUrlEntry("http://mine.com", "entry", 823 history::URLRow original_entry1(MakeTypedUrlEntry("http://mine.com", "entry",
833 2, 15, false, 824 2, 15, false,
834 &original_visits1)); 825 &original_visits1));
835 history::VisitVector original_visits2; 826 history::VisitVector original_visits2;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 1129 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
1139 content::Source<Profile>(profile_), 1130 content::Source<Profile>(profile_),
1140 content::Details<history::URLsModifiedDetails>(&details)); 1131 content::Details<history::URLsModifiedDetails>(&details));
1141 1132
1142 history::URLRows new_sync_entries; 1133 history::URLRows new_sync_entries;
1143 GetTypedUrlsFromSyncDB(&new_sync_entries); 1134 GetTypedUrlsFromSyncDB(&new_sync_entries);
1144 1135
1145 // The change should be ignored. 1136 // The change should be ignored.
1146 ASSERT_EQ(0U, new_sync_entries.size()); 1137 ASSERT_EQ(0U, new_sync_entries.size());
1147 } 1138 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/typed_url_change_processor.cc ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698