[skyvault] Add default display root integrations tests

Adds files manager integration tests to check if the Files App defaults
to the correct directory when SkyVault is enabled, e.g. Google Drive and
not to My Files as usual.

R=lucmult@chromium.org

Fixed: b/330879532
Change-Id: I4f9566fcf41a0bb02a69965884a053fd6e395045
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5439532
Reviewed-by: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Aida Zolic <aidazolic@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1287800}
diff --git a/chrome/browser/ash/file_manager/file_manager_browsertest.cc b/chrome/browser/ash/file_manager/file_manager_browsertest.cc
index d2bef94..bd64772 100644
--- a/chrome/browser/ash/file_manager/file_manager_browsertest.cc
+++ b/chrome/browser/ash/file_manager/file_manager_browsertest.cc
@@ -425,7 +425,15 @@
         TestCase("fileDisplayCheckReadOnlyIconOnFakeDirectory"),
         TestCase("fileDisplayCheckNoReadOnlyIconOnDownloads"),
         TestCase("fileDisplayCheckNoReadOnlyIconOnLinuxFiles"),
-        TestCase("fileDisplayCheckNoReadOnlyIconOnGuestOs")));
+        TestCase("fileDisplayCheckNoReadOnlyIconOnGuestOs"),
+        TestCase("fileDisplayLocalFilesDisabledUnmountRemovable")
+            .DontMountVolumes()
+            .NewDirectoryTree()
+            .EnableSkyVault(),
+        TestCase("fileDisplayLocalFilesDisableInMyFiles")
+            .DontMountVolumes()
+            .NewDirectoryTree()
+            .EnableSkyVault()));
 
 WRAPPED_INSTANTIATE_TEST_SUITE_P(
     OpenVideoMediaApp, /* open_video_media_app.js */
diff --git a/chrome/browser/ash/file_manager/file_manager_browsertest_base.cc b/chrome/browser/ash/file_manager/file_manager_browsertest_base.cc
index 436ca99..37a4180 100644
--- a/chrome/browser/ash/file_manager/file_manager_browsertest_base.cc
+++ b/chrome/browser/ash/file_manager/file_manager_browsertest_base.cc
@@ -98,6 +98,7 @@
 #include "chrome/browser/ash/system/timezone_util.h"
 #include "chrome/browser/ash/system_web_apps/system_web_app_manager.h"
 #include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_dir_util.h"
 #include "chrome/browser/download/download_prefs.h"
 #include "chrome/browser/enterprise/connectors/connectors_service.h"
 #include "chrome/browser/extensions/mixin_based_extension_apitest.h"
@@ -2424,6 +2425,12 @@
     disabled_features.push_back(ash::features::kFilesNewDirectoryTree);
   }
 
+  if (options.enable_skyvault) {
+    enabled_features.push_back(features::kSkyVault);
+  } else {
+    disabled_features.push_back(features::kSkyVault);
+  }
+
   // This is destroyed in |TearDown()|. We cannot initialize this in the
   // constructor due to this feature values' above dependence on virtual
   // method calls, but by convention subclasses of this fixture may initialize
@@ -3411,6 +3418,14 @@
     return;
   }
 
+  if (name == "setupSkyVault") {
+    profile()->GetPrefs()->SetString(prefs::kFilesAppDefaultLocation,
+                                     download_dir_util::kLocationGoogleDrive);
+    g_browser_process->local_state()->SetBoolean(prefs::kLocalUserFilesAllowed,
+                                                 false);
+    return;
+  }
+
   if (name == "setTrashEnabled") {
     std::optional<bool> enabled = value.FindBool("enabled");
     ASSERT_TRUE(enabled.has_value());
diff --git a/chrome/browser/ash/file_manager/file_manager_browsertest_base.h b/chrome/browser/ash/file_manager/file_manager_browsertest_base.h
index 094f9ac..06b0856 100644
--- a/chrome/browser/ash/file_manager/file_manager_browsertest_base.h
+++ b/chrome/browser/ash/file_manager/file_manager_browsertest_base.h
@@ -207,6 +207,9 @@
     // Whether to enable new directory tree implementation.
     bool enable_new_directory_tree = false;
 
+    // Whether test should enable the SkyVault feature.
+    bool enable_skyvault = false;
+
     // Feature IDs associated for mapping test cases and features.
     std::vector<std::string> feature_ids;
   };
