OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
24 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
26 #include "components/browser_sync/browser/abstract_profile_sync_service_test.h" | 26 #include "components/browser_sync/abstract_profile_sync_service_test.h" |
27 #include "components/browser_sync/browser/test_profile_sync_service.h" | 27 #include "components/browser_sync/test_profile_sync_service.h" |
28 #include "components/history/core/browser/history_backend.h" | 28 #include "components/history/core/browser/history_backend.h" |
29 #include "components/history/core/browser/history_backend_client.h" | 29 #include "components/history/core/browser/history_backend_client.h" |
30 #include "components/history/core/browser/history_backend_notifier.h" | 30 #include "components/history/core/browser/history_backend_notifier.h" |
31 #include "components/history/core/browser/history_db_task.h" | 31 #include "components/history/core/browser/history_db_task.h" |
32 #include "components/history/core/browser/history_service.h" | 32 #include "components/history/core/browser/history_service.h" |
33 #include "components/history/core/browser/typed_url_data_type_controller.h" | 33 #include "components/history/core/browser/typed_url_data_type_controller.h" |
34 #include "components/signin/core/browser/signin_manager.h" | 34 #include "components/signin/core/browser/signin_manager.h" |
35 #include "components/sync/api/data_type_error_handler_mock.h" | 35 #include "components/sync/api/data_type_error_handler_mock.h" |
36 #include "components/sync/core/read_node.h" | 36 #include "components/sync/core/read_node.h" |
37 #include "components/sync/core/read_transaction.h" | 37 #include "components/sync/core/read_transaction.h" |
(...skipping 26 matching lines...) Expand all Loading... |
64 } | 64 } |
65 | 65 |
66 class HistoryBackendMock : public HistoryBackend { | 66 class HistoryBackendMock : public HistoryBackend { |
67 public: | 67 public: |
68 HistoryBackendMock() | 68 HistoryBackendMock() |
69 : HistoryBackend(nullptr, nullptr, base::ThreadTaskRunnerHandle::Get()) {} | 69 : HistoryBackend(nullptr, nullptr, base::ThreadTaskRunnerHandle::Get()) {} |
70 bool IsExpiredVisitTime(const base::Time& time) override { | 70 bool IsExpiredVisitTime(const base::Time& time) override { |
71 return time.ToInternalValue() == EXPIRED_VISIT; | 71 return time.ToInternalValue() == EXPIRED_VISIT; |
72 } | 72 } |
73 MOCK_METHOD1(GetAllTypedURLs, bool(history::URLRows* entries)); | 73 MOCK_METHOD1(GetAllTypedURLs, bool(history::URLRows* entries)); |
74 MOCK_METHOD3(GetMostRecentVisitsForURL, bool(history::URLID id, | 74 MOCK_METHOD3(GetMostRecentVisitsForURL, |
75 int max_visits, | 75 bool(history::URLID id, |
76 history::VisitVector* visits)); | 76 int max_visits, |
| 77 history::VisitVector* visits)); |
77 MOCK_METHOD2(UpdateURL, bool(history::URLID id, const history::URLRow& url)); | 78 MOCK_METHOD2(UpdateURL, bool(history::URLID id, const history::URLRow& url)); |
78 MOCK_METHOD3(AddVisits, bool(const GURL& url, | 79 MOCK_METHOD3(AddVisits, |
79 const std::vector<history::VisitInfo>& visits, | 80 bool(const GURL& url, |
80 history::VisitSource visit_source)); | 81 const std::vector<history::VisitInfo>& visits, |
| 82 history::VisitSource visit_source)); |
81 MOCK_METHOD2(GetURL, bool(const GURL& url_id, history::URLRow* url_row)); | 83 MOCK_METHOD2(GetURL, bool(const GURL& url_id, history::URLRow* url_row)); |
82 MOCK_METHOD2(SetPageTitle, void(const GURL& url, | 84 MOCK_METHOD2(SetPageTitle, |
83 const base::string16& title)); | 85 void(const GURL& url, const base::string16& title)); |
84 MOCK_METHOD1(DeleteURL, void(const GURL& url)); | 86 MOCK_METHOD1(DeleteURL, void(const GURL& url)); |
85 | 87 |
86 private: | 88 private: |
87 friend class ProfileSyncServiceTypedUrlTest; | 89 friend class ProfileSyncServiceTypedUrlTest; |
88 | 90 |
89 virtual ~HistoryBackendMock() {} | 91 virtual ~HistoryBackendMock() {} |
90 }; | 92 }; |
91 | 93 |
92 class HistoryServiceMock : public history::HistoryService { | 94 class HistoryServiceMock : public history::HistoryService { |
93 public: | 95 public: |
94 HistoryServiceMock() : history::HistoryService(), backend_(nullptr) {} | 96 HistoryServiceMock() : history::HistoryService(), backend_(nullptr) {} |
95 | 97 |
96 base::CancelableTaskTracker::TaskId ScheduleDBTask( | 98 base::CancelableTaskTracker::TaskId ScheduleDBTask( |
97 std::unique_ptr<history::HistoryDBTask> task, | 99 std::unique_ptr<history::HistoryDBTask> task, |
98 base::CancelableTaskTracker* tracker) override { | 100 base::CancelableTaskTracker* tracker) override { |
99 // Explicitly copy out the raw pointer -- compilers might decide to | 101 // Explicitly copy out the raw pointer -- compilers might decide to |
100 // evaluate task.release() before the arguments for the first Bind(). | 102 // evaluate task.release() before the arguments for the first Bind(). |
101 history::HistoryDBTask* task_raw = task.get(); | 103 history::HistoryDBTask* task_raw = task.get(); |
102 task_runner_->PostTaskAndReply( | 104 task_runner_->PostTaskAndReply( |
103 FROM_HERE, | 105 FROM_HERE, base::Bind(&HistoryServiceMock::RunTaskOnDBThread, |
104 base::Bind(&HistoryServiceMock::RunTaskOnDBThread, | 106 base::Unretained(this), task_raw), |
105 base::Unretained(this), task_raw), | |
106 base::Bind(&base::DeletePointer<history::HistoryDBTask>, | 107 base::Bind(&base::DeletePointer<history::HistoryDBTask>, |
107 task.release())); | 108 task.release())); |
108 return base::CancelableTaskTracker::kBadTaskId; // unused | 109 return base::CancelableTaskTracker::kBadTaskId; // unused |
109 } | 110 } |
110 | 111 |
111 ~HistoryServiceMock() override {} | 112 ~HistoryServiceMock() override {} |
112 | 113 |
113 void set_task_runner( | 114 void set_task_runner( |
114 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 115 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
115 DCHECK(task_runner.get()); | 116 DCHECK(task_runner.get()); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 FROM_HERE, task, | 307 FROM_HERE, task, |
307 base::Bind(&base::MessageLoop::QuitNow, | 308 base::Bind(&base::MessageLoop::QuitNow, |
308 base::Unretained(base::MessageLoop::current()))); | 309 base::Unretained(base::MessageLoop::current()))); |
309 base::RunLoop().Run(); | 310 base::RunLoop().Run(); |
310 } | 311 } |
311 | 312 |
312 void SendNotificationURLVisited(ui::PageTransition transition, | 313 void SendNotificationURLVisited(ui::PageTransition transition, |
313 const history::URLRow& row) { | 314 const history::URLRow& row) { |
314 base::Time visit_time; | 315 base::Time visit_time; |
315 history::RedirectList redirects; | 316 history::RedirectList redirects; |
316 SendNotification( | 317 SendNotification(base::Bind(&HistoryBackendNotifier::NotifyURLVisited, |
317 base::Bind(&HistoryBackendNotifier::NotifyURLVisited, | 318 base::Unretained(history_backend_.get()), |
318 base::Unretained(history_backend_.get()), | 319 transition, row, redirects, visit_time)); |
319 transition, | |
320 row, | |
321 redirects, | |
322 visit_time)); | |
323 } | 320 } |
324 | 321 |
325 void SendNotificationURLsModified(const history::URLRows& rows) { | 322 void SendNotificationURLsModified(const history::URLRows& rows) { |
326 SendNotification(base::Bind(&HistoryBackendNotifier::NotifyURLsModified, | 323 SendNotification(base::Bind(&HistoryBackendNotifier::NotifyURLsModified, |
327 base::Unretained(history_backend_.get()), | 324 base::Unretained(history_backend_.get()), |
328 rows)); | 325 rows)); |
329 } | 326 } |
330 | 327 |
331 void SendNotificationURLsDeleted(bool all_history, | 328 void SendNotificationURLsDeleted(bool all_history, |
332 bool expired, | 329 bool expired, |
(...skipping 21 matching lines...) Expand all Loading... |
354 int typed_count, | 351 int typed_count, |
355 int64_t last_visit, | 352 int64_t last_visit, |
356 bool hidden, | 353 bool hidden, |
357 history::VisitVector* visits) { | 354 history::VisitVector* visits) { |
358 // Give each URL a unique ID, to mimic the behavior of the real database. | 355 // Give each URL a unique ID, to mimic the behavior of the real database. |
359 static int unique_url_id = 0; | 356 static int unique_url_id = 0; |
360 GURL gurl(url); | 357 GURL gurl(url); |
361 history::URLRow history_url(gurl, ++unique_url_id); | 358 history::URLRow history_url(gurl, ++unique_url_id); |
362 history_url.set_title(base::UTF8ToUTF16(title)); | 359 history_url.set_title(base::UTF8ToUTF16(title)); |
363 history_url.set_typed_count(typed_count); | 360 history_url.set_typed_count(typed_count); |
364 history_url.set_last_visit( | 361 history_url.set_last_visit(base::Time::FromInternalValue(last_visit)); |
365 base::Time::FromInternalValue(last_visit)); | |
366 history_url.set_hidden(hidden); | 362 history_url.set_hidden(hidden); |
367 visits->push_back(history::VisitRow( | 363 visits->push_back(history::VisitRow(history_url.id(), |
368 history_url.id(), history_url.last_visit(), 0, | 364 history_url.last_visit(), 0, |
369 ui::PAGE_TRANSITION_TYPED, 0)); | 365 ui::PAGE_TRANSITION_TYPED, 0)); |
370 history_url.set_visit_count(visits->size()); | 366 history_url.set_visit_count(visits->size()); |
371 return history_url; | 367 return history_url; |
372 } | 368 } |
373 | 369 |
374 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 370 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( |
375 syncer::ModelType type) { | 371 syncer::ModelType type) { |
376 DCHECK_EQ(syncer::TYPED_URLS, type); | 372 DCHECK_EQ(syncer::TYPED_URLS, type); |
377 return syncable_service_->AsWeakPtr(); | 373 return syncable_service_->AsWeakPtr(); |
378 } | 374 } |
379 | 375 |
380 HistoryBackendMock& history_backend() { return *history_backend_.get(); } | 376 HistoryBackendMock& history_backend() { return *history_backend_.get(); } |
381 | 377 |
382 private: | 378 private: |
383 scoped_refptr<HistoryBackendMock> history_backend_; | 379 scoped_refptr<HistoryBackendMock> history_backend_; |
384 std::unique_ptr<HistoryServiceMock> history_service_; | 380 std::unique_ptr<HistoryServiceMock> history_service_; |
385 syncer::DataTypeErrorHandlerMock error_handler_; | 381 syncer::DataTypeErrorHandlerMock error_handler_; |
386 std::unique_ptr<TestTypedUrlSyncableService> syncable_service_; | 382 std::unique_ptr<TestTypedUrlSyncableService> syncable_service_; |
387 std::unique_ptr<sync_driver::FakeSyncClient> sync_client_; | 383 std::unique_ptr<sync_driver::FakeSyncClient> sync_client_; |
388 | 384 |
389 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTypedUrlTest); | 385 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTypedUrlTest); |
390 }; | 386 }; |
391 | 387 |
392 void AddTypedUrlEntries(ProfileSyncServiceTypedUrlTest* test, | 388 void AddTypedUrlEntries(ProfileSyncServiceTypedUrlTest* test, |
393 const history::URLRows& entries) { | 389 const history::URLRows& entries) { |
394 test->CreateRoot(syncer::TYPED_URLS); | 390 test->CreateRoot(syncer::TYPED_URLS); |
395 for (size_t i = 0; i < entries.size(); ++i) { | 391 for (size_t i = 0; i < entries.size(); ++i) { |
396 history::VisitVector visits; | 392 history::VisitVector visits; |
397 visits.push_back(history::VisitRow( | 393 visits.push_back(history::VisitRow(entries[i].id(), entries[i].last_visit(), |
398 entries[i].id(), entries[i].last_visit(), 0, | 394 0, ui::PageTransitionFromInt(0), 0)); |
399 ui::PageTransitionFromInt(0), 0)); | |
400 test->AddTypedUrlSyncNode(entries[i], visits); | 395 test->AddTypedUrlSyncNode(entries[i], visits); |
401 } | 396 } |
402 } | 397 } |
403 | 398 |
404 } // namespace | 399 } // namespace |
405 | 400 |
406 TEST_F(ProfileSyncServiceTypedUrlTest, EmptyNativeEmptySync) { | 401 TEST_F(ProfileSyncServiceTypedUrlTest, EmptyNativeEmptySync) { |
407 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); | 402 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); |
408 SetIdleChangeProcessorExpectations(); | 403 SetIdleChangeProcessorExpectations(); |
409 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 404 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
410 TypedUrlSyncableService* syncable_service = | 405 TypedUrlSyncableService* syncable_service = |
411 StartSyncService(create_root.callback()); | 406 StartSyncService(create_root.callback()); |
412 history::URLRows sync_entries; | 407 history::URLRows sync_entries; |
413 GetTypedUrlsFromSyncDB(&sync_entries); | 408 GetTypedUrlsFromSyncDB(&sync_entries); |
414 EXPECT_EQ(0U, sync_entries.size()); | 409 EXPECT_EQ(0U, sync_entries.size()); |
415 ASSERT_EQ(0, syncable_service->GetErrorPercentage()); | 410 ASSERT_EQ(0, syncable_service->GetErrorPercentage()); |
416 } | 411 } |
417 | 412 |
418 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeEmptySync) { | 413 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeEmptySync) { |
419 history::URLRows entries; | 414 history::URLRows entries; |
420 history::VisitVector visits; | 415 history::VisitVector visits; |
421 entries.push_back(MakeTypedUrlEntry("http://foo.com", "bar", | 416 entries.push_back( |
422 2, 15, false, &visits)); | 417 MakeTypedUrlEntry("http://foo.com", "bar", 2, 15, false, &visits)); |
423 | 418 |
424 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 419 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
425 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); | 420 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); |
426 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 421 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
427 .WillRepeatedly(DoAll(SetArgumentPointee<2>(visits), Return(true))); | 422 .WillRepeatedly(DoAll(SetArgumentPointee<2>(visits), Return(true))); |
428 SetIdleChangeProcessorExpectations(); | 423 SetIdleChangeProcessorExpectations(); |
429 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 424 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
430 TypedUrlSyncableService* syncable_service = | 425 TypedUrlSyncableService* syncable_service = |
431 StartSyncService(create_root.callback()); | 426 StartSyncService(create_root.callback()); |
432 history::URLRows sync_entries; | 427 history::URLRows sync_entries; |
433 GetTypedUrlsFromSyncDB(&sync_entries); | 428 GetTypedUrlsFromSyncDB(&sync_entries); |
434 ASSERT_EQ(1U, sync_entries.size()); | 429 ASSERT_EQ(1U, sync_entries.size()); |
435 EXPECT_TRUE(URLsEqual(entries[0], sync_entries[0])); | 430 EXPECT_TRUE(URLsEqual(entries[0], sync_entries[0])); |
436 ASSERT_EQ(0, syncable_service->GetErrorPercentage()); | 431 ASSERT_EQ(0, syncable_service->GetErrorPercentage()); |
437 } | 432 } |
438 | 433 |
439 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeErrorReadingVisits) { | 434 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeErrorReadingVisits) { |
440 history::URLRows entries; | 435 history::URLRows entries; |
441 history::VisitVector visits; | 436 history::VisitVector visits; |
442 history::URLRow native_entry1(MakeTypedUrlEntry("http://foo.com", "bar", | 437 history::URLRow native_entry1( |
443 2, 15, false, &visits)); | 438 MakeTypedUrlEntry("http://foo.com", "bar", 2, 15, false, &visits)); |
444 history::URLRow native_entry2(MakeTypedUrlEntry("http://foo2.com", "bar", | 439 history::URLRow native_entry2( |
445 3, 15, false, &visits)); | 440 MakeTypedUrlEntry("http://foo2.com", "bar", 3, 15, false, &visits)); |
446 entries.push_back(native_entry1); | 441 entries.push_back(native_entry1); |
447 entries.push_back(native_entry2); | 442 entries.push_back(native_entry2); |
448 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 443 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
449 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); | 444 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); |
450 // Return an error from GetMostRecentVisitsForURL() for the second URL. | 445 // Return an error from GetMostRecentVisitsForURL() for the second URL. |
451 EXPECT_CALL((history_backend()), | 446 EXPECT_CALL((history_backend()), |
452 GetMostRecentVisitsForURL(native_entry1.id(), _, _)) | 447 GetMostRecentVisitsForURL(native_entry1.id(), _, _)) |
453 .WillRepeatedly(Return(true)); | 448 .WillRepeatedly(Return(true)); |
454 EXPECT_CALL((history_backend()), | 449 EXPECT_CALL((history_backend()), |
455 GetMostRecentVisitsForURL(native_entry2.id(), _, _)) | 450 GetMostRecentVisitsForURL(native_entry2.id(), _, _)) |
456 .WillRepeatedly(Return(false)); | 451 .WillRepeatedly(Return(false)); |
457 SetIdleChangeProcessorExpectations(); | 452 SetIdleChangeProcessorExpectations(); |
458 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 453 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
459 StartSyncService(create_root.callback()); | 454 StartSyncService(create_root.callback()); |
460 history::URLRows sync_entries; | 455 history::URLRows sync_entries; |
461 GetTypedUrlsFromSyncDB(&sync_entries); | 456 GetTypedUrlsFromSyncDB(&sync_entries); |
462 ASSERT_EQ(1U, sync_entries.size()); | 457 ASSERT_EQ(1U, sync_entries.size()); |
463 EXPECT_TRUE(URLsEqual(native_entry1, sync_entries[0])); | 458 EXPECT_TRUE(URLsEqual(native_entry1, sync_entries[0])); |
464 } | 459 } |
465 | 460 |
466 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeWithBlankEmptySync) { | 461 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeWithBlankEmptySync) { |
467 std::vector<history::URLRow> entries; | 462 std::vector<history::URLRow> entries; |
468 history::VisitVector visits; | 463 history::VisitVector visits; |
469 // Add an empty URL. | 464 // Add an empty URL. |
470 entries.push_back(MakeTypedUrlEntry("", "bar", | 465 entries.push_back(MakeTypedUrlEntry("", "bar", 2, 15, false, &visits)); |
471 2, 15, false, &visits)); | 466 entries.push_back( |
472 entries.push_back(MakeTypedUrlEntry("http://foo.com", "bar", | 467 MakeTypedUrlEntry("http://foo.com", "bar", 2, 15, false, &visits)); |
473 2, 15, false, &visits)); | |
474 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 468 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
475 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); | 469 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); |
476 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 470 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
477 .WillRepeatedly(DoAll(SetArgumentPointee<2>(visits), Return(true))); | 471 .WillRepeatedly(DoAll(SetArgumentPointee<2>(visits), Return(true))); |
478 SetIdleChangeProcessorExpectations(); | 472 SetIdleChangeProcessorExpectations(); |
479 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 473 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
480 StartSyncService(create_root.callback()); | 474 StartSyncService(create_root.callback()); |
481 std::vector<history::URLRow> sync_entries; | 475 std::vector<history::URLRow> sync_entries; |
482 GetTypedUrlsFromSyncDB(&sync_entries); | 476 GetTypedUrlsFromSyncDB(&sync_entries); |
483 // The empty URL should be ignored. | 477 // The empty URL should be ignored. |
484 ASSERT_EQ(1U, sync_entries.size()); | 478 ASSERT_EQ(1U, sync_entries.size()); |
485 EXPECT_TRUE(URLsEqual(entries[1], sync_entries[0])); | 479 EXPECT_TRUE(URLsEqual(entries[1], sync_entries[0])); |
486 } | 480 } |
487 | 481 |
488 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeHasSyncNoMerge) { | 482 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeHasSyncNoMerge) { |
489 history::VisitVector native_visits; | 483 history::VisitVector native_visits; |
490 history::VisitVector sync_visits; | 484 history::VisitVector sync_visits; |
491 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", | 485 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", |
492 2, 15, false, &native_visits)); | 486 2, 15, false, &native_visits)); |
493 history::URLRow sync_entry(MakeTypedUrlEntry("http://sync.com", "entry", | 487 history::URLRow sync_entry(MakeTypedUrlEntry("http://sync.com", "entry", 3, |
494 3, 16, false, &sync_visits)); | 488 16, false, &sync_visits)); |
495 | 489 |
496 history::URLRows native_entries; | 490 history::URLRows native_entries; |
497 native_entries.push_back(native_entry); | 491 native_entries.push_back(native_entry); |
498 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 492 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
499 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 493 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
500 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 494 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
501 .WillRepeatedly( | 495 .WillRepeatedly( |
502 DoAll(SetArgumentPointee<2>(native_visits), Return(true))); | 496 DoAll(SetArgumentPointee<2>(native_visits), Return(true))); |
503 EXPECT_CALL((history_backend()), AddVisits(_, _, history::SOURCE_SYNCED)) | 497 EXPECT_CALL((history_backend()), AddVisits(_, _, history::SOURCE_SYNCED)) |
504 .WillRepeatedly(Return(true)); | 498 .WillRepeatedly(Return(true)); |
(...skipping 14 matching lines...) Expand all Loading... |
519 | 513 |
520 EXPECT_TRUE(new_sync_entries.size() == expected.size()); | 514 EXPECT_TRUE(new_sync_entries.size() == expected.size()); |
521 for (history::URLRows::iterator entry = new_sync_entries.begin(); | 515 for (history::URLRows::iterator entry = new_sync_entries.begin(); |
522 entry != new_sync_entries.end(); ++entry) { | 516 entry != new_sync_entries.end(); ++entry) { |
523 EXPECT_TRUE(URLsEqual(expected[entry->url().spec()], *entry)); | 517 EXPECT_TRUE(URLsEqual(expected[entry->url().spec()], *entry)); |
524 } | 518 } |
525 } | 519 } |
526 | 520 |
527 TEST_F(ProfileSyncServiceTypedUrlTest, EmptyNativeExpiredSync) { | 521 TEST_F(ProfileSyncServiceTypedUrlTest, EmptyNativeExpiredSync) { |
528 history::VisitVector sync_visits; | 522 history::VisitVector sync_visits; |
529 history::URLRow sync_entry(MakeTypedUrlEntry("http://sync.com", "entry", | 523 history::URLRow sync_entry(MakeTypedUrlEntry( |
530 3, EXPIRED_VISIT, false, | 524 "http://sync.com", "entry", 3, EXPIRED_VISIT, false, &sync_visits)); |
531 &sync_visits)); | |
532 history::URLRows sync_entries; | 525 history::URLRows sync_entries; |
533 sync_entries.push_back(sync_entry); | 526 sync_entries.push_back(sync_entry); |
534 | 527 |
535 // Since all our URLs are expired, no backend calls to add new URLs will be | 528 // Since all our URLs are expired, no backend calls to add new URLs will be |
536 // made. | 529 // made. |
537 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); | 530 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); |
538 SetIdleChangeProcessorExpectations(); | 531 SetIdleChangeProcessorExpectations(); |
539 | 532 |
540 StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); | 533 StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); |
541 } | 534 } |
542 | 535 |
543 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeHasSyncMerge) { | 536 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeHasSyncMerge) { |
544 history::VisitVector native_visits; | 537 history::VisitVector native_visits; |
545 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", | 538 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", |
546 2, 15, false, &native_visits)); | 539 2, 15, false, &native_visits)); |
547 history::VisitVector sync_visits; | 540 history::VisitVector sync_visits; |
548 history::URLRow sync_entry(MakeTypedUrlEntry("http://native.com", "name", | 541 history::URLRow sync_entry(MakeTypedUrlEntry("http://native.com", "name", 1, |
549 1, 17, false, &sync_visits)); | 542 17, false, &sync_visits)); |
550 history::VisitVector merged_visits; | 543 history::VisitVector merged_visits; |
551 merged_visits.push_back(history::VisitRow( | 544 merged_visits.push_back( |
552 sync_entry.id(), base::Time::FromInternalValue(15), 0, | 545 history::VisitRow(sync_entry.id(), base::Time::FromInternalValue(15), 0, |
553 ui::PageTransitionFromInt(0), 0)); | 546 ui::PageTransitionFromInt(0), 0)); |
554 | 547 |
555 history::URLRow merged_entry(MakeTypedUrlEntry("http://native.com", "name", | 548 history::URLRow merged_entry(MakeTypedUrlEntry("http://native.com", "name", 2, |
556 2, 17, false, &merged_visits)); | 549 17, false, &merged_visits)); |
557 | 550 |
558 history::URLRows native_entries; | 551 history::URLRows native_entries; |
559 native_entries.push_back(native_entry); | 552 native_entries.push_back(native_entry); |
560 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 553 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
561 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 554 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
562 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 555 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
563 .WillRepeatedly( | 556 .WillRepeatedly( |
564 DoAll(SetArgumentPointee<2>(native_visits), Return(true))); | 557 DoAll(SetArgumentPointee<2>(native_visits), Return(true))); |
565 EXPECT_CALL((history_backend()), AddVisits(_, _, history::SOURCE_SYNCED)) | 558 EXPECT_CALL((history_backend()), AddVisits(_, _, history::SOURCE_SYNCED)) |
566 .WillRepeatedly(Return(true)); | 559 .WillRepeatedly(Return(true)); |
(...skipping 10 matching lines...) Expand all Loading... |
577 GetTypedUrlsFromSyncDB(&new_sync_entries); | 570 GetTypedUrlsFromSyncDB(&new_sync_entries); |
578 ASSERT_EQ(1U, new_sync_entries.size()); | 571 ASSERT_EQ(1U, new_sync_entries.size()); |
579 EXPECT_TRUE(URLsEqual(merged_entry, new_sync_entries[0])); | 572 EXPECT_TRUE(URLsEqual(merged_entry, new_sync_entries[0])); |
580 } | 573 } |
581 | 574 |
582 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeWithErrorHasSyncMerge) { | 575 TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeWithErrorHasSyncMerge) { |
583 history::VisitVector native_visits; | 576 history::VisitVector native_visits; |
584 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "native", | 577 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "native", |
585 2, 15, false, &native_visits)); | 578 2, 15, false, &native_visits)); |
586 history::VisitVector sync_visits; | 579 history::VisitVector sync_visits; |
587 history::URLRow sync_entry(MakeTypedUrlEntry("http://native.com", "sync", | 580 history::URLRow sync_entry(MakeTypedUrlEntry("http://native.com", "sync", 1, |
588 1, 17, false, &sync_visits)); | 581 17, false, &sync_visits)); |
589 | 582 |
590 history::URLRows native_entries; | 583 history::URLRows native_entries; |
591 native_entries.push_back(native_entry); | 584 native_entries.push_back(native_entry); |
592 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 585 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
593 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 586 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
594 // Return an error getting the visits for the native URL. | 587 // Return an error getting the visits for the native URL. |
595 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 588 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
596 .WillRepeatedly(Return(false)); | 589 .WillRepeatedly(Return(false)); |
597 EXPECT_CALL((history_backend()), GetURL(_, _)) | 590 EXPECT_CALL((history_backend()), GetURL(_, _)) |
598 .WillRepeatedly(DoAll(SetArgumentPointee<1>(native_entry), Return(true))); | 591 .WillRepeatedly(DoAll(SetArgumentPointee<1>(native_entry), Return(true))); |
599 EXPECT_CALL((history_backend()), AddVisits(_, _, history::SOURCE_SYNCED)) | 592 EXPECT_CALL((history_backend()), AddVisits(_, _, history::SOURCE_SYNCED)) |
600 .WillRepeatedly(Return(true)); | 593 .WillRepeatedly(Return(true)); |
601 | 594 |
602 history::URLRows sync_entries; | 595 history::URLRows sync_entries; |
603 sync_entries.push_back(sync_entry); | 596 sync_entries.push_back(sync_entry); |
604 | 597 |
605 EXPECT_CALL((history_backend()), UpdateURL(_, _)) | 598 EXPECT_CALL((history_backend()), UpdateURL(_, _)) |
606 .WillRepeatedly(Return(true)); | 599 .WillRepeatedly(Return(true)); |
607 EXPECT_CALL((history_backend()), SetPageTitle(_, _)).WillRepeatedly(Return()); | 600 EXPECT_CALL((history_backend()), SetPageTitle(_, _)).WillRepeatedly(Return()); |
608 StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); | 601 StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); |
609 | 602 |
610 history::URLRows new_sync_entries; | 603 history::URLRows new_sync_entries; |
611 GetTypedUrlsFromSyncDB(&new_sync_entries); | 604 GetTypedUrlsFromSyncDB(&new_sync_entries); |
612 ASSERT_EQ(1U, new_sync_entries.size()); | 605 ASSERT_EQ(1U, new_sync_entries.size()); |
613 EXPECT_TRUE(URLsEqual(sync_entry, new_sync_entries[0])); | 606 EXPECT_TRUE(URLsEqual(sync_entry, new_sync_entries[0])); |
614 } | 607 } |
615 | 608 |
616 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAdd) { | 609 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAdd) { |
617 history::VisitVector added_visits; | 610 history::VisitVector added_visits; |
618 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", | 611 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", 2, |
619 2, 15, false, &added_visits)); | 612 15, false, &added_visits)); |
620 | 613 |
621 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); | 614 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); |
622 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 615 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
623 .WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); | 616 .WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); |
624 | 617 |
625 SetIdleChangeProcessorExpectations(); | 618 SetIdleChangeProcessorExpectations(); |
626 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 619 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
627 StartSyncService(create_root.callback()); | 620 StartSyncService(create_root.callback()); |
628 | 621 |
629 history::URLRows changed_urls; | 622 history::URLRows changed_urls; |
630 changed_urls.push_back(added_entry); | 623 changed_urls.push_back(added_entry); |
631 SendNotificationURLsModified(changed_urls); | 624 SendNotificationURLsModified(changed_urls); |
632 | 625 |
633 history::URLRows new_sync_entries; | 626 history::URLRows new_sync_entries; |
634 GetTypedUrlsFromSyncDB(&new_sync_entries); | 627 GetTypedUrlsFromSyncDB(&new_sync_entries); |
635 ASSERT_EQ(1U, new_sync_entries.size()); | 628 ASSERT_EQ(1U, new_sync_entries.size()); |
636 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); | 629 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); |
637 } | 630 } |
638 | 631 |
639 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddWithBlank) { | 632 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddWithBlank) { |
640 history::VisitVector added_visits; | 633 history::VisitVector added_visits; |
641 history::URLRow empty_entry(MakeTypedUrlEntry("", "entry", | 634 history::URLRow empty_entry( |
642 2, 15, false, &added_visits)); | 635 MakeTypedUrlEntry("", "entry", 2, 15, false, &added_visits)); |
643 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", | 636 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", 2, |
644 2, 15, false, &added_visits)); | 637 15, false, &added_visits)); |
645 | 638 |
646 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); | 639 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); |
647 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 640 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
648 .WillRepeatedly(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); | 641 .WillRepeatedly(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); |
649 | 642 |
650 SetIdleChangeProcessorExpectations(); | 643 SetIdleChangeProcessorExpectations(); |
651 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 644 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
652 StartSyncService(create_root.callback()); | 645 StartSyncService(create_root.callback()); |
653 | 646 |
654 history::URLRows changed_urls; | 647 history::URLRows changed_urls; |
655 changed_urls.push_back(empty_entry); | 648 changed_urls.push_back(empty_entry); |
656 changed_urls.push_back(added_entry); | 649 changed_urls.push_back(added_entry); |
657 SendNotificationURLsModified(changed_urls); | 650 SendNotificationURLsModified(changed_urls); |
658 | 651 |
659 std::vector<history::URLRow> new_sync_entries; | 652 std::vector<history::URLRow> new_sync_entries; |
660 GetTypedUrlsFromSyncDB(&new_sync_entries); | 653 GetTypedUrlsFromSyncDB(&new_sync_entries); |
661 ASSERT_EQ(1U, new_sync_entries.size()); | 654 ASSERT_EQ(1U, new_sync_entries.size()); |
662 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); | 655 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); |
663 } | 656 } |
664 | 657 |
665 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdate) { | 658 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdate) { |
666 history::VisitVector original_visits; | 659 history::VisitVector original_visits; |
667 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry", | 660 history::URLRow original_entry(MakeTypedUrlEntry( |
668 2, 15, false, | 661 "http://mine.com", "entry", 2, 15, false, &original_visits)); |
669 &original_visits)); | |
670 history::URLRows original_entries; | 662 history::URLRows original_entries; |
671 original_entries.push_back(original_entry); | 663 original_entries.push_back(original_entry); |
672 | 664 |
673 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 665 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
674 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 666 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
675 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 667 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
676 .WillOnce(DoAll(SetArgumentPointee<2>(original_visits), Return(true))); | 668 .WillOnce(DoAll(SetArgumentPointee<2>(original_visits), Return(true))); |
677 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 669 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
678 StartSyncService(create_root.callback()); | 670 StartSyncService(create_root.callback()); |
679 | 671 |
680 history::VisitVector updated_visits; | 672 history::VisitVector updated_visits; |
681 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", | 673 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", 7, |
682 7, 17, false, | 674 17, false, &updated_visits)); |
683 &updated_visits)); | |
684 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 675 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
685 .WillOnce(DoAll(SetArgumentPointee<2>(updated_visits), Return(true))); | 676 .WillOnce(DoAll(SetArgumentPointee<2>(updated_visits), Return(true))); |
686 | 677 |
687 history::URLRows changed_urls; | 678 history::URLRows changed_urls; |
688 changed_urls.push_back(updated_entry); | 679 changed_urls.push_back(updated_entry); |
689 SendNotificationURLsModified(changed_urls); | 680 SendNotificationURLsModified(changed_urls); |
690 | 681 |
691 history::URLRows new_sync_entries; | 682 history::URLRows new_sync_entries; |
692 GetTypedUrlsFromSyncDB(&new_sync_entries); | 683 GetTypedUrlsFromSyncDB(&new_sync_entries); |
693 ASSERT_EQ(1U, new_sync_entries.size()); | 684 ASSERT_EQ(1U, new_sync_entries.size()); |
694 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0])); | 685 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0])); |
695 } | 686 } |
696 | 687 |
697 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddFromVisit) { | 688 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddFromVisit) { |
698 history::VisitVector added_visits; | 689 history::VisitVector added_visits; |
699 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", | 690 history::URLRow added_entry(MakeTypedUrlEntry("http://added.com", "entry", 2, |
700 2, 15, false, &added_visits)); | 691 15, false, &added_visits)); |
701 | 692 |
702 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); | 693 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)).WillOnce(Return(true)); |
703 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 694 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
704 .WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); | 695 .WillOnce(DoAll(SetArgumentPointee<2>(added_visits), Return(true))); |
705 | 696 |
706 SetIdleChangeProcessorExpectations(); | 697 SetIdleChangeProcessorExpectations(); |
707 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 698 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
708 StartSyncService(create_root.callback()); | 699 StartSyncService(create_root.callback()); |
709 | 700 |
710 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, added_entry); | 701 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, added_entry); |
711 | 702 |
712 history::URLRows new_sync_entries; | 703 history::URLRows new_sync_entries; |
713 GetTypedUrlsFromSyncDB(&new_sync_entries); | 704 GetTypedUrlsFromSyncDB(&new_sync_entries); |
714 ASSERT_EQ(1U, new_sync_entries.size()); | 705 ASSERT_EQ(1U, new_sync_entries.size()); |
715 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); | 706 EXPECT_TRUE(URLsEqual(added_entry, new_sync_entries[0])); |
716 } | 707 } |
717 | 708 |
718 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdateFromVisit) { | 709 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdateFromVisit) { |
719 history::VisitVector original_visits; | 710 history::VisitVector original_visits; |
720 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry", | 711 history::URLRow original_entry(MakeTypedUrlEntry( |
721 2, 15, false, | 712 "http://mine.com", "entry", 2, 15, false, &original_visits)); |
722 &original_visits)); | |
723 history::URLRows original_entries; | 713 history::URLRows original_entries; |
724 original_entries.push_back(original_entry); | 714 original_entries.push_back(original_entry); |
725 | 715 |
726 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 716 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
727 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 717 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
728 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 718 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
729 .WillOnce(DoAll(SetArgumentPointee<2>(original_visits), Return(true))); | 719 .WillOnce(DoAll(SetArgumentPointee<2>(original_visits), Return(true))); |
730 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 720 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
731 StartSyncService(create_root.callback()); | 721 StartSyncService(create_root.callback()); |
732 | 722 |
733 history::VisitVector updated_visits; | 723 history::VisitVector updated_visits; |
734 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", | 724 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", 7, |
735 7, 17, false, | 725 17, false, &updated_visits)); |
736 &updated_visits)); | |
737 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 726 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
738 .WillOnce(DoAll(SetArgumentPointee<2>(updated_visits), Return(true))); | 727 .WillOnce(DoAll(SetArgumentPointee<2>(updated_visits), Return(true))); |
739 | 728 |
740 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, updated_entry); | 729 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, updated_entry); |
741 | 730 |
742 history::URLRows new_sync_entries; | 731 history::URLRows new_sync_entries; |
743 GetTypedUrlsFromSyncDB(&new_sync_entries); | 732 GetTypedUrlsFromSyncDB(&new_sync_entries); |
744 ASSERT_EQ(1U, new_sync_entries.size()); | 733 ASSERT_EQ(1U, new_sync_entries.size()); |
745 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0])); | 734 EXPECT_TRUE(URLsEqual(updated_entry, new_sync_entries[0])); |
746 } | 735 } |
747 | 736 |
748 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) { | 737 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) { |
749 history::VisitVector original_visits; | 738 history::VisitVector original_visits; |
750 history::URLRow original_entry(MakeTypedUrlEntry("http://mine.com", "entry", | 739 history::URLRow original_entry(MakeTypedUrlEntry( |
751 2, 15, false, | 740 "http://mine.com", "entry", 2, 15, false, &original_visits)); |
752 &original_visits)); | |
753 history::URLRows original_entries; | 741 history::URLRows original_entries; |
754 original_entries.push_back(original_entry); | 742 original_entries.push_back(original_entry); |
755 | 743 |
756 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 744 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
757 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 745 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
758 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 746 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
759 .WillRepeatedly( | 747 .WillRepeatedly( |
760 DoAll(SetArgumentPointee<2>(original_visits), Return(true))); | 748 DoAll(SetArgumentPointee<2>(original_visits), Return(true))); |
761 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 749 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
762 StartSyncService(create_root.callback()); | 750 StartSyncService(create_root.callback()); |
763 history::URLRows new_sync_entries; | 751 history::URLRows new_sync_entries; |
764 GetTypedUrlsFromSyncDB(&new_sync_entries); | 752 GetTypedUrlsFromSyncDB(&new_sync_entries); |
765 ASSERT_EQ(1U, new_sync_entries.size()); | 753 ASSERT_EQ(1U, new_sync_entries.size()); |
766 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); | 754 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); |
767 | 755 |
768 history::VisitVector updated_visits; | 756 history::VisitVector updated_visits; |
769 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", | 757 history::URLRow updated_entry(MakeTypedUrlEntry("http://mine.com", "entry", 7, |
770 7, 15, false, | 758 15, false, &updated_visits)); |
771 &updated_visits)); | |
772 | 759 |
773 // Should ignore this change because it's not TYPED. | 760 // Should ignore this change because it's not TYPED. |
774 SendNotificationURLVisited(ui::PAGE_TRANSITION_RELOAD, updated_entry); | 761 SendNotificationURLVisited(ui::PAGE_TRANSITION_RELOAD, updated_entry); |
775 GetTypedUrlsFromSyncDB(&new_sync_entries); | 762 GetTypedUrlsFromSyncDB(&new_sync_entries); |
776 | 763 |
777 // Should be no changes to the sync DB from this notification. | 764 // Should be no changes to the sync DB from this notification. |
778 ASSERT_EQ(1U, new_sync_entries.size()); | 765 ASSERT_EQ(1U, new_sync_entries.size()); |
779 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); | 766 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); |
780 | 767 |
781 // Now, try updating it with a large number of visits not divisible by 10 | 768 // Now, try updating it with a large number of visits not divisible by 10 |
782 // (should ignore this visit). | 769 // (should ignore this visit). |
783 history::URLRow twelve_visits(MakeTypedUrlEntry("http://mine.com", "entry", | 770 history::URLRow twelve_visits(MakeTypedUrlEntry( |
784 12, 15, false, | 771 "http://mine.com", "entry", 12, 15, false, &updated_visits)); |
785 &updated_visits)); | |
786 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, twelve_visits); | 772 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, twelve_visits); |
787 GetTypedUrlsFromSyncDB(&new_sync_entries); | 773 GetTypedUrlsFromSyncDB(&new_sync_entries); |
788 | 774 |
789 // Should be no changes to the sync DB from this notification. | 775 // Should be no changes to the sync DB from this notification. |
790 ASSERT_EQ(1U, new_sync_entries.size()); | 776 ASSERT_EQ(1U, new_sync_entries.size()); |
791 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); | 777 EXPECT_TRUE(URLsEqual(original_entry, new_sync_entries[0])); |
792 | 778 |
793 // Now, try updating it with a large number of visits that is divisible by 10 | 779 // Now, try updating it with a large number of visits that is divisible by 10 |
794 // (should *not* be ignored). | 780 // (should *not* be ignored). |
795 history::URLRow twenty_visits(MakeTypedUrlEntry("http://mine.com", "entry", | 781 history::URLRow twenty_visits(MakeTypedUrlEntry( |
796 20, 15, false, | 782 "http://mine.com", "entry", 20, 15, false, &updated_visits)); |
797 &updated_visits)); | |
798 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, twenty_visits); | 783 SendNotificationURLVisited(ui::PAGE_TRANSITION_TYPED, twenty_visits); |
799 GetTypedUrlsFromSyncDB(&new_sync_entries); | 784 GetTypedUrlsFromSyncDB(&new_sync_entries); |
800 | 785 |
801 ASSERT_EQ(1U, new_sync_entries.size()); | 786 ASSERT_EQ(1U, new_sync_entries.size()); |
802 EXPECT_TRUE(URLsEqual(twenty_visits, new_sync_entries[0])); | 787 EXPECT_TRUE(URLsEqual(twenty_visits, new_sync_entries[0])); |
803 } | 788 } |
804 | 789 |
805 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemove) { | 790 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemove) { |
806 history::VisitVector original_visits1; | 791 history::VisitVector original_visits1; |
807 history::URLRow original_entry1(MakeTypedUrlEntry("http://mine.com", "entry", | 792 history::URLRow original_entry1(MakeTypedUrlEntry( |
808 2, 15, false, | 793 "http://mine.com", "entry", 2, 15, false, &original_visits1)); |
809 &original_visits1)); | |
810 history::VisitVector original_visits2; | 794 history::VisitVector original_visits2; |
811 history::URLRow original_entry2(MakeTypedUrlEntry("http://mine2.com", | 795 history::URLRow original_entry2(MakeTypedUrlEntry( |
812 "entry2", | 796 "http://mine2.com", "entry2", 3, 15, false, &original_visits2)); |
813 3, 15, false, | |
814 &original_visits2)); | |
815 history::URLRows original_entries; | 797 history::URLRows original_entries; |
816 original_entries.push_back(original_entry1); | 798 original_entries.push_back(original_entry1); |
817 original_entries.push_back(original_entry2); | 799 original_entries.push_back(original_entry2); |
818 | 800 |
819 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 801 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
820 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 802 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
821 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 803 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
822 .WillRepeatedly( | 804 .WillRepeatedly( |
823 DoAll(SetArgumentPointee<2>(original_visits1), Return(true))); | 805 DoAll(SetArgumentPointee<2>(original_visits1), Return(true))); |
824 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 806 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
825 StartSyncService(create_root.callback()); | 807 StartSyncService(create_root.callback()); |
826 | 808 |
827 history::URLRows rows; | 809 history::URLRows rows; |
828 rows.push_back(history::URLRow(GURL("http://mine.com"))); | 810 rows.push_back(history::URLRow(GURL("http://mine.com"))); |
829 SendNotificationURLsDeleted(false, false, rows, std::set<GURL>()); | 811 SendNotificationURLsDeleted(false, false, rows, std::set<GURL>()); |
830 history::URLRows new_sync_entries; | 812 history::URLRows new_sync_entries; |
831 GetTypedUrlsFromSyncDB(&new_sync_entries); | 813 GetTypedUrlsFromSyncDB(&new_sync_entries); |
832 ASSERT_EQ(1U, new_sync_entries.size()); | 814 ASSERT_EQ(1U, new_sync_entries.size()); |
833 EXPECT_TRUE(URLsEqual(original_entry2, new_sync_entries[0])); | 815 EXPECT_TRUE(URLsEqual(original_entry2, new_sync_entries[0])); |
834 } | 816 } |
835 | 817 |
836 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveExpired) { | 818 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveExpired) { |
837 history::VisitVector original_visits1; | 819 history::VisitVector original_visits1; |
838 history::URLRow original_entry1(MakeTypedUrlEntry("http://mine.com", "entry", | 820 history::URLRow original_entry1(MakeTypedUrlEntry( |
839 2, 15, false, | 821 "http://mine.com", "entry", 2, 15, false, &original_visits1)); |
840 &original_visits1)); | |
841 history::VisitVector original_visits2; | 822 history::VisitVector original_visits2; |
842 history::URLRow original_entry2(MakeTypedUrlEntry("http://mine2.com", | 823 history::URLRow original_entry2(MakeTypedUrlEntry( |
843 "entry2", | 824 "http://mine2.com", "entry2", 3, 15, false, &original_visits2)); |
844 3, 15, false, | |
845 &original_visits2)); | |
846 history::URLRows original_entries; | 825 history::URLRows original_entries; |
847 original_entries.push_back(original_entry1); | 826 original_entries.push_back(original_entry1); |
848 original_entries.push_back(original_entry2); | 827 original_entries.push_back(original_entry2); |
849 | 828 |
850 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 829 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
851 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 830 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
852 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 831 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
853 .WillRepeatedly( | 832 .WillRepeatedly( |
854 DoAll(SetArgumentPointee<2>(original_visits1), Return(true))); | 833 DoAll(SetArgumentPointee<2>(original_visits1), Return(true))); |
855 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 834 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
856 StartSyncService(create_root.callback()); | 835 StartSyncService(create_root.callback()); |
857 | 836 |
858 // Setting expired=true should cause the sync code to ignore this deletion. | 837 // Setting expired=true should cause the sync code to ignore this deletion. |
859 history::URLRows rows; | 838 history::URLRows rows; |
860 rows.push_back(history::URLRow(GURL("http://mine.com"))); | 839 rows.push_back(history::URLRow(GURL("http://mine.com"))); |
861 SendNotificationURLsDeleted(false, true, rows, std::set<GURL>()); | 840 SendNotificationURLsDeleted(false, true, rows, std::set<GURL>()); |
862 history::URLRows new_sync_entries; | 841 history::URLRows new_sync_entries; |
863 GetTypedUrlsFromSyncDB(&new_sync_entries); | 842 GetTypedUrlsFromSyncDB(&new_sync_entries); |
864 // Both URLs should still be there. | 843 // Both URLs should still be there. |
865 ASSERT_EQ(2U, new_sync_entries.size()); | 844 ASSERT_EQ(2U, new_sync_entries.size()); |
866 } | 845 } |
867 | 846 |
868 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveAll) { | 847 TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveAll) { |
869 history::VisitVector original_visits1; | 848 history::VisitVector original_visits1; |
870 history::URLRow original_entry1(MakeTypedUrlEntry("http://mine.com", "entry", | 849 history::URLRow original_entry1(MakeTypedUrlEntry( |
871 2, 15, false, | 850 "http://mine.com", "entry", 2, 15, false, &original_visits1)); |
872 &original_visits1)); | |
873 history::VisitVector original_visits2; | 851 history::VisitVector original_visits2; |
874 history::URLRow original_entry2(MakeTypedUrlEntry("http://mine2.com", | 852 history::URLRow original_entry2(MakeTypedUrlEntry( |
875 "entry2", | 853 "http://mine2.com", "entry2", 3, 15, false, &original_visits2)); |
876 3, 15, false, | |
877 &original_visits2)); | |
878 history::URLRows original_entries; | 854 history::URLRows original_entries; |
879 original_entries.push_back(original_entry1); | 855 original_entries.push_back(original_entry1); |
880 original_entries.push_back(original_entry2); | 856 original_entries.push_back(original_entry2); |
881 | 857 |
882 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 858 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
883 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 859 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
884 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 860 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
885 .WillRepeatedly( | 861 .WillRepeatedly( |
886 DoAll(SetArgumentPointee<2>(original_visits1), Return(true))); | 862 DoAll(SetArgumentPointee<2>(original_visits1), Return(true))); |
887 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 863 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
888 StartSyncService(create_root.callback()); | 864 StartSyncService(create_root.callback()); |
889 | 865 |
890 history::URLRows new_sync_entries; | 866 history::URLRows new_sync_entries; |
891 GetTypedUrlsFromSyncDB(&new_sync_entries); | 867 GetTypedUrlsFromSyncDB(&new_sync_entries); |
892 ASSERT_EQ(2U, new_sync_entries.size()); | 868 ASSERT_EQ(2U, new_sync_entries.size()); |
893 | 869 |
894 SendNotificationURLsDeleted(true, false, history::URLRows(), | 870 SendNotificationURLsDeleted(true, false, history::URLRows(), |
895 std::set<GURL>()); | 871 std::set<GURL>()); |
896 | 872 |
897 GetTypedUrlsFromSyncDB(&new_sync_entries); | 873 GetTypedUrlsFromSyncDB(&new_sync_entries); |
898 ASSERT_EQ(0U, new_sync_entries.size()); | 874 ASSERT_EQ(0U, new_sync_entries.size()); |
899 } | 875 } |
900 | 876 |
901 TEST_F(ProfileSyncServiceTypedUrlTest, FailWriteToHistoryBackend) { | 877 TEST_F(ProfileSyncServiceTypedUrlTest, FailWriteToHistoryBackend) { |
902 history::VisitVector native_visits; | 878 history::VisitVector native_visits; |
903 history::VisitVector sync_visits; | 879 history::VisitVector sync_visits; |
904 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", | 880 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", |
905 2, 15, false, &native_visits)); | 881 2, 15, false, &native_visits)); |
906 history::URLRow sync_entry(MakeTypedUrlEntry("http://sync.com", "entry", | 882 history::URLRow sync_entry(MakeTypedUrlEntry("http://sync.com", "entry", 3, |
907 3, 16, false, &sync_visits)); | 883 16, false, &sync_visits)); |
908 | 884 |
909 history::URLRows native_entries; | 885 history::URLRows native_entries; |
910 native_entries.push_back(native_entry); | 886 native_entries.push_back(native_entry); |
911 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 887 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
912 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 888 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
913 EXPECT_CALL((history_backend()), GetURL(_, _)) | 889 EXPECT_CALL((history_backend()), GetURL(_, _)) |
914 .WillOnce(DoAll(SetArgumentPointee<1>(native_entry), Return(false))); | 890 .WillOnce(DoAll(SetArgumentPointee<1>(native_entry), Return(false))); |
915 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 891 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
916 .WillRepeatedly( | 892 .WillRepeatedly( |
917 DoAll(SetArgumentPointee<2>(native_visits), Return(true))); | 893 DoAll(SetArgumentPointee<2>(native_visits), Return(true))); |
(...skipping 15 matching lines...) Expand all Loading... |
933 // somewhere > 0 and < 100. | 909 // somewhere > 0 and < 100. |
934 ASSERT_NE(0, syncable_service->GetErrorPercentage()); | 910 ASSERT_NE(0, syncable_service->GetErrorPercentage()); |
935 ASSERT_NE(100, syncable_service->GetErrorPercentage()); | 911 ASSERT_NE(100, syncable_service->GetErrorPercentage()); |
936 } | 912 } |
937 | 913 |
938 TEST_F(ProfileSyncServiceTypedUrlTest, FailToGetTypedURLs) { | 914 TEST_F(ProfileSyncServiceTypedUrlTest, FailToGetTypedURLs) { |
939 history::VisitVector native_visits; | 915 history::VisitVector native_visits; |
940 history::VisitVector sync_visits; | 916 history::VisitVector sync_visits; |
941 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", | 917 history::URLRow native_entry(MakeTypedUrlEntry("http://native.com", "entry", |
942 2, 15, false, &native_visits)); | 918 2, 15, false, &native_visits)); |
943 history::URLRow sync_entry(MakeTypedUrlEntry("http://sync.com", "entry", | 919 history::URLRow sync_entry(MakeTypedUrlEntry("http://sync.com", "entry", 3, |
944 3, 16, false, &sync_visits)); | 920 16, false, &sync_visits)); |
945 | 921 |
946 history::URLRows native_entries; | 922 history::URLRows native_entries; |
947 native_entries.push_back(native_entry); | 923 native_entries.push_back(native_entry); |
948 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 924 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
949 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(false))); | 925 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(false))); |
950 | 926 |
951 history::URLRows sync_entries; | 927 history::URLRows sync_entries; |
952 sync_entries.push_back(sync_entry); | 928 sync_entries.push_back(sync_entry); |
953 | 929 |
954 StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); | 930 StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); |
955 // Errors getting typed URLs will cause an unrecoverable error (since we can | 931 // Errors getting typed URLs will cause an unrecoverable error (since we can |
956 // do *nothing* in that case). | 932 // do *nothing* in that case). |
957 ASSERT_TRUE(sync_service()->data_type_status_table().GetFailedTypes().Has( | 933 ASSERT_TRUE(sync_service()->data_type_status_table().GetFailedTypes().Has( |
958 syncer::TYPED_URLS)); | 934 syncer::TYPED_URLS)); |
959 ASSERT_EQ(1u, | 935 ASSERT_EQ(1u, |
960 sync_service()->data_type_status_table().GetFailedTypes().Size()); | 936 sync_service()->data_type_status_table().GetFailedTypes().Size()); |
961 // Can't check GetErrorPercentage(), because generating an unrecoverable | 937 // Can't check GetErrorPercentage(), because generating an unrecoverable |
962 // error will free the model associator. | 938 // error will free the model associator. |
963 } | 939 } |
964 | 940 |
965 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreLocalFileURL) { | 941 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreLocalFileURL) { |
966 history::VisitVector original_visits; | 942 history::VisitVector original_visits; |
967 // Create http and file url. | 943 // Create http and file url. |
968 history::URLRow url_entry(MakeTypedUrlEntry("http://yey.com", | 944 history::URLRow url_entry(MakeTypedUrlEntry("http://yey.com", "yey", 12, 15, |
969 "yey", 12, 15, false, | 945 false, &original_visits)); |
970 &original_visits)); | 946 history::URLRow file_entry(MakeTypedUrlEntry( |
971 history::URLRow file_entry(MakeTypedUrlEntry("file:///kitty.jpg", | 947 "file:///kitty.jpg", "kitteh", 12, 15, false, &original_visits)); |
972 "kitteh", 12, 15, false, | |
973 &original_visits)); | |
974 | 948 |
975 history::URLRows original_entries; | 949 history::URLRows original_entries; |
976 original_entries.push_back(url_entry); | 950 original_entries.push_back(url_entry); |
977 original_entries.push_back(file_entry); | 951 original_entries.push_back(file_entry); |
978 | 952 |
979 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 953 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
980 .WillRepeatedly( | 954 .WillRepeatedly( |
981 DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 955 DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
982 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 956 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
983 .WillRepeatedly( | 957 .WillRepeatedly( |
984 DoAll(SetArgumentPointee<2>(original_visits), Return(true))); | 958 DoAll(SetArgumentPointee<2>(original_visits), Return(true))); |
985 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 959 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
986 StartSyncService(create_root.callback()); | 960 StartSyncService(create_root.callback()); |
987 | 961 |
988 history::VisitVector updated_visits; | 962 history::VisitVector updated_visits; |
989 // Create updates for the previous urls + a new file one. | 963 // Create updates for the previous urls + a new file one. |
990 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com", | 964 history::URLRow updated_url_entry(MakeTypedUrlEntry( |
991 "yey", 20, 15, false, | 965 "http://yey.com", "yey", 20, 15, false, &updated_visits)); |
992 &updated_visits)); | 966 history::URLRow updated_file_entry(MakeTypedUrlEntry( |
993 history::URLRow updated_file_entry(MakeTypedUrlEntry("file:///cat.jpg", | 967 "file:///cat.jpg", "cat", 20, 15, false, &updated_visits)); |
994 "cat", 20, 15, false, | 968 history::URLRow new_file_entry(MakeTypedUrlEntry("file:///dog.jpg", "dog", 20, |
995 &updated_visits)); | 969 15, false, &updated_visits)); |
996 history::URLRow new_file_entry(MakeTypedUrlEntry("file:///dog.jpg", | |
997 "dog", 20, 15, false, | |
998 &updated_visits)); | |
999 | 970 |
1000 history::URLRows changed_urls; | 971 history::URLRows changed_urls; |
1001 changed_urls.push_back(updated_url_entry); | 972 changed_urls.push_back(updated_url_entry); |
1002 changed_urls.push_back(updated_file_entry); | 973 changed_urls.push_back(updated_file_entry); |
1003 changed_urls.push_back(new_file_entry); | 974 changed_urls.push_back(new_file_entry); |
1004 SendNotificationURLsModified(changed_urls); | 975 SendNotificationURLsModified(changed_urls); |
1005 | 976 |
1006 history::URLRows new_sync_entries; | 977 history::URLRows new_sync_entries; |
1007 GetTypedUrlsFromSyncDB(&new_sync_entries); | 978 GetTypedUrlsFromSyncDB(&new_sync_entries); |
1008 | 979 |
1009 // We should ignore the local file urls (existing and updated), | 980 // We should ignore the local file urls (existing and updated), |
1010 // and only be left with the updated http url. | 981 // and only be left with the updated http url. |
1011 ASSERT_EQ(1U, new_sync_entries.size()); | 982 ASSERT_EQ(1U, new_sync_entries.size()); |
1012 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0])); | 983 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0])); |
1013 } | 984 } |
1014 | 985 |
1015 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreLocalhostURL) { | 986 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreLocalhostURL) { |
1016 history::VisitVector original_visits; | 987 history::VisitVector original_visits; |
1017 // Create http and localhost url. | 988 // Create http and localhost url. |
1018 history::URLRow url_entry(MakeTypedUrlEntry("http://yey.com", | 989 history::URLRow url_entry(MakeTypedUrlEntry("http://yey.com", "yey", 12, 15, |
1019 "yey", 12, 15, false, | 990 false, &original_visits)); |
1020 &original_visits)); | 991 history::URLRow localhost_entry(MakeTypedUrlEntry( |
1021 history::URLRow localhost_entry(MakeTypedUrlEntry("http://localhost", | 992 "http://localhost", "localhost", 12, 15, false, &original_visits)); |
1022 "localhost", 12, 15, false, | |
1023 &original_visits)); | |
1024 | 993 |
1025 history::URLRows original_entries; | 994 history::URLRows original_entries; |
1026 original_entries.push_back(url_entry); | 995 original_entries.push_back(url_entry); |
1027 original_entries.push_back(localhost_entry); | 996 original_entries.push_back(localhost_entry); |
1028 | 997 |
1029 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 998 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
1030 .WillRepeatedly( | 999 .WillRepeatedly( |
1031 DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 1000 DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
1032 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 1001 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
1033 .WillRepeatedly( | 1002 .WillRepeatedly( |
1034 DoAll(SetArgumentPointee<2>(original_visits), Return(true))); | 1003 DoAll(SetArgumentPointee<2>(original_visits), Return(true))); |
1035 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 1004 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
1036 StartSyncService(create_root.callback()); | 1005 StartSyncService(create_root.callback()); |
1037 | 1006 |
1038 history::VisitVector updated_visits; | 1007 history::VisitVector updated_visits; |
1039 // Update the previous entries and add a new localhost. | 1008 // Update the previous entries and add a new localhost. |
1040 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com", | 1009 history::URLRow updated_url_entry(MakeTypedUrlEntry( |
1041 "yey", 20, 15, false, | 1010 "http://yey.com", "yey", 20, 15, false, &updated_visits)); |
1042 &updated_visits)); | |
1043 history::URLRow updated_localhost_entry(MakeTypedUrlEntry( | 1011 history::URLRow updated_localhost_entry(MakeTypedUrlEntry( |
1044 "http://localhost:80", | 1012 "http://localhost:80", "localhost", 20, 15, false, &original_visits)); |
1045 "localhost", 20, 15, false, | 1013 history::URLRow localhost_ip_entry(MakeTypedUrlEntry( |
1046 &original_visits)); | 1014 "http://127.0.0.1", "localhost", 12, 15, false, &original_visits)); |
1047 history::URLRow localhost_ip_entry(MakeTypedUrlEntry("http://127.0.0.1", | |
1048 "localhost", 12, 15, false, | |
1049 &original_visits)); | |
1050 | 1015 |
1051 history::URLRows changed_urls; | 1016 history::URLRows changed_urls; |
1052 changed_urls.push_back(updated_url_entry); | 1017 changed_urls.push_back(updated_url_entry); |
1053 changed_urls.push_back(updated_localhost_entry); | 1018 changed_urls.push_back(updated_localhost_entry); |
1054 changed_urls.push_back(localhost_ip_entry); | 1019 changed_urls.push_back(localhost_ip_entry); |
1055 SendNotificationURLsModified(changed_urls); | 1020 SendNotificationURLsModified(changed_urls); |
1056 | 1021 |
1057 history::URLRows new_sync_entries; | 1022 history::URLRows new_sync_entries; |
1058 GetTypedUrlsFromSyncDB(&new_sync_entries); | 1023 GetTypedUrlsFromSyncDB(&new_sync_entries); |
1059 | 1024 |
1060 // We should ignore the localhost urls and left only with http url. | 1025 // We should ignore the localhost urls and left only with http url. |
1061 ASSERT_EQ(1U, new_sync_entries.size()); | 1026 ASSERT_EQ(1U, new_sync_entries.size()); |
1062 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0])); | 1027 EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0])); |
1063 } | 1028 } |
1064 | 1029 |
1065 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreModificationWithoutValidVisit) { | 1030 TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreModificationWithoutValidVisit) { |
1066 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) | 1031 EXPECT_CALL((history_backend()), GetAllTypedURLs(_)) |
1067 .WillRepeatedly(Return(true)); | 1032 .WillRepeatedly(Return(true)); |
1068 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) | 1033 EXPECT_CALL((history_backend()), GetMostRecentVisitsForURL(_, _, _)) |
1069 .WillRepeatedly(Return(true)); | 1034 .WillRepeatedly(Return(true)); |
1070 | 1035 |
1071 CreateRootHelper create_root(this, syncer::TYPED_URLS); | 1036 CreateRootHelper create_root(this, syncer::TYPED_URLS); |
1072 StartSyncService(create_root.callback()); | 1037 StartSyncService(create_root.callback()); |
1073 | 1038 |
1074 history::VisitVector updated_visits; | 1039 history::VisitVector updated_visits; |
1075 history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com", | 1040 history::URLRow updated_url_entry(MakeTypedUrlEntry( |
1076 "yey", 20, 0, false, | 1041 "http://yey.com", "yey", 20, 0, false, &updated_visits)); |
1077 &updated_visits)); | |
1078 | 1042 |
1079 history::URLRows changed_urls; | 1043 history::URLRows changed_urls; |
1080 changed_urls.push_back(updated_url_entry); | 1044 changed_urls.push_back(updated_url_entry); |
1081 SendNotificationURLsModified(changed_urls); | 1045 SendNotificationURLsModified(changed_urls); |
1082 | 1046 |
1083 history::URLRows new_sync_entries; | 1047 history::URLRows new_sync_entries; |
1084 GetTypedUrlsFromSyncDB(&new_sync_entries); | 1048 GetTypedUrlsFromSyncDB(&new_sync_entries); |
1085 | 1049 |
1086 // The change should be ignored. | 1050 // The change should be ignored. |
1087 ASSERT_EQ(0U, new_sync_entries.size()); | 1051 ASSERT_EQ(0U, new_sync_entries.size()); |
1088 } | 1052 } |
OLD | NEW |