blob: 885ca130edfa8cdada79a8ed813f73a2d20a46b3 [file]
// 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 bluetooth
import (
"context"
"chromiumos/tast/local/bluetooth"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/uiauto"
"chromiumos/tast/local/chrome/uiauto/quicksettings"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: ToggleBluetoothFromBluetoothQuickSettings,
LacrosStatus: testing.LacrosVariantUnknown,
Desc: "Checks that Bluetooth can be enabled and disabled from within the Bluetooth Quick Settings",
Contacts: []string{
"chadduffin@chromium.org",
"cros-connectivity@google.com",
},
Attr: []string{"group:mainline", "informational"},
SoftwareDeps: []string{"chrome"},
Fixture: "chromeLoggedInWithBluetoothEnabled",
})
}
// ToggleBluetoothFromBluetoothQuickSettings tests that a user can successfully
// toggle the Bluetooth state using the toggle in the detailed Bluetooth view
// within the Quick Settings.
func ToggleBluetoothFromBluetoothQuickSettings(ctx context.Context, s *testing.State) {
cr := s.FixtValue().(*chrome.Chrome)
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to create Test API connection: ", err)
}
if err := quicksettings.NavigateToBluetoothDetailedView(ctx, tconn); err != nil {
s.Fatal("Failed to navigate to the detailed Bluetooth view: ", err)
}
if err := bluetooth.PollForBTEnabled(ctx); err != nil {
s.Fatal("Expected Bluetooth to be enabled: ", err)
}
ui := uiauto.New(tconn)
state := false
const iterations = 20
for i := 0; i < iterations; i++ {
s.Logf("Toggling Bluetooth (iteration %d of %d)", i+1, iterations)
if err := ui.LeftClick(quicksettings.BluetoothDetailedViewToggleButton)(ctx); err != nil {
s.Fatal("Failed to click the Bluetooth toggle: ", err)
}
if err := bluetooth.PollForAdapterState(ctx, state); err != nil {
s.Fatal("Failed to toggle Bluetooth state: ", err)
}
state = !state
}
}