blob: f71deb68167a274d6cb6f183c6e5d2527707ffa5 [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/ossettings"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: ToggleBluetoothFromOSSettings,
Desc: "Checks that Bluetooth can be enabled and disabled from the OS Settings",
Contacts: []string{
"chadduffin@chromium.org",
"cros-connectivity@google.com",
},
Attr: []string{"group:mainline", "informational"},
SoftwareDeps: []string{"chrome"},
Fixture: "chromeLoggedInWithBluetoothEnabled",
})
}
// ToggleBluetoothFromOSSettings tests that a user can successfully toggle the
// Bluetooth state using the Bluetooth toggle on the OS Settings page.
func ToggleBluetoothFromOSSettings(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)
}
app, err := ossettings.Launch(ctx, tconn)
defer app.Close(ctx)
if err != nil {
s.Fatal("Failed to launch OS Settings: ", err)
}
if err := bluetooth.Enable(ctx); err != nil {
s.Fatal("Failed to enable Bluetooth: ", err)
}
ui := uiauto.New(tconn)
if err := ui.WaitUntilExists(ossettings.OsSettingsBluetoothToggleButton)(ctx); err != nil {
s.Fatal("Failed to find the Bluetooth toggle: ", err)
}
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(ossettings.OsSettingsBluetoothToggleButton)(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
}
}