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

Unified Diff: chrome/browser/sync/test/integration/bookmarks_helper.cc

Issue 11428004: Sync the bookmark's icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/test/integration/bookmarks_helper.cc
diff --git a/chrome/browser/sync/test/integration/bookmarks_helper.cc b/chrome/browser/sync/test/integration/bookmarks_helper.cc
index 856797dcdde7e9849b635e759a84429ab8c5dae8..608f1072ace3011d6bfd9f03f0a90941376cc96e 100644
--- a/chrome/browser/sync/test/integration/bookmarks_helper.cc
+++ b/chrome/browser/sync/test/integration/bookmarks_helper.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
+#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/profiles/profile.h"
@@ -25,7 +26,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/models/tree_node_iterator.h"
-#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/image/image_skia.h"
using sync_datatype_helper::test;
@@ -163,13 +164,32 @@ bool FaviconBitmapsMatch(const SkBitmap& bitmap_a, const SkBitmap& bitmap_b) {
}
}
-// Gets the favicon associated with |node| in |model|.
-gfx::Image GetFavicon(BookmarkModel* model, const BookmarkNode* node) {
+// Represents a favicon image and the icon URL associated with it.
+struct FaviconData {
+ FaviconData() {
+ }
+
+ FaviconData(const gfx::Image& favicon_image,
+ const GURL& favicon_url)
+ : image(favicon_image),
+ icon_url(favicon_url) {
+ }
+
+ ~FaviconData() {
+ }
+
+ gfx::Image image;
+ GURL icon_url;
+};
+
+// Gets the favicon and icon URL associated with |node| in |model|.
+FaviconData GetFaviconData(BookmarkModel* model,
+ const BookmarkNode* node) {
// If a favicon wasn't explicitly set for a particular URL, simply return its
// blank favicon.
if (!urls_with_favicons_ ||
urls_with_favicons_->find(node->url()) == urls_with_favicons_->end()) {
- return gfx::Image();
+ return FaviconData();
}
// If a favicon was explicitly set, we may need to wait for it to be loaded
// via BookmarkModel::GetFavicon(), which is an asynchronous operation.
@@ -180,13 +200,14 @@ gfx::Image GetFavicon(BookmarkModel* model, const BookmarkNode* node) {
}
EXPECT_TRUE(node->is_favicon_loaded());
EXPECT_FALSE(model->GetFavicon(node).IsEmpty());
- return model->GetFavicon(node);
+ return FaviconData(model->GetFavicon(node), node->icon_url());
}
// Sets the favicon for |profile| and |node|. |profile| may be
// |test()->verifier()|.
void SetFaviconImpl(Profile* profile,
const BookmarkNode* node,
+ const GURL& icon_url,
const gfx::Image& image) {
BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
@@ -195,7 +216,7 @@ void SetFaviconImpl(Profile* profile,
FaviconServiceFactory::GetForProfile(profile,
Profile::EXPLICIT_ACCESS);
favicon_service->SetFavicons(node->url(),
- node->url(),
+ icon_url,
history::FAVICON,
image);
@@ -203,7 +224,7 @@ void SetFaviconImpl(Profile* profile,
observer.WaitForSetFavicon();
// Wait for the BookmarkModel to fetch the updated favicon and for the new
// favicon to be sent to BookmarkChangeProcessor.
- GetFavicon(model, node);
+ GetFaviconData(model, node);
}
// Wait for all currently scheduled tasks on the history thread for all
@@ -241,13 +262,27 @@ bool FaviconsMatch(BookmarkModel* model_a,
BookmarkModel* model_b,
const BookmarkNode* node_a,
const BookmarkNode* node_b) {
- const gfx::Image& bitmap_a = GetFavicon(model_a, node_a);
- const gfx::Image& bitmap_b = GetFavicon(model_b, node_b);
+ FaviconData favicon_data_a = GetFaviconData(model_a, node_a);
+ FaviconData favicon_data_b = GetFaviconData(model_b, node_b);
+
+ if (favicon_data_a.icon_url != favicon_data_b.icon_url)
+ return false;
+
+ gfx::Image image_a = favicon_data_a.image;
+ gfx::Image image_b = favicon_data_b.image;
- if (bitmap_a.IsEmpty() && bitmap_b.IsEmpty())
+ if (image_a.IsEmpty() && image_b.IsEmpty())
return true; // Two empty images are equivalent.
- return !bitmap_a.IsEmpty() && !bitmap_b.IsEmpty() &&
- FaviconBitmapsMatch(*bitmap_a.ToSkBitmap(), *bitmap_b.ToSkBitmap());
+
+ if (image_a.IsEmpty() != image_b.IsEmpty())
+ return false;
+
+ // Compare only the 1x bitmaps as only those are synced.
+ SkBitmap bitmap_a = image_a.AsImageSkia().GetRepresentation(
+ ui::SCALE_FACTOR_100P).sk_bitmap();
+ SkBitmap bitmap_b = image_b.AsImageSkia().GetRepresentation(
+ ui::SCALE_FACTOR_100P).sk_bitmap();
+ return FaviconBitmapsMatch(bitmap_a, bitmap_b);
}
// Does a deep comparison of BookmarkNode fields in |model_a| and |model_b|.
@@ -457,10 +492,8 @@ void SetTitle(int profile,
void SetFavicon(int profile,
const BookmarkNode* node,
- const std::vector<unsigned char>& icon_bytes_vector) {
- scoped_refptr<base::RefCountedBytes> bitmap_data(
- new base::RefCountedBytes(icon_bytes_vector));
- gfx::Image image(bitmap_data->front(), bitmap_data->size());
+ const GURL& icon_url,
+ const gfx::Image& image) {
ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node)
<< "Node " << node->GetTitle() << " does not belong to "
<< "Profile " << profile;
@@ -472,9 +505,9 @@ void SetFavicon(int profile,
if (test()->use_verifier()) {
const BookmarkNode* v_node = NULL;
FindNodeInVerifier(GetBookmarkModel(profile), node, &v_node);
- SetFaviconImpl(test()->verifier(), v_node, image);
+ SetFaviconImpl(test()->verifier(), v_node, icon_url, image);
}
- SetFaviconImpl(test()->GetProfile(profile), node, image);
+ SetFaviconImpl(test()->GetProfile(profile), node, icon_url, image);
}
const BookmarkNode* SetURL(int profile,
@@ -653,22 +686,23 @@ int CountFoldersWithTitlesMatching(int profile, const std::wstring& title) {
WideToUTF16(title));
}
-std::vector<unsigned char> CreateFavicon(int seed) {
- const int w = 16;
- const int h = 16;
- SkBitmap bmp;
- bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h);
- bmp.allocPixels();
- uint32_t* src_data = bmp.getAddr32(0, 0);
- for (int i = 0; i < w * h; ++i) {
- src_data[i] = SkPreMultiplyARGB((seed + i) % 255,
- (seed + i) % 250,
- (seed + i) % 245,
- (seed + i) % 240);
- }
- std::vector<unsigned char> favicon;
- gfx::PNGCodec::EncodeBGRASkBitmap(bmp, false, &favicon);
- return favicon;
+gfx::Image CreateFavicon(SkColor color) {
+ const int dip_width = 16;
+ const int dip_height = 16;
+ std::vector<ui::ScaleFactor> favicon_scale_factors =
+ FaviconUtil::GetFaviconScaleFactors();
+ gfx::ImageSkia favicon;
+ for (size_t i = 0; i < favicon_scale_factors.size(); ++i) {
+ float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]);
+ int pixel_width = dip_width * scale;
+ int pixel_height = dip_height * scale;
+ SkBitmap bmp;
+ bmp.setConfig(SkBitmap::kARGB_8888_Config, pixel_width, pixel_height);
+ bmp.allocPixels();
+ bmp.eraseColor(color);
+ favicon.AddRepresentation(gfx::ImageSkiaRep(bmp, favicon_scale_factors[i]));
+ }
+ return gfx::Image(favicon);
}
std::string IndexedURL(int i) {

Powered by Google App Engine
This is Rietveld 408576698