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/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/frame_host/render_frame_host_impl.h" | 8 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 9 #include "content/browser/renderer_host/render_message_filter.h" |
9 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 10 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
| 11 #include "content/browser/renderer_host/render_widget_helper.h" |
10 #include "content/common/input_messages.h" | 12 #include "content/common/input_messages.h" |
11 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
13 #include "content/public/common/bindings_policy.h" | 16 #include "content/public/common/bindings_policy.h" |
14 #include "content/public/common/drop_data.h" | 17 #include "content/public/common/drop_data.h" |
15 #include "content/public/common/page_transition_types.h" | 18 #include "content/public/common/page_transition_types.h" |
16 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
17 #include "content/public/test/mock_render_process_host.h" | 20 #include "content/public/test/mock_render_process_host.h" |
18 #include "content/test/test_content_browser_client.h" | 21 #include "content/test/test_content_browser_client.h" |
19 #include "content/test/test_render_view_host.h" | 22 #include "content/test/test_render_view_host.h" |
20 #include "content/test/test_web_contents.h" | 23 #include "content/test/test_web_contents.h" |
21 #include "net/base/filename_util.h" | 24 #include "net/base/filename_util.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 EXPECT_EQ(1, process()->bad_msg_count()); | 241 EXPECT_EQ(1, process()->bad_msg_count()); |
239 } | 242 } |
240 | 243 |
241 TEST_F(RenderViewHostTest, RoutingIdSane) { | 244 TEST_F(RenderViewHostTest, RoutingIdSane) { |
242 RenderFrameHostImpl* root_rfh = | 245 RenderFrameHostImpl* root_rfh = |
243 contents()->GetFrameTree()->root()->current_frame_host(); | 246 contents()->GetFrameTree()->root()->current_frame_host(); |
244 EXPECT_EQ(test_rvh()->GetProcess(), root_rfh->GetProcess()); | 247 EXPECT_EQ(test_rvh()->GetProcess(), root_rfh->GetProcess()); |
245 EXPECT_NE(test_rvh()->GetRoutingID(), root_rfh->routing_id()); | 248 EXPECT_NE(test_rvh()->GetRoutingID(), root_rfh->routing_id()); |
246 } | 249 } |
247 | 250 |
| 251 class TestSaveImageFromDataURL : public RenderMessageFilter { |
| 252 public: |
| 253 TestSaveImageFromDataURL( |
| 254 BrowserContext* context) |
| 255 : RenderMessageFilter( |
| 256 0, |
| 257 nullptr, |
| 258 context, |
| 259 context->GetRequestContext(), |
| 260 nullptr, |
| 261 nullptr, |
| 262 nullptr, |
| 263 nullptr) { |
| 264 Reset(); |
| 265 } |
| 266 |
| 267 void Reset() { |
| 268 url_string_ = std::string(); |
| 269 is_downloaded_ = false; |
| 270 } |
| 271 |
| 272 std::string& UrlString() const { |
| 273 return url_string_; |
| 274 } |
| 275 |
| 276 bool IsDownloaded() const { |
| 277 return is_downloaded_; |
| 278 } |
| 279 |
| 280 void Test(const std::string& url) { |
| 281 OnMessageReceived(ViewHostMsg_SaveImageFromDataURL(0, url)); |
| 282 } |
| 283 |
| 284 protected: |
| 285 virtual ~TestSaveImageFromDataURL() { } |
| 286 virtual void DownloadUrl(int render_view_id, |
| 287 const GURL& url, |
| 288 const Referrer& referrer, |
| 289 const base::string16& suggested_name, |
| 290 const bool use_prompt) const OVERRIDE { |
| 291 url_string_ = url.spec(); |
| 292 is_downloaded_ = true; |
| 293 } |
| 294 |
| 295 private: |
| 296 mutable std::string url_string_; |
| 297 mutable bool is_downloaded_; |
| 298 }; |
| 299 |
| 300 TEST_F(RenderViewHostTest, SaveImageFromDataURL) { |
| 301 scoped_refptr<TestSaveImageFromDataURL> tester( |
| 302 new TestSaveImageFromDataURL(browser_context())); |
| 303 |
| 304 tester->Reset(); |
| 305 tester->Test("http://non-data-url.com"); |
| 306 EXPECT_EQ(tester->UrlString(), ""); |
| 307 EXPECT_FALSE(tester->IsDownloaded()); |
| 308 |
| 309 const std::string data_url = "data:image/gif;base64," |
| 310 "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; |
| 311 |
| 312 tester->Reset(); |
| 313 tester->Test(data_url); |
| 314 EXPECT_EQ(tester->UrlString(), data_url); |
| 315 EXPECT_TRUE(tester->IsDownloaded()); |
| 316 } |
| 317 |
248 } // namespace content | 318 } // namespace content |
OLD | NEW |