/
smart_selection_chrome.go
103 lines (92 loc) · 3.59 KB
/
smart_selection_chrome.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
// Copyright 2020 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"
"strings"
"time"
"chromiumos/tast/local/arc"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/uiauto"
"chromiumos/tast/local/chrome/uiauto/event"
"chromiumos/tast/local/chrome/uiauto/faillog"
"chromiumos/tast/local/chrome/uiauto/nodewith"
"chromiumos/tast/local/chrome/uiauto/role"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: SmartSelectionChrome,
LacrosStatus: testing.LacrosVariantNeeded,
Desc: "Test ARC's smart selections show up in Chrome's right click menu",
Contacts: []string{"djacobo@chromium.org", "jorgegil@google.com", "chromeos-sw-engprod@google.com", "cros-arc-te@google.com"},
Attr: []string{"group:mainline", "informational"},
SoftwareDeps: []string{"chrome"},
Timeout: 4 * time.Minute,
VarDeps: []string{"arc.SmartSelectionChrome.username", "arc.SmartSelectionChrome.password"},
Params: []testing.Param{{
ExtraSoftwareDeps: []string{"android_p"},
}, {
Name: "vm",
ExtraSoftwareDeps: []string{"android_vm"},
}},
})
}
func SmartSelectionChrome(ctx context.Context, s *testing.State) {
username := s.RequiredVar("arc.SmartSelectionChrome.username")
password := s.RequiredVar("arc.SmartSelectionChrome.password")
cr, err := chrome.New(ctx, chrome.GAIALogin(chrome.Creds{User: username, Pass: password}), chrome.ARCSupported())
if err != nil {
s.Fatal("Failed to start Chrome: ", err)
}
defer cr.Close(ctx)
a, err := arc.New(ctx, s.OutDir())
if err != nil {
s.Fatal("Failed to start ARC by user policy: ", err)
}
defer a.Close(ctx)
if err := a.WaitIntentHelper(ctx); err != nil {
s.Fatal("Failed to wait for ARC Intent Helper: ", err)
}
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to connect Test API: ", err)
}
defer faillog.DumpUITreeOnError(ctx, s.OutDir(), s.HasError, tconn)
ui := uiauto.New(tconn).WithTimeout(30 * time.Second)
// Open page with an address on it.
if _, err := cr.NewConn(ctx, "https://google.com/search?q=1600+amphitheatre+parkway"); err != nil {
s.Fatal("Failed to create new Chrome connection: ", err)
}
// Wait for the address to appear.
address := nodewith.Name("1600 amphitheatre parkway").Role(role.StaticText).First()
if err := ui.WaitUntilExists(address)(ctx); err != nil {
s.Fatal("Failed to wait for address to load: ", err)
}
// Select the address and setup watcher to wait for text selection event
if err := ui.WaitForEvent(nodewith.Root(),
event.TextSelectionChanged,
ui.Select(address, 0, address, 25))(ctx); err != nil {
s.Fatal("Failed to select address: ", err)
}
// Right click the selected address and ensure the smart selection map option is available.
mapOption := nodewith.Name("Map").Role(role.MenuItem)
if err := uiauto.Combine("Show context menu",
ui.RightClick(address),
ui.WaitUntilExists(mapOption))(ctx); err != nil {
s.Log("Failed to show map option: ", err)
// After timeout, dump all the menuItems if possible, this should provide a clear
// idea whether items are missing in the menu or the menu not being there at all.
menu := nodewith.ClassName("MenuItemView")
menuItems, err := ui.NodesInfo(ctx, menu)
if err != nil {
s.Fatal("Could not find context menu items: ", err)
}
var items []string
for _, item := range menuItems {
items = append(items, item.Name)
}
s.Fatalf("Found %d menu items, including: %s", len(items), strings.Join(items, " / "))
}
}