Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync_sessions/sessions_sync_manager.h" | 5 #include "components/sync_sessions/sessions_sync_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
|
skym
2016/12/03 01:20:46
:/ would be nice if most of these unit tests could
Nicolas Zea
2016/12/06 01:32:55
Yeah, that's valid. I filed crbug.com/671283 for t
| |
| 15 #include "chrome/browser/sync/chrome_sync_client.h" | 15 #include "chrome/browser/sync/chrome_sync_client.h" |
| 16 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" | 16 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
| 17 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" | 17 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" |
| 18 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | 18 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/test/base/browser_with_test_window_test.h" | 20 #include "chrome/test/base/browser_with_test_window_test.h" |
| 21 #include "components/sessions/content/content_serialized_navigation_builder.h" | 21 #include "components/sessions/content/content_serialized_navigation_builder.h" |
| 22 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" | 22 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" |
| 23 #include "components/sync/device_info/local_device_info_provider_mock.h" | 23 #include "components/sync/device_info/local_device_info_provider_mock.h" |
| 24 #include "components/sync/driver/sync_api_component_factory.h" | 24 #include "components/sync/driver/sync_api_component_factory.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 41 using syncer::DeviceInfo; | 41 using syncer::DeviceInfo; |
| 42 using syncer::LocalDeviceInfoProvider; | 42 using syncer::LocalDeviceInfoProvider; |
| 43 using syncer::LocalDeviceInfoProviderMock; | 43 using syncer::LocalDeviceInfoProviderMock; |
| 44 using syncer::SyncChange; | 44 using syncer::SyncChange; |
| 45 using syncer::SyncData; | 45 using syncer::SyncData; |
| 46 | 46 |
| 47 namespace sync_sessions { | 47 namespace sync_sessions { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 std::string TabNodeIdToTag(const std::string& machine_tag, int tab_node_id) { | |
| 52 return base::StringPrintf("%s %d", machine_tag.c_str(), tab_node_id); | |
| 53 } | |
| 54 | |
| 51 class SessionNotificationObserver { | 55 class SessionNotificationObserver { |
| 52 public: | 56 public: |
| 53 SessionNotificationObserver() | 57 SessionNotificationObserver() |
| 54 : notified_of_update_(false), notified_of_refresh_(false) {} | 58 : notified_of_update_(false), notified_of_refresh_(false) {} |
| 55 void NotifyOfUpdate() { notified_of_update_ = true; } | 59 void NotifyOfUpdate() { notified_of_update_ = true; } |
| 56 void NotifyOfRefresh() { notified_of_refresh_ = true; } | 60 void NotifyOfRefresh() { notified_of_refresh_ = true; } |
| 57 | 61 |
| 58 bool notified_of_update() const { return notified_of_update_; } | 62 bool notified_of_update() const { return notified_of_update_; } |
| 59 bool notified_of_refresh() const { return notified_of_refresh_; } | 63 bool notified_of_refresh() const { return notified_of_refresh_; } |
| 60 | 64 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 bool IsSessionRestoreInProgress() const override { | 125 bool IsSessionRestoreInProgress() const override { |
| 122 return wrapped_->IsSessionRestoreInProgress(); | 126 return wrapped_->IsSessionRestoreInProgress(); |
| 123 } | 127 } |
| 124 | 128 |
| 125 bool ShouldSync() const override { return wrapped_->ShouldSync(); } | 129 bool ShouldSync() const override { return wrapped_->ShouldSync(); } |
| 126 | 130 |
| 127 private: | 131 private: |
| 128 std::map<int, SyncedTabDelegate*> tab_overrides_; | 132 std::map<int, SyncedTabDelegate*> tab_overrides_; |
| 129 std::map<int, SessionID::id_type> tab_id_overrides_; | 133 std::map<int, SessionID::id_type> tab_id_overrides_; |
| 130 const SyncedWindowDelegate* const wrapped_; | 134 const SyncedWindowDelegate* const wrapped_; |
| 131 SessionID::id_type session_id_override_ = -1; | 135 SessionID::id_type session_id_override_ = TabNodePool::kInvalidTabID; |
| 132 }; | 136 }; |
| 133 | 137 |
| 134 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { | 138 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { |
| 135 public: | 139 public: |
| 136 TestSyncedWindowDelegatesGetter( | 140 TestSyncedWindowDelegatesGetter( |
| 137 const std::set<const SyncedWindowDelegate*>& delegates) | 141 const std::set<const SyncedWindowDelegate*>& delegates) |
| 138 : delegates_(delegates) {} | 142 : delegates_(delegates) {} |
| 139 | 143 |
| 140 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override { | 144 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override { |
| 141 return delegates_; | 145 return delegates_; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 } | 396 } |
| 393 } | 397 } |
| 394 EXPECT_TRUE(found); | 398 EXPECT_TRUE(found); |
| 395 return list; | 399 return list; |
| 396 } | 400 } |
| 397 | 401 |
| 398 SyncSessionsClient* GetSyncSessionsClient() { | 402 SyncSessionsClient* GetSyncSessionsClient() { |
| 399 return sessions_client_shim_.get(); | 403 return sessions_client_shim_.get(); |
| 400 } | 404 } |
| 401 | 405 |
| 406 TabNodePool* GetTabPool() { | |
| 407 return &manager()->session_tracker_.local_tab_pool_; | |
| 408 } | |
| 409 | |
| 402 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } | 410 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } |
| 403 | 411 |
| 404 SyncedWindowDelegatesGetter* get_synced_window_getter() { | 412 SyncedWindowDelegatesGetter* get_synced_window_getter() { |
| 405 return manager()->synced_window_delegates_getter(); | 413 return manager()->synced_window_delegates_getter(); |
| 406 } | 414 } |
| 407 | 415 |
| 408 void set_synced_window_getter( | 416 void set_synced_window_getter( |
| 409 SyncedWindowDelegatesGetter* synced_window_getter) { | 417 SyncedWindowDelegatesGetter* synced_window_getter) { |
| 410 sessions_client_shim_->set_synced_window_getter(synced_window_getter); | 418 sessions_client_shim_->set_synced_window_getter(synced_window_getter); |
| 411 } | 419 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 ASSERT_EQ(1U, session->windows[0]->tabs.size()); | 503 ASSERT_EQ(1U, session->windows[0]->tabs.size()); |
| 496 ASSERT_EQ(1, session->windows[0]->selected_tab_index); | 504 ASSERT_EQ(1, session->windows[0]->selected_tab_index); |
| 497 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, session->windows[0]->type); | 505 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, session->windows[0]->type); |
| 498 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions()); | 506 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions()); |
| 499 ASSERT_EQ(1U, | 507 ASSERT_EQ(1U, |
| 500 manager()->session_tracker_.num_synced_tabs(std::string("tag"))); | 508 manager()->session_tracker_.num_synced_tabs(std::string("tag"))); |
| 501 } | 509 } |
| 502 | 510 |
| 503 namespace { | 511 namespace { |
| 504 | 512 |
| 505 class SyncedTabDelegateFake : public SyncedTabDelegate { | 513 class SyncedTabDelegateFake : public SyncedTabDelegate { |
|
skym
2016/12/03 01:20:46
How that we have two implementations in here, can
Nicolas Zea
2016/12/06 01:32:55
Done.
| |
| 506 public: | 514 public: |
| 507 SyncedTabDelegateFake() | 515 SyncedTabDelegateFake() |
| 508 : current_entry_index_(0), is_supervised_(false), sync_id_(-1) {} | 516 : current_entry_index_(0), is_supervised_(false), sync_id_(-1) {} |
| 509 ~SyncedTabDelegateFake() override {} | 517 ~SyncedTabDelegateFake() override {} |
| 510 | 518 |
| 511 bool IsInitialBlankNavigation() const override { | 519 bool IsInitialBlankNavigation() const override { |
| 512 // This differs from NavigationControllerImpl, which has an initial blank | 520 // This differs from NavigationControllerImpl, which has an initial blank |
| 513 // NavigationEntry. | 521 // NavigationEntry. |
| 514 return GetEntryCount() == 0; | 522 return GetEntryCount() == 0; |
| 515 } | 523 } |
| 516 int GetCurrentEntryIndex() const override { return current_entry_index_; } | 524 int GetCurrentEntryIndex() const override { return current_entry_index_; } |
| 517 void set_current_entry_index(int i) { | 525 void set_current_entry_index(int i) { |
| 518 current_entry_index_ = i; | 526 current_entry_index_ = i; |
| 519 } | 527 } |
| 520 | 528 |
| 521 void AppendEntry(std::unique_ptr<content::NavigationEntry> entry) { | 529 void AppendEntry(std::unique_ptr<content::NavigationEntry> entry) { |
|
skym
2016/12/03 01:20:46
While you're in here, can you organize these so th
Nicolas Zea
2016/12/06 01:32:55
Done.
| |
| 522 entries_.push_back(std::move(entry)); | 530 entries_.push_back(std::move(entry)); |
| 523 } | 531 } |
| 524 | 532 |
| 525 GURL GetVirtualURLAtIndex(int i) const override { | 533 GURL GetVirtualURLAtIndex(int i) const override { |
| 526 if (static_cast<size_t>(i) >= entries_.size()) | 534 if (static_cast<size_t>(i) >= entries_.size()) |
| 527 return GURL(); | 535 return GURL(); |
| 528 return entries_[i]->GetVirtualURL(); | 536 return entries_[i]->GetVirtualURL(); |
| 529 } | 537 } |
| 530 | 538 |
| 531 GURL GetFaviconURLAtIndex(int i) const override { return GURL(); } | 539 GURL GetFaviconURLAtIndex(int i) const override { return GURL(); } |
| 532 | 540 |
| 533 ui::PageTransition GetTransitionAtIndex(int i) const override { | 541 ui::PageTransition GetTransitionAtIndex(int i) const override { |
| 534 if (static_cast<size_t>(i) >= entries_.size()) | 542 if (static_cast<size_t>(i) >= entries_.size()) |
| 535 return ui::PAGE_TRANSITION_LINK; | 543 return ui::PAGE_TRANSITION_LINK; |
| 536 return entries_[i]->GetTransitionType(); | 544 return entries_[i]->GetTransitionType(); |
| 537 } | 545 } |
| 538 | 546 |
| 539 void GetSerializedNavigationAtIndex( | 547 void GetSerializedNavigationAtIndex( |
| 540 int i, | 548 int i, |
| 541 sessions::SerializedNavigationEntry* serialized_entry) const override { | 549 sessions::SerializedNavigationEntry* serialized_entry) const override { |
| 542 if (static_cast<size_t>(i) >= entries_.size()) | 550 if (static_cast<size_t>(i) >= entries_.size()) |
| 543 return; | 551 return; |
| 544 *serialized_entry = | 552 *serialized_entry = |
| 545 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( | 553 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( |
| 546 i, *entries_[i]); | 554 i, *entries_[i]); |
| 547 } | 555 } |
| 548 | 556 |
| 549 int GetEntryCount() const override { return entries_.size(); } | 557 int GetEntryCount() const override { return entries_.size(); } |
| 550 | 558 |
| 551 SessionID::id_type GetWindowId() const override { | 559 SessionID::id_type GetWindowId() const override { return window_id_; } |
| 552 return SessionID::id_type(); | 560 void SetWindowId(SessionID::id_type window_id) { window_id_ = window_id; } |
| 553 } | |
| 554 | 561 |
| 555 SessionID::id_type GetSessionId() const override { | 562 SessionID::id_type GetSessionId() const override { return tab_id_; } |
| 556 return SessionID::id_type(); | 563 void SetSessionId(SessionID::id_type id) { tab_id_ = id; } |
| 557 } | |
| 558 | 564 |
| 559 bool IsBeingDestroyed() const override { return false; } | 565 bool IsBeingDestroyed() const override { return false; } |
| 560 std::string GetExtensionAppId() const override { return std::string(); } | 566 std::string GetExtensionAppId() const override { return std::string(); } |
| 561 bool ProfileIsSupervised() const override { return is_supervised_; } | 567 bool ProfileIsSupervised() const override { return is_supervised_; } |
| 562 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } | 568 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } |
| 563 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* | 569 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* |
| 564 GetBlockedNavigations() const override { | 570 GetBlockedNavigations() const override { |
| 565 return &blocked_navigations_; | 571 return &blocked_navigations_; |
| 566 } | 572 } |
| 567 void set_blocked_navigations( | 573 void set_blocked_navigations( |
| 568 std::vector<const content::NavigationEntry*>* navs) { | 574 std::vector<const content::NavigationEntry*>* navs) { |
| 569 for (auto* entry : *navs) { | 575 for (auto* entry : *navs) { |
| 570 auto serialized_entry = | 576 auto serialized_entry = |
| 571 base::MakeUnique<sessions::SerializedNavigationEntry>( | 577 base::MakeUnique<sessions::SerializedNavigationEntry>( |
| 572 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( | 578 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( |
| 573 blocked_navigations_.size(), *entry)); | 579 blocked_navigations_.size(), *entry)); |
| 574 blocked_navigations_.push_back(std::move(serialized_entry)); | 580 blocked_navigations_.push_back(std::move(serialized_entry)); |
| 575 } | 581 } |
| 576 } | 582 } |
| 577 bool IsPlaceholderTab() const override { return true; } | 583 bool IsPlaceholderTab() const override { return false; } |
| 578 | 584 |
| 579 // Session sync related methods. | 585 // Session sync related methods. |
| 580 int GetSyncId() const override { return sync_id_; } | 586 int GetSyncId() const override { return sync_id_; } |
| 581 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } | 587 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } |
| 582 | 588 |
| 583 bool ShouldSync(SyncSessionsClient* sessions_client) override { | 589 bool ShouldSync(SyncSessionsClient* sessions_client) override { |
| 584 return false; | 590 return false; |
| 585 } | 591 } |
| 586 | 592 |
| 587 void reset() { | 593 void reset() { |
| 588 current_entry_index_ = 0; | 594 current_entry_index_ = 0; |
| 589 sync_id_ = -1; | 595 sync_id_ = TabNodePool::kInvalidTabNodeID; |
| 590 entries_.clear(); | 596 entries_.clear(); |
| 591 } | 597 } |
| 592 | 598 |
| 593 private: | 599 private: |
| 594 int current_entry_index_; | 600 int current_entry_index_; |
| 595 bool is_supervised_; | 601 bool is_supervised_; |
| 596 int sync_id_; | 602 int sync_id_; |
| 603 SessionID::id_type tab_id_ = 0; | |
| 604 SessionID::id_type window_id_ = 0; | |
| 597 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> | 605 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> |
| 598 blocked_navigations_; | 606 blocked_navigations_; |
| 599 std::vector<std::unique_ptr<content::NavigationEntry>> entries_; | 607 std::vector<std::unique_ptr<content::NavigationEntry>> entries_; |
| 600 }; | 608 }; |
| 601 | 609 |
| 610 // An Android placeholder delegate. These delegates have no WebContents | |
|
skym
2016/12/03 01:20:46
Can you elaborate in this comment what's android s
Nicolas Zea
2016/12/06 01:32:55
Done.
| |
| 611 // or TabContentsDelegate. | |
|
skym
2016/12/03 01:20:46
I'm confused what exactly a TabContentsDelegate is
Nicolas Zea
2016/12/06 01:32:55
Looks like they don't exist anymore. Basically the
| |
| 612 class PlaceholderTabDelegate : public SyncedTabDelegate { | |
| 613 public: | |
| 614 PlaceholderTabDelegate(SessionID::id_type session_id, int sync_id) | |
| 615 : session_id_(session_id), sync_id_(sync_id) {} | |
| 616 ~PlaceholderTabDelegate() override {} | |
| 617 | |
| 618 // Overrides. | |
|
skym
2016/12/03 01:20:46
Is there a reason you didn't do
// SyncedTabDeleg
Nicolas Zea
2016/12/06 01:32:55
Nope. Done.
| |
| 619 SessionID::id_type GetSessionId() const override { return session_id_; } | |
| 620 int GetSyncId() const override { return sync_id_; } | |
| 621 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } | |
| 622 bool IsPlaceholderTab() const override { return true; } | |
| 623 | |
| 624 // Everything else is invalid to invoke as it depends on either a WebContents | |
| 625 // or a TabContentsDelegate. | |
|
skym
2016/12/03 01:20:46
Again, what is a TabContentsDelegate?
Nicolas Zea
2016/12/06 01:32:55
Removed.
| |
| 626 SessionID::id_type GetWindowId() const override { | |
| 627 NOTREACHED(); | |
| 628 return 0; | |
| 629 } | |
| 630 bool IsBeingDestroyed() const override { | |
| 631 NOTREACHED(); | |
| 632 return false; | |
| 633 } | |
| 634 std::string GetExtensionAppId() const override { | |
| 635 NOTREACHED(); | |
| 636 return ""; | |
| 637 } | |
| 638 bool IsInitialBlankNavigation() const override { | |
| 639 NOTREACHED(); | |
| 640 return false; | |
| 641 } | |
| 642 int GetCurrentEntryIndex() const override { | |
| 643 NOTREACHED(); | |
| 644 return 0; | |
| 645 } | |
| 646 int GetEntryCount() const override { | |
| 647 NOTREACHED(); | |
| 648 return 0; | |
| 649 } | |
| 650 GURL GetVirtualURLAtIndex(int i) const override { | |
| 651 NOTREACHED(); | |
| 652 return GURL(); | |
| 653 } | |
| 654 GURL GetFaviconURLAtIndex(int i) const override { | |
| 655 NOTREACHED(); | |
| 656 return GURL(); | |
| 657 } | |
| 658 ui::PageTransition GetTransitionAtIndex(int i) const override { | |
| 659 NOTREACHED(); | |
| 660 return ui::PageTransition(); | |
| 661 } | |
| 662 void GetSerializedNavigationAtIndex( | |
| 663 int i, | |
| 664 sessions::SerializedNavigationEntry* serialized_entry) const override { | |
| 665 NOTREACHED(); | |
| 666 } | |
| 667 bool ProfileIsSupervised() const override { | |
| 668 NOTREACHED(); | |
| 669 return false; | |
| 670 } | |
| 671 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* | |
| 672 GetBlockedNavigations() const override { | |
| 673 NOTREACHED(); | |
| 674 return nullptr; | |
| 675 } | |
| 676 bool ShouldSync(SyncSessionsClient* sessions_client) override { | |
| 677 NOTREACHED(); | |
| 678 return false; | |
| 679 } | |
| 680 | |
| 681 private: | |
| 682 SessionID::id_type session_id_; | |
| 683 int sync_id_; | |
| 684 }; | |
| 685 | |
| 602 } // namespace | 686 } // namespace |
| 603 | 687 |
| 604 static const base::Time kTime0 = base::Time::FromInternalValue(100); | 688 static const base::Time kTime0 = base::Time::FromInternalValue(100); |
| 605 static const base::Time kTime1 = base::Time::FromInternalValue(110); | 689 static const base::Time kTime1 = base::Time::FromInternalValue(110); |
| 606 static const base::Time kTime2 = base::Time::FromInternalValue(120); | 690 static const base::Time kTime2 = base::Time::FromInternalValue(120); |
| 607 static const base::Time kTime3 = base::Time::FromInternalValue(130); | 691 static const base::Time kTime3 = base::Time::FromInternalValue(130); |
| 608 static const base::Time kTime4 = base::Time::FromInternalValue(140); | 692 static const base::Time kTime4 = base::Time::FromInternalValue(140); |
| 609 static const base::Time kTime5 = base::Time::FromInternalValue(150); | 693 static const base::Time kTime5 = base::Time::FromInternalValue(150); |
| 610 static const base::Time kTime6 = base::Time::FromInternalValue(160); | 694 static const base::Time kTime6 = base::Time::FromInternalValue(160); |
| 611 static const base::Time kTime7 = base::Time::FromInternalValue(170); | 695 static const base::Time kTime7 = base::Time::FromInternalValue(170); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 new syncer::SyncErrorFactoryMock())); | 1030 new syncer::SyncErrorFactoryMock())); |
| 947 ASSERT_FALSE(result.error().IsSet()); | 1031 ASSERT_FALSE(result.error().IsSet()); |
| 948 | 1032 |
| 949 EXPECT_EQ(1U, out.size()); | 1033 EXPECT_EQ(1U, out.size()); |
| 950 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 1034 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
| 951 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); | 1035 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); |
| 952 } | 1036 } |
| 953 | 1037 |
| 954 // Ensure model association associates the pre-existing tabs. | 1038 // Ensure model association associates the pre-existing tabs. |
| 955 TEST_F(SessionsSyncManagerTest, SwappedOutOnRestore) { | 1039 TEST_F(SessionsSyncManagerTest, SwappedOutOnRestore) { |
| 956 AddTab(browser(), GURL("http://foo1")); | 1040 const char kFoo1[] = "http://foo1/"; |
| 957 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1041 const char kFoo2[] = "http://foo2/"; |
| 958 AddTab(browser(), GURL("http://bar1")); | 1042 const char kBar1[] = "http://bar1/"; |
| 959 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1043 const char kBar2[] = "http://bar2/"; |
| 960 AddTab(browser(), GURL("http://baz1")); | 1044 const char kBaz1[] = "http://baz1/"; |
| 961 NavigateAndCommitActiveTab(GURL("http://baz2")); | 1045 const char kBaz2[] = "http://baz2/"; |
| 962 const int kRestoredTabId = 1337; | 1046 const int kRestoredTabId = 1337; |
| 963 const int kNewTabId = 2468; | 1047 const int kNewTabId = 2468; |
| 964 | 1048 |
| 1049 // AddTab inserts at index 0, so go in reverse order (tab 3 -> tab 1). | |
| 1050 AddTab(browser(), GURL(kBaz1)); | |
| 1051 NavigateAndCommitActiveTab(GURL(kBaz2)); | |
| 1052 AddTab(browser(), GURL(kBar1)); | |
| 1053 NavigateAndCommitActiveTab(GURL(kBar2)); | |
| 1054 AddTab(browser(), GURL(kFoo1)); | |
| 1055 NavigateAndCommitActiveTab(GURL(kFoo2)); | |
| 1056 | |
| 965 syncer::SyncDataList in; | 1057 syncer::SyncDataList in; |
| 966 syncer::SyncChangeList out; | 1058 syncer::SyncChangeList out; |
| 967 InitWithSyncDataTakeOutput(in, &out); | 1059 InitWithSyncDataTakeOutput(in, &out); |
| 968 | 1060 |
| 969 // Should be one header add, 3 tab add/update pairs, one header update. | 1061 // Should be one header add, 3 tab adds, one header update. |
| 970 ASSERT_EQ(8U, out.size()); | 1062 ASSERT_EQ(5U, out.size()); |
| 971 | 1063 |
| 972 // For input, we set up: | 1064 // For input, we set up: |
| 973 // * one "normal" fully loaded tab | 1065 // * one "normal" fully loaded tab |
| 974 // * one "frozen" tab with no WebContents and a tab_id change | 1066 // * one placeholder tab with no WebContents and a tab_id change |
| 975 // * one "frozen" tab with no WebContents and no tab_id change | 1067 // * one placeholder tab with no WebContents and no tab_id change |
| 976 sync_pb::EntitySpecifics t0_entity = out[2].sync_data().GetSpecifics(); | 1068 sync_pb::EntitySpecifics t0_entity = out[1].sync_data().GetSpecifics(); |
| 977 sync_pb::EntitySpecifics t1_entity = out[4].sync_data().GetSpecifics(); | 1069 sync_pb::EntitySpecifics t1_entity = out[2].sync_data().GetSpecifics(); |
| 978 sync_pb::EntitySpecifics t2_entity = out[6].sync_data().GetSpecifics(); | 1070 sync_pb::EntitySpecifics t2_entity = out[3].sync_data().GetSpecifics(); |
| 979 t1_entity.mutable_session()->mutable_tab()->set_tab_id(kRestoredTabId); | 1071 t1_entity.mutable_session()->mutable_tab()->set_tab_id(kRestoredTabId); |
| 980 in.push_back(CreateRemoteData(t0_entity)); | 1072 in.push_back(CreateRemoteData(t0_entity)); |
| 981 in.push_back(CreateRemoteData(t1_entity)); | 1073 in.push_back(CreateRemoteData(t1_entity)); |
| 982 in.push_back(CreateRemoteData(t2_entity)); | 1074 in.push_back(CreateRemoteData(t2_entity)); |
| 983 out.clear(); | 1075 out.clear(); |
| 984 manager()->StopSyncing(syncer::SESSIONS); | 1076 manager()->StopSyncing(syncer::SESSIONS); |
| 985 | 1077 |
| 986 const std::set<const SyncedWindowDelegate*>& windows = | 1078 const std::set<const SyncedWindowDelegate*>& windows = |
| 987 manager()->synced_window_delegates_getter()->GetSyncedWindowDelegates(); | 1079 manager()->synced_window_delegates_getter()->GetSyncedWindowDelegates(); |
| 988 ASSERT_EQ(1U, windows.size()); | 1080 ASSERT_EQ(1U, windows.size()); |
| 989 SyncedTabDelegateFake t1_override, t2_override; | 1081 PlaceholderTabDelegate t1_override(kNewTabId, 1); |
| 990 t1_override.SetSyncId(1); // No WebContents by default. | 1082 PlaceholderTabDelegate t2_override(t2_entity.session().tab().tab_id(), 2); |
| 991 t2_override.SetSyncId(2); // No WebContents by default. | |
| 992 SyncedWindowDelegateOverride window_override(*windows.begin()); | 1083 SyncedWindowDelegateOverride window_override(*windows.begin()); |
| 993 window_override.OverrideTabAt(1, &t1_override, kNewTabId); | 1084 window_override.OverrideTabAt(1, &t1_override, kNewTabId); |
| 994 window_override.OverrideTabAt(2, &t2_override, | 1085 window_override.OverrideTabAt(2, &t2_override, |
| 995 t2_entity.session().tab().tab_id()); | 1086 t2_entity.session().tab().tab_id()); |
| 996 std::set<const SyncedWindowDelegate*> delegates; | 1087 std::set<const SyncedWindowDelegate*> delegates; |
| 997 delegates.insert(&window_override); | 1088 delegates.insert(&window_override); |
| 998 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( | 1089 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( |
| 999 new TestSyncedWindowDelegatesGetter(delegates)); | 1090 new TestSyncedWindowDelegatesGetter(delegates)); |
| 1000 set_synced_window_getter(getter.get()); | 1091 set_synced_window_getter(getter.get()); |
| 1001 | 1092 |
| 1002 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( | 1093 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( |
| 1003 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( | 1094 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( |
| 1004 new TestSyncProcessorStub(&out)), | 1095 new TestSyncProcessorStub(&out)), |
| 1005 std::unique_ptr<syncer::SyncErrorFactory>( | 1096 std::unique_ptr<syncer::SyncErrorFactory>( |
| 1006 new syncer::SyncErrorFactoryMock())); | 1097 new syncer::SyncErrorFactoryMock())); |
| 1007 | 1098 |
| 1008 // There should be two changes, one for the fully associated tab, and | 1099 // There should be two changes, one for the fully associated tab, and |
| 1009 // one for the tab_id update to t1. t2 shouldn't need to be updated. | 1100 // one each for the tab_id updates to t1 and t2. |
| 1010 ASSERT_EQ(2U, FilterOutLocalHeaderChanges(&out)->size()); | 1101 ASSERT_EQ(3U, FilterOutLocalHeaderChanges(&out)->size()); |
| 1011 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 1102 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
| 1103 EXPECT_EQ(kFoo2, out[0] | |
| 1104 .sync_data() | |
| 1105 .GetSpecifics() | |
| 1106 .session() | |
| 1107 .tab() | |
| 1108 .navigation(1) | |
| 1109 .virtual_url()); | |
| 1110 | |
| 1012 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); | 1111 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); |
| 1013 EXPECT_EQ(kNewTabId, | 1112 EXPECT_EQ(kNewTabId, |
| 1014 out[1].sync_data().GetSpecifics().session().tab().tab_id()); | 1113 out[1].sync_data().GetSpecifics().session().tab().tab_id()); |
| 1114 EXPECT_EQ(kBar2, out[1] | |
| 1115 .sync_data() | |
| 1116 .GetSpecifics() | |
| 1117 .session() | |
| 1118 .tab() | |
| 1119 .navigation(1) | |
| 1120 .virtual_url()); | |
| 1015 | 1121 |
| 1016 // Verify TabLinks. | 1122 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); |
| 1017 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; | 1123 EXPECT_EQ(t2_entity.session().tab().tab_id(), |
| 1018 ASSERT_EQ(3U, tab_map.size()); | 1124 out[2].sync_data().GetSpecifics().session().tab().tab_id()); |
| 1019 int t2_tab_id = t2_entity.session().tab().tab_id(); | 1125 EXPECT_EQ(kBaz2, out[2] |
| 1020 EXPECT_EQ(2, tab_map.find(t2_tab_id)->second->tab_node_id()); | 1126 .sync_data() |
| 1021 EXPECT_EQ(1, tab_map.find(kNewTabId)->second->tab_node_id()); | 1127 .GetSpecifics() |
| 1022 int t0_tab_id = out[0].sync_data().GetSpecifics().session().tab().tab_id(); | 1128 .session() |
| 1023 EXPECT_EQ(0, tab_map.find(t0_tab_id)->second->tab_node_id()); | 1129 .tab() |
| 1024 // TODO(tim): Once bug 337057 is fixed, we can issue an OnLocalTabModified | 1130 .navigation(1) |
| 1025 // from here (using an override similar to above) to return a new tab id | 1131 .virtual_url()); |
| 1026 // and verify that we don't see any node creations in the SyncChangeProcessor | |
| 1027 // (similar to how SessionsSyncManagerTest.OnLocalTabModified works.) | |
| 1028 } | 1132 } |
| 1029 | 1133 |
| 1030 // Ensure model association updates the window ID for tabs whose window's ID has | 1134 // Ensure model association updates the window ID for tabs whose window's ID has |
| 1031 // changed. | 1135 // changed. |
| 1032 TEST_F(SessionsSyncManagerTest, WindowIdUpdatedOnRestore) { | 1136 TEST_F(SessionsSyncManagerTest, WindowIdUpdatedOnRestore) { |
| 1137 const char kFoo1[] = "http://foo1/"; | |
| 1138 const char kFoo2[] = "http://foo2/"; | |
| 1033 const int kNewWindowId = 1337; | 1139 const int kNewWindowId = 1337; |
| 1034 syncer::SyncDataList in; | 1140 syncer::SyncDataList in; |
| 1035 syncer::SyncChangeList out; | 1141 syncer::SyncChangeList out; |
| 1036 | 1142 |
| 1037 // Set up one tab and start sync with it. | 1143 // Set up one tab and start sync with it. |
| 1038 AddTab(browser(), GURL("http://foo1")); | 1144 AddTab(browser(), GURL(kFoo1)); |
| 1039 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1145 NavigateAndCommitActiveTab(GURL(kFoo2)); |
| 1040 InitWithSyncDataTakeOutput(in, &out); | 1146 InitWithSyncDataTakeOutput(in, &out); |
| 1041 | 1147 |
| 1042 // Should be one header add, 1 tab add/update pair, and one header update. | 1148 // Should be one header add, 1 tab add, and one header update. |
| 1043 ASSERT_EQ(4U, out.size()); | 1149 ASSERT_EQ(3U, out.size()); |
| 1044 const sync_pb::EntitySpecifics t0_entity = out[2].sync_data().GetSpecifics(); | 1150 const sync_pb::EntitySpecifics t0_entity = out[1].sync_data().GetSpecifics(); |
| 1151 ASSERT_TRUE(t0_entity.session().has_tab()); | |
| 1045 | 1152 |
| 1046 in.push_back(CreateRemoteData(t0_entity)); | 1153 in.push_back(CreateRemoteData(t0_entity)); |
| 1047 out.clear(); | 1154 out.clear(); |
| 1048 manager()->StopSyncing(syncer::SESSIONS); | 1155 manager()->StopSyncing(syncer::SESSIONS); |
| 1049 | 1156 |
| 1050 // SyncedTabDelegateFake is a placeholder (no WebContents) by default. | 1157 // Override the tab with a placeholder tab delegate. |
| 1051 SyncedTabDelegateFake t0_override; | 1158 PlaceholderTabDelegate t0_override(t0_entity.session().tab().tab_id(), |
| 1052 t0_override.SetSyncId(t0_entity.session().tab_node_id()); | 1159 t0_entity.session().tab_node_id()); |
| 1053 | 1160 |
| 1054 // Set up the window override with the new window ID and placeholder tab. | 1161 // Set up the window override with the new window ID and placeholder tab. |
| 1055 const std::set<const SyncedWindowDelegate*>& windows = | 1162 const std::set<const SyncedWindowDelegate*>& windows = |
| 1056 get_synced_window_getter()->GetSyncedWindowDelegates(); | 1163 get_synced_window_getter()->GetSyncedWindowDelegates(); |
| 1057 ASSERT_EQ(1U, windows.size()); | 1164 ASSERT_EQ(1U, windows.size()); |
| 1058 SyncedWindowDelegateOverride window_override(*windows.begin()); | 1165 SyncedWindowDelegateOverride window_override(*windows.begin()); |
| 1059 window_override.OverrideSessionId(kNewWindowId); | 1166 window_override.OverrideSessionId(kNewWindowId); |
| 1060 window_override.OverrideTabAt(0, &t0_override, | 1167 window_override.OverrideTabAt(0, &t0_override, |
| 1061 t0_entity.session().tab().tab_id()); | 1168 t0_entity.session().tab().tab_id()); |
| 1062 | 1169 |
| 1063 // Inject the window override. | 1170 // Inject the window override. |
| 1064 std::set<const SyncedWindowDelegate*> delegates; | 1171 std::set<const SyncedWindowDelegate*> delegates; |
| 1065 delegates.insert(&window_override); | 1172 delegates.insert(&window_override); |
| 1066 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( | 1173 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( |
| 1067 new TestSyncedWindowDelegatesGetter(delegates)); | 1174 new TestSyncedWindowDelegatesGetter(delegates)); |
| 1068 set_synced_window_getter(getter.get()); | 1175 set_synced_window_getter(getter.get()); |
| 1069 | 1176 |
| 1070 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( | 1177 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( |
| 1071 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( | 1178 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( |
| 1072 new TestSyncProcessorStub(&out)), | 1179 new TestSyncProcessorStub(&out)), |
| 1073 std::unique_ptr<syncer::SyncErrorFactory>( | 1180 std::unique_ptr<syncer::SyncErrorFactory>( |
| 1074 new syncer::SyncErrorFactoryMock())); | 1181 new syncer::SyncErrorFactoryMock())); |
| 1075 | 1182 |
| 1076 // There should be one change for t0's window ID update. | 1183 // There should be one change for t0's window ID update. |
| 1077 ASSERT_EQ(1U, FilterOutLocalHeaderChanges(&out)->size()); | 1184 ASSERT_EQ(1U, FilterOutLocalHeaderChanges(&out)->size()); |
| 1078 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 1185 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
| 1079 EXPECT_EQ(kNewWindowId, | 1186 EXPECT_EQ(kNewWindowId, |
| 1080 out[0].sync_data().GetSpecifics().session().tab().window_id()); | 1187 out[0].sync_data().GetSpecifics().session().tab().window_id()); |
| 1188 EXPECT_EQ(kFoo2, out[0] | |
| 1189 .sync_data() | |
| 1190 .GetSpecifics() | |
| 1191 .session() | |
| 1192 .tab() | |
| 1193 .navigation(1) | |
| 1194 .virtual_url()); | |
| 1081 } | 1195 } |
| 1082 | 1196 |
| 1083 // Tests MergeDataAndStartSyncing with sync data but no local data. | 1197 // Tests MergeDataAndStartSyncing with sync data but no local data. |
| 1084 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) { | 1198 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) { |
| 1085 std::string tag = "tag1"; | 1199 std::string tag = "tag1"; |
| 1086 | 1200 |
| 1087 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1201 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1088 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 1202 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1089 std::vector<sync_pb::SessionSpecifics> tabs1; | 1203 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1090 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1204 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 1247 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1134 std::vector<sync_pb::SessionSpecifics> tabs1; | 1248 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1135 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1249 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1136 tag, tab_list1, &tabs1)); | 1250 tag, tab_list1, &tabs1)); |
| 1137 syncer::SyncDataList foreign_data; | 1251 syncer::SyncDataList foreign_data; |
| 1138 foreign_data.push_back(CreateRemoteData(meta)); | 1252 foreign_data.push_back(CreateRemoteData(meta)); |
| 1139 AddTabsToSyncDataList(tabs1, &foreign_data); | 1253 AddTabsToSyncDataList(tabs1, &foreign_data); |
| 1140 | 1254 |
| 1141 syncer::SyncChangeList output; | 1255 syncer::SyncChangeList output; |
| 1142 InitWithSyncDataTakeOutput(foreign_data, &output); | 1256 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1143 ASSERT_EQ(4U, output.size()); | 1257 // Should be one header add, 1 tab add, and one header update. |
| 1258 ASSERT_EQ(3U, output.size()); | |
| 1144 | 1259 |
| 1145 // Verify the local header. | 1260 // Verify the local header. |
| 1146 EXPECT_TRUE(output[0].IsValid()); | 1261 EXPECT_TRUE(output[0].IsValid()); |
| 1147 EXPECT_EQ(SyncChange::ACTION_ADD, output[0].change_type()); | 1262 EXPECT_EQ(SyncChange::ACTION_ADD, output[0].change_type()); |
| 1148 const SyncData data(output[0].sync_data()); | 1263 const SyncData data(output[0].sync_data()); |
| 1149 EXPECT_EQ(manager()->current_machine_tag(), | 1264 EXPECT_EQ(manager()->current_machine_tag(), |
| 1150 syncer::SyncDataLocal(data).GetTag()); | 1265 syncer::SyncDataLocal(data).GetTag()); |
| 1151 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1266 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
| 1152 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1267 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
| 1153 EXPECT_TRUE(specifics.has_header()); | 1268 EXPECT_TRUE(specifics.has_header()); |
| 1154 const sync_pb::SessionHeader& header_s = specifics.header(); | 1269 const sync_pb::SessionHeader& header_s = specifics.header(); |
| 1155 EXPECT_TRUE(header_s.has_device_type()); | 1270 EXPECT_TRUE(header_s.has_device_type()); |
| 1156 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); | 1271 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); |
| 1157 EXPECT_EQ(0, header_s.window_size()); | 1272 EXPECT_EQ(0, header_s.window_size()); |
| 1158 | 1273 |
| 1159 // Verify the tab node creations and updates with content. | 1274 // Verify the tab node creations and updates with content. |
| 1160 for (int i = 1; i < 3; i++) { | 1275 for (int i = 1; i < 3; i++) { |
| 1161 EXPECT_TRUE(output[i].IsValid()); | 1276 EXPECT_TRUE(output[i].IsValid()); |
| 1162 const SyncData data(output[i].sync_data()); | 1277 const SyncData data(output[i].sync_data()); |
| 1163 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), | 1278 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), |
| 1164 manager()->current_machine_tag(), | 1279 manager()->current_machine_tag(), |
| 1165 base::CompareCase::SENSITIVE)); | 1280 base::CompareCase::SENSITIVE)); |
| 1166 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1281 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
| 1167 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1282 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
| 1168 } | 1283 } |
| 1169 EXPECT_EQ(SyncChange::ACTION_ADD, output[1].change_type()); | 1284 EXPECT_EQ(SyncChange::ACTION_ADD, output[1].change_type()); |
| 1170 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[2].change_type()); | 1285 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[2].change_type()); |
| 1171 EXPECT_TRUE(output[2].sync_data().GetSpecifics().session().has_tab()); | 1286 EXPECT_TRUE(output[1].sync_data().GetSpecifics().session().has_tab()); |
| 1172 | 1287 |
| 1173 // Verify the header was updated to reflect window state. | 1288 // Verify the header was updated to reflect window state. |
| 1174 EXPECT_TRUE(output[3].IsValid()); | 1289 EXPECT_TRUE(output[2].IsValid()); |
| 1175 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[3].change_type()); | 1290 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[2].change_type()); |
| 1176 const SyncData data_2(output[3].sync_data()); | 1291 const SyncData data_2(output[2].sync_data()); |
| 1177 EXPECT_EQ(manager()->current_machine_tag(), | 1292 EXPECT_EQ(manager()->current_machine_tag(), |
| 1178 syncer::SyncDataLocal(data_2).GetTag()); | 1293 syncer::SyncDataLocal(data_2).GetTag()); |
| 1179 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); | 1294 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); |
| 1180 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); | 1295 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); |
| 1181 EXPECT_TRUE(specifics2.has_header()); | 1296 EXPECT_TRUE(specifics2.has_header()); |
| 1182 const sync_pb::SessionHeader& header_s2 = specifics2.header(); | 1297 const sync_pb::SessionHeader& header_s2 = specifics2.header(); |
| 1183 EXPECT_EQ(1, header_s2.window_size()); | 1298 EXPECT_EQ(1, header_s2.window_size()); |
| 1184 | 1299 |
| 1185 // Verify foreign data. | 1300 // Verify foreign data. |
| 1186 std::vector<const SyncedSession*> foreign_sessions; | 1301 std::vector<const SyncedSession*> foreign_sessions; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1209 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1324 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1210 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 1325 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1211 meta1_reference.push_back(tab_list1); | 1326 meta1_reference.push_back(tab_list1); |
| 1212 std::vector<sync_pb::SessionSpecifics> tabs1; | 1327 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1213 meta1 = helper()->BuildForeignSession(tag1, tab_list1, &tabs1); | 1328 meta1 = helper()->BuildForeignSession(tag1, tab_list1, &tabs1); |
| 1214 foreign_data1.push_back(CreateRemoteData(meta1)); | 1329 foreign_data1.push_back(CreateRemoteData(meta1)); |
| 1215 AddTabsToSyncDataList(tabs1, &foreign_data1); | 1330 AddTabsToSyncDataList(tabs1, &foreign_data1); |
| 1216 | 1331 |
| 1217 syncer::SyncChangeList output1; | 1332 syncer::SyncChangeList output1; |
| 1218 InitWithSyncDataTakeOutput(foreign_data1, &output1); | 1333 InitWithSyncDataTakeOutput(foreign_data1, &output1); |
| 1219 ASSERT_EQ(4U, output1.size()); | 1334 |
| 1335 // 1 header add, one tab add, one header update. | |
| 1336 ASSERT_EQ(3U, output1.size()); | |
| 1220 | 1337 |
| 1221 // Add a second window to the foreign session. | 1338 // Add a second window to the foreign session. |
| 1222 // TODO(tim): Bug 98892. Add local window too when observers are hooked up. | 1339 // TODO(tim): Bug 98892. Add local window too when observers are hooked up. |
| 1223 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; | 1340 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; |
| 1224 std::vector<SessionID::id_type> tab_list2( | 1341 std::vector<SessionID::id_type> tab_list2( |
| 1225 tab_nums2, tab_nums2 + arraysize(tab_nums2)); | 1342 tab_nums2, tab_nums2 + arraysize(tab_nums2)); |
| 1226 meta1_reference.push_back(tab_list2); | 1343 meta1_reference.push_back(tab_list2); |
| 1227 helper()->AddWindowSpecifics(1, tab_list2, &meta1); | 1344 helper()->AddWindowSpecifics(1, tab_list2, &meta1); |
| 1228 std::vector<sync_pb::SessionSpecifics> tabs2; | 1345 std::vector<sync_pb::SessionSpecifics> tabs2; |
| 1229 tabs2.resize(tab_list2.size()); | 1346 tabs2.resize(tab_list2.size()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1300 EXPECT_TRUE(changes.empty()); | 1417 EXPECT_TRUE(changes.empty()); |
| 1301 | 1418 |
| 1302 // Fill an instance of session specifics with a foreign session's data. | 1419 // Fill an instance of session specifics with a foreign session's data. |
| 1303 std::vector<sync_pb::SessionSpecifics> tabs; | 1420 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1304 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1421 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1305 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); | 1422 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); |
| 1306 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1423 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1307 tag, tab_nums1, &tabs)); | 1424 tag, tab_nums1, &tabs)); |
| 1308 | 1425 |
| 1309 // Update associator with the session's meta node, window, and tabs. | 1426 // Update associator with the session's meta node, window, and tabs. |
| 1310 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); | 1427 manager()->UpdateTrackerWithSpecifics(meta, base::Time()); |
| 1311 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); | 1428 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); |
| 1312 iter != tabs.end(); ++iter) { | 1429 iter != tabs.end(); ++iter) { |
| 1313 manager()->UpdateTrackerWithForeignSession(*iter, base::Time()); | 1430 manager()->UpdateTrackerWithSpecifics(*iter, base::Time()); |
| 1314 } | 1431 } |
| 1315 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1432 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1316 ASSERT_EQ(1U, foreign_sessions.size()); | 1433 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1317 | 1434 |
| 1318 // Now delete the foreign session. | 1435 // Now delete the foreign session. |
| 1319 manager()->DeleteForeignSessionInternal(tag, &changes); | 1436 manager()->DeleteForeignSessionInternal(tag, &changes); |
| 1320 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1437 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1321 | 1438 |
| 1322 EXPECT_EQ(5U, changes.size()); | 1439 EXPECT_EQ(5U, changes.size()); |
| 1323 std::set<std::string> expected_tags(&tag, &tag + 1); | 1440 std::set<std::string> expected_tags(&tag, &tag + 1); |
| 1324 for (int i = 0; i < 5; i++) | 1441 for (int i = 0; i < 5; i++) |
| 1325 expected_tags.insert(TabNodePool::TabIdToTag(tag, i)); | 1442 expected_tags.insert(TabNodeIdToTag(tag, i)); |
| 1326 | 1443 |
| 1327 for (int i = 0; i < 5; i++) { | 1444 for (int i = 0; i < 5; i++) { |
| 1328 SCOPED_TRACE(changes[i].ToString()); | 1445 SCOPED_TRACE(changes[i].ToString()); |
| 1329 EXPECT_TRUE(changes[i].IsValid()); | 1446 EXPECT_TRUE(changes[i].IsValid()); |
| 1330 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[i].change_type()); | 1447 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[i].change_type()); |
| 1331 EXPECT_TRUE(changes[i].sync_data().IsValid()); | 1448 EXPECT_TRUE(changes[i].sync_data().IsValid()); |
| 1332 EXPECT_EQ(1U, | 1449 EXPECT_EQ(1U, |
| 1333 expected_tags.erase( | 1450 expected_tags.erase( |
| 1334 syncer::SyncDataLocal(changes[i].sync_data()).GetTag())); | 1451 syncer::SyncDataLocal(changes[i].sync_data()).GetTag())); |
| 1335 } | 1452 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1438 | 1555 |
| 1439 // This should trigger repair of the TabNodePool. | 1556 // This should trigger repair of the TabNodePool. |
| 1440 const GURL foo1("http://foo/1"); | 1557 const GURL foo1("http://foo/1"); |
| 1441 AddTab(browser(), foo1); | 1558 AddTab(browser(), foo1); |
| 1442 EXPECT_FALSE(manager()->local_tab_pool_out_of_sync_); | 1559 EXPECT_FALSE(manager()->local_tab_pool_out_of_sync_); |
| 1443 | 1560 |
| 1444 // AddTab triggers two notifications, one for the tab insertion and one for | 1561 // AddTab triggers two notifications, one for the tab insertion and one for |
| 1445 // committing the NavigationEntry. The first notification results in a tab | 1562 // committing the NavigationEntry. The first notification results in a tab |
| 1446 // we don't associate although we do update the header node. The second | 1563 // we don't associate although we do update the header node. The second |
| 1447 // notification triggers association of the tab, and the subsequent window | 1564 // notification triggers association of the tab, and the subsequent window |
| 1448 // update. So we should see 4 changes at the SyncChangeProcessor. | 1565 // update. So we should see 3 changes at the SyncChangeProcessor. |
| 1449 ASSERT_EQ(4U, out.size()); | 1566 ASSERT_EQ(3U, out.size()); |
| 1450 | 1567 |
| 1451 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 1568 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
| 1452 ASSERT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); | 1569 ASSERT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); |
| 1453 EXPECT_EQ(SyncChange::ACTION_ADD, out[1].change_type()); | 1570 EXPECT_EQ(SyncChange::ACTION_ADD, out[1].change_type()); |
| 1454 int tab_node_id = out[1].sync_data().GetSpecifics().session().tab_node_id(); | 1571 int tab_node_id = out[1].sync_data().GetSpecifics().session().tab_node_id(); |
| 1455 EXPECT_EQ(TabNodePool::TabIdToTag( | 1572 EXPECT_EQ(TabNodeIdToTag(manager()->current_machine_tag(), tab_node_id), |
| 1456 manager()->current_machine_tag(), tab_node_id), | |
| 1457 syncer::SyncDataLocal(out[1].sync_data()).GetTag()); | 1573 syncer::SyncDataLocal(out[1].sync_data()).GetTag()); |
| 1458 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); | 1574 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); |
| 1459 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_tab()); | 1575 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); |
| 1460 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[3].change_type()); | 1576 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_header()); |
| 1461 ASSERT_TRUE(out[3].sync_data().GetSpecifics().session().has_header()); | |
| 1462 | 1577 |
| 1463 // Verify the actual content. | 1578 // Verify the actual content. |
| 1464 const sync_pb::SessionHeader& session_header = | 1579 const sync_pb::SessionHeader& session_header = |
| 1465 out[3].sync_data().GetSpecifics().session().header(); | 1580 out[2].sync_data().GetSpecifics().session().header(); |
| 1466 ASSERT_EQ(1, session_header.window_size()); | 1581 ASSERT_EQ(1, session_header.window_size()); |
| 1467 EXPECT_EQ(1, session_header.window(0).tab_size()); | 1582 EXPECT_EQ(1, session_header.window(0).tab_size()); |
| 1468 const sync_pb::SessionTab& tab1 = | 1583 const sync_pb::SessionTab& tab1 = |
| 1469 out[2].sync_data().GetSpecifics().session().tab(); | 1584 out[1].sync_data().GetSpecifics().session().tab(); |
| 1470 ASSERT_EQ(1, tab1.navigation_size()); | 1585 ASSERT_EQ(1, tab1.navigation_size()); |
| 1471 EXPECT_EQ(foo1.spec(), tab1.navigation(0).virtual_url()); | 1586 EXPECT_EQ(foo1.spec(), tab1.navigation(0).virtual_url()); |
| 1472 | 1587 |
| 1473 // Verify TabNodePool integrity. | 1588 // Verify TabNodePool integrity. |
| 1474 EXPECT_EQ(1U, manager()->local_tab_pool_.Capacity()); | 1589 EXPECT_EQ(1U, GetTabPool()->Capacity()); |
| 1475 EXPECT_TRUE(manager()->local_tab_pool_.Empty()); | 1590 EXPECT_TRUE(GetTabPool()->Empty()); |
| 1476 | |
| 1477 // Verify TabLinks. | |
| 1478 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; | |
| 1479 ASSERT_EQ(1U, tab_map.size()); | |
| 1480 int tab_id = out[2].sync_data().GetSpecifics().session().tab().tab_id(); | |
| 1481 EXPECT_EQ(tab_node_id, tab_map.find(tab_id)->second->tab_node_id()); | |
| 1482 } | 1591 } |
| 1483 | 1592 |
| 1484 // Test that receiving a session delete from sync removes the session | 1593 // Test that receiving a session delete from sync removes the session |
| 1485 // from tracking. | 1594 // from tracking. |
| 1486 TEST_F(SessionsSyncManagerTest, ProcessForeignDelete) { | 1595 TEST_F(SessionsSyncManagerTest, ProcessForeignDelete) { |
| 1487 InitWithNoSyncData(); | 1596 InitWithNoSyncData(); |
| 1488 SessionID::id_type n[] = {5}; | 1597 SessionID::id_type n[] = {5}; |
| 1489 std::vector<sync_pb::SessionSpecifics> tabs1; | 1598 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1490 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); | 1599 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 1491 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1600 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1615 output.clear(); | 1724 output.clear(); |
| 1616 | 1725 |
| 1617 // Verify that cleanup post-merge cleanup correctly removes all tabs objects. | 1726 // Verify that cleanup post-merge cleanup correctly removes all tabs objects. |
| 1618 const sessions::SessionTab* tab; | 1727 const sessions::SessionTab* tab; |
| 1619 ASSERT_FALSE( | 1728 ASSERT_FALSE( |
| 1620 manager()->session_tracker_.LookupSessionTab(session_tag, 1, &tab)); | 1729 manager()->session_tracker_.LookupSessionTab(session_tag, 1, &tab)); |
| 1621 ASSERT_FALSE( | 1730 ASSERT_FALSE( |
| 1622 manager()->session_tracker_.LookupSessionTab(session_tag, 2, &tab)); | 1731 manager()->session_tracker_.LookupSessionTab(session_tag, 2, &tab)); |
| 1623 | 1732 |
| 1624 std::set<int> tab_node_ids; | 1733 std::set<int> tab_node_ids; |
| 1625 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); | 1734 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, |
| 1735 &tab_node_ids); | |
| 1626 EXPECT_EQ(6U, tab_node_ids.size()); | 1736 EXPECT_EQ(6U, tab_node_ids.size()); |
| 1627 EXPECT_TRUE(tab_node_ids.find(tab1A.tab_node_id()) != tab_node_ids.end()); | 1737 EXPECT_TRUE(tab_node_ids.find(tab1A.tab_node_id()) != tab_node_ids.end()); |
| 1628 EXPECT_TRUE(tab_node_ids.find(tab1B.tab_node_id()) != tab_node_ids.end()); | 1738 EXPECT_TRUE(tab_node_ids.find(tab1B.tab_node_id()) != tab_node_ids.end()); |
| 1629 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); | 1739 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1630 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); | 1740 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1631 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); | 1741 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1632 EXPECT_TRUE(tab_node_ids.find(tab2C.tab_node_id()) != tab_node_ids.end()); | 1742 EXPECT_TRUE(tab_node_ids.find(tab2C.tab_node_id()) != tab_node_ids.end()); |
| 1633 | 1743 |
| 1634 syncer::SyncChangeList changes; | 1744 syncer::SyncChangeList changes; |
| 1635 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); | 1745 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); |
| 1636 changes.push_back(MakeRemoteChange(tab1B, SyncChange::ACTION_DELETE)); | 1746 changes.push_back(MakeRemoteChange(tab1B, SyncChange::ACTION_DELETE)); |
| 1637 changes.push_back(MakeRemoteChange(tab2C, SyncChange::ACTION_DELETE)); | 1747 changes.push_back(MakeRemoteChange(tab2C, SyncChange::ACTION_DELETE)); |
| 1638 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1748 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1639 | 1749 |
| 1640 tab_node_ids.clear(); | 1750 tab_node_ids.clear(); |
| 1641 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); | 1751 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, |
| 1752 &tab_node_ids); | |
| 1642 EXPECT_EQ(3U, tab_node_ids.size()); | 1753 EXPECT_EQ(3U, tab_node_ids.size()); |
| 1643 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); | 1754 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1644 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); | 1755 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1645 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); | 1756 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1646 | 1757 |
| 1647 manager()->DoGarbageCollection(); | 1758 manager()->DoGarbageCollection(); |
| 1648 ASSERT_EQ(3U, output.size()); | 1759 ASSERT_EQ(3U, output.size()); |
| 1649 } | 1760 } |
| 1650 | 1761 |
| 1651 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithReusedNodeIds) { | 1762 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithReusedNodeIds) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1669 helper()->BuildTabSpecifics(session_tag, 0, 2, tab_node_id_shared, &tab2A); | 1780 helper()->BuildTabSpecifics(session_tag, 0, 2, tab_node_id_shared, &tab2A); |
| 1670 AddToSyncDataList(tab2A, &foreign_data, | 1781 AddToSyncDataList(tab2A, &foreign_data, |
| 1671 stale_mtime + base::TimeDelta::FromMinutes(1)); | 1782 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1672 | 1783 |
| 1673 syncer::SyncChangeList output; | 1784 syncer::SyncChangeList output; |
| 1674 InitWithSyncDataTakeOutput(foreign_data, &output); | 1785 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1675 ASSERT_EQ(2U, output.size()); | 1786 ASSERT_EQ(2U, output.size()); |
| 1676 output.clear(); | 1787 output.clear(); |
| 1677 | 1788 |
| 1678 std::set<int> tab_node_ids; | 1789 std::set<int> tab_node_ids; |
| 1679 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); | 1790 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, |
| 1791 &tab_node_ids); | |
| 1680 EXPECT_EQ(2U, tab_node_ids.size()); | 1792 EXPECT_EQ(2U, tab_node_ids.size()); |
| 1681 EXPECT_TRUE(tab_node_ids.find(tab_node_id_shared) != tab_node_ids.end()); | 1793 EXPECT_TRUE(tab_node_ids.find(tab_node_id_shared) != tab_node_ids.end()); |
| 1682 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); | 1794 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
| 1683 | 1795 |
| 1684 syncer::SyncChangeList changes; | 1796 syncer::SyncChangeList changes; |
| 1685 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); | 1797 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); |
| 1686 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1798 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1687 | 1799 |
| 1688 tab_node_ids.clear(); | 1800 tab_node_ids.clear(); |
| 1689 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); | 1801 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, |
| 1802 &tab_node_ids); | |
| 1690 EXPECT_EQ(1U, tab_node_ids.size()); | 1803 EXPECT_EQ(1U, tab_node_ids.size()); |
| 1691 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); | 1804 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
| 1692 | 1805 |
| 1693 manager()->DoGarbageCollection(); | 1806 manager()->DoGarbageCollection(); |
| 1694 EXPECT_EQ(1U, output.size()); | 1807 EXPECT_EQ(1U, output.size()); |
| 1695 } | 1808 } |
| 1696 | 1809 |
| 1697 // TODO(shashishekhar): "Move this to TabNodePool unittests." | |
| 1698 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { | 1810 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { |
| 1699 syncer::SyncChangeList changes; | 1811 syncer::SyncChangeList changes; |
| 1700 InitWithNoSyncData(); | 1812 AddTab(browser(), GURL("http://foo1")); |
| 1813 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &changes); | |
| 1814 ASSERT_EQ(3U, changes.size()); // Header add, tab add, header update. | |
| 1815 ASSERT_TRUE(changes[1].sync_data().GetSpecifics().session().has_tab()); | |
| 1816 int tab_node_id = | |
| 1817 changes[1].sync_data().GetSpecifics().session().tab_node_id(); | |
| 1701 | 1818 |
| 1702 std::string local_tag = manager()->current_machine_tag(); | 1819 // Pass back the previous tab and header nodes at association, along with a |
| 1703 // Create a free node and then dissassociate sessions so that it ends up | 1820 // second tab node (with a rewritten tab node id). |
| 1704 // unassociated. | 1821 syncer::SyncDataList in; |
| 1705 manager()->local_tab_pool_.GetFreeTabNode(&changes); | 1822 in.push_back( |
| 1823 CreateRemoteData(changes[2].sync_data().GetSpecifics())); // Header node. | |
| 1824 sync_pb::SessionSpecifics new_tab( | |
| 1825 changes[1].sync_data().GetSpecifics().session()); | |
| 1826 new_tab.set_tab_node_id(tab_node_id + 1); | |
| 1827 in.push_back(CreateRemoteData(new_tab)); // New tab node. | |
| 1828 in.push_back(CreateRemoteData( | |
| 1829 changes[1].sync_data().GetSpecifics())); // Old tab node. | |
| 1830 changes.clear(); | |
| 1706 | 1831 |
| 1707 // Update the tab_id of the node, so that it is considered a valid | 1832 // Reassociate (with the same single tab/window open). |
| 1708 // unassociated node otherwise it will be mistaken for a corrupted node and | 1833 manager()->StopSyncing(syncer::SESSIONS); |
| 1709 // will be deleted before being added to the tab node pool. | 1834 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( |
| 1710 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); | |
| 1711 entity.mutable_session()->mutable_tab()->set_tab_id(1); | |
| 1712 SyncData d = CreateRemoteData(entity); | |
| 1713 syncer::SyncDataList in(&d, &d + 1); | |
| 1714 changes.clear(); | |
| 1715 SessionsSyncManager manager2(GetSyncSessionsClient(), sync_prefs(), | |
| 1716 local_device(), NewDummyRouter(), | |
| 1717 base::Closure(), base::Closure()); | |
| 1718 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( | |
| 1719 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( | 1835 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( |
| 1720 new TestSyncProcessorStub(&changes)), | 1836 new TestSyncProcessorStub(&changes)), |
| 1721 std::unique_ptr<syncer::SyncErrorFactory>( | 1837 std::unique_ptr<syncer::SyncErrorFactory>( |
| 1722 new syncer::SyncErrorFactoryMock())); | 1838 new syncer::SyncErrorFactoryMock())); |
| 1723 ASSERT_FALSE(result.error().IsSet()); | 1839 ASSERT_FALSE(result.error().IsSet()); |
| 1724 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); | 1840 |
| 1841 // No tab entities should be deleted. The original (lower) tab node id should | |
| 1842 // be reused for association. | |
| 1843 FilterOutLocalHeaderChanges(&changes); | |
| 1844 ASSERT_EQ(1U, changes.size()); | |
| 1845 EXPECT_EQ(SyncChange::ACTION_UPDATE, changes[0].change_type()); | |
| 1846 EXPECT_TRUE(changes[0].sync_data().GetSpecifics().session().has_tab()); | |
| 1847 EXPECT_EQ(tab_node_id, | |
| 1848 changes[0].sync_data().GetSpecifics().session().tab_node_id()); | |
| 1725 } | 1849 } |
| 1726 | 1850 |
| 1727 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) { | 1851 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) { |
| 1728 syncer::SyncChangeList changes; | 1852 syncer::SyncChangeList changes; |
| 1729 InitWithNoSyncData(); | 1853 InitWithNoSyncData(); |
| 1730 | 1854 |
| 1731 std::string local_tag = manager()->current_machine_tag(); | 1855 std::string local_tag = manager()->current_machine_tag(); |
| 1732 int tab_node_id = manager()->local_tab_pool_.GetFreeTabNode(&changes); | 1856 int tab_node_id = TabNodePool::kInvalidTabNodeID; |
| 1733 SyncData d = CreateRemoteData(changes[0].sync_data().GetSpecifics()); | 1857 GetTabPool()->GetTabNodeForTab(0, &tab_node_id); |
| 1858 sync_pb::SessionSpecifics specifics; | |
| 1859 specifics.set_session_tag(local_tag); | |
| 1860 specifics.set_tab_node_id(tab_node_id); | |
| 1861 SyncData d = CreateRemoteData(specifics); | |
| 1734 syncer::SyncDataList in(&d, &d + 1); | 1862 syncer::SyncDataList in(&d, &d + 1); |
| 1735 changes.clear(); | |
| 1736 TearDown(); | 1863 TearDown(); |
| 1737 SetUp(); | 1864 SetUp(); |
| 1738 InitWithSyncDataTakeOutput(in, &changes); | 1865 InitWithSyncDataTakeOutput(in, &changes); |
| 1739 EXPECT_EQ(1U, FilterOutLocalHeaderChanges(&changes)->size()); | 1866 EXPECT_EQ(1U, FilterOutLocalHeaderChanges(&changes)->size()); |
| 1740 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[0].change_type()); | 1867 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 1741 EXPECT_EQ(TabNodePool::TabIdToTag(local_tag, tab_node_id), | 1868 EXPECT_EQ(TabNodeIdToTag(local_tag, tab_node_id), |
| 1742 syncer::SyncDataLocal(changes[0].sync_data()).GetTag()); | 1869 syncer::SyncDataLocal(changes[0].sync_data()).GetTag()); |
| 1743 } | 1870 } |
| 1744 | 1871 |
| 1745 // Verifies that we drop both headers and tabs during merge if their stored tag | 1872 // Verifies that we drop both headers and tabs during merge if their stored tag |
| 1746 // hash doesn't match a computer tag hash. This mitigates potential failures | 1873 // hash doesn't match a computer tag hash. This mitigates potential failures |
| 1747 // while cleaning up bad foreign data, see crbug.com/604657. | 1874 // while cleaning up bad foreign data, see crbug.com/604657. |
| 1748 TEST_F(SessionsSyncManagerTest, MergeDeletesBadHash) { | 1875 TEST_F(SessionsSyncManagerTest, MergeDeletesBadHash) { |
| 1749 syncer::SyncDataList foreign_data; | 1876 syncer::SyncDataList foreign_data; |
| 1750 std::vector<SessionID::id_type> empty_ids; | 1877 std::vector<SessionID::id_type> empty_ids; |
| 1751 std::vector<sync_pb::SessionSpecifics> empty_tabs; | 1878 std::vector<sync_pb::SessionSpecifics> empty_tabs; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1800 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 1927 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
| 1801 ASSERT_EQ(2U, out.size()); // Header add and update. | 1928 ASSERT_EQ(2U, out.size()); // Header add and update. |
| 1802 EXPECT_EQ( | 1929 EXPECT_EQ( |
| 1803 0, | 1930 0, |
| 1804 out[1].sync_data().GetSpecifics().session().header().window_size()); | 1931 out[1].sync_data().GetSpecifics().session().header().window_size()); |
| 1805 out.clear(); | 1932 out.clear(); |
| 1806 | 1933 |
| 1807 // Go to a sync-interesting URL. | 1934 // Go to a sync-interesting URL. |
| 1808 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1935 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 1809 | 1936 |
| 1810 EXPECT_EQ(3U, out.size()); // Tab add, update, and header update. | 1937 EXPECT_EQ(2U, out.size()); // Tab add and header update. |
| 1811 | 1938 |
| 1812 EXPECT_TRUE( | 1939 EXPECT_TRUE( |
| 1813 base::StartsWith(syncer::SyncDataLocal(out[0].sync_data()).GetTag(), | 1940 base::StartsWith(syncer::SyncDataLocal(out[0].sync_data()).GetTag(), |
| 1814 manager()->current_machine_tag(), | 1941 manager()->current_machine_tag(), |
| 1815 base::CompareCase::SENSITIVE)); | 1942 base::CompareCase::SENSITIVE)); |
| 1816 EXPECT_EQ(manager()->current_machine_tag(), | 1943 EXPECT_EQ(manager()->current_machine_tag(), |
| 1817 out[0].sync_data().GetSpecifics().session().session_tag()); | 1944 out[0].sync_data().GetSpecifics().session().session_tag()); |
| 1818 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); | 1945 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); |
| 1819 | 1946 |
| 1820 EXPECT_TRUE( | 1947 EXPECT_TRUE(out[1].IsValid()); |
| 1821 base::StartsWith(syncer::SyncDataLocal(out[1].sync_data()).GetTag(), | |
| 1822 manager()->current_machine_tag(), | |
| 1823 base::CompareCase::SENSITIVE)); | |
| 1824 EXPECT_EQ(manager()->current_machine_tag(), | |
| 1825 out[1].sync_data().GetSpecifics().session().session_tag()); | |
| 1826 EXPECT_TRUE(out[1].sync_data().GetSpecifics().session().has_tab()); | |
| 1827 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); | 1948 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); |
| 1828 | 1949 const SyncData data(out[1].sync_data()); |
| 1829 EXPECT_TRUE(out[2].IsValid()); | |
| 1830 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); | |
| 1831 const SyncData data(out[2].sync_data()); | |
| 1832 EXPECT_EQ(manager()->current_machine_tag(), | 1950 EXPECT_EQ(manager()->current_machine_tag(), |
| 1833 syncer::SyncDataLocal(data).GetTag()); | 1951 syncer::SyncDataLocal(data).GetTag()); |
| 1834 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1952 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
| 1835 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1953 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
| 1836 EXPECT_TRUE(specifics.has_header()); | 1954 EXPECT_TRUE(specifics.has_header()); |
| 1837 const sync_pb::SessionHeader& header_s = specifics.header(); | 1955 const sync_pb::SessionHeader& header_s = specifics.header(); |
| 1838 EXPECT_EQ(1, header_s.window_size()); | 1956 EXPECT_EQ(1, header_s.window_size()); |
| 1839 EXPECT_EQ(1, header_s.window(0).tab_size()); | 1957 EXPECT_EQ(1, header_s.window(0).tab_size()); |
| 1840 } | 1958 } |
| 1841 | 1959 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1853 | 1971 |
| 1854 const GURL foo1("http://foo/1"); | 1972 const GURL foo1("http://foo/1"); |
| 1855 const GURL foo2("http://foo/2"); | 1973 const GURL foo2("http://foo/2"); |
| 1856 const GURL bar1("http://bar/1"); | 1974 const GURL bar1("http://bar/1"); |
| 1857 const GURL bar2("http://bar/2"); | 1975 const GURL bar2("http://bar/2"); |
| 1858 AddTab(browser(), foo1); | 1976 AddTab(browser(), foo1); |
| 1859 NavigateAndCommitActiveTab(foo2); | 1977 NavigateAndCommitActiveTab(foo2); |
| 1860 AddTab(browser(), bar1); | 1978 AddTab(browser(), bar1); |
| 1861 NavigateAndCommitActiveTab(bar2); | 1979 NavigateAndCommitActiveTab(bar2); |
| 1862 | 1980 |
| 1863 // One add, one update for each AddTab. | 1981 // One add for each AddTab. |
| 1864 // One update for each NavigateAndCommit. | 1982 // One update for each NavigateAndCommit. |
| 1865 // = 6 total tab updates. | 1983 // = 4 total tab updates. |
| 1866 // One header update corresponding to each of those. | 1984 // One header update corresponding to each of those. |
| 1867 // = 6 total header updates. | 1985 // = 6 total header updates. |
| 1868 // 12 total updates. | 1986 // 10 total updates. |
| 1869 ASSERT_EQ(12U, out.size()); | 1987 ASSERT_EQ(10U, out.size()); |
| 1870 | 1988 |
| 1871 // Verify the tab node creations and updates to ensure the SyncProcessor | 1989 // Verify the tab node creations and updates to ensure the SyncProcessor |
| 1872 // sees the right operations. | 1990 // sees the right operations. |
| 1873 for (int i = 0; i < 12; i++) { | 1991 for (int i = 0; i < 10; i++) { |
| 1874 SCOPED_TRACE(i); | 1992 SCOPED_TRACE(i); |
| 1875 EXPECT_TRUE(out[i].IsValid()); | 1993 EXPECT_TRUE(out[i].IsValid()); |
| 1876 const SyncData data(out[i].sync_data()); | 1994 const SyncData data(out[i].sync_data()); |
| 1877 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), | 1995 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), |
| 1878 manager()->current_machine_tag(), | 1996 manager()->current_machine_tag(), |
| 1879 base::CompareCase::SENSITIVE)); | 1997 base::CompareCase::SENSITIVE)); |
| 1880 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1998 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
| 1881 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1999 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
| 1882 if (i % 6 == 0) { | 2000 if (i % 5 == 0) { |
| 1883 // First thing on an AddTab is a no-op header update for parented tab. | 2001 // First thing on an AddTab is a no-op header update for parented tab. |
| 1884 EXPECT_EQ(header.SerializeAsString(), | 2002 EXPECT_EQ(header.SerializeAsString(), |
| 1885 data.GetSpecifics().SerializeAsString()); | 2003 data.GetSpecifics().SerializeAsString()); |
| 1886 EXPECT_EQ(manager()->current_machine_tag(), | 2004 EXPECT_EQ(manager()->current_machine_tag(), |
| 1887 syncer::SyncDataLocal(data).GetTag()); | 2005 syncer::SyncDataLocal(data).GetTag()); |
| 1888 } else if (i % 6 == 1) { | 2006 } else if (i % 5 == 1) { |
| 1889 // Next, the TabNodePool should create the tab node. | 2007 // Next, the tab should be added. |
| 1890 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); | 2008 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); |
| 1891 EXPECT_EQ(TabNodePool::TabIdToTag( | 2009 EXPECT_EQ(TabNodeIdToTag(manager()->current_machine_tag(), |
| 1892 manager()->current_machine_tag(), | 2010 data.GetSpecifics().session().tab_node_id()), |
| 1893 data.GetSpecifics().session().tab_node_id()), | |
| 1894 syncer::SyncDataLocal(data).GetTag()); | 2011 syncer::SyncDataLocal(data).GetTag()); |
| 1895 } else if (i % 6 == 2) { | 2012 } else if (i % 5 == 2) { |
| 1896 // Then we see the tab update to the URL. | |
| 1897 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | |
| 1898 EXPECT_EQ(TabNodePool::TabIdToTag( | |
| 1899 manager()->current_machine_tag(), | |
| 1900 data.GetSpecifics().session().tab_node_id()), | |
| 1901 syncer::SyncDataLocal(data).GetTag()); | |
| 1902 ASSERT_TRUE(specifics.has_tab()); | |
| 1903 } else if (i % 6 == 3) { | |
| 1904 // The header needs to be updated to reflect the new window state. | 2013 // The header needs to be updated to reflect the new window state. |
| 1905 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | 2014 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
| 1906 EXPECT_TRUE(specifics.has_header()); | 2015 EXPECT_TRUE(specifics.has_header()); |
| 1907 } else if (i % 6 == 4) { | 2016 } else if (i % 5 == 3) { |
| 1908 // Now we move on to NavigateAndCommit. Update the tab. | 2017 // Now we move on to NavigateAndCommit. Update the tab. |
| 1909 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | 2018 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
| 1910 EXPECT_EQ(TabNodePool::TabIdToTag( | 2019 EXPECT_EQ(TabNodeIdToTag(manager()->current_machine_tag(), |
| 1911 manager()->current_machine_tag(), | 2020 data.GetSpecifics().session().tab_node_id()), |
| 1912 data.GetSpecifics().session().tab_node_id()), | |
| 1913 syncer::SyncDataLocal(data).GetTag()); | 2021 syncer::SyncDataLocal(data).GetTag()); |
| 1914 ASSERT_TRUE(specifics.has_tab()); | 2022 ASSERT_TRUE(specifics.has_tab()); |
| 1915 } else if (i % 6 == 5) { | 2023 } else if (i % 5 == 4) { |
| 1916 // The header needs to be updated to reflect the new window state. | 2024 // The header needs to be updated to reflect the new window state. |
| 1917 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | 2025 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
| 1918 ASSERT_TRUE(specifics.has_header()); | 2026 ASSERT_TRUE(specifics.has_header()); |
| 1919 header = data.GetSpecifics(); | 2027 header = data.GetSpecifics(); |
| 1920 } | 2028 } |
| 1921 } | 2029 } |
| 1922 | 2030 |
| 1923 // Verify the actual content to ensure sync sees the right data. | 2031 // Verify the actual content to ensure sync sees the right data. |
| 1924 // When it's all said and done, the header should reflect two tabs. | 2032 // When it's all said and done, the header should reflect two tabs. |
| 1925 const sync_pb::SessionHeader& session_header = header.session().header(); | 2033 const sync_pb::SessionHeader& session_header = header.session().header(); |
| 1926 ASSERT_EQ(1, session_header.window_size()); | 2034 ASSERT_EQ(1, session_header.window_size()); |
| 1927 EXPECT_EQ(2, session_header.window(0).tab_size()); | 2035 EXPECT_EQ(2, session_header.window(0).tab_size()); |
| 1928 | 2036 |
| 1929 // ASSERT_TRUEs above allow us to dive in freely here. | 2037 // ASSERT_TRUEs above allow us to dive in freely here. |
| 1930 // Verify first tab. | 2038 // Verify first tab. |
| 1931 const sync_pb::SessionTab& tab1_1 = | 2039 const sync_pb::SessionTab& tab1_1 = |
| 1932 out[2].sync_data().GetSpecifics().session().tab(); | 2040 out[1].sync_data().GetSpecifics().session().tab(); |
| 1933 ASSERT_EQ(1, tab1_1.navigation_size()); | 2041 ASSERT_EQ(1, tab1_1.navigation_size()); |
| 1934 EXPECT_EQ(foo1.spec(), tab1_1.navigation(0).virtual_url()); | 2042 EXPECT_EQ(foo1.spec(), tab1_1.navigation(0).virtual_url()); |
| 1935 const sync_pb::SessionTab& tab1_2 = | 2043 const sync_pb::SessionTab& tab1_2 = |
| 1936 out[4].sync_data().GetSpecifics().session().tab(); | 2044 out[3].sync_data().GetSpecifics().session().tab(); |
| 1937 ASSERT_EQ(2, tab1_2.navigation_size()); | 2045 ASSERT_EQ(2, tab1_2.navigation_size()); |
| 1938 EXPECT_EQ(foo1.spec(), tab1_2.navigation(0).virtual_url()); | 2046 EXPECT_EQ(foo1.spec(), tab1_2.navigation(0).virtual_url()); |
| 1939 EXPECT_EQ(foo2.spec(), tab1_2.navigation(1).virtual_url()); | 2047 EXPECT_EQ(foo2.spec(), tab1_2.navigation(1).virtual_url()); |
| 1940 | 2048 |
| 1941 // Verify second tab. | 2049 // Verify second tab. |
| 1942 const sync_pb::SessionTab& tab2_1 = | 2050 const sync_pb::SessionTab& tab2_1 = |
| 1943 out[8].sync_data().GetSpecifics().session().tab(); | 2051 out[6].sync_data().GetSpecifics().session().tab(); |
| 1944 ASSERT_EQ(1, tab2_1.navigation_size()); | 2052 ASSERT_EQ(1, tab2_1.navigation_size()); |
| 1945 EXPECT_EQ(bar1.spec(), tab2_1.navigation(0).virtual_url()); | 2053 EXPECT_EQ(bar1.spec(), tab2_1.navigation(0).virtual_url()); |
| 1946 const sync_pb::SessionTab& tab2_2 = | 2054 const sync_pb::SessionTab& tab2_2 = |
| 1947 out[10].sync_data().GetSpecifics().session().tab(); | 2055 out[8].sync_data().GetSpecifics().session().tab(); |
| 1948 ASSERT_EQ(2, tab2_2.navigation_size()); | 2056 ASSERT_EQ(2, tab2_2.navigation_size()); |
| 1949 EXPECT_EQ(bar1.spec(), tab2_2.navigation(0).virtual_url()); | 2057 EXPECT_EQ(bar1.spec(), tab2_2.navigation(0).virtual_url()); |
| 1950 EXPECT_EQ(bar2.spec(), tab2_2.navigation(1).virtual_url()); | 2058 EXPECT_EQ(bar2.spec(), tab2_2.navigation(1).virtual_url()); |
| 1951 } | 2059 } |
| 1952 | 2060 |
| 1953 // Check that if a tab becomes uninteresting (for example no syncable URLs), | 2061 // Check that if a tab becomes uninteresting (for example no syncable URLs), |
| 1954 // we correctly remove it from the header node. | 2062 // we correctly remove it from the header node. |
| 1955 TEST_F(SessionsSyncManagerTest, TabBecomesUninteresting) { | 2063 TEST_F(SessionsSyncManagerTest, TabBecomesUninteresting) { |
| 1956 syncer::SyncChangeList out; | 2064 syncer::SyncChangeList out; |
| 1957 // Init with no local data, relies on MergeLocalSessionNoTabs. | 2065 // Init with no local data, relies on MergeLocalSessionNoTabs. |
| 1958 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 2066 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
| 1959 ASSERT_FALSE(manager()->current_machine_tag().empty()); | 2067 ASSERT_FALSE(manager()->current_machine_tag().empty()); |
| 1960 ASSERT_EQ(2U, out.size()); | 2068 ASSERT_EQ(2U, out.size()); |
| 1961 out.clear(); | 2069 out.clear(); |
| 1962 | 2070 |
| 1963 const GURL kValidUrl("http://foo/1"); | 2071 const GURL kValidUrl("http://foo/1"); |
| 1964 const GURL kInternalUrl("chrome://internal"); | 2072 const GURL kInternalUrl("chrome://internal"); |
| 1965 | 2073 |
| 1966 // Add an interesting tab. | 2074 // Add an interesting tab. |
| 1967 AddTab(browser(), kValidUrl); | 2075 AddTab(browser(), kValidUrl); |
| 1968 // No-op header update, tab creation, tab update, header update. | 2076 // No-op header update, tab creation, header update. |
| 1969 ASSERT_EQ(4U, out.size()); | 2077 ASSERT_EQ(3U, out.size()); |
| 1970 // The last two are the interesting updates. | 2078 // The last two are the interesting updates. |
| 1971 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_tab()); | 2079 ASSERT_TRUE(out[1].sync_data().GetSpecifics().session().has_tab()); |
| 1972 EXPECT_EQ(kValidUrl.spec(), out[2] | 2080 EXPECT_EQ(kValidUrl.spec(), out[1] |
| 1973 .sync_data() | 2081 .sync_data() |
| 1974 .GetSpecifics() | 2082 .GetSpecifics() |
| 1975 .session() | 2083 .session() |
| 1976 .tab() | 2084 .tab() |
| 1977 .navigation(0) | 2085 .navigation(0) |
| 1978 .virtual_url()); | 2086 .virtual_url()); |
| 1979 ASSERT_TRUE(out[3].sync_data().GetSpecifics().session().has_header()); | 2087 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_header()); |
| 1980 ASSERT_EQ(1, | 2088 ASSERT_EQ(1, |
| 1981 out[3].sync_data().GetSpecifics().session().header().window_size()); | 2089 out[2].sync_data().GetSpecifics().session().header().window_size()); |
| 1982 ASSERT_EQ(1, out[3] | 2090 ASSERT_EQ(1, out[2] |
| 1983 .sync_data() | 2091 .sync_data() |
| 1984 .GetSpecifics() | 2092 .GetSpecifics() |
| 1985 .session() | 2093 .session() |
| 1986 .header() | 2094 .header() |
| 1987 .window(0) | 2095 .window(0) |
| 1988 .tab_size()); | 2096 .tab_size()); |
| 1989 | 2097 |
| 1990 // Navigate five times to uninteresting urls to push the interesting one off | 2098 // Navigate five times to uninteresting urls to push the interesting one off |
| 1991 // the back of the stack. | 2099 // the back of the stack. |
| 1992 NavigateAndCommitActiveTab(kInternalUrl); | 2100 NavigateAndCommitActiveTab(kInternalUrl); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2008 | 2116 |
| 2009 // Ensure model association associates the pre-existing tabs. | 2117 // Ensure model association associates the pre-existing tabs. |
| 2010 TEST_F(SessionsSyncManagerTest, MergeLocalSessionExistingTabs) { | 2118 TEST_F(SessionsSyncManagerTest, MergeLocalSessionExistingTabs) { |
| 2011 AddTab(browser(), GURL("http://foo1")); | 2119 AddTab(browser(), GURL("http://foo1")); |
| 2012 NavigateAndCommitActiveTab(GURL("http://foo2")); // Adds back entry. | 2120 NavigateAndCommitActiveTab(GURL("http://foo2")); // Adds back entry. |
| 2013 AddTab(browser(), GURL("http://bar1")); | 2121 AddTab(browser(), GURL("http://bar1")); |
| 2014 NavigateAndCommitActiveTab(GURL("http://bar2")); // Adds back entry. | 2122 NavigateAndCommitActiveTab(GURL("http://bar2")); // Adds back entry. |
| 2015 | 2123 |
| 2016 syncer::SyncChangeList out; | 2124 syncer::SyncChangeList out; |
| 2017 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 2125 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
| 2018 ASSERT_EQ(6U, out.size()); | 2126 ASSERT_EQ(4U, out.size()); // Header creation, add two tabs, header update |
| 2019 | 2127 |
| 2020 // Check that this machine's data is not included in the foreign windows. | 2128 // Check that this machine's data is not included in the foreign windows. |
| 2021 std::vector<const SyncedSession*> foreign_sessions; | 2129 std::vector<const SyncedSession*> foreign_sessions; |
| 2022 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2130 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2023 | 2131 |
| 2024 // Verify the header. | 2132 // Verify the header. |
| 2025 EXPECT_TRUE(out[0].IsValid()); | 2133 EXPECT_TRUE(out[0].IsValid()); |
| 2026 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); | 2134 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); |
| 2027 const SyncData data(out[0].sync_data()); | 2135 const SyncData data(out[0].sync_data()); |
| 2028 EXPECT_EQ(manager()->current_machine_tag(), | 2136 EXPECT_EQ(manager()->current_machine_tag(), |
| 2029 syncer::SyncDataLocal(data).GetTag()); | 2137 syncer::SyncDataLocal(data).GetTag()); |
| 2030 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 2138 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
| 2031 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 2139 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
| 2032 EXPECT_TRUE(specifics.has_header()); | 2140 EXPECT_TRUE(specifics.has_header()); |
| 2033 const sync_pb::SessionHeader& header_s = specifics.header(); | 2141 const sync_pb::SessionHeader& header_s = specifics.header(); |
| 2034 EXPECT_TRUE(header_s.has_device_type()); | 2142 EXPECT_TRUE(header_s.has_device_type()); |
| 2035 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); | 2143 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); |
| 2036 EXPECT_EQ(0, header_s.window_size()); | 2144 EXPECT_EQ(0, header_s.window_size()); |
| 2037 | 2145 |
| 2038 // Verify the tab node creations and updates with content. | 2146 // Verify the tab node creations and updates with content. |
| 2039 for (int i = 1; i < 5; i++) { | 2147 for (int i = 1; i < 3; i++) { |
| 2040 EXPECT_TRUE(out[i].IsValid()); | 2148 EXPECT_TRUE(out[i].IsValid()); |
| 2041 const SyncData data(out[i].sync_data()); | 2149 const SyncData data(out[i].sync_data()); |
| 2042 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), | 2150 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), |
| 2043 manager()->current_machine_tag(), | 2151 manager()->current_machine_tag(), |
| 2044 base::CompareCase::SENSITIVE)); | 2152 base::CompareCase::SENSITIVE)); |
| 2045 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 2153 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
| 2046 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 2154 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
| 2047 if (i % 2 == 1) { | 2155 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); |
| 2048 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); | |
| 2049 } else { | |
| 2050 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | |
| 2051 EXPECT_TRUE(specifics.has_tab()); | |
| 2052 } | |
| 2053 } | 2156 } |
| 2054 | 2157 |
| 2055 // Verify the header was updated to reflect new window state. | 2158 // Verify the header was updated to reflect new window state. |
| 2056 EXPECT_TRUE(out[5].IsValid()); | 2159 EXPECT_TRUE(out[3].IsValid()); |
| 2057 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[5].change_type()); | 2160 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[3].change_type()); |
| 2058 const SyncData data_2(out[5].sync_data()); | 2161 const SyncData data_2(out[3].sync_data()); |
| 2059 EXPECT_EQ(manager()->current_machine_tag(), | 2162 EXPECT_EQ(manager()->current_machine_tag(), |
| 2060 syncer::SyncDataLocal(data_2).GetTag()); | 2163 syncer::SyncDataLocal(data_2).GetTag()); |
| 2061 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); | 2164 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); |
| 2062 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); | 2165 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); |
| 2063 EXPECT_TRUE(specifics2.has_header()); | 2166 EXPECT_TRUE(specifics2.has_header()); |
| 2064 const sync_pb::SessionHeader& header_s2 = specifics2.header(); | 2167 const sync_pb::SessionHeader& header_s2 = specifics2.header(); |
| 2065 EXPECT_EQ(1, header_s2.window_size()); | 2168 EXPECT_EQ(1, header_s2.window_size()); |
| 2066 | |
| 2067 // Verify TabLinks. | |
| 2068 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; | |
| 2069 ASSERT_EQ(2U, tab_map.size()); | |
| 2070 // Tabs are ordered by sessionid in tab_map, so should be able to traverse | |
| 2071 // the tree based on order of tabs created | |
| 2072 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); | |
| 2073 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | |
| 2074 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | |
| 2075 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | |
| 2076 iter++; | |
| 2077 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | |
| 2078 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | |
| 2079 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | |
| 2080 } | 2169 } |
| 2081 | 2170 |
| 2082 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { | 2171 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { |
| 2083 syncer::SyncDataList foreign_data; | 2172 syncer::SyncDataList foreign_data; |
| 2084 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); | 2173 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 2085 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); | 2174 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); |
| 2086 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); | 2175 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); |
| 2087 | 2176 |
| 2088 { | 2177 { |
| 2089 std::string session_tag = "tag1"; | 2178 std::string session_tag = "tag1"; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2172 | 2261 |
| 2173 // Now garbage collect and verify the non-stale session is still there. | 2262 // Now garbage collect and verify the non-stale session is still there. |
| 2174 manager()->DoGarbageCollection(); | 2263 manager()->DoGarbageCollection(); |
| 2175 ASSERT_EQ(5U, output.size()); | 2264 ASSERT_EQ(5U, output.size()); |
| 2176 EXPECT_EQ(SyncChange::ACTION_DELETE, output[0].change_type()); | 2265 EXPECT_EQ(SyncChange::ACTION_DELETE, output[0].change_type()); |
| 2177 const SyncData data(output[0].sync_data()); | 2266 const SyncData data(output[0].sync_data()); |
| 2178 EXPECT_EQ(tag1, syncer::SyncDataLocal(data).GetTag()); | 2267 EXPECT_EQ(tag1, syncer::SyncDataLocal(data).GetTag()); |
| 2179 for (int i = 1; i < 5; i++) { | 2268 for (int i = 1; i < 5; i++) { |
| 2180 EXPECT_EQ(SyncChange::ACTION_DELETE, output[i].change_type()); | 2269 EXPECT_EQ(SyncChange::ACTION_DELETE, output[i].change_type()); |
| 2181 const SyncData data(output[i].sync_data()); | 2270 const SyncData data(output[i].sync_data()); |
| 2182 EXPECT_EQ(TabNodePool::TabIdToTag(tag1, i), | 2271 EXPECT_EQ(TabNodeIdToTag(tag1, i), syncer::SyncDataLocal(data).GetTag()); |
| 2183 syncer::SyncDataLocal(data).GetTag()); | |
| 2184 } | 2272 } |
| 2185 | 2273 |
| 2186 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2274 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2187 ASSERT_EQ(1U, foreign_sessions.size()); | 2275 ASSERT_EQ(1U, foreign_sessions.size()); |
| 2188 std::vector<std::vector<SessionID::id_type> > session_reference; | 2276 std::vector<std::vector<SessionID::id_type> > session_reference; |
| 2189 session_reference.push_back(tab_list2); | 2277 session_reference.push_back(tab_list2); |
| 2190 helper()->VerifySyncedSession(tag2, session_reference, | 2278 helper()->VerifySyncedSession(tag2, session_reference, |
| 2191 *(foreign_sessions[0])); | 2279 *(foreign_sessions[0])); |
| 2192 } | 2280 } |
| 2193 | 2281 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2296 } | 2384 } |
| 2297 | 2385 |
| 2298 // Test that swapping WebContents for a tab is properly observed and handled | 2386 // Test that swapping WebContents for a tab is properly observed and handled |
| 2299 // by the SessionsSyncManager. | 2387 // by the SessionsSyncManager. |
| 2300 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { | 2388 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { |
| 2301 AddTab(browser(), GURL("http://foo1")); | 2389 AddTab(browser(), GURL("http://foo1")); |
| 2302 NavigateAndCommitActiveTab(GURL("http://foo2")); | 2390 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 2303 | 2391 |
| 2304 syncer::SyncChangeList out; | 2392 syncer::SyncChangeList out; |
| 2305 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 2393 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
| 2306 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE. | 2394 ASSERT_EQ(3U, out.size()); // Header ADD, tab ADD, header UPDATE. |
| 2395 out.clear(); | |
| 2307 | 2396 |
| 2308 // To simulate WebContents swap during prerendering, create new WebContents | 2397 // To simulate WebContents swap during prerendering, create new WebContents |
| 2309 // and swap with old WebContents. | 2398 // and swap with old WebContents. |
| 2310 std::unique_ptr<content::WebContents> old_web_contents; | 2399 std::unique_ptr<content::WebContents> old_web_contents; |
| 2311 old_web_contents.reset(browser()->tab_strip_model()->GetActiveWebContents()); | 2400 old_web_contents.reset(browser()->tab_strip_model()->GetActiveWebContents()); |
| 2312 | 2401 |
| 2313 // Create new WebContents, with the required tab helpers. | 2402 // Create new WebContents, with the required tab helpers. |
| 2314 WebContents* new_web_contents = WebContents::CreateWithSessionStorage( | 2403 WebContents* new_web_contents = WebContents::CreateWithSessionStorage( |
| 2315 WebContents::CreateParams(profile()), | 2404 WebContents::CreateParams(profile()), |
| 2316 old_web_contents->GetController().GetSessionStorageNamespaceMap()); | 2405 old_web_contents->GetController().GetSessionStorageNamespaceMap()); |
| 2317 SessionTabHelper::CreateForWebContents(new_web_contents); | 2406 SessionTabHelper::CreateForWebContents(new_web_contents); |
| 2318 TabContentsSyncedTabDelegate::CreateForWebContents(new_web_contents); | 2407 TabContentsSyncedTabDelegate::CreateForWebContents(new_web_contents); |
| 2319 new_web_contents->GetController() | 2408 new_web_contents->GetController() |
| 2320 .CopyStateFrom(old_web_contents->GetController()); | 2409 .CopyStateFrom(old_web_contents->GetController()); |
| 2321 | 2410 |
| 2322 // Swap the WebContents. | 2411 // Swap the WebContents. |
| 2323 int index = browser()->tab_strip_model()->GetIndexOfWebContents( | 2412 int index = browser()->tab_strip_model()->GetIndexOfWebContents( |
| 2324 old_web_contents.get()); | 2413 old_web_contents.get()); |
| 2325 browser()->tab_strip_model()->ReplaceWebContentsAt(index, new_web_contents); | 2414 browser()->tab_strip_model()->ReplaceWebContentsAt(index, new_web_contents); |
| 2326 | 2415 |
| 2327 ASSERT_EQ(9U, out.size()); | 2416 ASSERT_EQ(4U, out.size()); |
| 2328 EXPECT_EQ(SyncChange::ACTION_ADD, out[4].change_type()); | 2417 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); |
| 2329 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[5].change_type()); | 2418 out.clear(); |
| 2330 | 2419 |
| 2331 // Navigate away. | 2420 // Navigate away. +1 tab updates, 1 header update. |
| 2332 NavigateAndCommitActiveTab(GURL("http://bar2")); | 2421 NavigateAndCommitActiveTab(GURL("http://bar2")); |
| 2333 | 2422 |
| 2334 // Delete old WebContents. This should not crash. | 2423 // Delete old WebContents. This should not crash. |
| 2424 // +1 no-op header update. | |
| 2335 old_web_contents.reset(); | 2425 old_web_contents.reset(); |
| 2336 | 2426 |
| 2337 // Try more navigations and verify output size. This can also reveal | 2427 // Try more navigations and verify output size. This can also reveal |
| 2338 // bugs (leaks) on memcheck bots if the SessionSyncManager | 2428 // bugs (leaks) on memcheck bots if the SessionSyncManager |
| 2339 // didn't properly clean up the tab pool or session tracker. | 2429 // didn't properly clean up the tab pool or session tracker. |
| 2430 // +1 tab updates, 1 header update. | |
| 2340 NavigateAndCommitActiveTab(GURL("http://bar3")); | 2431 NavigateAndCommitActiveTab(GURL("http://bar3")); |
| 2341 | 2432 |
| 2433 // +1 no-op header update, tab add, header update. | |
| 2342 AddTab(browser(), GURL("http://bar4")); | 2434 AddTab(browser(), GURL("http://bar4")); |
| 2435 // +1 tab update, header update. | |
| 2343 NavigateAndCommitActiveTab(GURL("http://bar5")); | 2436 NavigateAndCommitActiveTab(GURL("http://bar5")); |
| 2344 ASSERT_EQ(19U, out.size()); | 2437 ASSERT_EQ(10U, out.size()); |
| 2345 } | 2438 } |
| 2346 | 2439 |
| 2347 // Test that NOTIFICATION_FOREIGN_SESSION_UPDATED is sent when processing | 2440 // Test that NOTIFICATION_FOREIGN_SESSION_UPDATED is sent when processing |
| 2348 // sync changes. | 2441 // sync changes. |
| 2349 TEST_F(SessionsSyncManagerTest, NotifiedOfUpdates) { | 2442 TEST_F(SessionsSyncManagerTest, NotifiedOfUpdates) { |
| 2350 ASSERT_FALSE(observer()->notified_of_update()); | 2443 ASSERT_FALSE(observer()->notified_of_update()); |
| 2351 InitWithNoSyncData(); | 2444 InitWithNoSyncData(); |
| 2352 | 2445 |
| 2353 SessionID::id_type n[] = {5}; | 2446 SessionID::id_type n[] = {5}; |
| 2354 std::vector<sync_pb::SessionSpecifics> tabs1; | 2447 std::vector<sync_pb::SessionSpecifics> tabs1; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2603 base::Time last_time; | 2696 base::Time last_time; |
| 2604 for (size_t i = 0; i < tabs.size(); ++i) { | 2697 for (size_t i = 0; i < tabs.size(); ++i) { |
| 2605 base::Time this_time = tabs[i]->timestamp; | 2698 base::Time this_time = tabs[i]->timestamp; |
| 2606 if (i > 0) | 2699 if (i > 0) |
| 2607 ASSERT_GE(last_time, this_time); | 2700 ASSERT_GE(last_time, this_time); |
| 2608 last_time = tabs[i]->timestamp; | 2701 last_time = tabs[i]->timestamp; |
| 2609 } | 2702 } |
| 2610 } | 2703 } |
| 2611 | 2704 |
| 2612 } // namespace sync_sessions | 2705 } // namespace sync_sessions |
| OLD | NEW |