Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/browser/sync/glue/session_model_associator_unittest.cc

Issue 10125002: [Sync] Add per-navigation timestamps/unique ids to tab sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/sessions/session_types.h" 10 #include "chrome/browser/sessions/session_types.h"
11 #include "chrome/browser/sync/glue/session_model_associator.h" 11 #include "chrome/browser/sync/glue/session_model_associator.h"
12 #include "chrome/browser/sync/glue/synced_tab_delegate.h" 12 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
13 #include "chrome/browser/sync/profile_sync_service_mock.h" 13 #include "chrome/browser/sync/profile_sync_service_mock.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/profile_mock.h" 16 #include "chrome/test/base/profile_mock.h"
17 #include "content/public/browser/navigation_entry.h" 17 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
21 #include "content/public/common/page_transition_types.h" 20 #include "content/public/common/page_transition_types.h"
22 #include "content/test/test_browser_thread.h" 21 #include "content/test/test_browser_thread.h"
23 #include "sync/protocol/session_specifics.pb.h" 22 #include "sync/protocol/session_specifics.pb.h"
24 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "sync/util/time.h"
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 using testing::NiceMock; 28 using testing::NiceMock;
29 using testing::Return; 29 using testing::Return;
30 using testing::_;
30 31
31 namespace browser_sync { 32 namespace browser_sync {
32 33
33 class SyncSessionModelAssociatorTest : public testing::Test { 34 class SyncSessionModelAssociatorTest : public testing::Test {
34 public: 35 public:
35 SyncSessionModelAssociatorTest() 36 SyncSessionModelAssociatorTest()
36 : ui_thread_(BrowserThread::UI, &message_loop_), 37 : ui_thread_(BrowserThread::UI, &message_loop_),
37 sync_service_(&profile_), 38 sync_service_(&profile_),
38 model_associator_(&sync_service_, true) {} 39 model_associator_(&sync_service_, true) {}
39 40
40 // Helper methods to avoid having to friend individual tests. 41 // Helper methods to avoid having to friend individual tests.
41 bool GetFavicon(std::string page_url, std::string* favicon) { 42 bool GetFavicon(std::string page_url, std::string* favicon) {
42 return model_associator_.GetSyncedFaviconForPageURL(page_url, favicon); 43 return model_associator_.GetSyncedFaviconForPageURL(page_url, favicon);
43 } 44 }
44 45
45 void LoadTabFavicon(const sync_pb::SessionTab& tab) { 46 void LoadTabFavicon(const sync_pb::SessionTab& tab) {
46 model_associator_.LoadForeignTabFavicon(tab); 47 model_associator_.LoadForeignTabFavicon(tab);
47 } 48 }
48 49
49 size_t NumFavicons() { 50 size_t NumFavicons() {
50 return model_associator_.NumFaviconsForTesting(); 51 return model_associator_.NumFaviconsForTesting();
51 } 52 }
52 53
53 void DecrementFavicon(std::string url) { 54 void DecrementFavicon(std::string url) {
54 model_associator_.DecrementAndCleanFaviconForURL(url); 55 model_associator_.DecrementAndCleanFaviconForURL(url);
55 } 56 }
56 57
58 void AssociateTabContents(const SyncedWindowDelegate& window,
59 const SyncedTabDelegate& new_tab,
60 SyncedSessionTab* prev_tab,
61 sync_pb::SessionTab* sync_tab,
62 GURL* new_url) {
63 model_associator_.AssociateTabContents(window,
64 new_tab,
65 prev_tab,
66 sync_tab,
67 new_url);
68 }
69
57 protected: 70 protected:
58 MessageLoopForUI message_loop_; 71 MessageLoopForUI message_loop_;
59 content::TestBrowserThread ui_thread_; 72 content::TestBrowserThread ui_thread_;
60 NiceMock<ProfileMock> profile_; 73 NiceMock<ProfileMock> profile_;
61 NiceMock<ProfileSyncServiceMock> sync_service_; 74 NiceMock<ProfileSyncServiceMock> sync_service_;
62 SessionModelAssociator model_associator_; 75 SessionModelAssociator model_associator_;
63 }; 76 };
64 77
65 TEST_F(SyncSessionModelAssociatorTest, SessionWindowHasNoTabsToSync) { 78 TEST_F(SyncSessionModelAssociatorTest, SessionWindowHasNoTabsToSync) {
66 SessionWindow win; 79 SessionWindow win;
67 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); 80 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win));
68 scoped_ptr<SessionTab> tab(new SessionTab()); 81 scoped_ptr<SessionTab> tab(new SessionTab());
69 win.tabs.push_back(tab.release()); 82 win.tabs.push_back(tab.release());
70 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); 83 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win));
71 TabNavigation nav(0, GURL("about:bubba"), 84 TabNavigation nav(0, GURL("about:bubba"),
72 content::Referrer(GURL("about:referrer"), 85 content::Referrer(GURL("about:referrer"),
73 WebKit::WebReferrerPolicyDefault), 86 WebKit::WebReferrerPolicyDefault),
74 string16(ASCIIToUTF16("title")), 87 string16(ASCIIToUTF16("title")),
75 std::string("state"), content::PageTransitionFromInt(0)); 88 std::string("state"), content::PageTransitionFromInt(0));
76 win.tabs[0]->navigations.push_back(nav); 89 win.tabs[0]->navigations.push_back(nav);
77 ASSERT_FALSE(SessionWindowHasNoTabsToSync(win)); 90 ASSERT_FALSE(SessionWindowHasNoTabsToSync(win));
78 } 91 }
79 92
80 TEST_F(SyncSessionModelAssociatorTest, ShouldSyncSessionTab) { 93 TEST_F(SyncSessionModelAssociatorTest, ShouldSyncSessionTab) {
81 SessionTab tab; 94 SyncedSessionTab tab;
82 ASSERT_FALSE(ShouldSyncSessionTab(tab)); 95 ASSERT_FALSE(ShouldSyncSessionTab(tab));
83 TabNavigation nav(0, GURL(chrome::kChromeUINewTabURL), 96 TabNavigation nav(0, GURL(chrome::kChromeUINewTabURL),
84 content::Referrer(GURL("about:referrer"), 97 content::Referrer(GURL("about:referrer"),
85 WebKit::WebReferrerPolicyDefault), 98 WebKit::WebReferrerPolicyDefault),
86 string16(ASCIIToUTF16("title")), 99 string16(ASCIIToUTF16("title")),
87 std::string("state"), content::PageTransitionFromInt(0)); 100 std::string("state"), content::PageTransitionFromInt(0));
88 tab.navigations.push_back(nav); 101 tab.navigations.push_back(nav);
89 // NewTab does not count as valid if it's the only navigation. 102 // NewTab does not count as valid if it's the only navigation.
90 ASSERT_FALSE(ShouldSyncSessionTab(tab)); 103 ASSERT_FALSE(ShouldSyncSessionTab(tab));
91 TabNavigation nav2(0, GURL("about:bubba"), 104 TabNavigation nav2(0, GURL("about:bubba"),
92 content::Referrer(GURL("about:referrer"), 105 content::Referrer(GURL("about:referrer"),
93 WebKit::WebReferrerPolicyDefault), 106 WebKit::WebReferrerPolicyDefault),
94 string16(ASCIIToUTF16("title")), 107 string16(ASCIIToUTF16("title")),
95 std::string("state"), content::PageTransitionFromInt(0)); 108 std::string("state"), content::PageTransitionFromInt(0));
96 tab.navigations.push_back(nav2); 109 tab.navigations.push_back(nav2);
97 // Once there's another navigation, the tab is valid. 110 // Once there's another navigation, the tab is valid.
98 ASSERT_TRUE(ShouldSyncSessionTab(tab)); 111 ASSERT_TRUE(ShouldSyncSessionTab(tab));
99 } 112 }
100 113
101 TEST_F(SyncSessionModelAssociatorTest, 114 TEST_F(SyncSessionModelAssociatorTest,
102 ShouldSyncSessionTabIgnoresFragmentForNtp) { 115 ShouldSyncSessionTabIgnoresFragmentForNtp) {
103 SessionTab tab; 116 SyncedSessionTab tab;
104 ASSERT_FALSE(ShouldSyncSessionTab(tab)); 117 ASSERT_FALSE(ShouldSyncSessionTab(tab));
105 TabNavigation nav(0, GURL(std::string(chrome::kChromeUINewTabURL) + 118 TabNavigation nav(0, GURL(std::string(chrome::kChromeUINewTabURL) +
106 "#bookmarks"), 119 "#bookmarks"),
107 content::Referrer(GURL("about:referrer"), 120 content::Referrer(GURL("about:referrer"),
108 WebKit::WebReferrerPolicyDefault), 121 WebKit::WebReferrerPolicyDefault),
109 string16(ASCIIToUTF16("title")), 122 string16(ASCIIToUTF16("title")),
110 std::string("state"), content::PageTransitionFromInt(0)); 123 std::string("state"), content::PageTransitionFromInt(0));
111 tab.navigations.push_back(nav); 124 tab.navigations.push_back(nav);
112 // NewTab does not count as valid if it's the only navigation. 125 // NewTab does not count as valid if it's the only navigation.
113 ASSERT_FALSE(ShouldSyncSessionTab(tab)); 126 ASSERT_FALSE(ShouldSyncSessionTab(tab));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 160 }
148 161
149 TEST_F(SyncSessionModelAssociatorTest, PopulateSessionTab) { 162 TEST_F(SyncSessionModelAssociatorTest, PopulateSessionTab) {
150 sync_pb::SessionTab tab_s; 163 sync_pb::SessionTab tab_s;
151 tab_s.set_tab_id(5); 164 tab_s.set_tab_id(5);
152 tab_s.set_tab_visual_index(13); 165 tab_s.set_tab_visual_index(13);
153 tab_s.set_current_navigation_index(3); 166 tab_s.set_current_navigation_index(3);
154 tab_s.set_pinned(true); 167 tab_s.set_pinned(true);
155 tab_s.set_extension_app_id("app_id"); 168 tab_s.set_extension_app_id("app_id");
156 sync_pb::TabNavigation* navigation = tab_s.add_navigation(); 169 sync_pb::TabNavigation* navigation = tab_s.add_navigation();
157 navigation->set_index(12);
158 navigation->set_virtual_url("http://foo/1"); 170 navigation->set_virtual_url("http://foo/1");
159 navigation->set_referrer("referrer"); 171 navigation->set_referrer("referrer");
160 navigation->set_title("title"); 172 navigation->set_title("title");
161 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED); 173 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED);
162 174
163 SessionTab tab; 175 SyncedSessionTab tab;
164 tab.tab_id.set_id(5); // Expected to be set by the SyncedSessionTracker. 176 tab.tab_id.set_id(5); // Expected to be set by the SyncedSessionTracker.
165 SessionModelAssociator::PopulateSessionTabFromSpecifics( 177 SessionModelAssociator::PopulateSessionTabFromSpecifics(
166 tab_s, base::Time(), &tab); 178 tab_s, base::Time(), &tab);
167 ASSERT_EQ(5, tab.tab_id.id()); 179 ASSERT_EQ(5, tab.tab_id.id());
168 ASSERT_EQ(13, tab.tab_visual_index); 180 ASSERT_EQ(13, tab.tab_visual_index);
169 ASSERT_EQ(3, tab.current_navigation_index); 181 ASSERT_EQ(3, tab.current_navigation_index);
170 ASSERT_TRUE(tab.pinned); 182 ASSERT_TRUE(tab.pinned);
171 ASSERT_EQ("app_id", tab.extension_app_id); 183 ASSERT_EQ("app_id", tab.extension_app_id);
172 ASSERT_EQ(12, tab.navigations[0].index());
173 ASSERT_EQ(GURL("referrer"), tab.navigations[0].referrer().url); 184 ASSERT_EQ(GURL("referrer"), tab.navigations[0].referrer().url);
174 ASSERT_EQ(string16(ASCIIToUTF16("title")), tab.navigations[0].title()); 185 ASSERT_EQ(string16(ASCIIToUTF16("title")), tab.navigations[0].title());
175 ASSERT_EQ(content::PAGE_TRANSITION_TYPED, tab.navigations[0].transition()); 186 ASSERT_EQ(content::PAGE_TRANSITION_TYPED, tab.navigations[0].transition());
176 ASSERT_EQ(GURL("http://foo/1"), tab.navigations[0].virtual_url()); 187 ASSERT_EQ(GURL("http://foo/1"), tab.navigations[0].virtual_url());
177 } 188 }
178 189
179 TEST_F(SyncSessionModelAssociatorTest, TabNodePool) { 190 TEST_F(SyncSessionModelAssociatorTest, TabNodePool) {
180 SessionModelAssociator::TabNodePool pool(NULL); 191 SessionModelAssociator::TabNodePool pool(NULL);
181 pool.set_machine_tag("tag"); 192 pool.set_machine_tag("tag");
182 ASSERT_TRUE(pool.empty()); 193 ASSERT_TRUE(pool.empty());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 ASSERT_TRUE(pool.full()); 230 ASSERT_TRUE(pool.full());
220 ASSERT_EQ(2U, pool.capacity()); 231 ASSERT_EQ(2U, pool.capacity());
221 pool.clear(); 232 pool.clear();
222 ASSERT_TRUE(pool.empty()); 233 ASSERT_TRUE(pool.empty());
223 ASSERT_TRUE(pool.full()); 234 ASSERT_TRUE(pool.full());
224 ASSERT_EQ(0U, pool.capacity()); 235 ASSERT_EQ(0U, pool.capacity());
225 } 236 }
226 237
227 namespace { 238 namespace {
228 239
240 class SyncedWindowDelegateMock : public SyncedWindowDelegate {
241 public:
242 SyncedWindowDelegateMock() {}
243 virtual ~SyncedWindowDelegateMock() {}
244 MOCK_CONST_METHOD0(HasWindow, bool());
245 MOCK_CONST_METHOD0(GetSessionId, SessionID::id_type());
246 MOCK_CONST_METHOD0(GetTabCount, int());
247 MOCK_CONST_METHOD0(GetActiveIndex, int());
248 MOCK_CONST_METHOD0(IsApp, bool());
249 MOCK_CONST_METHOD0(IsTypeTabbed, bool());
250 MOCK_CONST_METHOD0(IsTypePopup, bool());
251 MOCK_CONST_METHOD1(IsTabPinned, bool(const SyncedTabDelegate* tab));
252 MOCK_CONST_METHOD1(GetTabAt, SyncedTabDelegate*(int index));
253 MOCK_CONST_METHOD1(GetTabIdAt, SessionID::id_type(int index));
254 };
255
229 class SyncedTabDelegateMock : public SyncedTabDelegate { 256 class SyncedTabDelegateMock : public SyncedTabDelegate {
230 public: 257 public:
231 SyncedTabDelegateMock() {} 258 SyncedTabDelegateMock() {}
232 ~SyncedTabDelegateMock() {} 259 virtual ~SyncedTabDelegateMock() {}
233 260
234 MOCK_CONST_METHOD0(GetWindowId, SessionID::id_type()); 261 MOCK_CONST_METHOD0(GetWindowId, SessionID::id_type());
235 MOCK_CONST_METHOD0(GetSessionId, SessionID::id_type()); 262 MOCK_CONST_METHOD0(GetSessionId, SessionID::id_type());
236 MOCK_CONST_METHOD0(IsBeingDestroyed, bool()); 263 MOCK_CONST_METHOD0(IsBeingDestroyed, bool());
237 MOCK_CONST_METHOD0(profile, Profile*()); 264 MOCK_CONST_METHOD0(profile, Profile*());
238 MOCK_CONST_METHOD0(HasExtensionAppId, bool()); 265 MOCK_CONST_METHOD0(HasExtensionAppId, bool());
239 MOCK_CONST_METHOD0(GetExtensionAppId, const std::string&()); 266 MOCK_CONST_METHOD0(GetExtensionAppId, const std::string&());
240 MOCK_CONST_METHOD0(GetCurrentEntryIndex, int()); 267 MOCK_CONST_METHOD0(GetCurrentEntryIndex, int());
241 MOCK_CONST_METHOD0(GetEntryCount, int()); 268 MOCK_CONST_METHOD0(GetEntryCount, int());
242 MOCK_CONST_METHOD0(GetPendingEntryIndex, int()); 269 MOCK_CONST_METHOD0(GetPendingEntryIndex, int());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // stored into the synced favicon lookups. 364 // stored into the synced favicon lookups.
338 TEST_F(SyncSessionModelAssociatorTest, LoadEmptyFavicon) { 365 TEST_F(SyncSessionModelAssociatorTest, LoadEmptyFavicon) {
339 std::string favicon = ""; 366 std::string favicon = "";
340 std::string favicon_url = "http://www.faviconurl.com/favicon.ico"; 367 std::string favicon_url = "http://www.faviconurl.com/favicon.ico";
341 std::string page_url = "http://www.faviconurl.com/page.html"; 368 std::string page_url = "http://www.faviconurl.com/page.html";
342 sync_pb::SessionTab tab; 369 sync_pb::SessionTab tab;
343 tab.set_favicon(favicon); 370 tab.set_favicon(favicon);
344 tab.set_favicon_source(favicon_url); 371 tab.set_favicon_source(favicon_url);
345 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); 372 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
346 sync_pb::TabNavigation* navigation = tab.add_navigation(); 373 sync_pb::TabNavigation* navigation = tab.add_navigation();
347 navigation->set_index(0);
348 navigation->set_virtual_url(page_url); 374 navigation->set_virtual_url(page_url);
349 tab.set_current_navigation_index(0); 375 tab.set_current_navigation_index(0);
350 376
351 std::string synced_favicon; 377 std::string synced_favicon;
352 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon)); 378 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon));
353 EXPECT_TRUE(synced_favicon.empty()); 379 EXPECT_TRUE(synced_favicon.empty());
354 LoadTabFavicon(tab); 380 LoadTabFavicon(tab);
355 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon)); 381 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon));
356 EXPECT_TRUE(synced_favicon.empty()); 382 EXPECT_TRUE(synced_favicon.empty());
357 } 383 }
358 384
359 // Create tab specifics with a non-web favicon. Ensure it gets ignored and not 385 // Create tab specifics with a non-web favicon. Ensure it gets ignored and not
360 // stored into the synced favicon lookups. 386 // stored into the synced favicon lookups.
361 TEST_F(SyncSessionModelAssociatorTest, LoadNonWebFavicon) { 387 TEST_F(SyncSessionModelAssociatorTest, LoadNonWebFavicon) {
362 std::string favicon = "these are icon synced_favicon"; 388 std::string favicon = "these are icon synced_favicon";
363 std::string favicon_url = "http://www.faviconurl.com/favicon.ico"; 389 std::string favicon_url = "http://www.faviconurl.com/favicon.ico";
364 std::string page_url = "http://www.faviconurl.com/page.html"; 390 std::string page_url = "http://www.faviconurl.com/page.html";
365 sync_pb::SessionTab tab; 391 sync_pb::SessionTab tab;
366 tab.set_favicon(favicon); 392 tab.set_favicon(favicon);
367 tab.set_favicon_source(favicon_url); 393 tab.set_favicon_source(favicon_url);
368 // Set favicon type to an unsupported value (1 == WEB_FAVICON). 394 // Set favicon type to an unsupported value (1 == WEB_FAVICON).
369 tab.mutable_unknown_fields()->AddVarint(9, 2); 395 tab.mutable_unknown_fields()->AddVarint(9, 2);
370 sync_pb::TabNavigation* navigation = tab.add_navigation(); 396 sync_pb::TabNavigation* navigation = tab.add_navigation();
371 navigation->set_index(0);
372 navigation->set_virtual_url(page_url); 397 navigation->set_virtual_url(page_url);
373 tab.set_current_navigation_index(0); 398 tab.set_current_navigation_index(0);
374 399
375 std::string synced_favicon; 400 std::string synced_favicon;
376 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon)); 401 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon));
377 EXPECT_TRUE(synced_favicon.empty()); 402 EXPECT_TRUE(synced_favicon.empty());
378 LoadTabFavicon(tab); 403 LoadTabFavicon(tab);
379 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon)); 404 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon));
380 EXPECT_TRUE(synced_favicon.empty()); 405 EXPECT_TRUE(synced_favicon.empty());
381 } 406 }
382 407
383 // Create tab specifics with a valid favicon. Ensure it gets stored in the 408 // Create tab specifics with a valid favicon. Ensure it gets stored in the
384 // synced favicon lookups and is accessible by the page url. 409 // synced favicon lookups and is accessible by the page url.
385 TEST_F(SyncSessionModelAssociatorTest, LoadValidFavicon) { 410 TEST_F(SyncSessionModelAssociatorTest, LoadValidFavicon) {
386 std::string favicon = "these are icon synced_favicon"; 411 std::string favicon = "these are icon synced_favicon";
387 std::string favicon_url = "http://www.faviconurl.com/favicon.ico"; 412 std::string favicon_url = "http://www.faviconurl.com/favicon.ico";
388 std::string page_url = "http://www.faviconurl.com/page.html"; 413 std::string page_url = "http://www.faviconurl.com/page.html";
389 sync_pb::SessionTab tab; 414 sync_pb::SessionTab tab;
390 tab.set_favicon(favicon); 415 tab.set_favicon(favicon);
391 tab.set_favicon_source(favicon_url); 416 tab.set_favicon_source(favicon_url);
392 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); 417 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
393 sync_pb::TabNavigation* navigation = tab.add_navigation(); 418 sync_pb::TabNavigation* navigation = tab.add_navigation();
394 navigation->set_index(0);
395 navigation->set_virtual_url(page_url); 419 navigation->set_virtual_url(page_url);
396 tab.set_current_navigation_index(0); 420 tab.set_current_navigation_index(0);
397 421
398 std::string synced_favicon; 422 std::string synced_favicon;
399 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon)); 423 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon));
400 EXPECT_TRUE(synced_favicon.empty()); 424 EXPECT_TRUE(synced_favicon.empty());
401 LoadTabFavicon(tab); 425 LoadTabFavicon(tab);
402 EXPECT_TRUE(GetFavicon(page_url, &synced_favicon)); 426 EXPECT_TRUE(GetFavicon(page_url, &synced_favicon));
403 ASSERT_FALSE(synced_favicon.empty()); 427 ASSERT_FALSE(synced_favicon.empty());
404 EXPECT_EQ(favicon, synced_favicon); 428 EXPECT_EQ(favicon, synced_favicon);
405 } 429 }
406 430
407 // Create tab specifics with a valid favicon, load it, then load tab specifics 431 // Create tab specifics with a valid favicon, load it, then load tab specifics
408 // with a new favicon for the same favicon source but different page. Ensure the 432 // with a new favicon for the same favicon source but different page. Ensure the
409 // new favicon overwrites the old favicon for both page urls. 433 // new favicon overwrites the old favicon for both page urls.
410 TEST_F(SyncSessionModelAssociatorTest, UpdateValidFavicon) { 434 TEST_F(SyncSessionModelAssociatorTest, UpdateValidFavicon) {
411 std::string favicon_url = "http://www.faviconurl.com/favicon.ico"; 435 std::string favicon_url = "http://www.faviconurl.com/favicon.ico";
412 436
413 std::string favicon = "these are icon synced_favicon"; 437 std::string favicon = "these are icon synced_favicon";
414 std::string page_url = "http://www.faviconurl.com/page.html"; 438 std::string page_url = "http://www.faviconurl.com/page.html";
415 sync_pb::SessionTab tab; 439 sync_pb::SessionTab tab;
416 tab.set_favicon(favicon); 440 tab.set_favicon(favicon);
417 tab.set_favicon_source(favicon_url); 441 tab.set_favicon_source(favicon_url);
418 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); 442 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
419 sync_pb::TabNavigation* navigation = tab.add_navigation(); 443 sync_pb::TabNavigation* navigation = tab.add_navigation();
420 navigation->set_index(0);
421 navigation->set_virtual_url(page_url); 444 navigation->set_virtual_url(page_url);
422 tab.set_current_navigation_index(0); 445 tab.set_current_navigation_index(0);
423 446
424 std::string synced_favicon; 447 std::string synced_favicon;
425 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon)); 448 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon));
426 EXPECT_TRUE(synced_favicon.empty()); 449 EXPECT_TRUE(synced_favicon.empty());
427 LoadTabFavicon(tab); 450 LoadTabFavicon(tab);
428 EXPECT_TRUE(GetFavicon(page_url, &synced_favicon)); 451 EXPECT_TRUE(GetFavicon(page_url, &synced_favicon));
429 ASSERT_FALSE(synced_favicon.empty()); 452 ASSERT_FALSE(synced_favicon.empty());
430 EXPECT_EQ(favicon, synced_favicon); 453 EXPECT_EQ(favicon, synced_favicon);
431 454
432 // Now have a new page with same favicon source but newer favicon data. 455 // Now have a new page with same favicon source but newer favicon data.
433 std::string favicon2 = "these are new icon synced_favicon"; 456 std::string favicon2 = "these are new icon synced_favicon";
434 std::string page_url2 = "http://www.faviconurl.com/page2.html"; 457 std::string page_url2 = "http://www.faviconurl.com/page2.html";
435 sync_pb::SessionTab tab2; 458 sync_pb::SessionTab tab2;
436 tab2.set_favicon(favicon2); 459 tab2.set_favicon(favicon2);
437 tab2.set_favicon_source(favicon_url); 460 tab2.set_favicon_source(favicon_url);
438 tab2.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); 461 tab2.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
439 sync_pb::TabNavigation* navigation2 = tab2.add_navigation(); 462 sync_pb::TabNavigation* navigation2 = tab2.add_navigation();
440 navigation2->set_index(0);
441 navigation2->set_virtual_url(page_url2); 463 navigation2->set_virtual_url(page_url2);
442 tab2.set_current_navigation_index(0); 464 tab2.set_current_navigation_index(0);
443 465
444 // Verify the favicons for both pages match the newest favicon. 466 // Verify the favicons for both pages match the newest favicon.
445 synced_favicon.clear(); 467 synced_favicon.clear();
446 EXPECT_FALSE(GetFavicon(page_url2, &synced_favicon)); 468 EXPECT_FALSE(GetFavicon(page_url2, &synced_favicon));
447 EXPECT_TRUE(synced_favicon.empty()); 469 EXPECT_TRUE(synced_favicon.empty());
448 LoadTabFavicon(tab2); 470 LoadTabFavicon(tab2);
449 EXPECT_TRUE(GetFavicon(page_url2, &synced_favicon)); 471 EXPECT_TRUE(GetFavicon(page_url2, &synced_favicon));
450 ASSERT_FALSE(synced_favicon.empty()); 472 ASSERT_FALSE(synced_favicon.empty());
(...skipping 12 matching lines...) Expand all
463 EXPECT_EQ(NumFavicons(), 0U); 485 EXPECT_EQ(NumFavicons(), 0U);
464 486
465 std::string double_favicon = "these are icon synced_favicon"; 487 std::string double_favicon = "these are icon synced_favicon";
466 std::string double_favicon_url = "http://www.faviconurl.com/favicon.ico"; 488 std::string double_favicon_url = "http://www.faviconurl.com/favicon.ico";
467 std::string page_url = "http://www.faviconurl.com/page.html"; 489 std::string page_url = "http://www.faviconurl.com/page.html";
468 sync_pb::SessionTab tab; 490 sync_pb::SessionTab tab;
469 tab.set_favicon(double_favicon); 491 tab.set_favicon(double_favicon);
470 tab.set_favicon_source(double_favicon_url); 492 tab.set_favicon_source(double_favicon_url);
471 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); 493 tab.set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
472 sync_pb::TabNavigation* navigation = tab.add_navigation(); 494 sync_pb::TabNavigation* navigation = tab.add_navigation();
473 navigation->set_index(0);
474 navigation->set_virtual_url(page_url); 495 navigation->set_virtual_url(page_url);
475 tab.set_current_navigation_index(0); 496 tab.set_current_navigation_index(0);
476 LoadTabFavicon(tab); 497 LoadTabFavicon(tab);
477 EXPECT_EQ(1U, NumFavicons()); 498 EXPECT_EQ(1U, NumFavicons());
478 499
479 // Add another page using the first favicon. 500 // Add another page using the first favicon.
480 std::string page_url2 = "http://www.faviconurl.com/page2.html"; 501 std::string page_url2 = "http://www.faviconurl.com/page2.html";
481 tab.mutable_navigation(0)->set_virtual_url(page_url2); 502 tab.mutable_navigation(0)->set_virtual_url(page_url2);
482 LoadTabFavicon(tab); 503 LoadTabFavicon(tab);
483 EXPECT_EQ(1U, NumFavicons()); 504 EXPECT_EQ(1U, NumFavicons());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 synced_favicon.clear(); 554 synced_favicon.clear();
534 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon)); 555 EXPECT_FALSE(GetFavicon(page_url, &synced_favicon));
535 EXPECT_TRUE(synced_favicon.empty()); 556 EXPECT_TRUE(synced_favicon.empty());
536 EXPECT_EQ(0U, NumFavicons()); 557 EXPECT_EQ(0U, NumFavicons());
537 synced_favicon.clear(); 558 synced_favicon.clear();
538 EXPECT_FALSE(GetFavicon(page_url2, &synced_favicon)); 559 EXPECT_FALSE(GetFavicon(page_url2, &synced_favicon));
539 EXPECT_TRUE(synced_favicon.empty()); 560 EXPECT_TRUE(synced_favicon.empty());
540 EXPECT_EQ(0U, NumFavicons()); 561 EXPECT_EQ(0U, NumFavicons());
541 } 562 }
542 563
564 // Ensure new tabs have all new timestamps set.
565 TEST_F(SyncSessionModelAssociatorTest, AssociateNewTab) {
566 NiceMock<SyncedWindowDelegateMock> window_mock;
567 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false));
568
569 // Create a tab with three valid entries.
570 NiceMock<SyncedTabDelegateMock> tab_mock;
571 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0));
572 scoped_ptr<content::NavigationEntry> entry1(
573 content::NavigationEntry::Create());
574 entry1->SetVirtualURL(GURL("http://www.google.com"));
575 scoped_ptr<content::NavigationEntry> entry2(
576 content::NavigationEntry::Create());
577 entry2->SetVirtualURL(GURL("http://www.noodle.com"));
578 scoped_ptr<content::NavigationEntry> entry3(
579 content::NavigationEntry::Create());
580 entry3->SetVirtualURL(GURL("http://www.doodle.com"));
581 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(2));
582 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly(
583 Return(entry1.get()));
584 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly(
585 Return(entry2.get()));
586 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly(
587 Return(entry3.get()));
588 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3));
589 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
590
591 // This tab is new, so prev_tab is the default SyncedSessionTab object.
592 SyncedSessionTab prev_tab;
593 prev_tab.tab_id.set_id(0);
594
595 sync_pb::SessionTab sync_tab;
596 GURL new_url;
597 int64 now = TimeToProtoTime(base::Time::Now());
598 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
599
600 EXPECT_EQ(new_url, entry3->GetVirtualURL());
601 ASSERT_EQ(3, sync_tab.navigation_size());
602 EXPECT_EQ(entry1->GetVirtualURL().spec(),
603 sync_tab.navigation(0).virtual_url());
604 EXPECT_EQ(entry2->GetVirtualURL().spec(),
605 sync_tab.navigation(1).virtual_url());
606 EXPECT_EQ(entry3->GetVirtualURL().spec(),
607 sync_tab.navigation(2).virtual_url());
608 EXPECT_EQ(2, sync_tab.current_navigation_index());
609 EXPECT_LE(now, sync_tab.navigation(0).timestamp());
610 EXPECT_LE(now, sync_tab.navigation(1).timestamp());
611 EXPECT_LE(now, sync_tab.navigation(2).timestamp());
612 }
613
614 // Ensure we preserve old timestamps when the entries don't change.
615 TEST_F(SyncSessionModelAssociatorTest, AssociateExistingTab) {
616 NiceMock<SyncedWindowDelegateMock> window_mock;
617 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false));
618
619 // Create a tab with three valid entries.
620 NiceMock<SyncedTabDelegateMock> tab_mock;
621 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0));
622 scoped_ptr<content::NavigationEntry> entry1(
623 content::NavigationEntry::Create());
624 entry1->SetVirtualURL(GURL("http://www.google.com"));
625 scoped_ptr<content::NavigationEntry> entry2(
626 content::NavigationEntry::Create());
627 entry2->SetVirtualURL(GURL("http://www.noodle.com"));
628 scoped_ptr<content::NavigationEntry> entry3(
629 content::NavigationEntry::Create());
630 entry3->SetVirtualURL(GURL("http://www.doodle.com"));
631 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(2));
632 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly(
633 Return(entry1.get()));
634 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly(
635 Return(entry2.get()));
636 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly(
637 Return(entry3.get()));
638 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3));
639 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
640
641 // This tab is new, so prev_tab is the default SyncedSessionTab object.
642 SyncedSessionTab prev_tab;
643 prev_tab.tab_id.set_id(0);
644
645 // The initial AssociateTabContents call builds the prev_tab.
646 sync_pb::SessionTab sync_tab;
647 GURL new_url;
648 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
649
650 // Override the timestamps to arbitrary old values we can compare against.
651 prev_tab.synced_tab_navigations[0].set_timestamp(ProtoTimeToTime(1));
652 prev_tab.synced_tab_navigations[1].set_timestamp(ProtoTimeToTime(2));
653 prev_tab.synced_tab_navigations[2].set_timestamp(ProtoTimeToTime(3));
654
655 // Now re-associate with the same data.
656 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
657
658 EXPECT_EQ(new_url, entry3->GetVirtualURL());
659 ASSERT_EQ(3, sync_tab.navigation_size());
660 EXPECT_EQ(entry1->GetVirtualURL().spec(),
661 sync_tab.navigation(0).virtual_url());
662 EXPECT_EQ(entry2->GetVirtualURL().spec(),
663 sync_tab.navigation(1).virtual_url());
664 EXPECT_EQ(entry3->GetVirtualURL().spec(),
665 sync_tab.navigation(2).virtual_url());
666 EXPECT_EQ(2, sync_tab.current_navigation_index());
667 EXPECT_EQ(1, sync_tab.navigation(0).timestamp());
668 EXPECT_EQ(2, sync_tab.navigation(1).timestamp());
669 EXPECT_EQ(3, sync_tab.navigation(2).timestamp());
670 EXPECT_EQ(3U, prev_tab.navigations.size());
671 EXPECT_EQ(3U, prev_tab.synced_tab_navigations.size());
672 }
673
674 // Ensure we add a fresh timestamp for new entries appended to the end.
675 TEST_F(SyncSessionModelAssociatorTest, AssociateAppendedTab) {
676 NiceMock<SyncedWindowDelegateMock> window_mock;
677 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false));
678
679 // Create a tab with three valid entries.
680 NiceMock<SyncedTabDelegateMock> tab_mock;
681 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0));
682 scoped_ptr<content::NavigationEntry> entry1(
683 content::NavigationEntry::Create());
684 entry1->SetVirtualURL(GURL("http://www.google.com"));
685 scoped_ptr<content::NavigationEntry> entry2(
686 content::NavigationEntry::Create());
687 entry2->SetVirtualURL(GURL("http://www.noodle.com"));
688 scoped_ptr<content::NavigationEntry> entry3(
689 content::NavigationEntry::Create());
690 entry3->SetVirtualURL(GURL("http://www.doodle.com"));
691 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(2));
692 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly(
693 Return(entry1.get()));
694 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly(
695 Return(entry2.get()));
696 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly(
697 Return(entry3.get()));
698 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3));
699 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
700
701 // This tab is new, so prev_tab is the default SyncedSessionTab object.
702 SyncedSessionTab prev_tab;
703 prev_tab.tab_id.set_id(0);
704
705 // The initial AssociateTabContents call builds the prev_tab.
706 sync_pb::SessionTab sync_tab;
707 GURL new_url;
708 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
709
710 // Override the timestamps to arbitrary old values we can compare against.
711 prev_tab.synced_tab_navigations[0].set_timestamp(ProtoTimeToTime(1));
712 prev_tab.synced_tab_navigations[1].set_timestamp(ProtoTimeToTime(2));
713 prev_tab.synced_tab_navigations[2].set_timestamp(ProtoTimeToTime(3));
714
715 // Add a new entry and change the current navigation index.
716 scoped_ptr<content::NavigationEntry> entry4(
717 content::NavigationEntry::Create());
718 entry4->SetVirtualURL(GURL("http://www.poodle.com"));
719 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly(
720 Return(entry4.get()));
721 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4));
722 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(3));
723
724 // The new entry should have a timestamp later than this.
725 int64 now = TimeToProtoTime(base::Time::Now());
726
727 // Now re-associate with the new version.
728 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
729
730 EXPECT_EQ(new_url, entry4->GetVirtualURL());
731 ASSERT_EQ(4, sync_tab.navigation_size());
732 EXPECT_EQ(entry1->GetVirtualURL().spec(),
733 sync_tab.navigation(0).virtual_url());
734 EXPECT_EQ(entry2->GetVirtualURL().spec(),
735 sync_tab.navigation(1).virtual_url());
736 EXPECT_EQ(entry3->GetVirtualURL().spec(),
737 sync_tab.navigation(2).virtual_url());
738 EXPECT_EQ(entry4->GetVirtualURL().spec(),
739 sync_tab.navigation(3).virtual_url());
740 EXPECT_EQ(3, sync_tab.current_navigation_index());
741 EXPECT_EQ(1, sync_tab.navigation(0).timestamp());
742 EXPECT_EQ(2, sync_tab.navigation(1).timestamp());
743 EXPECT_EQ(3, sync_tab.navigation(2).timestamp());
744 EXPECT_LE(now, sync_tab.navigation(3).timestamp());
745 EXPECT_EQ(4U, prev_tab.navigations.size());
746 EXPECT_EQ(4U, prev_tab.synced_tab_navigations.size());
747 }
748
749 // We shouldn't get confused when old/new entries from the previous tab have
750 // been pruned in the new tab. Timestamps for old entries we move back to in the
751 // navigation stack should be refreshed.
752 TEST_F(SyncSessionModelAssociatorTest, AssociatePrunedTab) {
753 NiceMock<SyncedWindowDelegateMock> window_mock;
754 EXPECT_CALL(window_mock, IsTabPinned(_)).WillRepeatedly(Return(false));
755
756 // Create a tab with four valid entries.
757 NiceMock<SyncedTabDelegateMock> tab_mock;
758 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0));
759 scoped_ptr<content::NavigationEntry> entry1(
760 content::NavigationEntry::Create());
761 entry1->SetVirtualURL(GURL("http://www.google.com"));
762 scoped_ptr<content::NavigationEntry> entry2(
763 content::NavigationEntry::Create());
764 entry2->SetVirtualURL(GURL("http://www.noodle.com"));
765 scoped_ptr<content::NavigationEntry> entry3(
766 content::NavigationEntry::Create());
767 entry3->SetVirtualURL(GURL("http://www.doodle.com"));
768 scoped_ptr<content::NavigationEntry> entry4(
769 content::NavigationEntry::Create());
770 entry4->SetVirtualURL(GURL("http://www.poodle.com"));
771 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(3));
772 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly(
773 Return(entry1.get()));
774 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly(
775 Return(entry2.get()));
776 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly(
777 Return(entry3.get()));
778 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly(
779 Return(entry4.get()));
780 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4));
781 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
782
783 // This tab is new, so prev_tab is the default SyncedSessionTab object.
784 SyncedSessionTab prev_tab;
785 prev_tab.tab_id.set_id(0);
786
787 // The initial AssociateTabContents call builds the prev_tab.
788 sync_pb::SessionTab sync_tab;
789 GURL new_url;
790 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
791
792 // Override the timestamps to arbitrary old values we can compare against.
793 prev_tab.synced_tab_navigations[0].set_timestamp(ProtoTimeToTime(1));
794 prev_tab.synced_tab_navigations[1].set_timestamp(ProtoTimeToTime(2));
795 prev_tab.synced_tab_navigations[2].set_timestamp(ProtoTimeToTime(3));
796 prev_tab.synced_tab_navigations[2].set_timestamp(ProtoTimeToTime(4));
797
798 // Reset new tab to have the oldest entry pruned, the current navigation
799 // set to entry3, and a new entry added in place of entry4.
800 testing::Mock::VerifyAndClearExpectations(&tab_mock);
801 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(1));
802 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly(
803 Return(entry2.get()));
804 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly(
805 Return(entry3.get()));
806 scoped_ptr<content::NavigationEntry> entry5(
807 content::NavigationEntry::Create());
808 entry5->SetVirtualURL(GURL("http://www.noogle.com"));
809 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly(
810 Return(entry5.get()));
811 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3));
812 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
813
814 // The new entry should have a timestamp later than this.
815 int64 now = TimeToProtoTime(base::Time::Now());
816
817 // Now re-associate with the new version.
818 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
819
820 // Only entry2's timestamp should be preserved. The new entry should have a
821 // new timestamp.
822 EXPECT_EQ(new_url, entry3->GetVirtualURL());
823 ASSERT_EQ(3, sync_tab.navigation_size());
824 EXPECT_EQ(entry2->GetVirtualURL().spec(),
825 sync_tab.navigation(0).virtual_url());
826 EXPECT_EQ(entry3->GetVirtualURL().spec(),
827 sync_tab.navigation(1).virtual_url());
828 EXPECT_EQ(entry5->GetVirtualURL().spec(),
829 sync_tab.navigation(2).virtual_url());
830 EXPECT_EQ(1, sync_tab.current_navigation_index());
831 EXPECT_EQ(2, sync_tab.navigation(0).timestamp());
832 EXPECT_LE(now, sync_tab.navigation(1).timestamp());
833 EXPECT_LE(now, sync_tab.navigation(2).timestamp());
834 EXPECT_EQ(3U, prev_tab.navigations.size());
835 EXPECT_EQ(3U, prev_tab.synced_tab_navigations.size());
836 }
837
543 } // namespace browser_sync 838 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_model_associator.cc ('k') | chrome/browser/sync/glue/synced_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698