diff --git a/chrome/browser/ash/file_manager/file_manager_browsertest_utils.cc b/chrome/browser/ash/file_manager/file_manager_browsertest_utils.cc
index b93849f..30526cb 100644
--- a/chrome/browser/ash/file_manager/file_manager_browsertest_utils.cc
+++ b/chrome/browser/ash/file_manager/file_manager_browsertest_utils.cc
@@ -219,6 +219,11 @@
   return *this;
 }
 
+TestCase& TestCase::EnableSkyVault() {
+  options.enable_skyvault = true;
+  return *this;
+}
+
 std::string TestCase::GetFullName() const {
   std::string full_name = name;
 
diff --git a/chrome/browser/ash/file_manager/file_manager_browsertest_utils.h b/chrome/browser/ash/file_manager/file_manager_browsertest_utils.h
index 388cf84..b8e7cdd 100644
--- a/chrome/browser/ash/file_manager/file_manager_browsertest_utils.h
+++ b/chrome/browser/ash/file_manager/file_manager_browsertest_utils.h
@@ -116,6 +116,8 @@
 
   TestCase& EnableCrosComponents();
 
+  TestCase& EnableSkyVault();
+
   std::string GetFullName() const;
 
   const char* const name;
diff --git a/ui/file_manager/integration_tests/file_manager/file_display.ts b/ui/file_manager/integration_tests/file_manager/file_display.ts
index a7e8a14..f6a10b3 100644
--- a/ui/file_manager/integration_tests/file_manager/file_display.ts
+++ b/ui/file_manager/integration_tests/file_manager/file_display.ts
@@ -972,3 +972,63 @@
   // Check: the toolbar read-only indicator should not be visible.
   await remoteCall.waitForElement(appId, '#read-only-indicator[hidden]');
 }
+
+/**
+ * Tests that when local files are disabled, we navigate to default set by the
+ * policy, e.g. Drive after unmounting a USB.
+ */
+export async function fileDisplayLocalFilesDisabledUnmountRemovable() {
+  // Mount Drive and Downloads.
+  await sendTestMessage({name: 'mountDrive'});
+  await sendTestMessage({name: 'mountDownloads'});
+  // Ensure two volumes are mounted.
+  await remoteCall.waitForVolumesCount(2);
+
+  // Enable SkyVault, this should unmount Downloads.
+  await sendTestMessage({name: 'setupSkyVault'});
+  await remoteCall.waitForVolumesCount(1);
+
+  // Open Files app without specifying the initial directory/root.
+  const appId = await remoteCall.openNewWindow(null, null);
+  chrome.test.assertTrue(!!appId, 'failed to open new window');
+
+  // Confirm that the Files App opened in Google Drive, as set by the policy.
+  await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My Drive');
+
+  // Mount USB volume in the Downloads window.
+  await sendTestMessage({name: 'mountFakeUsb'});
+
+  // Wait for the USB mount and click to open the USB volume.
+  const directoryTree = await DirectoryTreePageObject.create(appId);
+  await directoryTree.selectItemByType('removable');
+  await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/fake-usb');
+
+  // Unmount the USB.
+  await sendTestMessage({name: 'unmountUsb'});
+
+  // We should navigate to My Drive.
+  await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My Drive');
+}
+
+/**
+ * Tests that disabling local storage while in a local folder navigates away to
+ * the default set by the policy, e.g. Drive.
+ */
+export async function fileDisplayLocalFilesDisableInMyFiles() {
+  // Mount Drive and Downloads.
+  await sendTestMessage({name: 'mountDrive'});
+  await sendTestMessage({name: 'mountDownloads'});
+
+  // Open Files app without specifying the initial directory/root.
+  const appId = await remoteCall.openNewWindow(null, null);
+  chrome.test.assertTrue(!!appId, 'failed to open new window');
+
+  // Confirm that the Files App opened in MyFiles.
+  await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My files');
+
+  // Disable local storage.
+  await sendTestMessage({name: 'setupSkyVault'});
+
+  // We should navigate to Drive.
+  await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My Drive');
+}