| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "chrome/browser/sessions/session_backend.h" | 10 #include "chrome/browser/sessions/session_backend.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 empty_commands->push_back(CreateCommandFromData(empty_command)); | 173 empty_commands->push_back(CreateCommandFromData(empty_command)); |
| 174 backend->AppendCommands(empty_commands, true); | 174 backend->AppendCommands(empty_commands, true); |
| 175 backend->MoveCurrentSessionToLastSession(); | 175 backend->MoveCurrentSessionToLastSession(); |
| 176 | 176 |
| 177 std::vector<SessionCommand*> commands; | 177 std::vector<SessionCommand*> commands; |
| 178 backend->ReadLastSessionCommandsImpl(&commands); | 178 backend->ReadLastSessionCommandsImpl(&commands); |
| 179 ASSERT_EQ(1, commands.size()); | 179 ASSERT_EQ(1, commands.size()); |
| 180 AssertCommandEqualsData(empty_command, commands[0]); | 180 AssertCommandEqualsData(empty_command, commands[0]); |
| 181 STLDeleteElements(&commands); | 181 STLDeleteElements(&commands); |
| 182 } | 182 } |
| 183 |
| 184 // Writes a command, appends another command with reset to true, then reads |
| 185 // making sure we only get back the second command. |
| 186 TEST_F(SessionBackendTest, Truncate) { |
| 187 scoped_refptr<SessionBackend> backend( |
| 188 new SessionBackend(BaseSessionService::SESSION_RESTORE, path_)); |
| 189 struct TestData first_data = { 1, "a" }; |
| 190 std::vector<SessionCommand*> commands; |
| 191 commands.push_back(CreateCommandFromData(first_data)); |
| 192 backend->AppendCommands(new SessionCommands(commands), false); |
| 193 commands.clear(); |
| 194 |
| 195 // Write another command, this time resetting the file when appending. |
| 196 struct TestData second_data = { 2, "b" }; |
| 197 commands.push_back(CreateCommandFromData(second_data)); |
| 198 backend->AppendCommands(new SessionCommands(commands), true); |
| 199 commands.clear(); |
| 200 |
| 201 // Read it back in. |
| 202 backend = NULL; |
| 203 backend = new SessionBackend(BaseSessionService::SESSION_RESTORE, path_); |
| 204 backend->ReadLastSessionCommandsImpl(&commands); |
| 205 |
| 206 // And make sure we get back the expected data. |
| 207 ASSERT_EQ(1, commands.size()); |
| 208 AssertCommandEqualsData(second_data, commands[0]); |
| 209 |
| 210 STLDeleteElements(&commands); |
| 211 } |
| OLD | NEW |