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" |
| 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
13 #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" |
14 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" |
15 #include "content/browser/tab_contents/test_tab_contents.h" | 20 #include "content/browser/tab_contents/test_tab_contents.h" |
16 #include "content/public/browser/navigation_controller.h" | 21 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_types.h" |
18 #include "content/test/render_view_test.h" | 25 #include "content/test/render_view_test.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
21 | 28 |
22 typedef TabRestoreService::Tab Tab; | 29 typedef TabRestoreService::Tab Tab; |
| 30 typedef TabRestoreService::Window Window; |
23 | 31 |
24 using content::NavigationEntry; | 32 using content::NavigationEntry; |
25 | 33 |
26 // Create subclass that overrides TimeNow so that we can control the time used | 34 // Create subclass that overrides TimeNow so that we can control the time used |
27 // for closed tabs and windows. | 35 // for closed tabs and windows. |
28 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { | 36 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { |
29 public: | 37 public: |
30 TabRestoreTimeFactory() : time_(base::Time::Now()) {} | 38 TabRestoreTimeFactory() : time_(base::Time::Now()) {} |
31 | 39 |
32 virtual ~TabRestoreTimeFactory() {} | 40 virtual ~TabRestoreTimeFactory() {} |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 service_->LoadTabsFromLastSession(); | 98 service_->LoadTabsFromLastSession(); |
91 } | 99 } |
92 | 100 |
93 // Adds a window with one tab and url to the profile's session service. | 101 // Adds a window with one tab and url to the profile's session service. |
94 // If |pinned| is true, the tab is marked as pinned in the session service. | 102 // If |pinned| is true, the tab is marked as pinned in the session service. |
95 void AddWindowWithOneTabToSessionService(bool pinned) { | 103 void AddWindowWithOneTabToSessionService(bool pinned) { |
96 SessionService* session_service = | 104 SessionService* session_service = |
97 SessionServiceFactory::GetForProfile(profile()); | 105 SessionServiceFactory::GetForProfile(profile()); |
98 SessionID tab_id; | 106 SessionID tab_id; |
99 SessionID window_id; | 107 SessionID window_id; |
100 session_service->SetWindowType(window_id, Browser::TYPE_TABBED); | 108 session_service->SetWindowType( |
| 109 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
101 session_service->SetTabWindow(window_id, tab_id); | 110 session_service->SetTabWindow(window_id, tab_id); |
102 session_service->SetTabIndexInWindow(window_id, tab_id, 0); | 111 session_service->SetTabIndexInWindow(window_id, tab_id, 0); |
103 session_service->SetSelectedTabInWindow(window_id, 0); | 112 session_service->SetSelectedTabInWindow(window_id, 0); |
104 if (pinned) | 113 if (pinned) |
105 session_service->SetPinnedState(window_id, tab_id, true); | 114 session_service->SetPinnedState(window_id, tab_id, true); |
106 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());; | 115 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());; |
107 entry->SetURL(url1_); | 116 entry->SetURL(url1_); |
108 session_service->UpdateTabNavigation(window_id, tab_id, 0, *entry.get()); | 117 session_service->UpdateTabNavigation(window_id, tab_id, 0, *entry.get()); |
109 } | 118 } |
110 | 119 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 tab = static_cast<Tab*>(entry); | 251 tab = static_cast<Tab*>(entry); |
243 EXPECT_TRUE(tab->pinned); | 252 EXPECT_TRUE(tab->pinned); |
244 ASSERT_EQ(3U, tab->navigations.size()); | 253 ASSERT_EQ(3U, tab->navigations.size()); |
245 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); | 254 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); |
246 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); | 255 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); |
247 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); | 256 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); |
248 EXPECT_EQ(2, tab->current_navigation_index); | 257 EXPECT_EQ(2, tab->current_navigation_index); |
249 EXPECT_TRUE(extension_app_id == tab->extension_app_id); | 258 EXPECT_TRUE(extension_app_id == tab->extension_app_id); |
250 } | 259 } |
251 | 260 |
| 261 // We only restore apps on chromeos. |
| 262 #if defined(OS_CHROMEOS) |
| 263 |
| 264 typedef InProcessBrowserTest TabRestoreServiceBrowserTest; |
| 265 |
| 266 IN_PROC_BROWSER_TEST_F(TabRestoreServiceBrowserTest, RestoreApp) { |
| 267 Profile* profile = browser()->profile(); |
| 268 TabRestoreService* trs = TabRestoreServiceFactory::GetForProfile(profile); |
| 269 const char* app_name = "TestApp"; |
| 270 |
| 271 Browser* app_browser = CreateBrowserForApp(app_name, profile); |
| 272 app_browser->window()->Close(); |
| 273 ui_test_utils::WindowedNotificationObserver observer( |
| 274 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 275 content::Source<Browser>(app_browser)); |
| 276 observer.Wait(); |
| 277 |
| 278 // One entry should be created. |
| 279 ASSERT_EQ(1U, trs->entries().size()); |
| 280 const TabRestoreService::Entry* restored_entry = trs->entries().front(); |
| 281 |
| 282 // It should be a window with an app. |
| 283 ASSERT_EQ(TabRestoreService::WINDOW, restored_entry->type); |
| 284 const Window* restored_window = |
| 285 static_cast<const Window*>(restored_entry); |
| 286 EXPECT_EQ(app_name, restored_window->app_name); |
| 287 |
| 288 } |
| 289 #endif |
| 290 |
252 // Make sure we persist entries to disk that have post data. | 291 // Make sure we persist entries to disk that have post data. |
253 TEST_F(TabRestoreServiceTest, DontPersistPostData) { | 292 TEST_F(TabRestoreServiceTest, DontPersistPostData) { |
254 AddThreeNavigations(); | 293 AddThreeNavigations(); |
255 controller().GetEntryAtIndex(0)->SetHasPostData(true); | 294 controller().GetEntryAtIndex(0)->SetHasPostData(true); |
256 controller().GetEntryAtIndex(1)->SetHasPostData(true); | 295 controller().GetEntryAtIndex(1)->SetHasPostData(true); |
257 controller().GetEntryAtIndex(2)->SetHasPostData(true); | 296 controller().GetEntryAtIndex(2)->SetHasPostData(true); |
258 | 297 |
259 // Have the service record the tab. | 298 // Have the service record the tab. |
260 service_->CreateHistoricalTab(&controller(), -1); | 299 service_->CreateHistoricalTab(&controller(), -1); |
261 ASSERT_EQ(1U, service_->entries().size()); | 300 ASSERT_EQ(1U, service_->entries().size()); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 for (size_t i = 0; i < max_entries + 5; i++) { | 639 for (size_t i = 0; i < max_entries + 5; i++) { |
601 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); | 640 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); |
602 service_->CreateHistoricalTab(&controller(), -1); | 641 service_->CreateHistoricalTab(&controller(), -1); |
603 } | 642 } |
604 | 643 |
605 EXPECT_EQ(max_entries, service_->entries_.size()); | 644 EXPECT_EQ(max_entries, service_->entries_.size()); |
606 // This should not crash. | 645 // This should not crash. |
607 service_->LoadTabsFromLastSession(); | 646 service_->LoadTabsFromLastSession(); |
608 EXPECT_EQ(max_entries, service_->entries_.size()); | 647 EXPECT_EQ(max_entries, service_->entries_.size()); |
609 } | 648 } |
OLD | NEW |