| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/sessions/session_types.h" | 11 #include "chrome/browser/sessions/session_types.h" |
| 11 #include "chrome/browser/sync/glue/session_model_associator.h" | 12 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 12 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 13 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
| 13 #include "chrome/browser/sync/profile_sync_service_mock.h" | 14 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/test/base/profile_mock.h" | 17 #include "chrome/test/base/profile_mock.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 size_t NumFavicons() { | 51 size_t NumFavicons() { |
| 51 return model_associator_.NumFaviconsForTesting(); | 52 return model_associator_.NumFaviconsForTesting(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void DecrementFavicon(std::string url) { | 55 void DecrementFavicon(std::string url) { |
| 55 model_associator_.DecrementAndCleanFaviconForURL(url); | 56 model_associator_.DecrementAndCleanFaviconForURL(url); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void AssociateTabContents(const SyncedWindowDelegate& window, | 59 void AssociateTabContents(const SyncedWindowDelegate& window, |
| 59 const SyncedTabDelegate& new_tab, | 60 const SyncedTabDelegate& new_tab, |
| 60 SyncedSessionTab* prev_tab, | 61 SessionTab* prev_tab, |
| 61 sync_pb::SessionTab* sync_tab, | 62 sync_pb::SessionTab* sync_tab, |
| 62 GURL* new_url) { | 63 GURL* new_url) { |
| 63 model_associator_.AssociateTabContents(window, | 64 model_associator_.AssociateTabContents(window, |
| 64 new_tab, | 65 new_tab, |
| 65 prev_tab, | 66 prev_tab, |
| 66 sync_tab, | 67 sync_tab, |
| 67 new_url); | 68 new_url); |
| 68 } | 69 } |
| 69 | 70 |
| 70 protected: | 71 protected: |
| 71 MessageLoopForUI message_loop_; | 72 MessageLoopForUI message_loop_; |
| 72 content::TestBrowserThread ui_thread_; | 73 content::TestBrowserThread ui_thread_; |
| 73 NiceMock<ProfileMock> profile_; | 74 NiceMock<ProfileMock> profile_; |
| 74 NiceMock<ProfileSyncServiceMock> sync_service_; | 75 NiceMock<ProfileSyncServiceMock> sync_service_; |
| 75 SessionModelAssociator model_associator_; | 76 SessionModelAssociator model_associator_; |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 TEST_F(SyncSessionModelAssociatorTest, SessionWindowHasNoTabsToSync) { | 79 TEST_F(SyncSessionModelAssociatorTest, SessionWindowHasNoTabsToSync) { |
| 79 SessionWindow win; | 80 SessionWindow win; |
| 80 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); | 81 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); |
| 81 scoped_ptr<SessionTab> tab(new SessionTab()); | 82 scoped_ptr<SessionTab> tab(new SessionTab()); |
| 82 win.tabs.push_back(tab.release()); | 83 win.tabs.push_back(tab.release()); |
| 83 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); | 84 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); |
| 84 TabNavigation nav(0, GURL("about:bubba"), | 85 TabNavigation nav = TabNavigation::CreateForTest("about:bubba", "title"); |
| 85 content::Referrer(GURL("about:referrer"), | |
| 86 WebKit::WebReferrerPolicyDefault), | |
| 87 string16(ASCIIToUTF16("title")), | |
| 88 std::string("state"), content::PageTransitionFromInt(0)); | |
| 89 win.tabs[0]->navigations.push_back(nav); | 86 win.tabs[0]->navigations.push_back(nav); |
| 90 ASSERT_FALSE(SessionWindowHasNoTabsToSync(win)); | 87 ASSERT_FALSE(SessionWindowHasNoTabsToSync(win)); |
| 91 } | 88 } |
| 92 | 89 |
| 93 TEST_F(SyncSessionModelAssociatorTest, ShouldSyncSessionTab) { | 90 TEST_F(SyncSessionModelAssociatorTest, ShouldSyncSessionTab) { |
| 94 SyncedSessionTab tab; | 91 SessionTab tab; |
| 95 ASSERT_FALSE(ShouldSyncSessionTab(tab)); | 92 ASSERT_FALSE(ShouldSyncSessionTab(tab)); |
| 96 TabNavigation nav(0, GURL(chrome::kChromeUINewTabURL), | 93 TabNavigation nav = |
| 97 content::Referrer(GURL("about:referrer"), | 94 TabNavigation::CreateForTest(chrome::kChromeUINewTabURL, "title"); |
| 98 WebKit::WebReferrerPolicyDefault), | |
| 99 string16(ASCIIToUTF16("title")), | |
| 100 std::string("state"), content::PageTransitionFromInt(0)); | |
| 101 tab.navigations.push_back(nav); | 95 tab.navigations.push_back(nav); |
| 102 // NewTab does not count as valid if it's the only navigation. | 96 // NewTab does not count as valid if it's the only navigation. |
| 103 ASSERT_FALSE(ShouldSyncSessionTab(tab)); | 97 ASSERT_FALSE(ShouldSyncSessionTab(tab)); |
| 104 TabNavigation nav2(0, GURL("about:bubba"), | 98 TabNavigation nav2 = TabNavigation::CreateForTest("about:bubba", "title"); |
| 105 content::Referrer(GURL("about:referrer"), | |
| 106 WebKit::WebReferrerPolicyDefault), | |
| 107 string16(ASCIIToUTF16("title")), | |
| 108 std::string("state"), content::PageTransitionFromInt(0)); | |
| 109 tab.navigations.push_back(nav2); | 99 tab.navigations.push_back(nav2); |
| 110 // Once there's another navigation, the tab is valid. | 100 // Once there's another navigation, the tab is valid. |
| 111 ASSERT_TRUE(ShouldSyncSessionTab(tab)); | 101 ASSERT_TRUE(ShouldSyncSessionTab(tab)); |
| 112 } | 102 } |
| 113 | 103 |
| 114 TEST_F(SyncSessionModelAssociatorTest, | 104 TEST_F(SyncSessionModelAssociatorTest, |
| 115 ShouldSyncSessionTabIgnoresFragmentForNtp) { | 105 ShouldSyncSessionTabIgnoresFragmentForNtp) { |
| 116 SyncedSessionTab tab; | 106 SessionTab tab; |
| 117 ASSERT_FALSE(ShouldSyncSessionTab(tab)); | 107 ASSERT_FALSE(ShouldSyncSessionTab(tab)); |
| 118 TabNavigation nav(0, GURL(std::string(chrome::kChromeUINewTabURL) + | 108 TabNavigation nav = |
| 119 "#bookmarks"), | 109 TabNavigation::CreateForTest( |
| 120 content::Referrer(GURL("about:referrer"), | 110 std::string(chrome::kChromeUINewTabURL) + "#bookmarks", "title"); |
| 121 WebKit::WebReferrerPolicyDefault), | |
| 122 string16(ASCIIToUTF16("title")), | |
| 123 std::string("state"), content::PageTransitionFromInt(0)); | |
| 124 tab.navigations.push_back(nav); | 111 tab.navigations.push_back(nav); |
| 125 // NewTab does not count as valid if it's the only navigation. | 112 // NewTab does not count as valid if it's the only navigation. |
| 126 ASSERT_FALSE(ShouldSyncSessionTab(tab)); | 113 ASSERT_FALSE(ShouldSyncSessionTab(tab)); |
| 127 } | 114 } |
| 128 | 115 |
| 129 TEST_F(SyncSessionModelAssociatorTest, PopulateSessionHeader) { | 116 TEST_F(SyncSessionModelAssociatorTest, PopulateSessionHeader) { |
| 130 sync_pb::SessionHeader header_s; | 117 sync_pb::SessionHeader header_s; |
| 131 header_s.set_client_name("Client 1"); | 118 header_s.set_client_name("Client 1"); |
| 132 header_s.set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN); | 119 header_s.set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN); |
| 133 | 120 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 159 ASSERT_EQ(1U, tracker.num_synced_tabs(std::string("tag"))); | 146 ASSERT_EQ(1U, tracker.num_synced_tabs(std::string("tag"))); |
| 160 } | 147 } |
| 161 | 148 |
| 162 TEST_F(SyncSessionModelAssociatorTest, PopulateSessionTab) { | 149 TEST_F(SyncSessionModelAssociatorTest, PopulateSessionTab) { |
| 163 sync_pb::SessionTab tab_s; | 150 sync_pb::SessionTab tab_s; |
| 164 tab_s.set_tab_id(5); | 151 tab_s.set_tab_id(5); |
| 165 tab_s.set_tab_visual_index(13); | 152 tab_s.set_tab_visual_index(13); |
| 166 tab_s.set_current_navigation_index(3); | 153 tab_s.set_current_navigation_index(3); |
| 167 tab_s.set_pinned(true); | 154 tab_s.set_pinned(true); |
| 168 tab_s.set_extension_app_id("app_id"); | 155 tab_s.set_extension_app_id("app_id"); |
| 169 sync_pb::TabNavigation* navigation = tab_s.add_navigation(); | 156 for (int i = 0; i < 5; ++i) { |
| 170 navigation->set_virtual_url("http://foo/1"); | 157 sync_pb::TabNavigation* navigation = tab_s.add_navigation(); |
| 171 navigation->set_referrer("referrer"); | 158 navigation->set_virtual_url("http://foo/" + base::IntToString(i)); |
| 172 navigation->set_title("title"); | 159 navigation->set_referrer("referrer"); |
| 173 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); | 160 navigation->set_title("title"); |
| 161 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); |
| 162 } |
| 174 | 163 |
| 175 SyncedSessionTab tab; | 164 SessionTab tab; |
| 176 tab.tab_id.set_id(5); // Expected to be set by the SyncedSessionTracker. | 165 tab.tab_id.set_id(5); // Expected to be set by the SyncedSessionTracker. |
| 177 SessionModelAssociator::PopulateSessionTabFromSpecifics( | 166 SessionModelAssociator::PopulateSessionTabFromSpecifics( |
| 178 tab_s, base::Time(), &tab); | 167 tab_s, base::Time(), &tab); |
| 179 ASSERT_EQ(5, tab.tab_id.id()); | 168 ASSERT_EQ(5, tab.tab_id.id()); |
| 180 ASSERT_EQ(13, tab.tab_visual_index); | 169 ASSERT_EQ(13, tab.tab_visual_index); |
| 181 ASSERT_EQ(3, tab.current_navigation_index); | 170 ASSERT_EQ(3, tab.current_navigation_index); |
| 182 ASSERT_TRUE(tab.pinned); | 171 ASSERT_TRUE(tab.pinned); |
| 183 ASSERT_EQ("app_id", tab.extension_app_id); | 172 ASSERT_EQ("app_id", tab.extension_app_id); |
| 184 ASSERT_EQ(GURL("referrer"), tab.navigations[0].referrer().url); | 173 ASSERT_EQ(5u, tab.navigations.size()); |
| 185 ASSERT_EQ(string16(ASCIIToUTF16("title")), tab.navigations[0].title()); | 174 for (int i = 0; i < 5; ++i) { |
| 186 ASSERT_EQ(content::PAGE_TRANSITION_TYPED, tab.navigations[0].transition()); | 175 ASSERT_EQ(i, tab.navigations[i].index()); |
| 187 ASSERT_EQ(GURL("http://foo/1"), tab.navigations[0].virtual_url()); | 176 ASSERT_EQ(GURL("referrer"), tab.navigations[i].GetReferrerForTest().url); |
| 177 ASSERT_EQ(string16(ASCIIToUTF16("title")), tab.navigations[i].title()); |
| 178 ASSERT_EQ(content::PAGE_TRANSITION_TYPED, |
| 179 tab.navigations[i].GetTransitionTypeForTest()); |
| 180 ASSERT_EQ(GURL("http://foo/" + base::IntToString(i)), |
| 181 tab.navigations[i].virtual_url()); |
| 182 } |
| 188 } | 183 } |
| 189 | 184 |
| 190 TEST_F(SyncSessionModelAssociatorTest, TabNodePool) { | 185 TEST_F(SyncSessionModelAssociatorTest, TabNodePool) { |
| 191 SessionModelAssociator::TabNodePool pool(NULL); | 186 SessionModelAssociator::TabNodePool pool(NULL); |
| 192 pool.set_machine_tag("tag"); | 187 pool.set_machine_tag("tag"); |
| 193 ASSERT_TRUE(pool.empty()); | 188 ASSERT_TRUE(pool.empty()); |
| 194 ASSERT_TRUE(pool.full()); | 189 ASSERT_TRUE(pool.full()); |
| 195 ASSERT_EQ(0U, pool.capacity()); | 190 ASSERT_EQ(0U, pool.capacity()); |
| 196 pool.AddTabNode(5); | 191 pool.AddTabNode(5); |
| 197 pool.AddTabNode(10); | 192 pool.AddTabNode(10); |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( | 579 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( |
| 585 Return(entry1.get())); | 580 Return(entry1.get())); |
| 586 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( | 581 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( |
| 587 Return(entry2.get())); | 582 Return(entry2.get())); |
| 588 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( | 583 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( |
| 589 Return(entry3.get())); | 584 Return(entry3.get())); |
| 590 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); | 585 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); |
| 591 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); | 586 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); |
| 592 | 587 |
| 593 // This tab is new, so prev_tab is the default SyncedSessionTab object. | 588 // This tab is new, so prev_tab is the default SyncedSessionTab object. |
| 594 SyncedSessionTab prev_tab; | 589 SessionTab prev_tab; |
| 595 prev_tab.tab_id.set_id(0); | 590 prev_tab.tab_id.set_id(0); |
| 596 | 591 |
| 597 sync_pb::SessionTab sync_tab; | 592 sync_pb::SessionTab sync_tab; |
| 598 GURL new_url; | 593 GURL new_url; |
| 599 int64 now = syncer::TimeToProtoTime(base::Time::Now()); | 594 int64 now = syncer::TimeToProtoTime(base::Time::Now()); |
| 600 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); | 595 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); |
| 601 | 596 |
| 602 EXPECT_EQ(new_url, entry3->GetVirtualURL()); | 597 EXPECT_EQ(new_url, entry3->GetVirtualURL()); |
| 603 ASSERT_EQ(3, sync_tab.navigation_size()); | 598 ASSERT_EQ(3, sync_tab.navigation_size()); |
| 604 EXPECT_EQ(entry1->GetVirtualURL().spec(), | 599 EXPECT_EQ(entry1->GetVirtualURL().spec(), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 634 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( | 629 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( |
| 635 Return(entry1.get())); | 630 Return(entry1.get())); |
| 636 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( | 631 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( |
| 637 Return(entry2.get())); | 632 Return(entry2.get())); |
| 638 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( | 633 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( |
| 639 Return(entry3.get())); | 634 Return(entry3.get())); |
| 640 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); | 635 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); |
| 641 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); | 636 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); |
| 642 | 637 |
| 643 // This tab is new, so prev_tab is the default SyncedSessionTab object. | 638 // This tab is new, so prev_tab is the default SyncedSessionTab object. |
| 644 SyncedSessionTab prev_tab; | 639 SessionTab prev_tab; |
| 645 prev_tab.tab_id.set_id(0); | 640 prev_tab.tab_id.set_id(0); |
| 646 | 641 |
| 647 // The initial AssociateTabContents call builds the prev_tab. | 642 // The initial AssociateTabContents call builds the prev_tab. |
| 648 sync_pb::SessionTab sync_tab; | 643 sync_pb::SessionTab sync_tab; |
| 649 GURL new_url; | 644 GURL new_url; |
| 650 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); | 645 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); |
| 651 | 646 |
| 652 // Override the timestamps to arbitrary old values we can compare against. | 647 ASSERT_EQ(3u, prev_tab.navigations.size()); |
| 653 prev_tab.synced_tab_navigations[0].set_timestamp(syncer::ProtoTimeToTime(1)); | |
| 654 prev_tab.synced_tab_navigations[1].set_timestamp(syncer::ProtoTimeToTime(2)); | |
| 655 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(3)); | |
| 656 | 648 |
| 657 // Now re-associate with the same data. | 649 // Now re-associate with the same data. |
| 658 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); | 650 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); |
| 659 | 651 |
| 660 EXPECT_EQ(new_url, entry3->GetVirtualURL()); | 652 EXPECT_EQ(new_url, entry3->GetVirtualURL()); |
| 661 ASSERT_EQ(3, sync_tab.navigation_size()); | 653 ASSERT_EQ(3, sync_tab.navigation_size()); |
| 662 EXPECT_EQ(entry1->GetVirtualURL().spec(), | 654 EXPECT_EQ(entry1->GetVirtualURL().spec(), |
| 663 sync_tab.navigation(0).virtual_url()); | 655 sync_tab.navigation(0).virtual_url()); |
| 664 EXPECT_EQ(entry2->GetVirtualURL().spec(), | 656 EXPECT_EQ(entry2->GetVirtualURL().spec(), |
| 665 sync_tab.navigation(1).virtual_url()); | 657 sync_tab.navigation(1).virtual_url()); |
| 666 EXPECT_EQ(entry3->GetVirtualURL().spec(), | 658 EXPECT_EQ(entry3->GetVirtualURL().spec(), |
| 667 sync_tab.navigation(2).virtual_url()); | 659 sync_tab.navigation(2).virtual_url()); |
| 668 EXPECT_EQ(2, sync_tab.current_navigation_index()); | 660 EXPECT_EQ(2, sync_tab.current_navigation_index()); |
| 669 EXPECT_EQ(1, sync_tab.navigation(0).timestamp()); | 661 EXPECT_EQ(syncer::TimeToProtoTime(prev_tab.navigations[0].timestamp()), |
| 670 EXPECT_EQ(2, sync_tab.navigation(1).timestamp()); | 662 sync_tab.navigation(0).timestamp()); |
| 671 EXPECT_EQ(3, sync_tab.navigation(2).timestamp()); | 663 EXPECT_EQ(syncer::TimeToProtoTime(prev_tab.navigations[1].timestamp()), |
| 664 sync_tab.navigation(1).timestamp()); |
| 665 EXPECT_EQ(syncer::TimeToProtoTime(prev_tab.navigations[2].timestamp()), |
| 666 sync_tab.navigation(2).timestamp()); |
| 672 EXPECT_EQ(3U, prev_tab.navigations.size()); | 667 EXPECT_EQ(3U, prev_tab.navigations.size()); |
| 673 EXPECT_EQ(3U, prev_tab.synced_tab_navigations.size()); | |
| 674 } | 668 } |
| 675 | 669 |
| 676 // Ensure we add a fresh timestamp for new entries appended to the end. | 670 // Ensure we add a fresh timestamp for new entries appended to the end. |
| 677 TEST_F(SyncSessionModelAssociatorTest, AssociateAppendedTab) { | 671 TEST_F(SyncSessionModelAssociatorTest, AssociateAppendedTab) { |
| 678 NiceMock<SyncedWindowDelegateMock> window_mock; | 672 NiceMock<SyncedWindowDelegateMock> window_mock; |
| 679 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false)); | 673 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false)); |
| 680 | 674 |
| 681 // Create a tab with three valid entries. | 675 // Create a tab with three valid entries. |
| 682 NiceMock<SyncedTabDelegateMock> tab_mock; | 676 NiceMock<SyncedTabDelegateMock> tab_mock; |
| 683 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0)); | 677 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 694 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( | 688 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( |
| 695 Return(entry1.get())); | 689 Return(entry1.get())); |
| 696 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( | 690 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( |
| 697 Return(entry2.get())); | 691 Return(entry2.get())); |
| 698 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( | 692 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( |
| 699 Return(entry3.get())); | 693 Return(entry3.get())); |
| 700 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); | 694 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); |
| 701 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); | 695 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); |
| 702 | 696 |
| 703 // This tab is new, so prev_tab is the default SyncedSessionTab object. | 697 // This tab is new, so prev_tab is the default SyncedSessionTab object. |
| 704 SyncedSessionTab prev_tab; | 698 SessionTab prev_tab; |
| 705 prev_tab.tab_id.set_id(0); | 699 prev_tab.tab_id.set_id(0); |
| 706 | 700 |
| 707 // The initial AssociateTabContents call builds the prev_tab. | 701 // The initial AssociateTabContents call builds the prev_tab. |
| 708 sync_pb::SessionTab sync_tab; | 702 sync_pb::SessionTab sync_tab; |
| 709 GURL new_url; | 703 GURL new_url; |
| 710 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); | 704 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); |
| 711 | 705 |
| 712 // Override the timestamps to arbitrary old values we can compare against. | 706 ASSERT_EQ(3u, prev_tab.navigations.size()); |
| 713 prev_tab.synced_tab_navigations[0].set_timestamp(syncer::ProtoTimeToTime(1)); | |
| 714 prev_tab.synced_tab_navigations[1].set_timestamp(syncer::ProtoTimeToTime(2)); | |
| 715 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(3)); | |
| 716 | 707 |
| 717 // Add a new entry and change the current navigation index. | 708 // Add a new entry and change the current navigation index. |
| 718 scoped_ptr<content::NavigationEntry> entry4( | 709 scoped_ptr<content::NavigationEntry> entry4( |
| 719 content::NavigationEntry::Create()); | 710 content::NavigationEntry::Create()); |
| 720 entry4->SetVirtualURL(GURL("http://www.poodle.com")); | 711 entry4->SetVirtualURL(GURL("http://www.poodle.com")); |
| 721 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly( | 712 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly( |
| 722 Return(entry4.get())); | 713 Return(entry4.get())); |
| 723 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4)); | 714 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4)); |
| 724 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(3)); | 715 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(3)); |
| 725 | 716 |
| 726 // The new entry should have a timestamp later than this. | 717 // The new entry should have a timestamp later than this. |
| 727 int64 now = syncer::TimeToProtoTime(base::Time::Now()); | 718 int64 now = syncer::TimeToProtoTime(base::Time::Now()); |
| 728 | 719 |
| 729 // Now re-associate with the new version. | 720 // Now re-associate with the new version. |
| 730 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); | 721 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); |
| 731 | 722 |
| 732 EXPECT_EQ(new_url, entry4->GetVirtualURL()); | 723 EXPECT_EQ(new_url, entry4->GetVirtualURL()); |
| 733 ASSERT_EQ(4, sync_tab.navigation_size()); | 724 ASSERT_EQ(4, sync_tab.navigation_size()); |
| 734 EXPECT_EQ(entry1->GetVirtualURL().spec(), | 725 EXPECT_EQ(entry1->GetVirtualURL().spec(), |
| 735 sync_tab.navigation(0).virtual_url()); | 726 sync_tab.navigation(0).virtual_url()); |
| 736 EXPECT_EQ(entry2->GetVirtualURL().spec(), | 727 EXPECT_EQ(entry2->GetVirtualURL().spec(), |
| 737 sync_tab.navigation(1).virtual_url()); | 728 sync_tab.navigation(1).virtual_url()); |
| 738 EXPECT_EQ(entry3->GetVirtualURL().spec(), | 729 EXPECT_EQ(entry3->GetVirtualURL().spec(), |
| 739 sync_tab.navigation(2).virtual_url()); | 730 sync_tab.navigation(2).virtual_url()); |
| 740 EXPECT_EQ(entry4->GetVirtualURL().spec(), | 731 EXPECT_EQ(entry4->GetVirtualURL().spec(), |
| 741 sync_tab.navigation(3).virtual_url()); | 732 sync_tab.navigation(3).virtual_url()); |
| 742 EXPECT_EQ(3, sync_tab.current_navigation_index()); | 733 EXPECT_EQ(3, sync_tab.current_navigation_index()); |
| 743 EXPECT_EQ(1, sync_tab.navigation(0).timestamp()); | 734 EXPECT_EQ(syncer::TimeToProtoTime(prev_tab.navigations[0].timestamp()), |
| 744 EXPECT_EQ(2, sync_tab.navigation(1).timestamp()); | 735 sync_tab.navigation(0).timestamp()); |
| 745 EXPECT_EQ(3, sync_tab.navigation(2).timestamp()); | 736 EXPECT_EQ(syncer::TimeToProtoTime(prev_tab.navigations[1].timestamp()), |
| 737 sync_tab.navigation(1).timestamp()); |
| 738 EXPECT_EQ(syncer::TimeToProtoTime(prev_tab.navigations[2].timestamp()), |
| 739 sync_tab.navigation(2).timestamp()); |
| 746 EXPECT_LE(now, sync_tab.navigation(3).timestamp()); | 740 EXPECT_LE(now, sync_tab.navigation(3).timestamp()); |
| 747 EXPECT_EQ(4U, prev_tab.navigations.size()); | 741 EXPECT_EQ(4U, prev_tab.navigations.size()); |
| 748 EXPECT_EQ(4U, prev_tab.synced_tab_navigations.size()); | |
| 749 } | 742 } |
| 750 | 743 |
| 751 // We shouldn't get confused when old/new entries from the previous tab have | 744 // We shouldn't get confused when old/new entries from the previous tab have |
| 752 // been pruned in the new tab. Timestamps for old entries we move back to in the | 745 // been pruned in the new tab. Timestamps for old entries we move back to in the |
| 753 // navigation stack should be refreshed. | 746 // navigation stack should be refreshed. |
| 754 TEST_F(SyncSessionModelAssociatorTest, AssociatePrunedTab) { | 747 TEST_F(SyncSessionModelAssociatorTest, AssociatePrunedTab) { |
| 755 NiceMock<SyncedWindowDelegateMock> window_mock; | 748 NiceMock<SyncedWindowDelegateMock> window_mock; |
| 756 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false)); | 749 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false)); |
| 757 | 750 |
| 758 // Create a tab with four valid entries. | 751 // Create a tab with four valid entries. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 776 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( | 769 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( |
| 777 Return(entry2.get())); | 770 Return(entry2.get())); |
| 778 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( | 771 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( |
| 779 Return(entry3.get())); | 772 Return(entry3.get())); |
| 780 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly( | 773 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly( |
| 781 Return(entry4.get())); | 774 Return(entry4.get())); |
| 782 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4)); | 775 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4)); |
| 783 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); | 776 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); |
| 784 | 777 |
| 785 // This tab is new, so prev_tab is the default SyncedSessionTab object. | 778 // This tab is new, so prev_tab is the default SyncedSessionTab object. |
| 786 SyncedSessionTab prev_tab; | 779 SessionTab prev_tab; |
| 787 prev_tab.tab_id.set_id(0); | 780 prev_tab.tab_id.set_id(0); |
| 788 | 781 |
| 789 // The initial AssociateTabContents call builds the prev_tab. | 782 // The initial AssociateTabContents call builds the prev_tab. |
| 790 sync_pb::SessionTab sync_tab; | 783 sync_pb::SessionTab sync_tab; |
| 791 GURL new_url; | 784 GURL new_url; |
| 792 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); | 785 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); |
| 793 | 786 |
| 794 // Override the timestamps to arbitrary old values we can compare against. | 787 ASSERT_EQ(4u, prev_tab.navigations.size()); |
| 795 prev_tab.synced_tab_navigations[0].set_timestamp(syncer::ProtoTimeToTime(1)); | |
| 796 prev_tab.synced_tab_navigations[1].set_timestamp(syncer::ProtoTimeToTime(2)); | |
| 797 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(3)); | |
| 798 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(4)); | |
| 799 | 788 |
| 800 // Reset new tab to have the oldest entry pruned, the current navigation | 789 // Reset new tab to have the oldest entry pruned, the current navigation |
| 801 // set to entry3, and a new entry added in place of entry4. | 790 // set to entry3, and a new entry added in place of entry4. |
| 802 testing::Mock::VerifyAndClearExpectations(&tab_mock); | 791 testing::Mock::VerifyAndClearExpectations(&tab_mock); |
| 803 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(1)); | 792 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(1)); |
| 804 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( | 793 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( |
| 805 Return(entry2.get())); | 794 Return(entry2.get())); |
| 806 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( | 795 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( |
| 807 Return(entry3.get())); | 796 Return(entry3.get())); |
| 808 scoped_ptr<content::NavigationEntry> entry5( | 797 scoped_ptr<content::NavigationEntry> entry5( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 823 // new timestamp. | 812 // new timestamp. |
| 824 EXPECT_EQ(new_url, entry3->GetVirtualURL()); | 813 EXPECT_EQ(new_url, entry3->GetVirtualURL()); |
| 825 ASSERT_EQ(3, sync_tab.navigation_size()); | 814 ASSERT_EQ(3, sync_tab.navigation_size()); |
| 826 EXPECT_EQ(entry2->GetVirtualURL().spec(), | 815 EXPECT_EQ(entry2->GetVirtualURL().spec(), |
| 827 sync_tab.navigation(0).virtual_url()); | 816 sync_tab.navigation(0).virtual_url()); |
| 828 EXPECT_EQ(entry3->GetVirtualURL().spec(), | 817 EXPECT_EQ(entry3->GetVirtualURL().spec(), |
| 829 sync_tab.navigation(1).virtual_url()); | 818 sync_tab.navigation(1).virtual_url()); |
| 830 EXPECT_EQ(entry5->GetVirtualURL().spec(), | 819 EXPECT_EQ(entry5->GetVirtualURL().spec(), |
| 831 sync_tab.navigation(2).virtual_url()); | 820 sync_tab.navigation(2).virtual_url()); |
| 832 EXPECT_EQ(1, sync_tab.current_navigation_index()); | 821 EXPECT_EQ(1, sync_tab.current_navigation_index()); |
| 833 EXPECT_EQ(2, sync_tab.navigation(0).timestamp()); | 822 EXPECT_EQ(syncer::TimeToProtoTime(prev_tab.navigations[0].timestamp()), |
| 823 sync_tab.navigation(0).timestamp()); |
| 834 EXPECT_LE(now, sync_tab.navigation(1).timestamp()); | 824 EXPECT_LE(now, sync_tab.navigation(1).timestamp()); |
| 835 EXPECT_LE(now, sync_tab.navigation(2).timestamp()); | 825 EXPECT_LE(now, sync_tab.navigation(2).timestamp()); |
| 836 EXPECT_EQ(3U, prev_tab.navigations.size()); | 826 EXPECT_EQ(3U, prev_tab.navigations.size()); |
| 837 EXPECT_EQ(3U, prev_tab.synced_tab_navigations.size()); | |
| 838 } | 827 } |
| 839 | 828 |
| 840 } // namespace browser_sync | 829 } // namespace browser_sync |
| OLD | NEW |