Commit 7f7e483d authored by Rushan Suleymanov's avatar Rushan Suleymanov Committed by Commit Bot

[Sync] Add iOS integration test for legacy sync bookmarks

Introduce a test which is equivalent to
SingleClientBookmarksSyncTest.DownloadTwoPre2015BookmarksWithSameItemId
desktop test.

Bug: 1048984
Change-Id: I729a296c28a91cac345c48b5f8f8982f7551c56e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2111150Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Rushan Suleymanov <rushans@google.com>
Cr-Commit-Position: refs/heads/master@{#752030}
parent 6d470004
......@@ -454,6 +454,39 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
timeout:kSyncOperationTimeout];
}
// Tests download of two legacy bookmarks with the same item id.
- (void)testDownloadTwoPre2015BookmarksWithSameItemId {
const GURL URL1 = web::test::HttpServer::MakeUrl("http://page1.com");
const GURL URL2 = web::test::HttpServer::MakeUrl("http://page2.com");
NSString* title1 = @"title1";
NSString* title2 = @"title2";
[[self class] assertBookmarksWithTitle:title1 expectedCount:0];
[[self class] assertBookmarksWithTitle:title2 expectedCount:0];
// Mimic the creation of two bookmarks from two different devices, with the
// same client item ID.
[ChromeEarlGrey
addFakeSyncServerLegacyBookmarkWithURL:URL1
title:base::SysNSStringToUTF8(title1)
originator_client_item_id:"1"];
[ChromeEarlGrey
addFakeSyncServerLegacyBookmarkWithURL:URL2
title:base::SysNSStringToUTF8(title2)
originator_client_item_id:"1"];
// Sign in to sync.
FakeChromeIdentity* fakeIdentity =
[SigninEarlGreyUtilsAppInterface fakeIdentity1];
[SigninEarlGreyUtilsAppInterface addFakeIdentity:fakeIdentity];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
[[self class] assertBookmarksWithTitle:title1 expectedCount:1];
[[self class] assertBookmarksWithTitle:title2 expectedCount:1];
}
#pragma mark - Test Utilities
// Adds a bookmark with the given |url| and |title| into the Mobile Bookmarks
......
......@@ -42,6 +42,14 @@ BOOL VerifyNumberOfSyncEntitiesWithName(syncer::ModelType type,
// Injects a bookmark into the fake sync server with |url| and |title|.
void InjectBookmarkOnFakeSyncServer(std::string url, std::string title);
// Injects a legacy bookmark into the fake sync server. The legacy bookmark
// means 2015 and earlier, prior to the adoption of GUIDs for originator client
// item ID.
void InjectLegacyBookmarkOnFakeSyncServer(
std::string url,
std::string title,
std::string originator_client_item_id);
// Injects an autofill profile into the fake sync server with |guid| and
// |full_name|.
void InjectAutofillProfileOnFakeSyncServer(std::string guid,
......
......@@ -8,6 +8,7 @@
#include <string>
#include "base/bind.h"
#include "base/guid.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
......@@ -149,6 +150,20 @@ void InjectBookmarkOnFakeSyncServer(std::string url, std::string title) {
gSyncFakeServer->InjectEntity(bookmark_builder.BuildBookmark(GURL(url)));
}
void InjectLegacyBookmarkOnFakeSyncServer(
std::string url,
std::string title,
std::string originator_client_item_id) {
DCHECK(gSyncFakeServer);
DCHECK(!base::IsValidGUID(originator_client_item_id));
fake_server::EntityBuilderFactory entity_builder_factory;
fake_server::BookmarkEntityBuilder bookmark_builder =
entity_builder_factory.NewBookmarkEntityBuilder(
title, std::move(originator_client_item_id));
gSyncFakeServer->InjectEntity(
bookmark_builder.BuildBookmark(GURL(url), /*is_legacy=*/true));
}
bool IsSyncInitialized() {
ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
......
......@@ -190,6 +190,14 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
- (void)addFakeSyncServerBookmarkWithURL:(const GURL&)URL
title:(const std::string&)title;
// Injects a legacy bookmark into the fake sync server. The legacy bookmark
// means 2015 and earlier, prior to the adoption of GUIDs for originator client
// item ID.
- (void)addFakeSyncServerLegacyBookmarkWithURL:(const GURL&)URL
title:(const std::string&)title
originator_client_item_id:
(const std::string&)originator_client_item_id;
// Injects typed URL to sync FakeServer.
- (void)addFakeSyncServerTypedURL:(const GURL&)URL;
......
......@@ -665,6 +665,20 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
title:title];
}
- (void)addFakeSyncServerLegacyBookmarkWithURL:(const GURL&)URL
title:(const std::string&)UTF8Title
originator_client_item_id:
(const std::string&)UTF8OriginatorClientItemId {
NSString* spec = base::SysUTF8ToNSString(URL.spec());
NSString* title = base::SysUTF8ToNSString(UTF8Title);
NSString* originator_client_item_id =
base::SysUTF8ToNSString(UTF8OriginatorClientItemId);
[ChromeEarlGreyAppInterface
addFakeSyncServerLegacyBookmarkWithURL:spec
title:title
originator_client_item_id:originator_client_item_id];
}
- (void)addFakeSyncServerTypedURL:(const GURL&)URL {
NSString* spec = base::SysUTF8ToNSString(URL.spec());
[ChromeEarlGreyAppInterface addFakeSyncServerTypedURL:spec];
......
......@@ -295,6 +295,14 @@
// Injects a bookmark into the fake sync server with |URL| and |title|.
+ (void)addFakeSyncServerBookmarkWithURL:(NSString*)URL title:(NSString*)title;
// Injects a legacy bookmark into the fake sync server. The legacy bookmark
// means 2015 and earlier, prior to the adoption of GUIDs for originator client
// item ID.
+ (void)addFakeSyncServerLegacyBookmarkWithURL:(NSString*)URL
title:(NSString*)title
originator_client_item_id:
(NSString*)originator_client_item_id;
// Injects typed URL to sync FakeServer.
+ (void)addFakeSyncServerTypedURL:(NSString*)URL;
......
......@@ -486,6 +486,15 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
base::SysNSStringToUTF8(URL), base::SysNSStringToUTF8(title));
}
+ (void)addFakeSyncServerLegacyBookmarkWithURL:(NSString*)URL
title:(NSString*)title
originator_client_item_id:
(NSString*)originator_client_item_id {
chrome_test_util::InjectLegacyBookmarkOnFakeSyncServer(
base::SysNSStringToUTF8(URL), base::SysNSStringToUTF8(title),
base::SysNSStringToUTF8(originator_client_item_id));
}
+ (void)addFakeSyncServerTypedURL:(NSString*)URL {
chrome_test_util::InjectTypedURLOnFakeSyncServer(
base::SysNSStringToUTF8(URL));
......
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