Index: chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc |
diff --git a/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc b/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc |
index f3428134968c1dbb7fd366951de0e14750a1fc70..90ae88db2707016b9091d90984f7ad47f1a84f22 100644 |
--- a/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc |
+++ b/chrome/browser/sync/test/integration/single_client_bookmarks_sync_test.cc |
@@ -6,18 +6,21 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/sync/profile_sync_service.h" |
#include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
+#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h" |
#include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
#include "chrome/browser/sync/test/integration/sync_test.h" |
#include "components/bookmarks/browser/bookmark_model.h" |
#include "sync/test/fake_server/bookmark_entity_builder.h" |
#include "sync/test/fake_server/entity_builder_factory.h" |
#include "sync/test/fake_server/fake_server_verifier.h" |
+#include "sync/test/fake_server/tombstone_entity.h" |
#include "ui/base/layout.h" |
using bookmarks::BookmarkModel; |
using bookmarks::BookmarkNode; |
using bookmarks_helper::AddFolder; |
using bookmarks_helper::AddURL; |
+using bookmarks_helper::AwaitCountBookmarksWithTitlesMatching; |
using bookmarks_helper::CountBookmarksWithTitlesMatching; |
using bookmarks_helper::Create1xFaviconFromPNGFile; |
using bookmarks_helper::GetBookmarkBarNode; |
@@ -31,6 +34,11 @@ using bookmarks_helper::SetFavicon; |
using bookmarks_helper::SetTitle; |
using sync_integration_test_util::AwaitCommitActivityCompletion; |
+// All tests in this file utilize a single profile. |
+// TODO(pvalenzuela): Standardize this pattern by moving this constant to |
+// SyncTest and using it in all single client tests. |
+const int kSingleProfileIndex = 0; |
+ |
class SingleClientBookmarksSyncTest : public SyncTest { |
public: |
SingleClientBookmarksSyncTest() : SyncTest(SINGLE_CLIENT) {} |
@@ -80,22 +88,30 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) { |
// -> http://www.facebook.com "tier1_a_url2" |
// -> tier1_b |
// -> http://www.nhl.com "tier1_b_url0" |
- const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, "top"); |
- const BookmarkNode* tier1_a = AddFolder(0, top, 0, "tier1_a"); |
- const BookmarkNode* tier1_b = AddFolder(0, top, 1, "tier1_b"); |
+ const BookmarkNode* top = AddFolder( |
+ kSingleProfileIndex, GetOtherNode(kSingleProfileIndex), 0, "top"); |
+ const BookmarkNode* tier1_a = AddFolder( |
+ kSingleProfileIndex, top, 0, "tier1_a"); |
+ const BookmarkNode* tier1_b = AddFolder( |
+ kSingleProfileIndex, top, 1, "tier1_b"); |
const BookmarkNode* tier1_a_url0 = AddURL( |
- 0, tier1_a, 0, "tier1_a_url0", GURL("http://mail.google.com")); |
+ kSingleProfileIndex, tier1_a, 0, "tier1_a_url0", |
+ GURL("http://mail.google.com")); |
const BookmarkNode* tier1_a_url1 = AddURL( |
- 0, tier1_a, 1, "tier1_a_url1", GURL("http://www.pandora.com")); |
+ kSingleProfileIndex, tier1_a, 1, "tier1_a_url1", |
+ GURL("http://www.pandora.com")); |
const BookmarkNode* tier1_a_url2 = AddURL( |
- 0, tier1_a, 2, "tier1_a_url2", GURL("http://www.facebook.com")); |
+ kSingleProfileIndex, tier1_a, 2, "tier1_a_url2", |
+ GURL("http://www.facebook.com")); |
const BookmarkNode* tier1_b_url0 = AddURL( |
- 0, tier1_b, 0, "tier1_b_url0", GURL("http://www.nhl.com")); |
+ kSingleProfileIndex, tier1_b, 0, "tier1_b_url0", |
+ GURL("http://www.nhl.com")); |
// Setup sync, wait for its completion, and make sure changes were synced. |
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
// Ultimately we want to end up with the following model; but this test is |
// more about the journey than the destination. |
@@ -118,73 +134,80 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) { |
// -> Toronto Maple Leafs (mapleleafs.nhl.com) |
// -> Wynn (www.wynnlasvegas.com) |
// -> tier1_a_url0 |
- const BookmarkNode* bar = GetBookmarkBarNode(0); |
- const BookmarkNode* cnn = AddURL(0, bar, 0, "CNN", |
- GURL("http://www.cnn.com")); |
+ const BookmarkNode* bar = GetBookmarkBarNode(kSingleProfileIndex); |
+ const BookmarkNode* cnn = AddURL( |
+ kSingleProfileIndex, bar, 0, "CNN", GURL("http://www.cnn.com")); |
ASSERT_TRUE(cnn != NULL); |
- Move(0, tier1_a, bar, 1); |
+ Move(kSingleProfileIndex, tier1_a, bar, 1); |
// Wait for the bookmark position change to sync. |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
- const BookmarkNode* porsche = AddURL(0, bar, 2, "Porsche", |
- GURL("http://www.porsche.com")); |
+ const BookmarkNode* porsche = AddURL( |
+ kSingleProfileIndex, bar, 2, "Porsche", GURL("http://www.porsche.com")); |
// Rearrange stuff in tier1_a. |
ASSERT_EQ(tier1_a, tier1_a_url2->parent()); |
ASSERT_EQ(tier1_a, tier1_a_url1->parent()); |
- Move(0, tier1_a_url2, tier1_a, 0); |
- Move(0, tier1_a_url1, tier1_a, 2); |
+ Move(kSingleProfileIndex, tier1_a_url2, tier1_a, 0); |
+ Move(kSingleProfileIndex, tier1_a_url1, tier1_a, 2); |
// Wait for the rearranged hierarchy to sync. |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
ASSERT_EQ(1, tier1_a_url0->parent()->GetIndexOf(tier1_a_url0)); |
- Move(0, tier1_a_url0, bar, bar->child_count()); |
- const BookmarkNode* boa = AddURL(0, bar, bar->child_count(), |
+ Move(kSingleProfileIndex, tier1_a_url0, bar, bar->child_count()); |
+ const BookmarkNode* boa = AddURL( |
+ kSingleProfileIndex, bar, bar->child_count(), |
"Bank of America", GURL("https://www.bankofamerica.com")); |
ASSERT_TRUE(boa != NULL); |
- Move(0, tier1_a_url0, top, top->child_count()); |
+ Move(kSingleProfileIndex, tier1_a_url0, top, top->child_count()); |
const BookmarkNode* bubble = AddURL( |
- 0, bar, bar->child_count(), "Seattle Bubble", |
+ kSingleProfileIndex, bar, bar->child_count(), "Seattle Bubble", |
GURL("http://seattlebubble.com")); |
ASSERT_TRUE(bubble != NULL); |
- const BookmarkNode* wired = AddURL(0, bar, 2, "Wired News", |
- GURL("http://www.wired.com")); |
+ const BookmarkNode* wired = AddURL( |
+ kSingleProfileIndex, bar, 2, "Wired News", GURL("http://www.wired.com")); |
const BookmarkNode* tier2_b = AddFolder( |
- 0, tier1_b, 0, "tier2_b"); |
- Move(0, tier1_b_url0, tier2_b, 0); |
- Move(0, porsche, bar, 0); |
- SetTitle(0, wired, "News Wired"); |
- SetTitle(0, porsche, "ICanHazPorsche?"); |
+ kSingleProfileIndex, tier1_b, 0, "tier2_b"); |
+ Move(kSingleProfileIndex, tier1_b_url0, tier2_b, 0); |
+ Move(kSingleProfileIndex, porsche, bar, 0); |
+ SetTitle(kSingleProfileIndex, wired, "News Wired"); |
+ SetTitle(kSingleProfileIndex, porsche, "ICanHazPorsche?"); |
// Wait for the title change to sync. |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
ASSERT_EQ(tier1_a_url0->id(), top->GetChild(top->child_count() - 1)->id()); |
- Remove(0, top, top->child_count() - 1); |
- Move(0, wired, tier1_b, 0); |
- Move(0, porsche, bar, 3); |
- const BookmarkNode* tier3_b = AddFolder(0, tier2_b, 1, "tier3_b"); |
+ Remove(kSingleProfileIndex, top, top->child_count() - 1); |
+ Move(kSingleProfileIndex, wired, tier1_b, 0); |
+ Move(kSingleProfileIndex, porsche, bar, 3); |
+ const BookmarkNode* tier3_b = AddFolder( |
+ kSingleProfileIndex, tier2_b, 1, "tier3_b"); |
const BookmarkNode* leafs = AddURL( |
- 0, tier1_a, 0, "Toronto Maple Leafs", GURL("http://mapleleafs.nhl.com")); |
- const BookmarkNode* wynn = AddURL(0, bar, 1, "Wynn", |
- GURL("http://www.wynnlasvegas.com")); |
+ kSingleProfileIndex, tier1_a, 0, "Toronto Maple Leafs", |
+ GURL("http://mapleleafs.nhl.com")); |
+ const BookmarkNode* wynn = AddURL( |
+ kSingleProfileIndex, bar, 1, "Wynn", GURL("http://www.wynnlasvegas.com")); |
- Move(0, wynn, tier3_b, 0); |
- Move(0, leafs, tier3_b, 0); |
+ Move(kSingleProfileIndex, wynn, tier3_b, 0); |
+ Move(kSingleProfileIndex, leafs, tier3_b, 0); |
// Wait for newly added bookmarks to sync. |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
// Only verify FakeServer data if FakeServer is being used. |
// TODO(pvalenzuela): Use this style of verification in more tests once it is |
// proven stable. |
if (GetFakeServer()) |
- VerifyBookmarkModelMatchesFakeServer(0); |
+ VerifyBookmarkModelMatchesFakeServer(kSingleProfileIndex); |
} |
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, InjectedBookmark) { |
@@ -199,7 +222,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, InjectedBookmark) { |
ASSERT_TRUE(SetupClients()); |
ASSERT_TRUE(SetupSync()); |
- ASSERT_EQ(1, CountBookmarksWithTitlesMatching(0, title)); |
+ ASSERT_EQ(1, CountBookmarksWithTitlesMatching(kSingleProfileIndex, title)); |
} |
// Test that a client doesn't mutate the favicon data in the process |
@@ -216,11 +239,11 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, |
ui::SetSupportedScaleFactors(supported_scale_factors); |
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
const GURL page_url("http://www.google.com"); |
const GURL icon_url("http://www.google.com/favicon.ico"); |
- const BookmarkNode* bookmark = AddURL(0, "title", page_url); |
+ const BookmarkNode* bookmark = AddURL(kSingleProfileIndex, "title", page_url); |
// Simulate receiving a favicon from sync encoded by a different PNG encoder |
// than the one native to the OS. This tests the PNG data is not decoded to |
@@ -229,15 +252,17 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, |
gfx::Image original_favicon = Create1xFaviconFromPNGFile( |
"favicon_cocoa_png_codec.png"); |
ASSERT_FALSE(original_favicon.IsEmpty()); |
- SetFavicon(0, bookmark, icon_url, original_favicon, |
+ SetFavicon(kSingleProfileIndex, bookmark, icon_url, original_favicon, |
bookmarks_helper::FROM_SYNC); |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
scoped_refptr<base::RefCountedMemory> original_favicon_bytes = |
original_favicon.As1xPNGBytes(); |
- gfx::Image final_favicon = GetBookmarkModel(0)->GetFavicon(bookmark); |
+ gfx::Image final_favicon = |
+ GetBookmarkModel(kSingleProfileIndex)->GetFavicon(bookmark); |
scoped_refptr<base::RefCountedMemory> final_favicon_bytes = |
final_favicon.As1xPNGBytes(); |
@@ -264,33 +289,77 @@ IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, |
// -> http://yahoo.com |
// -> http://gmail.com |
- const BookmarkNode* folder0 = AddFolder(0, GetOtherNode(0), 0, "folder0"); |
- const BookmarkNode* tier1_a = AddFolder(0, folder0, 0, "tier1_a"); |
- ASSERT_TRUE(AddURL(0, folder0, 1, "News", GURL("http://news.google.com"))); |
- ASSERT_TRUE(AddURL(0, folder0, 2, "Yahoo", GURL("http://www.yahoo.com"))); |
- ASSERT_TRUE(AddURL(0, tier1_a, 0, "Gmai", GURL("http://mail.google.com"))); |
- ASSERT_TRUE(AddURL(0, tier1_a, 1, "Google", GURL("http://www.google.com"))); |
- ASSERT_TRUE( |
- AddURL(0, GetOtherNode(0), 1, "CNN", GURL("http://www.cnn.com"))); |
- |
- ASSERT_TRUE(AddFolder(0, GetBookmarkBarNode(0), 0, "empty_folder")); |
- const BookmarkNode* folder1 = |
- AddFolder(0, GetBookmarkBarNode(0), 1, "folder1"); |
- ASSERT_TRUE(AddURL(0, folder1, 0, "Yahoo", GURL("http://www.yahoo.com"))); |
- ASSERT_TRUE( |
- AddURL(0, GetBookmarkBarNode(0), 2, "Gmai", GURL("http://gmail.com"))); |
+ const BookmarkNode* folder0 = AddFolder( |
+ kSingleProfileIndex, GetOtherNode(kSingleProfileIndex), 0, "folder0"); |
+ const BookmarkNode* tier1_a = AddFolder( |
+ kSingleProfileIndex, folder0, 0, "tier1_a"); |
+ ASSERT_TRUE(AddURL( |
+ kSingleProfileIndex, folder0, 1, "News", GURL("http://news.google.com"))); |
+ ASSERT_TRUE(AddURL( |
+ kSingleProfileIndex, folder0, 2, "Yahoo", GURL("http://www.yahoo.com"))); |
+ ASSERT_TRUE(AddURL( |
+ kSingleProfileIndex, tier1_a, 0, "Gmai", GURL("http://mail.google.com"))); |
+ ASSERT_TRUE(AddURL( |
+ kSingleProfileIndex, tier1_a, 1, "Google", GURL("http://www.google.com"))); |
+ ASSERT_TRUE(AddURL( |
+ kSingleProfileIndex, GetOtherNode(kSingleProfileIndex), 1, "CNN", |
+ GURL("http://www.cnn.com"))); |
+ |
+ ASSERT_TRUE(AddFolder( |
+ kSingleProfileIndex, GetBookmarkBarNode(kSingleProfileIndex), 0, |
+ "empty_folder")); |
+ const BookmarkNode* folder1 = AddFolder( |
+ kSingleProfileIndex, GetBookmarkBarNode(kSingleProfileIndex), 1, |
+ "folder1"); |
+ ASSERT_TRUE(AddURL( |
+ kSingleProfileIndex, folder1, 0, "Yahoo", GURL("http://www.yahoo.com"))); |
+ ASSERT_TRUE(AddURL( |
+ kSingleProfileIndex, GetBookmarkBarNode(0), 2, "Gmai", |
+ GURL("http://gmail.com"))); |
// Set up sync, wait for its completion and verify that changes propagated. |
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
// Remove all bookmarks and wait for sync completion. |
- RemoveAll(0); |
- ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
+ RemoveAll(kSingleProfileIndex); |
+ ASSERT_TRUE(AwaitCommitActivityCompletion( |
+ GetSyncService((kSingleProfileIndex)))); |
// Verify other node has no children now. |
- EXPECT_EQ(0, GetOtherNode(0)->child_count()); |
- EXPECT_EQ(0, GetBookmarkBarNode(0)->child_count()); |
+ EXPECT_EQ(0, GetOtherNode(kSingleProfileIndex)->child_count()); |
+ EXPECT_EQ(0, GetBookmarkBarNode(kSingleProfileIndex)->child_count()); |
// Verify model matches verifier. |
- ASSERT_TRUE(ModelMatchesVerifier(0)); |
+ ASSERT_TRUE(ModelMatchesVerifier(kSingleProfileIndex)); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, |
+ DownloadDeletedBookmark) { |
+ std::string title = "Patrick Star"; |
+ fake_server::EntityBuilderFactory entity_builder_factory; |
+ scoped_ptr<fake_server::FakeServerEntity> entity = |
+ entity_builder_factory.NewBookmarkEntityBuilder( |
+ title, GURL("http://en.wikipedia.org/wiki/Patrick_Star")).Build(); |
+ fake_server_->InjectEntity(entity.Pass()); |
+ |
+ DisableVerifier(); |
+ ASSERT_TRUE(SetupSync()); |
+ |
+ ASSERT_EQ(1, CountBookmarksWithTitlesMatching(kSingleProfileIndex, title)); |
+ |
+ std::vector<sync_pb::SyncEntity> server_bookmarks = |
+ GetFakeServer()->GetSyncEntitiesByModelType(syncer::BOOKMARKS); |
+ ASSERT_EQ(1ul, server_bookmarks.size()); |
+ std::string entity_id = server_bookmarks[0].id_string(); |
+ scoped_ptr<fake_server::FakeServerEntity> tombstone( |
+ fake_server::TombstoneEntity::Create(entity_id)); |
+ GetFakeServer()->InjectEntity(tombstone.Pass()); |
+ |
+ const syncer::ModelTypeSet kBookmarksType(syncer::BOOKMARKS); |
+ TriggerSyncForModelTypes(kSingleProfileIndex, kBookmarksType); |
+ |
+ const int kExpectedCountAfterDeletion = 0; |
+ ASSERT_TRUE(AwaitCountBookmarksWithTitlesMatching( |
+ kSingleProfileIndex, title, kExpectedCountAfterDeletion)); |
} |