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..2122314e34d0319d0c857a0223a8c6ba364a3171 100644 |
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc |
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc |
@@ -1167,4 +1167,86 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
EXPECT_EQ(web_ui_url, entry->GetURL()); |
} |
+namespace { |
+ |
+class DownloadImageObserver : |
+ public base::RefCountedThreadSafe<DownloadImageObserver> { |
pkotwicz
2016/07/04 17:17:01
Why is DownloadImageObserver ref counted?
The tes
Zhiqiang Zhang (Slow)
2016/07/04 19:34:27
Oops, I forget using base::Unretained in base::Bin
|
+ 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)); |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<DownloadImageObserver>; |
+ ~DownloadImageObserver() = default; |
+}; |
+ |
+void DownloadImageTestInternal(Shell* shell, |
+ const GURL &page_url, |
+ const GURL &image_url, |
+ int expected_http_status) { |
+ using ::testing::_; |
+ using ::testing::InvokeWithoutArgs; |
+ |
+ // Set up everything. |
+ scoped_refptr<DownloadImageObserver> download_image_observer = |
+ new DownloadImageObserver(); |
+ 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(); |
+ })); |
+ |
+ // Load test URL and start download image. |
+ shell->LoadURL(page_url); |
+ shell->web_contents()->DownloadImage( |
+ image_url, false, 1024, false, |
+ base::Bind(&DownloadImageObserver::OnFinishDownloadImage, |
+ download_image_observer)); |
+ |
+ // Wait for response. |
+ loop_runner->Run(); |
+} |
+ |
+} // anonymous namespace |
+ |
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
+ DownloadImage_HttpPage_HttpImage) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ const GURL kPageUrl = |
+ embedded_test_server()->GetURL("/simple_page.html"); |
pkotwicz
2016/07/04 17:17:01
I don't think that the page URL affects whether th
Zhiqiang Zhang (Slow)
2016/07/04 19:34:27
OK, so now I just test for cases: file/http page *
|
+ 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 |