1 // Copyright 2020 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 COMPONENTS_AUTOFILL_CONTENT_RENDERER_FOCUS_TEST_UTILS_H_ 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_FOCUS_TEST_UTILS_H_ 7 8 #include "base/callback.h" 9 #include "string" 10 11 #include "third_party/blink/public/web/web_document.h" 12 13 namespace autofill { 14 15 namespace test { 16 17 class FocusTestUtils { 18 // Creates a result input field in the HTML body, then sets-up event listeners 19 // for the focus, change and blur events to track the order of events emitted 20 // for the fields. Ex. -> 'f0c0b0f1c1b1' would mean the following: 21 // 1. Focus event for the field with name '0' 22 // 2. Change event for the field with name '0' 23 // 3. Blur event for the field with name '0' 24 // 4. Focus event for the field with name '1' 25 // 5. Change event for the field with name '1' 26 // 6. Blur event for field with name '1' 27 public: 28 explicit FocusTestUtils( 29 base::RepeatingCallback<void(const char*)> execute_java_script_function); 30 ~FocusTestUtils(); 31 FocusTestUtils(const FocusTestUtils&) = delete; 32 FocusTestUtils& operator=(const FocusTestUtils&) = delete; 33 34 // Creates a result input element and sets up event listeners for focus, 35 // blur and change events for the form elements. 36 void SetUpFocusLogging(); 37 38 // Emits focus event for the given field with id |element_id|. 39 void FocusElement(const char* element_id); 40 41 // Returns the sequence of focus events (see class description). 42 std::string GetFocusLog(const blink::WebDocument& document); 43 44 private: 45 base::RepeatingCallback<void(const char*)> execute_java_script_function_; 46 }; 47 48 } // namespace test 49 } // namespace autofill 50 51 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_FOCUS_TEST_UTILS_H_ 52