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

Side by Side Diff: content/browser/renderer_host/render_view_host_unittest.cc

Issue 282303014: Add regression tests to ensure that IPC::Listener::OnBadMessageReceived is always called for all ca… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 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
« no previous file with comments | « no previous file | ipc/ipc_channel_proxy_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/path_service.h" 5 #include "base/path_service.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/child_process_security_policy_impl.h" 7 #include "content/browser/child_process_security_policy_impl.h"
8 #include "content/browser/frame_host/render_frame_host_impl.h" 8 #include "content/browser/frame_host/render_frame_host_impl.h"
9 #include "content/browser/renderer_host/render_view_host_delegate_view.h" 9 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
10 #include "content/common/input_messages.h" 10 #include "content/common/input_messages.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ChildProcessSecurityPolicyImpl* policy = 200 ChildProcessSecurityPolicyImpl* policy =
201 ChildProcessSecurityPolicyImpl::GetInstance(); 201 ChildProcessSecurityPolicyImpl::GetInstance();
202 202
203 EXPECT_FALSE(policy->CanRequestURL(id, highlighted_file_url)); 203 EXPECT_FALSE(policy->CanRequestURL(id, highlighted_file_url));
204 EXPECT_FALSE(policy->CanReadFile(id, highlighted_file_path)); 204 EXPECT_FALSE(policy->CanReadFile(id, highlighted_file_path));
205 EXPECT_TRUE(policy->CanRequestURL(id, dragged_file_url)); 205 EXPECT_TRUE(policy->CanRequestURL(id, dragged_file_url));
206 EXPECT_TRUE(policy->CanReadFile(id, dragged_file_path)); 206 EXPECT_TRUE(policy->CanReadFile(id, dragged_file_path));
207 EXPECT_FALSE(policy->CanRequestURL(id, sensitive_file_url)); 207 EXPECT_FALSE(policy->CanRequestURL(id, sensitive_file_url));
208 EXPECT_FALSE(policy->CanReadFile(id, sensitive_file_path)); 208 EXPECT_FALSE(policy->CanReadFile(id, sensitive_file_path));
209 } 209 }
210 /* TODO(jam)
211 // The test that follow trigger DCHECKS in debug build.
212 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
213
214 // Test that when we fail to de-serialize a message, RenderViewHost calls the
215 // ReceivedBadMessage() handler.
216 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) {
217 EXPECT_EQ(0, process()->bad_msg_count());
218 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has
219 // two payload items but the one we construct has none.
220 IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID,
221 IPC::Message::PRIORITY_NORMAL);
222 test_rvh()->OnMessageReceived(message);
223 EXPECT_EQ(1, process()->bad_msg_count());
224 }
225
226 // Test that when we fail to de-serialize a message, RenderWidgetHost calls the
227 // ReceivedBadMessage() handler.
228 TEST_F(RenderViewHostTest, BadMessageHandlerRenderWidgetHost) {
229 EXPECT_EQ(0, process()->bad_msg_count());
230 // craft an incorrect ViewHostMsg_UpdateRect message. The real one has
231 // one payload item but the one we construct has none.
232 IPC::Message message(0, ViewHostMsg_UpdateRect::ID,
233 IPC::Message::PRIORITY_NORMAL);
234 test_rvh()->OnMessageReceived(message);
235 EXPECT_EQ(1, process()->bad_msg_count());
236 }
237
238 // Test that OnInputEventAck() detects bad messages.
239 TEST_F(RenderViewHostTest, BadMessageHandlerInputEventAck) {
240 EXPECT_EQ(0, process()->bad_msg_count());
241 // InputHostMsg_HandleInputEvent_ACK is defined taking 0 params but
242 // the code actually expects it to have at least one int para, this this
243 // bogus message will not fail at de-serialization but should fail in
244 // OnInputEventAck() processing.
245 IPC::Message message(0, InputHostMsg_HandleInputEvent_ACK::ID,
246 IPC::Message::PRIORITY_NORMAL);
247 test_rvh()->OnMessageReceived(message);
248 EXPECT_EQ(1, process()->bad_msg_count());
249 }
250 #endif
251 */
252 210
253 TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) { 211 TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) {
254 base::FilePath file_path; 212 base::FilePath file_path;
255 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); 213 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path));
256 file_path = file_path.AppendASCII("foo"); 214 file_path = file_path.AppendASCII("foo");
257 EXPECT_EQ(0, process()->bad_msg_count()); 215 EXPECT_EQ(0, process()->bad_msg_count());
258 test_rvh()->TestOnUpdateStateWithFile(process()->GetID(), file_path); 216 test_rvh()->TestOnUpdateStateWithFile(process()->GetID(), file_path);
259 EXPECT_EQ(1, process()->bad_msg_count()); 217 EXPECT_EQ(1, process()->bad_msg_count());
260 218
261 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( 219 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
(...skipping 18 matching lines...) Expand all
280 } 238 }
281 239
282 TEST_F(RenderViewHostTest, RoutingIdSane) { 240 TEST_F(RenderViewHostTest, RoutingIdSane) {
283 RenderFrameHostImpl* root_rfh = 241 RenderFrameHostImpl* root_rfh =
284 contents()->GetFrameTree()->root()->current_frame_host(); 242 contents()->GetFrameTree()->root()->current_frame_host();
285 EXPECT_EQ(test_rvh()->GetProcess(), root_rfh->GetProcess()); 243 EXPECT_EQ(test_rvh()->GetProcess(), root_rfh->GetProcess());
286 EXPECT_NE(test_rvh()->GetRoutingID(), root_rfh->routing_id()); 244 EXPECT_NE(test_rvh()->GetRoutingID(), root_rfh->routing_id());
287 } 245 }
288 246
289 } // namespace content 247 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_channel_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698