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: | |
| 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; | |
|
pkotwicz
2016/07/05 19:05:04
Nit: You do not need line 1188 anymore
Zhiqiang Zhang (Slow)
2016/07/05 19:23:20
Done.
| |
| 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 ON_CALL(download_image_observer, OnFinishDownloadImage(_, _, _, _, _)) | |
| 1199 .WillByDefault(InvokeWithoutArgs([&]() { | |
| 1200 loop_runner->Quit(); | |
| 1201 })); | |
|
pkotwicz
2016/07/05 19:05:04
Nit: The indentation of line 1201 looks off.
Zhiqiang Zhang (Slow)
2016/07/05 19:23:20
This seems to be because of the lambda. I now use
| |
| 1202 | |
| 1203 shell->LoadURL(GURL("about:blank")); | |
| 1204 shell->web_contents()->DownloadImage( | |
| 1205 image_url, false, 1024, false, | |
| 1206 base::Bind(&DownloadImageObserver::OnFinishDownloadImage, | |
| 1207 base::Unretained(&download_image_observer))); | |
| 1208 | |
| 1209 // Wait for response. | |
| 1210 loop_runner->Run(); | |
| 1211 } | |
| 1212 | |
| 1213 } // anonymous namespace | |
| 1214 | |
| 1215 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
| 1216 DownloadImage_HttpImage) { | |
| 1217 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1218 const GURL kImageUrl = | |
| 1219 embedded_test_server()->GetURL("/image.jpg"); | |
| 1220 DownloadImageTestInternal(shell(), kImageUrl, 200); | |
| 1221 } | |
| 1222 | |
| 1223 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
| 1224 DownloadImage_Deny_FileImage) { | |
| 1225 const GURL kImageUrl = | |
| 1226 GetTestUrl("", "image.jpg"); | |
| 1227 DownloadImageTestInternal(shell(), kImageUrl, 0); | |
| 1228 } | |
| 1229 | |
| 1170 } // namespace content | 1230 } // namespace content |
| OLD | NEW |