Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Side by Side Diff: content/browser/renderer_host/render_view_host_unittest.cc

Issue 18281002: Move WebDropData to content::DropData and split off conversion function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac build error. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/web_contents/navigation_controller_impl.h" 9 #include "content/browser/web_contents/navigation_controller_impl.h"
10 #include "content/common/input_messages.h" 10 #include "content/common/input_messages.h"
11 #include "content/common/view_messages.h" 11 #include "content/common/view_messages.h"
12 #include "content/port/browser/render_view_host_delegate_view.h" 12 #include "content/port/browser/render_view_host_delegate_view.h"
13 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/common/bindings_policy.h" 14 #include "content/public/common/bindings_policy.h"
15 #include "content/public/common/drop_data.h"
15 #include "content/public/common/page_transition_types.h" 16 #include "content/public/common/page_transition_types.h"
16 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
17 #include "content/public/test/mock_render_process_host.h" 18 #include "content/public/test/mock_render_process_host.h"
18 #include "content/test/test_content_browser_client.h" 19 #include "content/test/test_content_browser_client.h"
19 #include "content/test/test_web_contents.h" 20 #include "content/test/test_web_contents.h"
20 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
21 #include "third_party/WebKit/public/web/WebDragOperation.h" 22 #include "third_party/WebKit/public/web/WebDragOperation.h"
22 #include "webkit/common/webdropdata.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 class RenderViewHostTestBrowserClient : public TestContentBrowserClient { 26 class RenderViewHostTestBrowserClient : public TestContentBrowserClient {
27 public: 27 public:
28 RenderViewHostTestBrowserClient() {} 28 RenderViewHostTestBrowserClient() {}
29 virtual ~RenderViewHostTestBrowserClient() {} 29 virtual ~RenderViewHostTestBrowserClient() {}
30 30
31 virtual bool IsHandledURL(const GURL& url) OVERRIDE { 31 virtual bool IsHandledURL(const GURL& url) OVERRIDE {
32 return url.scheme() == chrome::kFileScheme; 32 return url.scheme() == chrome::kFileScheme;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 : public RenderViewHostDelegateView { 118 : public RenderViewHostDelegateView {
119 public: 119 public:
120 virtual ~MockDraggingRenderViewHostDelegateView() {} 120 virtual ~MockDraggingRenderViewHostDelegateView() {}
121 virtual void ShowPopupMenu(const gfx::Rect& bounds, 121 virtual void ShowPopupMenu(const gfx::Rect& bounds,
122 int item_height, 122 int item_height,
123 double item_font_size, 123 double item_font_size,
124 int selected_item, 124 int selected_item,
125 const std::vector<WebMenuItem>& items, 125 const std::vector<WebMenuItem>& items,
126 bool right_aligned, 126 bool right_aligned,
127 bool allow_multiple_selection) OVERRIDE {} 127 bool allow_multiple_selection) OVERRIDE {}
128 virtual void StartDragging(const WebDropData& drop_data, 128 virtual void StartDragging(const DropData& drop_data,
129 WebKit::WebDragOperationsMask allowed_ops, 129 WebKit::WebDragOperationsMask allowed_ops,
130 const gfx::ImageSkia& image, 130 const gfx::ImageSkia& image,
131 const gfx::Vector2d& image_offset, 131 const gfx::Vector2d& image_offset,
132 const DragEventSourceInfo& event_info) OVERRIDE { 132 const DragEventSourceInfo& event_info) OVERRIDE {
133 drag_url_ = drop_data.url; 133 drag_url_ = drop_data.url;
134 html_base_url_ = drop_data.html_base_url; 134 html_base_url_ = drop_data.html_base_url;
135 } 135 }
136 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE {} 136 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE {}
137 virtual void GotFocus() OVERRIDE {} 137 virtual void GotFocus() OVERRIDE {}
138 virtual void TakeFocus(bool reverse) OVERRIDE {} 138 virtual void TakeFocus(bool reverse) OVERRIDE {}
(...skipping 10 matching lines...) Expand all
149 private: 149 private:
150 GURL drag_url_; 150 GURL drag_url_;
151 GURL html_base_url_; 151 GURL html_base_url_;
152 }; 152 };
153 153
154 TEST_F(RenderViewHostTest, StartDragging) { 154 TEST_F(RenderViewHostTest, StartDragging) {
155 TestWebContents* web_contents = contents(); 155 TestWebContents* web_contents = contents();
156 MockDraggingRenderViewHostDelegateView delegate_view; 156 MockDraggingRenderViewHostDelegateView delegate_view;
157 web_contents->set_delegate_view(&delegate_view); 157 web_contents->set_delegate_view(&delegate_view);
158 158
159 WebDropData drop_data; 159 DropData drop_data;
160 GURL file_url = GURL("file:///home/user/secrets.txt"); 160 GURL file_url = GURL("file:///home/user/secrets.txt");
161 drop_data.url = file_url; 161 drop_data.url = file_url;
162 drop_data.html_base_url = file_url; 162 drop_data.html_base_url = file_url;
163 test_rvh()->TestOnStartDragging(drop_data); 163 test_rvh()->TestOnStartDragging(drop_data);
164 EXPECT_EQ(GURL("about:blank"), delegate_view.drag_url()); 164 EXPECT_EQ(GURL("about:blank"), delegate_view.drag_url());
165 EXPECT_EQ(GURL("about:blank"), delegate_view.html_base_url()); 165 EXPECT_EQ(GURL("about:blank"), delegate_view.html_base_url());
166 166
167 GURL http_url = GURL("http://www.domain.com/index.html"); 167 GURL http_url = GURL("http://www.domain.com/index.html");
168 drop_data.url = http_url; 168 drop_data.url = http_url;
169 drop_data.html_base_url = http_url; 169 drop_data.html_base_url = http_url;
(...skipping 10 matching lines...) Expand all
180 180
181 GURL javascript_url = GURL("javascript:alert('I am a bookmarklet')"); 181 GURL javascript_url = GURL("javascript:alert('I am a bookmarklet')");
182 drop_data.url = javascript_url; 182 drop_data.url = javascript_url;
183 drop_data.html_base_url = http_url; 183 drop_data.html_base_url = http_url;
184 test_rvh()->TestOnStartDragging(drop_data); 184 test_rvh()->TestOnStartDragging(drop_data);
185 EXPECT_EQ(javascript_url, delegate_view.drag_url()); 185 EXPECT_EQ(javascript_url, delegate_view.drag_url());
186 EXPECT_EQ(http_url, delegate_view.html_base_url()); 186 EXPECT_EQ(http_url, delegate_view.html_base_url());
187 } 187 }
188 188
189 TEST_F(RenderViewHostTest, DragEnteredFileURLsStillBlocked) { 189 TEST_F(RenderViewHostTest, DragEnteredFileURLsStillBlocked) {
190 WebDropData dropped_data; 190 DropData dropped_data;
191 gfx::Point client_point; 191 gfx::Point client_point;
192 gfx::Point screen_point; 192 gfx::Point screen_point;
193 // We use "//foo/bar" path (rather than "/foo/bar") since dragged paths are 193 // We use "//foo/bar" path (rather than "/foo/bar") since dragged paths are
194 // expected to be absolute on any platforms. 194 // expected to be absolute on any platforms.
195 base::FilePath highlighted_file_path(FILE_PATH_LITERAL("//tmp/foo.html")); 195 base::FilePath highlighted_file_path(FILE_PATH_LITERAL("//tmp/foo.html"));
196 base::FilePath dragged_file_path(FILE_PATH_LITERAL("//tmp/image.jpg")); 196 base::FilePath dragged_file_path(FILE_PATH_LITERAL("//tmp/image.jpg"));
197 base::FilePath sensitive_file_path(FILE_PATH_LITERAL("//etc/passwd")); 197 base::FilePath sensitive_file_path(FILE_PATH_LITERAL("//etc/passwd"));
198 GURL highlighted_file_url = net::FilePathToFileURL(highlighted_file_path); 198 GURL highlighted_file_url = net::FilePathToFileURL(highlighted_file_path);
199 GURL dragged_file_url = net::FilePathToFileURL(dragged_file_path); 199 GURL dragged_file_url = net::FilePathToFileURL(dragged_file_path);
200 GURL sensitive_file_url = net::FilePathToFileURL(sensitive_file_path); 200 GURL sensitive_file_url = net::FilePathToFileURL(sensitive_file_path);
201 dropped_data.url = highlighted_file_url; 201 dropped_data.url = highlighted_file_url;
202 dropped_data.filenames.push_back(WebDropData::FileInfo( 202 dropped_data.filenames.push_back(DropData::FileInfo(
203 UTF8ToUTF16(dragged_file_path.AsUTF8Unsafe()), string16())); 203 UTF8ToUTF16(dragged_file_path.AsUTF8Unsafe()), string16()));
204 204
205 rvh()->DragTargetDragEnter(dropped_data, client_point, screen_point, 205 rvh()->DragTargetDragEnter(dropped_data, client_point, screen_point,
206 WebKit::WebDragOperationNone, 0); 206 WebKit::WebDragOperationNone, 0);
207 207
208 int id = process()->GetID(); 208 int id = process()->GetID();
209 ChildProcessSecurityPolicyImpl* policy = 209 ChildProcessSecurityPolicyImpl* policy =
210 ChildProcessSecurityPolicyImpl::GetInstance(); 210 ChildProcessSecurityPolicyImpl::GetInstance();
211 211
212 EXPECT_FALSE(policy->CanRequestURL(id, highlighted_file_url)); 212 EXPECT_FALSE(policy->CanRequestURL(id, highlighted_file_url));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 process()->GetID(), file_path, 290 process()->GetID(), file_path,
291 base::PLATFORM_FILE_OPEN | 291 base::PLATFORM_FILE_OPEN |
292 base::PLATFORM_FILE_READ | 292 base::PLATFORM_FILE_READ |
293 base::PLATFORM_FILE_EXCLUSIVE_READ | 293 base::PLATFORM_FILE_EXCLUSIVE_READ |
294 base::PLATFORM_FILE_ASYNC); 294 base::PLATFORM_FILE_ASYNC);
295 test_rvh()->SendNavigateWithFile(process()->GetID(), url, file_path); 295 test_rvh()->SendNavigateWithFile(process()->GetID(), url, file_path);
296 EXPECT_EQ(1, process()->bad_msg_count()); 296 EXPECT_EQ(1, process()->bad_msg_count());
297 } 297 }
298 298
299 } // namespace content 299 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | content/browser/renderer_host/test_render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698