| 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/utf_string_conversions.h" |
| 5 #include "content/browser/child_process_security_policy_impl.h" | 6 #include "content/browser/child_process_security_policy_impl.h" |
| 6 #include "content/browser/renderer_host/test_render_view_host.h" | 7 #include "content/browser/renderer_host/test_render_view_host.h" |
| 7 #include "content/browser/web_contents/navigation_controller_impl.h" | 8 #include "content/browser/web_contents/navigation_controller_impl.h" |
| 8 #include "content/browser/web_contents/test_web_contents.h" | 9 #include "content/browser/web_contents/test_web_contents.h" |
| 9 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| 10 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
| 11 #include "content/public/common/bindings_policy.h" | 12 #include "content/public/common/bindings_policy.h" |
| 12 #include "content/public/common/page_transition_types.h" | 13 #include "content/public/common/page_transition_types.h" |
| 13 #include "content/test/mock_render_process_host.h" | 14 #include "content/test/mock_render_process_host.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 drop_data.html_base_url = http_url; | 158 drop_data.html_base_url = http_url; |
| 158 test_rvh()->TestOnMsgStartDragging(drop_data); | 159 test_rvh()->TestOnMsgStartDragging(drop_data); |
| 159 EXPECT_EQ(javascript_url, view_delegate.drag_url()); | 160 EXPECT_EQ(javascript_url, view_delegate.drag_url()); |
| 160 EXPECT_EQ(http_url, view_delegate.html_base_url()); | 161 EXPECT_EQ(http_url, view_delegate.html_base_url()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 TEST_F(RenderViewHostTest, DragEnteredFileURLsStillBlocked) { | 164 TEST_F(RenderViewHostTest, DragEnteredFileURLsStillBlocked) { |
| 164 WebDropData dropped_data; | 165 WebDropData dropped_data; |
| 165 gfx::Point client_point; | 166 gfx::Point client_point; |
| 166 gfx::Point screen_point; | 167 gfx::Point screen_point; |
| 167 GURL file_url = GURL("file:///etc/passwd"); | 168 FilePath highlighted_file_path(FILE_PATH_LITERAL("/etc/passwd")); |
| 168 dropped_data.url = file_url; | 169 FilePath selected_file_path(FILE_PATH_LITERAL("/tmp/image.jpg")); |
| 170 GURL highlighted_file_url = net::FilePathToFileURL(highlighted_file_path); |
| 171 GURL selected_file_url = net::FilePathToFileURL(selected_file_path); |
| 172 dropped_data.url = highlighted_file_url; |
| 173 dropped_data.filenames.push_back(WebDropData::FileInfo( |
| 174 UTF8ToUTF16(selected_file_path.AsUTF8Unsafe()), string16())); |
| 175 |
| 169 rvh()->DragTargetDragEnter(dropped_data, client_point, screen_point, | 176 rvh()->DragTargetDragEnter(dropped_data, client_point, screen_point, |
| 170 WebKit::WebDragOperationNone); | 177 WebKit::WebDragOperationNone); |
| 171 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | 178 |
| 172 process()->GetID(), file_url)); | 179 int id = process()->GetID(); |
| 180 ChildProcessSecurityPolicyImpl* policy = |
| 181 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 182 |
| 183 EXPECT_FALSE(policy->CanRequestURL(id, highlighted_file_url)); |
| 184 EXPECT_FALSE(policy->CanReadFile(id, highlighted_file_path)); |
| 185 EXPECT_FALSE(policy->CanRequestURL(id, selected_file_url)); |
| 186 EXPECT_TRUE(policy->CanReadFile(id, selected_file_path)); |
| 173 } | 187 } |
| 174 | 188 |
| 175 // The test that follow trigger DCHECKS in debug build. | 189 // The test that follow trigger DCHECKS in debug build. |
| 176 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 190 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 177 | 191 |
| 178 // Test that when we fail to de-serialize a message, RenderViewHost calls the | 192 // Test that when we fail to de-serialize a message, RenderViewHost calls the |
| 179 // ReceivedBadMessage() handler. | 193 // ReceivedBadMessage() handler. |
| 180 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { | 194 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { |
| 181 EXPECT_EQ(0, process()->bad_msg_count()); | 195 EXPECT_EQ(0, process()->bad_msg_count()); |
| 182 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has | 196 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has |
| (...skipping 23 matching lines...) Expand all Loading... |
| 206 // the code actually expects it to have at least one int para, this this | 220 // the code actually expects it to have at least one int para, this this |
| 207 // bogus message will not fail at de-serialization but should fail in | 221 // bogus message will not fail at de-serialization but should fail in |
| 208 // OnMsgInputEventAck() processing. | 222 // OnMsgInputEventAck() processing. |
| 209 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID, | 223 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID, |
| 210 IPC::Message::PRIORITY_NORMAL); | 224 IPC::Message::PRIORITY_NORMAL); |
| 211 test_rvh()->OnMessageReceived(message); | 225 test_rvh()->OnMessageReceived(message); |
| 212 EXPECT_EQ(1, process()->bad_msg_count()); | 226 EXPECT_EQ(1, process()->bad_msg_count()); |
| 213 } | 227 } |
| 214 | 228 |
| 215 #endif | 229 #endif |
| OLD | NEW |