OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "components/history/core/browser/typed_url_syncable_service.h" | 5 #include "components/history/core/browser/typed_url_syncable_service.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
14 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
15 #include "components/history/core/browser/history_backend.h" | 19 #include "components/history/core/browser/history_backend.h" |
16 #include "components/history/core/browser/history_backend_client.h" | 20 #include "components/history/core/browser/history_backend_client.h" |
17 #include "components/history/core/browser/history_database_params.h" | 21 #include "components/history/core/browser/history_database_params.h" |
18 #include "components/history/core/browser/history_types.h" | 22 #include "components/history/core/browser/history_types.h" |
19 #include "components/history/core/browser/in_memory_history_backend.h" | 23 #include "components/history/core/browser/in_memory_history_backend.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 64 |
61 bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) { | 65 bool URLsEqual(history::URLRow& lhs, history::URLRow& rhs) { |
62 // Only compare synced fields (ignore typed_count and visit_count as those | 66 // Only compare synced fields (ignore typed_count and visit_count as those |
63 // are maintained by the history subsystem). | 67 // are maintained by the history subsystem). |
64 return (lhs.url().spec().compare(rhs.url().spec()) == 0) && | 68 return (lhs.url().spec().compare(rhs.url().spec()) == 0) && |
65 (lhs.title().compare(rhs.title()) == 0) && | 69 (lhs.title().compare(rhs.title()) == 0) && |
66 (lhs.hidden() == rhs.hidden()); | 70 (lhs.hidden() == rhs.hidden()); |
67 } | 71 } |
68 | 72 |
69 void AddNewestVisit(ui::PageTransition transition, | 73 void AddNewestVisit(ui::PageTransition transition, |
70 int64 visit_time, | 74 int64_t visit_time, |
71 URLRow* url, | 75 URLRow* url, |
72 VisitVector* visits) { | 76 VisitVector* visits) { |
73 base::Time time = base::Time::FromInternalValue(visit_time); | 77 base::Time time = base::Time::FromInternalValue(visit_time); |
74 visits->insert(visits->begin(), VisitRow(url->id(), time, 0, transition, 0)); | 78 visits->insert(visits->begin(), VisitRow(url->id(), time, 0, transition, 0)); |
75 | 79 |
76 if (transition == ui::PAGE_TRANSITION_TYPED) { | 80 if (transition == ui::PAGE_TRANSITION_TYPED) { |
77 url->set_typed_count(url->typed_count() + 1); | 81 url->set_typed_count(url->typed_count() + 1); |
78 } | 82 } |
79 | 83 |
80 url->set_last_visit(time); | 84 url->set_last_visit(time); |
81 url->set_visit_count(visits->size()); | 85 url->set_visit_count(visits->size()); |
82 } | 86 } |
83 | 87 |
84 void AddOldestVisit(ui::PageTransition transition, | 88 void AddOldestVisit(ui::PageTransition transition, |
85 int64 visit_time, | 89 int64_t visit_time, |
86 URLRow* url, | 90 URLRow* url, |
87 VisitVector* visits) { | 91 VisitVector* visits) { |
88 base::Time time = base::Time::FromInternalValue(visit_time); | 92 base::Time time = base::Time::FromInternalValue(visit_time); |
89 visits->push_back(VisitRow(url->id(), time, 0, transition, 0)); | 93 visits->push_back(VisitRow(url->id(), time, 0, transition, 0)); |
90 | 94 |
91 if (transition == ui::PAGE_TRANSITION_TYPED) { | 95 if (transition == ui::PAGE_TRANSITION_TYPED) { |
92 url->set_typed_count(url->typed_count() + 1); | 96 url->set_typed_count(url->typed_count() + 1); |
93 } | 97 } |
94 | 98 |
95 url->set_visit_count(visits->size()); | 99 url->set_visit_count(visits->size()); |
96 } | 100 } |
97 | 101 |
98 // Create a new row object and the typed visit çorresponding with the time at | 102 // Create a new row object and the typed visit çorresponding with the time at |
99 // |last_visit| in the |visits| vector. | 103 // |last_visit| in the |visits| vector. |
100 URLRow MakeTypedUrlRow(const std::string& url, | 104 URLRow MakeTypedUrlRow(const std::string& url, |
101 const std::string& title, | 105 const std::string& title, |
102 int typed_count, | 106 int typed_count, |
103 int64 last_visit, | 107 int64_t last_visit, |
104 bool hidden, | 108 bool hidden, |
105 VisitVector* visits) { | 109 VisitVector* visits) { |
106 // Give each URL a unique ID, to mimic the behavior of the real database. | 110 // Give each URL a unique ID, to mimic the behavior of the real database. |
107 GURL gurl(url); | 111 GURL gurl(url); |
108 URLRow history_url(gurl); | 112 URLRow history_url(gurl); |
109 history_url.set_title(base::UTF8ToUTF16(title)); | 113 history_url.set_title(base::UTF8ToUTF16(title)); |
110 history_url.set_typed_count(typed_count); | 114 history_url.set_typed_count(typed_count); |
111 history_url.set_hidden(hidden); | 115 history_url.set_hidden(hidden); |
112 | 116 |
113 base::Time last_visit_time = base::Time::FromInternalValue(last_visit); | 117 base::Time last_visit_time = base::Time::FromInternalValue(last_visit); |
114 history_url.set_last_visit(last_visit_time); | 118 history_url.set_last_visit(last_visit_time); |
115 | 119 |
116 if (typed_count > 0) { | 120 if (typed_count > 0) { |
117 // Add a typed visit for time |last_visit|. | 121 // Add a typed visit for time |last_visit|. |
118 visits->push_back(VisitRow(history_url.id(), last_visit_time, 0, | 122 visits->push_back(VisitRow(history_url.id(), last_visit_time, 0, |
119 ui::PAGE_TRANSITION_TYPED, 0)); | 123 ui::PAGE_TRANSITION_TYPED, 0)); |
120 } else { | 124 } else { |
121 // Add a non-typed visit for time |last_visit|. | 125 // Add a non-typed visit for time |last_visit|. |
122 visits->push_back(VisitRow(history_url.id(), last_visit_time, 0, | 126 visits->push_back(VisitRow(history_url.id(), last_visit_time, 0, |
123 ui::PAGE_TRANSITION_RELOAD, 0)); | 127 ui::PAGE_TRANSITION_RELOAD, 0)); |
124 } | 128 } |
125 | 129 |
126 history_url.set_visit_count(visits->size()); | 130 history_url.set_visit_count(visits->size()); |
127 return history_url; | 131 return history_url; |
128 } | 132 } |
129 | 133 |
130 static sync_pb::TypedUrlSpecifics MakeTypedUrlSpecifics(const char* url, | 134 static sync_pb::TypedUrlSpecifics MakeTypedUrlSpecifics(const char* url, |
131 const char* title, | 135 const char* title, |
132 int64 last_visit, | 136 int64_t last_visit, |
133 bool hidden) { | 137 bool hidden) { |
134 sync_pb::TypedUrlSpecifics typed_url; | 138 sync_pb::TypedUrlSpecifics typed_url; |
135 typed_url.set_url(url); | 139 typed_url.set_url(url); |
136 typed_url.set_title(title); | 140 typed_url.set_title(title); |
137 typed_url.set_hidden(hidden); | 141 typed_url.set_hidden(hidden); |
138 typed_url.add_visits(last_visit); | 142 typed_url.add_visits(last_visit); |
139 typed_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); | 143 typed_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); |
140 return typed_url; | 144 return typed_url; |
141 } | 145 } |
142 | 146 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 std::vector<VisitVector>* visit_vectors); | 245 std::vector<VisitVector>* visit_vectors); |
242 | 246 |
243 // Fills |urls| with the set of synced urls within |typed_url_sync_service_|. | 247 // Fills |urls| with the set of synced urls within |typed_url_sync_service_|. |
244 void GetSyncedUrls(std::set<GURL>* urls) const; | 248 void GetSyncedUrls(std::set<GURL>* urls) const; |
245 | 249 |
246 // Create and apply a change for url and its visits into history backend. | 250 // Create and apply a change for url and its visits into history backend. |
247 VisitVector ApplyUrlAndVisitsChange( | 251 VisitVector ApplyUrlAndVisitsChange( |
248 const std::string& url, | 252 const std::string& url, |
249 const std::string& title, | 253 const std::string& title, |
250 int typed_count, | 254 int typed_count, |
251 int64 last_visit, | 255 int64_t last_visit, |
252 bool hidden, | 256 bool hidden, |
253 syncer::SyncChange::SyncChangeType change_type); | 257 syncer::SyncChange::SyncChangeType change_type); |
254 | 258 |
255 // Fills |specifics| with the sync data for |url| and |visits|. | 259 // Fills |specifics| with the sync data for |url| and |visits|. |
256 static void WriteToTypedUrlSpecifics(const URLRow& url, | 260 static void WriteToTypedUrlSpecifics(const URLRow& url, |
257 const VisitVector& visits, | 261 const VisitVector& visits, |
258 sync_pb::TypedUrlSpecifics* specifics); | 262 sync_pb::TypedUrlSpecifics* specifics); |
259 | 263 |
260 // Helper to call TypedUrlSyncableService's MergeURLs method. | 264 // Helper to call TypedUrlSyncableService's MergeURLs method. |
261 static TypedUrlSyncableService::MergeResult MergeUrls( | 265 static TypedUrlSyncableService::MergeResult MergeUrls( |
262 const sync_pb::TypedUrlSpecifics& typed_url, | 266 const sync_pb::TypedUrlSpecifics& typed_url, |
263 const history::URLRow& url, | 267 const history::URLRow& url, |
264 history::VisitVector* visits, | 268 history::VisitVector* visits, |
265 history::URLRow* new_url, | 269 history::URLRow* new_url, |
266 std::vector<history::VisitInfo>* new_visits); | 270 std::vector<history::VisitInfo>* new_visits); |
267 | 271 |
268 // Helper to call TypedUrlSyncableService's DiffVisits method. | 272 // Helper to call TypedUrlSyncableService's DiffVisits method. |
269 static void DiffVisits(const history::VisitVector& history_visits, | 273 static void DiffVisits(const history::VisitVector& history_visits, |
270 const sync_pb::TypedUrlSpecifics& sync_specifics, | 274 const sync_pb::TypedUrlSpecifics& sync_specifics, |
271 std::vector<history::VisitInfo>* new_visits, | 275 std::vector<history::VisitInfo>* new_visits, |
272 history::VisitVector* removed_visits); | 276 history::VisitVector* removed_visits); |
273 | 277 |
274 // Create a new row associated with a specific visit's time. | 278 // Create a new row associated with a specific visit's time. |
275 static history::VisitRow CreateVisit(ui::PageTransition type, | 279 static history::VisitRow CreateVisit(ui::PageTransition type, |
276 int64 timestamp); | 280 int64_t timestamp); |
277 | 281 |
278 static const TypedUrlSyncableService::MergeResult DIFF_NONE = | 282 static const TypedUrlSyncableService::MergeResult DIFF_NONE = |
279 TypedUrlSyncableService::DIFF_NONE; | 283 TypedUrlSyncableService::DIFF_NONE; |
280 static const TypedUrlSyncableService::MergeResult DIFF_UPDATE_NODE = | 284 static const TypedUrlSyncableService::MergeResult DIFF_UPDATE_NODE = |
281 TypedUrlSyncableService::DIFF_UPDATE_NODE; | 285 TypedUrlSyncableService::DIFF_UPDATE_NODE; |
282 static const TypedUrlSyncableService::MergeResult DIFF_LOCAL_ROW_CHANGED = | 286 static const TypedUrlSyncableService::MergeResult DIFF_LOCAL_ROW_CHANGED = |
283 TypedUrlSyncableService::DIFF_LOCAL_ROW_CHANGED; | 287 TypedUrlSyncableService::DIFF_LOCAL_ROW_CHANGED; |
284 static const TypedUrlSyncableService::MergeResult DIFF_LOCAL_VISITS_ADDED = | 288 static const TypedUrlSyncableService::MergeResult DIFF_LOCAL_VISITS_ADDED = |
285 TypedUrlSyncableService::DIFF_LOCAL_VISITS_ADDED; | 289 TypedUrlSyncableService::DIFF_LOCAL_VISITS_ADDED; |
286 | 290 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 } | 351 } |
348 | 352 |
349 void TypedUrlSyncableServiceTest::GetSyncedUrls(std::set<GURL>* urls) const { | 353 void TypedUrlSyncableServiceTest::GetSyncedUrls(std::set<GURL>* urls) const { |
350 return typed_url_sync_service_->GetSyncedUrls(urls); | 354 return typed_url_sync_service_->GetSyncedUrls(urls); |
351 } | 355 } |
352 | 356 |
353 VisitVector TypedUrlSyncableServiceTest::ApplyUrlAndVisitsChange( | 357 VisitVector TypedUrlSyncableServiceTest::ApplyUrlAndVisitsChange( |
354 const std::string& url, | 358 const std::string& url, |
355 const std::string& title, | 359 const std::string& title, |
356 int typed_count, | 360 int typed_count, |
357 int64 last_visit, | 361 int64_t last_visit, |
358 bool hidden, | 362 bool hidden, |
359 syncer::SyncChange::SyncChangeType change_type) { | 363 syncer::SyncChange::SyncChangeType change_type) { |
360 VisitVector visits; | 364 VisitVector visits; |
361 URLRow row = | 365 URLRow row = |
362 MakeTypedUrlRow(url, title, typed_count, last_visit, hidden, &visits); | 366 MakeTypedUrlRow(url, title, typed_count, last_visit, hidden, &visits); |
363 syncer::SyncChangeList change_list; | 367 syncer::SyncChangeList change_list; |
364 sync_pb::EntitySpecifics entity_specifics; | 368 sync_pb::EntitySpecifics entity_specifics; |
365 sync_pb::TypedUrlSpecifics* typed_url_specifics = | 369 sync_pb::TypedUrlSpecifics* typed_url_specifics = |
366 entity_specifics.mutable_typed_url(); | 370 entity_specifics.mutable_typed_url(); |
367 WriteToTypedUrlSpecifics(row, visits, typed_url_specifics); | 371 WriteToTypedUrlSpecifics(row, visits, typed_url_specifics); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 const sync_pb::TypedUrlSpecifics& sync_specifics, | 403 const sync_pb::TypedUrlSpecifics& sync_specifics, |
400 std::vector<history::VisitInfo>* new_visits, | 404 std::vector<history::VisitInfo>* new_visits, |
401 history::VisitVector* removed_visits) { | 405 history::VisitVector* removed_visits) { |
402 TypedUrlSyncableService::DiffVisits(history_visits, sync_specifics, | 406 TypedUrlSyncableService::DiffVisits(history_visits, sync_specifics, |
403 new_visits, removed_visits); | 407 new_visits, removed_visits); |
404 } | 408 } |
405 | 409 |
406 // Static. | 410 // Static. |
407 history::VisitRow TypedUrlSyncableServiceTest::CreateVisit( | 411 history::VisitRow TypedUrlSyncableServiceTest::CreateVisit( |
408 ui::PageTransition type, | 412 ui::PageTransition type, |
409 int64 timestamp) { | 413 int64_t timestamp) { |
410 return history::VisitRow(0, base::Time::FromInternalValue(timestamp), 0, type, | 414 return history::VisitRow(0, base::Time::FromInternalValue(timestamp), 0, type, |
411 0); | 415 0); |
412 } | 416 } |
413 | 417 |
414 // Create a local typed URL with one TYPED visit after sync has started. Check | 418 // Create a local typed URL with one TYPED visit after sync has started. Check |
415 // that sync is sent an ADD change for the new URL. | 419 // that sync is sent an ADD change for the new URL. |
416 TEST_F(TypedUrlSyncableServiceTest, AddLocalTypedUrl) { | 420 TEST_F(TypedUrlSyncableServiceTest, AddLocalTypedUrl) { |
417 // Create a local typed URL (simulate a typed visit) that is not already | 421 // Create a local typed URL (simulate a typed visit) that is not already |
418 // in sync. Check that sync is sent an ADD change for the existing URL. | 422 // in sync. Check that sync is sent an ADD change for the existing URL. |
419 URLRows url_rows; | 423 URLRows url_rows; |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 url_id = fake_history_backend_->GetIdByUrl(GURL(kURL)); | 1146 url_id = fake_history_backend_->GetIdByUrl(GURL(kURL)); |
1143 ASSERT_EQ(0, url_id); | 1147 ASSERT_EQ(0, url_id); |
1144 } | 1148 } |
1145 | 1149 |
1146 // Create two set of visits for history DB and sync DB, two same set of visits | 1150 // Create two set of visits for history DB and sync DB, two same set of visits |
1147 // are same. Check DiffVisits will return empty set of diff visits. | 1151 // are same. Check DiffVisits will return empty set of diff visits. |
1148 TEST_F(TypedUrlSyncableServiceTest, DiffVisitsSame) { | 1152 TEST_F(TypedUrlSyncableServiceTest, DiffVisitsSame) { |
1149 history::VisitVector old_visits; | 1153 history::VisitVector old_visits; |
1150 sync_pb::TypedUrlSpecifics new_url; | 1154 sync_pb::TypedUrlSpecifics new_url; |
1151 | 1155 |
1152 const int64 visits[] = {1024, 2065, 65534, 1237684}; | 1156 const int64_t visits[] = {1024, 2065, 65534, 1237684}; |
1153 | 1157 |
1154 for (int64 visit : visits) { | 1158 for (int64_t visit : visits) { |
1155 old_visits.push_back(history::VisitRow(0, | 1159 old_visits.push_back(history::VisitRow(0, |
1156 base::Time::FromInternalValue(visit), | 1160 base::Time::FromInternalValue(visit), |
1157 0, ui::PAGE_TRANSITION_TYPED, 0)); | 1161 0, ui::PAGE_TRANSITION_TYPED, 0)); |
1158 new_url.add_visits(visit); | 1162 new_url.add_visits(visit); |
1159 new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); | 1163 new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); |
1160 } | 1164 } |
1161 | 1165 |
1162 std::vector<history::VisitInfo> new_visits; | 1166 std::vector<history::VisitInfo> new_visits; |
1163 history::VisitVector removed_visits; | 1167 history::VisitVector removed_visits; |
1164 | 1168 |
1165 DiffVisits(old_visits, new_url, &new_visits, &removed_visits); | 1169 DiffVisits(old_visits, new_url, &new_visits, &removed_visits); |
1166 EXPECT_TRUE(new_visits.empty()); | 1170 EXPECT_TRUE(new_visits.empty()); |
1167 EXPECT_TRUE(removed_visits.empty()); | 1171 EXPECT_TRUE(removed_visits.empty()); |
1168 } | 1172 } |
1169 | 1173 |
1170 // Create two set of visits for history DB and sync DB. Check DiffVisits will | 1174 // Create two set of visits for history DB and sync DB. Check DiffVisits will |
1171 // return correct set of diff visits. | 1175 // return correct set of diff visits. |
1172 TEST_F(TypedUrlSyncableServiceTest, DiffVisitsRemove) { | 1176 TEST_F(TypedUrlSyncableServiceTest, DiffVisitsRemove) { |
1173 history::VisitVector old_visits; | 1177 history::VisitVector old_visits; |
1174 sync_pb::TypedUrlSpecifics new_url; | 1178 sync_pb::TypedUrlSpecifics new_url; |
1175 | 1179 |
1176 const int64 visits_left[] = {1, 2, 1024, 1500, 2065, | 1180 const int64_t visits_left[] = {1, 2, 1024, 1500, 2065, |
1177 6000, 65534, 1237684, 2237684}; | 1181 6000, 65534, 1237684, 2237684}; |
1178 const int64 visits_right[] = {1024, 2065, 65534, 1237684}; | 1182 const int64_t visits_right[] = {1024, 2065, 65534, 1237684}; |
1179 | 1183 |
1180 // DiffVisits will not remove the first visit, because we never delete visits | 1184 // DiffVisits will not remove the first visit, because we never delete visits |
1181 // from the start of the array (since those visits can get truncated by the | 1185 // from the start of the array (since those visits can get truncated by the |
1182 // size-limiting code). | 1186 // size-limiting code). |
1183 const int64 visits_removed[] = {1500, 6000, 2237684}; | 1187 const int64_t visits_removed[] = {1500, 6000, 2237684}; |
1184 | 1188 |
1185 for (int64 visit : visits_left) { | 1189 for (int64_t visit : visits_left) { |
1186 old_visits.push_back(history::VisitRow(0, | 1190 old_visits.push_back(history::VisitRow(0, |
1187 base::Time::FromInternalValue(visit), | 1191 base::Time::FromInternalValue(visit), |
1188 0, ui::PAGE_TRANSITION_TYPED, 0)); | 1192 0, ui::PAGE_TRANSITION_TYPED, 0)); |
1189 } | 1193 } |
1190 | 1194 |
1191 for (int64 visit : visits_right) { | 1195 for (int64_t visit : visits_right) { |
1192 new_url.add_visits(visit); | 1196 new_url.add_visits(visit); |
1193 new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); | 1197 new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); |
1194 } | 1198 } |
1195 | 1199 |
1196 std::vector<history::VisitInfo> new_visits; | 1200 std::vector<history::VisitInfo> new_visits; |
1197 history::VisitVector removed_visits; | 1201 history::VisitVector removed_visits; |
1198 | 1202 |
1199 DiffVisits(old_visits, new_url, &new_visits, &removed_visits); | 1203 DiffVisits(old_visits, new_url, &new_visits, &removed_visits); |
1200 EXPECT_TRUE(new_visits.empty()); | 1204 EXPECT_TRUE(new_visits.empty()); |
1201 ASSERT_EQ(removed_visits.size(), arraysize(visits_removed)); | 1205 ASSERT_EQ(removed_visits.size(), arraysize(visits_removed)); |
1202 for (size_t i = 0; i < arraysize(visits_removed); ++i) { | 1206 for (size_t i = 0; i < arraysize(visits_removed); ++i) { |
1203 EXPECT_EQ(removed_visits[i].visit_time.ToInternalValue(), | 1207 EXPECT_EQ(removed_visits[i].visit_time.ToInternalValue(), |
1204 visits_removed[i]); | 1208 visits_removed[i]); |
1205 } | 1209 } |
1206 } | 1210 } |
1207 | 1211 |
1208 // Create two set of visits for history DB and sync DB. Check DiffVisits will | 1212 // Create two set of visits for history DB and sync DB. Check DiffVisits will |
1209 // return correct set of diff visits. | 1213 // return correct set of diff visits. |
1210 TEST_F(TypedUrlSyncableServiceTest, DiffVisitsAdd) { | 1214 TEST_F(TypedUrlSyncableServiceTest, DiffVisitsAdd) { |
1211 history::VisitVector old_visits; | 1215 history::VisitVector old_visits; |
1212 sync_pb::TypedUrlSpecifics new_url; | 1216 sync_pb::TypedUrlSpecifics new_url; |
1213 | 1217 |
1214 const int64 visits_left[] = {1024, 2065, 65534, 1237684}; | 1218 const int64_t visits_left[] = {1024, 2065, 65534, 1237684}; |
1215 const int64 visits_right[] = {1, 1024, 1500, 2065, | 1219 const int64_t visits_right[] = {1, 1024, 1500, 2065, |
1216 6000, 65534, 1237684, 2237684}; | 1220 6000, 65534, 1237684, 2237684}; |
1217 | 1221 |
1218 const int64 visits_added[] = {1, 1500, 6000, 2237684}; | 1222 const int64_t visits_added[] = {1, 1500, 6000, 2237684}; |
1219 | 1223 |
1220 for (int64 visit : visits_left) { | 1224 for (int64_t visit : visits_left) { |
1221 old_visits.push_back(history::VisitRow(0, | 1225 old_visits.push_back(history::VisitRow(0, |
1222 base::Time::FromInternalValue(visit), | 1226 base::Time::FromInternalValue(visit), |
1223 0, ui::PAGE_TRANSITION_TYPED, 0)); | 1227 0, ui::PAGE_TRANSITION_TYPED, 0)); |
1224 } | 1228 } |
1225 | 1229 |
1226 for (int64 visit : visits_right) { | 1230 for (int64_t visit : visits_right) { |
1227 new_url.add_visits(visit); | 1231 new_url.add_visits(visit); |
1228 new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); | 1232 new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); |
1229 } | 1233 } |
1230 | 1234 |
1231 std::vector<history::VisitInfo> new_visits; | 1235 std::vector<history::VisitInfo> new_visits; |
1232 history::VisitVector removed_visits; | 1236 history::VisitVector removed_visits; |
1233 | 1237 |
1234 DiffVisits(old_visits, new_url, &new_visits, &removed_visits); | 1238 DiffVisits(old_visits, new_url, &new_visits, &removed_visits); |
1235 EXPECT_TRUE(removed_visits.empty()); | 1239 EXPECT_TRUE(removed_visits.empty()); |
1236 ASSERT_TRUE(new_visits.size() == arraysize(visits_added)); | 1240 ASSERT_TRUE(new_visits.size() == arraysize(visits_added)); |
(...skipping 21 matching lines...) Expand all Loading... |
1258 EXPECT_EQ(3, typed_url.visits(1)); | 1262 EXPECT_EQ(3, typed_url.visits(1)); |
1259 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, | 1263 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, |
1260 ui::PageTransitionFromInt(typed_url.visit_transitions(0))); | 1264 ui::PageTransitionFromInt(typed_url.visit_transitions(0))); |
1261 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, | 1265 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, |
1262 ui::PageTransitionFromInt(typed_url.visit_transitions(1))); | 1266 ui::PageTransitionFromInt(typed_url.visit_transitions(1))); |
1263 } | 1267 } |
1264 | 1268 |
1265 // Create 101 visits, check WriteToTypedUrlSpecifics will only keep 100 visits. | 1269 // Create 101 visits, check WriteToTypedUrlSpecifics will only keep 100 visits. |
1266 TEST_F(TypedUrlSyncableServiceTest, TooManyVisits) { | 1270 TEST_F(TypedUrlSyncableServiceTest, TooManyVisits) { |
1267 history::VisitVector visits; | 1271 history::VisitVector visits; |
1268 int64 timestamp = 1000; | 1272 int64_t timestamp = 1000; |
1269 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_TYPED, timestamp++)); | 1273 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_TYPED, timestamp++)); |
1270 for (int i = 0; i < 100; ++i) { | 1274 for (int i = 0; i < 100; ++i) { |
1271 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_LINK, timestamp++)); | 1275 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_LINK, timestamp++)); |
1272 } | 1276 } |
1273 history::URLRow url( | 1277 history::URLRow url( |
1274 MakeTypedUrlRow(kURL, kTitle, 0, timestamp++, false, &visits)); | 1278 MakeTypedUrlRow(kURL, kTitle, 0, timestamp++, false, &visits)); |
1275 sync_pb::TypedUrlSpecifics typed_url; | 1279 sync_pb::TypedUrlSpecifics typed_url; |
1276 WriteToTypedUrlSpecifics(url, visits, &typed_url); | 1280 WriteToTypedUrlSpecifics(url, visits, &typed_url); |
1277 // # visits should be capped at 100. | 1281 // # visits should be capped at 100. |
1278 EXPECT_EQ(100, typed_url.visits_size()); | 1282 EXPECT_EQ(100, typed_url.visits_size()); |
1279 EXPECT_EQ(typed_url.visit_transitions_size(), typed_url.visits_size()); | 1283 EXPECT_EQ(typed_url.visit_transitions_size(), typed_url.visits_size()); |
1280 EXPECT_EQ(1000, typed_url.visits(0)); | 1284 EXPECT_EQ(1000, typed_url.visits(0)); |
1281 // Visit with timestamp of 1001 should be omitted since we should have | 1285 // Visit with timestamp of 1001 should be omitted since we should have |
1282 // skipped that visit to stay under the cap. | 1286 // skipped that visit to stay under the cap. |
1283 EXPECT_EQ(1002, typed_url.visits(1)); | 1287 EXPECT_EQ(1002, typed_url.visits(1)); |
1284 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, | 1288 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, |
1285 ui::PageTransitionFromInt(typed_url.visit_transitions(0))); | 1289 ui::PageTransitionFromInt(typed_url.visit_transitions(0))); |
1286 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, | 1290 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, |
1287 ui::PageTransitionFromInt(typed_url.visit_transitions(1))); | 1291 ui::PageTransitionFromInt(typed_url.visit_transitions(1))); |
1288 } | 1292 } |
1289 | 1293 |
1290 // Create 306 visits, check WriteToTypedUrlSpecifics will only keep 100 typed | 1294 // Create 306 visits, check WriteToTypedUrlSpecifics will only keep 100 typed |
1291 // visits. | 1295 // visits. |
1292 TEST_F(TypedUrlSyncableServiceTest, TooManyTypedVisits) { | 1296 TEST_F(TypedUrlSyncableServiceTest, TooManyTypedVisits) { |
1293 history::VisitVector visits; | 1297 history::VisitVector visits; |
1294 int64 timestamp = 1000; | 1298 int64_t timestamp = 1000; |
1295 for (int i = 0; i < 102; ++i) { | 1299 for (int i = 0; i < 102; ++i) { |
1296 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_TYPED, timestamp++)); | 1300 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_TYPED, timestamp++)); |
1297 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_LINK, timestamp++)); | 1301 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_LINK, timestamp++)); |
1298 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_RELOAD, timestamp++)); | 1302 visits.push_back(CreateVisit(ui::PAGE_TRANSITION_RELOAD, timestamp++)); |
1299 } | 1303 } |
1300 history::URLRow url( | 1304 history::URLRow url( |
1301 MakeTypedUrlRow(kURL, kTitle, 0, timestamp++, false, &visits)); | 1305 MakeTypedUrlRow(kURL, kTitle, 0, timestamp++, false, &visits)); |
1302 sync_pb::TypedUrlSpecifics typed_url; | 1306 sync_pb::TypedUrlSpecifics typed_url; |
1303 WriteToTypedUrlSpecifics(url, visits, &typed_url); | 1307 WriteToTypedUrlSpecifics(url, visits, &typed_url); |
1304 // # visits should be capped at 100. | 1308 // # visits should be capped at 100. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 // We should not sync the visit with timestamp #1 since it is earlier than | 1448 // We should not sync the visit with timestamp #1 since it is earlier than |
1445 // any other visit for this URL in the history DB. But we should sync visit | 1449 // any other visit for this URL in the history DB. But we should sync visit |
1446 // #4. | 1450 // #4. |
1447 EXPECT_EQ(3U, history_visits.size()); | 1451 EXPECT_EQ(3U, history_visits.size()); |
1448 EXPECT_EQ(2U, history_visits[0].visit_time.ToInternalValue()); | 1452 EXPECT_EQ(2U, history_visits[0].visit_time.ToInternalValue()); |
1449 EXPECT_EQ(3U, history_visits[1].visit_time.ToInternalValue()); | 1453 EXPECT_EQ(3U, history_visits[1].visit_time.ToInternalValue()); |
1450 EXPECT_EQ(4U, history_visits[2].visit_time.ToInternalValue()); | 1454 EXPECT_EQ(4U, history_visits[2].visit_time.ToInternalValue()); |
1451 } | 1455 } |
1452 | 1456 |
1453 } // namespace history | 1457 } // namespace history |
OLD | NEW |