blob: 7010f8842e7571e6ab47af57bebfd5431d33a6e2 [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 filemanager
import (
"context"
"time"
"chromiumos/tast/common/testexec"
"chromiumos/tast/errors"
"chromiumos/tast/local/chrome/uiauto"
"chromiumos/tast/local/chrome/uiauto/faillog"
"chromiumos/tast/local/chrome/uiauto/filesapp"
"chromiumos/tast/local/chrome/uiauto/nodewith"
"chromiumos/tast/local/chrome/uiauto/role"
"chromiumos/tast/local/crostini"
"chromiumos/tast/local/input"
"chromiumos/tast/local/vm"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: SMB,
Desc: "Mount and check a file on Samba SMB share",
Contacts: []string{
"benreich@chromium.org",
"chromeos-files-syd@google.com",
},
Attr: []string{"group:mainline", "informational"},
Vars: []string{"keepState"},
VarDeps: []string{"ui.gaiaPoolDefault"},
SoftwareDeps: []string{"chrome", "vm_host"},
Data: []string{"smb.conf"},
Params: []testing.Param{
// Parameters generated by smb_test.go. DO NOT EDIT.
{
ExtraData: []string{crostini.GetContainerMetadataArtifact("buster", false), crostini.GetContainerRootfsArtifact("buster", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniStable,
Pre: crostini.StartedByDlcBuster(),
Timeout: 7 * time.Minute,
},
},
})
}
func SMB(ctx context.Context, s *testing.State) {
pre := s.PreValue().(crostini.PreData)
tconn := pre.TestAPIConn
cont := pre.Container
defer faillog.DumpUITreeOnError(ctx, s.OutDir(), s.HasError, tconn)
const smbConfigFile = "smb.conf"
if err := cont.PushFile(ctx, s.DataPath(smbConfigFile), "/tmp/smb.conf"); err != nil {
s.Fatal("Failed copying smb.conf into container: ", err)
}
if err := setupSambaShare(ctx, cont); err != nil {
s.Fatal("Failed executing Samba step commands: ", err)
}
// Launch the files application
files, err := filesapp.Launch(ctx, tconn)
if err != nil {
s.Fatal("Launching the Files App failed: ", err)
}
ui := uiauto.New(tconn)
fileShareURLTextBox := nodewith.Name("File share URL").Role(role.TextField)
if err := uiauto.Combine("Click add SMB file share",
files.ClickMoreMenuItem("Services", "SMB file share"),
ui.WaitForLocation(fileShareURLTextBox),
ui.LeftClick(fileShareURLTextBox))(ctx); err != nil {
s.Fatal("Failed to click add SMB share: ", err)
}
// Get a handle to the input keyboard
kb, err := input.Keyboard(ctx)
if err != nil {
s.Fatal("Failed to get keyboard handle: ", err)
}
defer kb.Close()
if err := kb.Type(ctx, `\\penguin.linux.test\guestshare`); err != nil {
s.Fatal("Failed entering the new SMB file share path: ", err)
}
if err := kb.Accel(ctx, "Enter"); err != nil {
s.Fatal("Failed pressing enter: ", err)
}
if err := uiauto.Combine("Wait for SMB to mount",
files.OpenPath("Files - guestshare", "guestshare"),
files.WaitForFile("test.txt"))(ctx); err != nil {
s.Fatal("Failed to wait for SMB to mount: ", err)
}
}
func setupSambaShare(ctx context.Context, cont *vm.Container) error {
setupCommands := []string{
"sudo mkdir -p /pub/guestshare",
"echo 'test file contents' | sudo tee /pub/guestshare/test.txt",
"sudo chown -R nobody:nogroup /pub/guestshare",
"sudo chmod 0770 /pub/guestshare",
"sudo cp -f /tmp/smb.conf /etc/samba/",
"sudo service smbd restart",
}
for _, cmd := range setupCommands {
if err := cont.Command(ctx, "sh", "-c", cmd).Run(testexec.DumpLogOnError); err != nil {
return errors.Wrapf(err, "failed command: %s", cmd)
}
}
return nil
}