blob: 6c3baa3fa86abbdeca2448db0048ef50f29b3fa1 [file] [log] [blame]
// 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 filemanager
import (
func init() {
Func: DrivefsDssOffline,
Desc: "Verify that making a Docs/Sheets/Slides file available offline through Files App works",
Contacts: []string{
SoftwareDeps: []string{
Attr: []string{
Timeout: 5 * time.Minute,
Pre: pre.DriveFsWithDssPinning,
VarDeps: []string{
func installRequiredExtensions(ctx context.Context, cr *chrome.Chrome, tconn *chrome.TestConn) error {
// TODO(b/193595364): Figure out why these extensions aren't being installed by default in tast tests.
docsOfflineName := "Google Docs Offline"
docsOfflineURL := ""
docsOfflineExt := cws.App{Name: docsOfflineName, URL: docsOfflineURL, InstalledTxt: "Remove from Chrome",
AddTxt: "Add to Chrome", ConfirmTxt: "Add extension"}
if err := cws.InstallApp(ctx, cr, tconn, docsOfflineExt); err != nil {
return errors.Wrap(err, "failed to install Google Docs Offline extension")
proxyExtName := "Application Launcher For Drive (by Google)"
proxyExtURL := ""
proxyExt := cws.App{Name: proxyExtName, URL: proxyExtURL, InstalledTxt: "Remove from Chrome",
AddTxt: "Add to Chrome", ConfirmTxt: "Add extension"}
if err := cws.InstallApp(ctx, cr, tconn, proxyExt); err != nil {
return errors.Wrap(err, "failed to install Application Launcher for Drive extension")
return nil
func DrivefsDssOffline(ctx context.Context, s *testing.State) {
APIClient := s.PreValue().(drivefs.PreData).APIClient
cr := s.PreValue().(drivefs.PreData).Chrome
tconn := s.PreValue().(drivefs.PreData).TestAPIConn
testDocFileName := fmt.Sprintf("doc-drivefs-%d-%d", time.Now().UnixNano(), rand.Intn(10000))
cleanupCtx := ctx
ctx, cancel := ctxutil.Shorten(ctx, 30*time.Second)
defer cancel()
// Create a blank Google doc in the root GDrive directory.
file, err := APIClient.CreateBlankGoogleDoc(ctx, testDocFileName, []string{"root"})
if err != nil {
s.Fatal("Failed to create blank google doc: ", err)
defer APIClient.RemoveFileByID(cleanupCtx, file.Id)
defer faillog.DumpUITreeOnError(cleanupCtx, s.OutDir(), s.HasError, tconn)
if err := installRequiredExtensions(ctx, cr, tconn); err != nil {
s.Fatal("Failed to install the required extensions: ", err)
// Launch Files App.
filesApp, err := filesapp.Launch(ctx, tconn)
if err != nil {
s.Fatal("Failed to launch the Files App: ", err)
// Try make the newly created Google doc available offline.
testFileNameWithExt := fmt.Sprintf("%s.gdoc", testDocFileName)
if err := uiauto.Combine(fmt.Sprintf("Make test file %q in Drive available offline", testFileNameWithExt),
filesApp.LeftClick(nodewith.Name("Enable Offline").Role(role.Button)),
)(ctx); err != nil {
s.Fatalf("Failed to make test file %q in Drive available offline: %v", testFileNameWithExt, err)
s.Log("Waiting for the Available offline toggle to stabilize")
var previousNodeInfo *uiauto.NodeInfo
var currentNodeInfo *uiauto.NodeInfo
if err := testing.Poll(ctx, func(ctx context.Context) error {
currentNodeInfo, err = filesApp.Info(ctx, nodewith.Name("Available offline").Role(role.ToggleButton))
if err != nil {
return testing.PollBreak(errors.Wrap(err, "failed to get info of the Available offline toggle"))
if previousNodeInfo != nil && previousNodeInfo.Checked == currentNodeInfo.Checked {
return nil
previousNodeInfo = currentNodeInfo
return errors.New("the Available offline toggle did not stabilize")
}, &testing.PollOptions{Interval: 500 * time.Millisecond}); err != nil {
s.Fatal("Failed to wait for the Available offline toggle to stabilize")
if currentNodeInfo.Checked != checked.True {
s.Fatalf("The test file %q in Drive was not made available offline", testFileNameWithExt)