/
unicorn_parent_permission.go
131 lines (115 loc) · 4.36 KB
/
unicorn_parent_permission.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
// Copyright 2021 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 arc
import (
"context"
"time"
"chromiumos/tast/common/android/ui"
"chromiumos/tast/local/apps"
"chromiumos/tast/local/arc"
"chromiumos/tast/local/arc/optin"
"chromiumos/tast/local/chrome/familylink"
"chromiumos/tast/local/chrome/uiauto/faillog"
"chromiumos/tast/local/chrome/uiauto/launcher"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: UnicornParentPermission,
LacrosStatus: testing.LacrosVariantUnneeded,
Desc: "Checks if App Install Triggers Parent Permission For Unicorn Account",
Contacts: []string{"rnanjappan@chromium.org", "cros-arc-te@google.com"},
Attr: []string{"group:mainline", "informational", "group:arc-functional"},
SoftwareDeps: []string{"chrome"},
Timeout: 4 * time.Minute,
VarDeps: []string{"arc.parentUser"},
Params: []testing.Param{{
ExtraSoftwareDeps: []string{"android_p"},
}, {
Name: "vm",
ExtraSoftwareDeps: []string{"android_vm"},
}},
Fixture: "familyLinkUnicornArcLogin",
})
}
func UnicornParentPermission(ctx context.Context, s *testing.State) {
const (
askinMessageButtonText = "Ask in a message"
askinPersonButtonText = "Ask in person"
installButtonText = "install"
playStoreSearchText = "Search for apps & games"
appName = "Instagram"
)
parentUser := s.RequiredVar("arc.parentUser")
cr := s.FixtValue().(*familylink.FixtData).Chrome
tconn := s.FixtValue().(*familylink.FixtData).TestConn
st, err := arc.GetState(ctx, tconn)
if err != nil {
s.Fatal("Failed to get ARC state: ", err)
}
defer faillog.DumpUITreeOnError(ctx, s.OutDir(), s.HasError, tconn)
if st.Provisioned {
s.Log("ARC is already provisioned. Skipping the Play Store setup")
if err := apps.Close(ctx, tconn, apps.PlayStore.ID); err != nil {
s.Fatal("Failed to close the provisioned Play Store: ", err)
}
} else {
// Optin to Play Store.
s.Log("Opting into Play Store")
if err := optin.PerformAndClose(ctx, cr, tconn); err != nil {
s.Fatal("Failed to optin to Play Store and Close: ", err)
}
}
if err := launcher.LaunchApp(tconn, apps.PlayStore.Name)(ctx); err != nil {
s.Fatal("Failed to launch Play Store")
}
// Setup ARC.
a, err := arc.New(ctx, s.OutDir())
if err != nil {
s.Fatal("Failed to start ARC: ", err)
}
defer a.Close(ctx)
d, err := a.NewUIDevice(ctx)
if err != nil {
s.Fatal("Failed initializing UI Automator: ", err)
}
defer d.Close(ctx)
// Try on Install Some Games App.
searchText := d.Object(ui.ClassName("android.widget.TextView"), ui.Text(playStoreSearchText))
if err := searchText.WaitForExists(ctx, 90*time.Second); err != nil {
s.Fatal("searchText doesn't exist: ", err)
}
if err := searchText.Click(ctx); err != nil {
s.Fatal("Failed to click on searchText: ", err)
}
searchTextEdit := d.Object(ui.ClassName("android.widget.EditText"), ui.Text(playStoreSearchText))
if err := searchTextEdit.SetText(ctx, appName); err != nil {
s.Fatal("Failed to set text to search: ", err)
}
if err := d.PressKeyCode(ctx, ui.KEYCODE_ENTER, 0); err != nil {
s.Fatal("Failed to click on KEYCODE_ENTER button: ", err)
}
installButton := d.Object(ui.ClassName("android.widget.Button"), ui.TextMatches("(?i)"+installButtonText), ui.Enabled(true))
if err := installButton.WaitForExists(ctx, 10*time.Second); err != nil {
s.Fatal("Install Button Exisits: ", err)
}
if err := installButton.Click(ctx); err != nil {
s.Fatal("Failed to click installButton: ", err)
}
// Verify Parent Permission Dialog is displayed.
askinPersonButton := d.Object(ui.ClassName("android.widget.Button"), ui.Text(askinPersonButtonText), ui.Enabled(true))
if err := askinPersonButton.WaitForExists(ctx, 90*time.Second); err != nil {
s.Fatal("Ask in person button doesn't Exists: ", err)
}
if err := d.Object(ui.TextMatches(askinMessageButtonText)).Exists(ctx); err != nil {
s.Fatal("Ask in a message button doesn't exist: ", err)
}
if err = askinPersonButton.Click(ctx); err != nil {
s.Fatal("Failed to click Ask in person: ", err)
}
parentPwd := d.Object(ui.ClassName("android.widget.EditText"), ui.Text(parentUser))
if err := parentPwd.WaitForExists(ctx, 90*time.Second); err != nil {
s.Fatal("parentPwd doesn't Exists: ", err)
}
}