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

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

Issue 6575009: Move files out of chrome\browser\renderer_host\test alongside their source. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
6 #include "chrome/browser/tab_contents/navigation_controller.h"
7 #include "chrome/browser/tab_contents/navigation_entry.h"
8 #include "chrome/browser/tab_contents/test_tab_contents.h"
9 #include "chrome/common/page_transition_types.h"
10 #include "chrome/common/render_messages.h"
11
12 class RenderViewHostTest : public RenderViewHostTestHarness {
13 };
14
15 // All about URLs reported by the renderer should get rewritten to about:blank.
16 // See RenderViewHost::OnMsgNavigate for a discussion.
17 TEST_F(RenderViewHostTest, FilterAbout) {
18 rvh()->SendNavigate(1, GURL("about:cache"));
19 ASSERT_TRUE(controller().GetActiveEntry());
20 EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->url());
21 }
22
23 // Create a full screen popup RenderWidgetHost and View.
24 TEST_F(RenderViewHostTest, CreateFullscreenWidget) {
25 int routing_id = process()->GetNextRoutingID();
26 rvh()->CreateNewFullscreenWidget(routing_id);
27 }
28
29 // Makes sure that RenderViewHost::is_waiting_for_unload_ack_ is false when
30 // reloading a page. If is_waiting_for_unload_ack_ is not false when reloading
31 // the tab may get closed out even though the user pressed the reload button.
32 TEST_F(RenderViewHostTest, ResetUnloadOnReload) {
33 const GURL url1("http://foo1");
34 const GURL url2("http://foo2");
35
36 // This test is for a subtle timing bug. Here's the sequence that triggered
37 // the bug:
38 // . go to a page.
39 // . go to a new page, preferably one that takes a while to resolve, such
40 // as one on a site that doesn't exist.
41 // . After this step is_waiting_for_unload_ack_ has been set to true on
42 // the first RVH.
43 // . click stop before the page has been commited.
44 // . click reload.
45 // . is_waiting_for_unload_ack_ is still true, and the if the hang monitor
46 // fires the tab gets closed.
47
48 NavigateAndCommit(url1);
49 controller().LoadURL(url2, GURL(), PageTransition::LINK);
50 // Simulate the ClosePage call which is normally sent by the net::URLRequest.
51 rvh()->ClosePage(true, 0, 0);
52 // Needed so that navigations are not suspended on the RVH. Normally handled
53 // by way of ViewHostMsg_ShouldClose_ACK.
54 contents()->render_manager()->ShouldClosePage(true, true);
55 contents()->Stop();
56 controller().Reload(false);
57 EXPECT_FALSE(rvh()->is_waiting_for_unload_ack());
58 }
59
60 // The test that follow trigger DCHECKS in debug build.
61 #if defined(NDEBUG)
62
63 // Test that when we fail to de-serialize a message, RenderViewHost calls the
64 // ReceivedBadMessage() handler.
65 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) {
66 EXPECT_EQ(0, process()->bad_msg_count());
67 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has
68 // two payload items but the one we construct has none.
69 IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID,
70 IPC::Message::PRIORITY_NORMAL);
71 rvh()->TestOnMessageReceived(message);
72 EXPECT_EQ(1, process()->bad_msg_count());
73 }
74
75 // Test that when we fail to de-serialize a message, RenderWidgetHost calls the
76 // ReceivedBadMessage() handler.
77 TEST_F(RenderViewHostTest, BadMessageHandlerRenderWidgetHost) {
78 EXPECT_EQ(0, process()->bad_msg_count());
79 // craft an incorrect ViewHostMsg_UpdateRect message. The real one has
80 // one payload item but the one we construct has none.
81 IPC::Message message(0, ViewHostMsg_UpdateRect::ID,
82 IPC::Message::PRIORITY_NORMAL);
83 rvh()->TestOnMessageReceived(message);
84 EXPECT_EQ(1, process()->bad_msg_count());
85 }
86
87 // Test that OnMsgInputEventAck() detects bad messages.
88 TEST_F(RenderViewHostTest, BadMessageHandlerInputEventAck) {
89 EXPECT_EQ(0, process()->bad_msg_count());
90 // ViewHostMsg_HandleInputEvent_ACK is defined taking 0 params but
91 // the code actually expects it to have at least one int para, this this
92 // bogus message will not fail at de-serialization but should fail in
93 // OnMsgInputEventAck() processing.
94 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID,
95 IPC::Message::PRIORITY_NORMAL);
96 rvh()->TestOnMessageReceived(message);
97 EXPECT_EQ(1, process()->bad_msg_count());
98 }
99
100 #endif // NDEBUG
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698