blob: c6ccab7492a0f33fa7ff3656fb98055ccd24ac23 [file] [log] [blame]
// 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"
"fmt"
"time"
"chromiumos/tast/errors"
"chromiumos/tast/local/bundles/cros/ui/perfutil"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/ash"
"chromiumos/tast/local/chrome/uiauto"
"chromiumos/tast/local/chrome/uiauto/nodewith"
"chromiumos/tast/local/power"
"chromiumos/tast/testing"
"chromiumos/tast/testing/hwdep"
)
func init() {
testing.AddTest(&testing.Test{
Func: SystemTrayPerf,
Desc: "Measures animation smoothness of system tray animations",
Contacts: []string{"amehfooz@chromium.org", "leandre@chromium.org", "chromeos-wmp@google.com"},
Attr: []string{"group:crosbolt", "crosbolt_perbuild"},
SoftwareDeps: []string{"chrome"},
HardwareDeps: hwdep.D(hwdep.InternalDisplay()),
Fixture: "chromeLoggedIn",
Timeout: 3 * time.Minute,
})
}
func SystemTrayPerf(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)
}
// Add some notifications so that notification centre shows up when opening Quick Settings.
const uiTimeout = 30 * time.Second
const n = 5
ts := []ash.NotificationType{
ash.NotificationTypeBasic,
ash.NotificationTypeImage,
ash.NotificationTypeProgress,
ash.NotificationTypeList,
}
for i := 0; i <= n; i++ {
for _, t := range ts {
if _, err := ash.CreateTestNotification(ctx, tconn, t, fmt.Sprintf("Test%sNotification%d", t, i), "test message"); err != nil {
s.Fatalf("Failed to create %d-th %s notification: %v", i, t, err)
}
}
}
// Wait for the last notification to finish creating.
if _, err := ash.WaitForNotification(ctx, tconn, uiTimeout, ash.WaitTitle(fmt.Sprintf("Test%sNotification%d", ts[len(ts)-1], n))); err != nil {
s.Fatal("Failed waiting for notification: ", err)
}
ac := uiauto.New(tconn)
statusArea := nodewith.ClassName("ash/StatusAreaWidgetDelegate")
collapseButton := nodewith.ClassName("CollapseButton")
// This includes toggle the Status Area button to record input latency of showing Quick Settings/notification centre
// and toggle the collapsed state of the system tray to record animation smoothness.
pv := perfutil.RunMultiple(ctx, s, cr, perfutil.RunAndWaitAll(tconn, func(ctx context.Context) error {
if err := uiauto.Combine(
"open the uber tray, collapse and expand it, then close it",
ac.LeftClick(statusArea),
ac.WaitUntilExists(collapseButton),
ac.LeftClick(collapseButton),
ac.WaitForLocation(collapseButton),
ac.LeftClick(collapseButton),
ac.WaitForLocation(collapseButton),
ac.LeftClick(statusArea),
ac.WaitUntilGone(collapseButton),
)(ctx); err != nil {
return errors.Wrap(err, "failed to open the uber tray, collapse and expand, then close")
}
return nil
},
"Ash.StatusAreaShowBubble.PresentationTime",
"ChromeOS.SystemTray.AnimationSmoothness.TransitionToCollapsed",
"ChromeOS.SystemTray.AnimationSmoothness.TransitionToExpanded"),
perfutil.StoreAllWithHeuristics(""))
if err := pv.Save(ctx, s.OutDir()); err != nil {
s.Fatal("Failed saving perf data: ", err)
}
}