Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: ios/chrome/test/earl_grey/chrome_earl_grey.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
6
7 #import <Foundation/Foundation.h>
8 #import <WebKit/WebKit.h>
9
10 #include "base/strings/sys_string_conversions.h"
11 #import "ios/chrome/test/app/chrome_test_util.h"
12 #include "ios/chrome/test/app/history_test_util.h"
13 #include "ios/chrome/test/app/navigation_test_util.h"
14 #import "ios/testing/wait_util.h"
15 #import "ios/web/public/test/earl_grey/js_test_util.h"
16 #import "ios/web/public/test/web_view_interaction_test_util.h"
17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
18 #include "ios/web/public/web_state/web_state.h"
19
20 namespace chrome_test_util {
21
22 id ExecuteJavaScript(NSString* javascript, NSError** out_error) {
23 __block bool did_complete = false;
24 __block id result = nil;
25 __block NSError* temp_error = nil;
26 CRWJSInjectionReceiver* evaluator =
27 chrome_test_util::GetCurrentWebState()->GetJSInjectionReceiver();
28 [evaluator executeJavaScript:javascript
29 completionHandler:^(id value, NSError* error) {
30 did_complete = true;
31 result = [value copy];
32 temp_error = [error copy];
33 }];
34
35 // Wait for completion.
36 GREYCondition* condition = [GREYCondition
37 conditionWithName:@"Wait for JavaScript execution to complete."
38 block:^BOOL {
39 return did_complete;
40 }];
41 [condition waitWithTimeout:testing::kWaitForJSCompletionTimeout];
42 if (!did_complete)
43 return nil;
44 [temp_error autorelease];
45 if (out_error)
46 *out_error = temp_error;
47 return [result autorelease];
48 }
49
50 } // namespace chrome_test_util
51
52 @implementation ChromeEarlGrey
53
54 #pragma mark - History Utilities
55
56 + (void)clearBrowsingHistory {
57 chrome_test_util::ClearBrowsingHistory();
58 // After clearing browsing history via code, wait for the UI to be done
59 // with any updates. This includes icons from the new tab page being removed.
60 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
61 }
62
63 #pragma mark - Navigation Utilities
64
65 + (void)loadURL:(GURL)URL {
66 chrome_test_util::LoadUrl(URL);
67 // Make sure that the page started loading.
68 GREYAssert(chrome_test_util::IsLoading(), @"Page did not start loading.");
69 [ChromeEarlGrey waitForPageToFinishLoading];
70
71 web::WebState* webState = chrome_test_util::GetCurrentWebState();
72 if (webState->ContentIsHTML())
73 web::WaitUntilWindowIdInjected(webState);
74 }
75
76 + (void)waitForPageToFinishLoading {
77 GREYCondition* condition =
78 [GREYCondition conditionWithName:@"Wait for page to complete loading."
79 block:^BOOL {
80 return !chrome_test_util::IsLoading();
81 }];
82 GREYAssert([condition waitWithTimeout:testing::kWaitForPageLoadTimeout],
83 @"Page did not complete loading.");
84 }
85
86 + (void)tapWebViewElementWithID:(NSString*)elementID {
87 BOOL success =
88 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(),
89 base::SysNSStringToUTF8(elementID));
90 GREYAssertTrue(
91 success,
92 [NSString stringWithFormat:@"Failed to tap web view element with ID: %@",
93 elementID]);
94 }
95
96 @end
OLDNEW
« no previous file with comments | « ios/chrome/test/earl_grey/chrome_earl_grey.h ('k') | ios/chrome/test/earl_grey/chrome_earl_grey_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698