Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon/content/content_favicon_driver.h" | 5 #include "components/favicon/content/content_favicon_driver.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 content::WebContents* web_contents() { | 172 content::WebContents* web_contents() { |
| 173 return browser()->tab_strip_model()->GetActiveWebContents(); | 173 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // FaviconDriverPendingTaskChecker: | 176 // FaviconDriverPendingTaskChecker: |
| 177 bool HasPendingTasks() override { | 177 bool HasPendingTasks() override { |
| 178 return favicon::ContentFaviconDriver::FromWebContents(web_contents()) | 178 return favicon::ContentFaviconDriver::FromWebContents(web_contents()) |
| 179 ->HasPendingTasksForTest(); | 179 ->HasPendingTasksForTest(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 favicon_base::FaviconRawBitmapResult GetFaviconForPageURL(const GURL& url) { | 182 favicon_base::FaviconRawBitmapResult GetFaviconForPageURL( |
| 183 const GURL& url, | |
| 184 favicon_base::IconType icon_type) { | |
| 183 favicon::FaviconService* favicon_service = | 185 favicon::FaviconService* favicon_service = |
| 184 FaviconServiceFactory::GetForProfile( | 186 FaviconServiceFactory::GetForProfile( |
| 185 browser()->profile(), ServiceAccessType::EXPLICIT_ACCESS); | 187 browser()->profile(), ServiceAccessType::EXPLICIT_ACCESS); |
| 186 | 188 |
| 187 std::vector<favicon_base::FaviconRawBitmapResult> results; | 189 std::vector<favicon_base::FaviconRawBitmapResult> results; |
| 188 base::CancelableTaskTracker tracker; | 190 base::CancelableTaskTracker tracker; |
| 189 base::RunLoop loop; | 191 base::RunLoop loop; |
| 190 favicon_service->GetFaviconForPageURL( | 192 favicon_service->GetFaviconForPageURL( |
| 191 url, favicon_base::FAVICON, /*desired_size_in_dip=*/0, | 193 url, icon_type, /*desired_size_in_dip=*/0, |
| 192 base::Bind( | 194 base::Bind( |
| 193 [](std::vector<favicon_base::FaviconRawBitmapResult>* save_results, | 195 [](std::vector<favicon_base::FaviconRawBitmapResult>* save_results, |
| 194 base::RunLoop* loop, | 196 base::RunLoop* loop, |
| 195 const std::vector<favicon_base::FaviconRawBitmapResult>& | 197 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 196 results) { | 198 results) { |
| 197 *save_results = results; | 199 *save_results = results; |
| 198 loop->Quit(); | 200 loop->Quit(); |
| 199 }, | 201 }, |
| 200 &results, &loop), | 202 &results, &loop), |
| 201 &tracker); | 203 &tracker); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 content::ResourceDispatcherHost::Get()->SetDelegate(delegate.get()); | 276 content::ResourceDispatcherHost::Get()->SetDelegate(delegate.get()); |
| 275 | 277 |
| 276 PendingTaskWaiter waiter(web_contents(), this); | 278 PendingTaskWaiter waiter(web_contents(), this); |
| 277 ui_test_utils::NavigateToURLWithDisposition( | 279 ui_test_utils::NavigateToURLWithDisposition( |
| 278 browser(), url, WindowOpenDisposition::CURRENT_TAB, | 280 browser(), url, WindowOpenDisposition::CURRENT_TAB, |
| 279 ui_test_utils::BROWSER_TEST_NONE); | 281 ui_test_utils::BROWSER_TEST_NONE); |
| 280 waiter.Wait(); | 282 waiter.Wait(); |
| 281 | 283 |
| 282 #if defined(OS_ANDROID) || defined(OS_IOS) | 284 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 283 EXPECT_TRUE(delegate->was_requested()); | 285 EXPECT_TRUE(delegate->was_requested()); |
| 286 EXPECT_NE( | |
| 287 nullptr, | |
| 288 GetFaviconForPageURL(url, favicon_base::WEB_MANIFEST_ICON).bitmap_data); | |
| 284 #else | 289 #else |
| 285 EXPECT_FALSE(delegate->was_requested()); | 290 EXPECT_FALSE(delegate->was_requested()); |
| 286 #endif | 291 #endif |
| 287 } | 292 } |
| 288 | 293 |
| 289 // Test that loading a page that contains a Web Manifest without icons and a | 294 // Test that loading a page that contains a Web Manifest without icons and a |
| 290 // regular favicon in the HTML reports the icon. The regular icon is initially | 295 // regular favicon in the HTML reports the icon. The regular icon is initially |
| 291 // cached in the Favicon database. | 296 // cached in the Favicon database. |
| 292 IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, | 297 IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, |
| 293 LoadRegularIconDespiteWebManifestWithoutIcons) { | 298 LoadRegularIconDespiteWebManifestWithoutIcons) { |
| 294 ASSERT_TRUE(embedded_test_server()->Start()); | 299 ASSERT_TRUE(embedded_test_server()->Start()); |
| 295 GURL url = embedded_test_server()->GetURL( | 300 GURL url = embedded_test_server()->GetURL( |
| 296 "/favicon/page_with_manifest_without_icons.html"); | 301 "/favicon/page_with_manifest_without_icons.html"); |
| 297 GURL icon_url = embedded_test_server()->GetURL("/favicon/icon.png"); | 302 GURL icon_url = embedded_test_server()->GetURL("/favicon/icon.png"); |
| 298 | 303 |
| 299 // Initial visit with the feature still disabled, to populate the cache. | 304 // Initial visit with the feature still disabled, to populate the cache. |
| 300 { | 305 { |
| 301 PendingTaskWaiter waiter(web_contents(), this); | 306 PendingTaskWaiter waiter(web_contents(), this); |
| 302 ui_test_utils::NavigateToURLWithDisposition( | 307 ui_test_utils::NavigateToURLWithDisposition( |
| 303 browser(), url, WindowOpenDisposition::CURRENT_TAB, | 308 browser(), url, WindowOpenDisposition::CURRENT_TAB, |
| 304 ui_test_utils::BROWSER_TEST_NONE); | 309 ui_test_utils::BROWSER_TEST_NONE); |
| 305 waiter.Wait(); | 310 waiter.Wait(); |
| 306 } | 311 } |
| 307 ASSERT_NE(nullptr, GetFaviconForPageURL(url).bitmap_data); | 312 ASSERT_NE(nullptr, |
| 313 GetFaviconForPageURL(url, favicon_base::FAVICON).bitmap_data); | |
| 308 | 314 |
| 309 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 315 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
| 310 | 316 |
| 311 // Enable the feature and visit the page again. | 317 // Enable the feature and visit the page again. |
| 312 base::test::ScopedFeatureList override_features; | 318 base::test::ScopedFeatureList override_features; |
| 313 override_features.InitAndEnableFeature(favicon::kFaviconsFromWebManifest); | 319 override_features.InitAndEnableFeature(favicon::kFaviconsFromWebManifest); |
| 314 | 320 |
| 315 { | 321 { |
| 316 PendingTaskWaiter waiter(web_contents(), this); | 322 PendingTaskWaiter waiter(web_contents(), this); |
| 317 ui_test_utils::NavigateToURLWithDisposition( | 323 ui_test_utils::NavigateToURLWithDisposition( |
| 318 browser(), url, WindowOpenDisposition::CURRENT_TAB, | 324 browser(), url, WindowOpenDisposition::CURRENT_TAB, |
| 319 ui_test_utils::BROWSER_TEST_NONE); | 325 ui_test_utils::BROWSER_TEST_NONE); |
| 320 waiter.Wait(); | 326 waiter.Wait(); |
| 321 } | 327 } |
| 322 | 328 |
| 323 EXPECT_NE(nullptr, GetFaviconForPageURL(url).bitmap_data); | 329 EXPECT_NE(nullptr, |
| 330 GetFaviconForPageURL(url, favicon_base::FAVICON).bitmap_data); | |
| 324 } | 331 } |
| 332 | |
| 333 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 334 IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, | |
| 335 LoadIconFromWebManifestDespitePushState) { | |
| 336 base::test::ScopedFeatureList override_features; | |
| 337 override_features.InitAndEnableFeature(favicon::kFaviconsFromWebManifest); | |
| 338 | |
| 339 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 340 GURL url = | |
| 341 embedded_test_server()->GetURL("/favicon/pushstate_with_manifest.html"); | |
| 342 GURL pushstate_url = embedded_test_server()->GetURL( | |
| 343 "/favicon/pushstate_with_manifest.html#pushState"); | |
| 344 | |
| 345 PendingTaskWaiter waiter(web_contents(), this); | |
| 346 ui_test_utils::NavigateToURLWithDisposition( | |
| 347 browser(), url, WindowOpenDisposition::CURRENT_TAB, | |
| 348 ui_test_utils::BROWSER_TEST_NONE); | |
|
pkotwicz
2017/06/21 18:48:34
You should probably wait till the JavaScript has e
| |
| 349 waiter.Wait(); | |
| 350 | |
| 351 EXPECT_NE(nullptr, | |
| 352 GetFaviconForPageURL(pushstate_url, favicon_base::WEB_MANIFEST_ICON) | |
| 353 .bitmap_data); | |
| 354 } | |
| 355 #endif | |
| OLD | NEW |