| 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 11 matching lines...) Expand all Loading... |
| 22 #include "content/test/test_web_contents.h" | 22 #include "content/test/test_web_contents.h" |
| 23 #include "net/base/filename_util.h" | 23 #include "net/base/filename_util.h" |
| 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 ~RenderViewHostTestBrowserClient() override {} |
| 33 | 33 |
| 34 virtual bool IsHandledURL(const GURL& url) override { | 34 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) {} |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 scoped_ptr<TestWebContents> new_web_contents( | 112 scoped_ptr<TestWebContents> new_web_contents( |
| 113 TestWebContents::Create(browser_context(), rvh()->GetSiteInstance())); | 113 TestWebContents::Create(browser_context(), rvh()->GetSiteInstance())); |
| 114 | 114 |
| 115 rvh()->AllowBindings(BINDINGS_POLICY_WEB_UI); | 115 rvh()->AllowBindings(BINDINGS_POLICY_WEB_UI); |
| 116 EXPECT_FALSE(rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 116 EXPECT_FALSE(rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 117 } | 117 } |
| 118 | 118 |
| 119 class MockDraggingRenderViewHostDelegateView | 119 class MockDraggingRenderViewHostDelegateView |
| 120 : public RenderViewHostDelegateView { | 120 : public RenderViewHostDelegateView { |
| 121 public: | 121 public: |
| 122 virtual ~MockDraggingRenderViewHostDelegateView() {} | 122 ~MockDraggingRenderViewHostDelegateView() override {} |
| 123 virtual void StartDragging(const DropData& drop_data, | 123 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 void UpdateDragCursor(blink::WebDragOperation operation) override {} |
| 132 virtual void GotFocus() override {} | 132 void GotFocus() override {} |
| 133 virtual void TakeFocus(bool reverse) override {} | 133 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 bool IsDownloaded() const { | 278 bool IsDownloaded() const { |
| 279 return is_downloaded_; | 279 return is_downloaded_; |
| 280 } | 280 } |
| 281 | 281 |
| 282 void Test(const std::string& url) { | 282 void Test(const std::string& url) { |
| 283 OnMessageReceived(ViewHostMsg_SaveImageFromDataURL(0, url)); | 283 OnMessageReceived(ViewHostMsg_SaveImageFromDataURL(0, url)); |
| 284 } | 284 } |
| 285 | 285 |
| 286 protected: | 286 protected: |
| 287 virtual ~TestSaveImageFromDataURL() { } | 287 ~TestSaveImageFromDataURL() override {} |
| 288 virtual void DownloadUrl(int render_view_id, | 288 void DownloadUrl(int render_view_id, |
| 289 const GURL& url, | 289 const GURL& url, |
| 290 const Referrer& referrer, | 290 const Referrer& referrer, |
| 291 const base::string16& suggested_name, | 291 const base::string16& suggested_name, |
| 292 const bool use_prompt) const override { | 292 const bool use_prompt) const override { |
| 293 url_string_ = url.spec(); | 293 url_string_ = url.spec(); |
| 294 is_downloaded_ = true; | 294 is_downloaded_ = true; |
| 295 } | 295 } |
| 296 | 296 |
| 297 private: | 297 private: |
| 298 mutable std::string url_string_; | 298 mutable std::string url_string_; |
| 299 mutable bool is_downloaded_; | 299 mutable bool is_downloaded_; |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 TEST_F(RenderViewHostTest, SaveImageFromDataURL) { | 302 TEST_F(RenderViewHostTest, SaveImageFromDataURL) { |
| 303 scoped_refptr<TestSaveImageFromDataURL> tester( | 303 scoped_refptr<TestSaveImageFromDataURL> tester( |
| 304 new TestSaveImageFromDataURL(browser_context())); | 304 new TestSaveImageFromDataURL(browser_context())); |
| 305 | 305 |
| 306 tester->Reset(); | 306 tester->Reset(); |
| 307 tester->Test("http://non-data-url.com"); | 307 tester->Test("http://non-data-url.com"); |
| 308 EXPECT_EQ(tester->UrlString(), ""); | 308 EXPECT_EQ(tester->UrlString(), ""); |
| 309 EXPECT_FALSE(tester->IsDownloaded()); | 309 EXPECT_FALSE(tester->IsDownloaded()); |
| 310 | 310 |
| 311 const std::string data_url = "data:image/gif;base64," | 311 const std::string data_url = "data:image/gif;base64," |
| 312 "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; | 312 "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; |
| 313 | 313 |
| 314 tester->Reset(); | 314 tester->Reset(); |
| 315 tester->Test(data_url); | 315 tester->Test(data_url); |
| 316 EXPECT_EQ(tester->UrlString(), data_url); | 316 EXPECT_EQ(tester->UrlString(), data_url); |
| 317 EXPECT_TRUE(tester->IsDownloaded()); | 317 EXPECT_TRUE(tester->IsDownloaded()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace content | 320 } // namespace content |
| OLD | NEW |