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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 &page_url,
1185 const GURL &image_url,
1186 int expected_http_status) {
1187 using ::testing::_;
1188 using ::testing::InvokeWithoutArgs;
1189 using ::testing::Ne;
1190
1191 // Set up everything.
1192 DownloadImageObserver download_image_observer;
1193 scoped_refptr<MessageLoopRunner> loop_runner =
1194 new MessageLoopRunner();
1195
1196 // Set up expectation and stub.
1197 EXPECT_CALL(download_image_observer,
1198 OnFinishDownloadImage(_, expected_http_status, _, _, _))
1199 .WillOnce(InvokeWithoutArgs([&]() {
1200 loop_runner->Quit();
1201 }));
1202 ON_CALL(download_image_observer,
1203 OnFinishDownloadImage(_, Ne(expected_http_status), _, _, _))
1204 .WillByDefault(InvokeWithoutArgs([&]() {
1205 loop_runner->Quit();
1206 }));
1207
1208 // Load test URL and start download image.
1209 shell->LoadURL(page_url);
1210
1211 shell->web_contents()->DownloadImage(
1212 image_url, false, 1024, false,
1213 base::Bind(&DownloadImageObserver::OnFinishDownloadImage,
1214 base::Unretained(&download_image_observer)));
1215
1216 // Wait for response.
1217 loop_runner->Run();
1218 }
1219
1220 } // anonymous namespace
1221
1222 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1223 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.
1224 ASSERT_TRUE(embedded_test_server()->Start());
1225
1226 const GURL kPageUrl =
1227 embedded_test_server()->GetURL("/simple_page.html");
1228 const GURL kImageUrl =
1229 embedded_test_server()->GetURL("/image.jpg");
1230
1231 DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0);
1232 }
1233
1234 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1235 DownloadImage_FilePage_HttpImage) {
1236 ASSERT_TRUE(embedded_test_server()->Start());
1237
1238 const GURL kPageUrl =
1239 GetTestUrl("", "simple_page.html");
1240 const GURL kImageUrl =
1241 embedded_test_server()->GetURL("/image.jpg");
1242
1243 DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 200);
1244 }
1245
1246 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1247 DownloadImage_Deny_HttpPage_FileImage) {
1248 ASSERT_TRUE(embedded_test_server()->Start());
1249
1250 const GURL kPageUrl =
1251 embedded_test_server()->GetURL("/simple_page.html");
1252 const GURL kImageUrl =
1253 GetTestUrl("", "image.jpg");
1254
1255 DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0);
1256 }
1257
1258 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1259 DownloadImage_Deny_FilePage_FileImage) {
1260 const GURL kPageUrl = GetTestUrl("", "simple-page.html");
1261 const GURL kImageUrl = GetTestUrl("", "image.jpg");
1262
1263 DownloadImageTestInternal(shell(), kPageUrl, kImageUrl, 0);
1264 }
1265
1170 } // namespace content 1266 } // namespace content
OLDNEW
« 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