blob: da242352c17ffc6c96077c07136ff6c6d72625b6 [file] [log] [blame]
// Copyright 2019 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 camera
import (
"context"
"time"
"chromiumos/tast/local/bundles/cros/camera/cca"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/media/caps"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: CCAUIExpert,
Desc: "Opens CCA and verifies the expert options",
Contacts: []string{"shik@google.com", "chromeos-camera-eng@google.com"},
Attr: []string{"informational"},
SoftwareDeps: []string{"chrome", "arc_camera3", caps.BuiltinOrVividCamera},
Data: []string{"cca_ui.js"},
Pre: chrome.LoggedIn(),
})
}
func CCAUIExpert(ctx context.Context, s *testing.State) {
cr := s.PreValue().(*chrome.Chrome)
app, err := cca.New(ctx, cr, []string{s.DataPath("cca_ui.js")})
if err != nil {
s.Fatal("Failed to open CCA: ", err)
}
defer app.Close(ctx)
defer app.RemoveCacheData(ctx,
[]string{"expert", "showMetadata", "saveMetadata"})
if err := app.WaitForVideoActive(ctx); err != nil {
s.Fatal("Preview is inactive after launching app: ", err)
}
s.Log("Preview started")
for i, action := range []struct {
Name string
Func func(context.Context, *cca.App) error
Enabled bool
}{
// Expert mode is not reset after each test for persistency
{"toggleExpertMode", toggleExpertMode, false},
{"toggleExpertModeOptions", toggleExpertModeOptions, true},
{"switchSquareMode", switchSquareMode, true},
{"toggleExpertMode", toggleExpertMode, false},
{"toggleExpertMode", toggleExpertMode, true},
{"toggleExpertModeOptions", toggleExpertModeOptions, false},
} {
if err := action.Func(ctx, app); err != nil {
s.Fatalf("Failed to perform action %v of test %v: %v", action.Name, i, err)
}
if err := verifyExpertMode(ctx, app, action.Enabled); err != nil {
s.Errorf("Failed in test %v %v(): %v", i, action.Name, err)
}
}
}
func verifyExpertMode(ctx context.Context, app *cca.App, enabled bool) error {
if err := app.CheckMetadataVisibility(ctx, enabled); err != nil {
return err
}
if _, err := app.TakeSinglePhoto(ctx, cca.TimerOff); err != nil {
return err
}
return nil
}
func toggleExpertMode(ctx context.Context, app *cca.App) error {
_, err := app.ToggleExpertMode(ctx)
// TODO(crbug.com/1039991): There are asynchronous mojo IPC calls happens
// after toggling, and we don't have a way to poll it properly without
// significantly refactor the logic.
testing.Sleep(ctx, time.Second)
return err
}
func toggleExpertModeOptions(ctx context.Context, app *cca.App) error {
if _, err := app.ToggleShowMetadata(ctx); err != nil {
return err
}
if _, err := app.ToggleSaveMetadata(ctx); err != nil {
return err
}
return nil
}
func switchSquareMode(ctx context.Context, app *cca.App) error {
return app.SwitchMode(ctx, cca.Square)
}