| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/sessions/session_service.h" | 13 #include "chrome/browser/sessions/session_service.h" |
| 14 #include "chrome/browser/sessions/session_service_factory.h" |
| 14 #include "chrome/browser/sessions/session_service_test_helper.h" | 15 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 15 #include "chrome/browser/sessions/session_types.h" | 16 #include "chrome/browser/sessions/session_types.h" |
| 16 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 17 #include "chrome/test/test_notification_tracker.h" | 18 #include "chrome/test/test_notification_tracker.h" |
| 18 #include "chrome/test/testing_profile.h" | 19 #include "chrome/test/testing_profile.h" |
| 19 #include "content/browser/renderer_host/test_render_view_host.h" | 20 #include "content/browser/renderer_host/test_render_view_host.h" |
| 20 #include "content/browser/site_instance.h" | 21 #include "content/browser/site_instance.h" |
| 21 #include "content/browser/tab_contents/navigation_controller.h" | 22 #include "content/browser/tab_contents/navigation_controller.h" |
| 22 #include "content/browser/tab_contents/navigation_entry.h" | 23 #include "content/browser/tab_contents/navigation_entry.h" |
| 23 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 54 // lifetime is managed by profile_manager_. | 55 // lifetime is managed by profile_manager_. |
| 55 STLDeleteElements(&windows_); | 56 STLDeleteElements(&windows_); |
| 56 } | 57 } |
| 57 | 58 |
| 58 // testing::Test overrides. | 59 // testing::Test overrides. |
| 59 virtual void SetUp() { | 60 virtual void SetUp() { |
| 60 NavigationControllerTest::SetUp(); | 61 NavigationControllerTest::SetUp(); |
| 61 | 62 |
| 62 // Force the session service to be created. | 63 // Force the session service to be created. |
| 63 SessionService* service = new SessionService(profile()); | 64 SessionService* service = new SessionService(profile()); |
| 64 profile()->set_session_service(service); | 65 SessionServiceFactory::SetForTestProfile(profile(), service); |
| 65 service->SetWindowType(window_id, Browser::TYPE_NORMAL); | 66 service->SetWindowType(window_id, Browser::TYPE_NORMAL); |
| 66 service->SetWindowBounds(window_id, gfx::Rect(0, 1, 2, 3), false); | 67 service->SetWindowBounds(window_id, gfx::Rect(0, 1, 2, 3), false); |
| 67 service->SetTabIndexInWindow(window_id, | 68 service->SetTabIndexInWindow(window_id, |
| 68 controller().session_id(), 0); | 69 controller().session_id(), 0); |
| 69 controller().SetWindowID(window_id); | 70 controller().SetWindowID(window_id); |
| 70 | 71 |
| 71 session_helper_.set_service(service); | 72 session_helper_.set_service(service); |
| 72 } | 73 } |
| 73 | 74 |
| 74 virtual void TearDown() { | 75 virtual void TearDown() { |
| 75 // Release profile's reference to the session service. Otherwise the file | 76 // Release profile's reference to the session service. Otherwise the file |
| 76 // will still be open and we won't be able to delete the directory below. | 77 // will still be open and we won't be able to delete the directory below. |
| 77 session_helper_.ReleaseService(); // profile owns this | 78 session_helper_.ReleaseService(); // profile owns this |
| 78 profile()->set_session_service(NULL); | 79 SessionServiceFactory::SetForTestProfile(profile(), NULL); |
| 79 | 80 |
| 80 // Make sure we wait for history to shut down before continuing. The task | 81 // Make sure we wait for history to shut down before continuing. The task |
| 81 // we add will cause our message loop to quit once it is destroyed. | 82 // we add will cause our message loop to quit once it is destroyed. |
| 82 HistoryService* history = | 83 HistoryService* history = |
| 83 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 84 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 84 if (history) { | 85 if (history) { |
| 85 history->SetOnBackendDestroyTask(new MessageLoop::QuitTask); | 86 history->SetOnBackendDestroyTask(new MessageLoop::QuitTask); |
| 86 MessageLoop::current()->Run(); | 87 MessageLoop::current()->Run(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Do normal cleanup before deleting the profile directory below. | 90 // Do normal cleanup before deleting the profile directory below. |
| 90 NavigationControllerTest::TearDown(); | 91 NavigationControllerTest::TearDown(); |
| 91 | 92 |
| 92 ASSERT_TRUE(file_util::Delete(test_dir_, true)); | 93 ASSERT_TRUE(file_util::Delete(test_dir_, true)); |
| 93 ASSERT_FALSE(file_util::PathExists(test_dir_)); | 94 ASSERT_FALSE(file_util::PathExists(test_dir_)); |
| 94 } | 95 } |
| 95 | 96 |
| 96 // Deletes the current profile manager and creates a new one. Indirectly this | 97 // Deletes the current profile manager and creates a new one. Indirectly this |
| 97 // shuts down the history database and reopens it. | 98 // shuts down the history database and reopens it. |
| 98 void ReopenDatabase() { | 99 void ReopenDatabase() { |
| 99 session_helper_.set_service(NULL); | 100 session_helper_.set_service(NULL); |
| 100 profile()->set_session_service(NULL); | 101 SessionServiceFactory::SetForTestProfile(profile(), NULL); |
| 101 | 102 |
| 102 SessionService* service = new SessionService(profile()); | 103 SessionService* service = new SessionService(profile()); |
| 103 profile()->set_session_service(service); | 104 SessionServiceFactory::SetForTestProfile(profile(), service); |
| 104 session_helper_.set_service(service); | 105 session_helper_.set_service(service); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void GetLastSession() { | 108 void GetLastSession() { |
| 108 profile()->GetSessionService()->TabClosed(controller().window_id(), | 109 SessionServiceFactory::GetForProfile(profile())->TabClosed( |
| 109 controller().session_id(), | 110 controller().window_id(), controller().session_id(), false); |
| 110 false); | |
| 111 | 111 |
| 112 ReopenDatabase(); | 112 ReopenDatabase(); |
| 113 Time close_time; | 113 Time close_time; |
| 114 | 114 |
| 115 session_helper_.ReadWindows(&windows_); | 115 session_helper_.ReadWindows(&windows_); |
| 116 } | 116 } |
| 117 | 117 |
| 118 CancelableRequestConsumer consumer; | 118 CancelableRequestConsumer consumer; |
| 119 | 119 |
| 120 // URLs for testing. | 120 // URLs for testing. |
| (...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 TabNavigation nav(0, url0, GURL(), string16(), | 2235 TabNavigation nav(0, url0, GURL(), string16(), |
| 2236 webkit_glue::CreateHistoryStateForURL(url0), | 2236 webkit_glue::CreateHistoryStateForURL(url0), |
| 2237 PageTransition::LINK); | 2237 PageTransition::LINK); |
| 2238 session_helper_.AssertNavigationEquals(nav, | 2238 session_helper_.AssertNavigationEquals(nav, |
| 2239 windows_[0]->tabs[0]->navigations[0]); | 2239 windows_[0]->tabs[0]->navigations[0]); |
| 2240 nav.set_url(url2); | 2240 nav.set_url(url2); |
| 2241 session_helper_.AssertNavigationEquals(nav, | 2241 session_helper_.AssertNavigationEquals(nav, |
| 2242 windows_[0]->tabs[0]->navigations[1]); | 2242 windows_[0]->tabs[0]->navigations[1]); |
| 2243 } | 2243 } |
| 2244 */ | 2244 */ |
| OLD | NEW |