File: automation_test_utils.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,659 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_ACCESSIBILITY_AUTOMATION_TEST_UTILS_H_
#define CHROME_BROWSER_ASH_ACCESSIBILITY_AUTOMATION_TEST_UTILS_H_

#include <string>

#include "ui/gfx/geometry/rect.h"

namespace ash {

// Class that provides Ash browsertests support via the Automation API.
class AutomationTestUtils {
 public:
  explicit AutomationTestUtils(const std::string& extension_id);
  ~AutomationTestUtils();
  AutomationTestUtils(const AutomationTestUtils&) = delete;
  AutomationTestUtils& operator=(const AutomationTestUtils&) = delete;

  // Should be called once the extension under test is loaded.
  void SetUpTestSupport();

  // Waits for the root web area with the given URL to be loaded.
  // Note that the URL should not use backtick quotes, or if so they
  // should be escaped, to avoid collisions with the Javascript
  // strings.
  void WaitForPageLoad(const std::string& url);

  // Gets the bounds of the root web area with the given URL in
  // density-independent pixels.
  // Note that the URL should not use backtick quotes, or if so they
  // should be escaped, to avoid collisions with the Javascript
  // strings.
  gfx::Rect GetBoundsOfRootWebArea(const std::string& url);

  // Gets the value of the node with the given `class_name`.
  std::string GetValueForNodeWithClassName(const std::string& class_name);

  // Waits for the node with the given `class_name` to have the value `value`.
  void WaitForNodeWithClassNameAndValue(const std::string& class_name,
                                        const std::string& value);

  // Gets the bounds of the automation node with the given
  // `name` and `role` in density-independent pixels. Will wait
  // for the node to exist if it does not exist already.
  gfx::Rect GetNodeBoundsInRoot(const std::string& name,
                                const std::string& role);

  // Gets the bounds of the automation node with the given
  // `class_name` in density-independent pixels. Will wait
  // for the node to exist if it does not exist already.
  gfx::Rect GetBoundsForNodeInRootByClassName(const std::string& class_name);

  // Sets focus on the automation node with the given `name` and `role`.
  // Will wait for the node to exist if it does not exist already.
  void SetFocusOnNode(const std::string& name, const std::string& role);

  // Checks if a given node exists in the tree. Does not wait if the
  // node does not exist.
  bool NodeExistsNoWait(const std::string& name, const std::string& role);

  // Does the default action on the node with `name` and `role`.
  void DoDefault(const std::string& name, const std::string& role);

  // Various event waiters. This is the automation equivalent of
  // AccessibilityNotificationWaiter.

  // Waits for a chrome.automation.EventType.TEXT_SELECTION_CHANGED event to be
  // fired on the desktop node.
  void WaitForTextSelectionChangedEvent();

  // Waits for a chrome.automation.EventType.VALUE_CHANGED event to be fired
  // on the desktop node.
  void WaitForValueChangedEvent();

  // Waits for a chrome.automation.EventType.CHILDREN_CHANGED event to be fired
  // on the desktop node.
  void WaitForChildrenChangedEvent();

  // Waits for there to be `num` tabs in the tabstrip with regex name `name`.
  void WaitForNumTabsWithRegexName(int num, const std::string& name);

 private:
  std::string ExecuteScriptInExtensionPage(const std::string& script);
  std::string extension_id_;
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_ACCESSIBILITY_AUTOMATION_TEST_UTILS_H_