| // 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" |
| |
| "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/input" |
| "chromiumos/tast/local/power" |
| "chromiumos/tast/local/ui" |
| "chromiumos/tast/testing" |
| "chromiumos/tast/testing/hwdep" |
| ) |
| |
| func init() { |
| testing.AddTest(&testing.Test{ |
| Func: DragWindowFromShelfPerf, |
| Desc: "Measures the presentation time of dragging a window from the shelf in tablet mode", |
| Contacts: []string{"tbarzic@chromium.org", "xdai@chromium.org", "chromeos-wmp@google.com"}, |
| Attr: []string{"group:crosbolt", "crosbolt_perbuild"}, |
| SoftwareDeps: []string{"chrome"}, |
| HardwareDeps: hwdep.D(hwdep.InternalDisplay()), |
| Fixture: "chromeLoggedIn", |
| }) |
| } |
| |
| func DragWindowFromShelfPerf(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) |
| } |
| |
| 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) |
| |
| // 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() |
| |
| const numWindows = 8 |
| if err := ash.CreateWindows(ctx, tconn, cr, ui.PerftestURL, numWindows); err != nil { |
| s.Fatal("Failed to open browser windows: ", err) |
| } |
| |
| pv := perfutil.RunMultiple(ctx, s, cr, 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") |
| } |
| // Clear the overview mode state so that the next drag can enter into the |
| // overview mode. |
| return ash.SetOverviewModeAndWait(ctx, tconn, false) |
| }, |
| "Ash.DragWindowFromShelf.PresentationTime", |
| "Ash.DragWindowFromShelf.PresentationTime.MaxLatency"), |
| perfutil.StoreLatency) |
| |
| if err := pv.Save(ctx, s.OutDir()); err != nil { |
| s.Error("Failed saving perf data: ", err) |
| } |
| } |