This source file includes following definitions.
- CheckClientsEqual
- CheckNoDuplicateVisits
- GetVisitCountForFirstURL
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/i18n/number_formatting.h"
#include "base/memory/scoped_vector.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/typed_urls_helper.h"
using base::ASCIIToUTF16;
using sync_integration_test_util::AwaitCommitActivityCompletion;
using typed_urls_helper::AddUrlToHistory;
using typed_urls_helper::AddUrlToHistoryWithTimestamp;
using typed_urls_helper::AddUrlToHistoryWithTransition;
using typed_urls_helper::AreVisitsEqual;
using typed_urls_helper::AreVisitsUnique;
using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
using typed_urls_helper::AssertURLRowVectorsAreEqual;
using typed_urls_helper::DeleteUrlFromHistory;
using typed_urls_helper::GetTypedUrlsFromClient;
using typed_urls_helper::GetUrlFromClient;
using typed_urls_helper::GetVisitsFromClient;
using typed_urls_helper::RemoveVisitsFromClient;
class TwoClientTypedUrlsSyncTest : public SyncTest {
public:
TwoClientTypedUrlsSyncTest() : SyncTest(TWO_CLIENT) {}
virtual ~TwoClientTypedUrlsSyncTest() {}
bool CheckClientsEqual() {
history::URLRows urls = GetTypedUrlsFromClient(0);
history::URLRows urls2 = GetTypedUrlsFromClient(1);
AssertURLRowVectorsAreEqual(urls, urls2);
for (size_t i = 0; i < urls.size() && i < urls2.size(); i++) {
history::VisitVector visit1 = GetVisitsFromClient(0, urls[i].id());
history::VisitVector visit2 = GetVisitsFromClient(1, urls2[i].id());
if (!AreVisitsEqual(visit1, visit2))
return false;
}
return true;
}
bool CheckNoDuplicateVisits() {
for (int i = 0; i < num_clients(); ++i) {
history::URLRows urls = GetTypedUrlsFromClient(i);
for (size_t j = 0; j < urls.size(); ++j) {
history::VisitVector visits = GetVisitsFromClient(i, urls[j].id());
if (!AreVisitsUnique(visits))
return false;
}
}
return true;
}
int GetVisitCountForFirstURL(int index) {
history::URLRows urls = GetTypedUrlsFromClient(index);
if (urls.size() == 0)
return 0;
else
return urls[0].visit_count();
}
private:
DISALLOW_COPY_AND_ASSIGN(TwoClientTypedUrlsSyncTest);
};
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, Add) {
const base::string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GURL new_url(kHistoryUrl);
AddUrlToHistory(0, new_url);
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, AddExpired) {
const base::string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GURL new_url(kHistoryUrl);
base::Time timestamp = base::Time::Now() - base::TimeDelta::FromDays(365);
AddUrlToHistoryWithTimestamp(0,
new_url,
content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED,
timestamp);
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
urls = GetTypedUrlsFromClient(1);
ASSERT_EQ(0U, urls.size());
}
#if defined(OS_MACOSX)
#define MAYBE_AddExpiredThenUpdate DISABLED_AddExpiredThenUpdate
#else
#define MAYBE_AddExpiredThenUpdate AddExpiredThenUpdate
#endif
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, MAYBE_AddExpiredThenUpdate) {
const base::string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GURL new_url(kHistoryUrl);
base::Time timestamp = base::Time::Now() - base::TimeDelta::FromDays(365);
AddUrlToHistoryWithTimestamp(0,
new_url,
content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED,
timestamp);
std::vector<history::URLRow> urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
urls = GetTypedUrlsFromClient(1);
ASSERT_EQ(0U, urls.size());
AddUrlToHistory(0, new_url);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
urls = GetTypedUrlsFromClient(1);
ASSERT_EQ(1U, urls.size());
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, DISABLED_AddThenDelete) {
const base::string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GURL new_url(kHistoryUrl);
AddUrlToHistory(0, new_url);
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
DeleteUrlFromHistory(0, new_url);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, DisableEnableSync) {
const base::string16 kUrl1(ASCIIToUTF16("http://history1.google.com/"));
const base::string16 kUrl2(ASCIIToUTF16("http://history2.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GetClient(0)->DisableSyncForDatatype(syncer::TYPED_URLS);
GURL url1(kUrl1);
GURL url2(kUrl2);
AddUrlToHistory(0, url1);
AddUrlToHistory(1, url2);
ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((1))));
history::URLRows post_sync_urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, post_sync_urls.size());
ASSERT_EQ(url1, post_sync_urls[0].url());
post_sync_urls = GetTypedUrlsFromClient(1);
ASSERT_EQ(1U, post_sync_urls.size());
ASSERT_EQ(url2, post_sync_urls[0].url());
GetClient(0)->EnableSyncForDatatype(syncer::TYPED_URLS);
ASSERT_TRUE(AwaitQuiescence());
AssertAllProfilesHaveSameURLsAsVerifier();
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, DISABLED_AddOneDeleteOther) {
const base::string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-one-delete-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GURL new_url(kHistoryUrl);
AddUrlToHistory(0, new_url);
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
DeleteUrlFromHistory(1, new_url);
urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest,
DISABLED_AddOneDeleteOtherAddAgain) {
const base::string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-delete-add-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GURL new_url(kHistoryUrl);
AddUrlToHistory(0, new_url);
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
DeleteUrlFromHistory(1, new_url);
urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
AddUrlToHistory(0, new_url);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest,
MergeTypedWithNonTypedDuringAssociation) {
ASSERT_TRUE(SetupClients());
GURL new_url("http://history.com");
base::Time timestamp = base::Time::Now();
AddUrlToHistoryWithTimestamp(0, new_url, content::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED, timestamp);
AddUrlToHistoryWithTimestamp(1, new_url, content::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED, timestamp);
AddUrlToHistoryWithTimestamp(1, new_url, content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED,
timestamp + base::TimeDelta::FromSeconds(1));
ASSERT_TRUE(GetClient(1)->SetupSync()) << "SetupSync() failed";
AwaitCommitActivityCompletion(GetSyncService((1)));
ASSERT_TRUE(GetClient(0)->SetupSync()) << "SetupSync() failed";
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(CheckClientsEqual());
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_TRUE(CheckNoDuplicateVisits());
ASSERT_EQ(2, GetVisitCountForFirstURL(0));
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest,
MergeTypedWithNonTypedDuringChangeProcessing) {
ASSERT_TRUE(SetupClients());
GURL new_url("http://history.com");
base::Time timestamp = base::Time::Now();
AddUrlToHistoryWithTimestamp(0, new_url, content::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED, timestamp);
AddUrlToHistoryWithTimestamp(1, new_url, content::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED, timestamp);
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(CheckClientsEqual());
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(0U, urls.size());
AddUrlToHistoryWithTimestamp(0, new_url, content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED,
timestamp + base::TimeDelta::FromSeconds(1));
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(CheckClientsEqual());
ASSERT_TRUE(CheckNoDuplicateVisits());
urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(2, GetVisitCountForFirstURL(0));
ASSERT_EQ(2, GetVisitCountForFirstURL(1));
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, UpdateToNonTypedURL) {
const base::string16 kHistoryUrl(
ASCIIToUTF16("http://www.add-delete-add-history.google.com/"));
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
GURL new_url(kHistoryUrl);
AddUrlToHistoryWithTransition(0, new_url, content::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED);
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(0U, urls.size());
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(0U, urls.size());
AddUrlToHistory(0, new_url);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(CheckClientsEqual());
urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(new_url, urls[0].url());
ASSERT_EQ(2, GetVisitCountForFirstURL(0));
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest,
SkipImportedVisits) {
GURL imported_url("http://imported_url.com");
GURL browsed_url("http://browsed_url.com");
GURL browsed_and_imported_url("http://browsed_and_imported_url.com");
ASSERT_TRUE(SetupClients());
AddUrlToHistoryWithTransition(0, imported_url,
content::PAGE_TRANSITION_TYPED,
history::SOURCE_FIREFOX_IMPORTED);
AddUrlToHistoryWithTransition(0, browsed_url,
content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED);
AddUrlToHistoryWithTransition(0, browsed_and_imported_url,
content::PAGE_TRANSITION_TYPED,
history::SOURCE_FIREFOX_IMPORTED);
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
history::URLRows urls = GetTypedUrlsFromClient(1);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(browsed_url, urls[0].url());
AddUrlToHistoryWithTransition(0, browsed_and_imported_url,
content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
urls = GetTypedUrlsFromClient(1);
ASSERT_EQ(2U, urls.size());
for (size_t i = 0; i < urls.size(); ++i) {
ASSERT_NE(imported_url, urls[i].url());
}
}
IN_PROC_BROWSER_TEST_F(TwoClientTypedUrlsSyncTest, BookmarksWithTypedVisit) {
GURL bookmark_url("http://www.bookmark.google.com/");
GURL bookmark_icon_url("http://www.bookmark.google.com/favicon.ico");
ASSERT_TRUE(SetupClients());
const BookmarkNode* node = bookmarks_helper::AddURL(
0, bookmarks_helper::IndexedURLTitle(0), bookmark_url);
bookmarks_helper::SetFavicon(0, node, bookmark_icon_url,
bookmarks_helper::CreateFavicon(SK_ColorWHITE),
bookmarks_helper::FROM_UI);
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
history::URLRow row;
ASSERT_TRUE(GetUrlFromClient(1, bookmark_url, &row));
AddUrlToHistory(0, bookmark_url);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
AssertAllProfilesHaveSameURLsAsVerifier();
history::URLRows urls = GetTypedUrlsFromClient(0);
ASSERT_EQ(1U, urls.size());
ASSERT_EQ(bookmark_url, urls[0].url());
ASSERT_EQ(1, GetVisitCountForFirstURL(0));
}