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

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

Issue 633323003: Fix unresponsive tab closure when a navigation is in progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/frame_host/cross_site_transferring_request.h" 10 #include "content/browser/frame_host/cross_site_transferring_request.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 virtual void BeforeUnloadFired(WebContents* web_contents, 94 virtual void BeforeUnloadFired(WebContents* web_contents,
95 bool proceed, 95 bool proceed,
96 bool* proceed_to_fire_unload) override { 96 bool* proceed_to_fire_unload) override {
97 *proceed_to_fire_unload = proceed; 97 *proceed_to_fire_unload = proceed;
98 } 98 }
99 99
100 private: 100 private:
101 DISALLOW_COPY_AND_ASSIGN(BeforeUnloadFiredWebContentsDelegate); 101 DISALLOW_COPY_AND_ASSIGN(BeforeUnloadFiredWebContentsDelegate);
102 }; 102 };
103 103
104 class CloseWebContentsDelegate : public WebContentsDelegate {
105 public:
106 CloseWebContentsDelegate() : close_called_(false) {}
107 virtual ~CloseWebContentsDelegate() {}
108
109 virtual void CloseContents(WebContents* web_contents) override {
110 close_called_ = true;
111 }
112
113 bool is_closed() { return close_called_; }
114
115 private:
116 DISALLOW_COPY_AND_ASSIGN(CloseWebContentsDelegate);
117
118 bool close_called_;
119 };
120
104 // This observer keeps track of the last deleted RenderViewHost to avoid 121 // This observer keeps track of the last deleted RenderViewHost to avoid
105 // accessing it and causing use-after-free condition. 122 // accessing it and causing use-after-free condition.
106 class RenderViewHostDeletedObserver : public WebContentsObserver { 123 class RenderViewHostDeletedObserver : public WebContentsObserver {
107 public: 124 public:
108 RenderViewHostDeletedObserver(RenderViewHost* rvh) 125 RenderViewHostDeletedObserver(RenderViewHost* rvh)
109 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)), 126 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)),
110 process_id_(rvh->GetProcess()->GetID()), 127 process_id_(rvh->GetProcess()->GetID()),
111 routing_id_(rvh->GetRoutingID()), 128 routing_id_(rvh->GetRoutingID()),
112 deleted_(false) { 129 deleted_(false) {
113 } 130 }
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 1524 notifications.ListenFor(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1508 Source<RenderWidgetHost>(host2->render_view_host())); 1525 Source<RenderWidgetHost>(host2->render_view_host()));
1509 manager->OnBeforeUnloadACK(false, true, base::TimeTicks()); 1526 manager->OnBeforeUnloadACK(false, true, base::TimeTicks());
1510 1527
1511 EXPECT_TRUE( 1528 EXPECT_TRUE(
1512 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); 1529 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED));
1513 EXPECT_FALSE(manager->pending_frame_host()); 1530 EXPECT_FALSE(manager->pending_frame_host());
1514 EXPECT_EQ(host, manager->current_frame_host()); 1531 EXPECT_EQ(host, manager->current_frame_host());
1515 } 1532 }
1516 1533
1534 TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) {
1535 const GURL kUrl1("http://www.google.com/");
1536 const GURL kUrl2("http://www.chromium.org/");
1537
1538 CloseWebContentsDelegate close_delegate;
1539 contents()->SetDelegate(&close_delegate);
1540
1541 // Navigate to the first page.
1542 contents()->NavigateAndCommit(kUrl1);
1543 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
1544
1545 // Start to close the tab, but assume it's unresponsive.
1546 rfh1->render_view_host()->ClosePage();
1547 EXPECT_TRUE(rfh1->render_view_host()->is_waiting_for_close_ack());
1548
1549 // Start a navigation to a new site.
1550 controller().LoadURL(
1551 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1552 EXPECT_TRUE(contents()->cross_navigation_pending());
1553
1554 // Simulate the unresponsiveness timer. The tab should close.
1555 contents()->RendererUnresponsive(rfh1->render_view_host());
1556 EXPECT_TRUE(close_delegate.is_closed());
1557 }
1558
1517 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is 1559 // Tests that the RenderFrameHost is properly deleted when the SwapOutACK is
1518 // received. (SwapOut and the corresponding ACK always occur after commit.) 1560 // received. (SwapOut and the corresponding ACK always occur after commit.)
1519 // Also tests that an early SwapOutACK is properly ignored. 1561 // Also tests that an early SwapOutACK is properly ignored.
1520 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { 1562 TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) {
1521 const GURL kUrl1("http://www.google.com/"); 1563 const GURL kUrl1("http://www.google.com/");
1522 const GURL kUrl2("http://www.chromium.org/"); 1564 const GURL kUrl2("http://www.chromium.org/");
1523 1565
1524 // Navigate to the first page. 1566 // Navigate to the first page.
1525 contents()->NavigateAndCommit(kUrl1); 1567 contents()->NavigateAndCommit(kUrl1);
1526 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); 1568 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 1734 pending_rfh->GetSiteInstance()->increment_active_frame_count();
1693 1735
1694 contents()->GetMainFrame()->OnMessageReceived( 1736 contents()->GetMainFrame()->OnMessageReceived(
1695 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1737 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
1696 EXPECT_FALSE(contents()->cross_navigation_pending()); 1738 EXPECT_FALSE(contents()->cross_navigation_pending());
1697 EXPECT_FALSE(rfh_deleted_observer.deleted()); 1739 EXPECT_FALSE(rfh_deleted_observer.deleted());
1698 } 1740 }
1699 } 1741 }
1700 1742
1701 } // namespace content 1743 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager.cc ('k') | content/browser/renderer_host/render_view_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698