Commit c8ede4df authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][eg2] Convert SyncFakeServerTestCase to eg2.

This CL adds helper methods to signin_earlgrey_utils_app_interface.*
and converts the following tests:
-testSyncUploadBookmarkOnFirstSync
-testSyncUploadBookmark
-testSyncDownloadBookmark
-testSyncCheckSameCacheGuid_SyncRestarted
-testSyncCheckDifferentCacheGuid_SignOutAndSignIn
-testSyncCheckSameCacheGuid_SyncRestartedAfterSignOutAndSignIn
-testSyncDownloadAutofillProfile
-testSyncUpdateAutofillProfile
-testSyncDeleteAutofillProfile
-testSyncUploadOpenTabs
-testSyncTypedURLUpload
-testSyncTypedUrlDownload
-testSyncTypedURLDeleteFromClient
-testSyncTypedURLDeleteFromServer.

Bug: 987646

Change-Id: I559a90182f78996399bfc1ae9ac98a184c36d914
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1955555
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Auto-Submit: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#727468}
parent 861dffb6
......@@ -164,8 +164,10 @@ source_set("eg_test_support") {
":authentication",
"unified_consent",
"//base/test:test_support",
"//components/bookmarks/browser",
"//components/signin/public/identity_manager",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/bookmarks",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/authentication/cells",
......@@ -198,8 +200,10 @@ source_set("eg_app_support+eg2") {
deps = [
":authentication",
"unified_consent",
"//components/bookmarks/browser",
"//components/signin/public/identity_manager",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/bookmarks",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/authentication/cells",
......
......@@ -15,6 +15,12 @@
// compiled into the app binary and can be called from either app or test code.
@interface SigninEarlGreyUtilsAppInterface : NSObject
// Returns a fake identity.
+ (FakeChromeIdentity*)fakeIdentity1;
// Returns a second fake identity.
+ (FakeChromeIdentity*)fakeIdentity2;
// Adds |fakeIdentity| to the fake identity service.
+ (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
......@@ -34,6 +40,18 @@
// Removes |fakeIdentity| from the fake identity service.
+ (void)removeFakeIdentity:(FakeChromeIdentity*)fakeIdentity;
// Returns the current number of bookmarks from BookmarkModel.
+ (NSUInteger)bookmarkCount:(NSString*)title;
// Checks if any identity is currently authenticated.
+ (BOOL)isAuthenticated;
// Signs out the current user.
+ (void)signOut;
// Adds the new bookmark with URL and title to the |BookmarkModel|.
+ (void)addBookmark:(NSString*)urlString withTitle:(NSString*)title;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_SIGNIN_EARLGREY_UTILS_APP_INTERFACE_H_
......@@ -5,15 +5,22 @@
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils_app_interface.h"
#include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/titled_url_match.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
#include "ios/chrome/browser/bookmarks/bookmarks_utils.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_cell.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/testing/earl_grey/earl_grey_app.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -21,6 +28,18 @@
@implementation SigninEarlGreyUtilsAppInterface
+ (FakeChromeIdentity*)fakeIdentity1 {
return [FakeChromeIdentity identityWithEmail:@"foo1@gmail.com"
gaiaID:@"foo1ID"
name:@"Fake Foo 1"];
}
+ (FakeChromeIdentity*)fakeIdentity2 {
return [FakeChromeIdentity identityWithEmail:@"foo2@gmail.com"
gaiaID:@"foo2ID"
name:@"Fake Foo 2"];
}
+ (void)addFakeIdentity:(FakeChromeIdentity*)fakeIdentity {
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
fakeIdentity);
......@@ -60,4 +79,41 @@
->RemoveIdentity(fakeIdentity);
}
+ (NSUInteger)bookmarkCount:(NSString*)title {
bookmarks::BookmarkModel* bookmarkModel =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
base::string16 matchString = base::SysNSStringToUTF16(title);
std::vector<bookmarks::TitledUrlMatch> matches;
bookmarkModel->GetBookmarksMatching(matchString, 50, &matches);
const size_t count = matches.size();
return count;
}
+ (BOOL)isAuthenticated {
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state);
return authentication_service->IsAuthenticated();
}
+ (void)signOut {
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
AuthenticationService* authentication_service =
AuthenticationServiceFactory::GetForBrowserState(browser_state);
authentication_service->SignOut(signin_metrics::SIGNOUT_TEST, nil);
}
+ (void)addBookmark:(NSString*)urlString withTitle:(NSString*)title {
GURL bookmarkURL = GURL(base::SysNSStringToUTF8(urlString));
bookmarks::BookmarkModel* bookmark_model =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(title), bookmarkURL);
}
@end
......@@ -35,6 +35,7 @@ source_set("utils") {
source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
defines = [ "CHROME_EARL_GREY_1" ]
testonly = true
sources = [
"sync_fake_server_egtest.mm",
......@@ -50,8 +51,37 @@ source_set("eg_tests") {
"//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin:fake_chrome_identity",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ios/web/public/test/http_server",
]
libs = [ "XCTest.framework" ]
}
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"sync_fake_server_egtest.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//ios/chrome/browser/ui/authentication:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/public/provider/chrome/browser/signin:fake_chrome_identity",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/test/http_server",
]
libs = [ "UIKit.framework" ]
}
......@@ -105,6 +105,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
"//ios/chrome/browser/ui/sad_tab:eg2_tests",
"//ios/chrome/browser/ui/safe_mode:eg2_tests",
"//ios/chrome/browser/ui/settings/google_services:eg2_tests",
"//ios/chrome/browser/ui/settings/sync/utils:eg2_tests",
"//ios/chrome/browser/ui/side_swipe:eg2_tests",
"//ios/chrome/browser/ui/signin_interaction:eg2_tests",
"//ios/chrome/browser/ui/tab_grid:eg2_tests",
......
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