Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/sync/test/integration/bookmarks_helper.h" | 5 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/run_loop.h" | |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/task/cancelable_task_tracker.h" | 21 #include "base/task/cancelable_task_tracker.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 22 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 23 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
| 23 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | 24 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" |
| 24 #include "chrome/browser/favicon/favicon_service_factory.h" | 25 #include "chrome/browser/favicon/favicon_service_factory.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 node, profile, icon_url, image.As1xPNGBytes()); | 262 node, profile, icon_url, image.As1xPNGBytes()); |
| 262 } | 263 } |
| 263 | 264 |
| 264 // Wait for the favicon for |node| to be invalidated. | 265 // Wait for the favicon for |node| to be invalidated. |
| 265 observer.WaitForSetFavicon(); | 266 observer.WaitForSetFavicon(); |
| 266 // Wait for the BookmarkModel to fetch the updated favicon and for the new | 267 // Wait for the BookmarkModel to fetch the updated favicon and for the new |
| 267 // favicon to be sent to BookmarkChangeProcessor. | 268 // favicon to be sent to BookmarkChangeProcessor. |
| 268 GetFaviconData(model, node); | 269 GetFaviconData(model, node); |
| 269 } | 270 } |
| 270 | 271 |
| 272 void ExpireFaviconImpl(Profile* profile, const BookmarkNode* node) { | |
|
Nicolas Zea
2015/05/14 04:08:23
nit: comment for these two methods and what they'r
pkotwicz
2015/05/14 14:54:36
Done.
| |
| 273 favicon::FaviconService* favicon_service = | |
| 274 FaviconServiceFactory::GetForProfile(profile, | |
| 275 ServiceAccessType::EXPLICIT_ACCESS); | |
| 276 favicon_service->SetFaviconOutOfDateForPage(node->url()); | |
| 277 } | |
| 278 | |
| 279 void OnGotFaviconForExpiryCheck( | |
| 280 const base::Closure& callback, | |
| 281 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | |
| 282 ASSERT_TRUE(bitmap_result.is_valid()); | |
| 283 ASSERT_TRUE(bitmap_result.expired); | |
| 284 callback.Run(); | |
| 285 } | |
| 286 | |
| 271 // Wait for all currently scheduled tasks on the history thread for all | 287 // Wait for all currently scheduled tasks on the history thread for all |
| 272 // profiles to complete and any notifications sent to the UI thread to have | 288 // profiles to complete and any notifications sent to the UI thread to have |
| 273 // finished processing. | 289 // finished processing. |
| 274 void WaitForHistoryToProcessPendingTasks() { | 290 void WaitForHistoryToProcessPendingTasks() { |
| 275 // Skip waiting for history to complete for tests without favicons. | 291 // Skip waiting for history to complete for tests without favicons. |
| 276 if (!urls_with_favicons_) | 292 if (!urls_with_favicons_) |
| 277 return; | 293 return; |
| 278 | 294 |
| 279 std::vector<Profile*> profiles_which_need_to_wait; | 295 std::vector<Profile*> profiles_which_need_to_wait; |
| 280 if (sync_datatype_helper::test()->use_verifier()) | 296 if (sync_datatype_helper::test()->use_verifier()) |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 image, | 593 image, |
| 578 favicon_source); | 594 favicon_source); |
| 579 } | 595 } |
| 580 SetFaviconImpl(sync_datatype_helper::test()->GetProfile(profile), | 596 SetFaviconImpl(sync_datatype_helper::test()->GetProfile(profile), |
| 581 node, | 597 node, |
| 582 icon_url, | 598 icon_url, |
| 583 image, | 599 image, |
| 584 favicon_source); | 600 favicon_source); |
| 585 } | 601 } |
| 586 | 602 |
| 603 void ExpireFavicon(int profile, const BookmarkNode* node) { | |
| 604 BookmarkModel* model = GetBookmarkModel(profile); | |
| 605 ASSERT_EQ(bookmarks::GetBookmarkNodeByID(model, node->id()), node) | |
| 606 << "Node " << node->GetTitle() << " does not belong to " | |
| 607 << "Profile " << profile; | |
| 608 ASSERT_EQ(BookmarkNode::URL, node->type()) << "Node " << node->GetTitle() | |
| 609 << " must be a url."; | |
| 610 ASSERT_EQ(1u, urls_with_favicons_->count(node->url())); | |
| 611 | |
| 612 if (sync_datatype_helper::test()->use_verifier()) { | |
| 613 const BookmarkNode* v_node = nullptr; | |
| 614 FindNodeInVerifier(model, node, &v_node); | |
| 615 ExpireFaviconImpl(sync_datatype_helper::test()->verifier(), node); | |
| 616 } | |
| 617 ExpireFaviconImpl(sync_datatype_helper::test()->GetProfile(profile), node); | |
| 618 | |
| 619 WaitForHistoryToProcessPendingTasks(); | |
| 620 } | |
| 621 | |
| 622 void CheckFaviconExpired(int profile, const GURL& icon_url) { | |
| 623 base::RunLoop run_loop; | |
| 624 | |
| 625 favicon::FaviconService* favicon_service = | |
| 626 FaviconServiceFactory::GetForProfile( | |
| 627 sync_datatype_helper::test()->GetProfile(profile), | |
| 628 ServiceAccessType::EXPLICIT_ACCESS); | |
| 629 base::CancelableTaskTracker task_tracker; | |
| 630 favicon_service->GetRawFavicon( | |
| 631 icon_url, favicon_base::FAVICON, 0, | |
| 632 base::Bind(&OnGotFaviconForExpiryCheck, run_loop.QuitClosure()), | |
| 633 &task_tracker); | |
| 634 | |
| 635 run_loop.Run(); | |
| 636 } | |
| 637 | |
| 587 const BookmarkNode* SetURL(int profile, | 638 const BookmarkNode* SetURL(int profile, |
| 588 const BookmarkNode* node, | 639 const BookmarkNode* node, |
| 589 const GURL& new_url) { | 640 const GURL& new_url) { |
| 590 BookmarkModel* model = GetBookmarkModel(profile); | 641 BookmarkModel* model = GetBookmarkModel(profile); |
| 591 if (bookmarks::GetBookmarkNodeByID(model, node->id()) != node) { | 642 if (bookmarks::GetBookmarkNodeByID(model, node->id()) != node) { |
| 592 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " | 643 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " |
| 593 << "Profile " << profile; | 644 << "Profile " << profile; |
| 594 return NULL; | 645 return NULL; |
| 595 } | 646 } |
| 596 if (sync_datatype_helper::test()->use_verifier()) { | 647 if (sync_datatype_helper::test()->use_verifier()) { |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 | 907 |
| 857 std::string IndexedSubfolderName(int i) { | 908 std::string IndexedSubfolderName(int i) { |
| 858 return base::StringPrintf("Subfolder Name %d", i); | 909 return base::StringPrintf("Subfolder Name %d", i); |
| 859 } | 910 } |
| 860 | 911 |
| 861 std::string IndexedSubsubfolderName(int i) { | 912 std::string IndexedSubsubfolderName(int i) { |
| 862 return base::StringPrintf("Subsubfolder Name %d", i); | 913 return base::StringPrintf("Subsubfolder Name %d", i); |
| 863 } | 914 } |
| 864 | 915 |
| 865 } // namespace bookmarks_helper | 916 } // namespace bookmarks_helper |
| OLD | NEW |