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

Side by Side Diff: ios/web/public/test/earl_grey/js_test_util.mm

Issue 2340533004: [ios] Implemented -[ShellEarlGrey loadURL:]. (Closed)
Patch Set: Addressed review comments Created 4 years, 3 months 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
« no previous file with comments | « ios/web/public/test/earl_grey/js_test_util.h ('k') | ios/web/shell/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/web/public/test/earl_grey/js_test_util.h"
6
7 #import <EarlGrey/EarlGrey.h>
8 #import <WebKit/WebKit.h>
9
10 #include "base/timer/elapsed_timer.h"
11 #import "ios/testing/earl_grey/wait_util.h"
12 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
13
14 namespace web {
15
16 void WaitUntilWindowIdInjected(WebState* web_state) {
17 bool is_window_id_injected = false;
18 bool is_timeout = false;
19 bool is_unrecoverable_error = false;
20
21 base::ElapsedTimer timer;
22 base::TimeDelta timeout =
23 base::TimeDelta::FromSeconds(testing::kWaitForJSCompletionTimeout);
24
25 // Keep polling until either the JavaScript execution returns with expected
26 // value (indicating that Window ID is set), the timeout occurs, or an
27 // unrecoverable error occurs.
28 while (!is_window_id_injected && !is_timeout && !is_unrecoverable_error) {
29 NSError* error = nil;
30 id result = ExecuteJavaScript(web_state, @"0", &error);
31 if (error) {
32 is_unrecoverable_error = ![error.domain isEqual:WKErrorDomain] ||
33 error.code != WKErrorJavaScriptExceptionOccurred;
34 } else {
35 is_window_id_injected = [result isEqual:@0];
36 }
37 is_timeout = timeout < timer.Elapsed();
38 }
39 GREYAssertFalse(is_timeout, @"windowID injection timed out");
40 GREYAssertFalse(is_unrecoverable_error, @"script execution error");
41 }
42
43 id ExecuteJavaScript(WebState* web_state,
44 NSString* javascript,
45 NSError** out_error) {
46 __block BOOL did_complete = NO;
47 __block id result = nil;
48 CRWJSInjectionReceiver* receiver = web_state->GetJSInjectionReceiver();
49 [receiver executeJavaScript:javascript
50 completionHandler:^(id value, NSError* error) {
51 did_complete = YES;
52 result = [value copy];
53 if (out_error)
54 *out_error = [error copy];
55 }];
56
57 // Wait for completion.
58 GREYCondition* condition = [GREYCondition
59 conditionWithName:@"Wait for JavaScript execution to complete."
60 block:^{
61 return did_complete;
62 }];
63 GREYAssert([condition waitWithTimeout:testing::kWaitForJSCompletionTimeout],
64 @"Script execution timed out");
65
66 if (out_error)
67 [*out_error autorelease];
68 return [result autorelease];
69 }
70
71 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/public/test/earl_grey/js_test_util.h ('k') | ios/web/shell/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698