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 CONTENT_BROWSER_ACCESSIBILITY_HIT_TESTING_BROWSERTEST_H_
6 #define CONTENT_BROWSER_ACCESSIBILITY_HIT_TESTING_BROWSERTEST_H_
7 
8 #include "content/browser/accessibility/accessibility_content_browsertest.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace content {
12 
13 // First parameter of the tuple = device scale factor
14 // Second parameter = whether use-zoom-for-dsf is enabled
15 using AccessibilityZoomTestParam = std::tuple<double, bool>;
16 
17 class AccessibilityHitTestingBrowserTest
18     : public AccessibilityContentBrowserTest,
19       public ::testing::WithParamInterface<AccessibilityZoomTestParam> {
20  public:
21   AccessibilityHitTestingBrowserTest();
22   ~AccessibilityHitTestingBrowserTest() override;
23 
24   void SetUpCommandLine(base::CommandLine* command_line) override;
25 
26   struct TestPassToString {
27     std::string operator()(
28         const ::testing::TestParamInfo<AccessibilityZoomTestParam>& info) const;
29   };
30 
31  protected:
32   BrowserAccessibilityManager* GetRootBrowserAccessibilityManager();
33   float GetDeviceScaleFactor();
34   float GetPageScaleFactor();
35   gfx::Rect GetViewBoundsInScreenCoordinates();
36   gfx::Point CSSToFramePoint(gfx::Point css_point);
37   gfx::Point CSSToPhysicalPixelPoint(gfx::Point css_point);
38 
39   // Test the hit test action that fires an event.
40   BrowserAccessibility* HitTestAndWaitForResultWithEvent(
41       const gfx::Point& point,
42       ax::mojom::Event event_to_fire);
43   BrowserAccessibility* HitTestAndWaitForResult(const gfx::Point& point);
44 
45   // Test the hit test mojo RPC that calls a callback function.
46   BrowserAccessibility* AsyncHitTestAndWaitForCallback(const gfx::Point& point);
47 
48   // Test the caching async hit test.
49   BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& page_point);
50 
51   BrowserAccessibility* CallNearestLeafNode(const gfx::Point& page_point);
52   void SynchronizeThreads();
53   std::string FormatHitTestAccessibilityTree();
54   std::string GetScopedTrace(gfx::Point css_point);
55   void SimulatePinchZoom(float desired_page_scale);
56 
57   float page_scale_ = 1.0f;
58   gfx::Vector2d scroll_offset_;
59 };
60 
61 }  // namespace content
62 
63 #endif  // CONTENT_BROWSER_ACCESSIBILITY_HIT_TESTING_BROWSERTEST_H_
64