/
hotseat_animation.go
397 lines (344 loc) · 13.9 KB
/
hotseat_animation.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// 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/common/perf"
"chromiumos/tast/ctxutil"
"chromiumos/tast/errors"
"chromiumos/tast/local/bundles/cros/ui/perfutil"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/ash"
"chromiumos/tast/local/chrome/browser"
"chromiumos/tast/local/chrome/display"
"chromiumos/tast/local/chrome/metrics"
"chromiumos/tast/local/coords"
"chromiumos/tast/local/input"
"chromiumos/tast/local/ui"
"chromiumos/tast/testing"
"chromiumos/tast/testing/hwdep"
)
type hotseatTestType string
const (
nonOverflow hotseatTestType = "NonOverflow"
overflow hotseatTestType = "Oveflow" // In test, add enough apps to enter overflow mode.
showNavigationWidget hotseatTestType = "ShowNavigationWidget" // In test, show the navigation widget (including home button and back button) by disabling the flag which hides the navigation widget as default.
)
type hotseatTestVal struct {
TestType hotseatTestType
}
func init() {
testing.AddTest(&testing.Test{
Func: HotseatAnimation,
LacrosStatus: testing.LacrosVariantUnknown,
Desc: "Measures the framerate of the hotseat animation in tablet mode",
Contacts: []string{"newcomer@chromium.org", "manucornet@chromium.org", "andrewxu@chromium.org", "cros-shelf-prod-notifications@google.com"},
Attr: []string{"group:crosbolt", "crosbolt_perbuild"},
SoftwareDeps: []string{"chrome"},
HardwareDeps: hwdep.D(hwdep.InternalDisplay()),
Timeout: 3 * time.Minute,
Params: []testing.Param{
{
Name: "non_overflow_shelf",
Val: nonOverflow,
Fixture: "chromeLoggedInWith100FakeApps",
},
{
Name: "overflow_shelf",
Val: overflow,
Fixture: "chromeLoggedInWith100FakeApps",
},
// TODO(https://crbug.com/1083068): when the flag shelf-hide-buttons-in-tablet is removed, delete this sub-test.
{
Name: "shelf_with_navigation_widget",
Val: showNavigationWidget,
Fixture: "install100Apps",
},
},
})
}
// HotseatAnimation measures the performance of hotseat background bounds animation.
func HotseatAnimation(ctx context.Context, s *testing.State) {
const (
// Histograms for hotseat.
extendedHotseatWidgetHistogram = "Ash.HotseatWidgetAnimation.Widget.AnimationSmoothness.TransitionToExtendedHotseat"
hiddenHotseatHistogram = "Ash.HotseatTransition.AnimationSmoothness.TransitionToHiddenHotseat"
hiddenHotseatWidgetHistogram = "Ash.HotseatWidgetAnimation.Widget.AnimationSmoothness.TransitionToHiddenHotseat"
shownHotseatHistogram = "Ash.HotseatTransition.AnimationSmoothness.TransitionToShownHotseat"
shownHotseatWidgetHistogram = "Ash.HotseatWidgetAnimation.Widget.AnimationSmoothness.TransitionToShownHotseat"
shownHotseatTranslucentBackgroundHistogram = "Ash.HotseatWidgetAnimation.TranslucentBackground.AnimationSmoothness.TransitionToShownHotseat"
shownHomeLauncherHistogram = "Apps.HomeLauncherTransition.AnimationSmoothness.FadeInOverview"
hiddenHomeLauncherHistogram = "Apps.HomeLauncherTransition.AnimationSmoothness.FadeOutOverview"
// Histograms for back button.
hiddenBackButtonHistogram = "Ash.NavigationWidget.BackButton.AnimationSmoothness.TransitionToHiddenHotseat"
shownBackButtonHistogram = "Ash.NavigationWidget.BackButton.AnimationSmoothness.TransitionToShownHotseat"
// Histograms for home button.
hiddenHomeButtonHistogram = "Ash.NavigationWidget.HomeButton.AnimationSmoothness.TransitionToHiddenHotseat"
shownHomeButtonHistogram = "Ash.NavigationWidget.HomeButton.AnimationSmoothness.TransitionToShownHotseat"
// Histograms for navigation widget.
hiddenWidgetHistogram = "Ash.NavigationWidget.Widget.AnimationSmoothness.TransitionToHiddenHotseat"
shownWidgetHistogram = "Ash.NavigationWidget.Widget.AnimationSmoothness.TransitionToShownHotseat"
overviewTimeout = 10 * time.Second
swipeDuration = 500 * time.Millisecond
)
var cr *chrome.Chrome
testType := s.Param().(hotseatTestType)
if testType == showNavigationWidget {
opts := []chrome.Option{chrome.DisableFeatures("HideShelfControlsInTabletMode")}
opts = append(opts, s.FixtValue().([]chrome.Option)...)
var err error
cr, err = chrome.New(ctx, opts...)
if err != nil {
s.Fatal("Failed to connect to Chrome: ", err)
}
defer cr.Close(ctx)
} else {
cr = s.FixtValue().(*chrome.Chrome)
}
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to connect to test API: ", err)
}
orientation, err := display.GetOrientation(ctx, tconn)
if err != nil {
s.Fatal("Failed to obtain the display rotation: ", err)
}
cleanup, err := ash.EnsureTabletModeEnabled(ctx, tconn, true)
if err != nil {
s.Fatal("Failed to ensure in tablet mode: ", err)
}
defer cleanup(ctx)
// The app list gets shown during transition to tablet mode, Wait for the transition to
// full screen app list to finish before proceeding with testing hotseat animations to
// prevent the app list animation's adverse effect on the initial hotseat transition.
if err := ash.WaitForLauncherState(ctx, tconn, ash.FullscreenAllApps); err != nil {
s.Fatal("Home launcher failed to show: ", err)
}
// Prepare the touch screen as this test requires touch scroll events.
tsw, err := input.Touchscreen(ctx)
if err != nil {
s.Fatal("Failed to create touch screen event writer: ", err)
}
defer tsw.Close()
if err := tsw.SetRotation(-orientation.Angle); err != nil {
s.Fatal("Failed to set rotation: ", err)
}
stw, err := tsw.NewSingleTouchWriter()
if err != nil {
s.Fatal("Failed to create single touch writer: ", err)
}
defer stw.Close()
shouldEnterOverflow := testType != nonOverflow
if shouldEnterOverflow {
if err := ash.EnterShelfOverflow(ctx, tconn); err != nil {
s.Fatal(err, "Failed to enter overflow shelf")
}
}
// Changing tablet mode may change the shelf/hotseat bounds. Make sure the bounds
// stabilize before starting tests.
if err := ash.WaitForStableShelfBounds(ctx, tconn); err != nil {
s.Fatal("Failed to wait for stable shelf bouds: ", err)
}
runner := perfutil.NewRunner(cr.Browser())
// Collect metrics data from hiding hotseat by window creation.
histogramsName := []string{
hiddenHotseatHistogram,
hiddenHotseatWidgetHistogram,
shownHotseatHistogram,
shownHotseatWidgetHistogram}
if s.Param().(hotseatTestType) == showNavigationWidget {
histogramsName = append(histogramsName,
hiddenBackButtonHistogram,
hiddenHomeButtonHistogram,
hiddenWidgetHistogram,
shownBackButtonHistogram,
shownHomeButtonHistogram,
shownWidgetHistogram)
}
runner.RunMultiple(ctx, s, "WindowCreation", perfutil.RunAndWaitAll(tconn, func(ctx context.Context) error {
sctx, cancel := ctxutil.Shorten(ctx, 5*time.Second)
defer cancel()
conn, err := cr.NewConn(sctx, "", browser.WithNewWindow())
if err != nil {
return errors.Wrap(err, "failed to open browser window")
}
defer func() {
if err := conn.Close(); err != nil {
s.Error("Failed to close a connection: ", err)
}
}()
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfHidden); err != nil {
conn.CloseTarget(ctx)
return err
}
if err := conn.CloseTarget(ctx); err != nil {
return errors.Wrap(err, "failed to close a target")
}
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfShownHomeLauncher); err != nil {
return err
}
return nil
}, histogramsName...),
perfutil.StoreAll(perf.BiggerIsBetter, "percent", "WindowCreation"))
// Collect metrics data from entering/exiting overview.
histogramsName = []string{
shownHotseatHistogram,
shownHotseatWidgetHistogram,
extendedHotseatWidgetHistogram,
shownHomeLauncherHistogram,
hiddenHomeLauncherHistogram}
if shouldEnterOverflow {
// Record metrics data which can only be collected in overflow shelf.
histogramsName = append(histogramsName, shownHotseatTranslucentBackgroundHistogram)
}
if testType == showNavigationWidget {
// Record metrics data which can only be collected with the shelf navigation widget shown.
histogramsName = append(histogramsName,
shownBackButtonHistogram,
shownHomeButtonHistogram,
shownWidgetHistogram)
}
// Histograms for window activation.
windowActivationHistogramNames := map[string]bool{
hiddenHotseatHistogram: true,
hiddenHotseatWidgetHistogram: true,
}
if s.Param().(hotseatTestType) == showNavigationWidget {
windowActivationHistogramNames[hiddenBackButtonHistogram] = true
windowActivationHistogramNames[hiddenHomeButtonHistogram] = true
windowActivationHistogramNames[hiddenWidgetHistogram] = true
}
for name := range windowActivationHistogramNames {
histogramsName = append(histogramsName, name)
}
// Add a new tab.
conn, err := cr.NewConn(ctx, ui.PerftestURL)
if err != nil {
s.Fatal("Failed to create a new tab: ", err)
}
conn.Close()
displayInfo, err := display.GetInternalInfo(ctx, tconn)
if err != nil {
s.Fatal("Failed to get display info")
}
tcc := tsw.NewTouchCoordConverter(displayInfo.Bounds.Size())
if err != nil {
s.Fatal("Failed to generate touch coord converter")
}
runner.RunMultiple(ctx, s, "", perfutil.RunAndWaitAll(tconn, func(ctx context.Context) error {
if err := ash.DragToShowOverview(ctx, tsw, stw, tconn); err != nil {
return errors.Wrap(err, "failed to drag from bottom of the screen to show overview")
}
touchPoint := coords.NewPoint(displayInfo.Bounds.Width/20, displayInfo.Bounds.Height/20)
// Enter home launcher from overview by gesture tap.
pressX, pressY := tcc.ConvertLocation(touchPoint)
if err := stw.Swipe(ctx, pressX, pressY, pressX+5, pressY+5, swipeDuration); err != nil {
return errors.Wrap(err, "failed to tap")
}
if err := stw.End(); err != nil {
return errors.Wrap(err, "failed to finish the tap gesture")
}
if err := ash.WaitForOverviewState(ctx, tconn, ash.Hidden, overviewTimeout); err != nil {
return errors.Wrap(err, "failed to wait for animation to finish")
}
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfShownHomeLauncher); err != nil {
return err
}
if err := ash.DragToShowOverview(ctx, tsw, stw, tconn); err != nil {
return errors.Wrap(err, "failed to drag from bottom of the screen to show overview")
}
// Enter in-app mode from overview by tapping within an overview window bounds.
window, err := ash.FindFirstWindowInOverview(ctx, tconn)
if err != nil {
return errors.Wrap(err, "no overview window found")
}
touchPoint = window.OverviewInfo.Bounds.CenterPoint()
pressX, pressY = tcc.ConvertLocation(touchPoint)
if err := stw.Swipe(ctx, pressX, pressY, pressX+5, pressY-5, swipeDuration); err != nil {
return errors.Wrap(err, "failed to tap")
}
if err := stw.End(); err != nil {
return errors.Wrap(err, "failed to finish the tap gesture")
}
if err := ash.WaitForOverviewState(ctx, tconn, ash.Hidden, overviewTimeout); err != nil {
return errors.Wrap(err, "failed to wait for animation to finish")
}
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfHidden); err != nil {
return err
}
// Swipe the hotseat up from the hidden state to the extended state.
if err := ash.SwipeUpHotseatAndWaitForCompletion(ctx, tconn, stw, tcc); err != nil {
return err
}
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfExtended); err != nil {
return err
}
// Enter home launcher from in-app mode by gesture swipe up from shelf.
start := displayInfo.Bounds.BottomCenter()
startX, startY := tcc.ConvertLocation(start)
end := displayInfo.Bounds.CenterPoint()
endX, endY := tcc.ConvertLocation(end)
if err := stw.Swipe(ctx, startX, startY-1, endX, endY, swipeDuration); err != nil {
return errors.Wrap(err, "failed to swipe")
}
if err := stw.End(); err != nil {
return errors.Wrap(err, "failed to finish the swipe gesture")
}
if err := ash.WaitForLauncherState(ctx, tconn, ash.FullscreenAllApps); err != nil {
return errors.Wrap(err, "home launcher failed to show")
}
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfShownHomeLauncher); err != nil {
return err
}
// Verify the initial hotseat state before hiding.
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfShownHomeLauncher); err != nil {
return err
}
scrollableShelfInfo, err := ash.FetchScrollableShelfInfoForState(ctx, tconn, &ash.ShelfState{})
if err != nil {
return err
}
if len(scrollableShelfInfo.IconsBoundsInScreen) == 0 {
return errors.New("failed to activate a window: got 0 shelf icons; expect at least one shelf icon")
}
// Tap on the shelf icon to activate a window to hide the hotseat.
centerPoint := scrollableShelfInfo.IconsBoundsInScreen[0].CenterPoint()
tapPointX, tapPointY := tcc.ConvertLocation(centerPoint)
if err := stw.Move(tapPointX, tapPointY); err != nil {
return err
}
if err := stw.End(); err != nil {
return err
}
// Verify the final hotseat state.
if err := ash.WaitForHotseatAnimatingToIdealState(ctx, tconn, ash.ShelfHidden); err != nil {
return err
}
return nil
}, histogramsName...),
func(ctx context.Context, pv *perfutil.Values, hists []*metrics.Histogram) error {
for _, hist := range hists {
mean, err := hist.Mean()
if err != nil {
return errors.Wrapf(err, "failed to get histogram for %s", hist.Name)
}
name := hist.Name
if windowActivationHistogramNames[hist.Name] {
name = name + ".WindowActivation"
}
testing.ContextLog(ctx, name, " = ", mean)
pv.Append(perf.Metric{
Name: name,
Unit: "percent",
Direction: perf.BiggerIsBetter,
}, mean)
}
return nil
})
// Save metrics data in file.
if err := runner.Values().Save(ctx, s.OutDir()); err != nil {
s.Fatal("Failed saving perf data in file: ", err)
}
}