blob: ba9fa7bd031d9e476394d63c4bf0669135a467f6 [file]
// Copyright 2022 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 assistant
import (
"context"
"time"
"chromiumos/tast/common/action"
"chromiumos/tast/local/assistant"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/uiauto"
"chromiumos/tast/local/chrome/uiauto/nodewith"
"chromiumos/tast/testing"
"chromiumos/tast/testing/hwdep"
)
func init() {
testing.AddTest(&testing.Test{
Func: Hotkey,
LacrosStatus: testing.LacrosVariantUnneeded,
Desc: "Test Assistant hotkey to toggle launcher",
Attr: []string{"group:mainline", "informational"},
Contacts: []string{"yawano@google.com", "assistive-eng@google.com"},
SoftwareDeps: []string{"chrome", "chrome_internal"},
Pre: chrome.LoggedIn(),
Timeout: 3 * time.Minute,
Params: []testing.Param{
{
Name: "assistant_key",
Val: assistant.AccelAssistantKey,
ExtraHardwareDeps: hwdep.D(hwdep.AssistantKey()),
},
{
Name: "search_plus_a",
Val: assistant.AccelSearchPlusA,
ExtraHardwareDeps: hwdep.D(hwdep.NoAssistantKey()),
},
},
})
}
func Hotkey(ctx context.Context, s *testing.State) {
accel := s.Param().(assistant.Accelerator)
cr := s.PreValue().(*chrome.Chrome)
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to create test API connection: ", err)
}
if err := assistant.Enable(ctx, tconn); err != nil {
s.Fatal("Failed to enable Assistant: ", err)
}
defer func() {
if err := assistant.Cleanup(ctx, s.HasError, cr, tconn); err != nil {
s.Fatal("Failed to disable Assistant: ", err)
}
}()
assistantUI := nodewith.HasClass("AssistantPageView")
action.Combine("Press hotkey and confirm that it toggles Assistant UI visibility",
uiauto.New(tconn).WaitUntilGone(assistantUI),
func(ctx context.Context) error { return assistant.ToggleUIWithHotkey(ctx, tconn, accel) },
uiauto.New(tconn).WaitUntilExists(assistantUI),
func(ctx context.Context) error { return assistant.ToggleUIWithHotkey(ctx, tconn, accel) },
uiauto.New(tconn).WaitUntilGone(assistantUI),
)
}