File: test_utils.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (122 lines) | stat: -rw-r--r-- 4,018 bytes parent folder | download | duplicates (5)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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 CHROME_BROWSER_ASH_ARC_INPUT_OVERLAY_TEST_TEST_UTILS_H_
#define CHROME_BROWSER_ASH_ARC_INPUT_OVERLAY_TEST_TEST_UTILS_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "chrome/browser/ash/arc/input_overlay/db/proto/app_data.pb.h"
#include "ui/gfx/geometry/rect.h"

class ArcAppTest;

namespace aura {
class Window;
}  // namespace aura

namespace base::test {
class TaskEnvironment;
}  // namespace base::test

namespace ukm {
class TestAutoSetUkmRecorder;
}  // namespace ukm

namespace views {
class Widget;
}  // namespace views

namespace arc::input_overlay {

// I/O time to wait.
inline constexpr base::TimeDelta kIORead = base::Milliseconds(50);

inline constexpr char kEnabledPackageName[] =
    "org.chromium.arc.testapp.inputoverlay";

class TouchInjector;

// Create ARC window without exo support.
std::unique_ptr<views::Widget> CreateArcWindow(
    aura::Window* root_window,
    const gfx::Rect& bounds = gfx::Rect(10, 10, 100, 100),
    const std::string& package_name = std::string("arc.packagename"));

// Make sure the tasks run synchronously when creating the window.
std::unique_ptr<views::Widget> CreateArcWindowSyncAndWait(
    base::test::TaskEnvironment* task_environment,
    aura::Window* root_window,
    const gfx::Rect& bounds,
    const std::string& package_name);

// Check the actions size in `injector`, action types, and action IDs.
void CheckActions(TouchInjector* injector,
                  size_t expect_size,
                  const std::vector<ActionType>& expect_types,
                  const std::vector<int>& expect_ids);

void SimulatedAppInstalled(base::test::TaskEnvironment* task_environment,
                           ArcAppTest& arc_app_test,
                           const std::string& package_name,
                           bool is_gc_opt_out,
                           bool is_game);

// Returns control name with localized strings:
// - "Button <key_string>" if `action_type` is ActionType::TAP.
// - "Joystick <key_string>" if `action_type` is ActionType::MOVE.
// - "Unassigned joystick" or "Unassigned button" if `key_string` is empty.
std::u16string GetControlName(ActionType action_type,
                              std::u16string key_string);

// Verifies UKM event entry size of EditingListFunctionTriggered is
// `expected_entry_size` and the last entry matches
// `expect_histograms_value`.
void VerifyEditingListFunctionTriggeredUkmEvent(
    const ukm::TestAutoSetUkmRecorder& ukm_recorder,
    size_t expected_entry_size,
    int64_t expect_histograms_value);

// Verifies UKM event entry size of ButtonOptionsMenuFunctionTriggered is
// `expected_entry_size` and the entry of `index` matches
// `expect_histograms_value`.
void VerifyButtonOptionsMenuFunctionTriggeredUkmEvent(
    const ukm::TestAutoSetUkmRecorder& ukm_recorder,
    size_t expected_entry_size,
    size_t index,
    int64_t expect_histograms_value);

// Increases the value for `key` by one. If there is no `key`, set the value
// to 1.
template <typename T>
void MapIncreaseValueByOne(std::map<T, int>& map, T key) {
  auto it = map.find(key);
  if (it == map.end()) {
    map[key] = 1;
  } else {
    map[key]++;
  }
}

template <typename T>
void VerifyHistogramValues(const base::HistogramTester& histograms,
                           const std::string& histogram_name,
                           const std::map<T, int>& histogram_values) {
  for (const auto& value : histogram_values) {
    histograms.ExpectBucketCount(histogram_name, value.first, value.second);
  }
}

void VerifyPlayWithGameControlsHistogram(
    const base::HistogramTester& histograms,
    const std::vector<int>& histograms_values);

}  // namespace arc::input_overlay

#endif  // CHROME_BROWSER_ASH_ARC_INPUT_OVERLAY_TEST_TEST_UTILS_H_