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

Side by Side Diff: components/sync_sessions/synced_session_tracker_unittest.cc

Issue 2791183003: [Sync] Restore previous session if no tabbed windows present (Closed)
Patch Set: Fix android compile Created 3 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/sync_sessions/synced_session_tracker.h" 5 #include "components/sync_sessions/synced_session_tracker.h"
6 6
7 #include "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" 10 #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 TEST_F(SyncedSessionTrackerTest, GetTabUnmapped) { 54 TEST_F(SyncedSessionTrackerTest, GetTabUnmapped) {
55 sessions::SessionTab* tab = GetTracker()->GetTab(kTag, 0); 55 sessions::SessionTab* tab = GetTracker()->GetTab(kTag, 0);
56 ASSERT_EQ(tab, GetTracker()->GetTab(kTag, 0)); 56 ASSERT_EQ(tab, GetTracker()->GetTab(kTag, 0));
57 // Should clean up memory on its own. 57 // Should clean up memory on its own.
58 } 58 }
59 59
60 TEST_F(SyncedSessionTrackerTest, PutWindowInSession) { 60 TEST_F(SyncedSessionTrackerTest, PutWindowInSession) {
61 GetTracker()->PutWindowInSession(kTag, 0); 61 GetTracker()->PutWindowInSession(kTag, 0);
62 SyncedSession* session = GetTracker()->GetSession(kTag); 62 SyncedSession* session = GetTracker()->GetSession(kTag);
63 ASSERT_EQ(1U, session->windows.size()); 63 ASSERT_EQ(1U, session->windows.size());
64
65 // Doing it again should have no effect.
66 GetTracker()->PutWindowInSession(kTag, 0);
67 ASSERT_EQ(1U, session->windows.size());
64 // Should clean up memory on its own. 68 // Should clean up memory on its own.
65 } 69 }
66 70
67 TEST_F(SyncedSessionTrackerTest, PutTabInWindow) { 71 TEST_F(SyncedSessionTrackerTest, PutTabInWindow) {
68 GetTracker()->PutWindowInSession(kTag, 10); 72 GetTracker()->PutWindowInSession(kTag, 10);
69 GetTracker()->PutTabInWindow(kTag, 10, 15); // win id 10, tab id 15 73 GetTracker()->PutTabInWindow(kTag, 10, 15); // win id 10, tab id 15
70 SyncedSession* session = GetTracker()->GetSession(kTag); 74 SyncedSession* session = GetTracker()->GetSession(kTag);
71 ASSERT_EQ(1U, session->windows.size()); 75 ASSERT_EQ(1U, session->windows.size());
72 ASSERT_EQ(1U, session->windows[10]->wrapped_window.tabs.size()); 76 ASSERT_EQ(1U, session->windows[10]->wrapped_window.tabs.size());
73 ASSERT_EQ(GetTracker()->GetTab(kTag, 15), 77 ASSERT_EQ(GetTracker()->GetTab(kTag, 15),
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 GetTracker()->ResetSessionTracking(kTag); 321 GetTracker()->ResetSessionTracking(kTag);
318 GetTracker()->PutWindowInSession(kTag, 0); 322 GetTracker()->PutWindowInSession(kTag, 0);
319 GetTracker()->PutTabInWindow(kTag, 0, 0); 323 GetTracker()->PutTabInWindow(kTag, 0, 0);
320 // Tab 1 is closed. 324 // Tab 1 is closed.
321 GetTracker()->PutTabInWindow(kTag, 0, 2); // No longer unmapped. 325 GetTracker()->PutTabInWindow(kTag, 0, 2); // No longer unmapped.
322 // Tab 3 was unmapped and does not get used. 326 // Tab 3 was unmapped and does not get used.
323 GetTracker()->PutTabInWindow(kTag, 0, 4); // Moved from window 1. 327 GetTracker()->PutTabInWindow(kTag, 0, 4); // Moved from window 1.
324 // Window 1 was closed, along with tab 5. 328 // Window 1 was closed, along with tab 5.
325 GetTracker()->PutTabInWindow(kTag, 0, 6); // No longer unmapped. 329 GetTracker()->PutTabInWindow(kTag, 0, 6); // No longer unmapped.
326 // Session 2 should not be affected. 330 // Session 2 should not be affected.
327 GetTracker()->CleanupForeignSession(kTag); 331 GetTracker()->CleanupSession(kTag);
328 332
329 // Verify that only those parts of the session not owned have been removed. 333 // Verify that only those parts of the session not owned have been removed.
330 ASSERT_EQ(1U, session1->windows.size()); 334 ASSERT_EQ(1U, session1->windows.size());
331 ASSERT_EQ(4U, session1->windows[0]->wrapped_window.tabs.size()); 335 ASSERT_EQ(4U, session1->windows[0]->wrapped_window.tabs.size());
332 ASSERT_EQ(1U, session2->windows.size()); 336 ASSERT_EQ(1U, session2->windows.size());
333 ASSERT_EQ(1U, session2->windows[2]->wrapped_window.tabs.size()); 337 ASSERT_EQ(1U, session2->windows[2]->wrapped_window.tabs.size());
334 ASSERT_EQ(2U, GetTracker()->num_synced_sessions()); 338 ASSERT_EQ(2U, GetTracker()->num_synced_sessions());
335 ASSERT_EQ(4U, GetTracker()->num_synced_tabs(kTag)); 339 ASSERT_EQ(4U, GetTracker()->num_synced_tabs(kTag));
336 ASSERT_EQ(1U, GetTracker()->num_synced_tabs(kTag2)); 340 ASSERT_EQ(1U, GetTracker()->num_synced_tabs(kTag2));
337 341
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 // Now that it's been mapped, it should be accessible both via the 557 // Now that it's been mapped, it should be accessible both via the
554 // GetSession as well as GetTab. 558 // GetSession as well as GetTab.
555 SyncedSession* session = GetTracker()->GetSession(kTag); 559 SyncedSession* session = GetTracker()->GetSession(kTag);
556 ASSERT_EQ(GetTracker()->GetTab(kTag, kTab2), 560 ASSERT_EQ(GetTracker()->GetTab(kTag, kTab2),
557 session->windows[kWindow1]->wrapped_window.tabs[0].get()); 561 session->windows[kWindow1]->wrapped_window.tabs[0].get());
558 ASSERT_EQ(session->tab_node_ids.size(), 562 ASSERT_EQ(session->tab_node_ids.size(),
559 session->tab_node_ids.count(kTabNode)); 563 session->tab_node_ids.count(kTabNode));
560 ASSERT_EQ(1U, GetTabNodePool()->Capacity()); 564 ASSERT_EQ(1U, GetTabNodePool()->Capacity());
561 } 565 }
562 566
567 TEST_F(SyncedSessionTrackerTest, ReassociateTabMapMismatch) {
568 std::set<int> free_node_ids;
569
570 // First create the old tab in an unmapped state.
571 GetTracker()->SetLocalSessionTag(kTag);
572 EXPECT_FALSE(GetTracker()->IsLocalTabNodeAssociated(kTabNode));
573 GetTracker()->ReassociateLocalTab(kTabNode, kTab1);
574 EXPECT_TRUE(GetTracker()->IsLocalTabNodeAssociated(kTabNode));
575 EXPECT_TRUE(GetTracker()->IsTabUnmappedForTesting(kTab1));
576
577 // Map an unseen tab to a window, then reassociate the existing tab to the
578 // mapped tab id.
579 GetTracker()->ResetSessionTracking(kTag);
580 EXPECT_TRUE(GetTracker()->IsLocalTabNodeAssociated(kTabNode));
581 GetTracker()->PutWindowInSession(kTag, kWindow1);
582 GetTracker()->PutTabInWindow(kTag, kWindow1, kTab2);
583 GetTracker()->CleanupLocalTabs(&free_node_ids);
584 EXPECT_FALSE(GetTracker()->IsTabUnmappedForTesting(kTab1));
585 EXPECT_FALSE(GetTracker()->IsTabUnmappedForTesting(kTab2));
586 GetTracker()->ReassociateLocalTab(kTabNode, kTab2);
587 EXPECT_TRUE(free_node_ids.empty());
588 EXPECT_FALSE(GetTracker()->IsTabUnmappedForTesting(kTab1));
589 EXPECT_FALSE(GetTracker()->IsTabUnmappedForTesting(kTab2));
590
591 // Now that it's been mapped, it should be accessible both via the
592 // GetSession as well as GetTab.
593 SyncedSession* session = GetTracker()->GetSession(kTag);
594 ASSERT_EQ(GetTracker()->GetTab(kTag, kTab2),
595 session->windows[kWindow1]->wrapped_window.tabs[0].get());
596 ASSERT_EQ(session->tab_node_ids.size(),
597 session->tab_node_ids.count(kTabNode));
598 ASSERT_EQ(1U, GetTabNodePool()->Capacity());
599 }
600
563 } // namespace sync_sessions 601 } // namespace sync_sessions
OLDNEW
« no previous file with comments | « components/sync_sessions/synced_session_tracker.cc ('k') | ios/chrome/browser/sync/ios_chrome_synced_tab_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698