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

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 2625703002: [MediaNotification] Don't check HTTP status code for image fetch (Closed)
Patch Set: fixed junit test & cl format Created 3 years, 11 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 | « chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaImageManagerTest.java ('k') | 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/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 MOCK_METHOD5(OnFinishDownloadImage, void( 1167 MOCK_METHOD5(OnFinishDownloadImage, void(
1168 int id, 1168 int id,
1169 int status_code, 1169 int status_code,
1170 const GURL& image_url, 1170 const GURL& image_url,
1171 const std::vector<SkBitmap>& bitmap, 1171 const std::vector<SkBitmap>& bitmap,
1172 const std::vector<gfx::Size>& sizes)); 1172 const std::vector<gfx::Size>& sizes));
1173 ~DownloadImageObserver() = default; 1173 ~DownloadImageObserver() = default;
1174 }; 1174 };
1175 1175
1176 void DownloadImageTestInternal(Shell* shell, 1176 void DownloadImageTestInternal(Shell* shell,
1177 const GURL &image_url, 1177 const GURL& image_url,
1178 int expected_http_status) { 1178 int expected_http_status,
1179 int expected_number_of_images) {
1179 using ::testing::_; 1180 using ::testing::_;
1180 using ::testing::InvokeWithoutArgs; 1181 using ::testing::InvokeWithoutArgs;
1182 using ::testing::SizeIs;
1181 1183
1182 // Set up everything. 1184 // Set up everything.
1183 DownloadImageObserver download_image_observer; 1185 DownloadImageObserver download_image_observer;
1184 scoped_refptr<MessageLoopRunner> loop_runner = 1186 scoped_refptr<MessageLoopRunner> loop_runner =
1185 new MessageLoopRunner(); 1187 new MessageLoopRunner();
1186 1188
1187 // Set up expectation and stub. 1189 // Set up expectation and stub.
1188 EXPECT_CALL(download_image_observer, 1190 EXPECT_CALL(download_image_observer,
1189 OnFinishDownloadImage(_, expected_http_status, _, _, _)); 1191 OnFinishDownloadImage(_, expected_http_status, _,
1192 SizeIs(expected_number_of_images), _));
1190 ON_CALL(download_image_observer, OnFinishDownloadImage(_, _, _, _, _)) 1193 ON_CALL(download_image_observer, OnFinishDownloadImage(_, _, _, _, _))
1191 .WillByDefault( 1194 .WillByDefault(
1192 InvokeWithoutArgs(loop_runner.get(), &MessageLoopRunner::Quit)); 1195 InvokeWithoutArgs(loop_runner.get(), &MessageLoopRunner::Quit));
1193 1196
1194 shell->LoadURL(GURL("about:blank")); 1197 shell->LoadURL(GURL("about:blank"));
1195 shell->web_contents()->DownloadImage( 1198 shell->web_contents()->DownloadImage(
1196 image_url, false, 1024, false, 1199 image_url, false, 1024, false,
1197 base::Bind(&DownloadImageObserver::OnFinishDownloadImage, 1200 base::Bind(&DownloadImageObserver::OnFinishDownloadImage,
1198 base::Unretained(&download_image_observer))); 1201 base::Unretained(&download_image_observer)));
1199 1202
(...skipping 11 matching lines...) Expand all
1211 EXPECT_TRUE(bitmap.empty()); 1214 EXPECT_TRUE(bitmap.empty());
1212 EXPECT_TRUE(sizes.empty()); 1215 EXPECT_TRUE(sizes.empty());
1213 quit_closure.Run(); 1216 quit_closure.Run();
1214 } 1217 }
1215 1218
1216 } // anonymous namespace 1219 } // anonymous namespace
1217 1220
1218 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 1221 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1219 DownloadImage_HttpImage) { 1222 DownloadImage_HttpImage) {
1220 ASSERT_TRUE(embedded_test_server()->Start()); 1223 ASSERT_TRUE(embedded_test_server()->Start());
1221 const GURL kImageUrl = 1224 const GURL kImageUrl = embedded_test_server()->GetURL("/single_face.jpg");
1222 embedded_test_server()->GetURL("/image.jpg"); 1225 DownloadImageTestInternal(shell(), kImageUrl, 200, 1);
1223 DownloadImageTestInternal(shell(), kImageUrl, 200);
1224 } 1226 }
1225 1227
1226 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 1228 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1227 DownloadImage_Deny_FileImage) { 1229 DownloadImage_Deny_FileImage) {
1230 ASSERT_TRUE(embedded_test_server()->Start());
1231 shell()->LoadURL(embedded_test_server()->GetURL("/simple_page.html"));
1232
1233 const GURL kImageUrl = GetTestUrl("", "single_face.jpg");
1234 DownloadImageTestInternal(shell(), kImageUrl, 0, 0);
1235 }
1236
1237 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1238 DownloadImage_Allow_FileImage) {
1239 shell()->LoadURL(GetTestUrl("", "simple_page.html"));
1240
1228 const GURL kImageUrl = 1241 const GURL kImageUrl =
1229 GetTestUrl("", "image.jpg"); 1242 GetTestUrl("", "image.jpg");
1230 DownloadImageTestInternal(shell(), kImageUrl, 0); 1243 DownloadImageTestInternal(shell(), kImageUrl, 0, 0);
1231 } 1244 }
1232 1245
1233 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DownloadImage_NoValidImage) { 1246 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DownloadImage_NoValidImage) {
1234 ASSERT_TRUE(embedded_test_server()->Start()); 1247 ASSERT_TRUE(embedded_test_server()->Start());
1235 const GURL kImageUrl = embedded_test_server()->GetURL("/invalid.ico"); 1248 const GURL kImageUrl = embedded_test_server()->GetURL("/invalid.ico");
1236 shell()->LoadURL(GURL("about:blank")); 1249 shell()->LoadURL(GURL("about:blank"));
1237 base::RunLoop run_loop; 1250 base::RunLoop run_loop;
1238 shell()->web_contents()->DownloadImage( 1251 shell()->web_contents()->DownloadImage(
1239 kImageUrl, false, 2, false, 1252 kImageUrl, false, 2, false,
1240 base::Bind(&ExpectNoValidImageCallback, run_loop.QuitClosure())); 1253 base::Bind(&ExpectNoValidImageCallback, run_loop.QuitClosure()));
1241 1254
1242 run_loop.Run(); 1255 run_loop.Run();
1243 } 1256 }
1244 1257
1258 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DownloadImage_DataImage) {
1259 const GURL kImageUrl = GURL(
1260 "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHE"
1261 "lEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==");
1262 DownloadImageTestInternal(shell(), kImageUrl, 0, 1);
1263 }
1264
1265 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
1266 DownloadImage_InvalidDataImage) {
1267 const GURL kImageUrl = GURL("data:image/png;invalid");
1268 DownloadImageTestInternal(shell(), kImageUrl, 0, 0);
1269 }
1270
1245 class MouseLockDelegate : public WebContentsDelegate { 1271 class MouseLockDelegate : public WebContentsDelegate {
1246 public: 1272 public:
1247 // WebContentsDelegate: 1273 // WebContentsDelegate:
1248 void RequestToLockMouse(WebContents* web_contents, 1274 void RequestToLockMouse(WebContents* web_contents,
1249 bool user_gesture, 1275 bool user_gesture,
1250 bool last_unlocked_by_target) override { 1276 bool last_unlocked_by_target) override {
1251 request_to_lock_mouse_called_ = true; 1277 request_to_lock_mouse_called_ = true;
1252 } 1278 }
1253 bool request_to_lock_mouse_called_ = false; 1279 bool request_to_lock_mouse_called_ = false;
1254 }; 1280 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 // Make sure the WebContents cleaned up the previous pending request. A new 1322 // Make sure the WebContents cleaned up the previous pending request. A new
1297 // request should be forwarded to the WebContentsDelegate. 1323 // request should be forwarded to the WebContentsDelegate.
1298 delegate.get()->request_to_lock_mouse_called_ = false; 1324 delegate.get()->request_to_lock_mouse_called_ = false;
1299 ASSERT_TRUE(ExecuteScript(shell(), 1325 ASSERT_TRUE(ExecuteScript(shell(),
1300 "window.domAutomationController.send(document.body." 1326 "window.domAutomationController.send(document.body."
1301 "requestPointerLock());")); 1327 "requestPointerLock());"));
1302 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_); 1328 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_);
1303 } 1329 }
1304 1330
1305 } // namespace content 1331 } // namespace content
OLDNEW
« no previous file with comments | « chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaImageManagerTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698