Commit c956a156 authored by shadi's avatar shadi Committed by Commit bot

Add new E2E sync multi profiles tests. This should not affect any existing

test cases.

The multi profiles tests creates multiple profiles each in different user data
dirs and signs in each one separately. Then each profile performs sync related
operations and verifies results on the other sync'ed profile.

The CL also adds some helper functions to force a client to do a sync cycle.

Note: These tests are DISABLED and do not run on the normal bots.

BUG=431366

Review URL: https://codereview.chromium.org/772513004

Cr-Commit-Position: refs/heads/master@{#311534}
parent c12e5564
......@@ -154,6 +154,20 @@ int CountNodesWithTitlesMatching(BookmarkModel* model,
return count;
}
// Returns the number of nodes of node type |node_type| in |model|.
int CountNodes(BookmarkModel* model, BookmarkNode::Type node_type) {
ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
// Walk through the model tree looking for bookmark nodes of node type
// |node_type|.
int count = 0;
while (iterator.has_next()) {
const BookmarkNode* node = iterator.Next();
if (node->type() == node_type)
++count;
}
return count;
}
// Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent.
// Returns true if they match.
bool FaviconRawBitmapsMatch(const SkBitmap& bitmap_a,
......@@ -774,6 +788,10 @@ const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) {
return nodes[0];
}
int CountAllBookmarks(int profile) {
return CountNodes(GetBookmarkModel(profile), BookmarkNode::URL);
}
int CountBookmarksWithTitlesMatching(int profile, const std::string& title) {
return CountNodesWithTitlesMatching(GetBookmarkModel(profile),
BookmarkNode::URL,
......
......@@ -171,6 +171,9 @@ const BookmarkNode* GetUniqueNodeByURL(
int profile,
const GURL& url) WARN_UNUSED_RESULT;
// Returns the number of bookmarks in bookmark model of profile |profile|.
int CountAllBookmarks(int profile) WARN_UNUSED_RESULT;
// Returns the number of bookmarks in bookmark model of profile |profile|
// whose titles match the string |title|.
int CountBookmarksWithTitlesMatching(
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sync/test/integration/p2p_sync_refresher.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "content/public/browser/notification_service.h"
#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
P2PSyncRefresher::P2PSyncRefresher(ProfileSyncService* sync_service)
: sync_service_(sync_service){
sync_service_->AddObserver(this);
}
P2PSyncRefresher::~P2PSyncRefresher() {
sync_service_->RemoveObserver(this);
}
void P2PSyncRefresher::OnStateChanged() {}
void P2PSyncRefresher::OnSyncCycleCompleted() {
const syncer::sessions::SyncSessionSnapshot& snap =
sync_service_->GetLastSessionSnapshot();
bool is_notifiable_commit =
(snap.model_neutral_state().num_successful_commits > 0);
if (is_notifiable_commit) {
syncer::ModelTypeSet model_types =
snap.model_neutral_state().commit_request_types;
SyncTest* test = sync_datatype_helper::test();
for (int i = 0; i < test->num_clients(); ++i) {
if (sync_service_->profile() != test->GetProfile(i)) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
content::Source<Profile>(test->GetProfile(i)),
content::Details<const syncer::ModelTypeSet>(&model_types));
}
}
}
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_P2P_SYNC_REFRESHER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_P2P_SYNC_REFRESHER_H_
#include "base/basictypes.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
class ProfileSyncService;
// This class observes ProfileSyncService events and emits refresh notifications
// to other test profiles for any committed changes it observes.
//
// It register and unregisters in its constructor and destructor. This is
// intended to make it easy to manage with a scoped_ptr.
class P2PSyncRefresher : public ProfileSyncServiceObserver {
public:
explicit P2PSyncRefresher(ProfileSyncService* sync_service);
~P2PSyncRefresher() override;
// Implementation of ProfileSyncServiceObserver
void OnStateChanged() override;
void OnSyncCycleCompleted() override;
private:
ProfileSyncService* sync_service_;
DISALLOW_COPY_AND_ASSIGN(P2PSyncRefresher);
};
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_P2P_SYNC_REFRESHER_H_
......@@ -14,6 +14,7 @@ class SingleClientE2ETest : public SyncTest {
DISALLOW_COPY_AND_ASSIGN(SingleClientE2ETest);
};
// http://crbug.com/431366
IN_PROC_BROWSER_TEST_F(SingleClientE2ETest, DISABLED_SanitySetup) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
// TODO(shadi): Add AwaitCommitActivityCompletion() once GCM servers are added
......
......@@ -34,6 +34,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/test/integration/fake_server_invalidation_service.h"
#include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h"
#include "chrome/browser/sync/test/integration/p2p_sync_refresher.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
......@@ -387,6 +388,7 @@ bool SyncTest::SetupClients() {
browsers_.resize(num_clients_);
clients_.resize(num_clients_);
invalidation_forwarders_.resize(num_clients_);
sync_refreshers_.resize(num_clients_);
fake_server_invalidation_services_.resize(num_clients_);
for (int i = 0; i < num_clients_; ++i) {
InitializeInstance(i);
......@@ -482,7 +484,8 @@ void SyncTest::InitializeInvalidations(int index) {
fake_server_invalidation_services_[index] = invalidation_service;
} else if (server_type_ == EXTERNAL_LIVE_SERVER) {
// DO NOTHING. External live sync servers use GCM to notify profiles of any
// invalidations in sync'ed data.
// invalidations in sync'ed data. In this case, to notify other profiles of
// invalidations, we use sync refresh notifications instead.
} else {
invalidation::P2PInvalidationService* p2p_invalidation_service =
static_cast<invalidation::P2PInvalidationService*>(
......@@ -526,6 +529,19 @@ bool SyncTest::SetupSync() {
AwaitQuiescence();
}
// SyncRefresher is used instead of invalidations to notify other profiles to
// do a sync refresh on committed data sets. This is only needed when running
// tests against external live server, otherwise invalidation service is used.
// With external live servers, the profiles commit data on first sync cycle
// automatically after signing in. To avoid misleading sync commit
// notifications at start up, we start the SyncRefresher observers post
// client set up.
if (server_type_ == EXTERNAL_LIVE_SERVER) {
for (int i = 0; i < num_clients_; ++i) {
sync_refreshers_[i] = new P2PSyncRefresher(clients_[i]->service());
}
}
return true;
}
......@@ -553,6 +569,7 @@ void SyncTest::TearDownOnMainThread() {
// corruption in QuitBrowser().
CHECK_EQ(0U, chrome::GetTotalBrowserCount());
invalidation_forwarders_.clear();
sync_refreshers_.clear();
fake_server_invalidation_services_.clear();
clients_.clear();
}
......
......@@ -26,6 +26,7 @@
class ProfileSyncService;
class ProfileSyncServiceHarness;
class P2PInvalidationForwarder;
class P2PSyncRefresher;
namespace base {
class CommandLine;
......@@ -365,6 +366,10 @@ class SyncTest : public InProcessBrowserTest {
// of this activity to its peer sync clients.
ScopedVector<P2PInvalidationForwarder> invalidation_forwarders_;
// A set of objects to listen for commit activity and broadcast refresh
// notifications of this activity to its peer sync clients.
ScopedVector<P2PSyncRefresher> sync_refreshers_;
// Collection of pointers to FakeServerInvalidation objects for each profile.
std::vector<fake_server::FakeServerInvalidationService*>
fake_server_invalidation_services_;
......
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/stringprintf.h"
#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
// The E2E tests are designed to run only against real backend servers. They are
// disabled on regular bots. http://crbug.com/431366
#define E2E_ONLY(x) DISABLED_##x
using bookmarks_helper::AddURL;
using bookmarks_helper::AwaitAllModelsMatch;
using bookmarks_helper::CountAllBookmarks;
class TwoClientE2ETest : public SyncTest {
public:
TwoClientE2ETest() : SyncTest(TWO_CLIENT) {}
~TwoClientE2ETest() override {}
bool TestUsesSelfNotifications() override { return false; }
private:
DISALLOW_COPY_AND_ASSIGN(TwoClientE2ETest);
};
IN_PROC_BROWSER_TEST_F(TwoClientE2ETest, E2E_ONLY(SanitySetup)) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
}
IN_PROC_BROWSER_TEST_F(TwoClientE2ETest, E2E_ONLY(OneClientAddsBookmark)) {
DisableVerifier();
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
// All profiles should sync same bookmarks.
ASSERT_TRUE(AwaitAllModelsMatch()) <<
"Initial bookmark models did not match for all profiles";
// For clean profiles, the bookmarks count should be zero. We are not
// enforcing this, we only check that the final count is equal to initial
// count plus new bookmarks count.
int init_bookmarks_count = CountAllBookmarks(0);
// Add one new bookmark to the first profile.
ASSERT_TRUE(
AddURL(0, "Google URL 0", GURL("http://www.google.com/0")) != NULL);
// Blocks and waits for bookmarks models in all profiles to match.
ASSERT_TRUE(AwaitAllModelsMatch());
// Check that total number of bookmarks is as expected.
for (int i = 0; i < num_clients(); ++i) {
ASSERT_EQ(CountAllBookmarks(i), init_bookmarks_count + 1) <<
"Total bookmark count is wrong.";
}
}
IN_PROC_BROWSER_TEST_F(TwoClientE2ETest, E2E_ONLY(TwoClientsAddBookmarks)) {
DisableVerifier();
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
// ALl profiles should sync same bookmarks.
ASSERT_TRUE(AwaitAllModelsMatch()) <<
"Initial bookmark models did not match for all profiles";
// For clean profiles, the bookmarks count should be zero. We are not
// enforcing this, we only check that the final count is equal to initial
// count plus new bookmarks count.
int init_bookmarks_count = CountAllBookmarks(0);
// Add one new bookmark per profile.
for (int i = 0; i < num_clients(); ++i) {
ASSERT_TRUE(AddURL(i, base::StringPrintf("Google URL %d", i),
GURL(base::StringPrintf("http://www.google.com/%d", i))) != NULL);
}
// Blocks and waits for bookmarks models in all profiles to match.
ASSERT_TRUE(AwaitAllModelsMatch());
// Check that total number of bookmarks is as expected.
for (int i = 0; i < num_clients(); ++i) {
ASSERT_EQ(CountAllBookmarks(i), init_bookmarks_count + num_clients()) <<
"Total bookmark count is wrong.";
}
}
......@@ -1312,6 +1312,7 @@
'browser/sync/test/integration/two_client_autofill_sync_test.cc',
'browser/sync/test/integration/two_client_bookmarks_sync_test.cc',
'browser/sync/test/integration/two_client_dictionary_sync_test.cc',
'browser/sync/test/integration/two_client_e2e_test.cc',
'browser/sync/test/integration/two_client_extension_settings_and_app_settings_sync_test.cc',
'browser/sync/test/integration/two_client_extensions_sync_test.cc',
'browser/sync/test/integration/two_client_passwords_sync_test.cc',
......@@ -1349,6 +1350,8 @@
'browser/sync/test/integration/passwords_helper.h',
'browser/sync/test/integration/p2p_invalidation_forwarder.cc',
'browser/sync/test/integration/p2p_invalidation_forwarder.h',
'browser/sync/test/integration/p2p_sync_refresher.cc',
'browser/sync/test/integration/p2p_sync_refresher.h',
'browser/sync/test/integration/preferences_helper.cc',
'browser/sync/test/integration/preferences_helper.h',
'browser/sync/test/integration/profile_sync_service_harness.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment