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

Side by Side Diff: chrome/browser/renderer_host/test/render_view_host_unittest.cc

Issue 3115020: Fixes race condition that could result in a tab prematurely (Closed)
Patch Set: Created 10 years, 4 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 | « chrome/browser/renderer_host/render_view_host.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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/renderer_host/test/test_render_view_host.h" 5 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
6 #include "chrome/browser/tab_contents/navigation_entry.h" 6 #include "chrome/browser/tab_contents/navigation_entry.h"
7 #include "chrome/common/render_messages.h" 7 #include "chrome/common/render_messages.h"
8 8
9 class RenderViewHostTest : public RenderViewHostTestHarness { 9 class RenderViewHostTest : public RenderViewHostTestHarness {
10 }; 10 };
11 11
12 // All about URLs reported by the renderer should get rewritten to about:blank. 12 // All about URLs reported by the renderer should get rewritten to about:blank.
13 // See RenderViewHost::OnMsgNavigate for a discussion. 13 // See RenderViewHost::OnMsgNavigate for a discussion.
14 TEST_F(RenderViewHostTest, FilterAbout) { 14 TEST_F(RenderViewHostTest, FilterAbout) {
15 rvh()->SendNavigate(1, GURL("about:cache")); 15 rvh()->SendNavigate(1, GURL("about:cache"));
16 ASSERT_TRUE(controller().GetActiveEntry()); 16 ASSERT_TRUE(controller().GetActiveEntry());
17 EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->url()); 17 EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->url());
18 } 18 }
19 19
20 // Create a full screen popup RenderWidgetHost and View. 20 // Create a full screen popup RenderWidgetHost and View.
21 TEST_F(RenderViewHostTest, CreateFullscreenWidget) { 21 TEST_F(RenderViewHostTest, CreateFullscreenWidget) {
22 int routing_id = process()->GetNextRoutingID(); 22 int routing_id = process()->GetNextRoutingID();
23 rvh()->CreateNewFullscreenWidget(routing_id, WebKit::WebPopupTypeNone); 23 rvh()->CreateNewFullscreenWidget(routing_id, WebKit::WebPopupTypeNone);
24 } 24 }
25 25
26 // Makes sure that RenderViewHost::is_waiting_for_unload_ack_ is false when
27 // reloading a page. If is_waiting_for_unload_ack_ is not false when reloading
28 // the tab may get closed out even though the user pressed the reload button.
29 TEST_F(RenderViewHostTest, ResetUnloadOnReload) {
30 const GURL url1("http://foo1");
31 const GURL url2("http://foo2");
32
33 // This test is for a subtle timing bug. Here's the sequence that triggered
34 // the bug:
35 // . go to a page.
36 // . go to a new page, preferably one that takes a while to resolve, such
37 // as one on a site that doesn't exist.
38 // . After this step is_waiting_for_unload_ack_ has been set to true on
39 // the first RVH.
40 // . click stop before the page has been commited.
41 // . click reload.
42 // . is_waiting_for_unload_ack_ is still true, and the if the hang monitor
43 // fires the tab gets closed.
44
45 NavigateAndCommit(url1);
46 controller().LoadURL(url2, GURL(), 0);
47 // Simulate the ClosePage call which is normally sent by the URLRequest.
48 rvh()->ClosePage(true, 0, 0);
49 // Needed so that navigations are not suspended on the RVH. Normally handled
50 // by way of ViewHostMsg_ShouldClose_ACK.
51 contents()->render_manager()->ShouldClosePage(true, true);
52 contents()->Stop();
53 controller().Reload(false);
54 EXPECT_FALSE(rvh()->is_waiting_for_unload_ack());
55 }
56
26 // The test that follow trigger DCHECKS in debug build. 57 // The test that follow trigger DCHECKS in debug build.
27 #if defined(NDEBUG) 58 #if defined(NDEBUG)
28 59
29 // Test that when we fail to de-serialize a message, RenderViewHost calls the 60 // Test that when we fail to de-serialize a message, RenderViewHost calls the
30 // ReceivedBadMessage() handler. 61 // ReceivedBadMessage() handler.
31 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { 62 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) {
32 EXPECT_EQ(0, process()->bad_msg_count()); 63 EXPECT_EQ(0, process()->bad_msg_count());
33 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has 64 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has
34 // two payload items but the one we construct has none. 65 // two payload items but the one we construct has none.
35 IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID, 66 IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID,
(...skipping 21 matching lines...) Expand all
57 // the code actually expects it to have at least one int para, this this 88 // the code actually expects it to have at least one int para, this this
58 // bogus message will not fail at de-serialization but should fail in 89 // bogus message will not fail at de-serialization but should fail in
59 // OnMsgInputEventAck() processing. 90 // OnMsgInputEventAck() processing.
60 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID, 91 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID,
61 IPC::Message::PRIORITY_NORMAL); 92 IPC::Message::PRIORITY_NORMAL);
62 rvh()->TestOnMessageReceived(message); 93 rvh()->TestOnMessageReceived(message);
63 EXPECT_EQ(1, process()->bad_msg_count()); 94 EXPECT_EQ(1, process()->bad_msg_count());
64 } 95 }
65 96
66 #endif // NDEBUG 97 #endif // NDEBUG
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_view_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698