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/sync/profile_sync_service_typed_url_unittest.cc

Issue 694843002: Remove NOTIFICATION_HISTORY_URLS_MODIFIED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 1 month 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 history::RedirectList redirects; 344 history::RedirectList redirects;
345 SendNotification( 345 SendNotification(
346 base::Bind(&HistoryBackendNotifier::NotifyURLVisited, 346 base::Bind(&HistoryBackendNotifier::NotifyURLVisited,
347 base::Unretained(history_backend_.get()), 347 base::Unretained(history_backend_.get()),
348 transition, 348 transition,
349 row, 349 row,
350 redirects, 350 redirects,
351 visit_time)); 351 visit_time));
352 } 352 }
353 353
354 void SendNotificationURLsModified(const history::URLRows& rows) {
355 SendNotification(base::Bind(&HistoryBackendNotifier::NotifyURLsModified,
356 base::Unretained(history_backend_.get()),
357 rows));
358 }
359
354 static bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) { 360 static bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) {
355 // Only verify the fields we explicitly sync (i.e. don't verify typed_count 361 // Only verify the fields we explicitly sync (i.e. don't verify typed_count
356 // or visit_count because we rely on the history DB to manage those values 362 // or visit_count because we rely on the history DB to manage those values
357 // and they are left unchanged by HistoryBackendMock). 363 // and they are left unchanged by HistoryBackendMock).
358 return (lhs.url().spec().compare(rhs.url().spec()) == 0) && 364 return (lhs.url().spec().compare(rhs.url().spec()) == 0) &&
359 (lhs.title().compare(rhs.title()) == 0) && 365 (lhs.title().compare(rhs.title()) == 0) &&
360 (lhs.last_visit() == rhs.last_visit()) && 366 (lhs.last_visit() == rhs.last_visit()) &&
361 (lhs.hidden() == rhs.hidden()); 367 (lhs.hidden() == rhs.hidden());
362 } 368 }
363 369
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 630
625 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). 631 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)).
626 WillOnce(Return(true)); 632 WillOnce(Return(true));
627 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)). 633 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)).
628 WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); 634 WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true)));
629 635
630 SetIdleChangeProcessorExpectations(); 636 SetIdleChangeProcessorExpectations();
631 CreateRootHelper create_root(this, syncer::TYPED_URLS); 637 CreateRootHelper create_root(this, syncer::TYPED_URLS);
632 StartSyncService(create_root.callback()); 638 StartSyncService(create_root.callback());
633 639
634 history::URLsModifiedDetails details; 640 history::URLRows changed_urls;
635 details.changed_urls.push_back(added_entry); 641 changed_urls.push_back(added_entry);
636 scoped_refptr<ThreadNotifier> notifier( 642 SendNotificationURLsModified(changed_urls);
637 new ThreadNotifier(history_thread_.get()));
638 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
639 content::Source<Profile>(profile_),
640 content::Details<history::URLsModifiedDetails>(&details));
641 643
642 history::URLRows new_sync_entries; 644 history::URLRows new_sync_entries;
643 GetTypedUrlsFromSyncDB(&new_sync_entries); 645 GetTypedUrlsFromSyncDB(&new_sync_entries);
644 ASSERT_EQ(1U, new_sync_entries.size()); 646 ASSERT_EQ(1U, new_sync_entries.size());
645 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); 647 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0]));
646 } 648 }
647 649
648 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddWithBlank) { 650 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddWithBlank) {
649 history::VisitVector added_visits; 651 history::VisitVector added_visits;
650 history::URLRow empty_entry(MakeTypedUrlEntry("", "entry", 652 history::URLRow empty_entry(MakeTypedUrlEntry("", "entry",
651 2, 15, false, &added_visits)); 653 2, 15, false, &added_visits));
652 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", 654 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry",
653 2, 15, false, &added_visits)); 655 2, 15, false, &added_visits));
654 656
655 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). 657 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)).
656 WillOnce(Return(true)); 658 WillOnce(Return(true));
657 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)). 659 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)).
658 WillRepeatedly(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); 660 WillRepeatedly(DoAll(SetArgumentPointee<2>(added_visits), Return(true)));
659 661
660 SetIdleChangeProcessorExpectations(); 662 SetIdleChangeProcessorExpectations();
661 CreateRootHelper create_root(this, syncer::TYPED_URLS); 663 CreateRootHelper create_root(this, syncer::TYPED_URLS);
662 StartSyncService(create_root.callback()); 664 StartSyncService(create_root.callback());
663 665
664 history::URLsModifiedDetails details; 666 history::URLRows changed_urls;
665 details.changed_urls.push_back(empty_entry); 667 changed_urls.push_back(empty_entry);
666 details.changed_urls.push_back(added_entry); 668 changed_urls.push_back(added_entry);
667 scoped_refptr<ThreadNotifier> notifier( 669 SendNotificationURLsModified(changed_urls);
668 new ThreadNotifier(history_thread_.get()));
669 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
670 content::Source<Profile>(profile_),
671 content::Details<history::URLsModifiedDetails>(&details));
672 670
673 std::vector<history::URLRow> new_sync_entries; 671 std::vector<history::URLRow> new_sync_entries;
674 GetTypedUrlsFromSyncDB(&new_sync_entries); 672 GetTypedUrlsFromSyncDB(&new_sync_entries);
675 ASSERT_EQ(1U, new_sync_entries.size()); 673 ASSERT_EQ(1U, new_sync_entries.size());
676 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); 674 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0]));
677 } 675 }
678 676
679 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdate) { 677 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdate) {
680 history::VisitVector original_visits; 678 history::VisitVector original_visits;
681 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry", 679 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry",
(...skipping 11 matching lines...) Expand all
693 StartSyncService(create_root.callback()); 691 StartSyncService(create_root.callback());
694 692
695 history::VisitVector updated_visits; 693 history::VisitVector updated_visits;
696 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", 694 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry",
697 7, 17, false, 695 7, 17, false,
698 &updated_visits)); 696 &updated_visits));
699 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)). 697 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)).
700 WillOnce(DoAll(SetArgumentPointee<2>(updated_visits), 698 WillOnce(DoAll(SetArgumentPointee<2>(updated_visits),
701 Return(true))); 699 Return(true)));
702 700
703 history::URLsModifiedDetails details; 701 history::URLRows changed_urls;
704 details.changed_urls.push_back(updated_entry); 702 changed_urls.push_back(updated_entry);
705 scoped_refptr<ThreadNotifier> notifier( 703 SendNotificationURLsModified(changed_urls);
706 new ThreadNotifier(history_thread_.get()));
707 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
708 content::Source<Profile>(profile_),
709 content::Details<history::URLsModifiedDetails>(&details));
710 704
711 history::URLRows new_sync_entries; 705 history::URLRows new_sync_entries;
712 GetTypedUrlsFromSyncDB(&new_sync_entries); 706 GetTypedUrlsFromSyncDB(&new_sync_entries);
713 ASSERT_EQ(1U, new_sync_entries.size()); 707 ASSERT_EQ(1U, new_sync_entries.size());
714 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0])); 708 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0]));
715 } 709 }
716 710
717 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddFromVisit) { 711 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddFromVisit) {
718 history::VisitVector added_visits; 712 history::VisitVector added_visits;
719 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", 713 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry",
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 // Create updates for the previous urls + a new file one. 1031 // Create updates for the previous urls + a new file one.
1038 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com", 1032 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com",
1039 "yey", 20, 15, false, 1033 "yey", 20, 15, false,
1040 &updated_visits)); 1034 &updated_visits));
1041 history::URLRow updated_file_entry(MakeTypedUrlEntry("file:///cat.jpg", 1035 history::URLRow updated_file_entry(MakeTypedUrlEntry("file:///cat.jpg",
1042 "cat", 20, 15, false, 1036 "cat", 20, 15, false,
1043 &updated_visits)); 1037 &updated_visits));
1044 history::URLRow new_file_entry(MakeTypedUrlEntry("file:///dog.jpg", 1038 history::URLRow new_file_entry(MakeTypedUrlEntry("file:///dog.jpg",
1045 "dog", 20, 15, false, 1039 "dog", 20, 15, false,
1046 &updated_visits)); 1040 &updated_visits));
1047 history::URLsModifiedDetails details; 1041
1048 details.changed_urls.push_back(updated_url_entry); 1042 history::URLRows changed_urls;
1049 details.changed_urls.push_back(updated_file_entry); 1043 changed_urls.push_back(updated_url_entry);
1050 details.changed_urls.push_back(new_file_entry); 1044 changed_urls.push_back(updated_file_entry);
1051 scoped_refptr<ThreadNotifier> notifier( 1045 changed_urls.push_back(new_file_entry);
1052 new ThreadNotifier(history_thread_.get())); 1046 SendNotificationURLsModified(changed_urls);
1053 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
1054 content::Source<Profile>(profile_),
1055 content::Details<history::URLsModifiedDetails>(&details));
1056 1047
1057 history::URLRows new_sync_entries; 1048 history::URLRows new_sync_entries;
1058 GetTypedUrlsFromSyncDB(&new_sync_entries); 1049 GetTypedUrlsFromSyncDB(&new_sync_entries);
1059 1050
1060 // We should ignore the local file urls (existing and updated), 1051 // We should ignore the local file urls (existing and updated),
1061 // and only be left with the updated http url. 1052 // and only be left with the updated http url.
1062 ASSERT_EQ(1U, new_sync_entries.size()); 1053 ASSERT_EQ(1U, new_sync_entries.size());
1063 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0])); 1054 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0]));
1064 } 1055 }
1065 1056
(...skipping 25 matching lines...) Expand all
1091 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com", 1082 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com",
1092 "yey", 20, 15, false, 1083 "yey", 20, 15, false,
1093 &updated_visits)); 1084 &updated_visits));
1094 history::URLRow updated_localhost_entry(MakeTypedUrlEntry( 1085 history::URLRow updated_localhost_entry(MakeTypedUrlEntry(
1095 "http://localhost:80", 1086 "http://localhost:80",
1096 "localhost", 20, 15, false, 1087 "localhost", 20, 15, false,
1097 &original_visits)); 1088 &original_visits));
1098 history::URLRow localhost_ip_entry(MakeTypedUrlEntry("http://127.0.0.1", 1089 history::URLRow localhost_ip_entry(MakeTypedUrlEntry("http://127.0.0.1",
1099 "localhost", 12, 15, false, 1090 "localhost", 12, 15, false,
1100 &original_visits)); 1091 &original_visits));
1101 history::URLsModifiedDetails details; 1092
1102 details.changed_urls.push_back(updated_url_entry); 1093 history::URLRows changed_urls;
1103 details.changed_urls.push_back(updated_localhost_entry); 1094 changed_urls.push_back(updated_url_entry);
1104 details.changed_urls.push_back(localhost_ip_entry); 1095 changed_urls.push_back(updated_localhost_entry);
1105 scoped_refptr<ThreadNotifier> notifier( 1096 changed_urls.push_back(localhost_ip_entry);
1106 new ThreadNotifier(history_thread_.get())); 1097 SendNotificationURLsModified(changed_urls);
1107 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
1108 content::Source<Profile>(profile_),
1109 content::Details<history::URLsModifiedDetails>(&details));
1110 1098
1111 history::URLRows new_sync_entries; 1099 history::URLRows new_sync_entries;
1112 GetTypedUrlsFromSyncDB(&new_sync_entries); 1100 GetTypedUrlsFromSyncDB(&new_sync_entries);
1113 1101
1114 // We should ignore the localhost urls and left only with http url. 1102 // We should ignore the localhost urls and left only with http url.
1115 ASSERT_EQ(1U, new_sync_entries.size()); 1103 ASSERT_EQ(1U, new_sync_entries.size());
1116 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0])); 1104 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0]));
1117 } 1105 }
1118 1106
1119 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreModificationWithoutValidVisit) { 1107 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreModificationWithoutValidVisit) {
1120 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). 1108 EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)).
1121 WillRepeatedly(Return(true)); 1109 WillRepeatedly(Return(true));
1122 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)). 1110 EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)).
1123 WillRepeatedly(Return(true)); 1111 WillRepeatedly(Return(true));
1124 1112
1125 CreateRootHelper create_root(this, syncer::TYPED_URLS); 1113 CreateRootHelper create_root(this, syncer::TYPED_URLS);
1126 StartSyncService(create_root.callback()); 1114 StartSyncService(create_root.callback());
1127 1115
1128 history::VisitVector updated_visits; 1116 history::VisitVector updated_visits;
1129 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com", 1117 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com",
1130 "yey", 20, 0, false, 1118 "yey", 20, 0, false,
1131 &updated_visits)); 1119 &updated_visits));
1132 history::URLsModifiedDetails details; 1120
1133 details.changed_urls.push_back(updated_url_entry); 1121 history::URLRows changed_urls;
1134 scoped_refptr<ThreadNotifier> notifier( 1122 changed_urls.push_back(updated_url_entry);
1135 new ThreadNotifier(history_thread_.get())); 1123 SendNotificationURLsModified(changed_urls);
1136 notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
1137 content::Source<Profile>(profile_),
1138 content::Details<history::URLsModifiedDetails>(&details));
1139 1124
1140 history::URLRows new_sync_entries; 1125 history::URLRows new_sync_entries;
1141 GetTypedUrlsFromSyncDB(&new_sync_entries); 1126 GetTypedUrlsFromSyncDB(&new_sync_entries);
1142 1127
1143 // The change should be ignored. 1128 // The change should be ignored.
1144 ASSERT_EQ(0U, new_sync_entries.size()); 1129 ASSERT_EQ(0U, new_sync_entries.size());
1145 } 1130 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/typed_url_change_processor.cc ('k') | chrome/browser/ui/cocoa/history_menu_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698