OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/sessions/session_service_factory.h" | 7 #include "chrome/browser/sessions/session_service_factory.h" |
8 #include "chrome/browser/sessions/session_service.h" | 8 #include "chrome/browser/sessions/session_service.h" |
9 #include "chrome/browser/sessions/session_types.h" | 9 #include "chrome/browser/sessions/session_types.h" |
10 #include "chrome/browser/sessions/tab_restore_service.h" | 10 #include "chrome/browser/sessions/tab_restore_service.h" |
11 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 11 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/chrome_render_view_test.h" | 16 #include "chrome/test/base/chrome_render_view_test.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "content/public/browser/browser_thread.h" | |
20 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
21 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
24 #include "content/public/test/render_view_test.h" | 23 #include "content/public/test/render_view_test.h" |
25 #include "content/public/test/test_browser_thread.h" | |
26 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
27 #include "content/public/test/web_contents_tester.h" | 25 #include "content/public/test/web_contents_tester.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
30 | 28 |
31 typedef TabRestoreService::Tab Tab; | 29 typedef TabRestoreService::Tab Tab; |
32 typedef TabRestoreService::Window Window; | 30 typedef TabRestoreService::Window Window; |
33 using content::WebContentsTester; | 31 using content::WebContentsTester; |
34 | 32 |
35 using content::NavigationEntry; | 33 using content::NavigationEntry; |
36 | 34 |
37 // Create subclass that overrides TimeNow so that we can control the time used | 35 // Create subclass that overrides TimeNow so that we can control the time used |
38 // for closed tabs and windows. | 36 // for closed tabs and windows. |
39 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { | 37 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { |
40 public: | 38 public: |
41 TabRestoreTimeFactory() : time_(base::Time::Now()) {} | 39 TabRestoreTimeFactory() : time_(base::Time::Now()) {} |
42 | 40 |
43 virtual ~TabRestoreTimeFactory() {} | 41 virtual ~TabRestoreTimeFactory() {} |
44 | 42 |
45 virtual base::Time TimeNow() { | 43 virtual base::Time TimeNow() { |
46 return time_; | 44 return time_; |
47 } | 45 } |
48 | 46 |
49 private: | 47 private: |
50 base::Time time_; | 48 base::Time time_; |
51 }; | 49 }; |
52 | 50 |
53 class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { | 51 class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { |
54 public: | 52 public: |
55 TabRestoreServiceTest() | 53 TabRestoreServiceTest() { |
56 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | |
57 url1_ = GURL("http://1"); | 54 url1_ = GURL("http://1"); |
58 url2_ = GURL("http://2"); | 55 url2_ = GURL("http://2"); |
59 url3_ = GURL("http://3"); | 56 url3_ = GURL("http://3"); |
60 } | 57 } |
61 | 58 |
62 ~TabRestoreServiceTest() { | 59 ~TabRestoreServiceTest() { |
63 } | 60 } |
64 | 61 |
65 protected: | 62 protected: |
66 // testing::Test overrides | 63 // testing::Test overrides |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 profile()->set_last_session_exited_cleanly(false); | 133 profile()->set_last_session_exited_cleanly(false); |
137 } | 134 } |
138 | 135 |
139 GURL url1_; | 136 GURL url1_; |
140 GURL url2_; | 137 GURL url2_; |
141 GURL url3_; | 138 GURL url3_; |
142 scoped_ptr<TabRestoreService> service_; | 139 scoped_ptr<TabRestoreService> service_; |
143 TabRestoreTimeFactory* time_factory_; | 140 TabRestoreTimeFactory* time_factory_; |
144 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox | 141 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox |
145 webkit_platform_support_; | 142 webkit_platform_support_; |
146 content::TestBrowserThread ui_thread_; | |
147 }; | 143 }; |
148 | 144 |
149 TEST_F(TabRestoreServiceTest, Basic) { | 145 TEST_F(TabRestoreServiceTest, Basic) { |
150 AddThreeNavigations(); | 146 AddThreeNavigations(); |
151 | 147 |
152 // Have the service record the tab. | 148 // Have the service record the tab. |
153 service_->CreateHistoricalTab(contents(), -1); | 149 service_->CreateHistoricalTab(&controller(), -1); |
154 | 150 |
155 // Make sure an entry was created. | 151 // Make sure an entry was created. |
156 ASSERT_EQ(1U, service_->entries().size()); | 152 ASSERT_EQ(1U, service_->entries().size()); |
157 | 153 |
158 // Make sure the entry matches. | 154 // Make sure the entry matches. |
159 TabRestoreService::Entry* entry = service_->entries().front(); | 155 TabRestoreService::Entry* entry = service_->entries().front(); |
160 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 156 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
161 Tab* tab = static_cast<Tab*>(entry); | 157 Tab* tab = static_cast<Tab*>(entry); |
162 EXPECT_FALSE(tab->pinned); | 158 EXPECT_FALSE(tab->pinned); |
163 EXPECT_TRUE(tab->extension_app_id.empty()); | 159 EXPECT_TRUE(tab->extension_app_id.empty()); |
164 ASSERT_EQ(3U, tab->navigations.size()); | 160 ASSERT_EQ(3U, tab->navigations.size()); |
165 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); | 161 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); |
166 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); | 162 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); |
167 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); | 163 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); |
168 EXPECT_EQ(2, tab->current_navigation_index); | 164 EXPECT_EQ(2, tab->current_navigation_index); |
169 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), | 165 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), |
170 tab->timestamp.ToInternalValue()); | 166 tab->timestamp.ToInternalValue()); |
171 | 167 |
172 NavigateToIndex(1); | 168 NavigateToIndex(1); |
173 | 169 |
174 // And check again. | 170 // And check again. |
175 service_->CreateHistoricalTab(contents(), -1); | 171 service_->CreateHistoricalTab(&controller(), -1); |
176 | 172 |
177 // There should be two entries now. | 173 // There should be two entries now. |
178 ASSERT_EQ(2U, service_->entries().size()); | 174 ASSERT_EQ(2U, service_->entries().size()); |
179 | 175 |
180 // Make sure the entry matches | 176 // Make sure the entry matches |
181 entry = service_->entries().front(); | 177 entry = service_->entries().front(); |
182 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 178 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
183 tab = static_cast<Tab*>(entry); | 179 tab = static_cast<Tab*>(entry); |
184 EXPECT_FALSE(tab->pinned); | 180 EXPECT_FALSE(tab->pinned); |
185 ASSERT_EQ(3U, tab->navigations.size()); | 181 ASSERT_EQ(3U, tab->navigations.size()); |
186 EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); | 182 EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); |
187 EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); | 183 EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); |
188 EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); | 184 EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); |
189 EXPECT_EQ(1, tab->current_navigation_index); | 185 EXPECT_EQ(1, tab->current_navigation_index); |
190 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), | 186 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), |
191 tab->timestamp.ToInternalValue()); | 187 tab->timestamp.ToInternalValue()); |
192 } | 188 } |
193 | 189 |
194 // Make sure TabRestoreService doesn't create an entry for a tab with no | 190 // Make sure TabRestoreService doesn't create an entry for a tab with no |
195 // navigations. | 191 // navigations. |
196 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { | 192 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { |
197 service_->CreateHistoricalTab(contents(), -1); | 193 service_->CreateHistoricalTab(&controller(), -1); |
198 EXPECT_TRUE(service_->entries().empty()); | 194 EXPECT_TRUE(service_->entries().empty()); |
199 } | 195 } |
200 | 196 |
201 // Tests restoring a single tab. | 197 // Tests restoring a single tab. |
202 TEST_F(TabRestoreServiceTest, Restore) { | 198 TEST_F(TabRestoreServiceTest, Restore) { |
203 AddThreeNavigations(); | 199 AddThreeNavigations(); |
204 | 200 |
205 // Have the service record the tab. | 201 // Have the service record the tab. |
206 service_->CreateHistoricalTab(contents(), -1); | 202 service_->CreateHistoricalTab(&controller(), -1); |
207 | 203 |
208 // Recreate the service and have it load the tabs. | 204 // Recreate the service and have it load the tabs. |
209 RecreateService(); | 205 RecreateService(); |
210 | 206 |
211 // One entry should be created. | 207 // One entry should be created. |
212 ASSERT_EQ(1U, service_->entries().size()); | 208 ASSERT_EQ(1U, service_->entries().size()); |
213 | 209 |
214 // And verify the entry. | 210 // And verify the entry. |
215 TabRestoreService::Entry* entry = service_->entries().front(); | 211 TabRestoreService::Entry* entry = service_->entries().front(); |
216 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 212 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
217 Tab* tab = static_cast<Tab*>(entry); | 213 Tab* tab = static_cast<Tab*>(entry); |
218 EXPECT_FALSE(tab->pinned); | 214 EXPECT_FALSE(tab->pinned); |
219 ASSERT_EQ(3U, tab->navigations.size()); | 215 ASSERT_EQ(3U, tab->navigations.size()); |
220 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); | 216 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); |
221 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); | 217 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); |
222 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); | 218 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); |
223 EXPECT_EQ(2, tab->current_navigation_index); | 219 EXPECT_EQ(2, tab->current_navigation_index); |
224 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), | 220 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), |
225 tab->timestamp.ToInternalValue()); | 221 tab->timestamp.ToInternalValue()); |
226 } | 222 } |
227 | 223 |
228 // Tests restoring a single pinned tab. | 224 // Tests restoring a single pinned tab. |
229 TEST_F(TabRestoreServiceTest, RestorePinnedAndApp) { | 225 TEST_F(TabRestoreServiceTest, RestorePinnedAndApp) { |
230 AddThreeNavigations(); | 226 AddThreeNavigations(); |
231 | 227 |
232 // Have the service record the tab. | 228 // Have the service record the tab. |
233 service_->CreateHistoricalTab(contents(), -1); | 229 service_->CreateHistoricalTab(&controller(), -1); |
234 | 230 |
235 // One entry should be created. | 231 // One entry should be created. |
236 ASSERT_EQ(1U, service_->entries().size()); | 232 ASSERT_EQ(1U, service_->entries().size()); |
237 | 233 |
238 // We have to explicitly mark the tab as pinned as there is no browser for | 234 // We have to explicitly mark the tab as pinned as there is no browser for |
239 // these tests. | 235 // these tests. |
240 TabRestoreService::Entry* entry = service_->entries().front(); | 236 TabRestoreService::Entry* entry = service_->entries().front(); |
241 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 237 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
242 Tab* tab = static_cast<Tab*>(entry); | 238 Tab* tab = static_cast<Tab*>(entry); |
243 tab->pinned = true; | 239 tab->pinned = true; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 #endif // defined(USE_AURA) | 289 #endif // defined(USE_AURA) |
294 | 290 |
295 // Make sure we persist entries to disk that have post data. | 291 // Make sure we persist entries to disk that have post data. |
296 TEST_F(TabRestoreServiceTest, DontPersistPostData) { | 292 TEST_F(TabRestoreServiceTest, DontPersistPostData) { |
297 AddThreeNavigations(); | 293 AddThreeNavigations(); |
298 controller().GetEntryAtIndex(0)->SetHasPostData(true); | 294 controller().GetEntryAtIndex(0)->SetHasPostData(true); |
299 controller().GetEntryAtIndex(1)->SetHasPostData(true); | 295 controller().GetEntryAtIndex(1)->SetHasPostData(true); |
300 controller().GetEntryAtIndex(2)->SetHasPostData(true); | 296 controller().GetEntryAtIndex(2)->SetHasPostData(true); |
301 | 297 |
302 // Have the service record the tab. | 298 // Have the service record the tab. |
303 service_->CreateHistoricalTab(contents(), -1); | 299 service_->CreateHistoricalTab(&controller(), -1); |
304 ASSERT_EQ(1U, service_->entries().size()); | 300 ASSERT_EQ(1U, service_->entries().size()); |
305 | 301 |
306 // Recreate the service and have it load the tabs. | 302 // Recreate the service and have it load the tabs. |
307 RecreateService(); | 303 RecreateService(); |
308 | 304 |
309 // One entry should be created. | 305 // One entry should be created. |
310 ASSERT_EQ(1U, service_->entries().size()); | 306 ASSERT_EQ(1U, service_->entries().size()); |
311 | 307 |
312 const TabRestoreService::Entry* restored_entry = service_->entries().front(); | 308 const TabRestoreService::Entry* restored_entry = service_->entries().front(); |
313 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); | 309 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); |
314 | 310 |
315 const Tab* restored_tab = | 311 const Tab* restored_tab = |
316 static_cast<const Tab*>(restored_entry); | 312 static_cast<const Tab*>(restored_entry); |
317 // There should be 3 navs. | 313 // There should be 3 navs. |
318 ASSERT_EQ(3U, restored_tab->navigations.size()); | 314 ASSERT_EQ(3U, restored_tab->navigations.size()); |
319 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), | 315 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), |
320 restored_tab->timestamp.ToInternalValue()); | 316 restored_tab->timestamp.ToInternalValue()); |
321 } | 317 } |
322 | 318 |
323 // Make sure we don't persist entries to disk that have post data. This | 319 // Make sure we don't persist entries to disk that have post data. This |
324 // differs from DontPersistPostData1 in that all the navigations have post | 320 // differs from DontPersistPostData1 in that all the navigations have post |
325 // data, so that nothing should be persisted. | 321 // data, so that nothing should be persisted. |
326 TEST_F(TabRestoreServiceTest, DontLoadTwice) { | 322 TEST_F(TabRestoreServiceTest, DontLoadTwice) { |
327 AddThreeNavigations(); | 323 AddThreeNavigations(); |
328 | 324 |
329 // Have the service record the tab. | 325 // Have the service record the tab. |
330 service_->CreateHistoricalTab(contents(), -1); | 326 service_->CreateHistoricalTab(&controller(), -1); |
331 ASSERT_EQ(1U, service_->entries().size()); | 327 ASSERT_EQ(1U, service_->entries().size()); |
332 | 328 |
333 // Recreate the service and have it load the tabs. | 329 // Recreate the service and have it load the tabs. |
334 RecreateService(); | 330 RecreateService(); |
335 | 331 |
336 service_->LoadTabsFromLastSession(); | 332 service_->LoadTabsFromLastSession(); |
337 | 333 |
338 // There should only be one entry. | 334 // There should only be one entry. |
339 ASSERT_EQ(1U, service_->entries().size()); | 335 ASSERT_EQ(1U, service_->entries().size()); |
340 } | 336 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 389 } |
394 | 390 |
395 TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) { | 391 TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) { |
396 CreateSessionServiceWithOneWindow(false); | 392 CreateSessionServiceWithOneWindow(false); |
397 | 393 |
398 SessionServiceFactory::GetForProfile(profile())-> | 394 SessionServiceFactory::GetForProfile(profile())-> |
399 MoveCurrentSessionToLastSession(); | 395 MoveCurrentSessionToLastSession(); |
400 | 396 |
401 AddThreeNavigations(); | 397 AddThreeNavigations(); |
402 | 398 |
403 service_->CreateHistoricalTab(contents(), -1); | 399 service_->CreateHistoricalTab(&controller(), -1); |
404 | 400 |
405 RecreateService(); | 401 RecreateService(); |
406 | 402 |
407 // We should get back two entries, one from the previous session and one from | 403 // We should get back two entries, one from the previous session and one from |
408 // the tab restore service. The previous session entry should be first. | 404 // the tab restore service. The previous session entry should be first. |
409 ASSERT_EQ(2U, service_->entries().size()); | 405 ASSERT_EQ(2U, service_->entries().size()); |
410 // The first entry should come from the session service. | 406 // The first entry should come from the session service. |
411 TabRestoreService::Entry* entry = service_->entries().front(); | 407 TabRestoreService::Entry* entry = service_->entries().front(); |
412 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); | 408 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); |
413 TabRestoreService::Window* window = | 409 TabRestoreService::Window* window = |
(...skipping 22 matching lines...) Expand all Loading... |
436 | 432 |
437 // Make sure pinned state is correctly loaded from session service. | 433 // Make sure pinned state is correctly loaded from session service. |
438 TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { | 434 TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { |
439 CreateSessionServiceWithOneWindow(true); | 435 CreateSessionServiceWithOneWindow(true); |
440 | 436 |
441 SessionServiceFactory::GetForProfile(profile())-> | 437 SessionServiceFactory::GetForProfile(profile())-> |
442 MoveCurrentSessionToLastSession(); | 438 MoveCurrentSessionToLastSession(); |
443 | 439 |
444 AddThreeNavigations(); | 440 AddThreeNavigations(); |
445 | 441 |
446 service_->CreateHistoricalTab(contents(), -1); | 442 service_->CreateHistoricalTab(&controller(), -1); |
447 | 443 |
448 RecreateService(); | 444 RecreateService(); |
449 | 445 |
450 // We should get back two entries, one from the previous session and one from | 446 // We should get back two entries, one from the previous session and one from |
451 // the tab restore service. The previous session entry should be first. | 447 // the tab restore service. The previous session entry should be first. |
452 ASSERT_EQ(2U, service_->entries().size()); | 448 ASSERT_EQ(2U, service_->entries().size()); |
453 // The first entry should come from the session service. | 449 // The first entry should come from the session service. |
454 TabRestoreService::Entry* entry = service_->entries().front(); | 450 TabRestoreService::Entry* entry = service_->entries().front(); |
455 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); | 451 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); |
456 TabRestoreService::Window* window = | 452 TabRestoreService::Window* window = |
(...skipping 23 matching lines...) Expand all Loading... |
480 CreateSessionServiceWithOneWindow(false); | 476 CreateSessionServiceWithOneWindow(false); |
481 | 477 |
482 for (size_t i = 0; i < TabRestoreService::kMaxEntries; ++i) | 478 for (size_t i = 0; i < TabRestoreService::kMaxEntries; ++i) |
483 AddWindowWithOneTabToSessionService(false); | 479 AddWindowWithOneTabToSessionService(false); |
484 | 480 |
485 SessionServiceFactory::GetForProfile(profile())-> | 481 SessionServiceFactory::GetForProfile(profile())-> |
486 MoveCurrentSessionToLastSession(); | 482 MoveCurrentSessionToLastSession(); |
487 | 483 |
488 AddThreeNavigations(); | 484 AddThreeNavigations(); |
489 | 485 |
490 service_->CreateHistoricalTab(contents(), -1); | 486 service_->CreateHistoricalTab(&controller(), -1); |
491 | 487 |
492 RecreateService(); | 488 RecreateService(); |
493 | 489 |
494 // We should get back kMaxEntries entries. We added more, but | 490 // We should get back kMaxEntries entries. We added more, but |
495 // TabRestoreService only allows up to kMaxEntries. | 491 // TabRestoreService only allows up to kMaxEntries. |
496 ASSERT_EQ(TabRestoreService::kMaxEntries, service_->entries().size()); | 492 ASSERT_EQ(TabRestoreService::kMaxEntries, service_->entries().size()); |
497 | 493 |
498 // The first entry should come from the session service. | 494 // The first entry should come from the session service. |
499 TabRestoreService::Entry* entry = service_->entries().front(); | 495 TabRestoreService::Entry* entry = service_->entries().front(); |
500 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); | 496 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); |
501 TabRestoreService::Window* window = | 497 TabRestoreService::Window* window = |
502 static_cast<TabRestoreService::Window*>(entry); | 498 static_cast<TabRestoreService::Window*>(entry); |
503 ASSERT_EQ(1U, window->tabs.size()); | 499 ASSERT_EQ(1U, window->tabs.size()); |
504 EXPECT_EQ(0, window->selected_tab_index); | 500 EXPECT_EQ(0, window->selected_tab_index); |
505 EXPECT_EQ(0, window->timestamp.ToInternalValue()); | 501 EXPECT_EQ(0, window->timestamp.ToInternalValue()); |
506 ASSERT_EQ(1U, window->tabs[0].navigations.size()); | 502 ASSERT_EQ(1U, window->tabs[0].navigations.size()); |
507 EXPECT_EQ(0, window->tabs[0].current_navigation_index); | 503 EXPECT_EQ(0, window->tabs[0].current_navigation_index); |
508 EXPECT_EQ(0, window->tabs[0].timestamp.ToInternalValue()); | 504 EXPECT_EQ(0, window->tabs[0].timestamp.ToInternalValue()); |
509 EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url()); | 505 EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url()); |
510 } | 506 } |
511 | 507 |
512 // Makes sure we restore the time stamp correctly. | 508 // Makes sure we restore the time stamp correctly. |
513 TEST_F(TabRestoreServiceTest, TimestampSurvivesRestore) { | 509 TEST_F(TabRestoreServiceTest, TimestampSurvivesRestore) { |
514 base::Time tab_timestamp(base::Time::FromInternalValue(123456789)); | 510 base::Time tab_timestamp(base::Time::FromInternalValue(123456789)); |
515 | 511 |
516 AddThreeNavigations(); | 512 AddThreeNavigations(); |
517 | 513 |
518 // Have the service record the tab. | 514 // Have the service record the tab. |
519 service_->CreateHistoricalTab(contents(), -1); | 515 service_->CreateHistoricalTab(&controller(), -1); |
520 | 516 |
521 // Make sure an entry was created. | 517 // Make sure an entry was created. |
522 ASSERT_EQ(1U, service_->entries().size()); | 518 ASSERT_EQ(1U, service_->entries().size()); |
523 | 519 |
524 // Make sure the entry matches. | 520 // Make sure the entry matches. |
525 TabRestoreService::Entry* entry = service_->entries().front(); | 521 TabRestoreService::Entry* entry = service_->entries().front(); |
526 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 522 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
527 Tab* tab = static_cast<Tab*>(entry); | 523 Tab* tab = static_cast<Tab*>(entry); |
528 tab->timestamp = tab_timestamp; | 524 tab->timestamp = tab_timestamp; |
529 | 525 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 CreateSessionServiceWithOneWindow(false); | 633 CreateSessionServiceWithOneWindow(false); |
638 | 634 |
639 SessionServiceFactory::GetForProfile(profile())-> | 635 SessionServiceFactory::GetForProfile(profile())-> |
640 MoveCurrentSessionToLastSession(); | 636 MoveCurrentSessionToLastSession(); |
641 | 637 |
642 profile()->set_restored_last_session(true); | 638 profile()->set_restored_last_session(true); |
643 | 639 |
644 const size_t max_entries = TabRestoreService::kMaxEntries; | 640 const size_t max_entries = TabRestoreService::kMaxEntries; |
645 for (size_t i = 0; i < max_entries + 5; i++) { | 641 for (size_t i = 0; i < max_entries + 5; i++) { |
646 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); | 642 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); |
647 service_->CreateHistoricalTab(contents(), -1); | 643 service_->CreateHistoricalTab(&controller(), -1); |
648 } | 644 } |
649 | 645 |
650 EXPECT_EQ(max_entries, service_->entries_.size()); | 646 EXPECT_EQ(max_entries, service_->entries_.size()); |
651 // This should not crash. | 647 // This should not crash. |
652 service_->LoadTabsFromLastSession(); | 648 service_->LoadTabsFromLastSession(); |
653 EXPECT_EQ(max_entries, service_->entries_.size()); | 649 EXPECT_EQ(max_entries, service_->entries_.size()); |
654 } | 650 } |
OLD | NEW |