| Index: ios/chrome/test/earl_grey/chrome_earl_grey.mm
|
| diff --git a/ios/chrome/test/earl_grey/chrome_earl_grey.mm b/ios/chrome/test/earl_grey/chrome_earl_grey.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..eeaa34a987d9a572f2e86aebe2475805572c8533
|
| --- /dev/null
|
| +++ b/ios/chrome/test/earl_grey/chrome_earl_grey.mm
|
| @@ -0,0 +1,96 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
|
| +
|
| +#import <Foundation/Foundation.h>
|
| +#import <WebKit/WebKit.h>
|
| +
|
| +#include "base/strings/sys_string_conversions.h"
|
| +#import "ios/chrome/test/app/chrome_test_util.h"
|
| +#include "ios/chrome/test/app/history_test_util.h"
|
| +#include "ios/chrome/test/app/navigation_test_util.h"
|
| +#import "ios/testing/wait_util.h"
|
| +#import "ios/web/public/test/earl_grey/js_test_util.h"
|
| +#import "ios/web/public/test/web_view_interaction_test_util.h"
|
| +#import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
|
| +#include "ios/web/public/web_state/web_state.h"
|
| +
|
| +namespace chrome_test_util {
|
| +
|
| +id ExecuteJavaScript(NSString* javascript, NSError** out_error) {
|
| + __block bool did_complete = false;
|
| + __block id result = nil;
|
| + __block NSError* temp_error = nil;
|
| + CRWJSInjectionReceiver* evaluator =
|
| + chrome_test_util::GetCurrentWebState()->GetJSInjectionReceiver();
|
| + [evaluator executeJavaScript:javascript
|
| + completionHandler:^(id value, NSError* error) {
|
| + did_complete = true;
|
| + result = [value copy];
|
| + temp_error = [error copy];
|
| + }];
|
| +
|
| + // Wait for completion.
|
| + GREYCondition* condition = [GREYCondition
|
| + conditionWithName:@"Wait for JavaScript execution to complete."
|
| + block:^BOOL {
|
| + return did_complete;
|
| + }];
|
| + [condition waitWithTimeout:testing::kWaitForJSCompletionTimeout];
|
| + if (!did_complete)
|
| + return nil;
|
| + [temp_error autorelease];
|
| + if (out_error)
|
| + *out_error = temp_error;
|
| + return [result autorelease];
|
| +}
|
| +
|
| +} // namespace chrome_test_util
|
| +
|
| +@implementation ChromeEarlGrey
|
| +
|
| +#pragma mark - History Utilities
|
| +
|
| ++ (void)clearBrowsingHistory {
|
| + chrome_test_util::ClearBrowsingHistory();
|
| + // After clearing browsing history via code, wait for the UI to be done
|
| + // with any updates. This includes icons from the new tab page being removed.
|
| + [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
|
| +}
|
| +
|
| +#pragma mark - Navigation Utilities
|
| +
|
| ++ (void)loadURL:(GURL)URL {
|
| + chrome_test_util::LoadUrl(URL);
|
| + // Make sure that the page started loading.
|
| + GREYAssert(chrome_test_util::IsLoading(), @"Page did not start loading.");
|
| + [ChromeEarlGrey waitForPageToFinishLoading];
|
| +
|
| + web::WebState* webState = chrome_test_util::GetCurrentWebState();
|
| + if (webState->ContentIsHTML())
|
| + web::WaitUntilWindowIdInjected(webState);
|
| +}
|
| +
|
| ++ (void)waitForPageToFinishLoading {
|
| + GREYCondition* condition =
|
| + [GREYCondition conditionWithName:@"Wait for page to complete loading."
|
| + block:^BOOL {
|
| + return !chrome_test_util::IsLoading();
|
| + }];
|
| + GREYAssert([condition waitWithTimeout:testing::kWaitForPageLoadTimeout],
|
| + @"Page did not complete loading.");
|
| +}
|
| +
|
| ++ (void)tapWebViewElementWithID:(NSString*)elementID {
|
| + BOOL success =
|
| + web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(),
|
| + base::SysNSStringToUTF8(elementID));
|
| + GREYAssertTrue(
|
| + success,
|
| + [NSString stringWithFormat:@"Failed to tap web view element with ID: %@",
|
| + elementID]);
|
| +}
|
| +
|
| +@end
|
|
|