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 "base/utf_string_conversions.h" |
6 #include "content/browser/child_process_security_policy_impl.h" | 6 #include "content/browser/child_process_security_policy_impl.h" |
7 #include "content/browser/renderer_host/test_render_view_host.h" | 7 #include "content/browser/renderer_host/test_render_view_host.h" |
8 #include "content/browser/web_contents/navigation_controller_impl.h" | 8 #include "content/browser/web_contents/navigation_controller_impl.h" |
9 #include "content/browser/web_contents/test_web_contents.h" | 9 #include "content/browser/web_contents/test_web_contents.h" |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
11 #include "content/port/browser/render_view_host_delegate_view.h" | 11 #include "content/port/browser/render_view_host_delegate_view.h" |
12 #include "content/public/browser/navigation_entry.h" | 12 #include "content/public/browser/navigation_entry.h" |
13 #include "content/public/common/bindings_policy.h" | 13 #include "content/public/common/bindings_policy.h" |
14 #include "content/public/common/page_transition_types.h" | 14 #include "content/public/common/page_transition_types.h" |
15 #include "content/public/test/mock_render_process_host.h" | 15 #include "content/public/test/mock_render_process_host.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" |
18 #include "webkit/glue/webdropdata.h" | 18 #include "webkit/glue/webdropdata.h" |
19 | 19 |
20 using content::RenderViewHostImplTestHarness; | 20 namespace content { |
21 using content::TestWebContents; | |
22 | 21 |
23 class RenderViewHostTest : public RenderViewHostImplTestHarness { | 22 class RenderViewHostTest : public RenderViewHostImplTestHarness { |
24 }; | 23 }; |
25 | 24 |
26 // All about URLs reported by the renderer should get rewritten to about:blank. | 25 // All about URLs reported by the renderer should get rewritten to about:blank. |
27 // See RenderViewHost::OnMsgNavigate for a discussion. | 26 // See RenderViewHost::OnMsgNavigate for a discussion. |
28 TEST_F(RenderViewHostTest, FilterAbout) { | 27 TEST_F(RenderViewHostTest, FilterAbout) { |
29 test_rvh()->SendNavigate(1, GURL("about:cache")); | 28 test_rvh()->SendNavigate(1, GURL("about:cache")); |
30 ASSERT_TRUE(controller().GetActiveEntry()); | 29 ASSERT_TRUE(controller().GetActiveEntry()); |
31 EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->GetURL()); | 30 EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->GetURL()); |
(...skipping 20 matching lines...) Expand all Loading... |
52 // as one on a site that doesn't exist. | 51 // as one on a site that doesn't exist. |
53 // . After this step is_waiting_for_unload_ack_ has been set to true on | 52 // . After this step is_waiting_for_unload_ack_ has been set to true on |
54 // the first RVH. | 53 // the first RVH. |
55 // . click stop before the page has been commited. | 54 // . click stop before the page has been commited. |
56 // . click reload. | 55 // . click reload. |
57 // . is_waiting_for_unload_ack_ is still true, and the if the hang monitor | 56 // . is_waiting_for_unload_ack_ is still true, and the if the hang monitor |
58 // fires the contents gets closed. | 57 // fires the contents gets closed. |
59 | 58 |
60 NavigateAndCommit(url1); | 59 NavigateAndCommit(url1); |
61 controller().LoadURL( | 60 controller().LoadURL( |
62 url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); | 61 url2, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
63 // Simulate the ClosePage call which is normally sent by the net::URLRequest. | 62 // Simulate the ClosePage call which is normally sent by the net::URLRequest. |
64 rvh()->ClosePage(); | 63 rvh()->ClosePage(); |
65 // Needed so that navigations are not suspended on the RVH. | 64 // Needed so that navigations are not suspended on the RVH. |
66 test_rvh()->SendShouldCloseACK(true); | 65 test_rvh()->SendShouldCloseACK(true); |
67 contents()->Stop(); | 66 contents()->Stop(); |
68 controller().Reload(false); | 67 controller().Reload(false); |
69 EXPECT_FALSE(test_rvh()->is_waiting_for_unload_ack_for_testing()); | 68 EXPECT_FALSE(test_rvh()->is_waiting_for_unload_ack_for_testing()); |
70 } | 69 } |
71 | 70 |
72 // Ensure we do not grant bindings to a process shared with unprivileged views. | 71 // Ensure we do not grant bindings to a process shared with unprivileged views. |
73 TEST_F(RenderViewHostTest, DontGrantBindingsToSharedProcess) { | 72 TEST_F(RenderViewHostTest, DontGrantBindingsToSharedProcess) { |
74 // Create another view in the same process. | 73 // Create another view in the same process. |
75 scoped_ptr<TestWebContents> new_web_contents( | 74 scoped_ptr<TestWebContents> new_web_contents( |
76 TestWebContents::Create(browser_context(), rvh()->GetSiteInstance())); | 75 TestWebContents::Create(browser_context(), rvh()->GetSiteInstance())); |
77 | 76 |
78 rvh()->AllowBindings(content::BINDINGS_POLICY_WEB_UI); | 77 rvh()->AllowBindings(BINDINGS_POLICY_WEB_UI); |
79 EXPECT_FALSE(rvh()->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); | 78 EXPECT_FALSE(rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
80 } | 79 } |
81 | 80 |
82 class MockDraggingRenderViewHostDelegateView | 81 class MockDraggingRenderViewHostDelegateView |
83 : public content::RenderViewHostDelegateView { | 82 : public RenderViewHostDelegateView { |
84 public: | 83 public: |
85 virtual ~MockDraggingRenderViewHostDelegateView() {} | 84 virtual ~MockDraggingRenderViewHostDelegateView() {} |
86 virtual void ShowContextMenu( | 85 virtual void ShowContextMenu( |
87 const content::ContextMenuParams& params, | 86 const ContextMenuParams& params, |
88 content::ContextMenuSourceType type) OVERRIDE {} | 87 ContextMenuSourceType type) OVERRIDE {} |
89 virtual void ShowPopupMenu(const gfx::Rect& bounds, | 88 virtual void ShowPopupMenu(const gfx::Rect& bounds, |
90 int item_height, | 89 int item_height, |
91 double item_font_size, | 90 double item_font_size, |
92 int selected_item, | 91 int selected_item, |
93 const std::vector<WebMenuItem>& items, | 92 const std::vector<WebMenuItem>& items, |
94 bool right_aligned, | 93 bool right_aligned, |
95 bool allow_multiple_selection) OVERRIDE {} | 94 bool allow_multiple_selection) OVERRIDE {} |
96 virtual void StartDragging(const WebDropData& drop_data, | 95 virtual void StartDragging(const WebDropData& drop_data, |
97 WebKit::WebDragOperationsMask allowed_ops, | 96 WebKit::WebDragOperationsMask allowed_ops, |
98 const gfx::ImageSkia& image, | 97 const gfx::ImageSkia& image, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // the code actually expects it to have at least one int para, this this | 217 // the code actually expects it to have at least one int para, this this |
219 // bogus message will not fail at de-serialization but should fail in | 218 // bogus message will not fail at de-serialization but should fail in |
220 // OnMsgInputEventAck() processing. | 219 // OnMsgInputEventAck() processing. |
221 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID, | 220 IPC::Message message(0, ViewHostMsg_HandleInputEvent_ACK::ID, |
222 IPC::Message::PRIORITY_NORMAL); | 221 IPC::Message::PRIORITY_NORMAL); |
223 test_rvh()->OnMessageReceived(message); | 222 test_rvh()->OnMessageReceived(message); |
224 EXPECT_EQ(1, process()->bad_msg_count()); | 223 EXPECT_EQ(1, process()->bad_msg_count()); |
225 } | 224 } |
226 | 225 |
227 #endif | 226 #endif |
| 227 |
| 228 } // namespace content |
OLD | NEW |