summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sessions/session_backend_unittest.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 18:27:34 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 18:27:34 +0000
commita1cf60700c1e9bdb06c4cc7a4770231ba63e3c41 (patch)
treeb4c43f9aa4f1b045fd5088168ddff450a04c7307 /chrome/browser/sessions/session_backend_unittest.cc
parent56e72f3fcac8fbf6a9694a10db9cfb8e0b0a0b82 (diff)
downloadchromium_src-a1cf60700c1e9bdb06c4cc7a4770231ba63e3c41.zip
chromium_src-a1cf60700c1e9bdb06c4cc7a4770231ba63e3c41.tar.gz
chromium_src-a1cf60700c1e9bdb06c4cc7a4770231ba63e3c41.tar.bz2
Fixes possible crash in SessionBackend. I believe what's happening
here is we fail to create the file, and so current_session_file_.get() is NULL and we crash. current_session_file_.get() is NULL if OpenAndWriteHeader returns NULL (which is does if the full header isn't written correctly. Here's how I'm changing the code: . The file is now truncated instead of closed/reopened. Hopefully this avoids the possibility of a scanner locking the file and the delete failing. . Added a unit test for coverage of truncation. . The file is opened in exclusive access. There is no reason why a scanner should open this file. . Added null checks. BUG=8476 TEST=none Review URL: http://codereview.chromium.org/39275 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions/session_backend_unittest.cc')
-rw-r--r--chrome/browser/sessions/session_backend_unittest.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/chrome/browser/sessions/session_backend_unittest.cc b/chrome/browser/sessions/session_backend_unittest.cc
index fb424f2..e5ba17d4 100644
--- a/chrome/browser/sessions/session_backend_unittest.cc
+++ b/chrome/browser/sessions/session_backend_unittest.cc
@@ -180,3 +180,32 @@ TEST_F(SessionBackendTest, EmptyCommand) {
AssertCommandEqualsData(empty_command, commands[0]);
STLDeleteElements(&commands);
}
+
+// Writes a command, appends another command with reset to true, then reads
+// making sure we only get back the second command.
+TEST_F(SessionBackendTest, Truncate) {
+ scoped_refptr<SessionBackend> backend(
+ new SessionBackend(BaseSessionService::SESSION_RESTORE, path_));
+ struct TestData first_data = { 1, "a" };
+ std::vector<SessionCommand*> commands;
+ commands.push_back(CreateCommandFromData(first_data));
+ backend->AppendCommands(new SessionCommands(commands), false);
+ commands.clear();
+
+ // Write another command, this time resetting the file when appending.
+ struct TestData second_data = { 2, "b" };
+ commands.push_back(CreateCommandFromData(second_data));
+ backend->AppendCommands(new SessionCommands(commands), true);
+ commands.clear();
+
+ // Read it back in.
+ backend = NULL;
+ backend = new SessionBackend(BaseSessionService::SESSION_RESTORE, path_);
+ backend->ReadLastSessionCommandsImpl(&commands);
+
+ // And make sure we get back the expected data.
+ ASSERT_EQ(1U, commands.size());
+ AssertCommandEqualsData(second_data, commands[0]);
+
+ STLDeleteElements(&commands);
+}