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

Unified Diff: chrome/test/live_sync/bookmark_model_verifier.cc

Issue 5149001: Merge 65840 - Provide sync integration tests with a way to set a favicon for ... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/552d/src/
Patch Set: Created 10 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
« no previous file with comments | « chrome/test/live_sync/bookmark_model_verifier.h ('k') | chrome/test/live_sync/live_bookmarks_sync_test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/live_sync/bookmark_model_verifier.cc
===================================================================
--- chrome/test/live_sync/bookmark_model_verifier.cc (revision 66375)
+++ chrome/test/live_sync/bookmark_model_verifier.cc (working copy)
@@ -11,9 +11,61 @@
#include "base/rand_util.h"
#include "base/string_number_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/bookmarks/bookmark_model_observer.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/browser/sync/glue/bookmark_change_processor.h"
+#include "chrome/test/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+// Helper class used to wait for the favicon of a particular bookmark node in
+// a particular bookmark model to load.
+class FaviconLoadObserver : public BookmarkModelObserver {
+ public:
+ FaviconLoadObserver(BookmarkModel* model, const BookmarkNode* node)
+ : model_(model),
+ node_(node) {
+ model->AddObserver(this);
+ }
+ virtual ~FaviconLoadObserver() {
+ model_->RemoveObserver(this);
+ }
+ void WaitForFaviconLoad() { ui_test_utils::RunMessageLoop(); }
+ virtual void Loaded(BookmarkModel* model) {}
+ virtual void BookmarkNodeMoved(BookmarkModel* model,
+ const BookmarkNode* old_parent,
+ int old_index,
+ const BookmarkNode* new_parent,
+ int new_index) {}
+ virtual void BookmarkNodeAdded(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int index) {}
+ virtual void BookmarkNodeRemoved(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int old_index,
+ const BookmarkNode* node) {}
+ virtual void BookmarkNodeChanged(BookmarkModel* model,
+ const BookmarkNode* node) {
+ if (model == model_ && node == node_)
+ model->GetFavIcon(node);
+ }
+ virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
+ const BookmarkNode* node) {}
+ virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
+ const BookmarkNode* node) {
+ if (model == model_ && node == node_)
+ MessageLoopForUI::current()->Quit();
+ }
+
+ private:
+ BookmarkModel* model_;
+ const BookmarkNode* node_;
+ DISALLOW_COPY_AND_ASSIGN(FaviconLoadObserver);
+};
+
+}
+
// static
bool BookmarkModelVerifier::NodesMatch(const BookmarkNode* node_a,
const BookmarkNode* node_b) {
@@ -30,8 +82,7 @@
// static
bool BookmarkModelVerifier::ModelsMatch(BookmarkModel* model_a,
- BookmarkModel* model_b,
- bool compare_favicons) {
+ BookmarkModel* model_b) {
bool ret_val = true;
TreeNodeIterator<const BookmarkNode> iterator_a(model_a->root_node());
TreeNodeIterator<const BookmarkNode> iterator_b(model_b->root_node());
@@ -40,11 +91,9 @@
EXPECT_TRUE(iterator_b.has_next());
const BookmarkNode* node_b = iterator_b.Next();
ret_val = ret_val && NodesMatch(node_a, node_b);
- if (compare_favicons) {
- const SkBitmap& bitmap_a = model_a->GetFavIcon(node_a);
- const SkBitmap& bitmap_b = model_b->GetFavIcon(node_b);
- ret_val = ret_val && FaviconsMatch(bitmap_a, bitmap_b);
- }
+ const SkBitmap& bitmap_a = model_a->GetFavIcon(node_a);
+ const SkBitmap& bitmap_b = model_b->GetFavIcon(node_b);
+ ret_val = ret_val && FaviconsMatch(bitmap_a, bitmap_b);
}
ret_val = ret_val && (!iterator_b.has_next());
return ret_val;
@@ -52,8 +101,9 @@
bool BookmarkModelVerifier::FaviconsMatch(const SkBitmap& bitmap_a,
const SkBitmap& bitmap_b) {
- if ((bitmap_a.getSize() == (size_t) 0) ||
- (bitmap_a.getSize() != bitmap_b.getSize()) ||
+ if (bitmap_a.getSize() == 0U && bitmap_a.getSize() == 0U)
+ return true;
+ if ((bitmap_a.getSize() != bitmap_b.getSize()) ||
(bitmap_a.width() != bitmap_b.width()) ||
(bitmap_a.height() != bitmap_b.height()))
return false;
@@ -116,7 +166,9 @@
}
const BookmarkNode* BookmarkModelVerifier::AddGroup(BookmarkModel* model,
- const BookmarkNode* parent, int index, const string16& title) {
+ const BookmarkNode* parent,
+ int index,
+ const string16& title) {
const BookmarkNode* result = model->AddGroup(parent, index, title);
EXPECT_TRUE(result);
if (!result)
@@ -167,6 +219,24 @@
model->SetTitle(node, title);
}
+void BookmarkModelVerifier::SetFavicon(
+ BookmarkModel* model,
+ const BookmarkNode* node,
+ const std::vector<unsigned char>& icon_bytes_vector) {
+ if (use_verifier_model_) {
+ const BookmarkNode* v_node = NULL;
+ FindNodeInVerifier(model, node, &v_node);
+ FaviconLoadObserver v_observer(verifier_model_, v_node);
+ browser_sync::BookmarkChangeProcessor::ApplyBookmarkFavicon(
+ v_node, verifier_model_->profile(), icon_bytes_vector);
+ v_observer.WaitForFaviconLoad();
+ }
+ FaviconLoadObserver observer(model, node);
+ browser_sync::BookmarkChangeProcessor::ApplyBookmarkFavicon(
+ node, model->profile(), icon_bytes_vector);
+ observer.WaitForFaviconLoad();
+}
+
void BookmarkModelVerifier::Move(BookmarkModel* model,
const BookmarkNode* node,
const BookmarkNode* new_parent,
« no previous file with comments | « chrome/test/live_sync/bookmark_model_verifier.h ('k') | chrome/test/live_sync/live_bookmarks_sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698