| OLD | NEW | 
|---|
| 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/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" | 
| 9 #include "content/common/input_messages.h" | 9 #include "content/common/input_messages.h" | 
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" | 
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 218 | 218 | 
| 219 // The test that follow trigger DCHECKS in debug build. | 219 // The test that follow trigger DCHECKS in debug build. | 
| 220 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 220 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 
| 221 | 221 | 
| 222 // Test that when we fail to de-serialize a message, RenderViewHost calls the | 222 // Test that when we fail to de-serialize a message, RenderViewHost calls the | 
| 223 // ReceivedBadMessage() handler. | 223 // ReceivedBadMessage() handler. | 
| 224 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { | 224 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { | 
| 225   EXPECT_EQ(0, process()->bad_msg_count()); | 225   EXPECT_EQ(0, process()->bad_msg_count()); | 
| 226   // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has | 226   // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has | 
| 227   // two payload items but the one we construct has none. | 227   // two payload items but the one we construct has none. | 
| 228   IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID); | 228   IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID, | 
|  | 229                        IPC::Message::PRIORITY_NORMAL); | 
| 229   test_rvh()->OnMessageReceived(message); | 230   test_rvh()->OnMessageReceived(message); | 
| 230   EXPECT_EQ(1, process()->bad_msg_count()); | 231   EXPECT_EQ(1, process()->bad_msg_count()); | 
| 231 } | 232 } | 
| 232 | 233 | 
| 233 // Test that when we fail to de-serialize a message, RenderWidgetHost calls the | 234 // Test that when we fail to de-serialize a message, RenderWidgetHost calls the | 
| 234 // ReceivedBadMessage() handler. | 235 // ReceivedBadMessage() handler. | 
| 235 TEST_F(RenderViewHostTest, BadMessageHandlerRenderWidgetHost) { | 236 TEST_F(RenderViewHostTest, BadMessageHandlerRenderWidgetHost) { | 
| 236   EXPECT_EQ(0, process()->bad_msg_count()); | 237   EXPECT_EQ(0, process()->bad_msg_count()); | 
| 237   // craft an incorrect ViewHostMsg_UpdateRect message. The real one has | 238   // craft an incorrect ViewHostMsg_UpdateRect message. The real one has | 
| 238   // one payload item but the one we construct has none. | 239   // one payload item but the one we construct has none. | 
| 239   IPC::Message message(0, ViewHostMsg_UpdateRect::ID); | 240   IPC::Message message(0, ViewHostMsg_UpdateRect::ID, | 
|  | 241                        IPC::Message::PRIORITY_NORMAL); | 
| 240   test_rvh()->OnMessageReceived(message); | 242   test_rvh()->OnMessageReceived(message); | 
| 241   EXPECT_EQ(1, process()->bad_msg_count()); | 243   EXPECT_EQ(1, process()->bad_msg_count()); | 
| 242 } | 244 } | 
| 243 | 245 | 
| 244 // Test that OnInputEventAck() detects bad messages. | 246 // Test that OnInputEventAck() detects bad messages. | 
| 245 TEST_F(RenderViewHostTest, BadMessageHandlerInputEventAck) { | 247 TEST_F(RenderViewHostTest, BadMessageHandlerInputEventAck) { | 
| 246   EXPECT_EQ(0, process()->bad_msg_count()); | 248   EXPECT_EQ(0, process()->bad_msg_count()); | 
| 247   // InputHostMsg_HandleInputEvent_ACK is defined taking 0 params but | 249   // InputHostMsg_HandleInputEvent_ACK is defined taking 0 params but | 
| 248   // the code actually expects it to have at least one int para, this this | 250   // the code actually expects it to have at least one int para, this this | 
| 249   // bogus message will not fail at de-serialization but should fail in | 251   // bogus message will not fail at de-serialization but should fail in | 
| 250   // OnInputEventAck() processing. | 252   // OnInputEventAck() processing. | 
| 251   IPC::Message message(0, InputHostMsg_HandleInputEvent_ACK::ID); | 253   IPC::Message message(0, InputHostMsg_HandleInputEvent_ACK::ID, | 
|  | 254                        IPC::Message::PRIORITY_NORMAL); | 
| 252   test_rvh()->OnMessageReceived(message); | 255   test_rvh()->OnMessageReceived(message); | 
| 253   EXPECT_EQ(1, process()->bad_msg_count()); | 256   EXPECT_EQ(1, process()->bad_msg_count()); | 
| 254 } | 257 } | 
| 255 | 258 | 
| 256 #endif | 259 #endif | 
| 257 | 260 | 
| 258 TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) { | 261 TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) { | 
| 259   base::FilePath file_path; | 262   base::FilePath file_path; | 
| 260   EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); | 263   EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); | 
| 261   file_path = file_path.AppendASCII("foo"); | 264   file_path = file_path.AppendASCII("foo"); | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 285 } | 288 } | 
| 286 | 289 | 
| 287 TEST_F(RenderViewHostTest, RoutingIdSane) { | 290 TEST_F(RenderViewHostTest, RoutingIdSane) { | 
| 288   EXPECT_EQ(test_rvh()->GetProcess(), | 291   EXPECT_EQ(test_rvh()->GetProcess(), | 
| 289             test_rvh()->main_render_frame_host()->GetProcess()); | 292             test_rvh()->main_render_frame_host()->GetProcess()); | 
| 290   EXPECT_NE(test_rvh()->GetRoutingID(), | 293   EXPECT_NE(test_rvh()->GetRoutingID(), | 
| 291             test_rvh()->main_render_frame_host()->routing_id()); | 294             test_rvh()->main_render_frame_host()->routing_id()); | 
| 292 } | 295 } | 
| 293 | 296 | 
| 294 }  // namespace content | 297 }  // namespace content | 
| OLD | NEW | 
|---|