Commit 09e31c47 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Remove Bookmarks methods from SigninUtilsAppInterface APIs.

BookmarkEarlGrey contains the required methods that are being
re-implemented in the Signin codebase. To ensure consistency across
the codebase remove sign-in versions and update tests.

Bug: 1103274
Change-Id: I2a9348945def367512240279731e7e9b6839960f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2290633Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791502}
parent 203513fb
......@@ -40,18 +40,12 @@
// 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_
......@@ -79,18 +79,6 @@
->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 {
ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
......@@ -108,13 +96,4 @@
/*force_clear_browsing_data=*/false, 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
......@@ -55,6 +55,10 @@ const GURL GetFrenchUrl();
// GREYAssert is induced if the folder doesn't exist or the count doesn't match.
- (void)verifyChildCount:(int)count inFolderWithName:(NSString*)name;
// Programmatically adds a bookmark with the given title and URL. GREYAssert is
// induced if the bookmark cannot be added.
- (void)addBookmarkWithTitle:(NSString*)title URL:(NSString*)url;
// Removes programmatically the first bookmark with the given title. GREYAssert
// is induced if the bookmark can't be removed.
- (void)removeBookmarkWithTitle:(NSString*)title;
......
......@@ -88,6 +88,11 @@ const GURL GetFrenchUrl() {
inFolderWithName:name]);
}
- (void)addBookmarkWithTitle:(NSString*)title URL:(NSString*)url {
EG_TEST_HELPER_ASSERT_NO_ERROR(
[BookmarkEarlGreyAppInterface addBookmarkWithTitle:title URL:url]);
}
- (void)removeBookmarkWithTitle:(NSString*)title {
EG_TEST_HELPER_ASSERT_NO_ERROR(
[BookmarkEarlGreyAppInterface removeBookmarkWithTitle:title]);
......
......@@ -33,6 +33,9 @@
+ (NSError*)verifyBookmarksWithTitle:(NSString*)title
expectedCount:(NSUInteger)expectedCount;
// Programmatically adds a bookmark with the given title and URL.
+ (NSError*)addBookmarkWithTitle:(NSString*)title URL:(NSString*)url;
// Removes programmatically the first bookmark with the given title.
+ (NSError*)removeBookmarkWithTitle:(NSString*)title;
......
......@@ -148,6 +148,20 @@
return nil;
}
+ (NSError*)addBookmarkWithTitle:(NSString*)title URL:(NSString*)url {
if (![BookmarkEarlGreyAppInterface waitForBookmarkModelLoaded:YES])
return testing::NSErrorWithLocalizedDescription(
@"Bookmark model was not loaded");
GURL bookmarkURL = GURL(base::SysNSStringToUTF8(url));
bookmarks::BookmarkModel* bookmark_model =
[BookmarkEarlGreyAppInterface bookmarkModel];
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(title), bookmarkURL);
return nil;
}
+ (NSError*)removeBookmarkWithTitle:(NSString*)title {
base::string16 name16(base::SysNSStringToUTF16(title));
bookmarks::BookmarkModel* bookmarkModel =
......
......@@ -7,7 +7,6 @@
#import "base/test/scoped_feature_list.h"
#import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils_app_interface.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey_ui.h"
#import "ios/chrome/browser/ui/settings/google_services/accounts_table_view_controller_constants.h"
......@@ -195,8 +194,7 @@ id<GREYMatcher> NoBookmarksLabel() {
// Add a bookmark after sync is initialized.
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
[ChromeEarlGrey waitForBookmarksToFinishLoading];
[SigninEarlGreyUtilsAppInterface addBookmark:@"http://youtube.com"
withTitle:@"cats"];
[BookmarkEarlGrey setupStandardBookmarks];
// Sign out.
[SigninEarlGreyUI
......@@ -206,9 +204,9 @@ id<GREYMatcher> NoBookmarksLabel() {
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Assert that the 'cats' bookmark is displayed.
[[EarlGrey selectElementWithMatcher:grey_text(@"cats")]
assertWithMatcher:grey_notNil()];
// Assert that the no bookmarks label is not present.
[[EarlGrey selectElementWithMatcher:NoBookmarksLabel()]
assertWithMatcher:grey_nil()];
}
// Tests that selecting sign-out and clear data from a non-managed user account
......@@ -222,8 +220,7 @@ id<GREYMatcher> NoBookmarksLabel() {
// Add a bookmark after sync is initialized.
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
[ChromeEarlGrey waitForBookmarksToFinishLoading];
[SigninEarlGreyUtilsAppInterface addBookmark:@"http://youtube.com"
withTitle:@"cats"];
[BookmarkEarlGrey setupStandardBookmarks];
// Sign out.
[SigninEarlGreyUI signOutWithSignOutConfirmation:
......@@ -248,8 +245,7 @@ id<GREYMatcher> NoBookmarksLabel() {
// Add a bookmark after sync is initialized.
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
[ChromeEarlGrey waitForBookmarksToFinishLoading];
[SigninEarlGreyUtilsAppInterface addBookmark:@"http://youtube.com"
withTitle:@"cats"];
[BookmarkEarlGrey setupStandardBookmarks];
// Sign out.
[SigninEarlGreyUI
......
......@@ -47,6 +47,7 @@ source_set("eg2_tests") {
"//base",
"//base/test:test_support",
"//ios/chrome/browser/ui/authentication:eg_test_support+eg2",
"//ios/chrome/browser/ui/bookmarks: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",
......
......@@ -6,6 +6,7 @@
#import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils_app_interface.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
......@@ -65,7 +66,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
// Tests that a bookmark added on the client (before Sync is enabled) is
// uploaded to the Sync server once Sync is turned on.
- (void)testSyncUploadBookmarkOnFirstSync {
[self addBookmark:@"https://www.foo.com" withTitle:@"foo"];
[BookmarkEarlGrey addBookmarkWithTitle:@"foo" URL:@"https://www.foo.com"];
// Sign in to sync, after a bookmark has been added.
FakeChromeIdentity* fakeIdentity =
......@@ -87,14 +88,14 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
// Add a bookmark after sync is initialized.
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
[self addBookmark:@"https://www.goo.com" withTitle:@"goo"];
[BookmarkEarlGrey addBookmarkWithTitle:@"goo" URL:@"https://www.goo.com"];
AssertNumberOfEntities(1, syncer::BOOKMARKS);
}
// Tests that a bookmark injected in the FakeServer is synced down to the
// client.
- (void)testSyncDownloadBookmark {
[[self class] assertBookmarksWithTitle:@"hoo" expectedCount:0];
[BookmarkEarlGrey verifyBookmarksWithTitle:@"hoo" expectedCount:0];
const GURL URL = web::test::HttpServer::MakeUrl("http://www.hoo.com");
[ChromeEarlGrey addFakeSyncServerBookmarkWithURL:URL title:"hoo"];
......@@ -104,7 +105,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
[SigninEarlGreyUtilsAppInterface addFakeIdentity:fakeIdentity];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
[ChromeEarlGrey waitForSyncInitialized:YES syncTimeout:kSyncOperationTimeout];
[[self class] assertBookmarksWithTitle:@"hoo" expectedCount:1];
[BookmarkEarlGrey verifyBookmarksWithTitle:@"hoo" expectedCount:1];
}
// Tests that the local cache guid does not change when sync is restarted.
......@@ -460,8 +461,8 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
NSString* title1 = @"title1";
NSString* title2 = @"title2";
[[self class] assertBookmarksWithTitle:title1 expectedCount:0];
[[self class] assertBookmarksWithTitle:title2 expectedCount:0];
[BookmarkEarlGrey verifyBookmarksWithTitle:title1 expectedCount:0];
[BookmarkEarlGrey verifyBookmarksWithTitle:title2 expectedCount:0];
// Mimic the creation of two bookmarks from two different devices, with the
// same client item ID.
......@@ -482,30 +483,8 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
[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
// folder.
// TODO(crbug.com/646164): This is copied from bookmarks_egtest.mm and should
// move to common location.
- (void)addBookmark:(NSString*)urlString withTitle:(NSString*)title {
[ChromeEarlGrey waitForBookmarksToFinishLoading];
[SigninEarlGreyUtilsAppInterface addBookmark:urlString withTitle:title];
}
// Asserts that |expectedCount| bookmarks exist with the corresponding |title|
// using the BookmarkModel.
// TODO(crbug.com/646164): This is copied from bookmarks_egtest.mm and should
// move to common location.
+ (void)assertBookmarksWithTitle:(NSString*)title
expectedCount:(NSUInteger)expectedCount {
GREYAssertEqual(expectedCount,
[SigninEarlGreyUtilsAppInterface bookmarkCount:title],
@"Unexpected number of bookmarks");
[BookmarkEarlGrey verifyBookmarksWithTitle:title1 expectedCount:1];
[BookmarkEarlGrey verifyBookmarksWithTitle:title2 expectedCount:1];
}
@end
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