joi@chromium.org | b0b67cf | 2012-01-18 21:59:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
maruel@chromium.org | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
tsepez@chromium.org | 6136d06 | 2013-05-08 19:31:34 | [diff] [blame] | 5 | #include "base/path_service.h" |
avi@chromium.org | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 6 | #include "base/strings/utf_string_conversions.h" |
ananta@chromium.org | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 7 | #include "content/browser/child_process_security_policy_impl.h" |
jam@chromium.org | 79ea486 | 2011-02-24 00:46:44 | [diff] [blame] | 8 | #include "content/browser/renderer_host/test_render_view_host.h" |
avi@chromium.org | f9e4dae | 2012-04-10 21:26:37 | [diff] [blame] | 9 | #include "content/browser/web_contents/navigation_controller_impl.h" |
jamesr@chromium.org | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 10 | #include "content/common/input_messages.h" |
jam@chromium.org | 1a17826 | 2011-03-23 18:14:18 | [diff] [blame] | 11 | #include "content/common/view_messages.h" |
jam@chromium.org | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 12 | #include "content/port/browser/render_view_host_delegate_view.h" |
jam@chromium.org | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 13 | #include "content/public/browser/navigation_entry.h" |
creis@chromium.org | 8ae9135 | 2012-03-15 17:06:00 | [diff] [blame] | 14 | #include "content/public/common/bindings_policy.h" |
darin@chromium.org | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 15 | #include "content/public/common/drop_data.h" |
jam@chromium.org | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 16 | #include "content/public/common/page_transition_types.h" |
pauljensen@chromium.org | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 17 | #include "content/public/common/url_constants.h" |
jam@chromium.org | 08a932d5 | 2012-06-03 21:42:12 | [diff] [blame] | 18 | #include "content/public/test/mock_render_process_host.h" |
pauljensen@chromium.org | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 19 | #include "content/test/test_content_browser_client.h" |
jam@chromium.org | 4172b08 | 2013-02-25 18:07:34 | [diff] [blame] | 20 | #include "content/test/test_web_contents.h" |
jam@chromium.org | 9d8ea30 | 2012-09-25 15:04:22 | [diff] [blame] | 21 | #include "net/base/net_util.h" |
abarth@chromium.org | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 22 | #include "third_party/WebKit/public/web/WebDragOperation.h" |
maruel@chromium.org | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 23 | |
jam@chromium.org | 1808285 | 2012-10-29 19:35:57 | [diff] [blame] | 24 | namespace content { |
joi@chromium.org | c025738 | 2012-03-12 20:15:34 | [diff] [blame] | 25 | |
pauljensen@chromium.org | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 26 | class RenderViewHostTestBrowserClient : public TestContentBrowserClient { |
| 27 | public: |
| 28 | RenderViewHostTestBrowserClient() {} |
| 29 | virtual ~RenderViewHostTestBrowserClient() {} |
| 30 | |
| 31 | virtual bool IsHandledURL(const GURL& url) OVERRIDE { |
| 32 | return url.scheme() == chrome::kFileScheme; |
| 33 | } |
| 34 | |
| 35 | private: |
| 36 | DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestBrowserClient); |
| 37 | }; |
| 38 | |
joi@chromium.org | c025738 | 2012-03-12 20:15:34 | [diff] [blame] | 39 | class RenderViewHostTest : public RenderViewHostImplTestHarness { |
pauljensen@chromium.org | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 40 | public: |
| 41 | RenderViewHostTest() : old_browser_client_(NULL) {} |
| 42 | virtual ~RenderViewHostTest() {} |
| 43 | |
| 44 | virtual void SetUp() OVERRIDE { |
| 45 | RenderViewHostImplTestHarness::SetUp(); |
| 46 | old_browser_client_ = SetBrowserClientForTesting(&test_browser_client_); |
| 47 | } |
| 48 | |
| 49 | virtual void TearDown() OVERRIDE { |
| 50 | SetBrowserClientForTesting(old_browser_client_); |
| 51 | RenderViewHostImplTestHarness::TearDown(); |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | RenderViewHostTestBrowserClient test_browser_client_; |
| 56 | ContentBrowserClient* old_browser_client_; |
| 57 | |
| 58 | DISALLOW_COPY_AND_ASSIGN(RenderViewHostTest); |
maruel@chromium.org | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | // All about URLs reported by the renderer should get rewritten to about:blank. |
jam@chromium.org | 3d9ec50 | 2013-01-02 22:05:25 | [diff] [blame] | 62 | // See RenderViewHost::OnNavigate for a discussion. |
maruel@chromium.org | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 63 | TEST_F(RenderViewHostTest, FilterAbout) { |
joi@chromium.org | c025738 | 2012-03-12 20:15:34 | [diff] [blame] | 64 | test_rvh()->SendNavigate(1, GURL("about:cache")); |
nasko@chromium.org | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 65 | ASSERT_TRUE(controller().GetVisibleEntry()); |
| 66 | EXPECT_EQ(GURL(kAboutBlankURL), controller().GetVisibleEntry()->GetURL()); |
maruel@chromium.org | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 67 | } |
cpu@google.com | d2fc65d | 2009-07-15 01:36:10 | [diff] [blame] | 68 | |
boliu@chromium.org | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 69 | // Create a full screen popup RenderWidgetHost and View. |
| 70 | TEST_F(RenderViewHostTest, CreateFullscreenWidget) { |
| 71 | int routing_id = process()->GetNextRoutingID(); |
joi@chromium.org | c025738 | 2012-03-12 20:15:34 | [diff] [blame] | 72 | test_rvh()->CreateNewFullscreenWidget(routing_id); |
boliu@chromium.org | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 73 | } |
| 74 | |
sky@chromium.org | d028226 | 2010-08-20 02:52:32 | [diff] [blame] | 75 | // Makes sure that RenderViewHost::is_waiting_for_unload_ack_ is false when |
| 76 | // reloading a page. If is_waiting_for_unload_ack_ is not false when reloading |
avi@chromium.org | adfd280e | 2012-04-13 15:52:39 | [diff] [blame] | 77 | // the contents may get closed out even though the user pressed the reload |
| 78 | // button. |
sky@chromium.org | d028226 | 2010-08-20 02:52:32 | [diff] [blame] | 79 | TEST_F(RenderViewHostTest, ResetUnloadOnReload) { |
| 80 | const GURL url1("http://foo1"); |
| 81 | const GURL url2("http://foo2"); |
| 82 | |
| 83 | // This test is for a subtle timing bug. Here's the sequence that triggered |
| 84 | // the bug: |
| 85 | // . go to a page. |
| 86 | // . go to a new page, preferably one that takes a while to resolve, such |
| 87 | // as one on a site that doesn't exist. |
| 88 | // . After this step is_waiting_for_unload_ack_ has been set to true on |
| 89 | // the first RVH. |
| 90 | // . click stop before the page has been commited. |
| 91 | // . click reload. |
| 92 | // . is_waiting_for_unload_ack_ is still true, and the if the hang monitor |
avi@chromium.org | adfd280e | 2012-04-13 15:52:39 | [diff] [blame] | 93 | // fires the contents gets closed. |
sky@chromium.org | d028226 | 2010-08-20 02:52:32 | [diff] [blame] | 94 | |
| 95 | NavigateAndCommit(url1); |
jam@chromium.org | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 96 | controller().LoadURL( |
jam@chromium.org | 1808285 | 2012-10-29 19:35:57 | [diff] [blame] | 97 | url2, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
tfarina@chromium.org | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 98 | // Simulate the ClosePage call which is normally sent by the net::URLRequest. |
creis@chromium.org | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 99 | rvh()->ClosePage(); |
| 100 | // Needed so that navigations are not suspended on the RVH. |
joi@chromium.org | c025738 | 2012-03-12 20:15:34 | [diff] [blame] | 101 | test_rvh()->SendShouldCloseACK(true); |
sky@chromium.org | d028226 | 2010-08-20 02:52:32 | [diff] [blame] | 102 | contents()->Stop(); |
| 103 | controller().Reload(false); |
creis@chromium.org | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 104 | EXPECT_FALSE(test_rvh()->is_waiting_for_unload_ack()); |
sky@chromium.org | d028226 | 2010-08-20 02:52:32 | [diff] [blame] | 105 | } |
| 106 | |
creis@chromium.org | 8ae9135 | 2012-03-15 17:06:00 | [diff] [blame] | 107 | // Ensure we do not grant bindings to a process shared with unprivileged views. |
| 108 | TEST_F(RenderViewHostTest, DontGrantBindingsToSharedProcess) { |
| 109 | // Create another view in the same process. |
avi@chromium.org | adfd280e | 2012-04-13 15:52:39 | [diff] [blame] | 110 | scoped_ptr<TestWebContents> new_web_contents( |
ajwong@chromium.org | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 111 | TestWebContents::Create(browser_context(), rvh()->GetSiteInstance())); |
creis@chromium.org | 8ae9135 | 2012-03-15 17:06:00 | [diff] [blame] | 112 | |
jam@chromium.org | 1808285 | 2012-10-29 19:35:57 | [diff] [blame] | 113 | rvh()->AllowBindings(BINDINGS_POLICY_WEB_UI); |
| 114 | EXPECT_FALSE(rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
creis@chromium.org | 8ae9135 | 2012-03-15 17:06:00 | [diff] [blame] | 115 | } |
| 116 | |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 117 | class MockDraggingRenderViewHostDelegateView |
jam@chromium.org | 1808285 | 2012-10-29 19:35:57 | [diff] [blame] | 118 | : public RenderViewHostDelegateView { |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 119 | public: |
| 120 | virtual ~MockDraggingRenderViewHostDelegateView() {} |
aruslan@chromium.org | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 121 | virtual void ShowPopupMenu(const gfx::Rect& bounds, |
| 122 | int item_height, |
| 123 | double item_font_size, |
| 124 | int selected_item, |
darin@chromium.org | 54bf995 | 2013-07-17 06:43:20 | [diff] [blame] | 125 | const std::vector<MenuItem>& items, |
aruslan@chromium.org | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 126 | bool right_aligned, |
| 127 | bool allow_multiple_selection) OVERRIDE {} |
darin@chromium.org | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 128 | virtual void StartDragging(const DropData& drop_data, |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 129 | WebKit::WebDragOperationsMask allowed_ops, |
pkotwicz@chromium.org | deb6bb7 | 2012-07-09 20:16:59 | [diff] [blame] | 130 | const gfx::ImageSkia& image, |
varunjain@chromium.org | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 131 | const gfx::Vector2d& image_offset, |
| 132 | const DragEventSourceInfo& event_info) OVERRIDE { |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 133 | drag_url_ = drop_data.url; |
| 134 | html_base_url_ = drop_data.html_base_url; |
| 135 | } |
aruslan@chromium.org | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 136 | virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE {} |
| 137 | virtual void GotFocus() OVERRIDE {} |
| 138 | virtual void TakeFocus(bool reverse) OVERRIDE {} |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 139 | virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} |
| 140 | |
| 141 | GURL drag_url() { |
| 142 | return drag_url_; |
| 143 | } |
| 144 | |
| 145 | GURL html_base_url() { |
| 146 | return html_base_url_; |
| 147 | } |
| 148 | |
| 149 | private: |
| 150 | GURL drag_url_; |
| 151 | GURL html_base_url_; |
| 152 | }; |
| 153 | |
| 154 | TEST_F(RenderViewHostTest, StartDragging) { |
joi@chromium.org | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 155 | TestWebContents* web_contents = contents(); |
jam@chromium.org | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 156 | MockDraggingRenderViewHostDelegateView delegate_view; |
| 157 | web_contents->set_delegate_view(&delegate_view); |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 158 | |
darin@chromium.org | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 159 | DropData drop_data; |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 160 | GURL file_url = GURL("file:///home/user/secrets.txt"); |
| 161 | drop_data.url = file_url; |
| 162 | drop_data.html_base_url = file_url; |
jam@chromium.org | 3d9ec50 | 2013-01-02 22:05:25 | [diff] [blame] | 163 | test_rvh()->TestOnStartDragging(drop_data); |
thestig@chromium.org | 685c8af | 2013-08-06 03:10:15 | [diff] [blame] | 164 | EXPECT_EQ(GURL(kAboutBlankURL), delegate_view.drag_url()); |
| 165 | EXPECT_EQ(GURL(kAboutBlankURL), delegate_view.html_base_url()); |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 166 | |
| 167 | GURL http_url = GURL("http://www.domain.com/index.html"); |
| 168 | drop_data.url = http_url; |
| 169 | drop_data.html_base_url = http_url; |
jam@chromium.org | 3d9ec50 | 2013-01-02 22:05:25 | [diff] [blame] | 170 | test_rvh()->TestOnStartDragging(drop_data); |
jam@chromium.org | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 171 | EXPECT_EQ(http_url, delegate_view.drag_url()); |
| 172 | EXPECT_EQ(http_url, delegate_view.html_base_url()); |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 173 | |
| 174 | GURL https_url = GURL("https://www.domain.com/index.html"); |
| 175 | drop_data.url = https_url; |
| 176 | drop_data.html_base_url = https_url; |
jam@chromium.org | 3d9ec50 | 2013-01-02 22:05:25 | [diff] [blame] | 177 | test_rvh()->TestOnStartDragging(drop_data); |
jam@chromium.org | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 178 | EXPECT_EQ(https_url, delegate_view.drag_url()); |
| 179 | EXPECT_EQ(https_url, delegate_view.html_base_url()); |
maf@chromium.org | d36ccf5 | 2011-06-22 00:23:48 | [diff] [blame] | 180 | |
| 181 | GURL javascript_url = GURL("javascript:alert('I am a bookmarklet')"); |
| 182 | drop_data.url = javascript_url; |
| 183 | drop_data.html_base_url = http_url; |
jam@chromium.org | 3d9ec50 | 2013-01-02 22:05:25 | [diff] [blame] | 184 | test_rvh()->TestOnStartDragging(drop_data); |
jam@chromium.org | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 185 | EXPECT_EQ(javascript_url, delegate_view.drag_url()); |
| 186 | EXPECT_EQ(http_url, delegate_view.html_base_url()); |
tony@chromium.org | 8c4575b | 2011-06-07 21:11:03 | [diff] [blame] | 187 | } |
| 188 | |
tsepez@chromium.org | c80ed0f | 2012-02-03 19:37:23 | [diff] [blame] | 189 | TEST_F(RenderViewHostTest, DragEnteredFileURLsStillBlocked) { |
darin@chromium.org | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 190 | DropData dropped_data; |
tsepez@chromium.org | c80ed0f | 2012-02-03 19:37:23 | [diff] [blame] | 191 | gfx::Point client_point; |
| 192 | gfx::Point screen_point; |
kinuko@chromium.org | 03f3997 | 2012-06-26 14:50:27 | [diff] [blame] | 193 | // We use "//foo/bar" path (rather than "/foo/bar") since dragged paths are |
| 194 | // expected to be absolute on any platforms. |
brettw@chromium.org | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 195 | base::FilePath highlighted_file_path(FILE_PATH_LITERAL("//tmp/foo.html")); |
| 196 | base::FilePath dragged_file_path(FILE_PATH_LITERAL("//tmp/image.jpg")); |
| 197 | base::FilePath sensitive_file_path(FILE_PATH_LITERAL("//etc/passwd")); |
tsepez@chromium.org | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 198 | GURL highlighted_file_url = net::FilePathToFileURL(highlighted_file_path); |
| 199 | GURL dragged_file_url = net::FilePathToFileURL(dragged_file_path); |
| 200 | GURL sensitive_file_url = net::FilePathToFileURL(sensitive_file_path); |
| 201 | dropped_data.url = highlighted_file_url; |
ajwong@chromium.org | ef1bbf63 | 2013-10-24 22:54:08 | [diff] [blame] | 202 | dropped_data.filenames.push_back(DropData::FileInfo( |
| 203 | UTF8ToUTF16(dragged_file_path.AsUTF8Unsafe()), string16())); |
tsepez@chromium.org | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 204 | |
tsepez@chromium.org | c80ed0f | 2012-02-03 19:37:23 | [diff] [blame] | 205 | rvh()->DragTargetDragEnter(dropped_data, client_point, screen_point, |
tsepez@chromium.org | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 206 | WebKit::WebDragOperationNone, 0); |
| 207 | |
| 208 | int id = process()->GetID(); |
| 209 | ChildProcessSecurityPolicyImpl* policy = |
| 210 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 211 | |
| 212 | EXPECT_FALSE(policy->CanRequestURL(id, highlighted_file_url)); |
| 213 | EXPECT_FALSE(policy->CanReadFile(id, highlighted_file_path)); |
| 214 | EXPECT_TRUE(policy->CanRequestURL(id, dragged_file_url)); |
| 215 | EXPECT_TRUE(policy->CanReadFile(id, dragged_file_path)); |
| 216 | EXPECT_FALSE(policy->CanRequestURL(id, sensitive_file_url)); |
| 217 | EXPECT_FALSE(policy->CanReadFile(id, sensitive_file_path)); |
tsepez@chromium.org | c80ed0f | 2012-02-03 19:37:23 | [diff] [blame] | 218 | } |
| 219 | |
cpu@google.com | d2fc65d | 2009-07-15 01:36:10 | [diff] [blame] | 220 | // The test that follow trigger DCHECKS in debug build. |
nsylvain@chromium.org | 20960e07 | 2011-09-20 20:59:01 | [diff] [blame] | 221 | #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
cpu@google.com | d2fc65d | 2009-07-15 01:36:10 | [diff] [blame] | 222 | |
| 223 | // Test that when we fail to de-serialize a message, RenderViewHost calls the |
| 224 | // ReceivedBadMessage() handler. |
| 225 | TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { |
| 226 | EXPECT_EQ(0, process()->bad_msg_count()); |
| 227 | // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has |
| 228 | // two payload items but the one we construct has none. |
| 229 | IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID, |
| 230 | IPC::Message::PRIORITY_NORMAL); |
joi@chromium.org | 446c1a30 | 2012-03-22 19:05:05 | [diff] [blame] | 231 | test_rvh()->OnMessageReceived(message); |
cpu@google.com | d2fc65d | 2009-07-15 01:36:10 | [diff] [blame] | 232 | EXPECT_EQ(1, process()->bad_msg_count()); |
| 233 | } |
| 234 | |
| 235 | // Test that when we fail to de-serialize a message, RenderWidgetHost calls the |
| 236 | // ReceivedBadMessage() handler. |
| 237 | TEST_F(RenderViewHostTest, BadMessageHandlerRenderWidgetHost) { |
| 238 | EXPECT_EQ(0, process()->bad_msg_count()); |
darin@chromium.org | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 239 | // craft an incorrect ViewHostMsg_UpdateRect message. The real one has |
cpu@google.com | d2fc65d | 2009-07-15 01:36:10 | [diff] [blame] | 240 | // one payload item but the one we construct has none. |
darin@chromium.org | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 241 | IPC::Message message(0, ViewHostMsg_UpdateRect::ID, |
cpu@google.com | d2fc65d | 2009-07-15 01:36:10 | [diff] [blame] | 242 | IPC::Message::PRIORITY_NORMAL); |
joi@chromium.org | 446c1a30 | 2012-03-22 19:05:05 | [diff] [blame] | 243 | test_rvh()->OnMessageReceived(message); |
cpu@google.com | d2fc65d | 2009-07-15 01:36:10 | [diff] [blame] | 244 | EXPECT_EQ(1, process()->bad_msg_count()); |
| 245 | } |
| 246 | |
jam@chromium.org | 3d9ec50 | 2013-01-02 22:05:25 | [diff] [blame] | 247 | // Test that OnInputEventAck() detects bad messages. |
cpu@google.com | 8faa5a1 | 2009-07-17 17:17:43 | [diff] [blame] | 248 | TEST_F(RenderViewHostTest, BadMessageHandlerInputEventAck) { |
| 249 | EXPECT_EQ(0, process()->bad_msg_count()); |
jamesr@chromium.org | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 250 | // InputHostMsg_HandleInputEvent_ACK is defined taking 0 params but |
cpu@google.com | 8faa5a1 | 2009-07-17 17:17:43 | [diff] [blame] | 251 | // the code actually expects it to have at least one int para, this this |
| 252 | // bogus message will not fail at de-serialization but should fail in |
jam@chromium.org | 3d9ec50 | 2013-01-02 22:05:25 | [diff] [blame] | 253 | // OnInputEventAck() processing. |
jamesr@chromium.org | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 254 | IPC::Message message(0, InputHostMsg_HandleInputEvent_ACK::ID, |
cpu@google.com | 8faa5a1 | 2009-07-17 17:17:43 | [diff] [blame] | 255 | IPC::Message::PRIORITY_NORMAL); |
joi@chromium.org | 446c1a30 | 2012-03-22 19:05:05 | [diff] [blame] | 256 | test_rvh()->OnMessageReceived(message); |
cpu@google.com | 8faa5a1 | 2009-07-17 17:17:43 | [diff] [blame] | 257 | EXPECT_EQ(1, process()->bad_msg_count()); |
| 258 | } |
| 259 | |
nsylvain@chromium.org | 20960e07 | 2011-09-20 20:59:01 | [diff] [blame] | 260 | #endif |
jam@chromium.org | 1808285 | 2012-10-29 19:35:57 | [diff] [blame] | 261 | |
tsepez@chromium.org | 6136d06 | 2013-05-08 19:31:34 | [diff] [blame] | 262 | TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) { |
| 263 | base::FilePath file_path; |
| 264 | EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); |
| 265 | file_path = file_path.AppendASCII("foo"); |
| 266 | EXPECT_EQ(0, process()->bad_msg_count()); |
| 267 | test_rvh()->TestOnUpdateStateWithFile(process()->GetID(), file_path); |
| 268 | EXPECT_EQ(1, process()->bad_msg_count()); |
| 269 | |
gbillock@chromium.org | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 270 | ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| 271 | process()->GetID(), file_path); |
tsepez@chromium.org | 6136d06 | 2013-05-08 19:31:34 | [diff] [blame] | 272 | test_rvh()->TestOnUpdateStateWithFile(process()->GetID(), file_path); |
| 273 | EXPECT_EQ(1, process()->bad_msg_count()); |
| 274 | } |
| 275 | |
| 276 | TEST_F(RenderViewHostTest, NavigationWithBadHistoryItemFiles) { |
| 277 | GURL url("http://www.google.com"); |
| 278 | base::FilePath file_path; |
| 279 | EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); |
| 280 | file_path = file_path.AppendASCII("bar"); |
| 281 | EXPECT_EQ(0, process()->bad_msg_count()); |
| 282 | test_rvh()->SendNavigateWithFile(1, url, file_path); |
| 283 | EXPECT_EQ(1, process()->bad_msg_count()); |
| 284 | |
gbillock@chromium.org | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 285 | ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| 286 | process()->GetID(), file_path); |
tsepez@chromium.org | 6136d06 | 2013-05-08 19:31:34 | [diff] [blame] | 287 | test_rvh()->SendNavigateWithFile(process()->GetID(), url, file_path); |
| 288 | EXPECT_EQ(1, process()->bad_msg_count()); |
| 289 | } |
| 290 | |
ajwong@chromium.org | 1c2052f | 2013-08-28 08:24:34 | [diff] [blame] | 291 | TEST_F(RenderViewHostTest, RoutingIdSane) { |
| 292 | EXPECT_EQ(test_rvh()->GetProcess(), |
| 293 | test_rvh()->main_render_frame_host()->GetProcess()); |
| 294 | EXPECT_NE(test_rvh()->GetRoutingID(), |
| 295 | test_rvh()->main_render_frame_host()->routing_id()); |
| 296 | } |
| 297 | |
jam@chromium.org | 1808285 | 2012-10-29 19:35:57 | [diff] [blame] | 298 | } // namespace content |