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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 1872313003: PlzNavigate: don't discard pending entry in DidFailProvisionalLoad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + removed the content_unittests filter Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/frame_host/navigator_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 27 matching lines...) Expand all
38 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/web_contents_delegate.h" 39 #include "content/public/browser/web_contents_delegate.h"
40 #include "content/public/browser/web_contents_observer.h" 40 #include "content/public/browser/web_contents_observer.h"
41 #include "content/public/common/browser_side_navigation_policy.h" 41 #include "content/public/common/browser_side_navigation_policy.h"
42 #include "content/public/common/page_state.h" 42 #include "content/public/common/page_state.h"
43 #include "content/public/common/page_type.h" 43 #include "content/public/common/page_type.h"
44 #include "content/public/common/url_constants.h" 44 #include "content/public/common/url_constants.h"
45 #include "content/public/test/mock_render_process_host.h" 45 #include "content/public/test/mock_render_process_host.h"
46 #include "content/public/test/test_notification_tracker.h" 46 #include "content/public/test/test_notification_tracker.h"
47 #include "content/public/test/test_utils.h" 47 #include "content/public/test/test_utils.h"
48 #include "content/test/browser_side_navigation_test_utils.h"
48 #include "content/test/test_render_frame_host.h" 49 #include "content/test/test_render_frame_host.h"
49 #include "content/test/test_render_view_host.h" 50 #include "content/test/test_render_view_host.h"
50 #include "content/test/test_web_contents.h" 51 #include "content/test/test_web_contents.h"
51 #include "skia/ext/platform_canvas.h" 52 #include "skia/ext/platform_canvas.h"
52 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
53 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" 54 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h"
54 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 55 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
55 56
56 using base::Time; 57 using base::Time;
57 58
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 private: 310 private:
310 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, 311 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
311 const LoadCommittedDetails& details, 312 const LoadCommittedDetails& details,
312 const FrameNavigateParams& params) override { 313 const FrameNavigateParams& params) override {
313 details_ = details; 314 details_ = details;
314 } 315 }
315 316
316 LoadCommittedDetails details_; 317 LoadCommittedDetails details_;
317 }; 318 };
318 319
320 // PlzNavigate
321 // A NavigationControllerTest run with --enable-browser-side-navigation.
322 class NavigationControllerTestWithBrowserSideNavigation
323 : public NavigationControllerTest {
324 public:
325 void SetUp() override {
326 EnableBrowserSideNavigation();
327 NavigationControllerTest::SetUp();
328 }
329 };
330
319 // ----------------------------------------------------------------------------- 331 // -----------------------------------------------------------------------------
320 332
321 TEST_F(NavigationControllerTest, Defaults) { 333 TEST_F(NavigationControllerTest, Defaults) {
322 NavigationControllerImpl& controller = controller_impl(); 334 NavigationControllerImpl& controller = controller_impl();
323 335
324 EXPECT_FALSE(controller.GetPendingEntry()); 336 EXPECT_FALSE(controller.GetPendingEntry());
325 EXPECT_FALSE(controller.GetVisibleEntry()); 337 EXPECT_FALSE(controller.GetVisibleEntry());
326 EXPECT_FALSE(controller.GetLastCommittedEntry()); 338 EXPECT_FALSE(controller.GetLastCommittedEntry());
327 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 339 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
328 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); 340 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // 1. Pending entry for A is created. 421 // 1. Pending entry for A is created.
410 // 2. DidStartProvisionalLoad message for A arrives. 422 // 2. DidStartProvisionalLoad message for A arrives.
411 // 3. Pending entry for B is created. 423 // 3. Pending entry for B is created.
412 // 4. DidFailProvisionalLoad message for A arrives. The logic here discards. 424 // 4. DidFailProvisionalLoad message for A arrives. The logic here discards.
413 // 5. DidStartProvisionalLoad message for B arrives. 425 // 5. DidStartProvisionalLoad message for B arrives.
414 // 426 //
415 // At step (4), the pending entry for B is discarded, when A is the one that 427 // At step (4), the pending entry for B is discarded, when A is the one that
416 // is being aborted. This caused the last committed entry to be displayed in 428 // is being aborted. This caused the last committed entry to be displayed in
417 // the omnibox, which is the entry before A was created. 429 // the omnibox, which is the entry before A was created.
418 TEST_F(NavigationControllerTest, DontDiscardWrongPendingEntry) { 430 TEST_F(NavigationControllerTest, DontDiscardWrongPendingEntry) {
431 if (IsBrowserSideNavigationEnabled()) {
432 // PlzNavigate: this exact order of events cannot happen in PlzNavigate. A
433 // similar issue with the wrong pending entry being discarded is tested in
434 // the PlzNavigate version of the test below.
435 SUCCEED() << "Test is not applicable with PlzNavigate.";
436 return;
437 }
438
419 NavigationControllerImpl& controller = controller_impl(); 439 NavigationControllerImpl& controller = controller_impl();
420 GURL initial_url("http://www.google.com"); 440 GURL initial_url("http://www.google.com");
421 GURL url_1("http://foo.com"); 441 GURL url_1("http://foo.com");
422 GURL url_2("http://foo2.com"); 442 GURL url_2("http://foo2.com");
423 443
424 // Navigate inititally. This is the url that could erroneously be the visible 444 // Navigate inititally. This is the url that could erroneously be the visible
425 // entry when url_1 fails. 445 // entry when url_1 fails.
426 NavigateAndCommit(initial_url); 446 NavigateAndCommit(initial_url);
427 447
428 // Set the pending entry as url_1 and receive the DidStartProvisionalLoad 448 // Set the pending entry as url_1 and receive the DidStartProvisionalLoad
(...skipping 12 matching lines...) Expand all
441 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL()); 461 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL());
442 main_test_rfh()->SimulateNavigationError(url_1, net::ERR_ABORTED); 462 main_test_rfh()->SimulateNavigationError(url_1, net::ERR_ABORTED);
443 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL()); 463 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL());
444 464
445 // Get the DidStartProvisionalLoad message for url_2. 465 // Get the DidStartProvisionalLoad message for url_2.
446 main_test_rfh()->SimulateNavigationStart(url_2); 466 main_test_rfh()->SimulateNavigationStart(url_2);
447 467
448 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL()); 468 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL());
449 } 469 }
450 470
471 // PlzNavigate: tests a case similar to
472 // NavigationControllerTest.DontDiscardWrongPendingEntry.
473 // Tests hat receiving a DidFailProvisionalLoad from the renderer that is
474 // trying to commit an error page won't reset the pending entry of a navigation
475 // that just started.
476 TEST_F(NavigationControllerTestWithBrowserSideNavigation,
477 DontDiscardWrongPendingEntry) {
478 NavigationControllerImpl& controller = controller_impl();
479 GURL initial_url("http://www.google.com");
480 GURL url_1("http://google.com/foo");
481 GURL url_2("http://foo2.com");
482
483 // Navigate inititally. This is the url that could erroneously be the visible
484 // entry when url_1 fails.
485 NavigateAndCommit(initial_url);
486
487 // Set the pending entry as url_1 and receive the DidStartProvisionalLoad
488 // message, creating the NavigationHandle.
489 controller.LoadURL(url_1, Referrer(), ui::PAGE_TRANSITION_TYPED,
490 std::string());
491 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL());
492 main_test_rfh()->SimulateNavigationStart(url_1);
493 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL());
494
495 // The navigation fails and needs to show an error page. This resets the
496 // pending entry.
497 main_test_rfh()->SimulateNavigationError(url_1, net::ERR_TIMED_OUT);
498 EXPECT_EQ(initial_url, controller.GetVisibleEntry()->GetURL());
499
500 // A navigation to url_2 starts, creating a pending navigation entry.
501 controller.LoadURL(url_2, Referrer(), ui::PAGE_TRANSITION_TYPED,
502 std::string());
503 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL());
504
505 // The DidFailProvsionalLoad IPC is received from the current RFH that is
506 // committing an error page. This should not reset the pending entry for the
507 // new ongoing navigation.
508 FrameHostMsg_DidFailProvisionalLoadWithError_Params error;
509 error.error_code = net::ERR_TIMED_OUT;
510 error.url = url_1;
511 main_test_rfh()->OnMessageReceived(
512 FrameHostMsg_DidFailProvisionalLoadWithError(
513 main_test_rfh()->GetRoutingID(), error));
514 EXPECT_EQ(url_2, controller.GetVisibleEntry()->GetURL());
515 }
516
451 TEST_F(NavigationControllerTest, LoadURL) { 517 TEST_F(NavigationControllerTest, LoadURL) {
452 NavigationControllerImpl& controller = controller_impl(); 518 NavigationControllerImpl& controller = controller_impl();
453 TestNotificationTracker notifications; 519 TestNotificationTracker notifications;
454 RegisterForAllNavNotifications(&notifications, &controller); 520 RegisterForAllNavNotifications(&notifications, &controller);
455 521
456 const GURL url1("http://foo1"); 522 const GURL url1("http://foo1");
457 const GURL url2("http://foo2"); 523 const GURL url2("http://foo2");
458 524
459 controller.LoadURL( 525 controller.LoadURL(
460 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 526 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
(...skipping 4776 matching lines...) Expand 10 before | Expand all | Expand 10 after
5237 EXPECT_EQ(default_ssl_status.content_status, 5303 EXPECT_EQ(default_ssl_status.content_status,
5238 observer.details().ssl_status.content_status); 5304 observer.details().ssl_status.content_status);
5239 EXPECT_EQ( 5305 EXPECT_EQ(
5240 0u, 5306 0u,
5241 observer.details().ssl_status.signed_certificate_timestamp_ids.size()); 5307 observer.details().ssl_status.signed_certificate_timestamp_ids.size());
5242 5308
5243 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); 5309 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count());
5244 } 5310 }
5245 5311
5246 } // namespace content 5312 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698