/
cca_ui_expert.go
139 lines (121 loc) · 4.01 KB
/
cca_ui_expert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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/errors"
"chromiumos/tast/local/camera/cca"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: CCAUIExpert,
LacrosStatus: testing.LacrosVariantUnneeded,
Desc: "Opens CCA and verifies the expert options",
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", "arc_camera3", caps.BuiltinOrVividCamera},
Fixture: "ccaLaunched",
})
}
func CCAUIExpert(ctx context.Context, s *testing.State) {
app := s.FixtValue().(cca.FixtureData).App()
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},
{"switchModeAndBack", switchModeAndBack, true},
{"toggleExpertMode", toggleExpertMode, false},
{"toggleExpertMode", toggleExpertMode, true},
{"toggleExpertModeOptions", toggleExpertModeOptions, false},
{"disableExpertModeOnUI", disableExpertModeOnUI, false},
{"enableExpertModeOnUI", enableExpertModeOnUI, 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.Fatalf("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 := cca.MainMenu.Open(ctx, app); err != nil {
return err
}
defer cca.MainMenu.Close(ctx, app)
if err := cca.ExpertMenu.Open(ctx, app); err != nil {
return err
}
defer cca.ExpertMenu.Close(ctx, app)
if _, err := app.ToggleOption(ctx, cca.ShowMetadataOption); err != nil {
return err
}
if _, err := app.ToggleOption(ctx, cca.SaveMetadataOption); err != nil {
return err
}
return nil
}
func switchModeAndBack(ctx context.Context, app *cca.App) error {
if err := app.SwitchMode(ctx, cca.Video); err != nil {
return errors.Wrap(err, "failed to switch to video mode")
}
if err := app.SwitchMode(ctx, cca.Photo); err != nil {
return errors.Wrap(err, "failed to switch back to photo mode")
}
return nil
}
func disableExpertModeOnUI(ctx context.Context, app *cca.App) error {
if err := cca.MainMenu.Open(ctx, app); err != nil {
return err
}
defer cca.MainMenu.Close(ctx, app)
if err := cca.ExpertMenu.Open(ctx, app); err != nil {
return err
}
defer cca.ExpertMenu.Close(ctx, app)
if _, err := app.ToggleOption(ctx, cca.ExpertModeOption); err != nil {
return err
}
return nil
}
func enableExpertModeOnUI(ctx context.Context, app *cca.App) error {
if err := cca.MainMenu.Open(ctx, app); err != nil {
return err
}
defer cca.MainMenu.Close(ctx, app)
// Clicking setting header 5 times should enable expert mode. (b/190696285)
for i := 0; i < 5; i++ {
if err := app.ClickWithSelector(ctx, "#settings-header"); err != nil {
return err
}
}
if err := app.WaitForState(ctx, "expert", true); err != nil {
return err
}
return nil
}