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

Unified Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 2113893005: Adding tests for WebContent.DownloadImage() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/web_contents/web_contents_impl_browsertest.cc
diff --git a/content/browser/web_contents/web_contents_impl_browsertest.cc b/content/browser/web_contents/web_contents_impl_browsertest.cc
index 0833357f8ae1406af8d69ddb1b990199837514a2..1c769daa40d2118d91ec311765992bbe741bb832 100644
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc
@@ -1167,4 +1167,62 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
EXPECT_EQ(web_ui_url, entry->GetURL());
}
+namespace {
+
+class DownloadImageObserver {
+ public:
+ MOCK_METHOD5(OnFinishDownloadImage, void(
+ int id,
+ int status_code,
+ const GURL& image_url,
+ const std::vector<SkBitmap>& bitmap,
+ const std::vector<gfx::Size>& sizes));
+ ~DownloadImageObserver() = default;
+};
+
+void DownloadImageTestInternal(Shell* shell,
+ const GURL &image_url,
+ int expected_http_status) {
+ using ::testing::_;
+ using ::testing::InvokeWithoutArgs;
+
+ // Set up everything.
+ DownloadImageObserver download_image_observer;
+ scoped_refptr<MessageLoopRunner> loop_runner =
+ new MessageLoopRunner();
+
+ // Set up expectation and stub.
+ EXPECT_CALL(download_image_observer,
+ OnFinishDownloadImage(_, expected_http_status, _, _, _));
+ ON_CALL(download_image_observer, OnFinishDownloadImage(_, _, _, _, _))
+ .WillByDefault(
+ InvokeWithoutArgs(loop_runner.get(), &MessageLoopRunner::Quit));
+
+ shell->LoadURL(GURL("about:blank"));
+ shell->web_contents()->DownloadImage(
+ image_url, false, 1024, false,
+ base::Bind(&DownloadImageObserver::OnFinishDownloadImage,
+ base::Unretained(&download_image_observer)));
+
+ // Wait for response.
+ loop_runner->Run();
+}
+
+} // anonymous namespace
+
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
+ DownloadImage_HttpImage) {
+ ASSERT_TRUE(embedded_test_server()->Start());
+ const GURL kImageUrl =
+ embedded_test_server()->GetURL("/image.jpg");
+ DownloadImageTestInternal(shell(), kImageUrl, 200);
+}
+
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
+ DownloadImage_Deny_FileImage) {
+ const GURL kImageUrl =
+ GetTestUrl("", "image.jpg");
+ DownloadImageTestInternal(shell(), kImageUrl, 0);
+}
+
} // namespace content
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698