Commit 3c5b9672 authored by Eric Aleshire's avatar Eric Aleshire Committed by Commit Bot

Convert some of chrome_earl_grey's typedURL helpers to compile under EG2.

Also adds them to a test to confirm they execute. The test is not rigid
enough to check for correctness at the moment (due to lack of helpers),
but will be expanded in future CLs.

Bug: 922813
Change-Id: I0f8c6c1cb4a9f2f5290a1244deca9b80d970f039
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1629168
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666047}
parent ac1ae090
......@@ -491,7 +491,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
@"There should be 1 typed URL entity");
// Delete typed URL from client.
[ChromeEarlGrey deleteTypedURL:mockURL];
[ChromeEarlGrey deleteHistoryServiceTypedURL:mockURL];
// Trigger sync and wait for typed URL to be deleted.
[ChromeEarlGrey triggerSyncCycleForType:syncer::TYPED_URLS];
......@@ -525,7 +525,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
name:mockURL.spec()
count:1
timeout:kSyncOperationTimeout]);
[ChromeEarlGrey deleteTypedURL:mockURL];
[ChromeEarlGrey deleteHistoryServiceTypedURL:mockURL];
// Trigger sync and wait for fake server to be updated.
[ChromeEarlGrey triggerSyncCycleForType:syncer::TYPED_URLS];
......
......@@ -152,6 +152,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// Adds typed URL into HistoryService.
- (void)addHistoryServiceTypedURL:(const GURL&)URL;
// Deletes typed URL from HistoryService.
- (void)deleteHistoryServiceTypedURL:(const GURL&)URL;
// Injects a bookmark with |URL| and |title| into the fake sync server.
- (void)addFakeSyncServerBookmarkWithURL:(const GURL&)URL
title:(const std::string&)title;
......@@ -184,6 +187,14 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
count:(size_t)count
timeout:(NSTimeInterval)timeout;
// Induces a GREYAssert if |expected_present| is YES and the provided |url| is
// not present, or vice versa.
// TODO(crbug.com/963613): Change return type to void when
// CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)waitForTypedURL:(const GURL&)URL
expectPresent:(BOOL)expectPresent
timeout:(NSTimeInterval)timeout;
#pragma mark - Tab Utilities (EG2)
// Opens a new tab and waits for the new tab animation to complete within a
......@@ -387,16 +398,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
- (void)injectBookmarkOnFakeSyncServerWithURL:(const std::string&)URL
bookmarkTitle:(const std::string&)title;
// If the provided |url| is present (or not) if |expected_present|
// is YES (or NO) returns nil, otherwise an NSError indicating why the operation
// failed.
- (NSError*)waitForTypedURL:(const GURL&)URL
expectPresent:(BOOL)expectPresent
timeout:(NSTimeInterval)timeout WARN_UNUSED_RESULT;
// Deletes typed URL from HistoryService.
- (void)deleteTypedURL:(const GURL&)URL;
@end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_H_
......@@ -41,7 +41,10 @@ using base::test::ios::kWaitForUIElementTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
namespace {
NSString* kWaitForPageToFinishLoadingError = @"Page did not finish loading";
NSString* const kWaitForPageToFinishLoadingError =
@"Page did not finish loading";
NSString* const kTypedURLError =
@"Error occurred during typed URL verification.";
}
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -452,6 +455,29 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
[ChromeEarlGreyAppInterface addHistoryServiceTypedURL:spec];
}
- (void)deleteHistoryServiceTypedURL:(const GURL&)URL {
NSString* spec = base::SysUTF8ToNSString(URL.spec());
[ChromeEarlGreyAppInterface deleteHistoryServiceTypedURL:spec];
}
- (NSError*)waitForTypedURL:(const GURL&)URL
expectPresent:(BOOL)expectPresent
timeout:(NSTimeInterval)timeout {
NSString* spec = base::SysUTF8ToNSString(URL.spec());
GREYCondition* waitForTypedURL =
[GREYCondition conditionWithName:kTypedURLError
block:^{
return [ChromeEarlGreyAppInterface
isTypedURL:spec
presentOnClient:expectPresent];
}];
bool success = [waitForTypedURL waitWithTimeout:timeout];
EG_TEST_HELPER_ASSERT_TRUE(success, kTypedURLError);
return nil;
}
- (void)triggerSyncCycleForType:(syncer::ModelType)type {
[ChromeEarlGreyAppInterface triggerSyncCycleForType:type];
}
......@@ -616,33 +642,6 @@ id ExecuteJavaScript(NSString* javascript,
chrome_test_util::InjectBookmarkOnFakeSyncServer(URL, title);
}
- (NSError*)waitForTypedURL:(const GURL&)URL
expectPresent:(BOOL)expectPresent
timeout:(NSTimeInterval)timeout {
__block NSError* error = nil;
ConditionBlock condition = ^{
NSError* __autoreleasing tempError = error;
BOOL success = chrome_test_util::IsTypedUrlPresentOnClient(
URL, expectPresent, &tempError);
error = tempError;
DCHECK(success || error);
return !!success;
};
bool success = WaitUntilConditionOrTimeout(timeout, condition);
if (error != nil) {
return nil;
}
if (!success) {
return testing::NSErrorWithLocalizedDescription(
@"Error occurred during typed URL verification.");
}
return nil;
}
- (void)deleteTypedURL:(const GURL&)URL {
chrome_test_util::DeleteTypedUrlFromClient(URL);
}
@end
#endif // defined(CHROME_EARL_GREY_1)
......@@ -22,9 +22,9 @@
// operation failed.
+ (NSError*)clearBrowsingHistory;
// Loads |URL| in the current WebState with transition type
// Loads the URL |spec| in the current WebState with transition type
// ui::PAGE_TRANSITION_TYPED and returns without waiting for the page to load.
+ (void)startLoadingURL:(NSString*)URL;
+ (void)startLoadingURL:(NSString*)spec;
// If the current WebState is HTML content, will wait until the window ID is
// injected. Returns YES if the injection is successful or if the WebState is
......@@ -217,6 +217,14 @@
// Adds typed URL into HistoryService.
+ (void)addHistoryServiceTypedURL:(NSString*)URL;
// Deletes typed URL from HistoryService.
+ (void)deleteHistoryServiceTypedURL:(NSString*)URL;
// If the provided URL |spec| is either present or not present in HistoryService
// (depending on |expectPresent|), return YES. If the present status of |spec|
// is not what is expected, or there is an error, return NO.
+ (BOOL)isTypedURL:(NSString*)spec presentOnClient:(BOOL)expectPresent;
// Triggers a sync cycle for a |type|.
+ (void)triggerSyncCycleForType:(syncer::ModelType)type;
......
......@@ -42,8 +42,8 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
@"Clearing browser history timed out");
}
+ (void)startLoadingURL:(NSString*)URL {
chrome_test_util::LoadUrl(GURL(base::SysNSStringToUTF8(URL)));
+ (void)startLoadingURL:(NSString*)spec {
chrome_test_util::LoadUrl(GURL(base::SysNSStringToUTF8(spec)));
}
+ (BOOL)waitForWindowIDInjectionIfNeeded {
......@@ -311,6 +311,19 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
chrome_test_util::AddTypedURLOnClient(GURL(base::SysNSStringToUTF8(URL)));
}
+ (void)deleteHistoryServiceTypedURL:(NSString*)URL {
chrome_test_util::DeleteTypedUrlFromClient(
GURL(base::SysNSStringToUTF8(URL)));
}
+ (BOOL)isTypedURL:(NSString*)spec presentOnClient:(BOOL)expectPresent {
NSError* error = nil;
GURL URL(base::SysNSStringToUTF8(spec));
BOOL success =
chrome_test_util::IsTypedUrlPresentOnClient(URL, expectPresent, &error);
return success && !error;
}
+ (void)triggerSyncCycleForType:(syncer::ModelType)type {
chrome_test_util::TriggerSyncCycle(type);
}
......
......@@ -179,4 +179,12 @@
actualResult);
}
// Tests typed URL converted helpers in chrome_earl_grey.h.
- (void)testTypedURLHelpers {
const GURL mockURL("http://not-a-real-site.test/");
[ChromeEarlGrey addHistoryServiceTypedURL:mockURL];
[ChromeEarlGrey deleteHistoryServiceTypedURL:mockURL];
}
@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