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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 // NavigationControllerTest ---------------------------------------------------- | 37 // NavigationControllerTest ---------------------------------------------------- |
38 | 38 |
39 class NavigationControllerTest : public RenderViewHostTestHarness { | 39 class NavigationControllerTest : public RenderViewHostTestHarness { |
40 public: | 40 public: |
41 NavigationControllerTest() {} | 41 NavigationControllerTest() {} |
42 }; | 42 }; |
43 | 43 |
44 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, | 44 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
45 NavigationController* controller) { | 45 NavigationController* controller) { |
46 tracker->ListenFor(NotificationType::NAV_ENTRY_COMMITTED, | 46 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
47 Source<NavigationController>(controller)); | 47 Source<NavigationController>(controller)); |
48 tracker->ListenFor(NotificationType::NAV_LIST_PRUNED, | 48 tracker->ListenFor(content::NOTIFICATION_NAV_LIST_PRUNED, |
49 Source<NavigationController>(controller)); | 49 Source<NavigationController>(controller)); |
50 tracker->ListenFor(NotificationType::NAV_ENTRY_CHANGED, | 50 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_CHANGED, |
51 Source<NavigationController>(controller)); | 51 Source<NavigationController>(controller)); |
52 } | 52 } |
53 | 53 |
54 class TestTabContentsDelegate : public TabContentsDelegate { | 54 class TestTabContentsDelegate : public TabContentsDelegate { |
55 public: | 55 public: |
56 explicit TestTabContentsDelegate() : | 56 explicit TestTabContentsDelegate() : |
57 navigation_state_change_count_(0) {} | 57 navigation_state_change_count_(0) {} |
58 | 58 |
59 int navigation_state_change_count() { | 59 int navigation_state_change_count() { |
60 return navigation_state_change_count_; | 60 return navigation_state_change_count_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 EXPECT_TRUE(controller().pending_entry()); | 103 EXPECT_TRUE(controller().pending_entry()); |
104 EXPECT_FALSE(controller().CanGoBack()); | 104 EXPECT_FALSE(controller().CanGoBack()); |
105 EXPECT_FALSE(controller().CanGoForward()); | 105 EXPECT_FALSE(controller().CanGoForward()); |
106 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 106 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
107 | 107 |
108 // We should have gotten no notifications from the preceeding checks. | 108 // We should have gotten no notifications from the preceeding checks. |
109 EXPECT_EQ(0U, notifications.size()); | 109 EXPECT_EQ(0U, notifications.size()); |
110 | 110 |
111 rvh()->SendNavigate(0, url1); | 111 rvh()->SendNavigate(0, url1); |
112 EXPECT_TRUE(notifications.Check1AndReset( | 112 EXPECT_TRUE(notifications.Check1AndReset( |
113 NotificationType::NAV_ENTRY_COMMITTED)); | 113 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
114 | 114 |
115 // The load should now be committed. | 115 // The load should now be committed. |
116 EXPECT_EQ(controller().entry_count(), 1); | 116 EXPECT_EQ(controller().entry_count(), 1); |
117 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 117 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
118 EXPECT_EQ(controller().pending_entry_index(), -1); | 118 EXPECT_EQ(controller().pending_entry_index(), -1); |
119 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 119 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
120 EXPECT_FALSE(controller().pending_entry()); | 120 EXPECT_FALSE(controller().pending_entry()); |
121 EXPECT_FALSE(controller().CanGoBack()); | 121 EXPECT_FALSE(controller().CanGoBack()); |
122 EXPECT_FALSE(controller().CanGoForward()); | 122 EXPECT_FALSE(controller().CanGoForward()); |
123 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 123 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
(...skipping 10 matching lines...) Expand all Loading... |
134 // TODO(darin): maybe this should really be true? | 134 // TODO(darin): maybe this should really be true? |
135 EXPECT_FALSE(controller().CanGoBack()); | 135 EXPECT_FALSE(controller().CanGoBack()); |
136 EXPECT_FALSE(controller().CanGoForward()); | 136 EXPECT_FALSE(controller().CanGoForward()); |
137 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 137 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
138 | 138 |
139 // Simulate the beforeunload ack for the cross-site transition, and then the | 139 // Simulate the beforeunload ack for the cross-site transition, and then the |
140 // commit. | 140 // commit. |
141 rvh()->SendShouldCloseACK(true); | 141 rvh()->SendShouldCloseACK(true); |
142 contents()->pending_rvh()->SendNavigate(1, url2); | 142 contents()->pending_rvh()->SendNavigate(1, url2); |
143 EXPECT_TRUE(notifications.Check1AndReset( | 143 EXPECT_TRUE(notifications.Check1AndReset( |
144 NotificationType::NAV_ENTRY_COMMITTED)); | 144 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
145 | 145 |
146 // The load should now be committed. | 146 // The load should now be committed. |
147 EXPECT_EQ(controller().entry_count(), 2); | 147 EXPECT_EQ(controller().entry_count(), 2); |
148 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 148 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
149 EXPECT_EQ(controller().pending_entry_index(), -1); | 149 EXPECT_EQ(controller().pending_entry_index(), -1); |
150 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 150 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
151 EXPECT_FALSE(controller().pending_entry()); | 151 EXPECT_FALSE(controller().pending_entry()); |
152 EXPECT_TRUE(controller().CanGoBack()); | 152 EXPECT_TRUE(controller().CanGoBack()); |
153 EXPECT_FALSE(controller().CanGoForward()); | 153 EXPECT_FALSE(controller().CanGoForward()); |
154 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 154 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
155 } | 155 } |
156 | 156 |
157 // Tests what happens when the same page is loaded again. Should not create a | 157 // Tests what happens when the same page is loaded again. Should not create a |
158 // new session history entry. This is what happens when you press enter in the | 158 // new session history entry. This is what happens when you press enter in the |
159 // URL bar to reload: a pending entry is created and then it is discarded when | 159 // URL bar to reload: a pending entry is created and then it is discarded when |
160 // the load commits (because WebCore didn't actually make a new entry). | 160 // the load commits (because WebCore didn't actually make a new entry). |
161 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 161 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
162 TestNotificationTracker notifications; | 162 TestNotificationTracker notifications; |
163 RegisterForAllNavNotifications(¬ifications, &controller()); | 163 RegisterForAllNavNotifications(¬ifications, &controller()); |
164 | 164 |
165 const GURL url1("http://foo1"); | 165 const GURL url1("http://foo1"); |
166 | 166 |
167 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 167 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
168 EXPECT_EQ(0U, notifications.size()); | 168 EXPECT_EQ(0U, notifications.size()); |
169 rvh()->SendNavigate(0, url1); | 169 rvh()->SendNavigate(0, url1); |
170 EXPECT_TRUE(notifications.Check1AndReset( | 170 EXPECT_TRUE(notifications.Check1AndReset( |
171 NotificationType::NAV_ENTRY_COMMITTED)); | 171 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
172 | 172 |
173 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 173 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
174 EXPECT_EQ(0U, notifications.size()); | 174 EXPECT_EQ(0U, notifications.size()); |
175 rvh()->SendNavigate(0, url1); | 175 rvh()->SendNavigate(0, url1); |
176 EXPECT_TRUE(notifications.Check1AndReset( | 176 EXPECT_TRUE(notifications.Check1AndReset( |
177 NotificationType::NAV_ENTRY_COMMITTED)); | 177 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
178 | 178 |
179 // We should not have produced a new session history entry. | 179 // We should not have produced a new session history entry. |
180 EXPECT_EQ(controller().entry_count(), 1); | 180 EXPECT_EQ(controller().entry_count(), 1); |
181 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 181 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
182 EXPECT_EQ(controller().pending_entry_index(), -1); | 182 EXPECT_EQ(controller().pending_entry_index(), -1); |
183 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 183 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
184 EXPECT_FALSE(controller().pending_entry()); | 184 EXPECT_FALSE(controller().pending_entry()); |
185 EXPECT_FALSE(controller().CanGoBack()); | 185 EXPECT_FALSE(controller().CanGoBack()); |
186 EXPECT_FALSE(controller().CanGoForward()); | 186 EXPECT_FALSE(controller().CanGoForward()); |
187 } | 187 } |
188 | 188 |
189 // Tests loading a URL but discarding it before the load commits. | 189 // Tests loading a URL but discarding it before the load commits. |
190 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 190 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
191 TestNotificationTracker notifications; | 191 TestNotificationTracker notifications; |
192 RegisterForAllNavNotifications(¬ifications, &controller()); | 192 RegisterForAllNavNotifications(¬ifications, &controller()); |
193 | 193 |
194 const GURL url1("http://foo1"); | 194 const GURL url1("http://foo1"); |
195 const GURL url2("http://foo2"); | 195 const GURL url2("http://foo2"); |
196 | 196 |
197 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 197 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
198 EXPECT_EQ(0U, notifications.size()); | 198 EXPECT_EQ(0U, notifications.size()); |
199 rvh()->SendNavigate(0, url1); | 199 rvh()->SendNavigate(0, url1); |
200 EXPECT_TRUE(notifications.Check1AndReset( | 200 EXPECT_TRUE(notifications.Check1AndReset( |
201 NotificationType::NAV_ENTRY_COMMITTED)); | 201 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
202 | 202 |
203 controller().LoadURL(url2, GURL(), PageTransition::TYPED); | 203 controller().LoadURL(url2, GURL(), PageTransition::TYPED); |
204 controller().DiscardNonCommittedEntries(); | 204 controller().DiscardNonCommittedEntries(); |
205 EXPECT_EQ(0U, notifications.size()); | 205 EXPECT_EQ(0U, notifications.size()); |
206 | 206 |
207 // Should not have produced a new session history entry. | 207 // Should not have produced a new session history entry. |
208 EXPECT_EQ(controller().entry_count(), 1); | 208 EXPECT_EQ(controller().entry_count(), 1); |
209 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 209 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
210 EXPECT_EQ(controller().pending_entry_index(), -1); | 210 EXPECT_EQ(controller().pending_entry_index(), -1); |
211 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 211 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
212 EXPECT_FALSE(controller().pending_entry()); | 212 EXPECT_FALSE(controller().pending_entry()); |
213 EXPECT_FALSE(controller().CanGoBack()); | 213 EXPECT_FALSE(controller().CanGoBack()); |
214 EXPECT_FALSE(controller().CanGoForward()); | 214 EXPECT_FALSE(controller().CanGoForward()); |
215 } | 215 } |
216 | 216 |
217 // Tests navigations that come in unrequested. This happens when the user | 217 // Tests navigations that come in unrequested. This happens when the user |
218 // navigates from the web page, and here we test that there is no pending entry. | 218 // navigates from the web page, and here we test that there is no pending entry. |
219 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 219 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
220 TestNotificationTracker notifications; | 220 TestNotificationTracker notifications; |
221 RegisterForAllNavNotifications(¬ifications, &controller()); | 221 RegisterForAllNavNotifications(¬ifications, &controller()); |
222 | 222 |
223 // First make an existing committed entry. | 223 // First make an existing committed entry. |
224 const GURL kExistingURL1("http://eh"); | 224 const GURL kExistingURL1("http://eh"); |
225 controller().LoadURL(kExistingURL1, GURL(), | 225 controller().LoadURL(kExistingURL1, GURL(), |
226 PageTransition::TYPED); | 226 PageTransition::TYPED); |
227 rvh()->SendNavigate(0, kExistingURL1); | 227 rvh()->SendNavigate(0, kExistingURL1); |
228 EXPECT_TRUE(notifications.Check1AndReset( | 228 EXPECT_TRUE(notifications.Check1AndReset( |
229 NotificationType::NAV_ENTRY_COMMITTED)); | 229 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
230 | 230 |
231 // Do a new navigation without making a pending one. | 231 // Do a new navigation without making a pending one. |
232 const GURL kNewURL("http://see"); | 232 const GURL kNewURL("http://see"); |
233 rvh()->SendNavigate(99, kNewURL); | 233 rvh()->SendNavigate(99, kNewURL); |
234 | 234 |
235 // There should no longer be any pending entry, and the third navigation we | 235 // There should no longer be any pending entry, and the third navigation we |
236 // just made should be committed. | 236 // just made should be committed. |
237 EXPECT_TRUE(notifications.Check1AndReset( | 237 EXPECT_TRUE(notifications.Check1AndReset( |
238 NotificationType::NAV_ENTRY_COMMITTED)); | 238 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
239 EXPECT_EQ(-1, controller().pending_entry_index()); | 239 EXPECT_EQ(-1, controller().pending_entry_index()); |
240 EXPECT_EQ(1, controller().last_committed_entry_index()); | 240 EXPECT_EQ(1, controller().last_committed_entry_index()); |
241 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); | 241 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); |
242 } | 242 } |
243 | 243 |
244 // Tests navigating to a new URL when there is a new pending navigation that is | 244 // Tests navigating to a new URL when there is a new pending navigation that is |
245 // not the one that just loaded. This will happen if the user types in a URL to | 245 // not the one that just loaded. This will happen if the user types in a URL to |
246 // somewhere slow, and then navigates the current page before the typed URL | 246 // somewhere slow, and then navigates the current page before the typed URL |
247 // commits. | 247 // commits. |
248 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 248 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
249 TestNotificationTracker notifications; | 249 TestNotificationTracker notifications; |
250 RegisterForAllNavNotifications(¬ifications, &controller()); | 250 RegisterForAllNavNotifications(¬ifications, &controller()); |
251 | 251 |
252 // First make an existing committed entry. | 252 // First make an existing committed entry. |
253 const GURL kExistingURL1("http://eh"); | 253 const GURL kExistingURL1("http://eh"); |
254 controller().LoadURL(kExistingURL1, GURL(), | 254 controller().LoadURL(kExistingURL1, GURL(), |
255 PageTransition::TYPED); | 255 PageTransition::TYPED); |
256 rvh()->SendNavigate(0, kExistingURL1); | 256 rvh()->SendNavigate(0, kExistingURL1); |
257 EXPECT_TRUE(notifications.Check1AndReset( | 257 EXPECT_TRUE(notifications.Check1AndReset( |
258 NotificationType::NAV_ENTRY_COMMITTED)); | 258 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
259 | 259 |
260 // Make a pending entry to somewhere new. | 260 // Make a pending entry to somewhere new. |
261 const GURL kExistingURL2("http://bee"); | 261 const GURL kExistingURL2("http://bee"); |
262 controller().LoadURL(kExistingURL2, GURL(), | 262 controller().LoadURL(kExistingURL2, GURL(), |
263 PageTransition::TYPED); | 263 PageTransition::TYPED); |
264 EXPECT_EQ(0U, notifications.size()); | 264 EXPECT_EQ(0U, notifications.size()); |
265 | 265 |
266 // After the beforeunload but before it commits, do a new navigation. | 266 // After the beforeunload but before it commits, do a new navigation. |
267 rvh()->SendShouldCloseACK(true); | 267 rvh()->SendShouldCloseACK(true); |
268 const GURL kNewURL("http://see"); | 268 const GURL kNewURL("http://see"); |
269 contents()->pending_rvh()->SendNavigate(3, kNewURL); | 269 contents()->pending_rvh()->SendNavigate(3, kNewURL); |
270 | 270 |
271 // There should no longer be any pending entry, and the third navigation we | 271 // There should no longer be any pending entry, and the third navigation we |
272 // just made should be committed. | 272 // just made should be committed. |
273 EXPECT_TRUE(notifications.Check1AndReset( | 273 EXPECT_TRUE(notifications.Check1AndReset( |
274 NotificationType::NAV_ENTRY_COMMITTED)); | 274 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
275 EXPECT_EQ(-1, controller().pending_entry_index()); | 275 EXPECT_EQ(-1, controller().pending_entry_index()); |
276 EXPECT_EQ(1, controller().last_committed_entry_index()); | 276 EXPECT_EQ(1, controller().last_committed_entry_index()); |
277 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); | 277 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); |
278 } | 278 } |
279 | 279 |
280 // Tests navigating to a new URL when there is a pending back/forward | 280 // Tests navigating to a new URL when there is a pending back/forward |
281 // navigation. This will happen if the user hits back, but before that commits, | 281 // navigation. This will happen if the user hits back, but before that commits, |
282 // they navigate somewhere new. | 282 // they navigate somewhere new. |
283 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 283 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
284 TestNotificationTracker notifications; | 284 TestNotificationTracker notifications; |
285 RegisterForAllNavNotifications(¬ifications, &controller()); | 285 RegisterForAllNavNotifications(¬ifications, &controller()); |
286 | 286 |
287 // First make some history. | 287 // First make some history. |
288 const GURL kExistingURL1("http://foo/eh"); | 288 const GURL kExistingURL1("http://foo/eh"); |
289 controller().LoadURL(kExistingURL1, GURL(), | 289 controller().LoadURL(kExistingURL1, GURL(), |
290 PageTransition::TYPED); | 290 PageTransition::TYPED); |
291 rvh()->SendNavigate(0, kExistingURL1); | 291 rvh()->SendNavigate(0, kExistingURL1); |
292 EXPECT_TRUE(notifications.Check1AndReset( | 292 EXPECT_TRUE(notifications.Check1AndReset( |
293 NotificationType::NAV_ENTRY_COMMITTED)); | 293 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
294 | 294 |
295 const GURL kExistingURL2("http://foo/bee"); | 295 const GURL kExistingURL2("http://foo/bee"); |
296 controller().LoadURL(kExistingURL2, GURL(), | 296 controller().LoadURL(kExistingURL2, GURL(), |
297 PageTransition::TYPED); | 297 PageTransition::TYPED); |
298 rvh()->SendNavigate(1, kExistingURL2); | 298 rvh()->SendNavigate(1, kExistingURL2); |
299 EXPECT_TRUE(notifications.Check1AndReset( | 299 EXPECT_TRUE(notifications.Check1AndReset( |
300 NotificationType::NAV_ENTRY_COMMITTED)); | 300 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
301 | 301 |
302 // Now make a pending back/forward navigation. The zeroth entry should be | 302 // Now make a pending back/forward navigation. The zeroth entry should be |
303 // pending. | 303 // pending. |
304 controller().GoBack(); | 304 controller().GoBack(); |
305 EXPECT_EQ(0U, notifications.size()); | 305 EXPECT_EQ(0U, notifications.size()); |
306 EXPECT_EQ(0, controller().pending_entry_index()); | 306 EXPECT_EQ(0, controller().pending_entry_index()); |
307 EXPECT_EQ(1, controller().last_committed_entry_index()); | 307 EXPECT_EQ(1, controller().last_committed_entry_index()); |
308 | 308 |
309 // Before that commits, do a new navigation. | 309 // Before that commits, do a new navigation. |
310 const GURL kNewURL("http://foo/see"); | 310 const GURL kNewURL("http://foo/see"); |
311 content::LoadCommittedDetails details; | 311 content::LoadCommittedDetails details; |
312 rvh()->SendNavigate(3, kNewURL); | 312 rvh()->SendNavigate(3, kNewURL); |
313 | 313 |
314 // There should no longer be any pending entry, and the third navigation we | 314 // There should no longer be any pending entry, and the third navigation we |
315 // just made should be committed. | 315 // just made should be committed. |
316 EXPECT_TRUE(notifications.Check1AndReset( | 316 EXPECT_TRUE(notifications.Check1AndReset( |
317 NotificationType::NAV_ENTRY_COMMITTED)); | 317 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
318 EXPECT_EQ(-1, controller().pending_entry_index()); | 318 EXPECT_EQ(-1, controller().pending_entry_index()); |
319 EXPECT_EQ(2, controller().last_committed_entry_index()); | 319 EXPECT_EQ(2, controller().last_committed_entry_index()); |
320 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); | 320 EXPECT_EQ(kNewURL, controller().GetActiveEntry()->url()); |
321 } | 321 } |
322 | 322 |
323 // Tests navigating to an existing URL when there is a pending new navigation. | 323 // Tests navigating to an existing URL when there is a pending new navigation. |
324 // This will happen if the user enters a URL, but before that commits, the | 324 // This will happen if the user enters a URL, but before that commits, the |
325 // current page fires history.back(). | 325 // current page fires history.back(). |
326 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 326 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
327 TestNotificationTracker notifications; | 327 TestNotificationTracker notifications; |
328 RegisterForAllNavNotifications(¬ifications, &controller()); | 328 RegisterForAllNavNotifications(¬ifications, &controller()); |
329 | 329 |
330 // First make some history. | 330 // First make some history. |
331 const GURL kExistingURL1("http://foo/eh"); | 331 const GURL kExistingURL1("http://foo/eh"); |
332 controller().LoadURL(kExistingURL1, GURL(), PageTransition::TYPED); | 332 controller().LoadURL(kExistingURL1, GURL(), PageTransition::TYPED); |
333 rvh()->SendNavigate(0, kExistingURL1); | 333 rvh()->SendNavigate(0, kExistingURL1); |
334 EXPECT_TRUE(notifications.Check1AndReset( | 334 EXPECT_TRUE(notifications.Check1AndReset( |
335 NotificationType::NAV_ENTRY_COMMITTED)); | 335 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
336 | 336 |
337 const GURL kExistingURL2("http://foo/bee"); | 337 const GURL kExistingURL2("http://foo/bee"); |
338 controller().LoadURL(kExistingURL2, GURL(), PageTransition::TYPED); | 338 controller().LoadURL(kExistingURL2, GURL(), PageTransition::TYPED); |
339 rvh()->SendNavigate(1, kExistingURL2); | 339 rvh()->SendNavigate(1, kExistingURL2); |
340 EXPECT_TRUE(notifications.Check1AndReset( | 340 EXPECT_TRUE(notifications.Check1AndReset( |
341 NotificationType::NAV_ENTRY_COMMITTED)); | 341 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
342 | 342 |
343 // Now make a pending new navigation. | 343 // Now make a pending new navigation. |
344 const GURL kNewURL("http://foo/see"); | 344 const GURL kNewURL("http://foo/see"); |
345 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED); | 345 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED); |
346 EXPECT_EQ(0U, notifications.size()); | 346 EXPECT_EQ(0U, notifications.size()); |
347 EXPECT_EQ(-1, controller().pending_entry_index()); | 347 EXPECT_EQ(-1, controller().pending_entry_index()); |
348 EXPECT_EQ(1, controller().last_committed_entry_index()); | 348 EXPECT_EQ(1, controller().last_committed_entry_index()); |
349 | 349 |
350 // Before that commits, a back navigation from the renderer commits. | 350 // Before that commits, a back navigation from the renderer commits. |
351 rvh()->SendNavigate(0, kExistingURL1); | 351 rvh()->SendNavigate(0, kExistingURL1); |
352 | 352 |
353 // There should no longer be any pending entry, and the back navigation we | 353 // There should no longer be any pending entry, and the back navigation we |
354 // just made should be committed. | 354 // just made should be committed. |
355 EXPECT_TRUE(notifications.Check1AndReset( | 355 EXPECT_TRUE(notifications.Check1AndReset( |
356 NotificationType::NAV_ENTRY_COMMITTED)); | 356 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
357 EXPECT_EQ(-1, controller().pending_entry_index()); | 357 EXPECT_EQ(-1, controller().pending_entry_index()); |
358 EXPECT_EQ(0, controller().last_committed_entry_index()); | 358 EXPECT_EQ(0, controller().last_committed_entry_index()); |
359 EXPECT_EQ(kExistingURL1, controller().GetActiveEntry()->url()); | 359 EXPECT_EQ(kExistingURL1, controller().GetActiveEntry()->url()); |
360 } | 360 } |
361 | 361 |
362 // Tests an ignored navigation when there is a pending new navigation. | 362 // Tests an ignored navigation when there is a pending new navigation. |
363 // This will happen if the user enters a URL, but before that commits, the | 363 // This will happen if the user enters a URL, but before that commits, the |
364 // current blank page reloads. See http://crbug.com/77507. | 364 // current blank page reloads. See http://crbug.com/77507. |
365 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { | 365 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { |
366 TestNotificationTracker notifications; | 366 TestNotificationTracker notifications; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 TEST_F(NavigationControllerTest, Reload) { | 498 TEST_F(NavigationControllerTest, Reload) { |
499 TestNotificationTracker notifications; | 499 TestNotificationTracker notifications; |
500 RegisterForAllNavNotifications(¬ifications, &controller()); | 500 RegisterForAllNavNotifications(¬ifications, &controller()); |
501 | 501 |
502 const GURL url1("http://foo1"); | 502 const GURL url1("http://foo1"); |
503 | 503 |
504 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 504 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
505 EXPECT_EQ(0U, notifications.size()); | 505 EXPECT_EQ(0U, notifications.size()); |
506 rvh()->SendNavigate(0, url1); | 506 rvh()->SendNavigate(0, url1); |
507 EXPECT_TRUE(notifications.Check1AndReset( | 507 EXPECT_TRUE(notifications.Check1AndReset( |
508 NotificationType::NAV_ENTRY_COMMITTED)); | 508 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
509 | 509 |
510 controller().Reload(true); | 510 controller().Reload(true); |
511 EXPECT_EQ(0U, notifications.size()); | 511 EXPECT_EQ(0U, notifications.size()); |
512 | 512 |
513 // The reload is pending. | 513 // The reload is pending. |
514 EXPECT_EQ(controller().entry_count(), 1); | 514 EXPECT_EQ(controller().entry_count(), 1); |
515 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 515 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
516 EXPECT_EQ(controller().pending_entry_index(), 0); | 516 EXPECT_EQ(controller().pending_entry_index(), 0); |
517 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 517 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
518 EXPECT_TRUE(controller().pending_entry()); | 518 EXPECT_TRUE(controller().pending_entry()); |
519 EXPECT_FALSE(controller().CanGoBack()); | 519 EXPECT_FALSE(controller().CanGoBack()); |
520 EXPECT_FALSE(controller().CanGoForward()); | 520 EXPECT_FALSE(controller().CanGoForward()); |
521 | 521 |
522 rvh()->SendNavigate(0, url1); | 522 rvh()->SendNavigate(0, url1); |
523 EXPECT_TRUE(notifications.Check1AndReset( | 523 EXPECT_TRUE(notifications.Check1AndReset( |
524 NotificationType::NAV_ENTRY_COMMITTED)); | 524 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
525 | 525 |
526 // Now the reload is committed. | 526 // Now the reload is committed. |
527 EXPECT_EQ(controller().entry_count(), 1); | 527 EXPECT_EQ(controller().entry_count(), 1); |
528 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 528 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
529 EXPECT_EQ(controller().pending_entry_index(), -1); | 529 EXPECT_EQ(controller().pending_entry_index(), -1); |
530 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 530 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
531 EXPECT_FALSE(controller().pending_entry()); | 531 EXPECT_FALSE(controller().pending_entry()); |
532 EXPECT_FALSE(controller().CanGoBack()); | 532 EXPECT_FALSE(controller().CanGoBack()); |
533 EXPECT_FALSE(controller().CanGoForward()); | 533 EXPECT_FALSE(controller().CanGoForward()); |
534 } | 534 } |
535 | 535 |
536 // Tests what happens when a reload navigation produces a new page. | 536 // Tests what happens when a reload navigation produces a new page. |
537 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 537 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
538 TestNotificationTracker notifications; | 538 TestNotificationTracker notifications; |
539 RegisterForAllNavNotifications(¬ifications, &controller()); | 539 RegisterForAllNavNotifications(¬ifications, &controller()); |
540 | 540 |
541 const GURL url1("http://foo1"); | 541 const GURL url1("http://foo1"); |
542 const GURL url2("http://foo2"); | 542 const GURL url2("http://foo2"); |
543 | 543 |
544 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 544 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
545 rvh()->SendNavigate(0, url1); | 545 rvh()->SendNavigate(0, url1); |
546 EXPECT_TRUE(notifications.Check1AndReset( | 546 EXPECT_TRUE(notifications.Check1AndReset( |
547 NotificationType::NAV_ENTRY_COMMITTED)); | 547 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
548 | 548 |
549 controller().Reload(true); | 549 controller().Reload(true); |
550 EXPECT_EQ(0U, notifications.size()); | 550 EXPECT_EQ(0U, notifications.size()); |
551 | 551 |
552 rvh()->SendNavigate(1, url2); | 552 rvh()->SendNavigate(1, url2); |
553 EXPECT_TRUE(notifications.Check1AndReset( | 553 EXPECT_TRUE(notifications.Check1AndReset( |
554 NotificationType::NAV_ENTRY_COMMITTED)); | 554 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
555 | 555 |
556 // Now the reload is committed. | 556 // Now the reload is committed. |
557 EXPECT_EQ(controller().entry_count(), 2); | 557 EXPECT_EQ(controller().entry_count(), 2); |
558 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 558 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
559 EXPECT_EQ(controller().pending_entry_index(), -1); | 559 EXPECT_EQ(controller().pending_entry_index(), -1); |
560 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 560 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
561 EXPECT_FALSE(controller().pending_entry()); | 561 EXPECT_FALSE(controller().pending_entry()); |
562 EXPECT_TRUE(controller().CanGoBack()); | 562 EXPECT_TRUE(controller().CanGoBack()); |
563 EXPECT_FALSE(controller().CanGoForward()); | 563 EXPECT_FALSE(controller().CanGoForward()); |
564 } | 564 } |
565 | 565 |
566 // Tests what happens when we navigate back successfully | 566 // Tests what happens when we navigate back successfully |
567 TEST_F(NavigationControllerTest, Back) { | 567 TEST_F(NavigationControllerTest, Back) { |
568 TestNotificationTracker notifications; | 568 TestNotificationTracker notifications; |
569 RegisterForAllNavNotifications(¬ifications, &controller()); | 569 RegisterForAllNavNotifications(¬ifications, &controller()); |
570 | 570 |
571 const GURL url1("http://foo1"); | 571 const GURL url1("http://foo1"); |
572 rvh()->SendNavigate(0, url1); | 572 rvh()->SendNavigate(0, url1); |
573 EXPECT_TRUE(notifications.Check1AndReset( | 573 EXPECT_TRUE(notifications.Check1AndReset( |
574 NotificationType::NAV_ENTRY_COMMITTED)); | 574 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
575 | 575 |
576 const GURL url2("http://foo2"); | 576 const GURL url2("http://foo2"); |
577 rvh()->SendNavigate(1, url2); | 577 rvh()->SendNavigate(1, url2); |
578 EXPECT_TRUE(notifications.Check1AndReset( | 578 EXPECT_TRUE(notifications.Check1AndReset( |
579 NotificationType::NAV_ENTRY_COMMITTED)); | 579 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
580 | 580 |
581 controller().GoBack(); | 581 controller().GoBack(); |
582 EXPECT_EQ(0U, notifications.size()); | 582 EXPECT_EQ(0U, notifications.size()); |
583 | 583 |
584 // We should now have a pending navigation to go back. | 584 // We should now have a pending navigation to go back. |
585 EXPECT_EQ(controller().entry_count(), 2); | 585 EXPECT_EQ(controller().entry_count(), 2); |
586 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 586 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
587 EXPECT_EQ(controller().pending_entry_index(), 0); | 587 EXPECT_EQ(controller().pending_entry_index(), 0); |
588 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 588 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
589 EXPECT_TRUE(controller().pending_entry()); | 589 EXPECT_TRUE(controller().pending_entry()); |
590 EXPECT_FALSE(controller().CanGoBack()); | 590 EXPECT_FALSE(controller().CanGoBack()); |
591 EXPECT_TRUE(controller().CanGoForward()); | 591 EXPECT_TRUE(controller().CanGoForward()); |
592 | 592 |
593 rvh()->SendNavigate(0, url2); | 593 rvh()->SendNavigate(0, url2); |
594 EXPECT_TRUE(notifications.Check1AndReset( | 594 EXPECT_TRUE(notifications.Check1AndReset( |
595 NotificationType::NAV_ENTRY_COMMITTED)); | 595 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
596 | 596 |
597 // The back navigation completed successfully. | 597 // The back navigation completed successfully. |
598 EXPECT_EQ(controller().entry_count(), 2); | 598 EXPECT_EQ(controller().entry_count(), 2); |
599 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 599 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
600 EXPECT_EQ(controller().pending_entry_index(), -1); | 600 EXPECT_EQ(controller().pending_entry_index(), -1); |
601 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 601 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
602 EXPECT_FALSE(controller().pending_entry()); | 602 EXPECT_FALSE(controller().pending_entry()); |
603 EXPECT_FALSE(controller().CanGoBack()); | 603 EXPECT_FALSE(controller().CanGoBack()); |
604 EXPECT_TRUE(controller().CanGoForward()); | 604 EXPECT_TRUE(controller().CanGoForward()); |
605 } | 605 } |
606 | 606 |
607 // Tests what happens when a back navigation produces a new page. | 607 // Tests what happens when a back navigation produces a new page. |
608 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { | 608 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { |
609 TestNotificationTracker notifications; | 609 TestNotificationTracker notifications; |
610 RegisterForAllNavNotifications(¬ifications, &controller()); | 610 RegisterForAllNavNotifications(¬ifications, &controller()); |
611 | 611 |
612 const GURL url1("http://foo/1"); | 612 const GURL url1("http://foo/1"); |
613 const GURL url2("http://foo/2"); | 613 const GURL url2("http://foo/2"); |
614 const GURL url3("http://foo/3"); | 614 const GURL url3("http://foo/3"); |
615 | 615 |
616 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 616 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
617 rvh()->SendNavigate(0, url1); | 617 rvh()->SendNavigate(0, url1); |
618 EXPECT_TRUE(notifications.Check1AndReset( | 618 EXPECT_TRUE(notifications.Check1AndReset( |
619 NotificationType::NAV_ENTRY_COMMITTED)); | 619 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
620 | 620 |
621 controller().LoadURL(url2, GURL(), PageTransition::TYPED); | 621 controller().LoadURL(url2, GURL(), PageTransition::TYPED); |
622 rvh()->SendNavigate(1, url2); | 622 rvh()->SendNavigate(1, url2); |
623 EXPECT_TRUE(notifications.Check1AndReset( | 623 EXPECT_TRUE(notifications.Check1AndReset( |
624 NotificationType::NAV_ENTRY_COMMITTED)); | 624 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
625 | 625 |
626 controller().GoBack(); | 626 controller().GoBack(); |
627 EXPECT_EQ(0U, notifications.size()); | 627 EXPECT_EQ(0U, notifications.size()); |
628 | 628 |
629 // We should now have a pending navigation to go back. | 629 // We should now have a pending navigation to go back. |
630 EXPECT_EQ(controller().entry_count(), 2); | 630 EXPECT_EQ(controller().entry_count(), 2); |
631 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 631 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
632 EXPECT_EQ(controller().pending_entry_index(), 0); | 632 EXPECT_EQ(controller().pending_entry_index(), 0); |
633 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 633 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
634 EXPECT_TRUE(controller().pending_entry()); | 634 EXPECT_TRUE(controller().pending_entry()); |
635 EXPECT_FALSE(controller().CanGoBack()); | 635 EXPECT_FALSE(controller().CanGoBack()); |
636 EXPECT_TRUE(controller().CanGoForward()); | 636 EXPECT_TRUE(controller().CanGoForward()); |
637 | 637 |
638 rvh()->SendNavigate(2, url3); | 638 rvh()->SendNavigate(2, url3); |
639 EXPECT_TRUE(notifications.Check1AndReset( | 639 EXPECT_TRUE(notifications.Check1AndReset( |
640 NotificationType::NAV_ENTRY_COMMITTED)); | 640 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
641 | 641 |
642 // The back navigation resulted in a completely new navigation. | 642 // The back navigation resulted in a completely new navigation. |
643 // TODO(darin): perhaps this behavior will be confusing to users? | 643 // TODO(darin): perhaps this behavior will be confusing to users? |
644 EXPECT_EQ(controller().entry_count(), 3); | 644 EXPECT_EQ(controller().entry_count(), 3); |
645 EXPECT_EQ(controller().last_committed_entry_index(), 2); | 645 EXPECT_EQ(controller().last_committed_entry_index(), 2); |
646 EXPECT_EQ(controller().pending_entry_index(), -1); | 646 EXPECT_EQ(controller().pending_entry_index(), -1); |
647 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 647 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
648 EXPECT_FALSE(controller().pending_entry()); | 648 EXPECT_FALSE(controller().pending_entry()); |
649 EXPECT_TRUE(controller().CanGoBack()); | 649 EXPECT_TRUE(controller().CanGoBack()); |
650 EXPECT_FALSE(controller().CanGoForward()); | 650 EXPECT_FALSE(controller().CanGoForward()); |
651 } | 651 } |
652 | 652 |
653 // Receives a back message when there is a new pending navigation entry. | 653 // Receives a back message when there is a new pending navigation entry. |
654 TEST_F(NavigationControllerTest, Back_NewPending) { | 654 TEST_F(NavigationControllerTest, Back_NewPending) { |
655 TestNotificationTracker notifications; | 655 TestNotificationTracker notifications; |
656 RegisterForAllNavNotifications(¬ifications, &controller()); | 656 RegisterForAllNavNotifications(¬ifications, &controller()); |
657 | 657 |
658 const GURL kUrl1("http://foo1"); | 658 const GURL kUrl1("http://foo1"); |
659 const GURL kUrl2("http://foo2"); | 659 const GURL kUrl2("http://foo2"); |
660 const GURL kUrl3("http://foo3"); | 660 const GURL kUrl3("http://foo3"); |
661 | 661 |
662 // First navigate two places so we have some back history. | 662 // First navigate two places so we have some back history. |
663 rvh()->SendNavigate(0, kUrl1); | 663 rvh()->SendNavigate(0, kUrl1); |
664 EXPECT_TRUE(notifications.Check1AndReset( | 664 EXPECT_TRUE(notifications.Check1AndReset( |
665 NotificationType::NAV_ENTRY_COMMITTED)); | 665 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
666 | 666 |
667 // controller().LoadURL(kUrl2, PageTransition::TYPED); | 667 // controller().LoadURL(kUrl2, PageTransition::TYPED); |
668 rvh()->SendNavigate(1, kUrl2); | 668 rvh()->SendNavigate(1, kUrl2); |
669 EXPECT_TRUE(notifications.Check1AndReset( | 669 EXPECT_TRUE(notifications.Check1AndReset( |
670 NotificationType::NAV_ENTRY_COMMITTED)); | 670 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
671 | 671 |
672 // Now start a new pending navigation and go back before it commits. | 672 // Now start a new pending navigation and go back before it commits. |
673 controller().LoadURL(kUrl3, GURL(), PageTransition::TYPED); | 673 controller().LoadURL(kUrl3, GURL(), PageTransition::TYPED); |
674 EXPECT_EQ(-1, controller().pending_entry_index()); | 674 EXPECT_EQ(-1, controller().pending_entry_index()); |
675 EXPECT_EQ(kUrl3, controller().pending_entry()->url()); | 675 EXPECT_EQ(kUrl3, controller().pending_entry()->url()); |
676 controller().GoBack(); | 676 controller().GoBack(); |
677 | 677 |
678 // The pending navigation should now be the "back" item and the new one | 678 // The pending navigation should now be the "back" item and the new one |
679 // should be gone. | 679 // should be gone. |
680 EXPECT_EQ(0, controller().pending_entry_index()); | 680 EXPECT_EQ(0, controller().pending_entry_index()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 // Tests what happens when we navigate forward successfully. | 731 // Tests what happens when we navigate forward successfully. |
732 TEST_F(NavigationControllerTest, Forward) { | 732 TEST_F(NavigationControllerTest, Forward) { |
733 TestNotificationTracker notifications; | 733 TestNotificationTracker notifications; |
734 RegisterForAllNavNotifications(¬ifications, &controller()); | 734 RegisterForAllNavNotifications(¬ifications, &controller()); |
735 | 735 |
736 const GURL url1("http://foo1"); | 736 const GURL url1("http://foo1"); |
737 const GURL url2("http://foo2"); | 737 const GURL url2("http://foo2"); |
738 | 738 |
739 rvh()->SendNavigate(0, url1); | 739 rvh()->SendNavigate(0, url1); |
740 EXPECT_TRUE(notifications.Check1AndReset( | 740 EXPECT_TRUE(notifications.Check1AndReset( |
741 NotificationType::NAV_ENTRY_COMMITTED)); | 741 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
742 | 742 |
743 rvh()->SendNavigate(1, url2); | 743 rvh()->SendNavigate(1, url2); |
744 EXPECT_TRUE(notifications.Check1AndReset( | 744 EXPECT_TRUE(notifications.Check1AndReset( |
745 NotificationType::NAV_ENTRY_COMMITTED)); | 745 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
746 | 746 |
747 controller().GoBack(); | 747 controller().GoBack(); |
748 rvh()->SendNavigate(0, url1); | 748 rvh()->SendNavigate(0, url1); |
749 EXPECT_TRUE(notifications.Check1AndReset( | 749 EXPECT_TRUE(notifications.Check1AndReset( |
750 NotificationType::NAV_ENTRY_COMMITTED)); | 750 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
751 | 751 |
752 controller().GoForward(); | 752 controller().GoForward(); |
753 | 753 |
754 // We should now have a pending navigation to go forward. | 754 // We should now have a pending navigation to go forward. |
755 EXPECT_EQ(controller().entry_count(), 2); | 755 EXPECT_EQ(controller().entry_count(), 2); |
756 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 756 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
757 EXPECT_EQ(controller().pending_entry_index(), 1); | 757 EXPECT_EQ(controller().pending_entry_index(), 1); |
758 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 758 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
759 EXPECT_TRUE(controller().pending_entry()); | 759 EXPECT_TRUE(controller().pending_entry()); |
760 EXPECT_TRUE(controller().CanGoBack()); | 760 EXPECT_TRUE(controller().CanGoBack()); |
761 EXPECT_FALSE(controller().CanGoForward()); | 761 EXPECT_FALSE(controller().CanGoForward()); |
762 | 762 |
763 rvh()->SendNavigate(1, url2); | 763 rvh()->SendNavigate(1, url2); |
764 EXPECT_TRUE(notifications.Check1AndReset( | 764 EXPECT_TRUE(notifications.Check1AndReset( |
765 NotificationType::NAV_ENTRY_COMMITTED)); | 765 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
766 | 766 |
767 // The forward navigation completed successfully. | 767 // The forward navigation completed successfully. |
768 EXPECT_EQ(controller().entry_count(), 2); | 768 EXPECT_EQ(controller().entry_count(), 2); |
769 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 769 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
770 EXPECT_EQ(controller().pending_entry_index(), -1); | 770 EXPECT_EQ(controller().pending_entry_index(), -1); |
771 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 771 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
772 EXPECT_FALSE(controller().pending_entry()); | 772 EXPECT_FALSE(controller().pending_entry()); |
773 EXPECT_TRUE(controller().CanGoBack()); | 773 EXPECT_TRUE(controller().CanGoBack()); |
774 EXPECT_FALSE(controller().CanGoForward()); | 774 EXPECT_FALSE(controller().CanGoForward()); |
775 } | 775 } |
776 | 776 |
777 // Tests what happens when a forward navigation produces a new page. | 777 // Tests what happens when a forward navigation produces a new page. |
778 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { | 778 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { |
779 TestNotificationTracker notifications; | 779 TestNotificationTracker notifications; |
780 RegisterForAllNavNotifications(¬ifications, &controller()); | 780 RegisterForAllNavNotifications(¬ifications, &controller()); |
781 | 781 |
782 const GURL url1("http://foo1"); | 782 const GURL url1("http://foo1"); |
783 const GURL url2("http://foo2"); | 783 const GURL url2("http://foo2"); |
784 const GURL url3("http://foo3"); | 784 const GURL url3("http://foo3"); |
785 | 785 |
786 rvh()->SendNavigate(0, url1); | 786 rvh()->SendNavigate(0, url1); |
787 EXPECT_TRUE(notifications.Check1AndReset( | 787 EXPECT_TRUE(notifications.Check1AndReset( |
788 NotificationType::NAV_ENTRY_COMMITTED)); | 788 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
789 rvh()->SendNavigate(1, url2); | 789 rvh()->SendNavigate(1, url2); |
790 EXPECT_TRUE(notifications.Check1AndReset( | 790 EXPECT_TRUE(notifications.Check1AndReset( |
791 NotificationType::NAV_ENTRY_COMMITTED)); | 791 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
792 | 792 |
793 controller().GoBack(); | 793 controller().GoBack(); |
794 rvh()->SendNavigate(0, url1); | 794 rvh()->SendNavigate(0, url1); |
795 EXPECT_TRUE(notifications.Check1AndReset( | 795 EXPECT_TRUE(notifications.Check1AndReset( |
796 NotificationType::NAV_ENTRY_COMMITTED)); | 796 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
797 | 797 |
798 controller().GoForward(); | 798 controller().GoForward(); |
799 EXPECT_EQ(0U, notifications.size()); | 799 EXPECT_EQ(0U, notifications.size()); |
800 | 800 |
801 // Should now have a pending navigation to go forward. | 801 // Should now have a pending navigation to go forward. |
802 EXPECT_EQ(controller().entry_count(), 2); | 802 EXPECT_EQ(controller().entry_count(), 2); |
803 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 803 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
804 EXPECT_EQ(controller().pending_entry_index(), 1); | 804 EXPECT_EQ(controller().pending_entry_index(), 1); |
805 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 805 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
806 EXPECT_TRUE(controller().pending_entry()); | 806 EXPECT_TRUE(controller().pending_entry()); |
807 EXPECT_TRUE(controller().CanGoBack()); | 807 EXPECT_TRUE(controller().CanGoBack()); |
808 EXPECT_FALSE(controller().CanGoForward()); | 808 EXPECT_FALSE(controller().CanGoForward()); |
809 | 809 |
810 rvh()->SendNavigate(2, url3); | 810 rvh()->SendNavigate(2, url3); |
811 EXPECT_TRUE(notifications.Check2AndReset( | 811 EXPECT_TRUE(notifications.Check2AndReset( |
812 NotificationType::NAV_LIST_PRUNED, | 812 content::NOTIFICATION_NAV_LIST_PRUNED, |
813 NotificationType::NAV_ENTRY_COMMITTED)); | 813 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
814 | 814 |
815 EXPECT_EQ(controller().entry_count(), 2); | 815 EXPECT_EQ(controller().entry_count(), 2); |
816 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 816 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
817 EXPECT_EQ(controller().pending_entry_index(), -1); | 817 EXPECT_EQ(controller().pending_entry_index(), -1); |
818 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 818 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
819 EXPECT_FALSE(controller().pending_entry()); | 819 EXPECT_FALSE(controller().pending_entry()); |
820 EXPECT_TRUE(controller().CanGoBack()); | 820 EXPECT_TRUE(controller().CanGoBack()); |
821 EXPECT_FALSE(controller().CanGoForward()); | 821 EXPECT_FALSE(controller().CanGoForward()); |
822 } | 822 } |
823 | 823 |
824 // Two consequent navigation for the same URL entered in should be considered | 824 // Two consequent navigation for the same URL entered in should be considered |
825 // as SAME_PAGE navigation even when we are redirected to some other page. | 825 // as SAME_PAGE navigation even when we are redirected to some other page. |
826 TEST_F(NavigationControllerTest, Redirect) { | 826 TEST_F(NavigationControllerTest, Redirect) { |
827 TestNotificationTracker notifications; | 827 TestNotificationTracker notifications; |
828 RegisterForAllNavNotifications(¬ifications, &controller()); | 828 RegisterForAllNavNotifications(¬ifications, &controller()); |
829 | 829 |
830 const GURL url1("http://foo1"); | 830 const GURL url1("http://foo1"); |
831 const GURL url2("http://foo2"); // Redirection target | 831 const GURL url2("http://foo2"); // Redirection target |
832 | 832 |
833 // First request | 833 // First request |
834 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 834 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
835 | 835 |
836 EXPECT_EQ(0U, notifications.size()); | 836 EXPECT_EQ(0U, notifications.size()); |
837 rvh()->SendNavigate(0, url2); | 837 rvh()->SendNavigate(0, url2); |
838 EXPECT_TRUE(notifications.Check1AndReset( | 838 EXPECT_TRUE(notifications.Check1AndReset( |
839 NotificationType::NAV_ENTRY_COMMITTED)); | 839 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
840 | 840 |
841 // Second request | 841 // Second request |
842 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 842 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
843 | 843 |
844 EXPECT_TRUE(controller().pending_entry()); | 844 EXPECT_TRUE(controller().pending_entry()); |
845 EXPECT_EQ(controller().pending_entry_index(), -1); | 845 EXPECT_EQ(controller().pending_entry_index(), -1); |
846 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 846 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
847 | 847 |
848 ViewHostMsg_FrameNavigate_Params params; | 848 ViewHostMsg_FrameNavigate_Params params; |
849 params.page_id = 0; | 849 params.page_id = 0; |
850 params.url = url2; | 850 params.url = url2; |
851 params.transition = PageTransition::SERVER_REDIRECT; | 851 params.transition = PageTransition::SERVER_REDIRECT; |
852 params.redirects.push_back(GURL("http://foo1")); | 852 params.redirects.push_back(GURL("http://foo1")); |
853 params.redirects.push_back(GURL("http://foo2")); | 853 params.redirects.push_back(GURL("http://foo2")); |
854 params.should_update_history = false; | 854 params.should_update_history = false; |
855 params.gesture = NavigationGestureAuto; | 855 params.gesture = NavigationGestureAuto; |
856 params.is_post = false; | 856 params.is_post = false; |
857 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 857 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
858 | 858 |
859 content::LoadCommittedDetails details; | 859 content::LoadCommittedDetails details; |
860 | 860 |
861 EXPECT_EQ(0U, notifications.size()); | 861 EXPECT_EQ(0U, notifications.size()); |
862 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 862 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
863 EXPECT_TRUE(notifications.Check1AndReset( | 863 EXPECT_TRUE(notifications.Check1AndReset( |
864 NotificationType::NAV_ENTRY_COMMITTED)); | 864 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
865 | 865 |
866 EXPECT_TRUE(details.type == NavigationType::SAME_PAGE); | 866 EXPECT_TRUE(details.type == NavigationType::SAME_PAGE); |
867 EXPECT_EQ(controller().entry_count(), 1); | 867 EXPECT_EQ(controller().entry_count(), 1); |
868 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 868 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
869 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 869 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
870 EXPECT_EQ(controller().pending_entry_index(), -1); | 870 EXPECT_EQ(controller().pending_entry_index(), -1); |
871 EXPECT_FALSE(controller().pending_entry()); | 871 EXPECT_FALSE(controller().pending_entry()); |
872 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); | 872 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); |
873 | 873 |
874 EXPECT_FALSE(controller().CanGoBack()); | 874 EXPECT_FALSE(controller().CanGoBack()); |
(...skipping 10 matching lines...) Expand all Loading... |
885 const GURL url1("http://foo1"); | 885 const GURL url1("http://foo1"); |
886 const GURL url2("http://foo2"); // Redirection target | 886 const GURL url2("http://foo2"); // Redirection target |
887 | 887 |
888 // First request as POST | 888 // First request as POST |
889 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 889 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
890 controller().GetActiveEntry()->set_has_post_data(true); | 890 controller().GetActiveEntry()->set_has_post_data(true); |
891 | 891 |
892 EXPECT_EQ(0U, notifications.size()); | 892 EXPECT_EQ(0U, notifications.size()); |
893 rvh()->SendNavigate(0, url2); | 893 rvh()->SendNavigate(0, url2); |
894 EXPECT_TRUE(notifications.Check1AndReset( | 894 EXPECT_TRUE(notifications.Check1AndReset( |
895 NotificationType::NAV_ENTRY_COMMITTED)); | 895 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
896 | 896 |
897 // Second request | 897 // Second request |
898 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 898 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
899 | 899 |
900 EXPECT_TRUE(controller().pending_entry()); | 900 EXPECT_TRUE(controller().pending_entry()); |
901 EXPECT_EQ(controller().pending_entry_index(), -1); | 901 EXPECT_EQ(controller().pending_entry_index(), -1); |
902 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); | 902 EXPECT_EQ(url1, controller().GetActiveEntry()->url()); |
903 | 903 |
904 ViewHostMsg_FrameNavigate_Params params; | 904 ViewHostMsg_FrameNavigate_Params params; |
905 params.page_id = 0; | 905 params.page_id = 0; |
906 params.url = url2; | 906 params.url = url2; |
907 params.transition = PageTransition::SERVER_REDIRECT; | 907 params.transition = PageTransition::SERVER_REDIRECT; |
908 params.redirects.push_back(GURL("http://foo1")); | 908 params.redirects.push_back(GURL("http://foo1")); |
909 params.redirects.push_back(GURL("http://foo2")); | 909 params.redirects.push_back(GURL("http://foo2")); |
910 params.should_update_history = false; | 910 params.should_update_history = false; |
911 params.gesture = NavigationGestureAuto; | 911 params.gesture = NavigationGestureAuto; |
912 params.is_post = false; | 912 params.is_post = false; |
913 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 913 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
914 | 914 |
915 content::LoadCommittedDetails details; | 915 content::LoadCommittedDetails details; |
916 | 916 |
917 EXPECT_EQ(0U, notifications.size()); | 917 EXPECT_EQ(0U, notifications.size()); |
918 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 918 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
919 EXPECT_TRUE(notifications.Check1AndReset( | 919 EXPECT_TRUE(notifications.Check1AndReset( |
920 NotificationType::NAV_ENTRY_COMMITTED)); | 920 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
921 | 921 |
922 EXPECT_TRUE(details.type == NavigationType::SAME_PAGE); | 922 EXPECT_TRUE(details.type == NavigationType::SAME_PAGE); |
923 EXPECT_EQ(controller().entry_count(), 1); | 923 EXPECT_EQ(controller().entry_count(), 1); |
924 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 924 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
925 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 925 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
926 EXPECT_EQ(controller().pending_entry_index(), -1); | 926 EXPECT_EQ(controller().pending_entry_index(), -1); |
927 EXPECT_FALSE(controller().pending_entry()); | 927 EXPECT_FALSE(controller().pending_entry()); |
928 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); | 928 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); |
929 EXPECT_FALSE(controller().GetActiveEntry()->has_post_data()); | 929 EXPECT_FALSE(controller().GetActiveEntry()->has_post_data()); |
930 | 930 |
(...skipping 25 matching lines...) Expand all Loading... |
956 params.should_update_history = false; | 956 params.should_update_history = false; |
957 params.gesture = NavigationGestureAuto; | 957 params.gesture = NavigationGestureAuto; |
958 params.is_post = false; | 958 params.is_post = false; |
959 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 959 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
960 | 960 |
961 content::LoadCommittedDetails details; | 961 content::LoadCommittedDetails details; |
962 | 962 |
963 EXPECT_EQ(0U, notifications.size()); | 963 EXPECT_EQ(0U, notifications.size()); |
964 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 964 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
965 EXPECT_TRUE(notifications.Check1AndReset( | 965 EXPECT_TRUE(notifications.Check1AndReset( |
966 NotificationType::NAV_ENTRY_COMMITTED)); | 966 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
967 | 967 |
968 EXPECT_TRUE(details.type == NavigationType::NEW_PAGE); | 968 EXPECT_TRUE(details.type == NavigationType::NEW_PAGE); |
969 EXPECT_EQ(controller().entry_count(), 1); | 969 EXPECT_EQ(controller().entry_count(), 1); |
970 EXPECT_EQ(controller().last_committed_entry_index(), 0); | 970 EXPECT_EQ(controller().last_committed_entry_index(), 0); |
971 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 971 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
972 EXPECT_EQ(controller().pending_entry_index(), -1); | 972 EXPECT_EQ(controller().pending_entry_index(), -1); |
973 EXPECT_FALSE(controller().pending_entry()); | 973 EXPECT_FALSE(controller().pending_entry()); |
974 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); | 974 EXPECT_EQ(url2, controller().GetActiveEntry()->url()); |
975 | 975 |
976 EXPECT_FALSE(controller().CanGoBack()); | 976 EXPECT_FALSE(controller().CanGoBack()); |
977 EXPECT_FALSE(controller().CanGoForward()); | 977 EXPECT_FALSE(controller().CanGoForward()); |
978 } | 978 } |
979 | 979 |
980 // Tests navigation via link click within a subframe. A new navigation entry | 980 // Tests navigation via link click within a subframe. A new navigation entry |
981 // should be created. | 981 // should be created. |
982 TEST_F(NavigationControllerTest, NewSubframe) { | 982 TEST_F(NavigationControllerTest, NewSubframe) { |
983 TestNotificationTracker notifications; | 983 TestNotificationTracker notifications; |
984 RegisterForAllNavNotifications(¬ifications, &controller()); | 984 RegisterForAllNavNotifications(¬ifications, &controller()); |
985 | 985 |
986 const GURL url1("http://foo1"); | 986 const GURL url1("http://foo1"); |
987 rvh()->SendNavigate(0, url1); | 987 rvh()->SendNavigate(0, url1); |
988 EXPECT_TRUE(notifications.Check1AndReset( | 988 EXPECT_TRUE(notifications.Check1AndReset( |
989 NotificationType::NAV_ENTRY_COMMITTED)); | 989 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
990 | 990 |
991 const GURL url2("http://foo2"); | 991 const GURL url2("http://foo2"); |
992 ViewHostMsg_FrameNavigate_Params params; | 992 ViewHostMsg_FrameNavigate_Params params; |
993 params.page_id = 1; | 993 params.page_id = 1; |
994 params.url = url2; | 994 params.url = url2; |
995 params.transition = PageTransition::MANUAL_SUBFRAME; | 995 params.transition = PageTransition::MANUAL_SUBFRAME; |
996 params.should_update_history = false; | 996 params.should_update_history = false; |
997 params.gesture = NavigationGestureUser; | 997 params.gesture = NavigationGestureUser; |
998 params.is_post = false; | 998 params.is_post = false; |
999 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 999 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1000 | 1000 |
1001 content::LoadCommittedDetails details; | 1001 content::LoadCommittedDetails details; |
1002 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1002 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1003 EXPECT_TRUE(notifications.Check1AndReset( | 1003 EXPECT_TRUE(notifications.Check1AndReset( |
1004 NotificationType::NAV_ENTRY_COMMITTED)); | 1004 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1005 EXPECT_EQ(url1, details.previous_url); | 1005 EXPECT_EQ(url1, details.previous_url); |
1006 EXPECT_FALSE(details.is_in_page); | 1006 EXPECT_FALSE(details.is_in_page); |
1007 EXPECT_FALSE(details.is_main_frame); | 1007 EXPECT_FALSE(details.is_main_frame); |
1008 | 1008 |
1009 // The new entry should be appended. | 1009 // The new entry should be appended. |
1010 EXPECT_EQ(2, controller().entry_count()); | 1010 EXPECT_EQ(2, controller().entry_count()); |
1011 | 1011 |
1012 // New entry should refer to the new page, but the old URL (entries only | 1012 // New entry should refer to the new page, but the old URL (entries only |
1013 // reflect the toplevel URL). | 1013 // reflect the toplevel URL). |
1014 EXPECT_EQ(url1, details.entry->url()); | 1014 EXPECT_EQ(url1, details.entry->url()); |
(...skipping 25 matching lines...) Expand all Loading... |
1040 | 1040 |
1041 // Auto subframes are ones the page loads automatically like ads. They should | 1041 // Auto subframes are ones the page loads automatically like ads. They should |
1042 // not create new navigation entries. | 1042 // not create new navigation entries. |
1043 TEST_F(NavigationControllerTest, AutoSubframe) { | 1043 TEST_F(NavigationControllerTest, AutoSubframe) { |
1044 TestNotificationTracker notifications; | 1044 TestNotificationTracker notifications; |
1045 RegisterForAllNavNotifications(¬ifications, &controller()); | 1045 RegisterForAllNavNotifications(¬ifications, &controller()); |
1046 | 1046 |
1047 const GURL url1("http://foo1"); | 1047 const GURL url1("http://foo1"); |
1048 rvh()->SendNavigate(0, url1); | 1048 rvh()->SendNavigate(0, url1); |
1049 EXPECT_TRUE(notifications.Check1AndReset( | 1049 EXPECT_TRUE(notifications.Check1AndReset( |
1050 NotificationType::NAV_ENTRY_COMMITTED)); | 1050 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1051 | 1051 |
1052 const GURL url2("http://foo2"); | 1052 const GURL url2("http://foo2"); |
1053 ViewHostMsg_FrameNavigate_Params params; | 1053 ViewHostMsg_FrameNavigate_Params params; |
1054 params.page_id = 0; | 1054 params.page_id = 0; |
1055 params.url = url2; | 1055 params.url = url2; |
1056 params.transition = PageTransition::AUTO_SUBFRAME; | 1056 params.transition = PageTransition::AUTO_SUBFRAME; |
1057 params.should_update_history = false; | 1057 params.should_update_history = false; |
1058 params.gesture = NavigationGestureUser; | 1058 params.gesture = NavigationGestureUser; |
1059 params.is_post = false; | 1059 params.is_post = false; |
1060 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1060 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1061 | 1061 |
1062 // Navigating should do nothing. | 1062 // Navigating should do nothing. |
1063 content::LoadCommittedDetails details; | 1063 content::LoadCommittedDetails details; |
1064 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); | 1064 EXPECT_FALSE(controller().RendererDidNavigate(params, &details)); |
1065 EXPECT_EQ(0U, notifications.size()); | 1065 EXPECT_EQ(0U, notifications.size()); |
1066 | 1066 |
1067 // There should still be only one entry. | 1067 // There should still be only one entry. |
1068 EXPECT_EQ(1, controller().entry_count()); | 1068 EXPECT_EQ(1, controller().entry_count()); |
1069 } | 1069 } |
1070 | 1070 |
1071 // Tests navigation and then going back to a subframe navigation. | 1071 // Tests navigation and then going back to a subframe navigation. |
1072 TEST_F(NavigationControllerTest, BackSubframe) { | 1072 TEST_F(NavigationControllerTest, BackSubframe) { |
1073 TestNotificationTracker notifications; | 1073 TestNotificationTracker notifications; |
1074 RegisterForAllNavNotifications(¬ifications, &controller()); | 1074 RegisterForAllNavNotifications(¬ifications, &controller()); |
1075 | 1075 |
1076 // Main page. | 1076 // Main page. |
1077 const GURL url1("http://foo1"); | 1077 const GURL url1("http://foo1"); |
1078 rvh()->SendNavigate(0, url1); | 1078 rvh()->SendNavigate(0, url1); |
1079 EXPECT_TRUE(notifications.Check1AndReset( | 1079 EXPECT_TRUE(notifications.Check1AndReset( |
1080 NotificationType::NAV_ENTRY_COMMITTED)); | 1080 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1081 | 1081 |
1082 // First manual subframe navigation. | 1082 // First manual subframe navigation. |
1083 const GURL url2("http://foo2"); | 1083 const GURL url2("http://foo2"); |
1084 ViewHostMsg_FrameNavigate_Params params; | 1084 ViewHostMsg_FrameNavigate_Params params; |
1085 params.page_id = 1; | 1085 params.page_id = 1; |
1086 params.url = url2; | 1086 params.url = url2; |
1087 params.transition = PageTransition::MANUAL_SUBFRAME; | 1087 params.transition = PageTransition::MANUAL_SUBFRAME; |
1088 params.should_update_history = false; | 1088 params.should_update_history = false; |
1089 params.gesture = NavigationGestureUser; | 1089 params.gesture = NavigationGestureUser; |
1090 params.is_post = false; | 1090 params.is_post = false; |
1091 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1091 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1092 | 1092 |
1093 // This should generate a new entry. | 1093 // This should generate a new entry. |
1094 content::LoadCommittedDetails details; | 1094 content::LoadCommittedDetails details; |
1095 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1095 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1096 EXPECT_TRUE(notifications.Check1AndReset( | 1096 EXPECT_TRUE(notifications.Check1AndReset( |
1097 NotificationType::NAV_ENTRY_COMMITTED)); | 1097 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1098 EXPECT_EQ(2, controller().entry_count()); | 1098 EXPECT_EQ(2, controller().entry_count()); |
1099 | 1099 |
1100 // Second manual subframe navigation should also make a new entry. | 1100 // Second manual subframe navigation should also make a new entry. |
1101 const GURL url3("http://foo3"); | 1101 const GURL url3("http://foo3"); |
1102 params.page_id = 2; | 1102 params.page_id = 2; |
1103 params.url = url3; | 1103 params.url = url3; |
1104 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1104 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1105 EXPECT_TRUE(notifications.Check1AndReset( | 1105 EXPECT_TRUE(notifications.Check1AndReset( |
1106 NotificationType::NAV_ENTRY_COMMITTED)); | 1106 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1107 EXPECT_EQ(3, controller().entry_count()); | 1107 EXPECT_EQ(3, controller().entry_count()); |
1108 EXPECT_EQ(2, controller().GetCurrentEntryIndex()); | 1108 EXPECT_EQ(2, controller().GetCurrentEntryIndex()); |
1109 | 1109 |
1110 // Go back one. | 1110 // Go back one. |
1111 controller().GoBack(); | 1111 controller().GoBack(); |
1112 params.url = url2; | 1112 params.url = url2; |
1113 params.page_id = 1; | 1113 params.page_id = 1; |
1114 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1114 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1115 EXPECT_TRUE(notifications.Check1AndReset( | 1115 EXPECT_TRUE(notifications.Check1AndReset( |
1116 NotificationType::NAV_ENTRY_COMMITTED)); | 1116 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1117 EXPECT_EQ(3, controller().entry_count()); | 1117 EXPECT_EQ(3, controller().entry_count()); |
1118 EXPECT_EQ(1, controller().GetCurrentEntryIndex()); | 1118 EXPECT_EQ(1, controller().GetCurrentEntryIndex()); |
1119 | 1119 |
1120 // Go back one more. | 1120 // Go back one more. |
1121 controller().GoBack(); | 1121 controller().GoBack(); |
1122 params.url = url1; | 1122 params.url = url1; |
1123 params.page_id = 0; | 1123 params.page_id = 0; |
1124 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1124 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1125 EXPECT_TRUE(notifications.Check1AndReset( | 1125 EXPECT_TRUE(notifications.Check1AndReset( |
1126 NotificationType::NAV_ENTRY_COMMITTED)); | 1126 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1127 EXPECT_EQ(3, controller().entry_count()); | 1127 EXPECT_EQ(3, controller().entry_count()); |
1128 EXPECT_EQ(0, controller().GetCurrentEntryIndex()); | 1128 EXPECT_EQ(0, controller().GetCurrentEntryIndex()); |
1129 } | 1129 } |
1130 | 1130 |
1131 TEST_F(NavigationControllerTest, LinkClick) { | 1131 TEST_F(NavigationControllerTest, LinkClick) { |
1132 TestNotificationTracker notifications; | 1132 TestNotificationTracker notifications; |
1133 RegisterForAllNavNotifications(¬ifications, &controller()); | 1133 RegisterForAllNavNotifications(¬ifications, &controller()); |
1134 | 1134 |
1135 const GURL url1("http://foo1"); | 1135 const GURL url1("http://foo1"); |
1136 const GURL url2("http://foo2"); | 1136 const GURL url2("http://foo2"); |
1137 | 1137 |
1138 rvh()->SendNavigate(0, url1); | 1138 rvh()->SendNavigate(0, url1); |
1139 EXPECT_TRUE(notifications.Check1AndReset( | 1139 EXPECT_TRUE(notifications.Check1AndReset( |
1140 NotificationType::NAV_ENTRY_COMMITTED)); | 1140 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1141 | 1141 |
1142 rvh()->SendNavigate(1, url2); | 1142 rvh()->SendNavigate(1, url2); |
1143 EXPECT_TRUE(notifications.Check1AndReset( | 1143 EXPECT_TRUE(notifications.Check1AndReset( |
1144 NotificationType::NAV_ENTRY_COMMITTED)); | 1144 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1145 | 1145 |
1146 // Should not have produced a new session history entry. | 1146 // Should not have produced a new session history entry. |
1147 EXPECT_EQ(controller().entry_count(), 2); | 1147 EXPECT_EQ(controller().entry_count(), 2); |
1148 EXPECT_EQ(controller().last_committed_entry_index(), 1); | 1148 EXPECT_EQ(controller().last_committed_entry_index(), 1); |
1149 EXPECT_EQ(controller().pending_entry_index(), -1); | 1149 EXPECT_EQ(controller().pending_entry_index(), -1); |
1150 EXPECT_TRUE(controller().GetLastCommittedEntry()); | 1150 EXPECT_TRUE(controller().GetLastCommittedEntry()); |
1151 EXPECT_FALSE(controller().pending_entry()); | 1151 EXPECT_FALSE(controller().pending_entry()); |
1152 EXPECT_TRUE(controller().CanGoBack()); | 1152 EXPECT_TRUE(controller().CanGoBack()); |
1153 EXPECT_FALSE(controller().CanGoForward()); | 1153 EXPECT_FALSE(controller().CanGoForward()); |
1154 } | 1154 } |
1155 | 1155 |
1156 TEST_F(NavigationControllerTest, InPage) { | 1156 TEST_F(NavigationControllerTest, InPage) { |
1157 TestNotificationTracker notifications; | 1157 TestNotificationTracker notifications; |
1158 RegisterForAllNavNotifications(¬ifications, &controller()); | 1158 RegisterForAllNavNotifications(¬ifications, &controller()); |
1159 | 1159 |
1160 // Main page. | 1160 // Main page. |
1161 const GURL url1("http://foo"); | 1161 const GURL url1("http://foo"); |
1162 rvh()->SendNavigate(0, url1); | 1162 rvh()->SendNavigate(0, url1); |
1163 EXPECT_TRUE(notifications.Check1AndReset( | 1163 EXPECT_TRUE(notifications.Check1AndReset( |
1164 NotificationType::NAV_ENTRY_COMMITTED)); | 1164 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1165 | 1165 |
1166 // First navigation. | 1166 // First navigation. |
1167 const GURL url2("http://foo#a"); | 1167 const GURL url2("http://foo#a"); |
1168 ViewHostMsg_FrameNavigate_Params params; | 1168 ViewHostMsg_FrameNavigate_Params params; |
1169 params.page_id = 1; | 1169 params.page_id = 1; |
1170 params.url = url2; | 1170 params.url = url2; |
1171 params.transition = PageTransition::LINK; | 1171 params.transition = PageTransition::LINK; |
1172 params.should_update_history = false; | 1172 params.should_update_history = false; |
1173 params.gesture = NavigationGestureUser; | 1173 params.gesture = NavigationGestureUser; |
1174 params.is_post = false; | 1174 params.is_post = false; |
1175 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1175 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1176 | 1176 |
1177 // This should generate a new entry. | 1177 // This should generate a new entry. |
1178 content::LoadCommittedDetails details; | 1178 content::LoadCommittedDetails details; |
1179 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1179 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1180 EXPECT_TRUE(notifications.Check1AndReset( | 1180 EXPECT_TRUE(notifications.Check1AndReset( |
1181 NotificationType::NAV_ENTRY_COMMITTED)); | 1181 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1182 EXPECT_TRUE(details.is_in_page); | 1182 EXPECT_TRUE(details.is_in_page); |
1183 EXPECT_FALSE(details.did_replace_entry); | 1183 EXPECT_FALSE(details.did_replace_entry); |
1184 EXPECT_EQ(2, controller().entry_count()); | 1184 EXPECT_EQ(2, controller().entry_count()); |
1185 | 1185 |
1186 // Go back one. | 1186 // Go back one. |
1187 ViewHostMsg_FrameNavigate_Params back_params(params); | 1187 ViewHostMsg_FrameNavigate_Params back_params(params); |
1188 controller().GoBack(); | 1188 controller().GoBack(); |
1189 back_params.url = url1; | 1189 back_params.url = url1; |
1190 back_params.page_id = 0; | 1190 back_params.page_id = 0; |
1191 EXPECT_TRUE(controller().RendererDidNavigate(back_params, &details)); | 1191 EXPECT_TRUE(controller().RendererDidNavigate(back_params, &details)); |
1192 EXPECT_TRUE(notifications.Check1AndReset( | 1192 EXPECT_TRUE(notifications.Check1AndReset( |
1193 NotificationType::NAV_ENTRY_COMMITTED)); | 1193 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1194 // is_in_page is false in that case but should be true. | 1194 // is_in_page is false in that case but should be true. |
1195 // See comment in AreURLsInPageNavigation() in navigation_controller.cc | 1195 // See comment in AreURLsInPageNavigation() in navigation_controller.cc |
1196 // EXPECT_TRUE(details.is_in_page); | 1196 // EXPECT_TRUE(details.is_in_page); |
1197 EXPECT_EQ(2, controller().entry_count()); | 1197 EXPECT_EQ(2, controller().entry_count()); |
1198 EXPECT_EQ(0, controller().GetCurrentEntryIndex()); | 1198 EXPECT_EQ(0, controller().GetCurrentEntryIndex()); |
1199 EXPECT_EQ(back_params.url, controller().GetActiveEntry()->url()); | 1199 EXPECT_EQ(back_params.url, controller().GetActiveEntry()->url()); |
1200 | 1200 |
1201 // Go forward | 1201 // Go forward |
1202 ViewHostMsg_FrameNavigate_Params forward_params(params); | 1202 ViewHostMsg_FrameNavigate_Params forward_params(params); |
1203 controller().GoForward(); | 1203 controller().GoForward(); |
1204 forward_params.url = url2; | 1204 forward_params.url = url2; |
1205 forward_params.page_id = 1; | 1205 forward_params.page_id = 1; |
1206 EXPECT_TRUE(controller().RendererDidNavigate(forward_params, &details)); | 1206 EXPECT_TRUE(controller().RendererDidNavigate(forward_params, &details)); |
1207 EXPECT_TRUE(notifications.Check1AndReset( | 1207 EXPECT_TRUE(notifications.Check1AndReset( |
1208 NotificationType::NAV_ENTRY_COMMITTED)); | 1208 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1209 EXPECT_TRUE(details.is_in_page); | 1209 EXPECT_TRUE(details.is_in_page); |
1210 EXPECT_EQ(2, controller().entry_count()); | 1210 EXPECT_EQ(2, controller().entry_count()); |
1211 EXPECT_EQ(1, controller().GetCurrentEntryIndex()); | 1211 EXPECT_EQ(1, controller().GetCurrentEntryIndex()); |
1212 EXPECT_EQ(forward_params.url, | 1212 EXPECT_EQ(forward_params.url, |
1213 controller().GetActiveEntry()->url()); | 1213 controller().GetActiveEntry()->url()); |
1214 | 1214 |
1215 // Now go back and forward again. This is to work around a bug where we would | 1215 // Now go back and forward again. This is to work around a bug where we would |
1216 // compare the incoming URL with the last committed entry rather than the | 1216 // compare the incoming URL with the last committed entry rather than the |
1217 // one identified by an existing page ID. This would result in the second URL | 1217 // one identified by an existing page ID. This would result in the second URL |
1218 // losing the reference fragment when you navigate away from it and then back. | 1218 // losing the reference fragment when you navigate away from it and then back. |
1219 controller().GoBack(); | 1219 controller().GoBack(); |
1220 EXPECT_TRUE(controller().RendererDidNavigate(back_params, &details)); | 1220 EXPECT_TRUE(controller().RendererDidNavigate(back_params, &details)); |
1221 controller().GoForward(); | 1221 controller().GoForward(); |
1222 EXPECT_TRUE(controller().RendererDidNavigate(forward_params, &details)); | 1222 EXPECT_TRUE(controller().RendererDidNavigate(forward_params, &details)); |
1223 EXPECT_EQ(forward_params.url, | 1223 EXPECT_EQ(forward_params.url, |
1224 controller().GetActiveEntry()->url()); | 1224 controller().GetActiveEntry()->url()); |
1225 | 1225 |
1226 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 1226 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
1227 const GURL url3("http://bar"); | 1227 const GURL url3("http://bar"); |
1228 params.page_id = 2; | 1228 params.page_id = 2; |
1229 params.url = url3; | 1229 params.url = url3; |
1230 notifications.Reset(); | 1230 notifications.Reset(); |
1231 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1231 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1232 EXPECT_TRUE(notifications.Check1AndReset( | 1232 EXPECT_TRUE(notifications.Check1AndReset( |
1233 NotificationType::NAV_ENTRY_COMMITTED)); | 1233 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1234 EXPECT_FALSE(details.is_in_page); | 1234 EXPECT_FALSE(details.is_in_page); |
1235 } | 1235 } |
1236 | 1236 |
1237 TEST_F(NavigationControllerTest, InPage_Replace) { | 1237 TEST_F(NavigationControllerTest, InPage_Replace) { |
1238 TestNotificationTracker notifications; | 1238 TestNotificationTracker notifications; |
1239 RegisterForAllNavNotifications(¬ifications, &controller()); | 1239 RegisterForAllNavNotifications(¬ifications, &controller()); |
1240 | 1240 |
1241 // Main page. | 1241 // Main page. |
1242 const GURL url1("http://foo"); | 1242 const GURL url1("http://foo"); |
1243 rvh()->SendNavigate(0, url1); | 1243 rvh()->SendNavigate(0, url1); |
1244 EXPECT_TRUE(notifications.Check1AndReset( | 1244 EXPECT_TRUE(notifications.Check1AndReset( |
1245 NotificationType::NAV_ENTRY_COMMITTED)); | 1245 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1246 | 1246 |
1247 // First navigation. | 1247 // First navigation. |
1248 const GURL url2("http://foo#a"); | 1248 const GURL url2("http://foo#a"); |
1249 ViewHostMsg_FrameNavigate_Params params; | 1249 ViewHostMsg_FrameNavigate_Params params; |
1250 params.page_id = 0; // Same page_id | 1250 params.page_id = 0; // Same page_id |
1251 params.url = url2; | 1251 params.url = url2; |
1252 params.transition = PageTransition::LINK; | 1252 params.transition = PageTransition::LINK; |
1253 params.should_update_history = false; | 1253 params.should_update_history = false; |
1254 params.gesture = NavigationGestureUser; | 1254 params.gesture = NavigationGestureUser; |
1255 params.is_post = false; | 1255 params.is_post = false; |
1256 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1256 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1257 | 1257 |
1258 // This should NOT generate a new entry. | 1258 // This should NOT generate a new entry. |
1259 content::LoadCommittedDetails details; | 1259 content::LoadCommittedDetails details; |
1260 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1260 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1261 EXPECT_TRUE(notifications.Check2AndReset( | 1261 EXPECT_TRUE(notifications.Check2AndReset( |
1262 NotificationType::NAV_LIST_PRUNED, | 1262 content::NOTIFICATION_NAV_LIST_PRUNED, |
1263 NotificationType::NAV_ENTRY_COMMITTED)); | 1263 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1264 EXPECT_TRUE(details.is_in_page); | 1264 EXPECT_TRUE(details.is_in_page); |
1265 EXPECT_TRUE(details.did_replace_entry); | 1265 EXPECT_TRUE(details.did_replace_entry); |
1266 EXPECT_EQ(1, controller().entry_count()); | 1266 EXPECT_EQ(1, controller().entry_count()); |
1267 } | 1267 } |
1268 | 1268 |
1269 // Tests for http://crbug.com/40395 | 1269 // Tests for http://crbug.com/40395 |
1270 // Simulates this: | 1270 // Simulates this: |
1271 // <script> | 1271 // <script> |
1272 // window.location.replace("#a"); | 1272 // window.location.replace("#a"); |
1273 // window.location='http://foo3/'; | 1273 // window.location='http://foo3/'; |
1274 // </script> | 1274 // </script> |
1275 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { | 1275 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
1276 TestNotificationTracker notifications; | 1276 TestNotificationTracker notifications; |
1277 RegisterForAllNavNotifications(¬ifications, &controller()); | 1277 RegisterForAllNavNotifications(¬ifications, &controller()); |
1278 | 1278 |
1279 // Load an initial page. | 1279 // Load an initial page. |
1280 { | 1280 { |
1281 const GURL url("http://foo/"); | 1281 const GURL url("http://foo/"); |
1282 rvh()->SendNavigate(0, url); | 1282 rvh()->SendNavigate(0, url); |
1283 EXPECT_TRUE(notifications.Check1AndReset( | 1283 EXPECT_TRUE(notifications.Check1AndReset( |
1284 NotificationType::NAV_ENTRY_COMMITTED)); | 1284 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1285 } | 1285 } |
1286 | 1286 |
1287 // Navigate to a new page. | 1287 // Navigate to a new page. |
1288 { | 1288 { |
1289 const GURL url("http://foo2/"); | 1289 const GURL url("http://foo2/"); |
1290 rvh()->SendNavigate(1, url); | 1290 rvh()->SendNavigate(1, url); |
1291 controller().DocumentLoadedInFrame(); | 1291 controller().DocumentLoadedInFrame(); |
1292 EXPECT_TRUE(notifications.Check1AndReset( | 1292 EXPECT_TRUE(notifications.Check1AndReset( |
1293 NotificationType::NAV_ENTRY_COMMITTED)); | 1293 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1294 } | 1294 } |
1295 | 1295 |
1296 // Navigate within the page. | 1296 // Navigate within the page. |
1297 { | 1297 { |
1298 const GURL url("http://foo2/#a"); | 1298 const GURL url("http://foo2/#a"); |
1299 ViewHostMsg_FrameNavigate_Params params; | 1299 ViewHostMsg_FrameNavigate_Params params; |
1300 params.page_id = 1; // Same page_id | 1300 params.page_id = 1; // Same page_id |
1301 params.url = url; | 1301 params.url = url; |
1302 params.transition = PageTransition::LINK; | 1302 params.transition = PageTransition::LINK; |
1303 params.redirects.push_back(url); | 1303 params.redirects.push_back(url); |
1304 params.should_update_history = true; | 1304 params.should_update_history = true; |
1305 params.gesture = NavigationGestureUnknown; | 1305 params.gesture = NavigationGestureUnknown; |
1306 params.is_post = false; | 1306 params.is_post = false; |
1307 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1307 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
1308 | 1308 |
1309 // This should NOT generate a new entry. | 1309 // This should NOT generate a new entry. |
1310 content::LoadCommittedDetails details; | 1310 content::LoadCommittedDetails details; |
1311 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1311 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1312 EXPECT_TRUE(notifications.Check2AndReset( | 1312 EXPECT_TRUE(notifications.Check2AndReset( |
1313 NotificationType::NAV_LIST_PRUNED, | 1313 content::NOTIFICATION_NAV_LIST_PRUNED, |
1314 NotificationType::NAV_ENTRY_COMMITTED)); | 1314 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1315 EXPECT_TRUE(details.is_in_page); | 1315 EXPECT_TRUE(details.is_in_page); |
1316 EXPECT_TRUE(details.did_replace_entry); | 1316 EXPECT_TRUE(details.did_replace_entry); |
1317 EXPECT_EQ(2, controller().entry_count()); | 1317 EXPECT_EQ(2, controller().entry_count()); |
1318 } | 1318 } |
1319 | 1319 |
1320 // Perform a client redirect to a new page. | 1320 // Perform a client redirect to a new page. |
1321 { | 1321 { |
1322 const GURL url("http://foo3/"); | 1322 const GURL url("http://foo3/"); |
1323 ViewHostMsg_FrameNavigate_Params params; | 1323 ViewHostMsg_FrameNavigate_Params params; |
1324 params.page_id = 2; // New page_id | 1324 params.page_id = 2; // New page_id |
1325 params.url = url; | 1325 params.url = url; |
1326 params.transition = PageTransition::CLIENT_REDIRECT; | 1326 params.transition = PageTransition::CLIENT_REDIRECT; |
1327 params.redirects.push_back(GURL("http://foo2/#a")); | 1327 params.redirects.push_back(GURL("http://foo2/#a")); |
1328 params.redirects.push_back(url); | 1328 params.redirects.push_back(url); |
1329 params.should_update_history = true; | 1329 params.should_update_history = true; |
1330 params.gesture = NavigationGestureUnknown; | 1330 params.gesture = NavigationGestureUnknown; |
1331 params.is_post = false; | 1331 params.is_post = false; |
1332 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1332 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
1333 | 1333 |
1334 // This SHOULD generate a new entry. | 1334 // This SHOULD generate a new entry. |
1335 content::LoadCommittedDetails details; | 1335 content::LoadCommittedDetails details; |
1336 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); | 1336 EXPECT_TRUE(controller().RendererDidNavigate(params, &details)); |
1337 EXPECT_TRUE(notifications.Check1AndReset( | 1337 EXPECT_TRUE(notifications.Check1AndReset( |
1338 NotificationType::NAV_ENTRY_COMMITTED)); | 1338 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1339 EXPECT_FALSE(details.is_in_page); | 1339 EXPECT_FALSE(details.is_in_page); |
1340 EXPECT_EQ(3, controller().entry_count()); | 1340 EXPECT_EQ(3, controller().entry_count()); |
1341 } | 1341 } |
1342 | 1342 |
1343 // Verify that BACK brings us back to http://foo2/. | 1343 // Verify that BACK brings us back to http://foo2/. |
1344 { | 1344 { |
1345 const GURL url("http://foo2/"); | 1345 const GURL url("http://foo2/"); |
1346 controller().GoBack(); | 1346 controller().GoBack(); |
1347 rvh()->SendNavigate(1, url); | 1347 rvh()->SendNavigate(1, url); |
1348 EXPECT_TRUE(notifications.Check1AndReset( | 1348 EXPECT_TRUE(notifications.Check1AndReset( |
1349 NotificationType::NAV_ENTRY_COMMITTED)); | 1349 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1350 EXPECT_EQ(url, controller().GetActiveEntry()->url()); | 1350 EXPECT_EQ(url, controller().GetActiveEntry()->url()); |
1351 } | 1351 } |
1352 } | 1352 } |
1353 | 1353 |
1354 // NotificationObserver implementation used in verifying we've received the | 1354 // NotificationObserver implementation used in verifying we've received the |
1355 // NotificationType::NAV_LIST_PRUNED method. | 1355 // content::NOTIFICATION_NAV_LIST_PRUNED method. |
1356 class PrunedListener : public NotificationObserver { | 1356 class PrunedListener : public NotificationObserver { |
1357 public: | 1357 public: |
1358 explicit PrunedListener(NavigationController* controller) | 1358 explicit PrunedListener(NavigationController* controller) |
1359 : notification_count_(0) { | 1359 : notification_count_(0) { |
1360 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, | 1360 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, |
1361 Source<NavigationController>(controller)); | 1361 Source<NavigationController>(controller)); |
1362 } | 1362 } |
1363 | 1363 |
1364 virtual void Observe(NotificationType type, | 1364 virtual void Observe(int type, |
1365 const NotificationSource& source, | 1365 const NotificationSource& source, |
1366 const NotificationDetails& details) { | 1366 const NotificationDetails& details) { |
1367 if (type == NotificationType::NAV_LIST_PRUNED) { | 1367 if (type == content::NOTIFICATION_NAV_LIST_PRUNED) { |
1368 notification_count_++; | 1368 notification_count_++; |
1369 details_ = *(Details<content::PrunedDetails>(details).ptr()); | 1369 details_ = *(Details<content::PrunedDetails>(details).ptr()); |
1370 } | 1370 } |
1371 } | 1371 } |
1372 | 1372 |
1373 // Number of times NAV_LIST_PRUNED has been observed. | 1373 // Number of times NAV_LIST_PRUNED has been observed. |
1374 int notification_count_; | 1374 int notification_count_; |
1375 | 1375 |
1376 // Details from the last NAV_LIST_PRUNED. | 1376 // Details from the last NAV_LIST_PRUNED. |
1377 content::PrunedDetails details_; | 1377 content::PrunedDetails details_; |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2289 TabNavigation nav(0, url0, GURL(), string16(), | 2289 TabNavigation nav(0, url0, GURL(), string16(), |
2290 webkit_glue::CreateHistoryStateForURL(url0), | 2290 webkit_glue::CreateHistoryStateForURL(url0), |
2291 PageTransition::LINK); | 2291 PageTransition::LINK); |
2292 session_helper_.AssertNavigationEquals(nav, | 2292 session_helper_.AssertNavigationEquals(nav, |
2293 windows_[0]->tabs[0]->navigations[0]); | 2293 windows_[0]->tabs[0]->navigations[0]); |
2294 nav.set_url(url2); | 2294 nav.set_url(url2); |
2295 session_helper_.AssertNavigationEquals(nav, | 2295 session_helper_.AssertNavigationEquals(nav, |
2296 windows_[0]->tabs[0]->navigations[1]); | 2296 windows_[0]->tabs[0]->navigations[1]); |
2297 } | 2297 } |
2298 */ | 2298 */ |
OLD | NEW |