blob: e6b9ddd63c6173335841eaf4495346d2ffca60ee [file] [log] [blame] [edit]
// 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 wallpaper
import (
"context"
"path/filepath"
"time"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/uiauto"
"chromiumos/tast/local/chrome/uiauto/faillog"
"chromiumos/tast/local/chrome/uiauto/nodewith"
"chromiumos/tast/local/chrome/uiauto/role"
"chromiumos/tast/local/input"
"chromiumos/tast/local/media/imgcmp"
"chromiumos/tast/local/screenshot"
"chromiumos/tast/local/wallpaper"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: DailyRefresh,
Desc: "Test enabling daily refresh in the new wallpaper app",
Contacts: []string{
"jasontt@google.com",
"croissant-eng@google.com",
},
Attr: []string{"group:mainline", "informational"},
SoftwareDeps: []string{"chrome"},
})
}
// DailyRefresh tests enabling daily refresh and compares the new wallpaper with the old one.
func DailyRefresh(ctx context.Context, s *testing.State) {
cr, err := chrome.New(ctx, chrome.EnableFeatures("WallpaperWebUI"))
if err != nil {
s.Fatal("Failed to connect to Chrome: ", err)
}
defer cr.Close(ctx)
// Open a keyboard device.
kb, err := input.Keyboard(ctx)
if err != nil {
s.Fatal("Failed to open keyboard device: ", err)
}
defer kb.Close()
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to create Test API connection: ", err)
}
defer faillog.DumpUITreeOnError(ctx, s.OutDir(), s.HasError, tconn)
// The test has a dependency of network speed, so we give uiauto.Context ample time to wait for nodes to load.
ui := uiauto.New(tconn).WithTimeout(30 * time.Second)
// Take a screenshot of the current wallpaper.
firstScreenshot, err := screenshot.GrabScreenshot(ctx, cr)
if err != nil {
s.Fatal("Failed to grab screenshot: ", err)
}
const collection = "Solid colors"
if err := uiauto.Combine("Enable daily refresh",
wallpaper.OpenWallpaperPicker(ui),
wallpaper.SelectCollection(ui, collection),
ui.LeftClick(nodewith.Name("Change wallpaper image daily").Role(role.ToggleButton)),
ui.WaitUntilExists(nodewith.Name("Refresh the current wallpaper image").Role(role.Button)),
wallpaper.MinimizeWallpaperPicker(ui),
)(ctx); err != nil {
s.Fatal("Failed to enable daily refresh: ", err)
}
// Take a screenshot of the new wallpaper.
secondScreenshot, err := screenshot.GrabScreenshot(ctx, cr)
if err != nil {
s.Fatal("Failed to grab screenshot: ", err)
}
// Verify that the wallpaper has indeed changed.
const expectedPercent = 90
if err = wallpaper.ValidateDiff(firstScreenshot, secondScreenshot, expectedPercent); err != nil {
firstScreenshotPath := filepath.Join(s.OutDir(), "screenshot_1.png")
secondScreenshotPath := filepath.Join(s.OutDir(), "screenshot_2.png")
if err := imgcmp.DumpImageToPNG(ctx, &firstScreenshot, firstScreenshotPath); err != nil {
s.Errorf("Failed to dump image to %s: %v", firstScreenshotPath, err)
}
if err := imgcmp.DumpImageToPNG(ctx, &secondScreenshot, secondScreenshotPath); err != nil {
s.Errorf("Failed to dump image to %s: %v", secondScreenshotPath, err)
}
s.Fatal("Failed to validate wallpaper difference: ", err)
}
}