diff options
author | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-11 20:09:13 +0000 |
---|---|---|
committer | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-11 20:09:13 +0000 |
commit | 0d1f08ac7aba23350d38a51af687e4d44b7e65a5 (patch) | |
tree | fa3a5a3a0934a9ef9fa5346889c44cadcf3597aa /chrome/test | |
parent | 4d48e55311d19ba96607ffc658acd961abc6f534 (diff) | |
download | chromium_src-0d1f08ac7aba23350d38a51af687e4d44b7e65a5.zip chromium_src-0d1f08ac7aba23350d38a51af687e4d44b7e65a5.tar.gz chromium_src-0d1f08ac7aba23350d38a51af687e4d44b7e65a5.tar.bz2 |
Provide sync integration tests with a way to set a favicon for a bookmark.
The sync integration test framework does not provide tests with a way to
set a favicon for a bookmark and verify that it gets synced.
This patch adds a method called SetFavicon, that allows tests to set
either a generic favicon, or a variable favicon (using an index) for a
bookmark.
BUG=57234
TEST=sync_integration_tests
Review URL: http://codereview.chromium.org/4749003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/live_sync/bookmark_model_verifier.cc | 90 | ||||
-rw-r--r-- | chrome/test/live_sync/bookmark_model_verifier.h | 20 | ||||
-rw-r--r-- | chrome/test/live_sync/live_bookmarks_sync_test.h | 35 | ||||
-rw-r--r-- | chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc | 21 |
4 files changed, 146 insertions, 20 deletions
diff --git a/chrome/test/live_sync/bookmark_model_verifier.cc b/chrome/test/live_sync/bookmark_model_verifier.cc index 16f027d..ae99f71 100644 --- a/chrome/test/live_sync/bookmark_model_verifier.cc +++ b/chrome/test/live_sync/bookmark_model_verifier.cc @@ -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 @@ bool BookmarkModelVerifier::NodesMatch(const BookmarkNode* node_a, // 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 @@ bool BookmarkModelVerifier::ModelsMatch(BookmarkModel* model_a, 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::ModelsMatch(BookmarkModel* model_a, 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; @@ -133,7 +183,9 @@ void BookmarkModelVerifier::FindNodeInVerifier(BookmarkModel* foreign_model, } 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) @@ -184,6 +236,24 @@ void BookmarkModelVerifier::SetTitle(BookmarkModel* model, 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, diff --git a/chrome/test/live_sync/bookmark_model_verifier.h b/chrome/test/live_sync/bookmark_model_verifier.h index 3051ddc..5ba3dd1 100644 --- a/chrome/test/live_sync/bookmark_model_verifier.h +++ b/chrome/test/live_sync/bookmark_model_verifier.h @@ -7,6 +7,7 @@ #pragma once #include <string> +#include <vector> #include "base/compiler_specific.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -29,18 +30,10 @@ class BookmarkModelVerifier { ~BookmarkModelVerifier() {} // Checks if the hierarchies in |model_a| and |model_b| are equivalent in - // terms of the data model. Compares favicons if |compare_favicons| is true. - // Returns true if they match. + // terms of the data model and favicon. Returns true if they both match. // Note: Some peripheral fields like creation times are allowed to mismatch. static bool ModelsMatch(BookmarkModel* model_a, - BookmarkModel* model_b, - bool compare_favicons) WARN_UNUSED_RESULT; - - // Same as the above method, but does not check if the favicons match. - static bool ModelsMatch(BookmarkModel* model_a, - BookmarkModel* model_b) WARN_UNUSED_RESULT { - return ModelsMatch(model_a, model_b, false); - } + BookmarkModel* model_b) WARN_UNUSED_RESULT; // Checks if |model| contains any instances of two bookmarks with the same URL // under the same parent folder. Returns true if even one instance is found. @@ -71,6 +64,13 @@ class BookmarkModelVerifier { const BookmarkNode* node, const string16& title); + // Sets the favicon of the same node in |model| and |verifier_model_| using + // the data in |icon_bytes_vector|. + // See BookmarkChangeProcessor::ApplyBookmarkFavicon for details. + void SetFavicon(BookmarkModel* model, + const BookmarkNode* node, + const std::vector<unsigned char>& icon_bytes_vector); + // Moves the same node to the same position in both |model| and // |verifier_model_|. See BookmarkModel::Move for details. void Move(BookmarkModel* model, diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.h b/chrome/test/live_sync/live_bookmarks_sync_test.h index e34bf4d..b3ac273 100644 --- a/chrome/test/live_sync/live_bookmarks_sync_test.h +++ b/chrome/test/live_sync/live_bookmarks_sync_test.h @@ -14,8 +14,10 @@ #include "chrome/test/live_sync/bookmark_model_verifier.h" #include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/ui_test_utils.h" +#include "gfx/codec/png_codec.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" class LiveBookmarksSyncTest : public LiveSyncTest { public: @@ -140,6 +142,20 @@ class LiveBookmarksSyncTest : public LiveSyncTest { GetBookmarkModel(profile), node, WideToUTF16(new_title)); } + // Sets the favicon of the node |node| (of type BookmarkNode::URL) in the + // bookmark model of profile |profile| using the data in |icon_bytes_vector|. + void SetFavicon(int profile, + const BookmarkNode* node, + const std::vector<unsigned char>& icon_bytes_vector) { + ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) + << "Node " << node->GetTitle() << " does not belong to " + << "Profile " << profile; + ASSERT_EQ(BookmarkNode::URL, node->type()) + << "Node " << node->GetTitle() << " must be a url."; + verifier_helper_->SetFavicon( + GetBookmarkModel(profile), node, icon_bytes_vector); + } + // Changes the url of the node |node| in the bookmark model of profile // |profile| to |new_url|. Returns a pointer to the node with the changed url. const BookmarkNode* SetURL(int profile, @@ -278,6 +294,25 @@ class LiveBookmarksSyncTest : public LiveSyncTest { GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title)); } + // Creates a unique favicon using |seed|. + static 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; + } + private: // Helper object that has the functionality to verify changes made to the // bookmarks of individual profiles. diff --git a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc index d91258f..b737d9f 100644 --- a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc @@ -32,6 +32,14 @@ static std::wstring IndexedSubsubfolderName(int i) { return StringPrintf(L"Subsubfolder Name %d", i); } +const std::vector<unsigned char> GenericFavicon() { + return LiveBookmarksSyncTest::CreateFavicon(254); +} + +const std::vector<unsigned char> IndexedFavicon(int i) { + return LiveBookmarksSyncTest::CreateFavicon(i); +} + IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, Sanity) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(AllModelsMatchVerifier()); @@ -112,6 +120,19 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, ASSERT_TRUE(AllModelsMatchVerifier()); } +// Test Scribe ID - 370489. +IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, + SC_AddFirstBMWithFavicon) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AllModelsMatchVerifier()); + + const BookmarkNode* bookmark = AddURL(0, kGenericURLTitle, GURL(kGenericURL)); + ASSERT_TRUE(bookmark != NULL); + SetFavicon(0, bookmark, GenericFavicon()); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AllModelsMatchVerifier()); +} + // Test Scribe ID - 370560. IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, SC_AddNonHTTPBMs) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |