blob: 5bdc5fd9c3cd088be1bcba9288ee17abd60808e4 [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"
"chromiumos/tast/common/media/caps"
"chromiumos/tast/errors"
"chromiumos/tast/local/camera/cca"
"chromiumos/tast/local/camera/testutil"
"chromiumos/tast/local/chrome"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: CCAUIPreview,
Desc: "Opens CCA and verifies the preview functions",
Contacts: []string{"inker@chromium.org", "shik@chromium.org", "chromeos-camera-eng@google.com"},
Attr: []string{"group:mainline", "informational", "group:camera-libcamera"},
SoftwareDeps: []string{"camera_app", "chrome", caps.BuiltinOrVividCamera},
Data: []string{"cca_ui.js"},
Pre: chrome.LoggedIn(),
})
}
func CCAUIPreview(ctx context.Context, s *testing.State) {
cr := s.PreValue().(*chrome.Chrome)
tb, err := testutil.NewTestBridge(ctx, cr, testutil.UseRealCamera)
if err != nil {
s.Fatal("Failed to construct test bridge: ", err)
}
defer tb.TearDown(ctx)
if err := cca.ClearSavedDirs(ctx, cr); err != nil {
s.Fatal("Failed to clear saved directory: ", err)
}
app, err := cca.New(ctx, cr, []string{s.DataPath("cca_ui.js")}, s.OutDir(), tb)
if err != nil {
s.Fatal("Failed to open CCA: ", err)
}
defer func(ctx context.Context) {
if err := app.Close(ctx); err != nil {
s.Error("Failed to close app: ", err)
}
}(ctx)
if err := testResize(ctx, app); err != nil {
s.Error("Failed in testResize(): ", err)
// TODO(b/184131041): Guard the restart using a longer context so that
// we can still restart app if the sub test reaches the timeout once we
// have other sub tests.
// Restart app using non-shorten context.
if err := app.Restart(ctx, tb); err != nil {
s.Fatal("Failed to restart CCA: ", err)
}
}
// TODO(shik): Add the missing preview tests in go/cca-test:
// * Preview active after going back from gallery
// * Preview active after taking picture
// * Preview active after recording
// * Preview active after suspend/resume
}
func testResize(ctx context.Context, app *cca.App) error {
restore := func() error {
if err := app.RestoreWindow(ctx); err != nil {
return errors.Wrap(err, "failed to restore window")
}
// It is expected that the preview will only be active after the window
// is focus.
if err := app.Focus(ctx); err != nil {
return errors.Wrap(err, "failed to focus window")
}
if err := app.WaitForVideoActive(ctx); err != nil {
return errors.Wrap(err, "preview is inactive after restoring window")
}
return nil
}
if err := restore(); err != nil {
return err
}
testing.ContextLog(ctx, "Maximizing window")
if err := app.MaximizeWindow(ctx); err != nil {
return errors.Wrap(err, "failed to maximize window")
}
if err := app.WaitForVideoActive(ctx); err != nil {
return errors.Wrap(err, "preview is inactive after maximizing window")
}
if err := restore(); err != nil {
return errors.Wrap(err, "failed in restore() after maximizing window")
}
testing.ContextLog(ctx, "Fullscreening window")
if err := app.FullscreenWindow(ctx); err != nil {
return errors.Wrap(err, "failed to fullscreen window")
}
if err := app.WaitForVideoActive(ctx); err != nil {
return errors.Wrap(err, "preview is inactive after fullscreening window")
}
if err := restore(); err != nil {
return errors.Wrap(err, "failed in restore() after fullscreening window")
}
testing.ContextLog(ctx, "Minimizing window")
if err := app.MinimizeWindow(ctx); err != nil {
return errors.Wrap(err, "failed to minimize window")
}
if err := app.CheckVideoInactive(ctx); err != nil {
return errors.Wrap(err, "preview is active after minimizing window")
}
if err := restore(); err != nil {
return errors.Wrap(err, "failed in restore() after maximizing window")
}
return nil
}