/
drag_maximized_window_perf.go
160 lines (139 loc) · 5.4 KB
/
drag_maximized_window_perf.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
158
159
160
// Copyright 2020 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 ui
import (
"context"
"time"
"chromiumos/tast/errors"
"chromiumos/tast/local/bundles/cros/ui/perfutil"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/ash"
"chromiumos/tast/local/chrome/display"
"chromiumos/tast/local/chrome/uiauto/mouse"
"chromiumos/tast/local/coords"
"chromiumos/tast/local/power"
"chromiumos/tast/local/ui"
"chromiumos/tast/testing"
"chromiumos/tast/testing/hwdep"
)
func init() {
testing.AddTest(&testing.Test{
Func: DragMaximizedWindowPerf,
LacrosStatus: testing.LacrosVariantNeeded,
Desc: "Measures the animation smoothness of dragging a maximized window in clamshell mode",
Contacts: []string{"sammiequon@chromium.org", "chromeos-wmp@google.com"},
Attr: []string{"group:crosbolt", "crosbolt_perbuild"},
SoftwareDeps: []string{"chrome"},
HardwareDeps: hwdep.D(
hwdep.InternalDisplay(),
hwdep.SkipOnModel("burnet"),
),
Fixture: "chromeLoggedIn",
})
}
func DragMaximizedWindowPerf(ctx context.Context, s *testing.State) {
// Ensure display on to record ui performance correctly.
if err := power.TurnOnDisplay(ctx); err != nil {
s.Fatal("Failed to turn on display: ", err)
}
cr := s.FixtValue().(*chrome.Chrome)
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to connect to test API: ", err)
}
cleanup, err := ash.EnsureTabletModeEnabled(ctx, tconn, false)
if err != nil {
s.Fatal("Failed to ensure in clamshell mode: ", err)
}
defer cleanup(ctx)
// We are only dragging one window, but have some background windows as occlusion changes can impact performance.
const numWindows = 5
if err := ash.CreateWindows(ctx, tconn, cr, ui.PerftestURL, numWindows); err != nil {
s.Fatal("Failed to open browser windows: ", err)
}
info, err := display.GetPrimaryInfo(ctx, tconn)
if err != nil {
s.Fatal("Failed to get the internal display info: ", err)
}
width := info.WorkArea.Width
height := info.WorkArea.Height
if err := ash.ForEachWindow(ctx, tconn, func(w *ash.Window) error {
if err := ash.SetWindowStateAndWait(ctx, tconn, w.ID, ash.WindowStateMaximized); err != nil {
return errors.Wrapf(err, "failed to maximize window %d", w.ID)
}
return nil
}); err != nil {
s.Fatal("Failed to setup windows: ", err)
}
// Get the first window.
maximizedWindow, err := ash.FindWindow(ctx, tconn, func(w *ash.Window) bool {
return true
})
if err != nil {
s.Fatal("Failed to obtain the first window: ", err)
}
if maximizedWindow.State != ash.WindowStateMaximized {
s.Fatalf("The first window %d is not maximized (state %q)", maximizedWindow.ID, maximizedWindow.State)
}
if !maximizedWindow.IsActive {
s.Fatalf("The first window %d is not active", maximizedWindow.ID)
}
// Start the drag in the middle of the caption. Drag down to unmaximize, then circle around to trigger some
// occlusion changes. Finally, drag back to the top to maximize the window again.
points := []coords.Point{
// Caption center.
coords.NewPoint(maximizedWindow.BoundsInRoot.Width/2, 5),
// Points in some select parts of the display (diamond shape).
coords.NewPoint(10, height/2),
coords.NewPoint(width/2, height-10),
coords.NewPoint(width-10, height/2),
}
// Return to the caption center, this will trigger a remaximize animation.
points = append(points, points[0])
pv := perfutil.RunMultiple(ctx, s, cr.Browser(), perfutil.RunAndWaitAll(tconn, func(ctx context.Context) error {
// Move the mouse to caption and press down.
if err := mouse.Move(tconn, points[0], 10*time.Millisecond)(ctx); err != nil {
return errors.Wrap(err, "failed to move to caption")
}
if err := mouse.Press(tconn, mouse.LeftButton)(ctx); err != nil {
return errors.Wrap(err, "failed to press the button")
}
// Drag the window around.
const dragTime = 500 * time.Millisecond
for _, point := range points {
if err := mouse.Move(tconn, point, dragTime)(ctx); err != nil {
return errors.Wrap(err, "failed to drag")
}
}
// Needs to wait a bit before releasing the mouse, otherwise the window
// may not get back to be maximized. See https://crbug.com/1158548.
if err := testing.Sleep(ctx, time.Second); err != nil {
return errors.Wrap(err, "failed to wait")
}
// Release the window. It is near the top of the screen so it should snap to maximize.
if err := mouse.Release(tconn, mouse.LeftButton)(ctx); err != nil {
return errors.Wrap(err, "failed to release the button")
}
// The window animates when snapping to maximize. Wait for it to finish animating before ending.
if err := ash.WaitWindowFinishAnimating(ctx, tconn, maximizedWindow.ID); err != nil {
return errors.Wrap(err, "failed to wait for top window animation")
}
// Validity check to ensure the window is maximized at the end. Otherwise, the test results are not very
// useful.
windows, err := ash.GetAllWindows(ctx, tconn)
if err != nil {
return errors.Wrap(err, "failed to obtain the window list")
}
if windows[0].State != ash.WindowStateMaximized {
return errors.New("window is not maximized")
}
return nil
},
"Ash.Window.AnimationSmoothness.CrossFade.DragMaximize",
"Ash.Window.AnimationSmoothness.CrossFade.DragUnmaximize"),
perfutil.StoreSmoothness)
if err := pv.Save(ctx, s.OutDir()); err != nil {
s.Error("Failed saving perf data: ", err)
}
}