// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_BASE_INTERACTION_INTERACTION_TEST_UTIL_H_ #define UI_BASE_INTERACTION_INTERACTION_TEST_UTIL_H_ #include <memory> #include <vector> #include "build/build_config.h" #include "ui/base/interaction/element_tracker.h" #if !BUILDFLAG(IS_IOS) #include "ui/base/accelerators/accelerator.h" #endif namespace ui::test { // Describes the result of a trying to perform a specific action as part of a // test. Returned by individual functions and action simulators (see // `InteractionTestUtil::Simulator` below). enum class [[nodiscard]] ActionResult { … }; // Platform- and framework-independent utility for delegating specific common // actions to framework-specific handlers. Use so you can write your // interaction tests without having to worry about framework specifics. // // Simulators are checked in the order they are added, so if more than one // simulator can handle a particular action, add the one that has the more // specific/desired behavior first. // // Example usage: // // class MyTest { // void SetUp() override { // test_util_.AddSimulator( // std::make_unique<InteractionTestUtilSimulatorViews>()); // #if BUILDFLAG(IS_MAC) // test_util_.AddSimulator( // std::make_unique<InteractionTestUtilSimulatorMac>()); // #endif // ... // } // InteractionTestUtil test_util_; // }; // // TEST_F(MyTest, TestClickButton) { // ... // step.SetStartCallback(base::BindLambdaForTesting([&] ( // InteractionSequence* seq, TrackedElement* element) { // ActionResult result = test_util_.PressButton(element); // if (result == ActionResult::kError) // seq->FailForTesting(); // else if (result = ActionResult::kNotSupportedOnThisPlatform) // seq->SkipForTesting(); // })) // ... // } // class InteractionTestUtil { … }; void PrintTo(InteractionTestUtil::InputType input_type, std::ostream* os); std::ostream& operator<<(std::ostream& os, InteractionTestUtil::InputType input_type); } // namespace ui::test #endif // UI_BASE_INTERACTION_INTERACTION_TEST_UTIL_H_