summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sessions
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 20:20:09 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 20:20:09 +0000
commit5c0e648d6f4ea988be36e74cae045ba5f041e5cb (patch)
treef0fb62cf06be0ef7afa2b74babb0fe0ee7c1bc02 /chrome/browser/sessions
parent2e7054c0c76fe1c9a12de5925b7ad1a7aff94e45 (diff)
downloadchromium_src-5c0e648d6f4ea988be36e74cae045ba5f041e5cb.zip
chromium_src-5c0e648d6f4ea988be36e74cae045ba5f041e5cb.tar.gz
chromium_src-5c0e648d6f4ea988be36e74cae045ba5f041e5cb.tar.bz2
Wires up restoring pinned tabs for session and tab restore
services. And turns on pinned tabs by default on linux. BUG=16634 TEST=Currently this linux only. Try tab pinning and make sure it works. Review URL: http://codereview.chromium.org/149621 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r--chrome/browser/sessions/session_restore.cc6
-rw-r--r--chrome/browser/sessions/session_service.cc48
-rw-r--r--chrome/browser/sessions/session_service.h12
-rw-r--r--chrome/browser/sessions/session_service_unittest.cc49
-rw-r--r--chrome/browser/sessions/session_types.h8
-rw-r--r--chrome/browser/sessions/tab_restore_service.cc36
-rw-r--r--chrome/browser/sessions/tab_restore_service.h6
-rw-r--r--chrome/browser/sessions/tab_restore_service_unittest.cc102
8 files changed, 245 insertions, 22 deletions
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc
index 9e88f42..871d256 100644
--- a/chrome/browser/sessions/session_restore.cc
+++ b/chrome/browser/sessions/session_restore.cc
@@ -327,7 +327,8 @@ class SessionRestoreImpl : public NotificationObserver {
&browser->AddRestoredTab(tab.navigations,
static_cast<int>(i - window.tabs.begin()),
selected_index,
- false)->controller());
+ false,
+ tab.pinned)->controller());
}
}
@@ -362,7 +363,8 @@ class SessionRestoreImpl : public NotificationObserver {
void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) {
SessionService* session_service = profile_->GetSessionService();
for (int i = initial_count; i < browser->tab_count(); ++i)
- session_service->TabRestored(&browser->GetTabContentsAt(i)->controller());
+ session_service->TabRestored(&browser->GetTabContentsAt(i)->controller(),
+ browser->tabstrip_model()->IsTabPinned(i));
}
// The profile to create the sessions for.
diff --git a/chrome/browser/sessions/session_service.cc b/chrome/browser/sessions/session_service.cc
index 33a5e6f..0a9c630 100644
--- a/chrome/browser/sessions/session_service.cc
+++ b/chrome/browser/sessions/session_service.cc
@@ -48,6 +48,7 @@ static const SessionCommand::id_type kCommandSetWindowType = 9;
static const SessionCommand::id_type kCommandSetWindowBounds2 = 10;
static const SessionCommand::id_type
kCommandTabNavigationPathPrunedFromFront = 11;
+static const SessionCommand::id_type kCommandSetPinnedState = 12;
// Every kWritesPerReset commands triggers recreating the file.
static const int kWritesPerReset = 250;
@@ -107,6 +108,11 @@ typedef IDAndIndexPayload WindowTypePayload;
typedef IDAndIndexPayload TabNavigationPathPrunedFromFrontPayload;
+struct PinnedStatePayload {
+ SessionID::id_type tab_id;
+ bool pinned_state;
+};
+
} // namespace
// SessionService -------------------------------------------------------------
@@ -175,6 +181,15 @@ void SessionService::SetTabIndexInWindow(const SessionID& window_id,
ScheduleCommand(CreateSetTabIndexInWindowCommand(tab_id, new_index));
}
+void SessionService::SetPinnedState(const SessionID& window_id,
+ const SessionID& tab_id,
+ bool is_pinned) {
+ if (!ShouldTrackChangesToWindow(window_id))
+ return;
+
+ ScheduleCommand(CreatePinnedStateCommand(tab_id, is_pinned));
+}
+
void SessionService::TabClosed(const SessionID& window_id,
const SessionID& tab_id) {
if (!ShouldTrackChangesToWindow(window_id))
@@ -320,12 +335,13 @@ void SessionService::UpdateTabNavigation(const SessionID& window_id,
tab_id.id(), index, entry));
}
-void SessionService::TabRestored(NavigationController* controller) {
+void SessionService::TabRestored(NavigationController* controller,
+ bool pinned) {
if (!ShouldTrackChangesToWindow(controller->window_id()))
return;
BuildCommandsForTab(controller->window_id(), controller, -1,
- &pending_commands(), NULL);
+ pinned, &pending_commands(), NULL);
StartSaveTimer();
}
@@ -562,7 +578,7 @@ SessionCommand* SessionService::CreateSetSelectedNavigationIndexCommand(
SessionCommand* SessionService::CreateSetWindowTypeCommand(
const SessionID& window_id,
Browser::Type type) {
- WindowTypePayload payload = { 0 };
+ WindowTypePayload payload = { 0 };
payload.id = window_id.id();
payload.index = static_cast<int32>(type);
SessionCommand* command = new SessionCommand(
@@ -571,6 +587,18 @@ SessionCommand* SessionService::CreateSetWindowTypeCommand(
return command;
}
+SessionCommand* SessionService::CreatePinnedStateCommand(
+ const SessionID& tab_id,
+ bool is_pinned) {
+ PinnedStatePayload payload = { 0 };
+ payload.tab_id = tab_id.id();
+ payload.pinned_state = is_pinned;
+ SessionCommand* command =
+ new SessionCommand(kCommandSetPinnedState, sizeof(payload));
+ memcpy(command->contents(), &payload, sizeof(payload));
+ return command;
+}
+
void SessionService::OnGotLastSessionCommands(
Handle handle,
scoped_refptr<InternalGetCommandsRequest> request) {
@@ -863,6 +891,14 @@ bool SessionService::CreateTabsAndWindows(
break;
}
+ case kCommandSetPinnedState: {
+ PinnedStatePayload payload;
+ if (!command->GetPayload(&payload, sizeof(payload)))
+ return true;
+ GetTab(payload.tab_id, tabs)->pinned = payload.pinned_state;
+ break;
+ }
+
default:
return true;
}
@@ -874,6 +910,7 @@ void SessionService::BuildCommandsForTab(
const SessionID& window_id,
NavigationController* controller,
int index_in_window,
+ bool is_pinned,
std::vector<SessionCommand*>* commands,
IdToRange* tab_to_available_range) {
DCHECK(controller && commands && window_id.id());
@@ -889,6 +926,10 @@ void SessionService::BuildCommandsForTab(
(*tab_to_available_range)[controller->session_id().id()] =
std::pair<int, int>(min_index, max_index);
}
+ if (is_pinned) {
+ commands->push_back(
+ CreatePinnedStateCommand(controller->session_id(), true));
+ }
for (int i = min_index; i < max_index; ++i) {
const NavigationEntry* entry = (i == pending_index) ?
controller->pending_entry() : controller->GetEntryAtIndex(i);
@@ -934,6 +975,7 @@ void SessionService::BuildCommandsForBrowser(
DCHECK(tab);
if (tab->profile() == profile()) {
BuildCommandsForTab(browser->session_id(), &tab->controller(), i,
+ browser->tabstrip_model()->IsTabPinned(i),
commands, tab_to_available_range);
if (windows_to_track && !added_to_windows_to_track) {
windows_to_track->insert(browser->session_id().id());
diff --git a/chrome/browser/sessions/session_service.h b/chrome/browser/sessions/session_service.h
index 577981d..b3daf22 100644
--- a/chrome/browser/sessions/session_service.h
+++ b/chrome/browser/sessions/session_service.h
@@ -75,6 +75,11 @@ class SessionService : public BaseSessionService,
const SessionID& tab_id,
int new_index);
+ // Sets the pinned state of the tab.
+ void SetPinnedState(const SessionID& window_id,
+ const SessionID& tab_id,
+ bool is_pinned);
+
// Notification that a tab has been closed.
//
// Note: this is invoked from the NavigationController's destructor, which is
@@ -112,7 +117,8 @@ class SessionService : public BaseSessionService,
// Notification that a tab has restored its entries or a closed tab is being
// reused.
- void TabRestored(NavigationController* controller);
+ void TabRestored(NavigationController* controller,
+ bool pinned);
// Sets the index of the selected entry in the navigation controller for the
// specified tab.
@@ -179,6 +185,9 @@ class SessionService : public BaseSessionService,
SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id,
Browser::Type type);
+ SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id,
+ bool is_pinned);
+
// Callback form the backend for getting the commands from the previous
// or save file. Converts the commands in SessionWindows and notifies
// the real callback.
@@ -253,6 +262,7 @@ class SessionService : public BaseSessionService,
const SessionID& window_id,
NavigationController* controller,
int index_in_window,
+ bool is_pinned,
std::vector<SessionCommand*>* commands,
IdToRange* tab_to_available_range);
diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc
index baafd90..19997e7 100644
--- a/chrome/browser/sessions/session_service_unittest.cc
+++ b/chrome/browser/sessions/session_service_unittest.cc
@@ -71,6 +71,40 @@ class SessionServiceTest : public testing::Test {
helper_.ReadWindows(windows);
}
+ // Configures the session service with one window with one tab and a single
+ // navigation. If |pinned_state| is true or |write_always| is true, the
+ // pinned state of the tab is updated. The session service is then recreated
+ // and the pinned state of the read back tab is returned.
+ bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) {
+ SessionID tab_id;
+
+ TabNavigation nav1(0, GURL("http://google.com"),
+ GURL("http://www.referrer.com"),
+ ASCIIToUTF16("abc"), "def",
+ PageTransition::QUALIFIER_MASK);
+
+ helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
+ UpdateNavigation(window_id, tab_id, nav1, 0, true);
+
+ if (pinned_state || write_always)
+ helper_.service()->SetPinnedState(window_id, tab_id, pinned_state);
+
+ ScopedVector<SessionWindow> windows;
+ ReadWindows(&(windows.get()));
+
+ EXPECT_EQ(1U, windows->size());
+ if (HasFatalFailure())
+ return false;
+ EXPECT_EQ(1U, windows[0]->tabs.size());
+ if (HasFatalFailure())
+ return false;
+
+ SessionTab* tab = windows[0]->tabs[0];
+ helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
+
+ return tab->pinned;
+ }
+
SessionService* service() { return helper_.service(); }
SessionBackend* backend() { return helper_.backend(); }
@@ -455,3 +489,18 @@ TEST_F(SessionServiceTest, PruneToEmpty) {
ASSERT_EQ(0U, windows->size());
}
+
+// Don't set the pinned state and make sure the pinned value is false.
+TEST_F(SessionServiceTest, PinnedDefaultsToFalse) {
+ EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, false));
+}
+
+// Explicitly set the pinned state to false and make sure we get back false.
+TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) {
+ EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, true));
+}
+
+// Explicitly set the pinned state to false and make sure we get back true.
+TEST_F(SessionServiceTest, PinnedTrue) {
+ EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true));
+}
diff --git a/chrome/browser/sessions/session_types.h b/chrome/browser/sessions/session_types.h
index 31cde3b..5841810 100644
--- a/chrome/browser/sessions/session_types.h
+++ b/chrome/browser/sessions/session_types.h
@@ -106,7 +106,10 @@ class TabNavigation {
// SessionTab corresponds to a NavigationController.
struct SessionTab {
- SessionTab() : tab_visual_index(-1), current_navigation_index(-1) { }
+ SessionTab()
+ : tab_visual_index(-1),
+ current_navigation_index(-1),
+ pinned(false) { }
// Unique id of the window.
SessionID window_id;
@@ -130,6 +133,9 @@ struct SessionTab {
// creating though, this is set to the index in navigations.
int current_navigation_index;
+ // True if the tab is pinned.
+ bool pinned;
+
std::vector<TabNavigation> navigations;
private:
diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc
index 4bbd660..fc44204 100644
--- a/chrome/browser/sessions/tab_restore_service.cc
+++ b/chrome/browser/sessions/tab_restore_service.cc
@@ -38,8 +38,9 @@ const size_t TabRestoreService::kMaxEntries = 10;
// The ordering in the file is as follows:
// . When the user closes a tab a command of type
// kCommandSelectedNavigationInTab is written identifying the tab and
-// the selected index. This is followed by any number of
-// kCommandUpdateTabNavigation commands (1 per navigation entry).
+// the selected index, then a kCommandPinnedState command if the tab was
+// pinned. This is followed by any number of kCommandUpdateTabNavigation
+// commands (1 per navigation entry).
// . When the user closes a window a kCommandSelectedNavigationInTab command
// is written out and followed by n tab closed sequences (as previoulsy
// described).
@@ -49,6 +50,7 @@ static const SessionCommand::id_type kCommandUpdateTabNavigation = 1;
static const SessionCommand::id_type kCommandRestoredEntry = 2;
static const SessionCommand::id_type kCommandWindow = 3;
static const SessionCommand::id_type kCommandSelectedNavigationInTab = 4;
+static const SessionCommand::id_type kCommandPinnedState = 5;
// Number of entries (not commands) before we clobber the file and write
// everything.
@@ -73,6 +75,9 @@ struct SelectedNavigationInTabPayload {
int32 index;
};
+// Only written if the tab is pinned.
+typedef bool PinnedStatePayload;
+
typedef std::map<SessionID::id_type, TabRestoreService::Entry*> IDToEntry;
// If |id_to_entry| contains an entry for |id| the corresponding entry is
@@ -248,7 +253,8 @@ void TabRestoreService::RestoreEntryById(Browser* browser,
if (tab_index < 0 || tab_index > tab_browser->tab_count())
tab_index = tab_browser->tab_count();
tab_browser->AddRestoredTab(tab->navigations, tab_index,
- tab->current_navigation_index, true);
+ tab->current_navigation_index, true,
+ tab->pinned);
}
} else if (entry->type == WINDOW) {
const Window* window = static_cast<Window*>(entry);
@@ -259,7 +265,8 @@ void TabRestoreService::RestoreEntryById(Browser* browser,
browser->AddRestoredTab(tab.navigations, browser->tab_count(),
tab.current_navigation_index,
(static_cast<int>(tab_i) ==
- window->selected_tab_index));
+ window->selected_tab_index),
+ tab.pinned);
if (restored_tab)
restored_tab->controller().LoadIfNecessary();
}
@@ -360,6 +367,7 @@ void TabRestoreService::PopulateTab(Tab* tab,
tab->browser_id = browser->session_id().id();
tab->tabstrip_index =
browser->tabstrip_model()->GetIndexOfController(controller);
+ tab->pinned = browser->tabstrip_model()->IsTabPinned(tab->tabstrip_index);
}
}
@@ -446,6 +454,14 @@ void TabRestoreService::ScheduleCommandsForTab(const Tab& tab,
CreateSelectedNavigationInTabCommand(tab.id,
valid_count_before_selected));
+ if (tab.pinned) {
+ PinnedStatePayload payload = true;
+ SessionCommand* command =
+ new SessionCommand(kCommandPinnedState, sizeof(payload));
+ memcpy(command->contents(), &payload, sizeof(payload));
+ ScheduleCommand(command);
+ }
+
// Then write the navigations.
for (int i = first_index_to_persist, wrote_count = 0;
i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) {
@@ -636,6 +652,17 @@ void TabRestoreService::CreateEntriesFromCommands(
break;
}
+ case kCommandPinnedState: {
+ if (!current_tab) {
+ // Should be in a tab when we get this.
+ return;
+ }
+ // NOTE: payload doesn't matter. kCommandPinnedState is only written if
+ // tab is pinned.
+ current_tab->pinned = true;
+ break;
+ }
+
default:
// Unknown type, usually indicates corruption of file. Ignore it.
return;
@@ -744,6 +771,7 @@ bool TabRestoreService::ConvertSessionWindowToWindow(
if (!session_window->tabs[i]->navigations.empty()) {
window->tabs.resize(window->tabs.size() + 1);
Tab& tab = window->tabs.back();
+ tab.pinned = session_window->tabs[i]->pinned;
tab.navigations.swap(session_window->tabs[i]->navigations);
tab.current_navigation_index =
session_window->tabs[i]->current_navigation_index;
diff --git a/chrome/browser/sessions/tab_restore_service.h b/chrome/browser/sessions/tab_restore_service.h
index a74f335..1c28da8 100644
--- a/chrome/browser/sessions/tab_restore_service.h
+++ b/chrome/browser/sessions/tab_restore_service.h
@@ -67,7 +67,8 @@ class TabRestoreService : public BaseSessionService {
: Entry(TAB),
current_navigation_index(-1),
browser_id(0),
- tabstrip_index(-1) {}
+ tabstrip_index(-1),
+ pinned(false) {}
bool has_browser() const { return browser_id > 0; }
@@ -83,6 +84,9 @@ class TabRestoreService : public BaseSessionService {
// Index within the tab strip. May be -1 for an unknown index.
int tabstrip_index;
+
+ // True if the tab was pinned.
+ bool pinned;
};
// Represents a previously open window.
diff --git a/chrome/browser/sessions/tab_restore_service_unittest.cc b/chrome/browser/sessions/tab_restore_service_unittest.cc
index 97fceff..72ce546 100644
--- a/chrome/browser/sessions/tab_restore_service_unittest.cc
+++ b/chrome/browser/sessions/tab_restore_service_unittest.cc
@@ -55,7 +55,8 @@ class TabRestoreServiceTest : public RenderViewHostTestHarness {
}
// Adds a window with one tab and url to the profile's session service.
- void AddWindowWithOneTabToSessionService() {
+ // If |pinned| is true, the tab is marked as pinned in the session service.
+ void AddWindowWithOneTabToSessionService(bool pinned) {
SessionService* session_service = profile()->GetSessionService();
SessionID tab_id;
SessionID window_id;
@@ -63,6 +64,8 @@ class TabRestoreServiceTest : public RenderViewHostTestHarness {
session_service->SetTabWindow(window_id, tab_id);
session_service->SetTabIndexInWindow(window_id, tab_id, 0);
session_service->SetSelectedTabInWindow(window_id, 0);
+ if (pinned)
+ session_service->SetPinnedState(window_id, tab_id, true);
NavigationEntry entry;
entry.set_url(url1_);
session_service->UpdateTabNavigation(window_id, tab_id, 0, entry);
@@ -70,13 +73,14 @@ class TabRestoreServiceTest : public RenderViewHostTestHarness {
// Creates a SessionService and assigns it to the Profile. The SessionService
// is configured with a single window with a single tab pointing at url1_ by
- // way of AddWindowWithOneTabToSessionService.
- void CreateSessionServiceWithOneWindow() {
+ // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the
+ // tab is marked as pinned in the session service.
+ void CreateSessionServiceWithOneWindow(bool pinned) {
// The profile takes ownership of this.
SessionService* session_service = new SessionService(profile());
profile()->set_session_service(session_service);
- AddWindowWithOneTabToSessionService();
+ AddWindowWithOneTabToSessionService(pinned);
// Set this, otherwise previous session won't be loaded.
profile()->set_last_session_exited_cleanly(false);
@@ -101,6 +105,7 @@ TEST_F(TabRestoreServiceTest, Basic) {
TabRestoreService::Entry* entry = service_->entries().front();
ASSERT_EQ(TabRestoreService::TAB, entry->type);
TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry);
+ EXPECT_FALSE(tab->pinned);
ASSERT_EQ(3U, tab->navigations.size());
EXPECT_TRUE(url1_ == tab->navigations[0].url());
EXPECT_TRUE(url2_ == tab->navigations[1].url());
@@ -119,6 +124,7 @@ TEST_F(TabRestoreServiceTest, Basic) {
entry = service_->entries().front();
ASSERT_EQ(TabRestoreService::TAB, entry->type);
tab = static_cast<TabRestoreService::Tab*>(entry);
+ EXPECT_FALSE(tab->pinned);
ASSERT_EQ(3U, tab->navigations.size());
EXPECT_TRUE(url1_ == tab->navigations[0].url());
EXPECT_TRUE(url2_ == tab->navigations[1].url());
@@ -150,6 +156,42 @@ TEST_F(TabRestoreServiceTest, Restore) {
TabRestoreService::Entry* entry = service_->entries().front();
ASSERT_EQ(TabRestoreService::TAB, entry->type);
TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry);
+ EXPECT_FALSE(tab->pinned);
+ ASSERT_EQ(3U, tab->navigations.size());
+ EXPECT_TRUE(url1_ == tab->navigations[0].url());
+ EXPECT_TRUE(url2_ == tab->navigations[1].url());
+ EXPECT_TRUE(url3_ == tab->navigations[2].url());
+ EXPECT_EQ(2, tab->current_navigation_index);
+}
+
+// Tests restoring a single pinned tab.
+TEST_F(TabRestoreServiceTest, RestorePinned) {
+ AddThreeNavigations();
+
+ // Have the service record the tab.
+ service_->CreateHistoricalTab(&controller());
+
+ // One entry should be created.
+ ASSERT_EQ(1U, service_->entries().size());
+
+ // We have to explicitly mark the tab as pinned as there is no browser for
+ // these tests.
+ TabRestoreService::Entry* entry = service_->entries().front();
+ ASSERT_EQ(TabRestoreService::TAB, entry->type);
+ TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry);
+ tab->pinned = true;
+
+ // Recreate the service and have it load the tabs.
+ RecreateService();
+
+ // One entry should be created.
+ ASSERT_EQ(1U, service_->entries().size());
+
+ // And verify the entry.
+ entry = service_->entries().front();
+ ASSERT_EQ(TabRestoreService::TAB, entry->type);
+ tab = static_cast<TabRestoreService::Tab*>(entry);
+ EXPECT_TRUE(tab->pinned);
ASSERT_EQ(3U, tab->navigations.size());
EXPECT_TRUE(url1_ == tab->navigations[0].url());
EXPECT_TRUE(url2_ == tab->navigations[1].url());
@@ -204,7 +246,7 @@ TEST_F(TabRestoreServiceTest, DontLoadTwice) {
// Makes sure we load the previous session as necessary.
TEST_F(TabRestoreServiceTest, LoadPreviousSession) {
- CreateSessionServiceWithOneWindow();
+ CreateSessionServiceWithOneWindow(false);
profile()->GetSessionService()->MoveCurrentSessionToLastSession();
@@ -225,7 +267,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSession) {
// Makes sure we don't attempt to load previous sessions after a restore.
TEST_F(TabRestoreServiceTest, DontLoadAfterRestore) {
- CreateSessionServiceWithOneWindow();
+ CreateSessionServiceWithOneWindow(false);
profile()->GetSessionService()->MoveCurrentSessionToLastSession();
@@ -239,7 +281,7 @@ TEST_F(TabRestoreServiceTest, DontLoadAfterRestore) {
// Makes sure we don't attempt to load previous sessions after a clean exit.
TEST_F(TabRestoreServiceTest, DontLoadAfterCleanExit) {
- CreateSessionServiceWithOneWindow();
+ CreateSessionServiceWithOneWindow(false);
profile()->GetSessionService()->MoveCurrentSessionToLastSession();
@@ -251,7 +293,45 @@ TEST_F(TabRestoreServiceTest, DontLoadAfterCleanExit) {
}
TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) {
- CreateSessionServiceWithOneWindow();
+ CreateSessionServiceWithOneWindow(false);
+
+ profile()->GetSessionService()->MoveCurrentSessionToLastSession();
+
+ AddThreeNavigations();
+
+ service_->CreateHistoricalTab(&controller());
+
+ RecreateService();
+
+ // We should get back two entries, one from the previous session and one from
+ // the tab restore service. The previous session entry should be first.
+ ASSERT_EQ(2U, service_->entries().size());
+ // The first entry should come from the session service.
+ TabRestoreService::Entry* entry = service_->entries().front();
+ ASSERT_EQ(TabRestoreService::WINDOW, entry->type);
+ TabRestoreService::Window* window =
+ static_cast<TabRestoreService::Window*>(entry);
+ ASSERT_EQ(1U, window->tabs.size());
+ EXPECT_EQ(0, window->selected_tab_index);
+ ASSERT_EQ(1U, window->tabs[0].navigations.size());
+ EXPECT_EQ(0, window->tabs[0].current_navigation_index);
+ EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url());
+
+ // Then the closed tab.
+ entry = *(++service_->entries().begin());
+ ASSERT_EQ(TabRestoreService::TAB, entry->type);
+ TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry);
+ ASSERT_FALSE(tab->pinned);
+ ASSERT_EQ(3U, tab->navigations.size());
+ EXPECT_EQ(2, tab->current_navigation_index);
+ EXPECT_TRUE(url1_ == tab->navigations[0].url());
+ EXPECT_TRUE(url2_ == tab->navigations[1].url());
+ EXPECT_TRUE(url3_ == tab->navigations[2].url());
+}
+
+// Make sure pinned state is correctly loaded from session service.
+TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) {
+ CreateSessionServiceWithOneWindow(true);
profile()->GetSessionService()->MoveCurrentSessionToLastSession();
@@ -271,6 +351,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) {
static_cast<TabRestoreService::Window*>(entry);
ASSERT_EQ(1U, window->tabs.size());
EXPECT_EQ(0, window->selected_tab_index);
+ EXPECT_TRUE(window->tabs[0].pinned);
ASSERT_EQ(1U, window->tabs[0].navigations.size());
EXPECT_EQ(0, window->tabs[0].current_navigation_index);
EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url());
@@ -279,6 +360,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) {
entry = *(++service_->entries().begin());
ASSERT_EQ(TabRestoreService::TAB, entry->type);
TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry);
+ ASSERT_FALSE(tab->pinned);
ASSERT_EQ(3U, tab->navigations.size());
EXPECT_EQ(2, tab->current_navigation_index);
EXPECT_TRUE(url1_ == tab->navigations[0].url());
@@ -289,10 +371,10 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) {
// Creates TabRestoreService::kMaxEntries + 1 windows in the session service
// and makes sure we only get back TabRestoreService::kMaxEntries on restore.
TEST_F(TabRestoreServiceTest, ManyWindowsInSessionService) {
- CreateSessionServiceWithOneWindow();
+ CreateSessionServiceWithOneWindow(false);
for (size_t i = 0; i < TabRestoreService::kMaxEntries; ++i)
- AddWindowWithOneTabToSessionService();
+ AddWindowWithOneTabToSessionService(false);
profile()->GetSessionService()->MoveCurrentSessionToLastSession();