Index: content/browser/renderer_host/render_view_host_unittest.cc |
diff --git a/content/browser/renderer_host/render_view_host_unittest.cc b/content/browser/renderer_host/render_view_host_unittest.cc |
index d765481705636dc7816576e2eea4c56238eb02b2..927942bb5fe3ec576e3676131e1d2793c6a98e0a 100644 |
--- a/content/browser/renderer_host/render_view_host_unittest.cc |
+++ b/content/browser/renderer_host/render_view_host_unittest.cc |
@@ -6,9 +6,12 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "content/browser/child_process_security_policy_impl.h" |
#include "content/browser/frame_host/render_frame_host_impl.h" |
+#include "content/browser/renderer_host/render_message_filter.h" |
#include "content/browser/renderer_host/render_view_host_delegate_view.h" |
+#include "content/browser/renderer_host/render_widget_helper.h" |
#include "content/common/input_messages.h" |
#include "content/common/view_messages.h" |
+#include "content/public/browser/browser_context.h" |
#include "content/public/browser/navigation_entry.h" |
#include "content/public/common/bindings_policy.h" |
#include "content/public/common/drop_data.h" |
@@ -245,4 +248,71 @@ TEST_F(RenderViewHostTest, RoutingIdSane) { |
EXPECT_NE(test_rvh()->GetRoutingID(), root_rfh->routing_id()); |
} |
+class TestSaveImageFromDataURL : public RenderMessageFilter { |
+ public: |
+ TestSaveImageFromDataURL( |
+ BrowserContext* context) |
+ : RenderMessageFilter( |
+ 0, |
+ nullptr, |
+ context, |
+ context->GetRequestContext(), |
+ nullptr, |
+ nullptr, |
+ nullptr, |
+ nullptr) { |
+ Reset(); |
+ } |
+ |
+ void Reset() { |
+ url_string_ = std::string(); |
+ is_downloaded_ = false; |
+ } |
+ |
+ std::string& UrlString() const { |
+ return url_string_; |
+ } |
+ |
+ bool IsDownloaded() const { |
+ return is_downloaded_; |
+ } |
+ |
+ void Test(const std::string& url) { |
+ OnMessageReceived(ViewHostMsg_SaveImageFromDataURL(0, url)); |
+ } |
+ |
+ protected: |
+ virtual ~TestSaveImageFromDataURL() { } |
+ virtual void DownloadUrl(int render_view_id, |
+ const GURL& url, |
+ const Referrer& referrer, |
+ const base::string16& suggested_name, |
+ const bool use_prompt) const OVERRIDE { |
+ url_string_ = url.spec(); |
+ is_downloaded_ = true; |
+ } |
+ |
+ private: |
+ mutable std::string url_string_; |
+ mutable bool is_downloaded_; |
+}; |
+ |
+TEST_F(RenderViewHostTest, SaveImageFromDataURL) { |
+ scoped_refptr<TestSaveImageFromDataURL> tester( |
+ new TestSaveImageFromDataURL(browser_context())); |
+ |
+ tester->Reset(); |
+ tester->Test("http://non-data-url.com"); |
+ EXPECT_EQ(tester->UrlString(), ""); |
+ EXPECT_FALSE(tester->IsDownloaded()); |
+ |
+ const std::string data_url = "data:image/gif;base64," |
+ "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; |
+ |
+ tester->Reset(); |
+ tester->Test(data_url); |
+ EXPECT_EQ(tester->UrlString(), data_url); |
+ EXPECT_TRUE(tester->IsDownloaded()); |
+} |
+ |
} // namespace content |