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 #ifndef IOS_WEB_PUBLIC_TEST_WEB_VIEW_INTERACTION_TEST_UTIL_H_ 6 #define IOS_WEB_PUBLIC_TEST_WEB_VIEW_INTERACTION_TEST_UTIL_H_ 7 8 #import <UIKit/UIKit.h> 9 10 #include <string> 11 12 #import "base/ios/block_types.h" 13 #include "base/values.h" 14 15 #include "ios/web/public/test/element_selector.h" 16 17 namespace web { 18 class WebState; 19 20 namespace test { 21 22 // Synchronously returns the result of executed JavaScript, returning nullptr 23 // if the JavaScript does not complete. 24 std::unique_ptr<base::Value> ExecuteJavaScript(web::WebState* web_state, 25 const std::string& script); 26 27 // Returns the CGRect, in the coordinate system of web_state's view, that 28 // encloses the element returned by |selector| in |web_state|'s webview. 29 // There is no guarantee that the CGRect returned is inside the current window; 30 // callers should check and act accordingly (scrolling the webview, perhaps). 31 // Returns CGRectNull if no element could be found. 32 CGRect GetBoundingRectOfElement(web::WebState* web_state, 33 ElementSelector* selector); 34 35 // Returns whether the element with |element_id| in the passed |web_state| has 36 // been tapped using a JavaScript click() event. 37 bool TapWebViewElementWithId(web::WebState* web_state, 38 const std::string& element_id); 39 40 // Returns whether the element with |element_id| in the passed |web_state| has 41 // been tapped using a JavaScript click() event. |error| can be nil. 42 bool TapWebViewElementWithId(web::WebState* web_state, 43 const std::string& element_id, 44 NSError* __autoreleasing* error); 45 46 // Looks for an element with |element_id| within window.frames[0] in the passed 47 // |web_state|. Returns whether this element has been tapped using a JavaScript 48 // click() event. This only works on same-origin iframes. 49 bool TapWebViewElementWithIdInIframe(web::WebState* web_state, 50 const std::string& element_id); 51 52 // Returns whether the element with |element_id| in the passed |web_state| has 53 // been focused using a JavaScript focus() event. 54 bool FocusWebViewElementWithId(web::WebState* web_state, 55 const std::string& element_id); 56 57 // Returns whether the form with |form_id| in the passed |web_state| has been 58 // submitted using a JavaScript submit() event. 59 bool SubmitWebViewFormWithId(web::WebState* web_state, 60 const std::string& form_id); 61 62 // Returns whether the <option id="|element_id|"> in the passed |web_state| has 63 // been selected using a JavaScript "selected=true" operation. 64 bool SelectWebViewElementWithId(web::WebState* web_state, 65 const std::string& element_id); 66 } // namespace test 67 } // namespace web 68 69 #endif // IOS_WEB_PUBLIC_TEST_WEB_VIEW_INTERACTION_TEST_UTIL_H_ 70