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

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 853083003: Try to test a theoretical problem: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | 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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "content/browser/frame_host/navigation_entry_impl.h" 7 #include "content/browser/frame_host/navigation_entry_impl.h"
8 #include "content/browser/web_contents/web_contents_impl.h" 8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/browser/web_contents/web_contents_view.h" 9 #include "content/browser/web_contents/web_contents_view.h"
10 #include "content/common/frame_messages.h" 10 #include "content/common/frame_messages.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 "a.click();")); 477 "a.click();"));
478 WebContents* new_web_contents = new_web_contents_observer.GetWebContents(); 478 WebContents* new_web_contents = new_web_contents_observer.GetWebContents();
479 WaitForLoadStop(new_web_contents); 479 WaitForLoadStop(new_web_contents);
480 EXPECT_TRUE(new_web_contents_observer.RenderViewCreatedCalled()); 480 EXPECT_TRUE(new_web_contents_observer.RenderViewCreatedCalled());
481 } 481 }
482 482
483 struct LoadProgressDelegateAndObserver : public WebContentsDelegate, 483 struct LoadProgressDelegateAndObserver : public WebContentsDelegate,
484 public WebContentsObserver { 484 public WebContentsObserver {
485 LoadProgressDelegateAndObserver(Shell* shell) 485 LoadProgressDelegateAndObserver(Shell* shell)
486 : WebContentsObserver(shell->web_contents()), 486 : WebContentsObserver(shell->web_contents()),
487 subframe_rfh(nullptr),
487 did_start_loading(false), 488 did_start_loading(false),
488 did_stop_loading(false) { 489 did_stop_loading(false) {
489 web_contents()->SetDelegate(this); 490 web_contents()->SetDelegate(this);
490 } 491 }
491 492
492 // WebContentsDelegate: 493 // WebContentsDelegate:
493 void LoadProgressChanged(WebContents* source, double progress) override { 494 void LoadProgressChanged(WebContents* source, double progress) override {
495 DLOG(INFO) << "LoadProgressChanged";
494 EXPECT_TRUE(did_start_loading); 496 EXPECT_TRUE(did_start_loading);
495 EXPECT_FALSE(did_stop_loading); 497 EXPECT_FALSE(did_stop_loading);
496 progresses.push_back(progress); 498 progresses.push_back(progress);
497 } 499 }
498 500
499 // WebContentsObserver: 501 // WebContentsObserver:
500 void DidStartLoading(RenderViewHost* render_view_host) override { 502 void DidStartLoading(RenderViewHost* render_view_host) override {
503 DLOG(INFO) << "DidStartLoading for " << render_view_host->GetSiteInstance()- >GetSiteURL();
501 EXPECT_FALSE(did_start_loading); 504 EXPECT_FALSE(did_start_loading);
502 EXPECT_EQ(0U, progresses.size()); 505 EXPECT_EQ(0U, progresses.size());
503 EXPECT_FALSE(did_stop_loading); 506 EXPECT_FALSE(did_stop_loading);
504 did_start_loading = true; 507 did_start_loading = true;
508
509 // TODO(creis): Replace with a callback with a setter function.
510 if (subframe_rfh) {
511 DLOG(INFO) << "Forcing a stale DidStartLoading for " << subframe_rfh->GetS iteInstance()->GetSiteURL();
512 // Before the new navigation has a chance to commit, simulate a
513 // DidStartLoading IPC from the old subframe RFH.
514 FrameHostMsg_DidStartLoading subframe_start_msg(
515 subframe_rfh->GetRoutingID(), true);
516 static_cast<WebContentsImpl*>(web_contents())->OnMessageReceived(
517 subframe_rfh, subframe_start_msg);
518
519 // Also simulate a DidChangeLoadProgress, but not a DidStopLoading.
520 FrameHostMsg_DidChangeLoadProgress progress_msg(
521 subframe_rfh->GetRoutingID(), 1.0);
522 static_cast<WebContentsImpl*>(web_contents())->OnMessageReceived(
523 subframe_rfh, progress_msg);
524
525 // Only do this once.
526 subframe_rfh = nullptr;
527 }
505 } 528 }
506 529
507 void DidStopLoading(RenderViewHost* render_view_host) override { 530 void DidStopLoading(RenderViewHost* render_view_host) override {
508 EXPECT_TRUE(did_start_loading); 531 EXPECT_TRUE(did_start_loading);
509 EXPECT_GE(progresses.size(), 1U); 532 EXPECT_GE(progresses.size(), 1U);
510 EXPECT_FALSE(did_stop_loading); 533 EXPECT_FALSE(did_stop_loading);
511 did_stop_loading = true; 534 did_stop_loading = true;
512 } 535 }
513 536
537 // TODO(creis): Replace with a Callback.
538 RenderFrameHost* subframe_rfh;
514 bool did_start_loading; 539 bool did_start_loading;
515 std::vector<double> progresses; 540 std::vector<double> progresses;
516 bool did_stop_loading; 541 bool did_stop_loading;
517 }; 542 };
518 543
519 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgress) { 544 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgress) {
520 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 545 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
521 scoped_ptr<LoadProgressDelegateAndObserver> delegate( 546 scoped_ptr<LoadProgressDelegateAndObserver> delegate(
522 new LoadProgressDelegateAndObserver(shell())); 547 new LoadProgressDelegateAndObserver(shell()));
523 548
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 TestNavigationObserver tab_observer(shell()->web_contents(), 1); 618 TestNavigationObserver tab_observer(shell()->web_contents(), 1);
594 GURL url(embedded_test_server()->GetURL("foo.com", "/title2.html")); 619 GURL url(embedded_test_server()->GetURL("foo.com", "/title2.html"));
595 shell()->LoadURL(url); 620 shell()->LoadURL(url);
596 tab_observer.Wait(); 621 tab_observer.Wait();
597 EXPECT_EQ(url, shell()->web_contents()->GetLastCommittedURL()); 622 EXPECT_EQ(url, shell()->web_contents()->GetLastCommittedURL());
598 623
599 // We should have gotten to DidStopLoading. 624 // We should have gotten to DidStopLoading.
600 EXPECT_TRUE(delegate->did_stop_loading); 625 EXPECT_TRUE(delegate->did_stop_loading);
601 } 626 }
602 627
628 // Ensure that a new navigation that interrupts a pending one will still fire
629 // a DidStopLoading. See http://crbug.com/429399.
630 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
631 LoadProgressAfterStaleDidStart) {
632 host_resolver()->AddRule("*", "127.0.0.1");
633 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
634
635 // Start at a real page with a subframe.
636 DLOG(INFO) << "First nav";
637 NavigateToURL(shell(), embedded_test_server()->GetURL(
638 "/frame_tree/page_with_one_frame.html"));
639 FrameTree* frame_tree =
640 static_cast<WebContentsImpl*>(shell()->web_contents())->GetFrameTree();
641 ASSERT_EQ(1U, frame_tree->root()->child_count());
642 RenderFrameHost* subframe_rfh =
643 frame_tree->root()->child_at(0)->current_frame_host();
644
645 scoped_ptr<LoadProgressDelegateAndObserver> delegate(
646 new LoadProgressDelegateAndObserver(shell()));
647
648 // Now start a new cross-process navigation.
649 TestNavigationObserver tab_observer(shell()->web_contents(), 1);
650 GURL url(embedded_test_server()->GetURL("foo.com", "/title2.html"));
651 DLOG(INFO) << "Second nav to " << url;
652 shell()->LoadURL(url);
653
654 // Do this after the fake DidStartLoading in RFH::Navigate, so that it runs
655 // when the real DidStartLoading arrives from the old renderer.
656 delegate->subframe_rfh = subframe_rfh;
657
658 // The fake subframe DidStartLoading should have incremented
659 // loading_frames_in_progress_...
660
661 // Now complete the new navigation.
662 tab_observer.Wait();
663 EXPECT_EQ(url, shell()->web_contents()->GetLastCommittedURL());
664
665 // We should have gotten to DidStopLoading.
666 EXPECT_TRUE(delegate->did_stop_loading);
667 }
668
603 struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver { 669 struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver {
604 FirstVisuallyNonEmptyPaintObserver(Shell* shell) 670 FirstVisuallyNonEmptyPaintObserver(Shell* shell)
605 : WebContentsObserver(shell->web_contents()), 671 : WebContentsObserver(shell->web_contents()),
606 did_fist_visually_non_empty_paint_(false) {} 672 did_fist_visually_non_empty_paint_(false) {}
607 673
608 void DidFirstVisuallyNonEmptyPaint() override { 674 void DidFirstVisuallyNonEmptyPaint() override {
609 did_fist_visually_non_empty_paint_ = true; 675 did_fist_visually_non_empty_paint_ = true;
610 on_did_first_visually_non_empty_paint_.Run(); 676 on_did_first_visually_non_empty_paint_.Run();
611 } 677 }
612 678
(...skipping 23 matching lines...) Expand all
636 new FirstVisuallyNonEmptyPaintObserver(shell())); 702 new FirstVisuallyNonEmptyPaintObserver(shell()));
637 703
638 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 704 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
639 705
640 observer->WaitForDidFirstVisuallyNonEmptyPaint(); 706 observer->WaitForDidFirstVisuallyNonEmptyPaint();
641 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_); 707 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_);
642 } 708 }
643 709
644 } // namespace content 710 } // namespace content
645 711
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698