Chromium Code Reviews| 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 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
| |
| 1174 public: | |
| 1175 MOCK_METHOD5(OnFinishDownloadImage, void( | |
| 1176 int id, | |
| 1177 int status_code, | |
| 1178 const GURL& image_url, | |
| 1179 const std::vector<SkBitmap>& bitmap, | |
| 1180 const std::vector<gfx::Size>& sizes)); | |
| 1181 | |
| 1182 private: | |
| 1183 friend class base::RefCountedThreadSafe<DownloadImageObserver>; | |
| 1184 ~DownloadImageObserver() = default; | |
| 1185 }; | |
| 1186 | |
| 1187 void DownloadImageTestInternal(Shell* shell, | |
| 1188 const GURL &page_url, | |
| 1189 const GURL &image_url, | |
| 1190 int expected_http_status) { | |
| 1191 using ::testing::_; | |
| 1192 using ::testing::InvokeWithoutArgs; | |
| 1193 | |
| 1194 // Set up everything. | |
| 1195 scoped_refptr<DownloadImageObserver> download_image_observer = | |
| 1196 new DownloadImageObserver(); | |
| 1197 scoped_refptr<MessageLoopRunner> loop_runner = | |
| 1198 new MessageLoopRunner(); | |
| 1199 | |
| 1200 // Set up expectation and stub. | |
| 1201 EXPECT_CALL(*download_image_observer, | |
| 1202 OnFinishDownloadImage(_, expected_http_status, _, _, _)) | |
| 1203 .WillOnce(InvokeWithoutArgs([&]() { | |
| 1204 loop_runner->Quit(); | |
| 1205 })); | |
| 1206 | |
| 1207 // Load test URL and start download image. | |
| 1208 shell->LoadURL(page_url); | |
| 1209 shell->web_contents()->DownloadImage( | |
| 1210 image_url, false, 1024, false, | |
| 1211 base::Bind(&DownloadImageObserver::OnFinishDownloadImage, | |
| 1212 download_image_observer)); | |
| 1213 | |
| 1214 // Wait for response. | |
| 1215 loop_runner->Run(); | |
| 1216 } | |
| 1217 | |
| 1218 } // anonymous namespace | |
| 1219 | |
| 1220 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
| 1221 DownloadImage_HttpPage_HttpImage) { | |
| 1222 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1223 | |
| 1224 const GURL kPageUrl = | |
| 1225 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 *
| |
| 1226 const GURL kImageUrl = | |
| 1227 embedded_test_server()->GetURL("/image.jpg"); | |
| 1228 | |
| 1229 DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 200); | |
| 1230 } | |
| 1231 | |
| 1232 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
| 1233 DownloadImage_Deny_HttpPage_FileImage) { | |
| 1234 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1235 | |
| 1236 const GURL kPageUrl = | |
| 1237 embedded_test_server()->GetURL("/simple_page.html"); | |
| 1238 const GURL kImageUrl = | |
| 1239 GetTestUrl("", "image.jpg"); | |
| 1240 | |
| 1241 DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0); | |
| 1242 } | |
| 1243 | |
| 1244 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
| 1245 DownloadImage_Deny_FilePage_FileImage) { | |
| 1246 const GURL kPageUrl = GetTestUrl("", "simple-page.html"); | |
| 1247 const GURL kImageUrl = GetTestUrl("", "image.jpg"); | |
| 1248 | |
| 1249 DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0); | |
| 1250 } | |
| 1251 | |
| 1170 } // namespace content | 1252 } // namespace content |
| OLD | NEW |