/
standardized_mouse_scroll.go
157 lines (137 loc) · 5.67 KB
/
standardized_mouse_scroll.go
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package arc
import (
"context"
"time"
"chromiumos/tast/common/android/ui"
"chromiumos/tast/errors"
"chromiumos/tast/local/bundles/cros/arc/standardizedtestutil"
"chromiumos/tast/local/chrome/ash"
"chromiumos/tast/local/input"
"chromiumos/tast/testing"
"chromiumos/tast/testing/hwdep"
)
type standardizedMouseScrollArgs struct {
test standardizedtestutil.Test
resizeLockEnabled bool
}
func init() {
testing.AddTest(&testing.Test{
Func: StandardizedMouseScroll,
LacrosStatus: testing.LacrosVariantUnneeded,
Desc: "Functional test that installs an app and tests that a standard mouse scroll up, an down works",
Contacts: []string{"davidwelling@google.com", "cros-appcompat-test-team@google.com"},
Attr: []string{"group:mainline"},
SoftwareDeps: []string{"chrome", "no_chrome_dcheck"},
Timeout: 10 * time.Minute,
Params: []testing.Param{
{
Val: &standardizedMouseScrollArgs{
test: standardizedtestutil.GetClamshellTest(runStandardizedMouseScrollTest),
resizeLockEnabled: false,
},
ExtraAttr: []string{"informational"},
ExtraSoftwareDeps: []string{"android_p"},
Fixture: "arcBooted",
ExtraHardwareDeps: hwdep.D(standardizedtestutil.ClamshellHardwareDep),
},
{
Name: "vm",
Val: &standardizedMouseScrollArgs{
test: standardizedtestutil.GetClamshellTest(runStandardizedMouseScrollTest),
resizeLockEnabled: false,
},
ExtraSoftwareDeps: []string{"android_vm"},
Fixture: "arcBooted",
ExtraHardwareDeps: hwdep.D(standardizedtestutil.ClamshellHardwareDep),
},
{
Name: "resize_lock_smooth_scroll_vm",
Val: &standardizedMouseScrollArgs{
test: standardizedtestutil.Test{
Fn: runStandardizedMouseScrollTest,
InTabletMode: false,
WindowStates: []standardizedtestutil.WindowState{
{Name: "Normal", WindowStateType: ash.WindowStateNormal},
},
},
resizeLockEnabled: true,
},
ExtraAttr: []string{"informational"},
ExtraSoftwareDeps: []string{"android_vm"},
Fixture: "arcBootedWithTouchModeMouse",
ExtraHardwareDeps: hwdep.D(standardizedtestutil.ClamshellHardwareDep),
},
},
})
}
func StandardizedMouseScroll(ctx context.Context, s *testing.State) {
const (
apkName = "ArcStandardizedInputTest.apk"
appName = "org.chromium.arc.testapp.arcstandardizedinputtest"
activityName = ".ScrollTestActivity"
)
t := s.Param().(*standardizedMouseScrollArgs).test
resizeLockEnabled := s.Param().(*standardizedMouseScrollArgs).resizeLockEnabled
if resizeLockEnabled {
standardizedtestutil.RunResizeLockTest(ctx, s, apkName, appName, activityName, t)
} else {
standardizedtestutil.RunTest(ctx, s, apkName, appName, activityName, t)
}
}
func runStandardizedMouseScrollTest(ctx context.Context, testParameters standardizedtestutil.TestFuncParams) error {
// Perform the down test first as the up test depends on it to be complete.
txtScrollDownTestStateID := testParameters.AppPkgName + ":id/txtScrollDownTestState"
txtScrollDownSuccessSelector := testParameters.Device.Object(ui.ID(txtScrollDownTestStateID), ui.Text("COMPLETE"))
if err := runMouseScroll(ctx, testParameters, txtScrollDownSuccessSelector, standardizedtestutil.DownScroll); err != nil {
return errors.Wrap(err, "scroll down test failed")
}
txtScrollUpTestStateID := testParameters.AppPkgName + ":id/txtScrollUpTestState"
txtScrollUpSuccessSelector := testParameters.Device.Object(ui.ID(txtScrollUpTestStateID), ui.Text("COMPLETE"))
if err := runMouseScroll(ctx, testParameters, txtScrollUpSuccessSelector, standardizedtestutil.UpScroll); err != nil {
return errors.Wrap(err, "scroll up test failed")
}
return nil
}
func runMouseScroll(ctx context.Context, testParameters standardizedtestutil.TestFuncParams, txtSuccessSelector *ui.Object, scrollDirection standardizedtestutil.ScrollDirection) error {
const (
maxNumScrollIterations = 15
)
txtScrollableContentID := testParameters.AppPkgName + ":id/txtScrollableContent"
txtScrollableContentSelector := testParameters.Device.Object(ui.ID(txtScrollableContentID))
// Setup the mouse.
mouse, err := input.Mouse(ctx)
if err != nil {
return errors.Wrap(err, "unable to setup the mouse")
}
defer mouse.Close()
if err := txtScrollableContentSelector.WaitForExists(ctx, standardizedtestutil.ShortUITimeout); err != nil {
return errors.Wrap(err, "failed to find the scrollable content")
}
if err := txtSuccessSelector.WaitUntilGone(ctx, standardizedtestutil.ShortUITimeout); err != nil {
return errors.Wrap(err, "failed to make sure the success label does not exist")
}
if err := standardizedtestutil.MouseMoveOntoObject(ctx, testParameters, txtScrollableContentSelector, mouse); err != nil {
return errors.Wrap(err, "failed to move onto the scrollable content")
}
// Scroll multiple times, if the threshold is reached early, the test passes.
testPassed := false
for i := 0; i < maxNumScrollIterations; i++ {
// Perform the scroll.
if err := standardizedtestutil.MouseScroll(ctx, testParameters, scrollDirection, mouse); err != nil {
return errors.Wrap(err, "failed to perform the scroll")
}
// Check to see if the test is done.
if err := txtSuccessSelector.WaitForExists(ctx, 1*time.Second); err == nil {
testPassed = true
break
}
}
// Error out if the test did not pass.
if testPassed == false {
return errors.Wrapf(err, "failed to scroll the content past the threshold after %v iterations", maxNumScrollIterations)
}
return nil
}