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