Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: content/browser/tab_contents/navigation_controller_unittest.cc

Issue 7054008: Remove history dependency from content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // These are only used for commented out tests. If someone wants to enable
12 #include "chrome/browser/profiles/profile_manager.h" 12 // them, they should be moved to chrome first.
13 #include "chrome/browser/sessions/session_service.h" 13 // #include "chrome/browser/history/history.h"
14 #include "chrome/browser/sessions/session_service_factory.h" 14 // #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/sessions/session_service_test_helper.h" 15 // #include "chrome/browser/sessions/session_service.h"
16 // #include "chrome/browser/sessions/session_service_factory.h"
17 // #include "chrome/browser/sessions/session_service_test_helper.h"
16 #include "chrome/browser/sessions/session_types.h" 18 #include "chrome/browser/sessions/session_types.h"
17 #include "chrome/common/render_messages.h" 19 #include "chrome/common/render_messages.h"
18 #include "chrome/test/test_notification_tracker.h" 20 #include "chrome/test/test_notification_tracker.h"
19 #include "chrome/test/testing_profile.h" 21 #include "chrome/test/testing_profile.h"
20 #include "content/browser/renderer_host/test_render_view_host.h" 22 #include "content/browser/renderer_host/test_render_view_host.h"
21 #include "content/browser/site_instance.h" 23 #include "content/browser/site_instance.h"
22 #include "content/browser/tab_contents/navigation_controller.h" 24 #include "content/browser/tab_contents/navigation_controller.h"
23 #include "content/browser/tab_contents/navigation_entry.h" 25 #include "content/browser/tab_contents/navigation_entry.h"
24 #include "content/browser/tab_contents/tab_contents.h" 26 #include "content/browser/tab_contents/tab_contents.h"
25 #include "content/browser/tab_contents/tab_contents_delegate.h" 27 #include "content/browser/tab_contents/tab_contents_delegate.h"
26 #include "content/browser/tab_contents/test_tab_contents.h" 28 #include "content/browser/tab_contents/test_tab_contents.h"
27 #include "content/common/notification_registrar.h" 29 #include "content/common/notification_registrar.h"
28 #include "content/common/view_messages.h" 30 #include "content/common/view_messages.h"
29 #include "net/base/net_util.h" 31 #include "net/base/net_util.h"
30 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
31 #include "webkit/glue/webkit_glue.h" 33 #include "webkit/glue/webkit_glue.h"
32 34
33 using base::Time; 35 using base::Time;
34 36
35 // NavigationControllerTest ---------------------------------------------------- 37 // NavigationControllerTest ----------------------------------------------------
36 38
37 class NavigationControllerTest : public RenderViewHostTestHarness { 39 class NavigationControllerTest : public RenderViewHostTestHarness {
38 public: 40 public:
39 NavigationControllerTest() {} 41 NavigationControllerTest() {}
40 }; 42 };
41 43
42 // NavigationControllerHistoryTest ---------------------------------------------
43
44 class NavigationControllerHistoryTest : public NavigationControllerTest {
45 public:
46 NavigationControllerHistoryTest()
47 : url0("http://foo1"),
48 url1("http://foo1"),
49 url2("http://foo1"),
50 profile_manager_(NULL) {
51 }
52
53 virtual ~NavigationControllerHistoryTest() {
54 // Prevent our base class from deleting the profile since profile's
55 // lifetime is managed by profile_manager_.
56 STLDeleteElements(&windows_);
57 }
58
59 // testing::Test overrides.
60 virtual void SetUp() {
61 NavigationControllerTest::SetUp();
62
63 // Force the session service to be created.
64 SessionService* service = new SessionService(profile());
65 SessionServiceFactory::SetForTestProfile(profile(), service);
66 service->SetWindowType(window_id, Browser::TYPE_TABBED);
67 service->SetWindowBounds(window_id, gfx::Rect(0, 1, 2, 3), false);
68 service->SetTabIndexInWindow(window_id,
69 controller().session_id(), 0);
70 controller().SetWindowID(window_id);
71
72 session_helper_.set_service(service);
73 }
74
75 virtual void TearDown() {
76 // Release profile's reference to the session service. Otherwise the file
77 // will still be open and we won't be able to delete the directory below.
78 session_helper_.ReleaseService(); // profile owns this
79 SessionServiceFactory::SetForTestProfile(profile(), NULL);
80
81 // Make sure we wait for history to shut down before continuing. The task
82 // we add will cause our message loop to quit once it is destroyed.
83 HistoryService* history =
84 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
85 if (history) {
86 history->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
87 MessageLoop::current()->Run();
88 }
89
90 // Do normal cleanup before deleting the profile directory below.
91 NavigationControllerTest::TearDown();
92
93 ASSERT_TRUE(file_util::Delete(test_dir_, true));
94 ASSERT_FALSE(file_util::PathExists(test_dir_));
95 }
96
97 // Deletes the current profile manager and creates a new one. Indirectly this
98 // shuts down the history database and reopens it.
99 void ReopenDatabase() {
100 session_helper_.set_service(NULL);
101 SessionServiceFactory::SetForTestProfile(profile(), NULL);
102
103 SessionService* service = new SessionService(profile());
104 SessionServiceFactory::SetForTestProfile(profile(), service);
105 session_helper_.set_service(service);
106 }
107
108 void GetLastSession() {
109 SessionServiceFactory::GetForProfile(profile())->TabClosed(
110 controller().window_id(), controller().session_id(), false);
111
112 ReopenDatabase();
113 Time close_time;
114
115 session_helper_.ReadWindows(&windows_);
116 }
117
118 CancelableRequestConsumer consumer;
119
120 // URLs for testing.
121 const GURL url0;
122 const GURL url1;
123 const GURL url2;
124
125 std::vector<SessionWindow*> windows_;
126
127 SessionID window_id;
128
129 SessionServiceTestHelper session_helper_;
130
131 private:
132 ProfileManager* profile_manager_;
133 FilePath test_dir_;
134 };
135
136 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, 44 void RegisterForAllNavNotifications(TestNotificationTracker* tracker,
137 NavigationController* controller) { 45 NavigationController* controller) {
138 tracker->ListenFor(NotificationType::NAV_ENTRY_COMMITTED, 46 tracker->ListenFor(NotificationType::NAV_ENTRY_COMMITTED,
139 Source<NavigationController>(controller)); 47 Source<NavigationController>(controller));
140 tracker->ListenFor(NotificationType::NAV_LIST_PRUNED, 48 tracker->ListenFor(NotificationType::NAV_LIST_PRUNED,
141 Source<NavigationController>(controller)); 49 Source<NavigationController>(controller));
142 tracker->ListenFor(NotificationType::NAV_ENTRY_CHANGED, 50 tracker->ListenFor(NotificationType::NAV_ENTRY_CHANGED,
143 Source<NavigationController>(controller)); 51 Source<NavigationController>(controller));
144 } 52 }
145 53
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after
2159 2067
2160 EXPECT_EQ(-1, controller().pending_entry_index()); 2068 EXPECT_EQ(-1, controller().pending_entry_index());
2161 EXPECT_EQ(-1, controller().pending_entry_index()); 2069 EXPECT_EQ(-1, controller().pending_entry_index());
2162 EXPECT_EQ(controller().GetTransientEntry()->url(), transient_url); 2070 EXPECT_EQ(controller().GetTransientEntry()->url(), transient_url);
2163 } 2071 }
2164 2072
2165 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot 2073 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot
2166 (but not Vista) cleaning up the directory after they run. 2074 (but not Vista) cleaning up the directory after they run.
2167 This should be fixed. 2075 This should be fixed.
2168 2076
2077 // NavigationControllerHistoryTest ---------------------------------------------
2078
2079 class NavigationControllerHistoryTest : public NavigationControllerTest {
brettw 2011/05/24 16:21:03 It looks like you commented this out. Does this re
jam 2011/05/24 16:26:49 Not sure what you mean by testing story? The test
2080 public:
2081 NavigationControllerHistoryTest()
2082 : url0("http://foo1"),
2083 url1("http://foo1"),
2084 url2("http://foo1"),
2085 profile_manager_(NULL) {
2086 }
2087
2088 virtual ~NavigationControllerHistoryTest() {
2089 // Prevent our base class from deleting the profile since profile's
2090 // lifetime is managed by profile_manager_.
2091 STLDeleteElements(&windows_);
2092 }
2093
2094 // testing::Test overrides.
2095 virtual void SetUp() {
2096 NavigationControllerTest::SetUp();
2097
2098 // Force the session service to be created.
2099 SessionService* service = new SessionService(profile());
2100 SessionServiceFactory::SetForTestProfile(profile(), service);
2101 service->SetWindowType(window_id, Browser::TYPE_TABBED);
2102 service->SetWindowBounds(window_id, gfx::Rect(0, 1, 2, 3), false);
2103 service->SetTabIndexInWindow(window_id,
2104 controller().session_id(), 0);
2105 controller().SetWindowID(window_id);
2106
2107 session_helper_.set_service(service);
2108 }
2109
2110 virtual void TearDown() {
2111 // Release profile's reference to the session service. Otherwise the file
2112 // will still be open and we won't be able to delete the directory below.
2113 session_helper_.ReleaseService(); // profile owns this
2114 SessionServiceFactory::SetForTestProfile(profile(), NULL);
2115
2116 // Make sure we wait for history to shut down before continuing. The task
2117 // we add will cause our message loop to quit once it is destroyed.
2118 HistoryService* history =
2119 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2120 if (history) {
2121 history->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
2122 MessageLoop::current()->Run();
2123 }
2124
2125 // Do normal cleanup before deleting the profile directory below.
2126 NavigationControllerTest::TearDown();
2127
2128 ASSERT_TRUE(file_util::Delete(test_dir_, true));
2129 ASSERT_FALSE(file_util::PathExists(test_dir_));
2130 }
2131
2132 // Deletes the current profile manager and creates a new one. Indirectly this
2133 // shuts down the history database and reopens it.
2134 void ReopenDatabase() {
2135 session_helper_.set_service(NULL);
2136 SessionServiceFactory::SetForTestProfile(profile(), NULL);
2137
2138 SessionService* service = new SessionService(profile());
2139 SessionServiceFactory::SetForTestProfile(profile(), service);
2140 session_helper_.set_service(service);
2141 }
2142
2143 void GetLastSession() {
2144 SessionServiceFactory::GetForProfile(profile())->TabClosed(
2145 controller().window_id(), controller().session_id(), false);
2146
2147 ReopenDatabase();
2148 Time close_time;
2149
2150 session_helper_.ReadWindows(&windows_);
2151 }
2152
2153 CancelableRequestConsumer consumer;
2154
2155 // URLs for testing.
2156 const GURL url0;
2157 const GURL url1;
2158 const GURL url2;
2159
2160 std::vector<SessionWindow*> windows_;
2161
2162 SessionID window_id;
2163
2164 SessionServiceTestHelper session_helper_;
2165
2166 private:
2167 ProfileManager* profile_manager_;
2168 FilePath test_dir_;
2169 };
2170
2169 // A basic test case. Navigates to a single url, and make sure the history 2171 // A basic test case. Navigates to a single url, and make sure the history
2170 // db matches. 2172 // db matches.
2171 TEST_F(NavigationControllerHistoryTest, Basic) { 2173 TEST_F(NavigationControllerHistoryTest, Basic) {
2172 controller().LoadURL(url0, GURL(), PageTransition::LINK); 2174 controller().LoadURL(url0, GURL(), PageTransition::LINK);
2173 rvh()->SendNavigate(0, url0); 2175 rvh()->SendNavigate(0, url0);
2174 2176
2175 GetLastSession(); 2177 GetLastSession();
2176 2178
2177 session_helper_.AssertSingleWindowWithSingleTab(windows_, 1); 2179 session_helper_.AssertSingleWindowWithSingleTab(windows_, 1);
2178 session_helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); 2180 session_helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0]));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 TabNavigation nav(0, url0, GURL(), string16(), 2237 TabNavigation nav(0, url0, GURL(), string16(),
2236 webkit_glue::CreateHistoryStateForURL(url0), 2238 webkit_glue::CreateHistoryStateForURL(url0),
2237 PageTransition::LINK); 2239 PageTransition::LINK);
2238 session_helper_.AssertNavigationEquals(nav, 2240 session_helper_.AssertNavigationEquals(nav,
2239 windows_[0]->tabs[0]->navigations[0]); 2241 windows_[0]->tabs[0]->navigations[0]);
2240 nav.set_url(url2); 2242 nav.set_url(url2);
2241 session_helper_.AssertNavigationEquals(nav, 2243 session_helper_.AssertNavigationEquals(nav,
2242 windows_[0]->tabs[0]->navigations[1]); 2244 windows_[0]->tabs[0]->navigations[1]);
2243 } 2245 }
2244 */ 2246 */
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_browsertest.cc ('k') | content/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698