| 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_message_filter.h" |
| 10 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 10 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "third_party/WebKit/public/web/WebDragOperation.h" | 24 #include "third_party/WebKit/public/web/WebDragOperation.h" |
| 25 #include "ui/base/page_transition_types.h" | 25 #include "ui/base/page_transition_types.h" |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 class RenderViewHostTestBrowserClient : public TestContentBrowserClient { | 29 class RenderViewHostTestBrowserClient : public TestContentBrowserClient { |
| 30 public: | 30 public: |
| 31 RenderViewHostTestBrowserClient() {} | 31 RenderViewHostTestBrowserClient() {} |
| 32 virtual ~RenderViewHostTestBrowserClient() {} | 32 virtual ~RenderViewHostTestBrowserClient() {} |
| 33 | 33 |
| 34 virtual bool IsHandledURL(const GURL& url) OVERRIDE { | 34 virtual bool IsHandledURL(const GURL& url) override { |
| 35 return url.scheme() == url::kFileScheme; | 35 return url.scheme() == url::kFileScheme; |
| 36 } | 36 } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestBrowserClient); | 39 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestBrowserClient); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class RenderViewHostTest : public RenderViewHostImplTestHarness { | 42 class RenderViewHostTest : public RenderViewHostImplTestHarness { |
| 43 public: | 43 public: |
| 44 RenderViewHostTest() : old_browser_client_(NULL) {} | 44 RenderViewHostTest() : old_browser_client_(NULL) {} |
| 45 virtual ~RenderViewHostTest() {} | 45 virtual ~RenderViewHostTest() {} |
| 46 | 46 |
| 47 virtual void SetUp() OVERRIDE { | 47 virtual void SetUp() override { |
| 48 RenderViewHostImplTestHarness::SetUp(); | 48 RenderViewHostImplTestHarness::SetUp(); |
| 49 old_browser_client_ = SetBrowserClientForTesting(&test_browser_client_); | 49 old_browser_client_ = SetBrowserClientForTesting(&test_browser_client_); |
| 50 } | 50 } |
| 51 | 51 |
| 52 virtual void TearDown() OVERRIDE { | 52 virtual void TearDown() override { |
| 53 SetBrowserClientForTesting(old_browser_client_); | 53 SetBrowserClientForTesting(old_browser_client_); |
| 54 RenderViewHostImplTestHarness::TearDown(); | 54 RenderViewHostImplTestHarness::TearDown(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 RenderViewHostTestBrowserClient test_browser_client_; | 58 RenderViewHostTestBrowserClient test_browser_client_; |
| 59 ContentBrowserClient* old_browser_client_; | 59 ContentBrowserClient* old_browser_client_; |
| 60 | 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTest); | 61 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTest); |
| 62 }; | 62 }; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 class MockDraggingRenderViewHostDelegateView | 119 class MockDraggingRenderViewHostDelegateView |
| 120 : public RenderViewHostDelegateView { | 120 : public RenderViewHostDelegateView { |
| 121 public: | 121 public: |
| 122 virtual ~MockDraggingRenderViewHostDelegateView() {} | 122 virtual ~MockDraggingRenderViewHostDelegateView() {} |
| 123 virtual void StartDragging(const DropData& drop_data, | 123 virtual void StartDragging(const DropData& drop_data, |
| 124 blink::WebDragOperationsMask allowed_ops, | 124 blink::WebDragOperationsMask allowed_ops, |
| 125 const gfx::ImageSkia& image, | 125 const gfx::ImageSkia& image, |
| 126 const gfx::Vector2d& image_offset, | 126 const gfx::Vector2d& image_offset, |
| 127 const DragEventSourceInfo& event_info) OVERRIDE { | 127 const DragEventSourceInfo& event_info) override { |
| 128 drag_url_ = drop_data.url; | 128 drag_url_ = drop_data.url; |
| 129 html_base_url_ = drop_data.html_base_url; | 129 html_base_url_ = drop_data.html_base_url; |
| 130 } | 130 } |
| 131 virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE {} | 131 virtual void UpdateDragCursor(blink::WebDragOperation operation) override {} |
| 132 virtual void GotFocus() OVERRIDE {} | 132 virtual void GotFocus() override {} |
| 133 virtual void TakeFocus(bool reverse) OVERRIDE {} | 133 virtual void TakeFocus(bool reverse) override {} |
| 134 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} | 134 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} |
| 135 | 135 |
| 136 GURL drag_url() { | 136 GURL drag_url() { |
| 137 return drag_url_; | 137 return drag_url_; |
| 138 } | 138 } |
| 139 | 139 |
| 140 GURL html_base_url() { | 140 GURL html_base_url() { |
| 141 return html_base_url_; | 141 return html_base_url_; |
| 142 } | 142 } |
| 143 | 143 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 void Test(const std::string& url) { | 280 void Test(const std::string& url) { |
| 281 OnMessageReceived(ViewHostMsg_SaveImageFromDataURL(0, url)); | 281 OnMessageReceived(ViewHostMsg_SaveImageFromDataURL(0, url)); |
| 282 } | 282 } |
| 283 | 283 |
| 284 protected: | 284 protected: |
| 285 virtual ~TestSaveImageFromDataURL() { } | 285 virtual ~TestSaveImageFromDataURL() { } |
| 286 virtual void DownloadUrl(int render_view_id, | 286 virtual void DownloadUrl(int render_view_id, |
| 287 const GURL& url, | 287 const GURL& url, |
| 288 const Referrer& referrer, | 288 const Referrer& referrer, |
| 289 const base::string16& suggested_name, | 289 const base::string16& suggested_name, |
| 290 const bool use_prompt) const OVERRIDE { | 290 const bool use_prompt) const override { |
| 291 url_string_ = url.spec(); | 291 url_string_ = url.spec(); |
| 292 is_downloaded_ = true; | 292 is_downloaded_ = true; |
| 293 } | 293 } |
| 294 | 294 |
| 295 private: | 295 private: |
| 296 mutable std::string url_string_; | 296 mutable std::string url_string_; |
| 297 mutable bool is_downloaded_; | 297 mutable bool is_downloaded_; |
| 298 }; | 298 }; |
| 299 | 299 |
| 300 TEST_F(RenderViewHostTest, SaveImageFromDataURL) { | 300 TEST_F(RenderViewHostTest, SaveImageFromDataURL) { |
| 301 scoped_refptr<TestSaveImageFromDataURL> tester( | 301 scoped_refptr<TestSaveImageFromDataURL> tester( |
| 302 new TestSaveImageFromDataURL(browser_context())); | 302 new TestSaveImageFromDataURL(browser_context())); |
| 303 | 303 |
| 304 tester->Reset(); | 304 tester->Reset(); |
| 305 tester->Test("http://non-data-url.com"); | 305 tester->Test("http://non-data-url.com"); |
| 306 EXPECT_EQ(tester->UrlString(), ""); | 306 EXPECT_EQ(tester->UrlString(), ""); |
| 307 EXPECT_FALSE(tester->IsDownloaded()); | 307 EXPECT_FALSE(tester->IsDownloaded()); |
| 308 | 308 |
| 309 const std::string data_url = "data:image/gif;base64," | 309 const std::string data_url = "data:image/gif;base64," |
| 310 "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; | 310 "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; |
| 311 | 311 |
| 312 tester->Reset(); | 312 tester->Reset(); |
| 313 tester->Test(data_url); | 313 tester->Test(data_url); |
| 314 EXPECT_EQ(tester->UrlString(), data_url); | 314 EXPECT_EQ(tester->UrlString(), data_url); |
| 315 EXPECT_TRUE(tester->IsDownloaded()); | 315 EXPECT_TRUE(tester->IsDownloaded()); |
| 316 } | 316 } |
| 317 | 317 |
| 318 } // namespace content | 318 } // namespace content |
| OLD | NEW |