OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 | 1160 |
1161 // Check that pre-warmed process isn't used. | 1161 // Check that pre-warmed process isn't used. |
1162 EXPECT_NE(renderer_id, web_contents->GetRenderProcessHost()->GetID()); | 1162 EXPECT_NE(renderer_id, web_contents->GetRenderProcessHost()->GetID()); |
1163 EXPECT_EQ(1, web_contents->GetController().GetEntryCount()); | 1163 EXPECT_EQ(1, web_contents->GetController().GetEntryCount()); |
1164 NavigationEntry* entry = | 1164 NavigationEntry* entry = |
1165 web_contents->GetController().GetLastCommittedEntry(); | 1165 web_contents->GetController().GetLastCommittedEntry(); |
1166 ASSERT_TRUE(entry); | 1166 ASSERT_TRUE(entry); |
1167 EXPECT_EQ(web_ui_url, entry->GetURL()); | 1167 EXPECT_EQ(web_ui_url, entry->GetURL()); |
1168 } | 1168 } |
1169 | 1169 |
| 1170 namespace { |
| 1171 |
| 1172 class DownloadImageObserver { |
| 1173 public: |
| 1174 MOCK_METHOD5(OnFinishDownloadImage, void( |
| 1175 int id, |
| 1176 int status_code, |
| 1177 const GURL& image_url, |
| 1178 const std::vector<SkBitmap>& bitmap, |
| 1179 const std::vector<gfx::Size>& sizes)); |
| 1180 ~DownloadImageObserver() = default; |
| 1181 }; |
| 1182 |
| 1183 void DownloadImageTestInternal(Shell* shell, |
| 1184 const GURL &image_url, |
| 1185 int expected_http_status) { |
| 1186 using ::testing::_; |
| 1187 using ::testing::InvokeWithoutArgs; |
| 1188 |
| 1189 // Set up everything. |
| 1190 DownloadImageObserver download_image_observer; |
| 1191 scoped_refptr<MessageLoopRunner> loop_runner = |
| 1192 new MessageLoopRunner(); |
| 1193 |
| 1194 // Set up expectation and stub. |
| 1195 EXPECT_CALL(download_image_observer, |
| 1196 OnFinishDownloadImage(_, expected_http_status, _, _, _)); |
| 1197 ON_CALL(download_image_observer, OnFinishDownloadImage(_, _, _, _, _)) |
| 1198 .WillByDefault( |
| 1199 InvokeWithoutArgs(loop_runner.get(), &MessageLoopRunner::Quit)); |
| 1200 |
| 1201 shell->LoadURL(GURL("about:blank")); |
| 1202 shell->web_contents()->DownloadImage( |
| 1203 image_url, false, 1024, false, |
| 1204 base::Bind(&DownloadImageObserver::OnFinishDownloadImage, |
| 1205 base::Unretained(&download_image_observer))); |
| 1206 |
| 1207 // Wait for response. |
| 1208 loop_runner->Run(); |
| 1209 } |
| 1210 |
| 1211 } // anonymous namespace |
| 1212 |
| 1213 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
| 1214 DownloadImage_HttpImage) { |
| 1215 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1216 const GURL kImageUrl = |
| 1217 embedded_test_server()->GetURL("/image.jpg"); |
| 1218 DownloadImageTestInternal(shell(), kImageUrl, 200); |
| 1219 } |
| 1220 |
| 1221 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
| 1222 DownloadImage_Deny_FileImage) { |
| 1223 const GURL kImageUrl = |
| 1224 GetTestUrl("", "image.jpg"); |
| 1225 DownloadImageTestInternal(shell(), kImageUrl, 0); |
| 1226 } |
| 1227 |
1170 } // namespace content | 1228 } // namespace content |
OLD | NEW |