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 "content/browser/child_process_security_policy_impl.h" | 5 #include "content/browser/child_process_security_policy_impl.h" |
| 6 #include "content/browser/renderer_host/mock_render_process_host.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/tab_contents/navigation_controller_impl.h" | 8 #include "content/browser/tab_contents/navigation_controller_impl.h" |
8 #include "content/browser/tab_contents/test_tab_contents.h" | 9 #include "content/browser/tab_contents/test_tab_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/page_transition_types.h" | 12 #include "content/public/common/page_transition_types.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" |
13 #include "webkit/glue/webdropdata.h" | 14 #include "webkit/glue/webdropdata.h" |
14 | 15 |
15 class RenderViewHostTest : public RenderViewHostTestHarness { | 16 using content::RenderViewHostImplTestHarness; |
| 17 |
| 18 class RenderViewHostTest : public RenderViewHostImplTestHarness { |
16 }; | 19 }; |
17 | 20 |
18 // All about URLs reported by the renderer should get rewritten to about:blank. | 21 // All about URLs reported by the renderer should get rewritten to about:blank. |
19 // See RenderViewHost::OnMsgNavigate for a discussion. | 22 // See RenderViewHost::OnMsgNavigate for a discussion. |
20 TEST_F(RenderViewHostTest, FilterAbout) { | 23 TEST_F(RenderViewHostTest, FilterAbout) { |
21 rvh()->SendNavigate(1, GURL("about:cache")); | 24 test_rvh()->SendNavigate(1, GURL("about:cache")); |
22 ASSERT_TRUE(controller().GetActiveEntry()); | 25 ASSERT_TRUE(controller().GetActiveEntry()); |
23 EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->GetURL()); | 26 EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->GetURL()); |
24 } | 27 } |
25 | 28 |
26 // Create a full screen popup RenderWidgetHost and View. | 29 // Create a full screen popup RenderWidgetHost and View. |
27 TEST_F(RenderViewHostTest, CreateFullscreenWidget) { | 30 TEST_F(RenderViewHostTest, CreateFullscreenWidget) { |
28 int routing_id = process()->GetNextRoutingID(); | 31 int routing_id = process()->GetNextRoutingID(); |
29 rvh()->CreateNewFullscreenWidget(routing_id); | 32 test_rvh()->CreateNewFullscreenWidget(routing_id); |
30 } | 33 } |
31 | 34 |
32 // Makes sure that RenderViewHost::is_waiting_for_unload_ack_ is false when | 35 // Makes sure that RenderViewHost::is_waiting_for_unload_ack_ is false when |
33 // reloading a page. If is_waiting_for_unload_ack_ is not false when reloading | 36 // reloading a page. If is_waiting_for_unload_ack_ is not false when reloading |
34 // the tab may get closed out even though the user pressed the reload button. | 37 // the tab may get closed out even though the user pressed the reload button. |
35 TEST_F(RenderViewHostTest, ResetUnloadOnReload) { | 38 TEST_F(RenderViewHostTest, ResetUnloadOnReload) { |
36 const GURL url1("http://foo1"); | 39 const GURL url1("http://foo1"); |
37 const GURL url2("http://foo2"); | 40 const GURL url2("http://foo2"); |
38 | 41 |
39 // This test is for a subtle timing bug. Here's the sequence that triggered | 42 // This test is for a subtle timing bug. Here's the sequence that triggered |
40 // the bug: | 43 // the bug: |
41 // . go to a page. | 44 // . go to a page. |
42 // . go to a new page, preferably one that takes a while to resolve, such | 45 // . go to a new page, preferably one that takes a while to resolve, such |
43 // as one on a site that doesn't exist. | 46 // as one on a site that doesn't exist. |
44 // . After this step is_waiting_for_unload_ack_ has been set to true on | 47 // . After this step is_waiting_for_unload_ack_ has been set to true on |
45 // the first RVH. | 48 // the first RVH. |
46 // . click stop before the page has been commited. | 49 // . click stop before the page has been commited. |
47 // . click reload. | 50 // . click reload. |
48 // . is_waiting_for_unload_ack_ is still true, and the if the hang monitor | 51 // . is_waiting_for_unload_ack_ is still true, and the if the hang monitor |
49 // fires the tab gets closed. | 52 // fires the tab gets closed. |
50 | 53 |
51 NavigateAndCommit(url1); | 54 NavigateAndCommit(url1); |
52 controller().LoadURL( | 55 controller().LoadURL( |
53 url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); | 56 url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
54 // Simulate the ClosePage call which is normally sent by the net::URLRequest. | 57 // Simulate the ClosePage call which is normally sent by the net::URLRequest. |
55 rvh()->ClosePage(); | 58 rvh()->ClosePage(); |
56 // Needed so that navigations are not suspended on the RVH. | 59 // Needed so that navigations are not suspended on the RVH. |
57 rvh()->SendShouldCloseACK(true); | 60 test_rvh()->SendShouldCloseACK(true); |
58 contents()->Stop(); | 61 contents()->Stop(); |
59 controller().Reload(false); | 62 controller().Reload(false); |
60 EXPECT_FALSE(rvh()->is_waiting_for_unload_ack_for_testing()); | 63 EXPECT_FALSE(test_rvh()->is_waiting_for_unload_ack_for_testing()); |
61 } | 64 } |
62 | 65 |
63 class MockDraggingRenderViewHostDelegateView | 66 class MockDraggingRenderViewHostDelegateView |
64 : public content::RenderViewHostDelegate::View { | 67 : public content::RenderViewHostDelegate::View { |
65 public: | 68 public: |
66 virtual ~MockDraggingRenderViewHostDelegateView() {} | 69 virtual ~MockDraggingRenderViewHostDelegateView() {} |
67 virtual void CreateNewWindow( | 70 virtual void CreateNewWindow( |
68 int route_id, | 71 int route_id, |
69 const ViewHostMsg_CreateWindow_Params& params) {} | 72 const ViewHostMsg_CreateWindow_Params& params) {} |
70 virtual void CreateNewWidget(int route_id, | 73 virtual void CreateNewWidget(int route_id, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 114 |
112 TEST_F(RenderViewHostTest, StartDragging) { | 115 TEST_F(RenderViewHostTest, StartDragging) { |
113 TestTabContents* tab_contents = contents(); | 116 TestTabContents* tab_contents = contents(); |
114 MockDraggingRenderViewHostDelegateView view_delegate; | 117 MockDraggingRenderViewHostDelegateView view_delegate; |
115 tab_contents->set_view_delegate(&view_delegate); | 118 tab_contents->set_view_delegate(&view_delegate); |
116 | 119 |
117 WebDropData drop_data; | 120 WebDropData drop_data; |
118 GURL file_url = GURL("file:///home/user/secrets.txt"); | 121 GURL file_url = GURL("file:///home/user/secrets.txt"); |
119 drop_data.url = file_url; | 122 drop_data.url = file_url; |
120 drop_data.html_base_url = file_url; | 123 drop_data.html_base_url = file_url; |
121 rvh()->TestOnMsgStartDragging(drop_data); | 124 test_rvh()->TestOnMsgStartDragging(drop_data); |
122 EXPECT_TRUE(view_delegate.drag_url().is_empty()); | 125 EXPECT_TRUE(view_delegate.drag_url().is_empty()); |
123 EXPECT_TRUE(view_delegate.html_base_url().is_empty()); | 126 EXPECT_TRUE(view_delegate.html_base_url().is_empty()); |
124 | 127 |
125 GURL http_url = GURL("http://www.domain.com/index.html"); | 128 GURL http_url = GURL("http://www.domain.com/index.html"); |
126 drop_data.url = http_url; | 129 drop_data.url = http_url; |
127 drop_data.html_base_url = http_url; | 130 drop_data.html_base_url = http_url; |
128 rvh()->TestOnMsgStartDragging(drop_data); | 131 test_rvh()->TestOnMsgStartDragging(drop_data); |
129 EXPECT_EQ(http_url, view_delegate.drag_url()); | 132 EXPECT_EQ(http_url, view_delegate.drag_url()); |
130 EXPECT_EQ(http_url, view_delegate.html_base_url()); | 133 EXPECT_EQ(http_url, view_delegate.html_base_url()); |
131 | 134 |
132 GURL https_url = GURL("https://www.domain.com/index.html"); | 135 GURL https_url = GURL("https://www.domain.com/index.html"); |
133 drop_data.url = https_url; | 136 drop_data.url = https_url; |
134 drop_data.html_base_url = https_url; | 137 drop_data.html_base_url = https_url; |
135 rvh()->TestOnMsgStartDragging(drop_data); | 138 test_rvh()->TestOnMsgStartDragging(drop_data); |
136 EXPECT_EQ(https_url, view_delegate.drag_url()); | 139 EXPECT_EQ(https_url, view_delegate.drag_url()); |
137 EXPECT_EQ(https_url, view_delegate.html_base_url()); | 140 EXPECT_EQ(https_url, view_delegate.html_base_url()); |
138 | 141 |
139 GURL javascript_url = GURL("javascript:alert('I am a bookmarklet')"); | 142 GURL javascript_url = GURL("javascript:alert('I am a bookmarklet')"); |
140 drop_data.url = javascript_url; | 143 drop_data.url = javascript_url; |
141 drop_data.html_base_url = http_url; | 144 drop_data.html_base_url = http_url; |
142 rvh()->TestOnMsgStartDragging(drop_data); | 145 test_rvh()->TestOnMsgStartDragging(drop_data); |
143 EXPECT_EQ(javascript_url, view_delegate.drag_url()); | 146 EXPECT_EQ(javascript_url, view_delegate.drag_url()); |
144 EXPECT_EQ(http_url, view_delegate.html_base_url()); | 147 EXPECT_EQ(http_url, view_delegate.html_base_url()); |
145 } | 148 } |
146 | 149 |
147 TEST_F(RenderViewHostTest, DragEnteredFileURLsStillBlocked) { | 150 TEST_F(RenderViewHostTest, DragEnteredFileURLsStillBlocked) { |
148 WebDropData dropped_data; | 151 WebDropData dropped_data; |
149 gfx::Point client_point; | 152 gfx::Point client_point; |
150 gfx::Point screen_point; | 153 gfx::Point screen_point; |
151 GURL file_url = GURL("file:///etc/passwd"); | 154 GURL file_url = GURL("file:///etc/passwd"); |
152 dropped_data.url = file_url; | 155 dropped_data.url = file_url; |
153 rvh()->DragTargetDragEnter(dropped_data, client_point, screen_point, | 156 rvh()->DragTargetDragEnter(dropped_data, client_point, screen_point, |
154 WebKit::WebDragOperationNone); | 157 WebKit::WebDragOperationNone); |
155 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | 158 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( |
156 process()->GetID(), file_url)); | 159 process()->GetID(), file_url)); |
157 } | 160 } |
158 | 161 |
159 // The test that follow trigger DCHECKS in debug build. | 162 // The test that follow trigger DCHECKS in debug build. |
160 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 163 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
161 | 164 |
162 // Test that when we fail to de-serialize a message, RenderViewHost calls the | 165 // Test that when we fail to de-serialize a message, RenderViewHost calls the |
163 // ReceivedBadMessage() handler. | 166 // ReceivedBadMessage() handler. |
164 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { | 167 TEST_F(RenderViewHostTest, BadMessageHandlerRenderViewHost) { |
165 EXPECT_EQ(0, process()->bad_msg_count()); | 168 EXPECT_EQ(0, process()->bad_msg_count()); |
166 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has | 169 // craft an incorrect ViewHostMsg_UpdateTargetURL message. The real one has |
167 // two payload items but the one we construct has none. | 170 // two payload items but the one we construct has none. |
168 IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID, | 171 IPC::Message message(0, ViewHostMsg_UpdateTargetURL::ID, |
169 IPC::Message::PRIORITY_NORMAL); | 172 IPC::Message::PRIORITY_NORMAL); |
170 rvh()->TestOnMessageReceived(message); | 173 test_rvh()->TestOnMessageReceived(message); |
171 EXPECT_EQ(1, process()->bad_msg_count()); | 174 EXPECT_EQ(1, process()->bad_msg_count()); |
172 } | 175 } |
173 | 176 |
174 // Test that when we fail to de-serialize a message, RenderWidgetHost calls the | 177 // Test that when we fail to de-serialize a message, RenderWidgetHost calls the |
175 // ReceivedBadMessage() handler. | 178 // ReceivedBadMessage() handler. |
176 TEST_F(RenderViewHostTest, BadMessageHandlerRenderWidgetHost) { | 179 TEST_F(RenderViewHostTest, BadMessageHandlerRenderWidgetHost) { |
177 EXPECT_EQ(0, process()->bad_msg_count()); | 180 EXPECT_EQ(0, process()->bad_msg_count()); |
178 // craft an incorrect ViewHostMsg_UpdateRect message. The real one has | 181 // craft an incorrect ViewHostMsg_UpdateRect message. The real one has |
179 // one payload item but the one we construct has none. | 182 // one payload item but the one we construct has none. |
180 IPC::Message message(0, ViewHostMsg_UpdateRect::ID, | 183 IPC::Message message(0, ViewHostMsg_UpdateRect::ID, |
181 IPC::Message::PRIORITY_NORMAL); | 184 IPC::Message::PRIORITY_NORMAL); |
182 rvh()->TestOnMessageReceived(message); | 185 test_rvh()->TestOnMessageReceived(message); |
183 EXPECT_EQ(1, process()->bad_msg_count()); | 186 EXPECT_EQ(1, process()->bad_msg_count()); |
184 } | 187 } |
185 | 188 |
186 // Test that OnMsgInputEventAck() detects bad messages. | 189 // Test that OnMsgInputEventAck() detects bad messages. |
187 TEST_F(RenderViewHostTest, BadMessageHandlerInputEventAck) { | 190 TEST_F(RenderViewHostTest, BadMessageHandlerInputEventAck) { |
188 EXPECT_EQ(0, process()->bad_msg_count()); | 191 EXPECT_EQ(0, process()->bad_msg_count()); |
189 // ViewHostMsg_HandleInputEvent_ACK is defined taking 0 params but | 192 // ViewHostMsg_HandleInputEvent_ACK is defined taking 0 params but |
190 // the code actually expects it to have at least one int para, this this | 193 // the code actually expects it to have at least one int para, this this |
191 // bogus message will not fail at de-serialization but should fail in | 194 // bogus message will not fail at de-serialization but should fail in |
192 // OnMsgInputEventAck() processing. | 195 // OnMsgInputEventAck() processing. |
193 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID, | 196 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID, |
194 IPC::Message::PRIORITY_NORMAL); | 197 IPC::Message::PRIORITY_NORMAL); |
195 rvh()->TestOnMessageReceived(message); | 198 test_rvh()->TestOnMessageReceived(message); |
196 EXPECT_EQ(1, process()->bad_msg_count()); | 199 EXPECT_EQ(1, process()->bad_msg_count()); |
197 } | 200 } |
198 | 201 |
199 #endif | 202 #endif |
OLD | NEW |