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

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: addressed pkotwicz's comments 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..35d1856b3ea01e551fae2160678e4e916d64654e 100644
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc
@@ -1167,4 +1167,73 @@ 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;
+ using ::testing::Ne;
+
+ // 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, _, _, _))
+ .WillOnce(InvokeWithoutArgs([&]() {
+ loop_runner->Quit();
+ }));
+ ON_CALL(download_image_observer,
+ OnFinishDownloadImage(_, Ne(expected_http_status), _, _, _))
pkotwicz 2016/07/05 18:00:36 Can you replace "Ne(expected_http_status)" with "_
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
+ .WillByDefault(InvokeWithoutArgs([&]() {
+ loop_runner->Quit();
+ }));
+
+ // Load test URL and start download image.
pkotwicz 2016/07/05 18:00:36 Nit: Please update (or remove) the comment
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
+ 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());
+
pkotwicz 2016/07/05 18:00:36 Nit: Remove blank line
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
+ const GURL kImageUrl =
+ embedded_test_server()->GetURL("/image.jpg");
+
pkotwicz 2016/07/05 18:00:36 Nit: Remove blank line
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
+ DownloadImageTestInternal(shell(), kImageUrl, 200);
+}
+
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
+ DownloadImage_Deny_FileImage) {
+ const GURL kImageUrl =
+ GetTestUrl("", "image.jpg");
+
pkotwicz 2016/07/05 18:00:36 Nit: Remove blank line
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
+ 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