OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
33 #include "content/public/browser/render_view_host_observer.h" | 33 #include "content/public/browser/render_view_host_observer.h" |
34 #include "content/public/browser/web_contents_delegate.h" | 34 #include "content/public/browser/web_contents_delegate.h" |
35 #include "content/public/test/mock_render_process_host.h" | 35 #include "content/public/test/mock_render_process_host.h" |
36 #include "content/public/test/test_notification_tracker.h" | 36 #include "content/public/test/test_notification_tracker.h" |
37 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
39 #include "webkit/glue/glue_serialize.h" | 39 #include "webkit/glue/glue_serialize.h" |
40 | 40 |
41 using base::Time; | 41 using base::Time; |
42 using content::NavigationController; | 42 |
43 using content::NavigationEntry; | 43 namespace content { |
44 using content::NavigationEntryImpl; | |
45 using content::RenderViewHostImplTestHarness; | |
46 using content::SessionStorageNamespaceMap; | |
47 using content::SiteInstance; | |
48 using content::TestNotificationTracker; | |
49 using content::TestRenderViewHost; | |
50 using content::TestWebContents; | |
51 using content::WebContents; | |
52 | 44 |
53 // TimeSmoother tests ---------------------------------------------------------- | 45 // TimeSmoother tests ---------------------------------------------------------- |
54 | 46 |
55 // With no duplicates, GetSmoothedTime should be the identity | 47 // With no duplicates, GetSmoothedTime should be the identity |
56 // function. | 48 // function. |
57 TEST(TimeSmoother, Basic) { | 49 TEST(TimeSmoother, Basic) { |
58 NavigationControllerImpl::TimeSmoother smoother; | 50 NavigationControllerImpl::TimeSmoother smoother; |
59 for (int64 i = 1; i < 1000; ++i) { | 51 for (int64 i = 1; i < 1000; ++i) { |
60 base::Time t = base::Time::FromInternalValue(i); | 52 base::Time t = base::Time::FromInternalValue(i); |
61 EXPECT_EQ(t, smoother.GetSmoothedTime(t)); | 53 EXPECT_EQ(t, smoother.GetSmoothedTime(t)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 public: | 105 public: |
114 NavigationControllerTest() {} | 106 NavigationControllerTest() {} |
115 | 107 |
116 NavigationControllerImpl& controller_impl() { | 108 NavigationControllerImpl& controller_impl() { |
117 return static_cast<NavigationControllerImpl&>(controller()); | 109 return static_cast<NavigationControllerImpl&>(controller()); |
118 } | 110 } |
119 }; | 111 }; |
120 | 112 |
121 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, | 113 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
122 NavigationController* controller) { | 114 NavigationController* controller) { |
123 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 115 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_COMMITTED, |
124 content::Source<NavigationController>( | 116 Source<NavigationController>(controller)); |
125 controller)); | 117 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, |
126 tracker->ListenFor(content::NOTIFICATION_NAV_LIST_PRUNED, | 118 Source<NavigationController>(controller)); |
127 content::Source<NavigationController>( | 119 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, |
128 controller)); | 120 Source<NavigationController>(controller)); |
129 tracker->ListenFor(content::NOTIFICATION_NAV_ENTRY_CHANGED, | |
130 content::Source<NavigationController>( | |
131 controller)); | |
132 } | 121 } |
133 | 122 |
134 SiteInstance* GetSiteInstanceFromEntry(NavigationEntry* entry) { | 123 SiteInstance* GetSiteInstanceFromEntry(NavigationEntry* entry) { |
135 return NavigationEntryImpl::FromNavigationEntry(entry)->site_instance(); | 124 return NavigationEntryImpl::FromNavigationEntry(entry)->site_instance(); |
136 } | 125 } |
137 | 126 |
138 class TestWebContentsDelegate : public content::WebContentsDelegate { | 127 class TestWebContentsDelegate : public WebContentsDelegate { |
139 public: | 128 public: |
140 explicit TestWebContentsDelegate() : | 129 explicit TestWebContentsDelegate() : |
141 navigation_state_change_count_(0) {} | 130 navigation_state_change_count_(0) {} |
142 | 131 |
143 int navigation_state_change_count() { | 132 int navigation_state_change_count() { |
144 return navigation_state_change_count_; | 133 return navigation_state_change_count_; |
145 } | 134 } |
146 | 135 |
147 // Keep track of whether the tab has notified us of a navigation state change. | 136 // Keep track of whether the tab has notified us of a navigation state change. |
148 virtual void NavigationStateChanged(const WebContents* source, | 137 virtual void NavigationStateChanged(const WebContents* source, |
(...skipping 27 matching lines...) Expand all Loading... |
176 TestNotificationTracker notifications; | 165 TestNotificationTracker notifications; |
177 RegisterForAllNavNotifications(¬ifications, &controller); | 166 RegisterForAllNavNotifications(¬ifications, &controller); |
178 | 167 |
179 const int kNumUrls = 5; | 168 const int kNumUrls = 5; |
180 std::vector<GURL> urls(kNumUrls); | 169 std::vector<GURL> urls(kNumUrls); |
181 for (int i = 0; i < kNumUrls; ++i) { | 170 for (int i = 0; i < kNumUrls; ++i) { |
182 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 171 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
183 } | 172 } |
184 | 173 |
185 test_rvh()->SendNavigate(0, urls[0]); | 174 test_rvh()->SendNavigate(0, urls[0]); |
186 EXPECT_TRUE(notifications.Check1AndReset( | 175 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
187 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
188 EXPECT_EQ(urls[0], controller.GetActiveEntry()->GetVirtualURL()); | 176 EXPECT_EQ(urls[0], controller.GetActiveEntry()->GetVirtualURL()); |
189 EXPECT_FALSE(controller.CanGoBack()); | 177 EXPECT_FALSE(controller.CanGoBack()); |
190 EXPECT_FALSE(controller.CanGoForward()); | 178 EXPECT_FALSE(controller.CanGoForward()); |
191 EXPECT_FALSE(controller.CanGoToOffset(1)); | 179 EXPECT_FALSE(controller.CanGoToOffset(1)); |
192 | 180 |
193 for (int i = 1; i <= 4; ++i) { | 181 for (int i = 1; i <= 4; ++i) { |
194 test_rvh()->SendNavigate(i, urls[i]); | 182 test_rvh()->SendNavigate(i, urls[i]); |
195 EXPECT_TRUE(notifications.Check1AndReset( | 183 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
196 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
197 EXPECT_EQ(urls[i], controller.GetActiveEntry()->GetVirtualURL()); | 184 EXPECT_EQ(urls[i], controller.GetActiveEntry()->GetVirtualURL()); |
198 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 185 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
199 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 186 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
200 EXPECT_FALSE(controller.CanGoToOffset(1)); | 187 EXPECT_FALSE(controller.CanGoToOffset(1)); |
201 } | 188 } |
202 | 189 |
203 // We have loaded 5 pages, and are currently at the last-loaded page. | 190 // We have loaded 5 pages, and are currently at the last-loaded page. |
204 int url_index = 4; | 191 int url_index = 4; |
205 | 192 |
206 enum Tests { | 193 enum Tests { |
(...skipping 13 matching lines...) Expand all Loading... |
220 GO_TO_END | 207 GO_TO_END |
221 }; | 208 }; |
222 | 209 |
223 for (int test = 0; test < NUM_TESTS; ++test) { | 210 for (int test = 0; test < NUM_TESTS; ++test) { |
224 int offset = test_offsets[test]; | 211 int offset = test_offsets[test]; |
225 controller.GoToOffset(offset); | 212 controller.GoToOffset(offset); |
226 url_index += offset; | 213 url_index += offset; |
227 // Check that the GoToOffset will land on the expected page. | 214 // Check that the GoToOffset will land on the expected page. |
228 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); | 215 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); |
229 test_rvh()->SendNavigate(url_index, urls[url_index]); | 216 test_rvh()->SendNavigate(url_index, urls[url_index]); |
230 EXPECT_TRUE(notifications.Check1AndReset( | 217 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
231 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
232 // Check that we can go to any valid offset into the history. | 218 // Check that we can go to any valid offset into the history. |
233 for (size_t j = 0; j < urls.size(); ++j) | 219 for (size_t j = 0; j < urls.size(); ++j) |
234 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); | 220 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); |
235 // Check that we can't go beyond the beginning or end of the history. | 221 // Check that we can't go beyond the beginning or end of the history. |
236 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); | 222 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); |
237 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); | 223 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); |
238 } | 224 } |
239 } | 225 } |
240 | 226 |
241 TEST_F(NavigationControllerTest, LoadURL) { | 227 TEST_F(NavigationControllerTest, LoadURL) { |
242 NavigationControllerImpl& controller = controller_impl(); | 228 NavigationControllerImpl& controller = controller_impl(); |
243 TestNotificationTracker notifications; | 229 TestNotificationTracker notifications; |
244 RegisterForAllNavNotifications(¬ifications, &controller); | 230 RegisterForAllNavNotifications(¬ifications, &controller); |
245 | 231 |
246 const GURL url1("http://foo1"); | 232 const GURL url1("http://foo1"); |
247 const GURL url2("http://foo2"); | 233 const GURL url2("http://foo2"); |
248 | 234 |
249 controller.LoadURL( | 235 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
250 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
251 // Creating a pending notification should not have issued any of the | 236 // Creating a pending notification should not have issued any of the |
252 // notifications we're listening for. | 237 // notifications we're listening for. |
253 EXPECT_EQ(0U, notifications.size()); | 238 EXPECT_EQ(0U, notifications.size()); |
254 | 239 |
255 // The load should now be pending. | 240 // The load should now be pending. |
256 EXPECT_EQ(controller.GetEntryCount(), 0); | 241 EXPECT_EQ(controller.GetEntryCount(), 0); |
257 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); | 242 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); |
258 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 243 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
259 EXPECT_FALSE(controller.GetLastCommittedEntry()); | 244 EXPECT_FALSE(controller.GetLastCommittedEntry()); |
260 ASSERT_TRUE(controller.GetPendingEntry()); | 245 ASSERT_TRUE(controller.GetPendingEntry()); |
261 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); | 246 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); |
262 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 247 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
263 EXPECT_FALSE(controller.CanGoBack()); | 248 EXPECT_FALSE(controller.CanGoBack()); |
264 EXPECT_FALSE(controller.CanGoForward()); | 249 EXPECT_FALSE(controller.CanGoForward()); |
265 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 250 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
266 | 251 |
267 // The timestamp should not have been set yet. | 252 // The timestamp should not have been set yet. |
268 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 253 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
269 | 254 |
270 // We should have gotten no notifications from the preceeding checks. | 255 // We should have gotten no notifications from the preceeding checks. |
271 EXPECT_EQ(0U, notifications.size()); | 256 EXPECT_EQ(0U, notifications.size()); |
272 | 257 |
273 test_rvh()->SendNavigate(0, url1); | 258 test_rvh()->SendNavigate(0, url1); |
274 EXPECT_TRUE(notifications.Check1AndReset( | 259 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
275 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
276 | 260 |
277 // The load should now be committed. | 261 // The load should now be committed. |
278 EXPECT_EQ(controller.GetEntryCount(), 1); | 262 EXPECT_EQ(controller.GetEntryCount(), 1); |
279 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 263 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
280 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 264 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
281 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 265 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
282 EXPECT_FALSE(controller.GetPendingEntry()); | 266 EXPECT_FALSE(controller.GetPendingEntry()); |
283 ASSERT_TRUE(controller.GetActiveEntry()); | 267 ASSERT_TRUE(controller.GetActiveEntry()); |
284 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); | 268 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); |
285 EXPECT_FALSE(controller.CanGoBack()); | 269 EXPECT_FALSE(controller.CanGoBack()); |
286 EXPECT_FALSE(controller.CanGoForward()); | 270 EXPECT_FALSE(controller.CanGoForward()); |
287 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 271 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
288 | 272 |
289 // The timestamp should have been set. | 273 // The timestamp should have been set. |
290 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null()); | 274 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null()); |
291 | 275 |
292 // Load another... | 276 // Load another... |
293 controller.LoadURL( | 277 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
294 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
295 | 278 |
296 // The load should now be pending. | 279 // The load should now be pending. |
297 EXPECT_EQ(controller.GetEntryCount(), 1); | 280 EXPECT_EQ(controller.GetEntryCount(), 1); |
298 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 281 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
299 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 282 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
300 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 283 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
301 ASSERT_TRUE(controller.GetPendingEntry()); | 284 ASSERT_TRUE(controller.GetPendingEntry()); |
302 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); | 285 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); |
303 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 286 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
304 // TODO(darin): maybe this should really be true? | 287 // TODO(darin): maybe this should really be true? |
305 EXPECT_FALSE(controller.CanGoBack()); | 288 EXPECT_FALSE(controller.CanGoBack()); |
306 EXPECT_FALSE(controller.CanGoForward()); | 289 EXPECT_FALSE(controller.CanGoForward()); |
307 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 290 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
308 | 291 |
309 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 292 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
310 | 293 |
311 // Simulate the beforeunload ack for the cross-site transition, and then the | 294 // Simulate the beforeunload ack for the cross-site transition, and then the |
312 // commit. | 295 // commit. |
313 test_rvh()->SendShouldCloseACK(true); | 296 test_rvh()->SendShouldCloseACK(true); |
314 static_cast<TestRenderViewHost*>( | 297 static_cast<TestRenderViewHost*>( |
315 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); | 298 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); |
316 EXPECT_TRUE(notifications.Check1AndReset( | 299 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
317 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
318 | 300 |
319 // The load should now be committed. | 301 // The load should now be committed. |
320 EXPECT_EQ(controller.GetEntryCount(), 2); | 302 EXPECT_EQ(controller.GetEntryCount(), 2); |
321 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 303 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
322 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 304 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
323 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 305 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
324 EXPECT_FALSE(controller.GetPendingEntry()); | 306 EXPECT_FALSE(controller.GetPendingEntry()); |
325 ASSERT_TRUE(controller.GetActiveEntry()); | 307 ASSERT_TRUE(controller.GetActiveEntry()); |
326 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); | 308 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); |
327 EXPECT_TRUE(controller.CanGoBack()); | 309 EXPECT_TRUE(controller.CanGoBack()); |
(...skipping 16 matching lines...) Expand all Loading... |
344 TestNotificationTracker notifications; | 326 TestNotificationTracker notifications; |
345 RegisterForAllNavNotifications(¬ifications, &controller); | 327 RegisterForAllNavNotifications(¬ifications, &controller); |
346 | 328 |
347 // Set the clock to always return a timestamp of 1. | 329 // Set the clock to always return a timestamp of 1. |
348 controller.SetGetTimestampCallbackForTest( | 330 controller.SetGetTimestampCallbackForTest( |
349 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); | 331 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); |
350 | 332 |
351 const GURL url1("http://foo1"); | 333 const GURL url1("http://foo1"); |
352 const GURL url2("http://foo2"); | 334 const GURL url2("http://foo2"); |
353 | 335 |
354 controller.LoadURL( | 336 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
355 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
356 | 337 |
357 test_rvh()->SendNavigate(0, url1); | 338 test_rvh()->SendNavigate(0, url1); |
358 EXPECT_TRUE(notifications.Check1AndReset( | 339 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
359 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
360 | 340 |
361 // Load another... | 341 // Load another... |
362 controller.LoadURL( | 342 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
363 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
364 | 343 |
365 // Simulate the beforeunload ack for the cross-site transition, and then the | 344 // Simulate the beforeunload ack for the cross-site transition, and then the |
366 // commit. | 345 // commit. |
367 test_rvh()->SendShouldCloseACK(true); | 346 test_rvh()->SendShouldCloseACK(true); |
368 test_rvh()->SendNavigate(1, url2); | 347 test_rvh()->SendNavigate(1, url2); |
369 EXPECT_TRUE(notifications.Check1AndReset( | 348 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
370 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
371 | 349 |
372 // The two loads should now be committed. | 350 // The two loads should now be committed. |
373 ASSERT_EQ(controller.GetEntryCount(), 2); | 351 ASSERT_EQ(controller.GetEntryCount(), 2); |
374 | 352 |
375 // Timestamps should be distinct despite the clock returning the | 353 // Timestamps should be distinct despite the clock returning the |
376 // same value. | 354 // same value. |
377 EXPECT_EQ(1u, | 355 EXPECT_EQ(1u, |
378 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); | 356 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); |
379 EXPECT_EQ(2u, | 357 EXPECT_EQ(2u, |
380 controller.GetEntryAtIndex(1)->GetTimestamp().ToInternalValue()); | 358 controller.GetEntryAtIndex(1)->GetTimestamp().ToInternalValue()); |
(...skipping 22 matching lines...) Expand all Loading... |
403 EXPECT_EQ(load_params.browser_initiated_post_data, | 381 EXPECT_EQ(load_params.browser_initiated_post_data, |
404 entry->GetBrowserInitiatedPostData()); | 382 entry->GetBrowserInitiatedPostData()); |
405 EXPECT_EQ(load_params.transferred_global_request_id, | 383 EXPECT_EQ(load_params.transferred_global_request_id, |
406 entry->transferred_global_request_id()); | 384 entry->transferred_global_request_id()); |
407 } | 385 } |
408 | 386 |
409 TEST_F(NavigationControllerTest, LoadURLWithParams) { | 387 TEST_F(NavigationControllerTest, LoadURLWithParams) { |
410 NavigationControllerImpl& controller = controller_impl(); | 388 NavigationControllerImpl& controller = controller_impl(); |
411 | 389 |
412 NavigationController::LoadURLParams load_params(GURL("http://foo")); | 390 NavigationController::LoadURLParams load_params(GURL("http://foo")); |
413 load_params.referrer = content::Referrer(GURL("http://referrer"), | 391 load_params.referrer = |
414 WebKit::WebReferrerPolicyDefault); | 392 Referrer(GURL("http://referrer"), WebKit::WebReferrerPolicyDefault); |
415 load_params.transition_type = content::PAGE_TRANSITION_GENERATED; | 393 load_params.transition_type = PAGE_TRANSITION_GENERATED; |
416 load_params.extra_headers = "content-type: text/plain"; | 394 load_params.extra_headers = "content-type: text/plain"; |
417 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; | 395 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; |
418 load_params.is_renderer_initiated = true; | 396 load_params.is_renderer_initiated = true; |
419 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | 397 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; |
420 load_params.transferred_global_request_id = content::GlobalRequestID(2,3); | 398 load_params.transferred_global_request_id = GlobalRequestID(2,3); |
421 | 399 |
422 controller.LoadURLWithParams(load_params); | 400 controller.LoadURLWithParams(load_params); |
423 NavigationEntryImpl* entry = | 401 NavigationEntryImpl* entry = |
424 NavigationEntryImpl::FromNavigationEntry( | 402 NavigationEntryImpl::FromNavigationEntry( |
425 controller.GetPendingEntry()); | 403 controller.GetPendingEntry()); |
426 | 404 |
427 // The timestamp should not have been set yet. | 405 // The timestamp should not have been set yet. |
428 ASSERT_TRUE(entry); | 406 ASSERT_TRUE(entry); |
429 EXPECT_TRUE(entry->GetTimestamp().is_null()); | 407 EXPECT_TRUE(entry->GetTimestamp().is_null()); |
430 | 408 |
(...skipping 15 matching lines...) Expand all Loading... |
446 NavigationEntryImpl::FromNavigationEntry( | 424 NavigationEntryImpl::FromNavigationEntry( |
447 controller.GetPendingEntry()); | 425 controller.GetPendingEntry()); |
448 | 426 |
449 CheckNavigationEntryMatchLoadParams(load_params, entry); | 427 CheckNavigationEntryMatchLoadParams(load_params, entry); |
450 } | 428 } |
451 | 429 |
452 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { | 430 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { |
453 NavigationControllerImpl& controller = controller_impl(); | 431 NavigationControllerImpl& controller = controller_impl(); |
454 | 432 |
455 NavigationController::LoadURLParams load_params(GURL("https://posturl")); | 433 NavigationController::LoadURLParams load_params(GURL("https://posturl")); |
456 load_params.transition_type = content::PAGE_TRANSITION_TYPED; | 434 load_params.transition_type = PAGE_TRANSITION_TYPED; |
457 load_params.load_type = | 435 load_params.load_type = |
458 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | 436 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; |
459 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | 437 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; |
460 | 438 |
461 | 439 |
462 const unsigned char* raw_data = | 440 const unsigned char* raw_data = |
463 reinterpret_cast<const unsigned char*>("d\n\0a2"); | 441 reinterpret_cast<const unsigned char*>("d\n\0a2"); |
464 const int length = 5; | 442 const int length = 5; |
465 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | 443 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); |
466 scoped_refptr<base::RefCountedBytes> data = | 444 scoped_refptr<base::RefCountedBytes> data = |
(...skipping 12 matching lines...) Expand all Loading... |
479 // new session history entry. This is what happens when you press enter in the | 457 // new session history entry. This is what happens when you press enter in the |
480 // URL bar to reload: a pending entry is created and then it is discarded when | 458 // URL bar to reload: a pending entry is created and then it is discarded when |
481 // the load commits (because WebCore didn't actually make a new entry). | 459 // the load commits (because WebCore didn't actually make a new entry). |
482 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 460 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
483 NavigationControllerImpl& controller = controller_impl(); | 461 NavigationControllerImpl& controller = controller_impl(); |
484 TestNotificationTracker notifications; | 462 TestNotificationTracker notifications; |
485 RegisterForAllNavNotifications(¬ifications, &controller); | 463 RegisterForAllNavNotifications(¬ifications, &controller); |
486 | 464 |
487 const GURL url1("http://foo1"); | 465 const GURL url1("http://foo1"); |
488 | 466 |
489 controller.LoadURL( | 467 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
490 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
491 EXPECT_EQ(0U, notifications.size()); | 468 EXPECT_EQ(0U, notifications.size()); |
492 test_rvh()->SendNavigate(0, url1); | 469 test_rvh()->SendNavigate(0, url1); |
493 EXPECT_TRUE(notifications.Check1AndReset( | 470 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
494 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
495 | 471 |
496 ASSERT_TRUE(controller.GetActiveEntry()); | 472 ASSERT_TRUE(controller.GetActiveEntry()); |
497 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); | 473 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); |
498 EXPECT_FALSE(timestamp.is_null()); | 474 EXPECT_FALSE(timestamp.is_null()); |
499 | 475 |
500 controller.LoadURL( | 476 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
501 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
502 EXPECT_EQ(0U, notifications.size()); | 477 EXPECT_EQ(0U, notifications.size()); |
503 test_rvh()->SendNavigate(0, url1); | 478 test_rvh()->SendNavigate(0, url1); |
504 EXPECT_TRUE(notifications.Check1AndReset( | 479 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
505 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
506 | 480 |
507 // We should not have produced a new session history entry. | 481 // We should not have produced a new session history entry. |
508 EXPECT_EQ(controller.GetEntryCount(), 1); | 482 EXPECT_EQ(controller.GetEntryCount(), 1); |
509 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 483 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
510 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 484 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
511 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 485 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
512 EXPECT_FALSE(controller.GetPendingEntry()); | 486 EXPECT_FALSE(controller.GetPendingEntry()); |
513 ASSERT_TRUE(controller.GetActiveEntry()); | 487 ASSERT_TRUE(controller.GetActiveEntry()); |
514 EXPECT_FALSE(controller.CanGoBack()); | 488 EXPECT_FALSE(controller.CanGoBack()); |
515 EXPECT_FALSE(controller.CanGoForward()); | 489 EXPECT_FALSE(controller.CanGoForward()); |
516 | 490 |
517 // The timestamp should have been updated. | 491 // The timestamp should have been updated. |
518 // | 492 // |
519 // TODO(akalin): Change this EXPECT_GE (and other similar ones) to | 493 // TODO(akalin): Change this EXPECT_GE (and other similar ones) to |
520 // EXPECT_GT once we guarantee that timestamps are unique. | 494 // EXPECT_GT once we guarantee that timestamps are unique. |
521 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); | 495 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); |
522 } | 496 } |
523 | 497 |
524 // Tests loading a URL but discarding it before the load commits. | 498 // Tests loading a URL but discarding it before the load commits. |
525 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 499 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
526 NavigationControllerImpl& controller = controller_impl(); | 500 NavigationControllerImpl& controller = controller_impl(); |
527 TestNotificationTracker notifications; | 501 TestNotificationTracker notifications; |
528 RegisterForAllNavNotifications(¬ifications, &controller); | 502 RegisterForAllNavNotifications(¬ifications, &controller); |
529 | 503 |
530 const GURL url1("http://foo1"); | 504 const GURL url1("http://foo1"); |
531 const GURL url2("http://foo2"); | 505 const GURL url2("http://foo2"); |
532 | 506 |
533 controller.LoadURL( | 507 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
534 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
535 EXPECT_EQ(0U, notifications.size()); | 508 EXPECT_EQ(0U, notifications.size()); |
536 test_rvh()->SendNavigate(0, url1); | 509 test_rvh()->SendNavigate(0, url1); |
537 EXPECT_TRUE(notifications.Check1AndReset( | 510 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
538 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
539 | 511 |
540 ASSERT_TRUE(controller.GetActiveEntry()); | 512 ASSERT_TRUE(controller.GetActiveEntry()); |
541 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); | 513 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); |
542 EXPECT_FALSE(timestamp.is_null()); | 514 EXPECT_FALSE(timestamp.is_null()); |
543 | 515 |
544 controller.LoadURL( | 516 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
545 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
546 controller.DiscardNonCommittedEntries(); | 517 controller.DiscardNonCommittedEntries(); |
547 EXPECT_EQ(0U, notifications.size()); | 518 EXPECT_EQ(0U, notifications.size()); |
548 | 519 |
549 // Should not have produced a new session history entry. | 520 // Should not have produced a new session history entry. |
550 EXPECT_EQ(controller.GetEntryCount(), 1); | 521 EXPECT_EQ(controller.GetEntryCount(), 1); |
551 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 522 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
552 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 523 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
553 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 524 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
554 EXPECT_FALSE(controller.GetPendingEntry()); | 525 EXPECT_FALSE(controller.GetPendingEntry()); |
555 ASSERT_TRUE(controller.GetActiveEntry()); | 526 ASSERT_TRUE(controller.GetActiveEntry()); |
556 EXPECT_FALSE(controller.CanGoBack()); | 527 EXPECT_FALSE(controller.CanGoBack()); |
557 EXPECT_FALSE(controller.CanGoForward()); | 528 EXPECT_FALSE(controller.CanGoForward()); |
558 | 529 |
559 // Timestamp should not have changed. | 530 // Timestamp should not have changed. |
560 EXPECT_EQ(timestamp, controller.GetActiveEntry()->GetTimestamp()); | 531 EXPECT_EQ(timestamp, controller.GetActiveEntry()->GetTimestamp()); |
561 } | 532 } |
562 | 533 |
563 // Tests navigations that come in unrequested. This happens when the user | 534 // Tests navigations that come in unrequested. This happens when the user |
564 // navigates from the web page, and here we test that there is no pending entry. | 535 // navigates from the web page, and here we test that there is no pending entry. |
565 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 536 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
566 NavigationControllerImpl& controller = controller_impl(); | 537 NavigationControllerImpl& controller = controller_impl(); |
567 TestNotificationTracker notifications; | 538 TestNotificationTracker notifications; |
568 RegisterForAllNavNotifications(¬ifications, &controller); | 539 RegisterForAllNavNotifications(¬ifications, &controller); |
569 | 540 |
570 // First make an existing committed entry. | 541 // First make an existing committed entry. |
571 const GURL kExistingURL1("http://eh"); | 542 const GURL kExistingURL1("http://eh"); |
572 controller.LoadURL(kExistingURL1, content::Referrer(), | 543 controller.LoadURL( |
573 content::PAGE_TRANSITION_TYPED, std::string()); | 544 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
574 test_rvh()->SendNavigate(0, kExistingURL1); | 545 test_rvh()->SendNavigate(0, kExistingURL1); |
575 EXPECT_TRUE(notifications.Check1AndReset( | 546 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
576 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
577 | 547 |
578 // Do a new navigation without making a pending one. | 548 // Do a new navigation without making a pending one. |
579 const GURL kNewURL("http://see"); | 549 const GURL kNewURL("http://see"); |
580 test_rvh()->SendNavigate(99, kNewURL); | 550 test_rvh()->SendNavigate(99, kNewURL); |
581 | 551 |
582 // There should no longer be any pending entry, and the third navigation we | 552 // There should no longer be any pending entry, and the third navigation we |
583 // just made should be committed. | 553 // just made should be committed. |
584 EXPECT_TRUE(notifications.Check1AndReset( | 554 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
585 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
586 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 555 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
587 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 556 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
588 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); | 557 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); |
589 } | 558 } |
590 | 559 |
591 // Tests navigating to a new URL when there is a new pending navigation that is | 560 // Tests navigating to a new URL when there is a new pending navigation that is |
592 // not the one that just loaded. This will happen if the user types in a URL to | 561 // not the one that just loaded. This will happen if the user types in a URL to |
593 // somewhere slow, and then navigates the current page before the typed URL | 562 // somewhere slow, and then navigates the current page before the typed URL |
594 // commits. | 563 // commits. |
595 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 564 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
596 NavigationControllerImpl& controller = controller_impl(); | 565 NavigationControllerImpl& controller = controller_impl(); |
597 TestNotificationTracker notifications; | 566 TestNotificationTracker notifications; |
598 RegisterForAllNavNotifications(¬ifications, &controller); | 567 RegisterForAllNavNotifications(¬ifications, &controller); |
599 | 568 |
600 // First make an existing committed entry. | 569 // First make an existing committed entry. |
601 const GURL kExistingURL1("http://eh"); | 570 const GURL kExistingURL1("http://eh"); |
602 controller.LoadURL(kExistingURL1, content::Referrer(), | 571 controller.LoadURL( |
603 content::PAGE_TRANSITION_TYPED, std::string()); | 572 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
604 test_rvh()->SendNavigate(0, kExistingURL1); | 573 test_rvh()->SendNavigate(0, kExistingURL1); |
605 EXPECT_TRUE(notifications.Check1AndReset( | 574 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
606 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
607 | 575 |
608 // Make a pending entry to somewhere new. | 576 // Make a pending entry to somewhere new. |
609 const GURL kExistingURL2("http://bee"); | 577 const GURL kExistingURL2("http://bee"); |
610 controller.LoadURL(kExistingURL2, content::Referrer(), | 578 controller.LoadURL( |
611 content::PAGE_TRANSITION_TYPED, std::string()); | 579 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
612 EXPECT_EQ(0U, notifications.size()); | 580 EXPECT_EQ(0U, notifications.size()); |
613 | 581 |
614 // After the beforeunload but before it commits, do a new navigation. | 582 // After the beforeunload but before it commits, do a new navigation. |
615 test_rvh()->SendShouldCloseACK(true); | 583 test_rvh()->SendShouldCloseACK(true); |
616 const GURL kNewURL("http://see"); | 584 const GURL kNewURL("http://see"); |
617 static_cast<TestRenderViewHost*>( | 585 static_cast<TestRenderViewHost*>( |
618 contents()->GetPendingRenderViewHost())->SendNavigate(3, kNewURL); | 586 contents()->GetPendingRenderViewHost())->SendNavigate(3, kNewURL); |
619 | 587 |
620 // There should no longer be any pending entry, and the third navigation we | 588 // There should no longer be any pending entry, and the third navigation we |
621 // just made should be committed. | 589 // just made should be committed. |
622 EXPECT_TRUE(notifications.Check1AndReset( | 590 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
623 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
624 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 591 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
625 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 592 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
626 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); | 593 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); |
627 } | 594 } |
628 | 595 |
629 // Tests navigating to a new URL when there is a pending back/forward | 596 // Tests navigating to a new URL when there is a pending back/forward |
630 // navigation. This will happen if the user hits back, but before that commits, | 597 // navigation. This will happen if the user hits back, but before that commits, |
631 // they navigate somewhere new. | 598 // they navigate somewhere new. |
632 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 599 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
633 NavigationControllerImpl& controller = controller_impl(); | 600 NavigationControllerImpl& controller = controller_impl(); |
634 TestNotificationTracker notifications; | 601 TestNotificationTracker notifications; |
635 RegisterForAllNavNotifications(¬ifications, &controller); | 602 RegisterForAllNavNotifications(¬ifications, &controller); |
636 | 603 |
637 // First make some history. | 604 // First make some history. |
638 const GURL kExistingURL1("http://foo/eh"); | 605 const GURL kExistingURL1("http://foo/eh"); |
639 controller.LoadURL(kExistingURL1, content::Referrer(), | 606 controller.LoadURL( |
640 content::PAGE_TRANSITION_TYPED, std::string()); | 607 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
641 test_rvh()->SendNavigate(0, kExistingURL1); | 608 test_rvh()->SendNavigate(0, kExistingURL1); |
642 EXPECT_TRUE(notifications.Check1AndReset( | 609 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
643 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
644 | 610 |
645 const GURL kExistingURL2("http://foo/bee"); | 611 const GURL kExistingURL2("http://foo/bee"); |
646 controller.LoadURL(kExistingURL2, content::Referrer(), | 612 controller.LoadURL( |
647 content::PAGE_TRANSITION_TYPED, std::string()); | 613 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
648 test_rvh()->SendNavigate(1, kExistingURL2); | 614 test_rvh()->SendNavigate(1, kExistingURL2); |
649 EXPECT_TRUE(notifications.Check1AndReset( | 615 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
650 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
651 | 616 |
652 // Now make a pending back/forward navigation. The zeroth entry should be | 617 // Now make a pending back/forward navigation. The zeroth entry should be |
653 // pending. | 618 // pending. |
654 controller.GoBack(); | 619 controller.GoBack(); |
655 EXPECT_EQ(0U, notifications.size()); | 620 EXPECT_EQ(0U, notifications.size()); |
656 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 621 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
657 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 622 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
658 | 623 |
659 // Before that commits, do a new navigation. | 624 // Before that commits, do a new navigation. |
660 const GURL kNewURL("http://foo/see"); | 625 const GURL kNewURL("http://foo/see"); |
661 content::LoadCommittedDetails details; | 626 LoadCommittedDetails details; |
662 test_rvh()->SendNavigate(3, kNewURL); | 627 test_rvh()->SendNavigate(3, kNewURL); |
663 | 628 |
664 // There should no longer be any pending entry, and the third navigation we | 629 // There should no longer be any pending entry, and the third navigation we |
665 // just made should be committed. | 630 // just made should be committed. |
666 EXPECT_TRUE(notifications.Check1AndReset( | 631 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
667 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
668 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 632 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
669 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 633 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
670 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); | 634 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); |
671 } | 635 } |
672 | 636 |
673 // Tests navigating to an existing URL when there is a pending new navigation. | 637 // Tests navigating to an existing URL when there is a pending new navigation. |
674 // This will happen if the user enters a URL, but before that commits, the | 638 // This will happen if the user enters a URL, but before that commits, the |
675 // current page fires history.back(). | 639 // current page fires history.back(). |
676 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 640 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
677 NavigationControllerImpl& controller = controller_impl(); | 641 NavigationControllerImpl& controller = controller_impl(); |
678 TestNotificationTracker notifications; | 642 TestNotificationTracker notifications; |
679 RegisterForAllNavNotifications(¬ifications, &controller); | 643 RegisterForAllNavNotifications(¬ifications, &controller); |
680 | 644 |
681 // First make some history. | 645 // First make some history. |
682 const GURL kExistingURL1("http://foo/eh"); | 646 const GURL kExistingURL1("http://foo/eh"); |
683 controller.LoadURL(kExistingURL1, content::Referrer(), | 647 controller.LoadURL( |
684 content::PAGE_TRANSITION_TYPED, std::string()); | 648 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
685 test_rvh()->SendNavigate(0, kExistingURL1); | 649 test_rvh()->SendNavigate(0, kExistingURL1); |
686 EXPECT_TRUE(notifications.Check1AndReset( | 650 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
687 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
688 | 651 |
689 const GURL kExistingURL2("http://foo/bee"); | 652 const GURL kExistingURL2("http://foo/bee"); |
690 controller.LoadURL(kExistingURL2, content::Referrer(), | 653 controller.LoadURL( |
691 content::PAGE_TRANSITION_TYPED, std::string()); | 654 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
692 test_rvh()->SendNavigate(1, kExistingURL2); | 655 test_rvh()->SendNavigate(1, kExistingURL2); |
693 EXPECT_TRUE(notifications.Check1AndReset( | 656 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
694 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
695 | 657 |
696 // Now make a pending new navigation. | 658 // Now make a pending new navigation. |
697 const GURL kNewURL("http://foo/see"); | 659 const GURL kNewURL("http://foo/see"); |
698 controller.LoadURL( | 660 controller.LoadURL( |
699 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 661 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
700 std::string()); | |
701 EXPECT_EQ(0U, notifications.size()); | 662 EXPECT_EQ(0U, notifications.size()); |
702 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 663 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
703 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 664 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
704 | 665 |
705 // Before that commits, a back navigation from the renderer commits. | 666 // Before that commits, a back navigation from the renderer commits. |
706 test_rvh()->SendNavigate(0, kExistingURL1); | 667 test_rvh()->SendNavigate(0, kExistingURL1); |
707 | 668 |
708 // There should no longer be any pending entry, and the back navigation we | 669 // There should no longer be any pending entry, and the back navigation we |
709 // just made should be committed. | 670 // just made should be committed. |
710 EXPECT_TRUE(notifications.Check1AndReset( | 671 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
711 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
712 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 672 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
713 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 673 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
714 EXPECT_EQ(kExistingURL1, controller.GetActiveEntry()->GetURL()); | 674 EXPECT_EQ(kExistingURL1, controller.GetActiveEntry()->GetURL()); |
715 } | 675 } |
716 | 676 |
717 // Tests an ignored navigation when there is a pending new navigation. | 677 // Tests an ignored navigation when there is a pending new navigation. |
718 // This will happen if the user enters a URL, but before that commits, the | 678 // This will happen if the user enters a URL, but before that commits, the |
719 // current blank page reloads. See http://crbug.com/77507. | 679 // current blank page reloads. See http://crbug.com/77507. |
720 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { | 680 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { |
721 NavigationControllerImpl& controller = controller_impl(); | 681 NavigationControllerImpl& controller = controller_impl(); |
722 TestNotificationTracker notifications; | 682 TestNotificationTracker notifications; |
723 RegisterForAllNavNotifications(¬ifications, &controller); | 683 RegisterForAllNavNotifications(¬ifications, &controller); |
724 | 684 |
725 // Set a WebContentsDelegate to listen for state changes. | 685 // Set a WebContentsDelegate to listen for state changes. |
726 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 686 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
727 EXPECT_FALSE(contents()->GetDelegate()); | 687 EXPECT_FALSE(contents()->GetDelegate()); |
728 contents()->SetDelegate(delegate.get()); | 688 contents()->SetDelegate(delegate.get()); |
729 | 689 |
730 // Without any navigations, the renderer starts at about:blank. | 690 // Without any navigations, the renderer starts at about:blank. |
731 const GURL kExistingURL("about:blank"); | 691 const GURL kExistingURL("about:blank"); |
732 | 692 |
733 // Now make a pending new navigation. | 693 // Now make a pending new navigation. |
734 const GURL kNewURL("http://eh"); | 694 const GURL kNewURL("http://eh"); |
735 controller.LoadURL( | 695 controller.LoadURL( |
736 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 696 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
737 std::string()); | |
738 EXPECT_EQ(0U, notifications.size()); | 697 EXPECT_EQ(0U, notifications.size()); |
739 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 698 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
740 EXPECT_TRUE(controller.GetPendingEntry()); | 699 EXPECT_TRUE(controller.GetPendingEntry()); |
741 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 700 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
742 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 701 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
743 | 702 |
744 // Before that commits, a document.write and location.reload can cause the | 703 // Before that commits, a document.write and location.reload can cause the |
745 // renderer to send a FrameNavigate with page_id -1. | 704 // renderer to send a FrameNavigate with page_id -1. |
746 test_rvh()->SendNavigate(-1, kExistingURL); | 705 test_rvh()->SendNavigate(-1, kExistingURL); |
747 | 706 |
(...skipping 19 matching lines...) Expand all Loading... |
767 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 726 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
768 EXPECT_FALSE(contents()->GetDelegate()); | 727 EXPECT_FALSE(contents()->GetDelegate()); |
769 contents()->SetDelegate(delegate.get()); | 728 contents()->SetDelegate(delegate.get()); |
770 | 729 |
771 // Without any navigations, the renderer starts at about:blank. | 730 // Without any navigations, the renderer starts at about:blank. |
772 const GURL kExistingURL("about:blank"); | 731 const GURL kExistingURL("about:blank"); |
773 | 732 |
774 // Now make a pending new navigation. | 733 // Now make a pending new navigation. |
775 const GURL kNewURL("http://eh"); | 734 const GURL kNewURL("http://eh"); |
776 controller.LoadURL( | 735 controller.LoadURL( |
777 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 736 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
778 std::string()); | |
779 EXPECT_EQ(0U, notifications.size()); | 737 EXPECT_EQ(0U, notifications.size()); |
780 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 738 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
781 EXPECT_TRUE(controller.GetPendingEntry()); | 739 EXPECT_TRUE(controller.GetPendingEntry()); |
782 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 740 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
783 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 741 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
784 | 742 |
785 // It may abort before committing, if it's a download or due to a stop or | 743 // It may abort before committing, if it's a download or due to a stop or |
786 // a new navigation from the user. | 744 // a new navigation from the user. |
787 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; | 745 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
788 params.frame_id = 1; | 746 params.frame_id = 1; |
(...skipping 27 matching lines...) Expand all Loading... |
816 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 774 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
817 EXPECT_FALSE(contents()->GetDelegate()); | 775 EXPECT_FALSE(contents()->GetDelegate()); |
818 contents()->SetDelegate(delegate.get()); | 776 contents()->SetDelegate(delegate.get()); |
819 | 777 |
820 // Without any navigations, the renderer starts at about:blank. | 778 // Without any navigations, the renderer starts at about:blank. |
821 const GURL kExistingURL("about:blank"); | 779 const GURL kExistingURL("about:blank"); |
822 | 780 |
823 // Now make a pending new navigation, initiated by the renderer. | 781 // Now make a pending new navigation, initiated by the renderer. |
824 const GURL kNewURL("http://eh"); | 782 const GURL kNewURL("http://eh"); |
825 NavigationController::LoadURLParams load_url_params(kNewURL); | 783 NavigationController::LoadURLParams load_url_params(kNewURL); |
826 load_url_params.transition_type = content::PAGE_TRANSITION_TYPED; | 784 load_url_params.transition_type = PAGE_TRANSITION_TYPED; |
827 load_url_params.is_renderer_initiated = true; | 785 load_url_params.is_renderer_initiated = true; |
828 controller.LoadURLWithParams(load_url_params); | 786 controller.LoadURLWithParams(load_url_params); |
829 EXPECT_EQ(0U, notifications.size()); | 787 EXPECT_EQ(0U, notifications.size()); |
830 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 788 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
831 EXPECT_TRUE(controller.GetPendingEntry()); | 789 EXPECT_TRUE(controller.GetPendingEntry()); |
832 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 790 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
833 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 791 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
834 | 792 |
835 // There should be no visible entry (resulting in about:blank in the | 793 // There should be no visible entry (resulting in about:blank in the |
836 // omnibox), because it was renderer-initiated and there's no last committed | 794 // omnibox), because it was renderer-initiated and there's no last committed |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 contents()->SetDelegate(NULL); | 835 contents()->SetDelegate(NULL); |
878 } | 836 } |
879 | 837 |
880 TEST_F(NavigationControllerTest, Reload) { | 838 TEST_F(NavigationControllerTest, Reload) { |
881 NavigationControllerImpl& controller = controller_impl(); | 839 NavigationControllerImpl& controller = controller_impl(); |
882 TestNotificationTracker notifications; | 840 TestNotificationTracker notifications; |
883 RegisterForAllNavNotifications(¬ifications, &controller); | 841 RegisterForAllNavNotifications(¬ifications, &controller); |
884 | 842 |
885 const GURL url1("http://foo1"); | 843 const GURL url1("http://foo1"); |
886 | 844 |
887 controller.LoadURL( | 845 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
888 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
889 EXPECT_EQ(0U, notifications.size()); | 846 EXPECT_EQ(0U, notifications.size()); |
890 test_rvh()->SendNavigate(0, url1); | 847 test_rvh()->SendNavigate(0, url1); |
891 EXPECT_TRUE(notifications.Check1AndReset( | 848 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
892 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
893 ASSERT_TRUE(controller.GetActiveEntry()); | 849 ASSERT_TRUE(controller.GetActiveEntry()); |
894 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); | 850 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); |
895 controller.Reload(true); | 851 controller.Reload(true); |
896 EXPECT_EQ(0U, notifications.size()); | 852 EXPECT_EQ(0U, notifications.size()); |
897 | 853 |
898 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); | 854 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); |
899 EXPECT_FALSE(timestamp.is_null()); | 855 EXPECT_FALSE(timestamp.is_null()); |
900 | 856 |
901 // The reload is pending. | 857 // The reload is pending. |
902 EXPECT_EQ(controller.GetEntryCount(), 1); | 858 EXPECT_EQ(controller.GetEntryCount(), 1); |
903 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 859 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
904 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 860 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
905 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 861 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
906 EXPECT_TRUE(controller.GetPendingEntry()); | 862 EXPECT_TRUE(controller.GetPendingEntry()); |
907 EXPECT_FALSE(controller.CanGoBack()); | 863 EXPECT_FALSE(controller.CanGoBack()); |
908 EXPECT_FALSE(controller.CanGoForward()); | 864 EXPECT_FALSE(controller.CanGoForward()); |
909 // Make sure the title has been cleared (will be redrawn just after reload). | 865 // Make sure the title has been cleared (will be redrawn just after reload). |
910 // Avoids a stale cached title when the new page being reloaded has no title. | 866 // Avoids a stale cached title when the new page being reloaded has no title. |
911 // See http://crbug.com/96041. | 867 // See http://crbug.com/96041. |
912 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); | 868 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); |
913 | 869 |
914 test_rvh()->SendNavigate(0, url1); | 870 test_rvh()->SendNavigate(0, url1); |
915 EXPECT_TRUE(notifications.Check1AndReset( | 871 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
916 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
917 | 872 |
918 // Now the reload is committed. | 873 // Now the reload is committed. |
919 EXPECT_EQ(controller.GetEntryCount(), 1); | 874 EXPECT_EQ(controller.GetEntryCount(), 1); |
920 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 875 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
921 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 876 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
922 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 877 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
923 EXPECT_FALSE(controller.GetPendingEntry()); | 878 EXPECT_FALSE(controller.GetPendingEntry()); |
924 EXPECT_FALSE(controller.CanGoBack()); | 879 EXPECT_FALSE(controller.CanGoBack()); |
925 EXPECT_FALSE(controller.CanGoForward()); | 880 EXPECT_FALSE(controller.CanGoForward()); |
926 | 881 |
927 // The timestamp should have been updated. | 882 // The timestamp should have been updated. |
928 ASSERT_TRUE(controller.GetActiveEntry()); | 883 ASSERT_TRUE(controller.GetActiveEntry()); |
929 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); | 884 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); |
930 } | 885 } |
931 | 886 |
932 // Tests what happens when a reload navigation produces a new page. | 887 // Tests what happens when a reload navigation produces a new page. |
933 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 888 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
934 NavigationControllerImpl& controller = controller_impl(); | 889 NavigationControllerImpl& controller = controller_impl(); |
935 TestNotificationTracker notifications; | 890 TestNotificationTracker notifications; |
936 RegisterForAllNavNotifications(¬ifications, &controller); | 891 RegisterForAllNavNotifications(¬ifications, &controller); |
937 | 892 |
938 const GURL url1("http://foo1"); | 893 const GURL url1("http://foo1"); |
939 const GURL url2("http://foo2"); | 894 const GURL url2("http://foo2"); |
940 | 895 |
941 controller.LoadURL( | 896 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
942 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
943 test_rvh()->SendNavigate(0, url1); | 897 test_rvh()->SendNavigate(0, url1); |
944 EXPECT_TRUE(notifications.Check1AndReset( | 898 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
945 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
946 | 899 |
947 controller.Reload(true); | 900 controller.Reload(true); |
948 EXPECT_EQ(0U, notifications.size()); | 901 EXPECT_EQ(0U, notifications.size()); |
949 | 902 |
950 test_rvh()->SendNavigate(1, url2); | 903 test_rvh()->SendNavigate(1, url2); |
951 EXPECT_TRUE(notifications.Check1AndReset( | 904 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
952 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
953 | 905 |
954 // Now the reload is committed. | 906 // Now the reload is committed. |
955 EXPECT_EQ(controller.GetEntryCount(), 2); | 907 EXPECT_EQ(controller.GetEntryCount(), 2); |
956 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 908 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
957 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 909 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
958 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 910 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
959 EXPECT_FALSE(controller.GetPendingEntry()); | 911 EXPECT_FALSE(controller.GetPendingEntry()); |
960 EXPECT_TRUE(controller.CanGoBack()); | 912 EXPECT_TRUE(controller.CanGoBack()); |
961 EXPECT_FALSE(controller.CanGoForward()); | 913 EXPECT_FALSE(controller.CanGoForward()); |
962 } | 914 } |
963 | 915 |
964 class TestNavigationObserver : public content::RenderViewHostObserver { | 916 class TestNavigationObserver : public RenderViewHostObserver { |
965 public: | 917 public: |
966 TestNavigationObserver(content::RenderViewHost* render_view_host) | 918 TestNavigationObserver(RenderViewHost* render_view_host) |
967 : RenderViewHostObserver(render_view_host) { | 919 : RenderViewHostObserver(render_view_host) { |
968 } | 920 } |
969 | 921 |
970 const GURL& navigated_url() const { | 922 const GURL& navigated_url() const { |
971 return navigated_url_; | 923 return navigated_url_; |
972 } | 924 } |
973 | 925 |
974 protected: | 926 protected: |
975 virtual void Navigate(const GURL& url) OVERRIDE { | 927 virtual void Navigate(const GURL& url) OVERRIDE { |
976 navigated_url_ = url; | 928 navigated_url_ = url; |
977 } | 929 } |
978 | 930 |
979 private: | 931 private: |
980 GURL navigated_url_; | 932 GURL navigated_url_; |
981 }; | 933 }; |
982 | 934 |
983 TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { | 935 TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { |
984 NavigationControllerImpl& controller = controller_impl(); | 936 NavigationControllerImpl& controller = controller_impl(); |
985 TestNotificationTracker notifications; | 937 TestNotificationTracker notifications; |
986 RegisterForAllNavNotifications(¬ifications, &controller); | 938 RegisterForAllNavNotifications(¬ifications, &controller); |
987 TestNavigationObserver observer(test_rvh()); | 939 TestNavigationObserver observer(test_rvh()); |
988 | 940 |
989 const GURL original_url("http://foo1"); | 941 const GURL original_url("http://foo1"); |
990 const GURL final_url("http://foo2"); | 942 const GURL final_url("http://foo2"); |
991 | 943 |
992 // Load up the original URL, but get redirected. | 944 // Load up the original URL, but get redirected. |
993 controller.LoadURL(original_url, content::Referrer(), | 945 controller.LoadURL( |
994 content::PAGE_TRANSITION_TYPED, std::string()); | 946 original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
995 EXPECT_EQ(0U, notifications.size()); | 947 EXPECT_EQ(0U, notifications.size()); |
996 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); | 948 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); |
997 EXPECT_TRUE(notifications.Check1AndReset( | 949 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
998 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
999 | 950 |
1000 // The NavigationEntry should save both the original URL and the final | 951 // The NavigationEntry should save both the original URL and the final |
1001 // redirected URL. | 952 // redirected URL. |
1002 EXPECT_EQ(original_url, controller.GetActiveEntry()->GetOriginalRequestURL()); | 953 EXPECT_EQ(original_url, controller.GetActiveEntry()->GetOriginalRequestURL()); |
1003 EXPECT_EQ(final_url, controller.GetActiveEntry()->GetURL()); | 954 EXPECT_EQ(final_url, controller.GetActiveEntry()->GetURL()); |
1004 | 955 |
1005 // Reload using the original URL. | 956 // Reload using the original URL. |
1006 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); | 957 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); |
1007 controller.ReloadOriginalRequestURL(false); | 958 controller.ReloadOriginalRequestURL(false); |
1008 EXPECT_EQ(0U, notifications.size()); | 959 EXPECT_EQ(0U, notifications.size()); |
1009 | 960 |
1010 // The reload is pending. The request should point to the original URL. | 961 // The reload is pending. The request should point to the original URL. |
1011 EXPECT_EQ(original_url, observer.navigated_url()); | 962 EXPECT_EQ(original_url, observer.navigated_url()); |
1012 EXPECT_EQ(controller.GetEntryCount(), 1); | 963 EXPECT_EQ(controller.GetEntryCount(), 1); |
1013 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 964 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1014 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 965 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1015 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 966 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1016 EXPECT_TRUE(controller.GetPendingEntry()); | 967 EXPECT_TRUE(controller.GetPendingEntry()); |
1017 EXPECT_FALSE(controller.CanGoBack()); | 968 EXPECT_FALSE(controller.CanGoBack()); |
1018 EXPECT_FALSE(controller.CanGoForward()); | 969 EXPECT_FALSE(controller.CanGoForward()); |
1019 | 970 |
1020 // Make sure the title has been cleared (will be redrawn just after reload). | 971 // Make sure the title has been cleared (will be redrawn just after reload). |
1021 // Avoids a stale cached title when the new page being reloaded has no title. | 972 // Avoids a stale cached title when the new page being reloaded has no title. |
1022 // See http://crbug.com/96041. | 973 // See http://crbug.com/96041. |
1023 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); | 974 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); |
1024 | 975 |
1025 // Send that the navigation has proceeded; say it got redirected again. | 976 // Send that the navigation has proceeded; say it got redirected again. |
1026 test_rvh()->SendNavigate(0, final_url); | 977 test_rvh()->SendNavigate(0, final_url); |
1027 EXPECT_TRUE(notifications.Check1AndReset( | 978 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1028 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1029 | 979 |
1030 // Now the reload is committed. | 980 // Now the reload is committed. |
1031 EXPECT_EQ(controller.GetEntryCount(), 1); | 981 EXPECT_EQ(controller.GetEntryCount(), 1); |
1032 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 982 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1033 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 983 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1034 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 984 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1035 EXPECT_FALSE(controller.GetPendingEntry()); | 985 EXPECT_FALSE(controller.GetPendingEntry()); |
1036 EXPECT_FALSE(controller.CanGoBack()); | 986 EXPECT_FALSE(controller.CanGoBack()); |
1037 EXPECT_FALSE(controller.CanGoForward()); | 987 EXPECT_FALSE(controller.CanGoForward()); |
1038 } | 988 } |
1039 | 989 |
1040 // Tests what happens when we navigate back successfully | 990 // Tests what happens when we navigate back successfully |
1041 TEST_F(NavigationControllerTest, Back) { | 991 TEST_F(NavigationControllerTest, Back) { |
1042 NavigationControllerImpl& controller = controller_impl(); | 992 NavigationControllerImpl& controller = controller_impl(); |
1043 TestNotificationTracker notifications; | 993 TestNotificationTracker notifications; |
1044 RegisterForAllNavNotifications(¬ifications, &controller); | 994 RegisterForAllNavNotifications(¬ifications, &controller); |
1045 | 995 |
1046 const GURL url1("http://foo1"); | 996 const GURL url1("http://foo1"); |
1047 test_rvh()->SendNavigate(0, url1); | 997 test_rvh()->SendNavigate(0, url1); |
1048 EXPECT_TRUE(notifications.Check1AndReset( | 998 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1049 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1050 | 999 |
1051 const GURL url2("http://foo2"); | 1000 const GURL url2("http://foo2"); |
1052 test_rvh()->SendNavigate(1, url2); | 1001 test_rvh()->SendNavigate(1, url2); |
1053 EXPECT_TRUE(notifications.Check1AndReset( | 1002 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1054 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1055 | 1003 |
1056 controller.GoBack(); | 1004 controller.GoBack(); |
1057 EXPECT_EQ(0U, notifications.size()); | 1005 EXPECT_EQ(0U, notifications.size()); |
1058 | 1006 |
1059 // We should now have a pending navigation to go back. | 1007 // We should now have a pending navigation to go back. |
1060 EXPECT_EQ(controller.GetEntryCount(), 2); | 1008 EXPECT_EQ(controller.GetEntryCount(), 2); |
1061 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1009 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1062 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1010 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1063 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1011 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1064 EXPECT_TRUE(controller.GetPendingEntry()); | 1012 EXPECT_TRUE(controller.GetPendingEntry()); |
1065 EXPECT_FALSE(controller.CanGoBack()); | 1013 EXPECT_FALSE(controller.CanGoBack()); |
1066 EXPECT_TRUE(controller.CanGoForward()); | 1014 EXPECT_TRUE(controller.CanGoForward()); |
1067 | 1015 |
1068 // Timestamp for entry 1 should be on or after that of entry 0. | 1016 // Timestamp for entry 1 should be on or after that of entry 0. |
1069 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1017 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
1070 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), | 1018 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), |
1071 controller.GetEntryAtIndex(0)->GetTimestamp()); | 1019 controller.GetEntryAtIndex(0)->GetTimestamp()); |
1072 | 1020 |
1073 test_rvh()->SendNavigate(0, url2); | 1021 test_rvh()->SendNavigate(0, url2); |
1074 EXPECT_TRUE(notifications.Check1AndReset( | 1022 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1075 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1076 | 1023 |
1077 // The back navigation completed successfully. | 1024 // The back navigation completed successfully. |
1078 EXPECT_EQ(controller.GetEntryCount(), 2); | 1025 EXPECT_EQ(controller.GetEntryCount(), 2); |
1079 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1026 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1080 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1027 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1081 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1028 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1082 EXPECT_FALSE(controller.GetPendingEntry()); | 1029 EXPECT_FALSE(controller.GetPendingEntry()); |
1083 EXPECT_FALSE(controller.CanGoBack()); | 1030 EXPECT_FALSE(controller.CanGoBack()); |
1084 EXPECT_TRUE(controller.CanGoForward()); | 1031 EXPECT_TRUE(controller.CanGoForward()); |
1085 | 1032 |
1086 // Timestamp for entry 0 should be on or after that of entry 1 | 1033 // Timestamp for entry 0 should be on or after that of entry 1 |
1087 // (since we went back to it). | 1034 // (since we went back to it). |
1088 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1035 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
1089 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1036 controller.GetEntryAtIndex(1)->GetTimestamp()); |
1090 } | 1037 } |
1091 | 1038 |
1092 // Tests what happens when a back navigation produces a new page. | 1039 // Tests what happens when a back navigation produces a new page. |
1093 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { | 1040 TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { |
1094 NavigationControllerImpl& controller = controller_impl(); | 1041 NavigationControllerImpl& controller = controller_impl(); |
1095 TestNotificationTracker notifications; | 1042 TestNotificationTracker notifications; |
1096 RegisterForAllNavNotifications(¬ifications, &controller); | 1043 RegisterForAllNavNotifications(¬ifications, &controller); |
1097 | 1044 |
1098 const GURL url1("http://foo/1"); | 1045 const GURL url1("http://foo/1"); |
1099 const GURL url2("http://foo/2"); | 1046 const GURL url2("http://foo/2"); |
1100 const GURL url3("http://foo/3"); | 1047 const GURL url3("http://foo/3"); |
1101 | 1048 |
1102 controller.LoadURL( | 1049 controller.LoadURL( |
1103 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1050 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1104 test_rvh()->SendNavigate(0, url1); | 1051 test_rvh()->SendNavigate(0, url1); |
1105 EXPECT_TRUE(notifications.Check1AndReset( | 1052 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1106 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1107 | 1053 |
1108 controller.LoadURL( | 1054 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1109 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1110 test_rvh()->SendNavigate(1, url2); | 1055 test_rvh()->SendNavigate(1, url2); |
1111 EXPECT_TRUE(notifications.Check1AndReset( | 1056 EXPECT_TRUE(notifications.Check1AndReset( |
1112 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1057 NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1113 | 1058 |
1114 controller.GoBack(); | 1059 controller.GoBack(); |
1115 EXPECT_EQ(0U, notifications.size()); | 1060 EXPECT_EQ(0U, notifications.size()); |
1116 | 1061 |
1117 // We should now have a pending navigation to go back. | 1062 // We should now have a pending navigation to go back. |
1118 EXPECT_EQ(controller.GetEntryCount(), 2); | 1063 EXPECT_EQ(controller.GetEntryCount(), 2); |
1119 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1064 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1120 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1065 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1121 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1066 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1122 EXPECT_TRUE(controller.GetPendingEntry()); | 1067 EXPECT_TRUE(controller.GetPendingEntry()); |
1123 EXPECT_FALSE(controller.CanGoBack()); | 1068 EXPECT_FALSE(controller.CanGoBack()); |
1124 EXPECT_TRUE(controller.CanGoForward()); | 1069 EXPECT_TRUE(controller.CanGoForward()); |
1125 | 1070 |
1126 test_rvh()->SendNavigate(2, url3); | 1071 test_rvh()->SendNavigate(2, url3); |
1127 EXPECT_TRUE(notifications.Check1AndReset( | 1072 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1128 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1129 | 1073 |
1130 // The back navigation resulted in a completely new navigation. | 1074 // The back navigation resulted in a completely new navigation. |
1131 // TODO(darin): perhaps this behavior will be confusing to users? | 1075 // TODO(darin): perhaps this behavior will be confusing to users? |
1132 EXPECT_EQ(controller.GetEntryCount(), 3); | 1076 EXPECT_EQ(controller.GetEntryCount(), 3); |
1133 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); | 1077 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); |
1134 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1078 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1135 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1079 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1136 EXPECT_FALSE(controller.GetPendingEntry()); | 1080 EXPECT_FALSE(controller.GetPendingEntry()); |
1137 EXPECT_TRUE(controller.CanGoBack()); | 1081 EXPECT_TRUE(controller.CanGoBack()); |
1138 EXPECT_FALSE(controller.CanGoForward()); | 1082 EXPECT_FALSE(controller.CanGoForward()); |
1139 } | 1083 } |
1140 | 1084 |
1141 // Receives a back message when there is a new pending navigation entry. | 1085 // Receives a back message when there is a new pending navigation entry. |
1142 TEST_F(NavigationControllerTest, Back_NewPending) { | 1086 TEST_F(NavigationControllerTest, Back_NewPending) { |
1143 NavigationControllerImpl& controller = controller_impl(); | 1087 NavigationControllerImpl& controller = controller_impl(); |
1144 TestNotificationTracker notifications; | 1088 TestNotificationTracker notifications; |
1145 RegisterForAllNavNotifications(¬ifications, &controller); | 1089 RegisterForAllNavNotifications(¬ifications, &controller); |
1146 | 1090 |
1147 const GURL kUrl1("http://foo1"); | 1091 const GURL kUrl1("http://foo1"); |
1148 const GURL kUrl2("http://foo2"); | 1092 const GURL kUrl2("http://foo2"); |
1149 const GURL kUrl3("http://foo3"); | 1093 const GURL kUrl3("http://foo3"); |
1150 | 1094 |
1151 // First navigate two places so we have some back history. | 1095 // First navigate two places so we have some back history. |
1152 test_rvh()->SendNavigate(0, kUrl1); | 1096 test_rvh()->SendNavigate(0, kUrl1); |
1153 EXPECT_TRUE(notifications.Check1AndReset( | 1097 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1154 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1155 | 1098 |
1156 // controller.LoadURL(kUrl2, content::PAGE_TRANSITION_TYPED); | 1099 // controller.LoadURL(kUrl2, PAGE_TRANSITION_TYPED); |
1157 test_rvh()->SendNavigate(1, kUrl2); | 1100 test_rvh()->SendNavigate(1, kUrl2); |
1158 EXPECT_TRUE(notifications.Check1AndReset( | 1101 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1159 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1160 | 1102 |
1161 // Now start a new pending navigation and go back before it commits. | 1103 // Now start a new pending navigation and go back before it commits. |
1162 controller.LoadURL( | 1104 controller.LoadURL(kUrl3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1163 kUrl3, content::Referrer(), content::PAGE_TRANSITION_TYPED, | |
1164 std::string()); | |
1165 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1105 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1166 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); | 1106 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); |
1167 controller.GoBack(); | 1107 controller.GoBack(); |
1168 | 1108 |
1169 // The pending navigation should now be the "back" item and the new one | 1109 // The pending navigation should now be the "back" item and the new one |
1170 // should be gone. | 1110 // should be gone. |
1171 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 1111 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
1172 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); | 1112 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); |
1173 } | 1113 } |
1174 | 1114 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 // Tests what happens when we navigate forward successfully. | 1164 // Tests what happens when we navigate forward successfully. |
1225 TEST_F(NavigationControllerTest, Forward) { | 1165 TEST_F(NavigationControllerTest, Forward) { |
1226 NavigationControllerImpl& controller = controller_impl(); | 1166 NavigationControllerImpl& controller = controller_impl(); |
1227 TestNotificationTracker notifications; | 1167 TestNotificationTracker notifications; |
1228 RegisterForAllNavNotifications(¬ifications, &controller); | 1168 RegisterForAllNavNotifications(¬ifications, &controller); |
1229 | 1169 |
1230 const GURL url1("http://foo1"); | 1170 const GURL url1("http://foo1"); |
1231 const GURL url2("http://foo2"); | 1171 const GURL url2("http://foo2"); |
1232 | 1172 |
1233 test_rvh()->SendNavigate(0, url1); | 1173 test_rvh()->SendNavigate(0, url1); |
1234 EXPECT_TRUE(notifications.Check1AndReset( | 1174 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1235 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1236 | 1175 |
1237 test_rvh()->SendNavigate(1, url2); | 1176 test_rvh()->SendNavigate(1, url2); |
1238 EXPECT_TRUE(notifications.Check1AndReset( | 1177 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1239 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1240 | 1178 |
1241 controller.GoBack(); | 1179 controller.GoBack(); |
1242 test_rvh()->SendNavigate(0, url1); | 1180 test_rvh()->SendNavigate(0, url1); |
1243 EXPECT_TRUE(notifications.Check1AndReset( | 1181 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1244 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1245 | 1182 |
1246 controller.GoForward(); | 1183 controller.GoForward(); |
1247 | 1184 |
1248 // We should now have a pending navigation to go forward. | 1185 // We should now have a pending navigation to go forward. |
1249 EXPECT_EQ(controller.GetEntryCount(), 2); | 1186 EXPECT_EQ(controller.GetEntryCount(), 2); |
1250 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1187 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1251 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1188 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1252 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1189 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1253 EXPECT_TRUE(controller.GetPendingEntry()); | 1190 EXPECT_TRUE(controller.GetPendingEntry()); |
1254 EXPECT_TRUE(controller.CanGoBack()); | 1191 EXPECT_TRUE(controller.CanGoBack()); |
1255 EXPECT_FALSE(controller.CanGoForward()); | 1192 EXPECT_FALSE(controller.CanGoForward()); |
1256 | 1193 |
1257 // Timestamp for entry 0 should be on or after that of entry 1 | 1194 // Timestamp for entry 0 should be on or after that of entry 1 |
1258 // (since we went back to it). | 1195 // (since we went back to it). |
1259 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1196 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
1260 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1197 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
1261 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1198 controller.GetEntryAtIndex(1)->GetTimestamp()); |
1262 | 1199 |
1263 test_rvh()->SendNavigate(1, url2); | 1200 test_rvh()->SendNavigate(1, url2); |
1264 EXPECT_TRUE(notifications.Check1AndReset( | 1201 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1265 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1266 | 1202 |
1267 // The forward navigation completed successfully. | 1203 // The forward navigation completed successfully. |
1268 EXPECT_EQ(controller.GetEntryCount(), 2); | 1204 EXPECT_EQ(controller.GetEntryCount(), 2); |
1269 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1205 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1270 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1206 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1271 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1207 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1272 EXPECT_FALSE(controller.GetPendingEntry()); | 1208 EXPECT_FALSE(controller.GetPendingEntry()); |
1273 EXPECT_TRUE(controller.CanGoBack()); | 1209 EXPECT_TRUE(controller.CanGoBack()); |
1274 EXPECT_FALSE(controller.CanGoForward()); | 1210 EXPECT_FALSE(controller.CanGoForward()); |
1275 | 1211 |
1276 // Timestamp for entry 1 should be on or after that of entry 0 | 1212 // Timestamp for entry 1 should be on or after that of entry 0 |
1277 // (since we went forward to it). | 1213 // (since we went forward to it). |
1278 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), | 1214 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), |
1279 controller.GetEntryAtIndex(0)->GetTimestamp()); | 1215 controller.GetEntryAtIndex(0)->GetTimestamp()); |
1280 } | 1216 } |
1281 | 1217 |
1282 // Tests what happens when a forward navigation produces a new page. | 1218 // Tests what happens when a forward navigation produces a new page. |
1283 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { | 1219 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { |
1284 NavigationControllerImpl& controller = controller_impl(); | 1220 NavigationControllerImpl& controller = controller_impl(); |
1285 TestNotificationTracker notifications; | 1221 TestNotificationTracker notifications; |
1286 RegisterForAllNavNotifications(¬ifications, &controller); | 1222 RegisterForAllNavNotifications(¬ifications, &controller); |
1287 | 1223 |
1288 const GURL url1("http://foo1"); | 1224 const GURL url1("http://foo1"); |
1289 const GURL url2("http://foo2"); | 1225 const GURL url2("http://foo2"); |
1290 const GURL url3("http://foo3"); | 1226 const GURL url3("http://foo3"); |
1291 | 1227 |
1292 test_rvh()->SendNavigate(0, url1); | 1228 test_rvh()->SendNavigate(0, url1); |
1293 EXPECT_TRUE(notifications.Check1AndReset( | 1229 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1294 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1295 test_rvh()->SendNavigate(1, url2); | 1230 test_rvh()->SendNavigate(1, url2); |
1296 EXPECT_TRUE(notifications.Check1AndReset( | 1231 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1297 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1298 | 1232 |
1299 controller.GoBack(); | 1233 controller.GoBack(); |
1300 test_rvh()->SendNavigate(0, url1); | 1234 test_rvh()->SendNavigate(0, url1); |
1301 EXPECT_TRUE(notifications.Check1AndReset( | 1235 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1302 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1303 | 1236 |
1304 controller.GoForward(); | 1237 controller.GoForward(); |
1305 EXPECT_EQ(0U, notifications.size()); | 1238 EXPECT_EQ(0U, notifications.size()); |
1306 | 1239 |
1307 // Should now have a pending navigation to go forward. | 1240 // Should now have a pending navigation to go forward. |
1308 EXPECT_EQ(controller.GetEntryCount(), 2); | 1241 EXPECT_EQ(controller.GetEntryCount(), 2); |
1309 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1242 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1310 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1243 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1311 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1244 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1312 EXPECT_TRUE(controller.GetPendingEntry()); | 1245 EXPECT_TRUE(controller.GetPendingEntry()); |
1313 EXPECT_TRUE(controller.CanGoBack()); | 1246 EXPECT_TRUE(controller.CanGoBack()); |
1314 EXPECT_FALSE(controller.CanGoForward()); | 1247 EXPECT_FALSE(controller.CanGoForward()); |
1315 | 1248 |
1316 test_rvh()->SendNavigate(2, url3); | 1249 test_rvh()->SendNavigate(2, url3); |
1317 EXPECT_TRUE(notifications.Check2AndReset( | 1250 EXPECT_TRUE(notifications.Check2AndReset( |
1318 content::NOTIFICATION_NAV_LIST_PRUNED, | 1251 NOTIFICATION_NAV_LIST_PRUNED, |
1319 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1252 NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1320 | 1253 |
1321 EXPECT_EQ(controller.GetEntryCount(), 2); | 1254 EXPECT_EQ(controller.GetEntryCount(), 2); |
1322 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1255 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1323 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1256 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1324 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1257 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1325 EXPECT_FALSE(controller.GetPendingEntry()); | 1258 EXPECT_FALSE(controller.GetPendingEntry()); |
1326 EXPECT_TRUE(controller.CanGoBack()); | 1259 EXPECT_TRUE(controller.CanGoBack()); |
1327 EXPECT_FALSE(controller.CanGoForward()); | 1260 EXPECT_FALSE(controller.CanGoForward()); |
1328 } | 1261 } |
1329 | 1262 |
1330 // Two consequent navigation for the same URL entered in should be considered | 1263 // Two consequent navigation for the same URL entered in should be considered |
1331 // as SAME_PAGE navigation even when we are redirected to some other page. | 1264 // as SAME_PAGE navigation even when we are redirected to some other page. |
1332 TEST_F(NavigationControllerTest, Redirect) { | 1265 TEST_F(NavigationControllerTest, Redirect) { |
1333 NavigationControllerImpl& controller = controller_impl(); | 1266 NavigationControllerImpl& controller = controller_impl(); |
1334 TestNotificationTracker notifications; | 1267 TestNotificationTracker notifications; |
1335 RegisterForAllNavNotifications(¬ifications, &controller); | 1268 RegisterForAllNavNotifications(¬ifications, &controller); |
1336 | 1269 |
1337 const GURL url1("http://foo1"); | 1270 const GURL url1("http://foo1"); |
1338 const GURL url2("http://foo2"); // Redirection target | 1271 const GURL url2("http://foo2"); // Redirection target |
1339 | 1272 |
1340 // First request | 1273 // First request |
1341 controller.LoadURL( | 1274 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1342 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1343 | 1275 |
1344 EXPECT_EQ(0U, notifications.size()); | 1276 EXPECT_EQ(0U, notifications.size()); |
1345 test_rvh()->SendNavigate(0, url2); | 1277 test_rvh()->SendNavigate(0, url2); |
1346 EXPECT_TRUE(notifications.Check1AndReset( | 1278 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1347 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1348 | 1279 |
1349 // Second request | 1280 // Second request |
1350 controller.LoadURL( | 1281 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1351 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1352 | 1282 |
1353 EXPECT_TRUE(controller.GetPendingEntry()); | 1283 EXPECT_TRUE(controller.GetPendingEntry()); |
1354 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1284 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1355 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 1285 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); |
1356 | 1286 |
1357 ViewHostMsg_FrameNavigate_Params params; | 1287 ViewHostMsg_FrameNavigate_Params params; |
1358 params.page_id = 0; | 1288 params.page_id = 0; |
1359 params.url = url2; | 1289 params.url = url2; |
1360 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 1290 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
1361 params.redirects.push_back(GURL("http://foo1")); | 1291 params.redirects.push_back(GURL("http://foo1")); |
1362 params.redirects.push_back(GURL("http://foo2")); | 1292 params.redirects.push_back(GURL("http://foo2")); |
1363 params.should_update_history = false; | 1293 params.should_update_history = false; |
1364 params.gesture = NavigationGestureAuto; | 1294 params.gesture = NavigationGestureAuto; |
1365 params.is_post = false; | 1295 params.is_post = false; |
1366 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1296 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1367 | 1297 |
1368 content::LoadCommittedDetails details; | 1298 LoadCommittedDetails details; |
1369 | 1299 |
1370 EXPECT_EQ(0U, notifications.size()); | 1300 EXPECT_EQ(0U, notifications.size()); |
1371 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1301 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1372 EXPECT_TRUE(notifications.Check1AndReset( | 1302 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1373 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1374 | 1303 |
1375 EXPECT_TRUE(details.type == content::NAVIGATION_TYPE_SAME_PAGE); | 1304 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
1376 EXPECT_EQ(controller.GetEntryCount(), 1); | 1305 EXPECT_EQ(controller.GetEntryCount(), 1); |
1377 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1306 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1378 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1307 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1379 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1308 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1380 EXPECT_FALSE(controller.GetPendingEntry()); | 1309 EXPECT_FALSE(controller.GetPendingEntry()); |
1381 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 1310 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); |
1382 | 1311 |
1383 EXPECT_FALSE(controller.CanGoBack()); | 1312 EXPECT_FALSE(controller.CanGoBack()); |
1384 EXPECT_FALSE(controller.CanGoForward()); | 1313 EXPECT_FALSE(controller.CanGoForward()); |
1385 } | 1314 } |
1386 | 1315 |
1387 // Similar to Redirect above, but the first URL is requested by POST, | 1316 // Similar to Redirect above, but the first URL is requested by POST, |
1388 // the second URL is requested by GET. NavigationEntry::has_post_data_ | 1317 // the second URL is requested by GET. NavigationEntry::has_post_data_ |
1389 // must be cleared. http://crbug.com/21245 | 1318 // must be cleared. http://crbug.com/21245 |
1390 TEST_F(NavigationControllerTest, PostThenRedirect) { | 1319 TEST_F(NavigationControllerTest, PostThenRedirect) { |
1391 NavigationControllerImpl& controller = controller_impl(); | 1320 NavigationControllerImpl& controller = controller_impl(); |
1392 TestNotificationTracker notifications; | 1321 TestNotificationTracker notifications; |
1393 RegisterForAllNavNotifications(¬ifications, &controller); | 1322 RegisterForAllNavNotifications(¬ifications, &controller); |
1394 | 1323 |
1395 const GURL url1("http://foo1"); | 1324 const GURL url1("http://foo1"); |
1396 const GURL url2("http://foo2"); // Redirection target | 1325 const GURL url2("http://foo2"); // Redirection target |
1397 | 1326 |
1398 // First request as POST | 1327 // First request as POST |
1399 controller.LoadURL( | 1328 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1400 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1401 controller.GetActiveEntry()->SetHasPostData(true); | 1329 controller.GetActiveEntry()->SetHasPostData(true); |
1402 | 1330 |
1403 EXPECT_EQ(0U, notifications.size()); | 1331 EXPECT_EQ(0U, notifications.size()); |
1404 test_rvh()->SendNavigate(0, url2); | 1332 test_rvh()->SendNavigate(0, url2); |
1405 EXPECT_TRUE(notifications.Check1AndReset( | 1333 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1406 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1407 | 1334 |
1408 // Second request | 1335 // Second request |
1409 controller.LoadURL( | 1336 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1410 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1411 | 1337 |
1412 EXPECT_TRUE(controller.GetPendingEntry()); | 1338 EXPECT_TRUE(controller.GetPendingEntry()); |
1413 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1339 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1414 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 1340 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); |
1415 | 1341 |
1416 ViewHostMsg_FrameNavigate_Params params; | 1342 ViewHostMsg_FrameNavigate_Params params; |
1417 params.page_id = 0; | 1343 params.page_id = 0; |
1418 params.url = url2; | 1344 params.url = url2; |
1419 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 1345 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
1420 params.redirects.push_back(GURL("http://foo1")); | 1346 params.redirects.push_back(GURL("http://foo1")); |
1421 params.redirects.push_back(GURL("http://foo2")); | 1347 params.redirects.push_back(GURL("http://foo2")); |
1422 params.should_update_history = false; | 1348 params.should_update_history = false; |
1423 params.gesture = NavigationGestureAuto; | 1349 params.gesture = NavigationGestureAuto; |
1424 params.is_post = false; | 1350 params.is_post = false; |
1425 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1351 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1426 | 1352 |
1427 content::LoadCommittedDetails details; | 1353 LoadCommittedDetails details; |
1428 | 1354 |
1429 EXPECT_EQ(0U, notifications.size()); | 1355 EXPECT_EQ(0U, notifications.size()); |
1430 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1356 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1431 EXPECT_TRUE(notifications.Check1AndReset( | 1357 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1432 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1433 | 1358 |
1434 EXPECT_TRUE(details.type == content::NAVIGATION_TYPE_SAME_PAGE); | 1359 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
1435 EXPECT_EQ(controller.GetEntryCount(), 1); | 1360 EXPECT_EQ(controller.GetEntryCount(), 1); |
1436 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1361 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1437 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1362 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1438 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1363 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1439 EXPECT_FALSE(controller.GetPendingEntry()); | 1364 EXPECT_FALSE(controller.GetPendingEntry()); |
1440 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 1365 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); |
1441 EXPECT_FALSE(controller.GetActiveEntry()->GetHasPostData()); | 1366 EXPECT_FALSE(controller.GetActiveEntry()->GetHasPostData()); |
1442 | 1367 |
1443 EXPECT_FALSE(controller.CanGoBack()); | 1368 EXPECT_FALSE(controller.CanGoBack()); |
1444 EXPECT_FALSE(controller.CanGoForward()); | 1369 EXPECT_FALSE(controller.CanGoForward()); |
1445 } | 1370 } |
1446 | 1371 |
1447 // A redirect right off the bat should be a NEW_PAGE. | 1372 // A redirect right off the bat should be a NEW_PAGE. |
1448 TEST_F(NavigationControllerTest, ImmediateRedirect) { | 1373 TEST_F(NavigationControllerTest, ImmediateRedirect) { |
1449 NavigationControllerImpl& controller = controller_impl(); | 1374 NavigationControllerImpl& controller = controller_impl(); |
1450 TestNotificationTracker notifications; | 1375 TestNotificationTracker notifications; |
1451 RegisterForAllNavNotifications(¬ifications, &controller); | 1376 RegisterForAllNavNotifications(¬ifications, &controller); |
1452 | 1377 |
1453 const GURL url1("http://foo1"); | 1378 const GURL url1("http://foo1"); |
1454 const GURL url2("http://foo2"); // Redirection target | 1379 const GURL url2("http://foo2"); // Redirection target |
1455 | 1380 |
1456 // First request | 1381 // First request |
1457 controller.LoadURL( | 1382 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1458 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1459 | 1383 |
1460 EXPECT_TRUE(controller.GetPendingEntry()); | 1384 EXPECT_TRUE(controller.GetPendingEntry()); |
1461 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1385 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1462 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 1386 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); |
1463 | 1387 |
1464 ViewHostMsg_FrameNavigate_Params params; | 1388 ViewHostMsg_FrameNavigate_Params params; |
1465 params.page_id = 0; | 1389 params.page_id = 0; |
1466 params.url = url2; | 1390 params.url = url2; |
1467 params.transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 1391 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
1468 params.redirects.push_back(GURL("http://foo1")); | 1392 params.redirects.push_back(GURL("http://foo1")); |
1469 params.redirects.push_back(GURL("http://foo2")); | 1393 params.redirects.push_back(GURL("http://foo2")); |
1470 params.should_update_history = false; | 1394 params.should_update_history = false; |
1471 params.gesture = NavigationGestureAuto; | 1395 params.gesture = NavigationGestureAuto; |
1472 params.is_post = false; | 1396 params.is_post = false; |
1473 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1397 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1474 | 1398 |
1475 content::LoadCommittedDetails details; | 1399 LoadCommittedDetails details; |
1476 | 1400 |
1477 EXPECT_EQ(0U, notifications.size()); | 1401 EXPECT_EQ(0U, notifications.size()); |
1478 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1402 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1479 EXPECT_TRUE(notifications.Check1AndReset( | 1403 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1480 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1481 | 1404 |
1482 EXPECT_TRUE(details.type == content::NAVIGATION_TYPE_NEW_PAGE); | 1405 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); |
1483 EXPECT_EQ(controller.GetEntryCount(), 1); | 1406 EXPECT_EQ(controller.GetEntryCount(), 1); |
1484 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1407 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1485 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1408 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1486 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1409 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1487 EXPECT_FALSE(controller.GetPendingEntry()); | 1410 EXPECT_FALSE(controller.GetPendingEntry()); |
1488 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 1411 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); |
1489 | 1412 |
1490 EXPECT_FALSE(controller.CanGoBack()); | 1413 EXPECT_FALSE(controller.CanGoBack()); |
1491 EXPECT_FALSE(controller.CanGoForward()); | 1414 EXPECT_FALSE(controller.CanGoForward()); |
1492 } | 1415 } |
1493 | 1416 |
1494 // Tests navigation via link click within a subframe. A new navigation entry | 1417 // Tests navigation via link click within a subframe. A new navigation entry |
1495 // should be created. | 1418 // should be created. |
1496 TEST_F(NavigationControllerTest, NewSubframe) { | 1419 TEST_F(NavigationControllerTest, NewSubframe) { |
1497 NavigationControllerImpl& controller = controller_impl(); | 1420 NavigationControllerImpl& controller = controller_impl(); |
1498 TestNotificationTracker notifications; | 1421 TestNotificationTracker notifications; |
1499 RegisterForAllNavNotifications(¬ifications, &controller); | 1422 RegisterForAllNavNotifications(¬ifications, &controller); |
1500 | 1423 |
1501 const GURL url1("http://foo1"); | 1424 const GURL url1("http://foo1"); |
1502 test_rvh()->SendNavigate(0, url1); | 1425 test_rvh()->SendNavigate(0, url1); |
1503 EXPECT_TRUE(notifications.Check1AndReset( | 1426 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1504 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1505 | 1427 |
1506 const GURL url2("http://foo2"); | 1428 const GURL url2("http://foo2"); |
1507 ViewHostMsg_FrameNavigate_Params params; | 1429 ViewHostMsg_FrameNavigate_Params params; |
1508 params.page_id = 1; | 1430 params.page_id = 1; |
1509 params.url = url2; | 1431 params.url = url2; |
1510 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME; | 1432 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
1511 params.should_update_history = false; | 1433 params.should_update_history = false; |
1512 params.gesture = NavigationGestureUser; | 1434 params.gesture = NavigationGestureUser; |
1513 params.is_post = false; | 1435 params.is_post = false; |
1514 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1436 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1515 | 1437 |
1516 content::LoadCommittedDetails details; | 1438 LoadCommittedDetails details; |
1517 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1439 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1518 EXPECT_TRUE(notifications.Check1AndReset( | 1440 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1519 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1520 EXPECT_EQ(url1, details.previous_url); | 1441 EXPECT_EQ(url1, details.previous_url); |
1521 EXPECT_FALSE(details.is_in_page); | 1442 EXPECT_FALSE(details.is_in_page); |
1522 EXPECT_FALSE(details.is_main_frame); | 1443 EXPECT_FALSE(details.is_main_frame); |
1523 | 1444 |
1524 // The new entry should be appended. | 1445 // The new entry should be appended. |
1525 EXPECT_EQ(2, controller.GetEntryCount()); | 1446 EXPECT_EQ(2, controller.GetEntryCount()); |
1526 | 1447 |
1527 // New entry should refer to the new page, but the old URL (entries only | 1448 // New entry should refer to the new page, but the old URL (entries only |
1528 // reflect the toplevel URL). | 1449 // reflect the toplevel URL). |
1529 EXPECT_EQ(url1, details.entry->GetURL()); | 1450 EXPECT_EQ(url1, details.entry->GetURL()); |
1530 EXPECT_EQ(params.page_id, details.entry->GetPageID()); | 1451 EXPECT_EQ(params.page_id, details.entry->GetPageID()); |
1531 } | 1452 } |
1532 | 1453 |
1533 // Some pages create a popup, then write an iframe into it. This causes a | 1454 // Some pages create a popup, then write an iframe into it. This causes a |
1534 // subframe navigation without having any committed entry. Such navigations | 1455 // subframe navigation without having any committed entry. Such navigations |
1535 // just get thrown on the ground, but we shouldn't crash. | 1456 // just get thrown on the ground, but we shouldn't crash. |
1536 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { | 1457 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { |
1537 NavigationControllerImpl& controller = controller_impl(); | 1458 NavigationControllerImpl& controller = controller_impl(); |
1538 TestNotificationTracker notifications; | 1459 TestNotificationTracker notifications; |
1539 RegisterForAllNavNotifications(¬ifications, &controller); | 1460 RegisterForAllNavNotifications(¬ifications, &controller); |
1540 | 1461 |
1541 // Navigation controller currently has no entries. | 1462 // Navigation controller currently has no entries. |
1542 const GURL url("http://foo2"); | 1463 const GURL url("http://foo2"); |
1543 ViewHostMsg_FrameNavigate_Params params; | 1464 ViewHostMsg_FrameNavigate_Params params; |
1544 params.page_id = 1; | 1465 params.page_id = 1; |
1545 params.url = url; | 1466 params.url = url; |
1546 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; | 1467 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
1547 params.should_update_history = false; | 1468 params.should_update_history = false; |
1548 params.gesture = NavigationGestureAuto; | 1469 params.gesture = NavigationGestureAuto; |
1549 params.is_post = false; | 1470 params.is_post = false; |
1550 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1471 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
1551 | 1472 |
1552 content::LoadCommittedDetails details; | 1473 LoadCommittedDetails details; |
1553 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); | 1474 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); |
1554 EXPECT_EQ(0U, notifications.size()); | 1475 EXPECT_EQ(0U, notifications.size()); |
1555 } | 1476 } |
1556 | 1477 |
1557 // Auto subframes are ones the page loads automatically like ads. They should | 1478 // Auto subframes are ones the page loads automatically like ads. They should |
1558 // not create new navigation entries. | 1479 // not create new navigation entries. |
1559 TEST_F(NavigationControllerTest, AutoSubframe) { | 1480 TEST_F(NavigationControllerTest, AutoSubframe) { |
1560 NavigationControllerImpl& controller = controller_impl(); | 1481 NavigationControllerImpl& controller = controller_impl(); |
1561 TestNotificationTracker notifications; | 1482 TestNotificationTracker notifications; |
1562 RegisterForAllNavNotifications(¬ifications, &controller); | 1483 RegisterForAllNavNotifications(¬ifications, &controller); |
1563 | 1484 |
1564 const GURL url1("http://foo1"); | 1485 const GURL url1("http://foo1"); |
1565 test_rvh()->SendNavigate(0, url1); | 1486 test_rvh()->SendNavigate(0, url1); |
1566 EXPECT_TRUE(notifications.Check1AndReset( | 1487 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1567 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1568 | 1488 |
1569 const GURL url2("http://foo2"); | 1489 const GURL url2("http://foo2"); |
1570 ViewHostMsg_FrameNavigate_Params params; | 1490 ViewHostMsg_FrameNavigate_Params params; |
1571 params.page_id = 0; | 1491 params.page_id = 0; |
1572 params.url = url2; | 1492 params.url = url2; |
1573 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; | 1493 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
1574 params.should_update_history = false; | 1494 params.should_update_history = false; |
1575 params.gesture = NavigationGestureUser; | 1495 params.gesture = NavigationGestureUser; |
1576 params.is_post = false; | 1496 params.is_post = false; |
1577 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1497 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1578 | 1498 |
1579 // Navigating should do nothing. | 1499 // Navigating should do nothing. |
1580 content::LoadCommittedDetails details; | 1500 LoadCommittedDetails details; |
1581 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); | 1501 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); |
1582 EXPECT_EQ(0U, notifications.size()); | 1502 EXPECT_EQ(0U, notifications.size()); |
1583 | 1503 |
1584 // There should still be only one entry. | 1504 // There should still be only one entry. |
1585 EXPECT_EQ(1, controller.GetEntryCount()); | 1505 EXPECT_EQ(1, controller.GetEntryCount()); |
1586 } | 1506 } |
1587 | 1507 |
1588 // Tests navigation and then going back to a subframe navigation. | 1508 // Tests navigation and then going back to a subframe navigation. |
1589 TEST_F(NavigationControllerTest, BackSubframe) { | 1509 TEST_F(NavigationControllerTest, BackSubframe) { |
1590 NavigationControllerImpl& controller = controller_impl(); | 1510 NavigationControllerImpl& controller = controller_impl(); |
1591 TestNotificationTracker notifications; | 1511 TestNotificationTracker notifications; |
1592 RegisterForAllNavNotifications(¬ifications, &controller); | 1512 RegisterForAllNavNotifications(¬ifications, &controller); |
1593 | 1513 |
1594 // Main page. | 1514 // Main page. |
1595 const GURL url1("http://foo1"); | 1515 const GURL url1("http://foo1"); |
1596 test_rvh()->SendNavigate(0, url1); | 1516 test_rvh()->SendNavigate(0, url1); |
1597 EXPECT_TRUE(notifications.Check1AndReset( | 1517 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1598 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1599 | 1518 |
1600 // First manual subframe navigation. | 1519 // First manual subframe navigation. |
1601 const GURL url2("http://foo2"); | 1520 const GURL url2("http://foo2"); |
1602 ViewHostMsg_FrameNavigate_Params params; | 1521 ViewHostMsg_FrameNavigate_Params params; |
1603 params.page_id = 1; | 1522 params.page_id = 1; |
1604 params.url = url2; | 1523 params.url = url2; |
1605 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME; | 1524 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
1606 params.should_update_history = false; | 1525 params.should_update_history = false; |
1607 params.gesture = NavigationGestureUser; | 1526 params.gesture = NavigationGestureUser; |
1608 params.is_post = false; | 1527 params.is_post = false; |
1609 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1528 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1610 | 1529 |
1611 // This should generate a new entry. | 1530 // This should generate a new entry. |
1612 content::LoadCommittedDetails details; | 1531 LoadCommittedDetails details; |
1613 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1532 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1614 EXPECT_TRUE(notifications.Check1AndReset( | 1533 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1615 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1616 EXPECT_EQ(2, controller.GetEntryCount()); | 1534 EXPECT_EQ(2, controller.GetEntryCount()); |
1617 | 1535 |
1618 // Second manual subframe navigation should also make a new entry. | 1536 // Second manual subframe navigation should also make a new entry. |
1619 const GURL url3("http://foo3"); | 1537 const GURL url3("http://foo3"); |
1620 params.page_id = 2; | 1538 params.page_id = 2; |
1621 params.url = url3; | 1539 params.url = url3; |
1622 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1540 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1623 EXPECT_TRUE(notifications.Check1AndReset( | 1541 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1624 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1625 EXPECT_EQ(3, controller.GetEntryCount()); | 1542 EXPECT_EQ(3, controller.GetEntryCount()); |
1626 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 1543 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
1627 | 1544 |
1628 // Go back one. | 1545 // Go back one. |
1629 controller.GoBack(); | 1546 controller.GoBack(); |
1630 params.url = url2; | 1547 params.url = url2; |
1631 params.page_id = 1; | 1548 params.page_id = 1; |
1632 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1549 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1633 EXPECT_TRUE(notifications.Check1AndReset( | 1550 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1634 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1635 EXPECT_EQ(3, controller.GetEntryCount()); | 1551 EXPECT_EQ(3, controller.GetEntryCount()); |
1636 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 1552 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
1637 | 1553 |
1638 // Go back one more. | 1554 // Go back one more. |
1639 controller.GoBack(); | 1555 controller.GoBack(); |
1640 params.url = url1; | 1556 params.url = url1; |
1641 params.page_id = 0; | 1557 params.page_id = 0; |
1642 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1558 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1643 EXPECT_TRUE(notifications.Check1AndReset( | 1559 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1644 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1645 EXPECT_EQ(3, controller.GetEntryCount()); | 1560 EXPECT_EQ(3, controller.GetEntryCount()); |
1646 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 1561 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
1647 } | 1562 } |
1648 | 1563 |
1649 TEST_F(NavigationControllerTest, LinkClick) { | 1564 TEST_F(NavigationControllerTest, LinkClick) { |
1650 NavigationControllerImpl& controller = controller_impl(); | 1565 NavigationControllerImpl& controller = controller_impl(); |
1651 TestNotificationTracker notifications; | 1566 TestNotificationTracker notifications; |
1652 RegisterForAllNavNotifications(¬ifications, &controller); | 1567 RegisterForAllNavNotifications(¬ifications, &controller); |
1653 | 1568 |
1654 const GURL url1("http://foo1"); | 1569 const GURL url1("http://foo1"); |
1655 const GURL url2("http://foo2"); | 1570 const GURL url2("http://foo2"); |
1656 | 1571 |
1657 test_rvh()->SendNavigate(0, url1); | 1572 test_rvh()->SendNavigate(0, url1); |
1658 EXPECT_TRUE(notifications.Check1AndReset( | 1573 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1659 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1660 | 1574 |
1661 test_rvh()->SendNavigate(1, url2); | 1575 test_rvh()->SendNavigate(1, url2); |
1662 EXPECT_TRUE(notifications.Check1AndReset( | 1576 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1663 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1664 | 1577 |
1665 // Should not have produced a new session history entry. | 1578 // Should not have produced a new session history entry. |
1666 EXPECT_EQ(controller.GetEntryCount(), 2); | 1579 EXPECT_EQ(controller.GetEntryCount(), 2); |
1667 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1580 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1668 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1581 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1669 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1582 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1670 EXPECT_FALSE(controller.GetPendingEntry()); | 1583 EXPECT_FALSE(controller.GetPendingEntry()); |
1671 EXPECT_TRUE(controller.CanGoBack()); | 1584 EXPECT_TRUE(controller.CanGoBack()); |
1672 EXPECT_FALSE(controller.CanGoForward()); | 1585 EXPECT_FALSE(controller.CanGoForward()); |
1673 } | 1586 } |
1674 | 1587 |
1675 TEST_F(NavigationControllerTest, InPage) { | 1588 TEST_F(NavigationControllerTest, InPage) { |
1676 NavigationControllerImpl& controller = controller_impl(); | 1589 NavigationControllerImpl& controller = controller_impl(); |
1677 TestNotificationTracker notifications; | 1590 TestNotificationTracker notifications; |
1678 RegisterForAllNavNotifications(¬ifications, &controller); | 1591 RegisterForAllNavNotifications(¬ifications, &controller); |
1679 | 1592 |
1680 // Main page. | 1593 // Main page. |
1681 const GURL url1("http://foo"); | 1594 const GURL url1("http://foo"); |
1682 test_rvh()->SendNavigate(0, url1); | 1595 test_rvh()->SendNavigate(0, url1); |
1683 EXPECT_TRUE(notifications.Check1AndReset( | 1596 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1684 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1685 | 1597 |
1686 // Ensure main page navigation to same url respects the was_within_same_page | 1598 // Ensure main page navigation to same url respects the was_within_same_page |
1687 // hint provided in the params. | 1599 // hint provided in the params. |
1688 ViewHostMsg_FrameNavigate_Params self_params; | 1600 ViewHostMsg_FrameNavigate_Params self_params; |
1689 self_params.page_id = 0; | 1601 self_params.page_id = 0; |
1690 self_params.url = url1; | 1602 self_params.url = url1; |
1691 self_params.transition = content::PAGE_TRANSITION_LINK; | 1603 self_params.transition = PAGE_TRANSITION_LINK; |
1692 self_params.should_update_history = false; | 1604 self_params.should_update_history = false; |
1693 self_params.gesture = NavigationGestureUser; | 1605 self_params.gesture = NavigationGestureUser; |
1694 self_params.is_post = false; | 1606 self_params.is_post = false; |
1695 self_params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1)); | 1607 self_params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1)); |
1696 self_params.was_within_same_page = true; | 1608 self_params.was_within_same_page = true; |
1697 | 1609 |
1698 content::LoadCommittedDetails details; | 1610 LoadCommittedDetails details; |
1699 EXPECT_TRUE(controller.RendererDidNavigate(self_params, &details)); | 1611 EXPECT_TRUE(controller.RendererDidNavigate(self_params, &details)); |
1700 EXPECT_TRUE(notifications.Check1AndReset( | 1612 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1701 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1702 EXPECT_TRUE(details.is_in_page); | 1613 EXPECT_TRUE(details.is_in_page); |
1703 EXPECT_TRUE(details.did_replace_entry); | 1614 EXPECT_TRUE(details.did_replace_entry); |
1704 EXPECT_EQ(1, controller.GetEntryCount()); | 1615 EXPECT_EQ(1, controller.GetEntryCount()); |
1705 | 1616 |
1706 // Fragment navigation to a new page_id. | 1617 // Fragment navigation to a new page_id. |
1707 const GURL url2("http://foo#a"); | 1618 const GURL url2("http://foo#a"); |
1708 ViewHostMsg_FrameNavigate_Params params; | 1619 ViewHostMsg_FrameNavigate_Params params; |
1709 params.page_id = 1; | 1620 params.page_id = 1; |
1710 params.url = url2; | 1621 params.url = url2; |
1711 params.transition = content::PAGE_TRANSITION_LINK; | 1622 params.transition = PAGE_TRANSITION_LINK; |
1712 params.should_update_history = false; | 1623 params.should_update_history = false; |
1713 params.gesture = NavigationGestureUser; | 1624 params.gesture = NavigationGestureUser; |
1714 params.is_post = false; | 1625 params.is_post = false; |
1715 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1626 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1716 | 1627 |
1717 // This should generate a new entry. | 1628 // This should generate a new entry. |
1718 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1629 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1719 EXPECT_TRUE(notifications.Check1AndReset( | 1630 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1720 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1721 EXPECT_TRUE(details.is_in_page); | 1631 EXPECT_TRUE(details.is_in_page); |
1722 EXPECT_FALSE(details.did_replace_entry); | 1632 EXPECT_FALSE(details.did_replace_entry); |
1723 EXPECT_EQ(2, controller.GetEntryCount()); | 1633 EXPECT_EQ(2, controller.GetEntryCount()); |
1724 | 1634 |
1725 // Go back one. | 1635 // Go back one. |
1726 ViewHostMsg_FrameNavigate_Params back_params(params); | 1636 ViewHostMsg_FrameNavigate_Params back_params(params); |
1727 controller.GoBack(); | 1637 controller.GoBack(); |
1728 back_params.url = url1; | 1638 back_params.url = url1; |
1729 back_params.page_id = 0; | 1639 back_params.page_id = 0; |
1730 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); | 1640 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); |
1731 EXPECT_TRUE(notifications.Check1AndReset( | 1641 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1732 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1733 // is_in_page is false in that case but should be true. | 1642 // is_in_page is false in that case but should be true. |
1734 // See comment in AreURLsInPageNavigation() in navigation_controller.cc | 1643 // See comment in AreURLsInPageNavigation() in navigation_controller.cc |
1735 // EXPECT_TRUE(details.is_in_page); | 1644 // EXPECT_TRUE(details.is_in_page); |
1736 EXPECT_EQ(2, controller.GetEntryCount()); | 1645 EXPECT_EQ(2, controller.GetEntryCount()); |
1737 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 1646 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
1738 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL()); | 1647 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL()); |
1739 | 1648 |
1740 // Go forward | 1649 // Go forward |
1741 ViewHostMsg_FrameNavigate_Params forward_params(params); | 1650 ViewHostMsg_FrameNavigate_Params forward_params(params); |
1742 controller.GoForward(); | 1651 controller.GoForward(); |
1743 forward_params.url = url2; | 1652 forward_params.url = url2; |
1744 forward_params.page_id = 1; | 1653 forward_params.page_id = 1; |
1745 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); | 1654 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); |
1746 EXPECT_TRUE(notifications.Check1AndReset( | 1655 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1747 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1748 EXPECT_TRUE(details.is_in_page); | 1656 EXPECT_TRUE(details.is_in_page); |
1749 EXPECT_EQ(2, controller.GetEntryCount()); | 1657 EXPECT_EQ(2, controller.GetEntryCount()); |
1750 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 1658 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
1751 EXPECT_EQ(forward_params.url, | 1659 EXPECT_EQ(forward_params.url, |
1752 controller.GetActiveEntry()->GetURL()); | 1660 controller.GetActiveEntry()->GetURL()); |
1753 | 1661 |
1754 // Now go back and forward again. This is to work around a bug where we would | 1662 // Now go back and forward again. This is to work around a bug where we would |
1755 // compare the incoming URL with the last committed entry rather than the | 1663 // compare the incoming URL with the last committed entry rather than the |
1756 // one identified by an existing page ID. This would result in the second URL | 1664 // one identified by an existing page ID. This would result in the second URL |
1757 // losing the reference fragment when you navigate away from it and then back. | 1665 // losing the reference fragment when you navigate away from it and then back. |
1758 controller.GoBack(); | 1666 controller.GoBack(); |
1759 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); | 1667 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); |
1760 controller.GoForward(); | 1668 controller.GoForward(); |
1761 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); | 1669 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); |
1762 EXPECT_EQ(forward_params.url, | 1670 EXPECT_EQ(forward_params.url, |
1763 controller.GetActiveEntry()->GetURL()); | 1671 controller.GetActiveEntry()->GetURL()); |
1764 | 1672 |
1765 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 1673 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
1766 const GURL url3("http://bar"); | 1674 const GURL url3("http://bar"); |
1767 params.page_id = 2; | 1675 params.page_id = 2; |
1768 params.url = url3; | 1676 params.url = url3; |
1769 notifications.Reset(); | 1677 notifications.Reset(); |
1770 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1678 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1771 EXPECT_TRUE(notifications.Check1AndReset( | 1679 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1772 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1773 EXPECT_FALSE(details.is_in_page); | 1680 EXPECT_FALSE(details.is_in_page); |
1774 EXPECT_EQ(3, controller.GetEntryCount()); | 1681 EXPECT_EQ(3, controller.GetEntryCount()); |
1775 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 1682 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
1776 } | 1683 } |
1777 | 1684 |
1778 TEST_F(NavigationControllerTest, InPage_Replace) { | 1685 TEST_F(NavigationControllerTest, InPage_Replace) { |
1779 NavigationControllerImpl& controller = controller_impl(); | 1686 NavigationControllerImpl& controller = controller_impl(); |
1780 TestNotificationTracker notifications; | 1687 TestNotificationTracker notifications; |
1781 RegisterForAllNavNotifications(¬ifications, &controller); | 1688 RegisterForAllNavNotifications(¬ifications, &controller); |
1782 | 1689 |
1783 // Main page. | 1690 // Main page. |
1784 const GURL url1("http://foo"); | 1691 const GURL url1("http://foo"); |
1785 test_rvh()->SendNavigate(0, url1); | 1692 test_rvh()->SendNavigate(0, url1); |
1786 EXPECT_TRUE(notifications.Check1AndReset( | 1693 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1787 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1788 | 1694 |
1789 // First navigation. | 1695 // First navigation. |
1790 const GURL url2("http://foo#a"); | 1696 const GURL url2("http://foo#a"); |
1791 ViewHostMsg_FrameNavigate_Params params; | 1697 ViewHostMsg_FrameNavigate_Params params; |
1792 params.page_id = 0; // Same page_id | 1698 params.page_id = 0; // Same page_id |
1793 params.url = url2; | 1699 params.url = url2; |
1794 params.transition = content::PAGE_TRANSITION_LINK; | 1700 params.transition = PAGE_TRANSITION_LINK; |
1795 params.should_update_history = false; | 1701 params.should_update_history = false; |
1796 params.gesture = NavigationGestureUser; | 1702 params.gesture = NavigationGestureUser; |
1797 params.is_post = false; | 1703 params.is_post = false; |
1798 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); | 1704 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); |
1799 | 1705 |
1800 // This should NOT generate a new entry, nor prune the list. | 1706 // This should NOT generate a new entry, nor prune the list. |
1801 content::LoadCommittedDetails details; | 1707 LoadCommittedDetails details; |
1802 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1708 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1803 EXPECT_TRUE(notifications.Check1AndReset( | 1709 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1804 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1805 EXPECT_TRUE(details.is_in_page); | 1710 EXPECT_TRUE(details.is_in_page); |
1806 EXPECT_TRUE(details.did_replace_entry); | 1711 EXPECT_TRUE(details.did_replace_entry); |
1807 EXPECT_EQ(1, controller.GetEntryCount()); | 1712 EXPECT_EQ(1, controller.GetEntryCount()); |
1808 } | 1713 } |
1809 | 1714 |
1810 // Tests for http://crbug.com/40395 | 1715 // Tests for http://crbug.com/40395 |
1811 // Simulates this: | 1716 // Simulates this: |
1812 // <script> | 1717 // <script> |
1813 // window.location.replace("#a"); | 1718 // window.location.replace("#a"); |
1814 // window.location='http://foo3/'; | 1719 // window.location='http://foo3/'; |
1815 // </script> | 1720 // </script> |
1816 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { | 1721 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
1817 NavigationControllerImpl& controller = controller_impl(); | 1722 NavigationControllerImpl& controller = controller_impl(); |
1818 TestNotificationTracker notifications; | 1723 TestNotificationTracker notifications; |
1819 RegisterForAllNavNotifications(¬ifications, &controller); | 1724 RegisterForAllNavNotifications(¬ifications, &controller); |
1820 | 1725 |
1821 // Load an initial page. | 1726 // Load an initial page. |
1822 { | 1727 { |
1823 const GURL url("http://foo/"); | 1728 const GURL url("http://foo/"); |
1824 test_rvh()->SendNavigate(0, url); | 1729 test_rvh()->SendNavigate(0, url); |
1825 EXPECT_TRUE(notifications.Check1AndReset( | 1730 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1826 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1827 } | 1731 } |
1828 | 1732 |
1829 // Navigate to a new page. | 1733 // Navigate to a new page. |
1830 { | 1734 { |
1831 const GURL url("http://foo2/"); | 1735 const GURL url("http://foo2/"); |
1832 test_rvh()->SendNavigate(1, url); | 1736 test_rvh()->SendNavigate(1, url); |
1833 controller.DocumentLoadedInFrame(); | 1737 controller.DocumentLoadedInFrame(); |
1834 EXPECT_TRUE(notifications.Check1AndReset( | 1738 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1835 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1836 } | 1739 } |
1837 | 1740 |
1838 // Navigate within the page. | 1741 // Navigate within the page. |
1839 { | 1742 { |
1840 const GURL url("http://foo2/#a"); | 1743 const GURL url("http://foo2/#a"); |
1841 ViewHostMsg_FrameNavigate_Params params; | 1744 ViewHostMsg_FrameNavigate_Params params; |
1842 params.page_id = 1; // Same page_id | 1745 params.page_id = 1; // Same page_id |
1843 params.url = url; | 1746 params.url = url; |
1844 params.transition = content::PAGE_TRANSITION_LINK; | 1747 params.transition = PAGE_TRANSITION_LINK; |
1845 params.redirects.push_back(url); | 1748 params.redirects.push_back(url); |
1846 params.should_update_history = true; | 1749 params.should_update_history = true; |
1847 params.gesture = NavigationGestureUnknown; | 1750 params.gesture = NavigationGestureUnknown; |
1848 params.is_post = false; | 1751 params.is_post = false; |
1849 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1752 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
1850 | 1753 |
1851 // This should NOT generate a new entry, nor prune the list. | 1754 // This should NOT generate a new entry, nor prune the list. |
1852 content::LoadCommittedDetails details; | 1755 LoadCommittedDetails details; |
1853 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1756 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1854 EXPECT_TRUE(notifications.Check1AndReset( | 1757 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1855 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1856 EXPECT_TRUE(details.is_in_page); | 1758 EXPECT_TRUE(details.is_in_page); |
1857 EXPECT_TRUE(details.did_replace_entry); | 1759 EXPECT_TRUE(details.did_replace_entry); |
1858 EXPECT_EQ(2, controller.GetEntryCount()); | 1760 EXPECT_EQ(2, controller.GetEntryCount()); |
1859 } | 1761 } |
1860 | 1762 |
1861 // Perform a client redirect to a new page. | 1763 // Perform a client redirect to a new page. |
1862 { | 1764 { |
1863 const GURL url("http://foo3/"); | 1765 const GURL url("http://foo3/"); |
1864 ViewHostMsg_FrameNavigate_Params params; | 1766 ViewHostMsg_FrameNavigate_Params params; |
1865 params.page_id = 2; // New page_id | 1767 params.page_id = 2; // New page_id |
1866 params.url = url; | 1768 params.url = url; |
1867 params.transition = content::PAGE_TRANSITION_CLIENT_REDIRECT; | 1769 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT; |
1868 params.redirects.push_back(GURL("http://foo2/#a")); | 1770 params.redirects.push_back(GURL("http://foo2/#a")); |
1869 params.redirects.push_back(url); | 1771 params.redirects.push_back(url); |
1870 params.should_update_history = true; | 1772 params.should_update_history = true; |
1871 params.gesture = NavigationGestureUnknown; | 1773 params.gesture = NavigationGestureUnknown; |
1872 params.is_post = false; | 1774 params.is_post = false; |
1873 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1775 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
1874 | 1776 |
1875 // This SHOULD generate a new entry. | 1777 // This SHOULD generate a new entry. |
1876 content::LoadCommittedDetails details; | 1778 LoadCommittedDetails details; |
1877 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); | 1779 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); |
1878 EXPECT_TRUE(notifications.Check1AndReset( | 1780 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1879 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
1880 EXPECT_FALSE(details.is_in_page); | 1781 EXPECT_FALSE(details.is_in_page); |
1881 EXPECT_EQ(3, controller.GetEntryCount()); | 1782 EXPECT_EQ(3, controller.GetEntryCount()); |
1882 } | 1783 } |
1883 | 1784 |
1884 // Verify that BACK brings us back to http://foo2/. | 1785 // Verify that BACK brings us back to http://foo2/. |
1885 { | 1786 { |
1886 const GURL url("http://foo2/"); | 1787 const GURL url("http://foo2/"); |
1887 controller.GoBack(); | 1788 controller.GoBack(); |
1888 test_rvh()->SendNavigate(1, url); | 1789 test_rvh()->SendNavigate(1, url); |
1889 EXPECT_TRUE(notifications.Check1AndReset( | 1790 EXPECT_TRUE(notifications.Check1AndReset( |
1890 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 1791 NOTIFICATION_NAV_ENTRY_COMMITTED)); |
1891 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); | 1792 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); |
1892 } | 1793 } |
1893 } | 1794 } |
1894 | 1795 |
1895 // NotificationObserver implementation used in verifying we've received the | 1796 // NotificationObserver implementation used in verifying we've received the |
1896 // content::NOTIFICATION_NAV_LIST_PRUNED method. | 1797 // NOTIFICATION_NAV_LIST_PRUNED method. |
1897 class PrunedListener : public content::NotificationObserver { | 1798 class PrunedListener : public NotificationObserver { |
1898 public: | 1799 public: |
1899 explicit PrunedListener(NavigationControllerImpl* controller) | 1800 explicit PrunedListener(NavigationControllerImpl* controller) |
1900 : notification_count_(0) { | 1801 : notification_count_(0) { |
1901 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, | 1802 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, |
1902 content::Source<NavigationController>(controller)); | 1803 Source<NavigationController>(controller)); |
1903 } | 1804 } |
1904 | 1805 |
1905 virtual void Observe(int type, | 1806 virtual void Observe(int type, |
1906 const content::NotificationSource& source, | 1807 const NotificationSource& source, |
1907 const content::NotificationDetails& details) { | 1808 const NotificationDetails& details) { |
1908 if (type == content::NOTIFICATION_NAV_LIST_PRUNED) { | 1809 if (type == NOTIFICATION_NAV_LIST_PRUNED) { |
1909 notification_count_++; | 1810 notification_count_++; |
1910 details_ = *(content::Details<content::PrunedDetails>(details).ptr()); | 1811 details_ = *(Details<PrunedDetails>(details).ptr()); |
1911 } | 1812 } |
1912 } | 1813 } |
1913 | 1814 |
1914 // Number of times NAV_LIST_PRUNED has been observed. | 1815 // Number of times NAV_LIST_PRUNED has been observed. |
1915 int notification_count_; | 1816 int notification_count_; |
1916 | 1817 |
1917 // Details from the last NAV_LIST_PRUNED. | 1818 // Details from the last NAV_LIST_PRUNED. |
1918 content::PrunedDetails details_; | 1819 PrunedDetails details_; |
1919 | 1820 |
1920 private: | 1821 private: |
1921 content::NotificationRegistrar registrar_; | 1822 NotificationRegistrar registrar_; |
1922 | 1823 |
1923 DISALLOW_COPY_AND_ASSIGN(PrunedListener); | 1824 DISALLOW_COPY_AND_ASSIGN(PrunedListener); |
1924 }; | 1825 }; |
1925 | 1826 |
1926 // Tests that we limit the number of navigation entries created correctly. | 1827 // Tests that we limit the number of navigation entries created correctly. |
1927 TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { | 1828 TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { |
1928 NavigationControllerImpl& controller = controller_impl(); | 1829 NavigationControllerImpl& controller = controller_impl(); |
1929 size_t original_count = NavigationControllerImpl::max_entry_count(); | 1830 size_t original_count = NavigationControllerImpl::max_entry_count(); |
1930 const int kMaxEntryCount = 5; | 1831 const int kMaxEntryCount = 5; |
1931 | 1832 |
1932 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 1833 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
1933 | 1834 |
1934 int url_index; | 1835 int url_index; |
1935 // Load up to the max count, all entries should be there. | 1836 // Load up to the max count, all entries should be there. |
1936 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 1837 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
1937 GURL url(StringPrintf("http://www.a.com/%d", url_index)); | 1838 GURL url(StringPrintf("http://www.a.com/%d", url_index)); |
1938 controller.LoadURL( | 1839 controller.LoadURL( |
1939 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 1840 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1940 std::string()); | |
1941 test_rvh()->SendNavigate(url_index, url); | 1841 test_rvh()->SendNavigate(url_index, url); |
1942 } | 1842 } |
1943 | 1843 |
1944 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 1844 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
1945 | 1845 |
1946 // Created a PrunedListener to observe prune notifications. | 1846 // Created a PrunedListener to observe prune notifications. |
1947 PrunedListener listener(&controller); | 1847 PrunedListener listener(&controller); |
1948 | 1848 |
1949 // Navigate some more. | 1849 // Navigate some more. |
1950 GURL url(StringPrintf("http://www.a.com/%d", url_index)); | 1850 GURL url(StringPrintf("http://www.a.com/%d", url_index)); |
1951 controller.LoadURL( | 1851 controller.LoadURL( |
1952 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 1852 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1953 test_rvh()->SendNavigate(url_index, url); | 1853 test_rvh()->SendNavigate(url_index, url); |
1954 url_index++; | 1854 url_index++; |
1955 | 1855 |
1956 // We should have got a pruned navigation. | 1856 // We should have got a pruned navigation. |
1957 EXPECT_EQ(1, listener.notification_count_); | 1857 EXPECT_EQ(1, listener.notification_count_); |
1958 EXPECT_TRUE(listener.details_.from_front); | 1858 EXPECT_TRUE(listener.details_.from_front); |
1959 EXPECT_EQ(1, listener.details_.count); | 1859 EXPECT_EQ(1, listener.details_.count); |
1960 | 1860 |
1961 // We expect http://www.a.com/0 to be gone. | 1861 // We expect http://www.a.com/0 to be gone. |
1962 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 1862 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
1963 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 1863 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
1964 GURL("http:////www.a.com/1")); | 1864 GURL("http:////www.a.com/1")); |
1965 | 1865 |
1966 // More navigations. | 1866 // More navigations. |
1967 for (int i = 0; i < 3; i++) { | 1867 for (int i = 0; i < 3; i++) { |
1968 url = GURL(StringPrintf("http:////www.a.com/%d", url_index)); | 1868 url = GURL(StringPrintf("http:////www.a.com/%d", url_index)); |
1969 controller.LoadURL( | 1869 controller.LoadURL( |
1970 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 1870 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1971 std::string()); | |
1972 test_rvh()->SendNavigate(url_index, url); | 1871 test_rvh()->SendNavigate(url_index, url); |
1973 url_index++; | 1872 url_index++; |
1974 } | 1873 } |
1975 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 1874 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
1976 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 1875 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
1977 GURL("http:////www.a.com/4")); | 1876 GURL("http:////www.a.com/4")); |
1978 | 1877 |
1979 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 1878 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
1980 } | 1879 } |
1981 | 1880 |
1982 // Tests that we can do a restore and navigate to the restored entries and | 1881 // Tests that we can do a restore and navigate to the restored entries and |
1983 // everything is updated properly. This can be tricky since there is no | 1882 // everything is updated properly. This can be tricky since there is no |
1984 // SiteInstance for the entries created initially. | 1883 // SiteInstance for the entries created initially. |
1985 TEST_F(NavigationControllerTest, RestoreNavigate) { | 1884 TEST_F(NavigationControllerTest, RestoreNavigate) { |
1986 // Create a NavigationController with a restored set of tabs. | 1885 // Create a NavigationController with a restored set of tabs. |
1987 GURL url("http://foo"); | 1886 GURL url("http://foo"); |
1988 std::vector<NavigationEntry*> entries; | 1887 std::vector<NavigationEntry*> entries; |
1989 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( | 1888 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( |
1990 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, | 1889 url, Referrer(), PAGE_TRANSITION_RELOAD, false, std::string(), |
1991 std::string(), browser_context()); | 1890 browser_context()); |
1992 entry->SetPageID(0); | 1891 entry->SetPageID(0); |
1993 entry->SetTitle(ASCIIToUTF16("Title")); | 1892 entry->SetTitle(ASCIIToUTF16("Title")); |
1994 entry->SetContentState("state"); | 1893 entry->SetContentState("state"); |
1995 const base::Time timestamp = base::Time::Now(); | 1894 const base::Time timestamp = base::Time::Now(); |
1996 entry->SetTimestamp(timestamp); | 1895 entry->SetTimestamp(timestamp); |
1997 entries.push_back(entry); | 1896 entries.push_back(entry); |
1998 scoped_ptr<WebContentsImpl> our_contents( | 1897 scoped_ptr<WebContentsImpl> our_contents( |
1999 WebContentsImpl::Create(browser_context(), NULL, MSG_ROUTING_NONE, | 1898 WebContentsImpl::Create(browser_context(), NULL, MSG_ROUTING_NONE, |
2000 NULL)); | 1899 NULL)); |
2001 NavigationControllerImpl& our_controller = our_contents->GetController(); | 1900 NavigationControllerImpl& our_controller = our_contents->GetController(); |
(...skipping 25 matching lines...) Expand all Loading... |
2027 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( | 1926 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( |
2028 our_controller.GetEntryAtIndex(0))->site_instance()); | 1927 our_controller.GetEntryAtIndex(0))->site_instance()); |
2029 | 1928 |
2030 // Timestamp should remain the same before the navigation finishes. | 1929 // Timestamp should remain the same before the navigation finishes. |
2031 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); | 1930 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); |
2032 | 1931 |
2033 // Say we navigated to that entry. | 1932 // Say we navigated to that entry. |
2034 ViewHostMsg_FrameNavigate_Params params; | 1933 ViewHostMsg_FrameNavigate_Params params; |
2035 params.page_id = 0; | 1934 params.page_id = 0; |
2036 params.url = url; | 1935 params.url = url; |
2037 params.transition = content::PAGE_TRANSITION_LINK; | 1936 params.transition = PAGE_TRANSITION_LINK; |
2038 params.should_update_history = false; | 1937 params.should_update_history = false; |
2039 params.gesture = NavigationGestureUser; | 1938 params.gesture = NavigationGestureUser; |
2040 params.is_post = false; | 1939 params.is_post = false; |
2041 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 1940 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
2042 content::LoadCommittedDetails details; | 1941 LoadCommittedDetails details; |
2043 our_controller.RendererDidNavigate(params, &details); | 1942 our_controller.RendererDidNavigate(params, &details); |
2044 | 1943 |
2045 // There should be no longer any pending entry and one committed one. This | 1944 // There should be no longer any pending entry and one committed one. This |
2046 // means that we were able to locate the entry, assign its site instance, and | 1945 // means that we were able to locate the entry, assign its site instance, and |
2047 // commit it properly. | 1946 // commit it properly. |
2048 EXPECT_EQ(1, our_controller.GetEntryCount()); | 1947 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2049 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 1948 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
2050 EXPECT_FALSE(our_controller.GetPendingEntry()); | 1949 EXPECT_FALSE(our_controller.GetPendingEntry()); |
2051 EXPECT_EQ(url, | 1950 EXPECT_EQ(url, |
2052 NavigationEntryImpl::FromNavigationEntry( | 1951 NavigationEntryImpl::FromNavigationEntry( |
2053 our_controller.GetLastCommittedEntry())->site_instance()-> | 1952 our_controller.GetLastCommittedEntry())->site_instance()-> |
2054 GetSiteURL()); | 1953 GetSiteURL()); |
2055 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 1954 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2056 NavigationEntryImpl::FromNavigationEntry( | 1955 NavigationEntryImpl::FromNavigationEntry( |
2057 our_controller.GetEntryAtIndex(0))->restore_type()); | 1956 our_controller.GetEntryAtIndex(0))->restore_type()); |
2058 | 1957 |
2059 // Timestamp should have been updated. | 1958 // Timestamp should have been updated. |
2060 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); | 1959 EXPECT_GE(our_controller.GetEntryAtIndex(0)->GetTimestamp(), timestamp); |
2061 } | 1960 } |
2062 | 1961 |
2063 // Tests that we can still navigate to a restored entry after a different | 1962 // Tests that we can still navigate to a restored entry after a different |
2064 // navigation fails and clears the pending entry. http://crbug.com/90085 | 1963 // navigation fails and clears the pending entry. http://crbug.com/90085 |
2065 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 1964 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
2066 // Create a NavigationController with a restored set of tabs. | 1965 // Create a NavigationController with a restored set of tabs. |
2067 GURL url("http://foo"); | 1966 GURL url("http://foo"); |
2068 std::vector<NavigationEntry*> entries; | 1967 std::vector<NavigationEntry*> entries; |
2069 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( | 1968 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( |
2070 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, | 1969 url, Referrer(), PAGE_TRANSITION_RELOAD, false, std::string(), |
2071 std::string(), browser_context()); | 1970 browser_context()); |
2072 entry->SetPageID(0); | 1971 entry->SetPageID(0); |
2073 entry->SetTitle(ASCIIToUTF16("Title")); | 1972 entry->SetTitle(ASCIIToUTF16("Title")); |
2074 entry->SetContentState("state"); | 1973 entry->SetContentState("state"); |
2075 entries.push_back(entry); | 1974 entries.push_back(entry); |
2076 scoped_ptr<WebContentsImpl> our_contents( | 1975 scoped_ptr<WebContentsImpl> our_contents( |
2077 WebContentsImpl::Create(browser_context(), NULL, MSG_ROUTING_NONE, | 1976 WebContentsImpl::Create(browser_context(), NULL, MSG_ROUTING_NONE, |
2078 NULL)); | 1977 NULL)); |
2079 NavigationControllerImpl& our_controller = our_contents->GetController(); | 1978 NavigationControllerImpl& our_controller = our_contents->GetController(); |
2080 our_controller.Restore( | 1979 our_controller.Restore( |
2081 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | 1980 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2114 fail_load_params.url = url; | 2013 fail_load_params.url = url; |
2115 fail_load_params.showing_repost_interstitial = false; | 2014 fail_load_params.showing_repost_interstitial = false; |
2116 rvh->OnMessageReceived( | 2015 rvh->OnMessageReceived( |
2117 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 2016 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
2118 fail_load_params)); | 2017 fail_load_params)); |
2119 | 2018 |
2120 // Now the pending restored entry commits. | 2019 // Now the pending restored entry commits. |
2121 ViewHostMsg_FrameNavigate_Params params; | 2020 ViewHostMsg_FrameNavigate_Params params; |
2122 params.page_id = 0; | 2021 params.page_id = 0; |
2123 params.url = url; | 2022 params.url = url; |
2124 params.transition = content::PAGE_TRANSITION_LINK; | 2023 params.transition = PAGE_TRANSITION_LINK; |
2125 params.should_update_history = false; | 2024 params.should_update_history = false; |
2126 params.gesture = NavigationGestureUser; | 2025 params.gesture = NavigationGestureUser; |
2127 params.is_post = false; | 2026 params.is_post = false; |
2128 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 2027 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
2129 content::LoadCommittedDetails details; | 2028 LoadCommittedDetails details; |
2130 our_controller.RendererDidNavigate(params, &details); | 2029 our_controller.RendererDidNavigate(params, &details); |
2131 | 2030 |
2132 // There should be no pending entry and one committed one. | 2031 // There should be no pending entry and one committed one. |
2133 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2032 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2134 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 2033 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
2135 EXPECT_FALSE(our_controller.GetPendingEntry()); | 2034 EXPECT_FALSE(our_controller.GetPendingEntry()); |
2136 EXPECT_EQ(url, | 2035 EXPECT_EQ(url, |
2137 NavigationEntryImpl::FromNavigationEntry( | 2036 NavigationEntryImpl::FromNavigationEntry( |
2138 our_controller.GetLastCommittedEntry())->site_instance()-> | 2037 our_controller.GetLastCommittedEntry())->site_instance()-> |
2139 GetSiteURL()); | 2038 GetSiteURL()); |
2140 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2039 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2141 NavigationEntryImpl::FromNavigationEntry( | 2040 NavigationEntryImpl::FromNavigationEntry( |
2142 our_controller.GetEntryAtIndex(0))->restore_type()); | 2041 our_controller.GetEntryAtIndex(0))->restore_type()); |
2143 } | 2042 } |
2144 | 2043 |
2145 // Make sure that the page type and stuff is correct after an interstitial. | 2044 // Make sure that the page type and stuff is correct after an interstitial. |
2146 TEST_F(NavigationControllerTest, Interstitial) { | 2045 TEST_F(NavigationControllerTest, Interstitial) { |
2147 NavigationControllerImpl& controller = controller_impl(); | 2046 NavigationControllerImpl& controller = controller_impl(); |
2148 // First navigate somewhere normal. | 2047 // First navigate somewhere normal. |
2149 const GURL url1("http://foo"); | 2048 const GURL url1("http://foo"); |
2150 controller.LoadURL( | 2049 controller.LoadURL( |
2151 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2050 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2152 test_rvh()->SendNavigate(0, url1); | 2051 test_rvh()->SendNavigate(0, url1); |
2153 | 2052 |
2154 // Now navigate somewhere with an interstitial. | 2053 // Now navigate somewhere with an interstitial. |
2155 const GURL url2("http://bar"); | 2054 const GURL url2("http://bar"); |
2156 controller.LoadURL( | 2055 controller.LoadURL( |
2157 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2056 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2158 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2057 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
2159 set_page_type(content::PAGE_TYPE_INTERSTITIAL); | 2058 set_page_type(PAGE_TYPE_INTERSTITIAL); |
2160 | 2059 |
2161 // At this point the interstitial will be displayed and the load will still | 2060 // At this point the interstitial will be displayed and the load will still |
2162 // be pending. If the user continues, the load will commit. | 2061 // be pending. If the user continues, the load will commit. |
2163 test_rvh()->SendNavigate(1, url2); | 2062 test_rvh()->SendNavigate(1, url2); |
2164 | 2063 |
2165 // The page should be a normal page again. | 2064 // The page should be a normal page again. |
2166 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2065 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2167 EXPECT_EQ(content::PAGE_TYPE_NORMAL, | 2066 EXPECT_EQ(PAGE_TYPE_NORMAL, |
2168 controller.GetLastCommittedEntry()->GetPageType()); | 2067 controller.GetLastCommittedEntry()->GetPageType()); |
2169 } | 2068 } |
2170 | 2069 |
2171 TEST_F(NavigationControllerTest, RemoveEntry) { | 2070 TEST_F(NavigationControllerTest, RemoveEntry) { |
2172 NavigationControllerImpl& controller = controller_impl(); | 2071 NavigationControllerImpl& controller = controller_impl(); |
2173 const GURL url1("http://foo/1"); | 2072 const GURL url1("http://foo/1"); |
2174 const GURL url2("http://foo/2"); | 2073 const GURL url2("http://foo/2"); |
2175 const GURL url3("http://foo/3"); | 2074 const GURL url3("http://foo/3"); |
2176 const GURL url4("http://foo/4"); | 2075 const GURL url4("http://foo/4"); |
2177 const GURL url5("http://foo/5"); | 2076 const GURL url5("http://foo/5"); |
2178 const GURL pending_url("http://foo/pending"); | 2077 const GURL pending_url("http://foo/pending"); |
2179 const GURL default_url("http://foo/default"); | 2078 const GURL default_url("http://foo/default"); |
2180 | 2079 |
2181 controller.LoadURL( | 2080 controller.LoadURL( |
2182 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2081 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2183 test_rvh()->SendNavigate(0, url1); | 2082 test_rvh()->SendNavigate(0, url1); |
2184 controller.LoadURL( | 2083 controller.LoadURL( |
2185 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2084 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2186 test_rvh()->SendNavigate(1, url2); | 2085 test_rvh()->SendNavigate(1, url2); |
2187 controller.LoadURL( | 2086 controller.LoadURL( |
2188 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2087 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2189 test_rvh()->SendNavigate(2, url3); | 2088 test_rvh()->SendNavigate(2, url3); |
2190 controller.LoadURL( | 2089 controller.LoadURL( |
2191 url4, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2090 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2192 test_rvh()->SendNavigate(3, url4); | 2091 test_rvh()->SendNavigate(3, url4); |
2193 controller.LoadURL( | 2092 controller.LoadURL( |
2194 url5, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2093 url5, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2195 test_rvh()->SendNavigate(4, url5); | 2094 test_rvh()->SendNavigate(4, url5); |
2196 | 2095 |
2197 // Try to remove the last entry. Will fail because it is the current entry. | 2096 // Try to remove the last entry. Will fail because it is the current entry. |
2198 controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1); | 2097 controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1); |
2199 EXPECT_EQ(5, controller.GetEntryCount()); | 2098 EXPECT_EQ(5, controller.GetEntryCount()); |
2200 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2099 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
2201 | 2100 |
2202 // Go back and remove the last entry. | 2101 // Go back and remove the last entry. |
2203 controller.GoBack(); | 2102 controller.GoBack(); |
2204 test_rvh()->SendNavigate(3, url4); | 2103 test_rvh()->SendNavigate(3, url4); |
(...skipping 24 matching lines...) Expand all Loading... |
2229 RegisterForAllNavNotifications(¬ifications, &controller); | 2128 RegisterForAllNavNotifications(¬ifications, &controller); |
2230 | 2129 |
2231 const GURL url0("http://foo/0"); | 2130 const GURL url0("http://foo/0"); |
2232 const GURL url1("http://foo/1"); | 2131 const GURL url1("http://foo/1"); |
2233 const GURL url2("http://foo/2"); | 2132 const GURL url2("http://foo/2"); |
2234 const GURL url3("http://foo/3"); | 2133 const GURL url3("http://foo/3"); |
2235 const GURL url4("http://foo/4"); | 2134 const GURL url4("http://foo/4"); |
2236 const GURL transient_url("http://foo/transient"); | 2135 const GURL transient_url("http://foo/transient"); |
2237 | 2136 |
2238 controller.LoadURL( | 2137 controller.LoadURL( |
2239 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2138 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2240 test_rvh()->SendNavigate(0, url0); | 2139 test_rvh()->SendNavigate(0, url0); |
2241 controller.LoadURL( | 2140 controller.LoadURL( |
2242 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2141 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2243 test_rvh()->SendNavigate(1, url1); | 2142 test_rvh()->SendNavigate(1, url1); |
2244 | 2143 |
2245 notifications.Reset(); | 2144 notifications.Reset(); |
2246 | 2145 |
2247 // Adding a transient with no pending entry. | 2146 // Adding a transient with no pending entry. |
2248 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2147 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2249 transient_entry->SetURL(transient_url); | 2148 transient_entry->SetURL(transient_url); |
2250 controller.AddTransientEntry(transient_entry); | 2149 controller.AddTransientEntry(transient_entry); |
2251 | 2150 |
2252 // We should not have received any notifications. | 2151 // We should not have received any notifications. |
2253 EXPECT_EQ(0U, notifications.size()); | 2152 EXPECT_EQ(0U, notifications.size()); |
2254 | 2153 |
2255 // Check our state. | 2154 // Check our state. |
2256 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2155 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); |
2257 EXPECT_EQ(controller.GetEntryCount(), 3); | 2156 EXPECT_EQ(controller.GetEntryCount(), 3); |
2258 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2157 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2259 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2158 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2260 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2159 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2261 EXPECT_FALSE(controller.GetPendingEntry()); | 2160 EXPECT_FALSE(controller.GetPendingEntry()); |
2262 EXPECT_TRUE(controller.CanGoBack()); | 2161 EXPECT_TRUE(controller.CanGoBack()); |
2263 EXPECT_FALSE(controller.CanGoForward()); | 2162 EXPECT_FALSE(controller.CanGoForward()); |
2264 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2163 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
2265 | 2164 |
2266 // Navigate. | 2165 // Navigate. |
2267 controller.LoadURL( | 2166 controller.LoadURL( |
2268 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2167 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2269 test_rvh()->SendNavigate(2, url2); | 2168 test_rvh()->SendNavigate(2, url2); |
2270 | 2169 |
2271 // We should have navigated, transient entry should be gone. | 2170 // We should have navigated, transient entry should be gone. |
2272 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 2171 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); |
2273 EXPECT_EQ(controller.GetEntryCount(), 3); | 2172 EXPECT_EQ(controller.GetEntryCount(), 3); |
2274 | 2173 |
2275 // Add a transient again, then navigate with no pending entry this time. | 2174 // Add a transient again, then navigate with no pending entry this time. |
2276 transient_entry = new NavigationEntryImpl; | 2175 transient_entry = new NavigationEntryImpl; |
2277 transient_entry->SetURL(transient_url); | 2176 transient_entry->SetURL(transient_url); |
2278 controller.AddTransientEntry(transient_entry); | 2177 controller.AddTransientEntry(transient_entry); |
2279 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2178 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); |
2280 test_rvh()->SendNavigate(3, url3); | 2179 test_rvh()->SendNavigate(3, url3); |
2281 // Transient entry should be gone. | 2180 // Transient entry should be gone. |
2282 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL()); | 2181 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL()); |
2283 EXPECT_EQ(controller.GetEntryCount(), 4); | 2182 EXPECT_EQ(controller.GetEntryCount(), 4); |
2284 | 2183 |
2285 // Initiate a navigation, add a transient then commit navigation. | 2184 // Initiate a navigation, add a transient then commit navigation. |
2286 controller.LoadURL( | 2185 controller.LoadURL( |
2287 url4, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2186 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2288 transient_entry = new NavigationEntryImpl; | 2187 transient_entry = new NavigationEntryImpl; |
2289 transient_entry->SetURL(transient_url); | 2188 transient_entry->SetURL(transient_url); |
2290 controller.AddTransientEntry(transient_entry); | 2189 controller.AddTransientEntry(transient_entry); |
2291 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2190 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); |
2292 test_rvh()->SendNavigate(4, url4); | 2191 test_rvh()->SendNavigate(4, url4); |
2293 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); | 2192 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); |
2294 EXPECT_EQ(controller.GetEntryCount(), 5); | 2193 EXPECT_EQ(controller.GetEntryCount(), 5); |
2295 | 2194 |
2296 // Add a transient and go back. This should simply remove the transient. | 2195 // Add a transient and go back. This should simply remove the transient. |
2297 transient_entry = new NavigationEntryImpl; | 2196 transient_entry = new NavigationEntryImpl; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2357 | 2256 |
2358 // Test that Reload initiates a new navigation to a transient entry's URL. | 2257 // Test that Reload initiates a new navigation to a transient entry's URL. |
2359 TEST_F(NavigationControllerTest, ReloadTransient) { | 2258 TEST_F(NavigationControllerTest, ReloadTransient) { |
2360 NavigationControllerImpl& controller = controller_impl(); | 2259 NavigationControllerImpl& controller = controller_impl(); |
2361 const GURL url0("http://foo/0"); | 2260 const GURL url0("http://foo/0"); |
2362 const GURL url1("http://foo/1"); | 2261 const GURL url1("http://foo/1"); |
2363 const GURL transient_url("http://foo/transient"); | 2262 const GURL transient_url("http://foo/transient"); |
2364 | 2263 |
2365 // Load |url0|, and start a pending navigation to |url1|. | 2264 // Load |url0|, and start a pending navigation to |url1|. |
2366 controller.LoadURL( | 2265 controller.LoadURL( |
2367 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2266 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2368 test_rvh()->SendNavigate(0, url0); | 2267 test_rvh()->SendNavigate(0, url0); |
2369 controller.LoadURL( | 2268 controller.LoadURL( |
2370 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2269 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2371 | 2270 |
2372 // A transient entry is added, interrupting the navigation. | 2271 // A transient entry is added, interrupting the navigation. |
2373 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2272 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2374 transient_entry->SetURL(transient_url); | 2273 transient_entry->SetURL(transient_url); |
2375 controller.AddTransientEntry(transient_entry); | 2274 controller.AddTransientEntry(transient_entry); |
2376 EXPECT_TRUE(controller.GetTransientEntry()); | 2275 EXPECT_TRUE(controller.GetTransientEntry()); |
2377 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); | 2276 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); |
2378 | 2277 |
2379 // The page is reloaded, which should remove the pending entry for |url1| and | 2278 // The page is reloaded, which should remove the pending entry for |url1| and |
2380 // the transient entry for |transient_url|, and start a navigation to | 2279 // the transient entry for |transient_url|, and start a navigation to |
(...skipping 18 matching lines...) Expand all Loading... |
2399 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 2298 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
2400 NavigationControllerImpl& controller = controller_impl(); | 2299 NavigationControllerImpl& controller = controller_impl(); |
2401 TestNotificationTracker notifications; | 2300 TestNotificationTracker notifications; |
2402 RegisterForAllNavNotifications(¬ifications, &controller); | 2301 RegisterForAllNavNotifications(¬ifications, &controller); |
2403 | 2302 |
2404 const GURL url0("http://foo/0"); | 2303 const GURL url0("http://foo/0"); |
2405 const GURL url1("http://foo/1"); | 2304 const GURL url1("http://foo/1"); |
2406 | 2305 |
2407 // For typed navigations (browser-initiated), both active and visible entries | 2306 // For typed navigations (browser-initiated), both active and visible entries |
2408 // should update before commit. | 2307 // should update before commit. |
2409 controller.LoadURL(url0, content::Referrer(), | 2308 controller.LoadURL(url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2410 content::PAGE_TRANSITION_TYPED, std::string()); | |
2411 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); | 2309 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); |
2412 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2310 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
2413 test_rvh()->SendNavigate(0, url0); | 2311 test_rvh()->SendNavigate(0, url0); |
2414 | 2312 |
2415 // For link clicks (renderer-initiated navigations), the active entry should | 2313 // For link clicks (renderer-initiated navigations), the active entry should |
2416 // update before commit but the visible should not. | 2314 // update before commit but the visible should not. |
2417 NavigationController::LoadURLParams load_url_params(url1); | 2315 NavigationController::LoadURLParams load_url_params(url1); |
2418 load_url_params.is_renderer_initiated = true; | 2316 load_url_params.is_renderer_initiated = true; |
2419 controller.LoadURLWithParams(load_url_params); | 2317 controller.LoadURLWithParams(load_url_params); |
2420 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 2318 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2474 | 2372 |
2475 // We should be at the first navigation entry. | 2373 // We should be at the first navigation entry. |
2476 EXPECT_EQ(controller.GetEntryCount(), 1); | 2374 EXPECT_EQ(controller.GetEntryCount(), 1); |
2477 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 2375 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
2478 | 2376 |
2479 // Navigate a subframe that would normally count as in-page. | 2377 // Navigate a subframe that would normally count as in-page. |
2480 const GURL subframe("http://www.google.com/#"); | 2378 const GURL subframe("http://www.google.com/#"); |
2481 ViewHostMsg_FrameNavigate_Params params; | 2379 ViewHostMsg_FrameNavigate_Params params; |
2482 params.page_id = 0; | 2380 params.page_id = 0; |
2483 params.url = subframe; | 2381 params.url = subframe; |
2484 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; | 2382 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
2485 params.should_update_history = false; | 2383 params.should_update_history = false; |
2486 params.gesture = NavigationGestureAuto; | 2384 params.gesture = NavigationGestureAuto; |
2487 params.is_post = false; | 2385 params.is_post = false; |
2488 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(subframe)); | 2386 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(subframe)); |
2489 content::LoadCommittedDetails details; | 2387 LoadCommittedDetails details; |
2490 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); | 2388 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); |
2491 | 2389 |
2492 // Nothing should have changed. | 2390 // Nothing should have changed. |
2493 EXPECT_EQ(controller.GetEntryCount(), 1); | 2391 EXPECT_EQ(controller.GetEntryCount(), 1); |
2494 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 2392 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
2495 } | 2393 } |
2496 | 2394 |
2497 // Make sure that on cloning a WebContentsImpl and going back needs_reload is | 2395 // Make sure that on cloning a WebContentsImpl and going back needs_reload is |
2498 // false. | 2396 // false. |
2499 TEST_F(NavigationControllerTest, CloneAndGoBack) { | 2397 TEST_F(NavigationControllerTest, CloneAndGoBack) { |
(...skipping 17 matching lines...) Expand all Loading... |
2517 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { | 2415 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { |
2518 NavigationControllerImpl& controller = controller_impl(); | 2416 NavigationControllerImpl& controller = controller_impl(); |
2519 const GURL url1("http://foo1"); | 2417 const GURL url1("http://foo1"); |
2520 const GURL url2("http://foo2"); | 2418 const GURL url2("http://foo2"); |
2521 | 2419 |
2522 NavigateAndCommit(url1); | 2420 NavigateAndCommit(url1); |
2523 NavigateAndCommit(url2); | 2421 NavigateAndCommit(url2); |
2524 | 2422 |
2525 // Add an interstitial entry. Should be deleted with controller. | 2423 // Add an interstitial entry. Should be deleted with controller. |
2526 NavigationEntryImpl* interstitial_entry = new NavigationEntryImpl(); | 2424 NavigationEntryImpl* interstitial_entry = new NavigationEntryImpl(); |
2527 interstitial_entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); | 2425 interstitial_entry->set_page_type(PAGE_TYPE_INTERSTITIAL); |
2528 controller.AddTransientEntry(interstitial_entry); | 2426 controller.AddTransientEntry(interstitial_entry); |
2529 | 2427 |
2530 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); | 2428 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); |
2531 | 2429 |
2532 ASSERT_EQ(2, clone->GetController().GetEntryCount()); | 2430 ASSERT_EQ(2, clone->GetController().GetEntryCount()); |
2533 } | 2431 } |
2534 | 2432 |
2535 // Tests a subframe navigation while a toplevel navigation is pending. | 2433 // Tests a subframe navigation while a toplevel navigation is pending. |
2536 // http://crbug.com/43967 | 2434 // http://crbug.com/43967 |
2537 TEST_F(NavigationControllerTest, SubframeWhilePending) { | 2435 TEST_F(NavigationControllerTest, SubframeWhilePending) { |
2538 NavigationControllerImpl& controller = controller_impl(); | 2436 NavigationControllerImpl& controller = controller_impl(); |
2539 // Load the first page. | 2437 // Load the first page. |
2540 const GURL url1("http://foo/"); | 2438 const GURL url1("http://foo/"); |
2541 NavigateAndCommit(url1); | 2439 NavigateAndCommit(url1); |
2542 | 2440 |
2543 // Now start a pending load to a totally different page, but don't commit it. | 2441 // Now start a pending load to a totally different page, but don't commit it. |
2544 const GURL url2("http://bar/"); | 2442 const GURL url2("http://bar/"); |
2545 controller.LoadURL( | 2443 controller.LoadURL( |
2546 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2444 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2547 | 2445 |
2548 // Send a subframe update from the first page, as if one had just | 2446 // Send a subframe update from the first page, as if one had just |
2549 // automatically loaded. Auto subframes don't increment the page ID. | 2447 // automatically loaded. Auto subframes don't increment the page ID. |
2550 const GURL url1_sub("http://foo/subframe"); | 2448 const GURL url1_sub("http://foo/subframe"); |
2551 ViewHostMsg_FrameNavigate_Params params; | 2449 ViewHostMsg_FrameNavigate_Params params; |
2552 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); | 2450 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); |
2553 params.url = url1_sub; | 2451 params.url = url1_sub; |
2554 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; | 2452 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
2555 params.should_update_history = false; | 2453 params.should_update_history = false; |
2556 params.gesture = NavigationGestureAuto; | 2454 params.gesture = NavigationGestureAuto; |
2557 params.is_post = false; | 2455 params.is_post = false; |
2558 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1_sub)); | 2456 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1_sub)); |
2559 content::LoadCommittedDetails details; | 2457 LoadCommittedDetails details; |
2560 | 2458 |
2561 // This should return false meaning that nothing was actually updated. | 2459 // This should return false meaning that nothing was actually updated. |
2562 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); | 2460 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); |
2563 | 2461 |
2564 // The notification should have updated the last committed one, and not | 2462 // The notification should have updated the last committed one, and not |
2565 // the pending load. | 2463 // the pending load. |
2566 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); | 2464 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); |
2567 | 2465 |
2568 // The active entry should be unchanged by the subframe load. | 2466 // The active entry should be unchanged by the subframe load. |
2569 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); | 2467 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2719 const GURL url3("http://foo3"); | 2617 const GURL url3("http://foo3"); |
2720 | 2618 |
2721 NavigateAndCommit(url1); | 2619 NavigateAndCommit(url1); |
2722 NavigateAndCommit(url2); | 2620 NavigateAndCommit(url2); |
2723 controller.GoBack(); | 2621 controller.GoBack(); |
2724 | 2622 |
2725 scoped_ptr<TestWebContents> other_contents( | 2623 scoped_ptr<TestWebContents> other_contents( |
2726 static_cast<TestWebContents*>(CreateTestWebContents())); | 2624 static_cast<TestWebContents*>(CreateTestWebContents())); |
2727 NavigationControllerImpl& other_controller = other_contents->GetController(); | 2625 NavigationControllerImpl& other_controller = other_contents->GetController(); |
2728 other_controller.LoadURL( | 2626 other_controller.LoadURL( |
2729 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2627 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2730 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); | 2628 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); |
2731 other_controller.CopyStateFromAndPrune(&controller); | 2629 other_controller.CopyStateFromAndPrune(&controller); |
2732 | 2630 |
2733 // other_controller should now contain 1 entry for url1, and a pending entry | 2631 // other_controller should now contain 1 entry for url1, and a pending entry |
2734 // for url3. | 2632 // for url3. |
2735 | 2633 |
2736 ASSERT_EQ(1, other_controller.GetEntryCount()); | 2634 ASSERT_EQ(1, other_controller.GetEntryCount()); |
2737 | 2635 |
2738 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); | 2636 EXPECT_EQ(0, other_controller.GetCurrentEntryIndex()); |
2739 | 2637 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2919 } | 2817 } |
2920 | 2818 |
2921 // Test call to PruneAllButActive for transient entry. | 2819 // Test call to PruneAllButActive for transient entry. |
2922 TEST_F(NavigationControllerTest, PruneAllButActiveForTransient) { | 2820 TEST_F(NavigationControllerTest, PruneAllButActiveForTransient) { |
2923 NavigationControllerImpl& controller = controller_impl(); | 2821 NavigationControllerImpl& controller = controller_impl(); |
2924 const GURL url0("http://foo/0"); | 2822 const GURL url0("http://foo/0"); |
2925 const GURL url1("http://foo/1"); | 2823 const GURL url1("http://foo/1"); |
2926 const GURL transient_url("http://foo/transient"); | 2824 const GURL transient_url("http://foo/transient"); |
2927 | 2825 |
2928 controller.LoadURL( | 2826 controller.LoadURL( |
2929 url0, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2827 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2930 test_rvh()->SendNavigate(0, url0); | 2828 test_rvh()->SendNavigate(0, url0); |
2931 controller.LoadURL( | 2829 controller.LoadURL( |
2932 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 2830 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2933 test_rvh()->SendNavigate(1, url1); | 2831 test_rvh()->SendNavigate(1, url1); |
2934 | 2832 |
2935 // Adding a transient with no pending entry. | 2833 // Adding a transient with no pending entry. |
2936 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2834 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2937 transient_entry->SetURL(transient_url); | 2835 transient_entry->SetURL(transient_url); |
2938 controller.AddTransientEntry(transient_entry); | 2836 controller.AddTransientEntry(transient_entry); |
2939 | 2837 |
2940 controller.PruneAllButActive(); | 2838 controller.PruneAllButActive(); |
2941 | 2839 |
2942 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2840 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2975 | 2873 |
2976 // Initial state. | 2874 // Initial state. |
2977 EXPECT_TRUE(controller.IsInitialNavigation()); | 2875 EXPECT_TRUE(controller.IsInitialNavigation()); |
2978 | 2876 |
2979 // After load, it is false. | 2877 // After load, it is false. |
2980 controller.DocumentLoadedInFrame(); | 2878 controller.DocumentLoadedInFrame(); |
2981 EXPECT_FALSE(controller.IsInitialNavigation()); | 2879 EXPECT_FALSE(controller.IsInitialNavigation()); |
2982 | 2880 |
2983 const GURL url1("http://foo1"); | 2881 const GURL url1("http://foo1"); |
2984 test_rvh()->SendNavigate(0, url1); | 2882 test_rvh()->SendNavigate(0, url1); |
2985 EXPECT_TRUE(notifications.Check1AndReset( | 2883 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); |
2986 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | |
2987 | 2884 |
2988 // After commit, it stays false. | 2885 // After commit, it stays false. |
2989 EXPECT_FALSE(controller.IsInitialNavigation()); | 2886 EXPECT_FALSE(controller.IsInitialNavigation()); |
2990 } | 2887 } |
2991 | 2888 |
2992 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot | 2889 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot |
2993 (but not Vista) cleaning up the directory after they run. | 2890 (but not Vista) cleaning up the directory after they run. |
2994 This should be fixed. | 2891 This should be fixed. |
2995 | 2892 |
2996 // NavigationControllerHistoryTest --------------------------------------------- | 2893 // NavigationControllerHistoryTest --------------------------------------------- |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3084 | 2981 |
3085 private: | 2982 private: |
3086 ProfileManager* profile_manager_; | 2983 ProfileManager* profile_manager_; |
3087 FilePath test_dir_; | 2984 FilePath test_dir_; |
3088 }; | 2985 }; |
3089 | 2986 |
3090 // A basic test case. Navigates to a single url, and make sure the history | 2987 // A basic test case. Navigates to a single url, and make sure the history |
3091 // db matches. | 2988 // db matches. |
3092 TEST_F(NavigationControllerHistoryTest, Basic) { | 2989 TEST_F(NavigationControllerHistoryTest, Basic) { |
3093 NavigationControllerImpl& controller = controller_impl(); | 2990 NavigationControllerImpl& controller = controller_impl(); |
3094 controller.LoadURL(url0, GURL(), content::PAGE_TRANSITION_LINK); | 2991 controller.LoadURL(url0, GURL(), PAGE_TRANSITION_LINK); |
3095 test_rvh()->SendNavigate(0, url0); | 2992 test_rvh()->SendNavigate(0, url0); |
3096 | 2993 |
3097 GetLastSession(); | 2994 GetLastSession(); |
3098 | 2995 |
3099 session_helper_.AssertSingleWindowWithSingleTab(windows_, 1); | 2996 session_helper_.AssertSingleWindowWithSingleTab(windows_, 1); |
3100 session_helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); | 2997 session_helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); |
3101 TabNavigation nav1(0, url0, GURL(), string16(), | 2998 TabNavigation nav1(0, url0, GURL(), string16(), |
3102 webkit_glue::CreateHistoryStateForURL(url0), | 2999 webkit_glue::CreateHistoryStateForURL(url0), |
3103 content::PAGE_TRANSITION_LINK); | 3000 PAGE_TRANSITION_LINK); |
3104 session_helper_.AssertNavigationEquals(nav1, | 3001 session_helper_.AssertNavigationEquals(nav1, |
3105 windows_[0]->tabs[0]->navigations[0]); | 3002 windows_[0]->tabs[0]->navigations[0]); |
3106 } | 3003 } |
3107 | 3004 |
3108 // Navigates to three urls, then goes back and make sure the history database | 3005 // Navigates to three urls, then goes back and make sure the history database |
3109 // is in sync. | 3006 // is in sync. |
3110 TEST_F(NavigationControllerHistoryTest, NavigationThenBack) { | 3007 TEST_F(NavigationControllerHistoryTest, NavigationThenBack) { |
3111 NavigationControllerImpl& controller = controller_impl(); | 3008 NavigationControllerImpl& controller = controller_impl(); |
3112 test_rvh()->SendNavigate(0, url0); | 3009 test_rvh()->SendNavigate(0, url0); |
3113 test_rvh()->SendNavigate(1, url1); | 3010 test_rvh()->SendNavigate(1, url1); |
3114 test_rvh()->SendNavigate(2, url2); | 3011 test_rvh()->SendNavigate(2, url2); |
3115 | 3012 |
3116 controller.GoBack(); | 3013 controller.GoBack(); |
3117 test_rvh()->SendNavigate(1, url1); | 3014 test_rvh()->SendNavigate(1, url1); |
3118 | 3015 |
3119 GetLastSession(); | 3016 GetLastSession(); |
3120 | 3017 |
3121 session_helper_.AssertSingleWindowWithSingleTab(windows_, 3); | 3018 session_helper_.AssertSingleWindowWithSingleTab(windows_, 3); |
3122 session_helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0])); | 3019 session_helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0])); |
3123 | 3020 |
3124 TabNavigation nav(0, url0, GURL(), string16(), | 3021 TabNavigation nav(0, url0, GURL(), string16(), |
3125 webkit_glue::CreateHistoryStateForURL(url0), | 3022 webkit_glue::CreateHistoryStateForURL(url0), |
3126 content::PAGE_TRANSITION_LINK); | 3023 PAGE_TRANSITION_LINK); |
3127 session_helper_.AssertNavigationEquals(nav, | 3024 session_helper_.AssertNavigationEquals(nav, |
3128 windows_[0]->tabs[0]->navigations[0]); | 3025 windows_[0]->tabs[0]->navigations[0]); |
3129 nav.set_url(url1); | 3026 nav.set_url(url1); |
3130 session_helper_.AssertNavigationEquals(nav, | 3027 session_helper_.AssertNavigationEquals(nav, |
3131 windows_[0]->tabs[0]->navigations[1]); | 3028 windows_[0]->tabs[0]->navigations[1]); |
3132 nav.set_url(url2); | 3029 nav.set_url(url2); |
3133 session_helper_.AssertNavigationEquals(nav, | 3030 session_helper_.AssertNavigationEquals(nav, |
3134 windows_[0]->tabs[0]->navigations[2]); | 3031 windows_[0]->tabs[0]->navigations[2]); |
3135 } | 3032 } |
3136 | 3033 |
(...skipping 14 matching lines...) Expand all Loading... |
3151 | 3048 |
3152 // Now have url0, and url2. | 3049 // Now have url0, and url2. |
3153 | 3050 |
3154 GetLastSession(); | 3051 GetLastSession(); |
3155 | 3052 |
3156 session_helper_.AssertSingleWindowWithSingleTab(windows_, 2); | 3053 session_helper_.AssertSingleWindowWithSingleTab(windows_, 2); |
3157 session_helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); | 3054 session_helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); |
3158 | 3055 |
3159 TabNavigation nav(0, url0, GURL(), string16(), | 3056 TabNavigation nav(0, url0, GURL(), string16(), |
3160 webkit_glue::CreateHistoryStateForURL(url0), | 3057 webkit_glue::CreateHistoryStateForURL(url0), |
3161 content::PAGE_TRANSITION_LINK); | 3058 PAGE_TRANSITION_LINK); |
3162 session_helper_.AssertNavigationEquals(nav, | 3059 session_helper_.AssertNavigationEquals(nav, |
3163 windows_[0]->tabs[0]->navigations[0]); | 3060 windows_[0]->tabs[0]->navigations[0]); |
3164 nav.set_url(url2); | 3061 nav.set_url(url2); |
3165 session_helper_.AssertNavigationEquals(nav, | 3062 session_helper_.AssertNavigationEquals(nav, |
3166 windows_[0]->tabs[0]->navigations[1]); | 3063 windows_[0]->tabs[0]->navigations[1]); |
3167 } | 3064 } |
3168 */ | 3065 */ |
| 3066 |
| 3067 } // namespace content |
OLD | NEW |