OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/defaults.h" | 5 #include "chrome/browser/defaults.h" |
6 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 6 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
7 #include "chrome/browser/sessions/session_types.h" | 7 #include "chrome/browser/sessions/session_types.h" |
8 #include "chrome/browser/sessions/session_service.h" | 8 #include "chrome/browser/sessions/session_service.h" |
9 #include "chrome/browser/sessions/tab_restore_service.h" | 9 #include "chrome/browser/sessions/tab_restore_service.h" |
10 #include "chrome/browser/tab_contents/navigation_controller.h" | 10 #include "chrome/browser/tab_contents/navigation_controller.h" |
11 #include "chrome/browser/tab_contents/navigation_entry.h" | 11 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 12 #include "chrome/browser/tab_contents/test_tab_contents.h" |
12 #include "chrome/test/render_view_test.h" | 13 #include "chrome/test/render_view_test.h" |
13 #include "chrome/test/testing_profile.h" | 14 #include "chrome/test/testing_profile.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" |
16 | 17 |
17 // Create subclass that overrides TimeNow so that we can control the time used | 18 // Create subclass that overrides TimeNow so that we can control the time used |
18 // for closed tabs and windows. | 19 // for closed tabs and windows. |
19 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { | 20 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { |
20 public: | 21 public: |
21 TabRestoreTimeFactory() : time_(base::Time::Now()) {} | 22 TabRestoreTimeFactory() : time_(base::Time::Now()) {} |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // Navigate to three URLs. | 62 // Navigate to three URLs. |
62 NavigateAndCommit(url1_); | 63 NavigateAndCommit(url1_); |
63 NavigateAndCommit(url2_); | 64 NavigateAndCommit(url2_); |
64 NavigateAndCommit(url3_); | 65 NavigateAndCommit(url3_); |
65 } | 66 } |
66 | 67 |
67 void NavigateToIndex(int index) { | 68 void NavigateToIndex(int index) { |
68 // Navigate back. We have to do this song and dance as NavigationController | 69 // Navigate back. We have to do this song and dance as NavigationController |
69 // isn't happy if you navigate immediately while going back. | 70 // isn't happy if you navigate immediately while going back. |
70 controller().GoToIndex(index); | 71 controller().GoToIndex(index); |
71 rvh()->SendNavigate(controller().pending_entry()->page_id(), | 72 contents()->CommitPendingNavigation(); |
72 controller().pending_entry()->url()); | |
73 } | 73 } |
74 | 74 |
75 void RecreateService() { | 75 void RecreateService() { |
76 // Must set service to null first so that it is destroyed before the new | 76 // Must set service to null first so that it is destroyed before the new |
77 // one is created. | 77 // one is created. |
78 service_ = NULL; | 78 service_ = NULL; |
79 service_ = new TabRestoreService(profile(), time_factory_); | 79 service_ = new TabRestoreService(profile(), time_factory_); |
80 service_->LoadTabsFromLastSession(); | 80 service_->LoadTabsFromLastSession(); |
81 } | 81 } |
82 | 82 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 // There should be two entries now. | 151 // There should be two entries now. |
152 ASSERT_EQ(2U, service_->entries().size()); | 152 ASSERT_EQ(2U, service_->entries().size()); |
153 | 153 |
154 // Make sure the entry matches | 154 // Make sure the entry matches |
155 entry = service_->entries().front(); | 155 entry = service_->entries().front(); |
156 ASSERT_EQ(TabRestoreService::TAB, entry->type); | 156 ASSERT_EQ(TabRestoreService::TAB, entry->type); |
157 tab = static_cast<TabRestoreService::Tab*>(entry); | 157 tab = static_cast<TabRestoreService::Tab*>(entry); |
158 EXPECT_FALSE(tab->pinned); | 158 EXPECT_FALSE(tab->pinned); |
159 ASSERT_EQ(3U, tab->navigations.size()); | 159 ASSERT_EQ(3U, tab->navigations.size()); |
160 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); | 160 EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); |
161 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); | 161 EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); |
162 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); | 162 EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); |
163 EXPECT_EQ(1, tab->current_navigation_index); | 163 EXPECT_EQ(1, tab->current_navigation_index); |
164 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), | 164 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), |
165 tab->timestamp.ToInternalValue()); | 165 tab->timestamp.ToInternalValue()); |
166 } | 166 } |
167 | 167 |
168 // Make sure TabRestoreService doesn't create an entry for a tab with no | 168 // Make sure TabRestoreService doesn't create an entry for a tab with no |
169 // navigations. | 169 // navigations. |
170 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { | 170 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { |
171 service_->CreateHistoricalTab(&controller()); | 171 service_->CreateHistoricalTab(&controller()); |
172 EXPECT_TRUE(service_->entries().empty()); | 172 EXPECT_TRUE(service_->entries().empty()); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 ASSERT_EQ(1U, service_->entries().size()); | 475 ASSERT_EQ(1U, service_->entries().size()); |
476 | 476 |
477 // And verify the entry. | 477 // And verify the entry. |
478 TabRestoreService::Entry* restored_entry = service_->entries().front(); | 478 TabRestoreService::Entry* restored_entry = service_->entries().front(); |
479 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); | 479 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); |
480 TabRestoreService::Tab* restored_tab = | 480 TabRestoreService::Tab* restored_tab = |
481 static_cast<TabRestoreService::Tab*>(restored_entry); | 481 static_cast<TabRestoreService::Tab*>(restored_entry); |
482 EXPECT_EQ(tab_timestamp.ToInternalValue(), | 482 EXPECT_EQ(tab_timestamp.ToInternalValue(), |
483 restored_tab->timestamp.ToInternalValue()); | 483 restored_tab->timestamp.ToInternalValue()); |
484 } | 484 } |
OLD | NEW |