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..585aeccdf56b9bd473165a5aef192437fc3d1f7e 100644 |
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc |
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc |
@@ -1167,4 +1167,100 @@ 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 &page_url, |
+ 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), _, _, _)) |
+ .WillByDefault(InvokeWithoutArgs([&]() { |
+ loop_runner->Quit(); |
+ })); |
+ |
+ // Load test URL and start download image. |
+ shell->LoadURL(page_url); |
+ |
+ 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_HttpPage_HttpImage) { |
pkotwicz
2016/07/04 20:17:17
I tried this test locally and it fails.
I think t
Zhiqiang Zhang (Slow)
2016/07/05 15:46:58
Done.
|
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ const GURL kPageUrl = |
+ embedded_test_server()->GetURL("/simple_page.html"); |
+ const GURL kImageUrl = |
+ embedded_test_server()->GetURL("/image.jpg"); |
+ |
+ DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
+ DownloadImage_FilePage_HttpImage) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ const GURL kPageUrl = |
+ GetTestUrl("", "simple_page.html"); |
+ const GURL kImageUrl = |
+ embedded_test_server()->GetURL("/image.jpg"); |
+ |
+ DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 200); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
+ DownloadImage_Deny_HttpPage_FileImage) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ const GURL kPageUrl = |
+ embedded_test_server()->GetURL("/simple_page.html"); |
+ const GURL kImageUrl = |
+ GetTestUrl("", "image.jpg"); |
+ |
+ DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
+ DownloadImage_Deny_FilePage_FileImage) { |
+ const GURL kPageUrl = GetTestUrl("", "simple-page.html"); |
+ const GURL kImageUrl = GetTestUrl("", "image.jpg"); |
+ |
+ DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0); |
+} |
+ |
} // namespace content |