Add integration tests for Enable Docs Offline dialog
Add FakeDriveFs code to simulate signalling to the browser to open the
Drive Enable Docs Offline dialog. Add integration tests that use this to
test the dialog appears in the Files App UI.
Bug: 1166058
Change-Id: I9b237eff7199b7718163cf1dc6c65ce5057e4b0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2666036
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: Noel Gordon <noel@chromium.org>
Reviewed-by: Sergei Datsenko <dats@chromium.org>
Cr-Commit-Position: refs/heads/master@{#850486}
diff --git a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
index 193c48dd..b266de5 100644
--- a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
+++ b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
@@ -673,7 +673,10 @@
TestCase("driveLinkOpenFileThroughTransitiveLink").MediaSwa(),
TestCase("driveWelcomeBanner"),
TestCase("driveOfflineInfoBanner").EnableDriveDssPin(),
- TestCase("driveOfflineInfoBannerWithoutFlag")));
+ TestCase("driveOfflineInfoBannerWithoutFlag"),
+ TestCase("driveEnableDocsOfflineDialog"),
+ TestCase("driveEnableDocsOfflineDialogWithoutWindow"),
+ TestCase("driveEnableDocsOfflineDialogMultipleWindows")));
WRAPPED_INSTANTIATE_TEST_SUITE_P(
HoldingSpace, /* holding_space.js */
diff --git a/chrome/browser/chromeos/file_manager/file_manager_browsertest_base.cc b/chrome/browser/chromeos/file_manager/file_manager_browsertest_base.cc
index 072dfda4..5ad8fde 100644
--- a/chrome/browser/chromeos/file_manager/file_manager_browsertest_base.cc
+++ b/chrome/browser/chromeos/file_manager/file_manager_browsertest_base.cc
@@ -71,6 +71,7 @@
#include "chrome/common/pref_names.h"
#include "chromeos/components/drivefs/drivefs_host.h"
#include "chromeos/components/drivefs/fake_drivefs.h"
+#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "chromeos/components/smbfs/smbfs_host.h"
#include "chromeos/components/smbfs/smbfs_mounter.h"
#include "chromeos/constants/chromeos_switches.h"
@@ -1164,6 +1165,16 @@
ASSERT_TRUE(UpdateModifiedTime(entry));
}
+ void DisplayConfirmDialog(drivefs::mojom::DialogReasonPtr reason) {
+ fake_drivefs_helper_->fake_drivefs().DisplayConfirmDialog(
+ std::move(reason), base::BindOnce(&DriveFsTestVolume::OnDialogResult,
+ base::Unretained(this)));
+ }
+
+ drivefs::mojom::DialogResult last_dialog_result() {
+ return last_dialog_result_;
+ }
+
private:
base::RepeatingCallback<std::unique_ptr<drivefs::DriveFsBootstrapListener>()>
CreateDriveFsBootstrapListener() {
@@ -1259,6 +1270,12 @@
return GetComputerGrandRoot().Append(computer_name);
}
+ void OnDialogResult(drivefs::mojom::DialogResult result) {
+ last_dialog_result_ = result;
+ }
+
+ drivefs::mojom::DialogResult last_dialog_result_;
+
// Profile associated with this volume: not owned.
Profile* profile_ = nullptr;
// Integration service used for testing: not owned.
@@ -2711,6 +2728,21 @@
->DropFailedPluginVmDirectoryNotShared();
return;
}
+
+ if (name == "displayEnableDocsOfflineDialog") {
+ drive_volume_->DisplayConfirmDialog(drivefs::mojom::DialogReason::New(
+ drivefs::mojom::DialogReason::Type::kEnableDocsOffline,
+ base::FilePath()));
+ return;
+ }
+
+ if (name == "getLastDriveDialogResult") {
+ base::JSONWriter::Write(
+ base::Value(static_cast<int32_t>(drive_volume_->last_dialog_result())),
+ output);
+ return;
+ }
+
FAIL() << "Unknown test message: " << name;
}
diff --git a/chromeos/components/drivefs/fake_drivefs.cc b/chromeos/components/drivefs/fake_drivefs.cc
index 40aa893d..403c907c 100644
--- a/chromeos/components/drivefs/fake_drivefs.cc
+++ b/chromeos/components/drivefs/fake_drivefs.cc
@@ -291,6 +291,13 @@
}
}
+void FakeDriveFs::DisplayConfirmDialog(
+ drivefs::mojom::DialogReasonPtr reason,
+ drivefs::mojom::DriveFsDelegate::DisplayConfirmDialogCallback callback) {
+ DCHECK(delegate_);
+ delegate_->DisplayConfirmDialog(std::move(reason), std::move(callback));
+}
+
void FakeDriveFs::Init(
drivefs::mojom::DriveFsConfigurationPtr config,
mojo::PendingReceiver<drivefs::mojom::DriveFs> receiver,
diff --git a/chromeos/components/drivefs/fake_drivefs.h b/chromeos/components/drivefs/fake_drivefs.h
index 7bba931..0154ae4 100644
--- a/chromeos/components/drivefs/fake_drivefs.h
+++ b/chromeos/components/drivefs/fake_drivefs.h
@@ -58,6 +58,10 @@
const mojom::FolderFeature& folder_feature,
const std::string& doc_id);
+ void DisplayConfirmDialog(
+ drivefs::mojom::DialogReasonPtr reason,
+ drivefs::mojom::DriveFsDelegate::DisplayConfirmDialogCallback callback);
+
const base::FilePath& mount_path() { return mount_path_; }
private:
diff --git a/ui/file_manager/file_manager/background/js/runtime_loaded_test_util.js b/ui/file_manager/file_manager/background/js/runtime_loaded_test_util.js
index 0fbf77b..7e76d6b 100644
--- a/ui/file_manager/file_manager/background/js/runtime_loaded_test_util.js
+++ b/ui/file_manager/file_manager/background/js/runtime_loaded_test_util.js
@@ -1228,3 +1228,12 @@
test.util.sync.progressCenterNeverNotifyCompleted = () => {
window.background.progressCenter.neverNotifyCompleted();
};
+
+/**
+ * Waits for the background page to initialize.
+ * @param {function()} callback Callback function called when background page
+ * has finished initializing.
+ */
+test.util.async.waitForBackgroundReady = callback => {
+ window.background.ready(callback);
+};
diff --git a/ui/file_manager/integration_tests/file_manager/drive_specific.js b/ui/file_manager/integration_tests/file_manager/drive_specific.js
index da4d816..3295969 100644
--- a/ui/file_manager/integration_tests/file_manager/drive_specific.js
+++ b/ui/file_manager/integration_tests/file_manager/drive_specific.js
@@ -24,6 +24,16 @@
];
/**
+ * Expected text shown in the Enable Docs Offline dialog.
+ *
+ * @type {string}
+ * @const
+ */
+const ENABLE_DOCS_OFFLINE_MESSAGE =
+ 'Enable Google Docs Offline to make Docs, Sheets and Slides ' +
+ 'available offline.';
+
+/**
* Returns the steps to start a search for 'hello' and wait for the
* autocomplete results to appear.
*/
@@ -57,6 +67,22 @@
}
/**
+ * Opens the Enable Docs Offline dialog and waits for it to appear in the given
+ * |appId| window.
+ *
+ * @param {string} appId
+ */
+async function openAndWaitForEnableDocsOfflineDialog(appId) {
+ // Simulate Drive signalling Files App to open a dialog.
+ await sendTestMessage({name: 'displayEnableDocsOfflineDialog'});
+
+ // Check: the Enable Docs Offline dialog should appear.
+ const dialogText = await remoteCall.waitForElement(
+ appId, '.cr-dialog-container.shown .cr-dialog-text');
+ chrome.test.assertEq(ENABLE_DOCS_OFFLINE_MESSAGE, dialogText.text);
+}
+
+/**
* Tests opening the "Offline" on the sidebar navigation by clicking the icon,
* and checks contents of the file list. Only the entries "available offline"
* should be shown. "Available offline" entries are hosted documents and the
@@ -817,3 +843,96 @@
await remoteCall.waitForElementLost(
appId, '#offline-info-banner:not([hidden])');
};
+
+/**
+ * Tests that the Enable Docs Offline dialog appears in the Files App.
+ */
+testcase.driveEnableDocsOfflineDialog = async () => {
+ // Open Files app on Drive.
+ const appId = await setupAndWaitUntilReady(RootPath.DRIVE, []);
+
+ // Open the Enable Docs Offline dialog.
+ await openAndWaitForEnableDocsOfflineDialog(appId);
+
+ // Click on the ok button.
+ await remoteCall.waitAndClickElement(
+ appId, '.cr-dialog-container.shown .cr-dialog-ok');
+
+ // Check: the last dialog result should be 1 (accept).
+ let lastResult = await sendTestMessage({name: 'getLastDriveDialogResult'});
+ chrome.test.assertEq('1', lastResult);
+
+ // Open the Enable Docs Offline dialog.
+ await openAndWaitForEnableDocsOfflineDialog(appId);
+
+ // Click on the cancel button.
+ await remoteCall.waitAndClickElement(
+ appId, '.cr-dialog-container.shown .cr-dialog-cancel');
+
+ // Check: the last dialog result should be 2 (reject).
+ lastResult = await sendTestMessage({name: 'getLastDriveDialogResult'});
+ chrome.test.assertEq('2', lastResult);
+
+ // Open the Enable Docs Offline dialog.
+ await openAndWaitForEnableDocsOfflineDialog(appId);
+
+ // Close Files App.
+ await remoteCall.closeWindowAndWait(appId);
+
+ // Check: the last dialog result should be 3 (dismiss).
+ lastResult = await sendTestMessage({name: 'getLastDriveDialogResult'});
+ chrome.test.assertEq('3', lastResult);
+};
+
+/**
+ * Tests that the Enable Docs Offline dialog launches a Files App window if
+ * there are none open.
+ */
+testcase.driveEnableDocsOfflineDialogWithoutWindow = async () => {
+ // Wait for the background page to listen to events from the browser.
+ await remoteCall.callRemoteTestUtil('waitForBackgroundReady', null, []);
+
+ // Simulate Drive signalling Files App to open a dialog.
+ await sendTestMessage({name: 'displayEnableDocsOfflineDialog'});
+
+ // Check: A Files App window should appear.
+ const appId = await remoteCall.waitForWindow('files#');
+
+ // Check: the Enable Docs Offline dialog should appear.
+ const dialogText = await remoteCall.waitForElement(
+ appId, '.cr-dialog-container.shown .cr-dialog-text');
+ chrome.test.assertEq(ENABLE_DOCS_OFFLINE_MESSAGE, dialogText.text);
+
+ // Click on the ok button.
+ await remoteCall.waitAndClickElement(
+ appId, '.cr-dialog-container.shown .cr-dialog-ok');
+
+ // Check: the last dialog result should be 1 (accept).
+ const lastResult = await sendTestMessage({name: 'getLastDriveDialogResult'});
+ chrome.test.assertEq('1', lastResult);
+};
+
+/**
+ * Tests that the Enable Docs Offline dialog appears in the focused window if
+ * there are more than one Files App windows open.
+ */
+testcase.driveEnableDocsOfflineDialogMultipleWindows = async () => {
+ // Open two Files app windows on Drive, and the second one should be focused.
+ const appId1 = await setupAndWaitUntilReady(RootPath.DRIVE, []);
+ const appId2 = await setupAndWaitUntilReady(RootPath.DRIVE, []);
+
+ // Open the Enable Docs Offline dialog and check that it appears in the second
+ // window.
+ await openAndWaitForEnableDocsOfflineDialog(appId2);
+
+ // Check: there should be no dialog shown in the first window.
+ await remoteCall.waitForElementLost(appId1, '.cr-dialog-container.shown');
+
+ // Click on the ok button in the second window.
+ await remoteCall.waitAndClickElement(
+ appId2, '.cr-dialog-container.shown .cr-dialog-ok');
+
+ // Check: the last dialog result should be 1 (accept).
+ const lastResult = await sendTestMessage({name: 'getLastDriveDialogResult'});
+ chrome.test.assertEq('1', lastResult);
+};