blob: bfe1f8c1f95793758e09c5e2d08e311cc4254022 [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 crostini
import (
"context"
"time"
"chromiumos/tast/ctxutil"
"chromiumos/tast/local/chrome/uiauto"
"chromiumos/tast/local/chrome/uiauto/filesapp"
"chromiumos/tast/local/crostini"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: FilesAppWatch,
Desc: "Checks crostini FilesApp watch",
Contacts: []string{"joelhockey@chromium.org", "cros-containers-dev@google.com"},
Attr: []string{"group:mainline", "informational"},
Vars: []string{"keepState"},
VarDeps: []string{"ui.gaiaPoolDefault"},
SoftwareDeps: []string{"chrome", "vm_host"},
Params: []testing.Param{
// Parameters generated by params_test.go. DO NOT EDIT.
{
Name: "stretch_stable",
ExtraData: []string{crostini.GetContainerMetadataArtifact("stretch", false), crostini.GetContainerRootfsArtifact("stretch", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniStable,
Pre: crostini.StartedByDlcStretch(),
Timeout: 7 * time.Minute,
}, {
Name: "stretch_unstable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("stretch", false), crostini.GetContainerRootfsArtifact("stretch", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniUnstable,
Pre: crostini.StartedByDlcStretch(),
Timeout: 7 * time.Minute,
}, {
Name: "buster_stable",
ExtraData: []string{crostini.GetContainerMetadataArtifact("buster", false), crostini.GetContainerRootfsArtifact("buster", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniStable,
Pre: crostini.StartedByDlcBuster(),
Timeout: 7 * time.Minute,
}, {
Name: "buster_unstable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("buster", false), crostini.GetContainerRootfsArtifact("buster", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniUnstable,
Pre: crostini.StartedByDlcBuster(),
Timeout: 7 * time.Minute,
}, {
Name: "bullseye_stable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("bullseye", false), crostini.GetContainerRootfsArtifact("bullseye", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniStable,
Pre: crostini.StartedByDlcBullseye(),
Timeout: 7 * time.Minute,
}, {
Name: "bullseye_unstable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("bullseye", false), crostini.GetContainerRootfsArtifact("bullseye", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniUnstable,
Pre: crostini.StartedByDlcBullseye(),
Timeout: 7 * time.Minute,
},
},
})
}
func FilesAppWatch(ctx context.Context, s *testing.State) {
pre := s.PreValue().(crostini.PreData)
tconn := pre.TestAPIConn
cont := s.PreValue().(crostini.PreData).Container
defer crostini.RunCrostiniPostTest(ctx, s.PreValue().(crostini.PreData))
// Use a shortened context for test operations to reserve time for cleanup.
cleanupCtx := ctx
ctx, cancel := ctxutil.Shorten(ctx, 5*time.Second)
defer cancel()
const (
testFileName1 = "FilesAppWatch1.txt"
testFileName2 = "FilesAppWatch2.txt"
testFileContent = "FilesAppWatch"
)
if err := cont.WriteFile(ctx, testFileName1, testFileContent); err != nil {
s.Fatal("Create file failed: ", err)
}
defer cont.RemoveAll(cleanupCtx, testFileName1)
// Launch the files application
files, err := filesapp.Launch(ctx, tconn)
if err != nil {
s.Fatal("Launching the Files App failed: ", err)
}
// Validate file1.txt is shown in 'Linux files'.
if err := uiauto.Combine("find file1.txt",
files.OpenDir("Linux files", "Files - Linux files"),
files.WithTimeout(10*time.Second).WaitForFile(testFileName1))(ctx); err != nil {
s.Fatal("Failed to find file1.txt created in the container in Linux files: ", err)
}
// Create file2.txt in container and check that FilesApp refreshes.
if err := cont.WriteFile(ctx, testFileName2, testFileContent); err != nil {
s.Fatal("Create file failed: ", err)
}
defer cont.RemoveAll(cleanupCtx, testFileName2)
if err := files.WithTimeout(10 * time.Second).WaitForFile(testFileName2)(ctx); err != nil {
s.Fatal("Waiting for file2.txt failed: ", err)
}
}