| 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 "chrome/browser/sessions/session_types.h" | 5 #include "chrome/browser/sessions/session_types.h" |
| 6 #include "chrome/browser/sessions/tab_restore_service.h" | 6 #include "chrome/browser/sessions/tab_restore_service.h" |
| 7 #include "chrome/browser/tab_contents/navigation_entry.h" | 7 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 8 #include "chrome/test/test_tab_contents.h" | 8 #include "chrome/test/test_tab_contents.h" |
| 9 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 service_->RestoreEntryById(NULL, service_->entries().front()->id, true); | 172 service_->RestoreEntryById(NULL, service_->entries().front()->id, true); |
| 173 ASSERT_TRUE(service_->entries().empty()); | 173 ASSERT_TRUE(service_->entries().empty()); |
| 174 | 174 |
| 175 // Recreate the service and have it load the tabs. | 175 // Recreate the service and have it load the tabs. |
| 176 RecreateService(); | 176 RecreateService(); |
| 177 | 177 |
| 178 // There should be no entries. | 178 // There should be no entries. |
| 179 ASSERT_EQ(0U, service_->entries().size()); | 179 ASSERT_EQ(0U, service_->entries().size()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Make sure we don't persist entries to disk that have post data. | 182 // Make sure we persist entries to disk that have post data. |
| 183 TEST_F(TabRestoreServiceTest, DontPersistPostData1) { | 183 TEST_F(TabRestoreServiceTest, DontPersistPostData) { |
| 184 AddThreeNavigations(); | 184 AddThreeNavigations(); |
| 185 controller_->GetEntryAtIndex(0)->set_has_post_data(true); |
| 186 controller_->GetEntryAtIndex(1)->set_has_post_data(true); |
| 185 controller_->GetEntryAtIndex(2)->set_has_post_data(true); | 187 controller_->GetEntryAtIndex(2)->set_has_post_data(true); |
| 186 | 188 |
| 187 // Have the service record the tab. | 189 // Have the service record the tab. |
| 188 service_->CreateHistoricalTab(controller_); | 190 service_->CreateHistoricalTab(controller_); |
| 189 ASSERT_EQ(1U, service_->entries().size()); | |
| 190 | |
| 191 // Recreate the service and have it load the tabs. | |
| 192 RecreateService(); | |
| 193 | |
| 194 // One entry should be created. | |
| 195 ASSERT_EQ(1U, service_->entries().size()); | |
| 196 | |
| 197 // And verify the entry, the last navigation (url3_) should not have | |
| 198 // been written to disk as it contained post data. | |
| 199 TabRestoreService::Entry* entry = service_->entries().front(); | |
| 200 ASSERT_EQ(TabRestoreService::TAB, entry->type); | |
| 201 TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry); | |
| 202 ASSERT_EQ(2U, tab->navigations.size()); | |
| 203 EXPECT_TRUE(url1_ == tab->navigations[0].url()); | |
| 204 EXPECT_TRUE(url2_ == tab->navigations[1].url()); | |
| 205 EXPECT_EQ(1, tab->current_navigation_index); | |
| 206 } | |
| 207 | |
| 208 // Make sure we don't persist entries to disk that have post data. This | |
| 209 // differs from DontPersistPostData1 in that all navigations before the | |
| 210 // current index have post data. | |
| 211 TEST_F(TabRestoreServiceTest, DontPersistPostData2) { | |
| 212 AddThreeNavigations(); | |
| 213 NavigateToIndex(1); | |
| 214 controller_->GetEntryAtIndex(0)->set_has_post_data(true); | |
| 215 controller_->GetEntryAtIndex(1)->set_has_post_data(true); | |
| 216 | |
| 217 // Have the service record the tab. | |
| 218 service_->CreateHistoricalTab(controller_); | |
| 219 ASSERT_EQ(1U, service_->entries().size()); | 191 ASSERT_EQ(1U, service_->entries().size()); |
| 220 | 192 |
| 221 // Recreate the service and have it load the tabs. | 193 // Recreate the service and have it load the tabs. |
| 222 RecreateService(); | 194 RecreateService(); |
| 223 | 195 |
| 224 // One entry should be created. | 196 // One entry should be created. |
| 225 ASSERT_EQ(1U, service_->entries().size()); | 197 ASSERT_EQ(1U, service_->entries().size()); |
| 226 | 198 |
| 227 // And verify the entry, the last navigation (url3_) should not have | 199 const TabRestoreService::Entry* restored_entry = service_->entries().front(); |
| 228 // been written to disk as it contained post data. | 200 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); |
| 229 TabRestoreService::Entry* entry = service_->entries().front(); | 201 |
| 230 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 202 const TabRestoreService::Tab* restored_tab = |
| 231 TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry); | 203 static_cast<const TabRestoreService::Tab*>(restored_entry); |
| 232 ASSERT_EQ(1U, tab->navigations.size()); | 204 // There should be 3 navs. |
| 233 EXPECT_TRUE(url3_ == tab->navigations[0].url()); | 205 ASSERT_EQ(3U, restored_tab->navigations.size()); |
| 234 EXPECT_EQ(0, tab->current_navigation_index); | |
| 235 } | 206 } |
| 236 | 207 |
| 237 // Make sure we don't persist entries to disk that have post data. This | 208 // Make sure we don't persist entries to disk that have post data. This |
| 238 // differs from DontPersistPostData1 in that all the navigations have post | |
| 239 // data, so that nothing should be persisted. | |
| 240 TEST_F(TabRestoreServiceTest, DontPersistPostData3) { | |
| 241 AddThreeNavigations(); | |
| 242 controller_->GetEntryAtIndex(0)->set_has_post_data(true); | |
| 243 controller_->GetEntryAtIndex(1)->set_has_post_data(true); | |
| 244 controller_->GetEntryAtIndex(2)->set_has_post_data(true); | |
| 245 | |
| 246 // Have the service record the tab. | |
| 247 service_->CreateHistoricalTab(controller_); | |
| 248 ASSERT_EQ(1U, service_->entries().size()); | |
| 249 | |
| 250 // Recreate the service and have it load the tabs. | |
| 251 RecreateService(); | |
| 252 | |
| 253 // One entry should be created. | |
| 254 ASSERT_TRUE(service_->entries().empty()); | |
| 255 } | |
| 256 | |
| 257 // Make sure we don't persist entries to disk that have post data. This | |
| 258 // differs from DontPersistPostData1 in that all the navigations have post | 209 // differs from DontPersistPostData1 in that all the navigations have post |
| 259 // data, so that nothing should be persisted. | 210 // data, so that nothing should be persisted. |
| 260 TEST_F(TabRestoreServiceTest, DontLoadTwice) { | 211 TEST_F(TabRestoreServiceTest, DontLoadTwice) { |
| 261 AddThreeNavigations(); | 212 AddThreeNavigations(); |
| 262 | 213 |
| 263 // Have the service record the tab. | 214 // Have the service record the tab. |
| 264 service_->CreateHistoricalTab(controller_); | 215 service_->CreateHistoricalTab(controller_); |
| 265 ASSERT_EQ(1U, service_->entries().size()); | 216 ASSERT_EQ(1U, service_->entries().size()); |
| 266 | 217 |
| 267 // Recreate the service and have it load the tabs. | 218 // Recreate the service and have it load the tabs. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 TabRestoreService::Entry* entry = service_->entries().front(); | 332 TabRestoreService::Entry* entry = service_->entries().front(); |
| 382 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); | 333 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); |
| 383 TabRestoreService::Window* window = | 334 TabRestoreService::Window* window = |
| 384 static_cast<TabRestoreService::Window*>(entry); | 335 static_cast<TabRestoreService::Window*>(entry); |
| 385 ASSERT_EQ(1U, window->tabs.size()); | 336 ASSERT_EQ(1U, window->tabs.size()); |
| 386 EXPECT_EQ(0, window->selected_tab_index); | 337 EXPECT_EQ(0, window->selected_tab_index); |
| 387 ASSERT_EQ(1U, window->tabs[0].navigations.size()); | 338 ASSERT_EQ(1U, window->tabs[0].navigations.size()); |
| 388 EXPECT_EQ(0, window->tabs[0].current_navigation_index); | 339 EXPECT_EQ(0, window->tabs[0].current_navigation_index); |
| 389 EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url()); | 340 EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url()); |
| 390 } | 341 } |
| OLD | NEW |