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

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 &image_url,
1185 int expected_http_status) {
1186 using ::testing::_;
1187 using ::testing::InvokeWithoutArgs;
1188 using ::testing::Ne;
1189
1190 // Set up everything.
1191 DownloadImageObserver download_image_observer;
1192 scoped_refptr<MessageLoopRunner> loop_runner =
1193 new MessageLoopRunner();
1194
1195 // Set up expectation and stub.
1196 EXPECT_CALL(download_image_observer,
1197 OnFinishDownloadImage(_, expected_http_status, _, _, _))
1198 .WillOnce(InvokeWithoutArgs([&]() {
1199 loop_runner->Quit();
1200 }));
1201 ON_CALL(download_image_observer,
1202 OnFinishDownloadImage(_, Ne(expected_http_status), _, _, _))
pkotwicz 2016/07/05 18:00:36 Can you replace "Ne(expected_http_status)" with "_
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
1203 .WillByDefault(InvokeWithoutArgs([&]() {
1204 loop_runner->Quit();
1205 }));
1206
1207 // Load test URL and start download image.
pkotwicz 2016/07/05 18:00:36 Nit: Please update (or remove) the comment
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
1208 shell->LoadURL(GURL("about:blank"));
1209
1210 shell->web_contents()->DownloadImage(
1211 image_url, false, 1024, false,
1212 base::Bind(&DownloadImageObserver::OnFinishDownloadImage,
1213 base::Unretained(&download_image_observer)));
1214
1215 // Wait for response.
1216 loop_runner->Run();
1217 }
1218
1219 } // anonymous namespace
1220
1221 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1222 DownloadImage_HttpImage) {
1223 ASSERT_TRUE(embedded_test_server()->Start());
1224
pkotwicz 2016/07/05 18:00:36 Nit: Remove blank line
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
1225 const GURL kImageUrl =
1226 embedded_test_server()->GetURL("/image.jpg");
1227
pkotwicz 2016/07/05 18:00:36 Nit: Remove blank line
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
1228 DownloadImageTestInternal(shell(), kImageUrl, 200);
1229 }
1230
1231 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1232 DownloadImage_Deny_FileImage) {
1233 const GURL kImageUrl =
1234 GetTestUrl("", "image.jpg");
1235
pkotwicz 2016/07/05 18:00:36 Nit: Remove blank line
Zhiqiang Zhang (Slow) 2016/07/05 18:12:44 Done.
1236 DownloadImageTestInternal(shell(), kImageUrl, 0);
1237 }
1238
1170 } // namespace content 1239 } // 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