OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/public/test/web_view_interaction_test_util.h" | 5 #import "ios/web/public/test/web_view_interaction_test_util.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/test/ios/wait_util.h" | 12 #include "base/test/ios/wait_util.h" |
13 #include "ios/testing/earl_grey/wait_util.h" | 13 #include "ios/testing/earl_grey/wait_util.h" |
14 | 14 |
15 using web::NavigationManager; | 15 using web::NavigationManager; |
16 | 16 |
17 namespace web { | 17 namespace web { |
18 namespace test { | 18 namespace test { |
19 | 19 |
20 void TapWebViewElementWithId(web::WebState* web_state, | 20 void TapWebViewElementWithId(web::WebState* web_state, |
21 const std::string& element_id) { | 21 const std::string& element_id) { |
22 const char kJsClick[] = "document.getElementById('%s').click()"; | 22 const char kJsClick[] = "document.getElementById('%s').click()"; |
23 __block bool did_complete = false; | 23 __block bool did_complete = false; |
24 web_state->ExecuteJavaScript( | 24 web_state->ExecuteJavaScript( |
25 base::UTF8ToUTF16(base::StringPrintf(kJsClick, element_id.c_str())), | 25 base::UTF8ToUTF16(base::StringPrintf(kJsClick, element_id.c_str())), |
26 base::BindBlock(^(const base::Value*) { | 26 base::BindBlock(^(const base::Value*) { |
27 did_complete = true; | 27 did_complete = true; |
28 })); | 28 })); |
29 | 29 |
30 // TODO(crbug.com/610837): Re-factor wait code into common location. | 30 testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^() { |
Eugene But (OOO till 7-30)
2016/06/06 21:38:59
Optional NIT: s/^() {/^{
baxley
2016/06/06 22:38:07
Done.
| |
31 NSDate* deadline = [NSDate | 31 return did_complete; |
32 dateWithTimeIntervalSinceNow:testing::kWaitForJSCompletionTimeout]; | 32 }); |
baxley
2016/06/06 21:20:48
Let me know what you think of the readability here
Eugene But (OOO till 7-30)
2016/06/06 21:38:59
I believe that inline blocks are more readable com
baxley
2016/06/06 22:38:07
Acknowledged.
| |
33 while (([[NSDate date] compare:deadline] != NSOrderedDescending) && | |
34 !did_complete) { | |
35 base::test::ios::SpinRunLoopWithMaxDelay( | |
36 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); | |
37 } | |
38 } | 33 } |
39 | 34 |
40 } // namespace test | 35 } // namespace test |
41 } // namespace web | 36 } // namespace web |
OLD | NEW |