| // 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/common/media/caps" |
| "chromiumos/tast/local/camera/cca" |
| "chromiumos/tast/testing" |
| ) |
| |
| func init() { |
| testing.AddTest(&testing.Test{ |
| Func: CCAUITakePicture, |
| Desc: "Opens CCA and verifies photo taking related use cases", |
| Contacts: []string{"inker@chromium.org", "chromeos-camera-eng@google.com"}, |
| Attr: []string{"group:mainline", "informational", "group:camera-libcamera"}, |
| SoftwareDeps: []string{"camera_app", "chrome", caps.BuiltinOrVividCamera}, |
| Fixture: "ccaTestBridgeReady", |
| }) |
| } |
| |
| func CCAUITakePicture(ctx context.Context, s *testing.State) { |
| runSubTest := s.FixtValue().(cca.FixtureData).RunSubTest |
| |
| subTestTimeout := 30 * time.Second |
| for _, tst := range []struct { |
| name string |
| testFunc func(context.Context, *cca.App) error |
| }{ |
| {"testTakeSinglePhoto", testTakeSinglePhoto}, |
| {"testTakeSinglePhotoWithTimer", testTakeSinglePhotoWithTimer}, |
| {"testCancelTimer", testCancelTimer}, |
| } { |
| subTestCtx, cancel := context.WithTimeout(ctx, subTestTimeout) |
| s.Run(subTestCtx, tst.name, func(ctx context.Context, s *testing.State) { |
| if err := runSubTest(ctx, tst.testFunc, cca.SubTestParams{}); err != nil { |
| s.Errorf("Failed to pass %v subtest: %v", tst.name, err) |
| } |
| }) |
| cancel() |
| } |
| } |
| |
| func testTakeSinglePhoto(ctx context.Context, app *cca.App) error { |
| _, err := app.TakeSinglePhoto(ctx, cca.TimerOff) |
| return err |
| } |
| |
| func testTakeSinglePhotoWithTimer(ctx context.Context, app *cca.App) error { |
| _, err := app.TakeSinglePhoto(ctx, cca.TimerOn) |
| return err |
| } |
| |
| func testCancelTimer(ctx context.Context, app *cca.App) error { |
| if err := app.SetTimerOption(ctx, true); err != nil { |
| return err |
| } |
| |
| testing.ContextLog(ctx, "Click on start shutter") |
| if err := app.ClickShutter(ctx); err != nil { |
| return err |
| } |
| if err := testing.Sleep(ctx, time.Second); err != nil { |
| return err |
| } |
| |
| testing.ContextLog(ctx, "Click on cancel shutter") |
| if err := app.ClickShutter(ctx); err != nil { |
| return err |
| } |
| if err := app.WaitForState(ctx, "taking", false); err != nil { |
| return err |
| } |
| return nil |
| } |