Commit 6f5e119b authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Add a QuickView integration test for smbfs

Bug: 1065271
Change-Id: Ie746af2f801ae4466f7a02dff0755c8a5200d425
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2125911Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754850}
parent 2392523d
...@@ -80,6 +80,11 @@ struct TestCase { ...@@ -80,6 +80,11 @@ struct TestCase {
return *this; return *this;
} }
TestCase& EnableSmbfs() {
enable_smbfs = true;
return *this;
}
TestCase& EnableUnifiedMediaView() { TestCase& EnableUnifiedMediaView() {
enable_unified_media_view.emplace(true); enable_unified_media_view.emplace(true);
return *this; return *this;
...@@ -141,6 +146,7 @@ struct TestCase { ...@@ -141,6 +146,7 @@ struct TestCase {
bool offline = false; bool offline = false;
base::Optional<bool> files_ng; base::Optional<bool> files_ng;
bool enable_native_smb = true; bool enable_native_smb = true;
bool enable_smbfs = false;
base::Optional<bool> enable_unified_media_view; base::Optional<bool> enable_unified_media_view;
bool mount_no_volumes = false; bool mount_no_volumes = false;
bool observe_file_tasks = true; bool observe_file_tasks = true;
...@@ -208,6 +214,8 @@ class FilesAppBrowserTest : public FileManagerBrowserTestBase, ...@@ -208,6 +214,8 @@ class FilesAppBrowserTest : public FileManagerBrowserTestBase,
return GetParam().enable_native_smb; return GetParam().enable_native_smb;
} }
bool GetEnableSmbfs() const override { return GetParam().enable_smbfs; }
bool GetEnableUnifiedMediaView() const override { bool GetEnableUnifiedMediaView() const override {
return GetParam().enable_unified_media_view.value_or( return GetParam().enable_unified_media_view.value_or(
FileManagerBrowserTestBase::GetEnableUnifiedMediaView()); FileManagerBrowserTestBase::GetEnableUnifiedMediaView());
...@@ -493,6 +501,7 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( ...@@ -493,6 +501,7 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
TestCase("openQuickViewScrollHtml"), TestCase("openQuickViewScrollHtml"),
TestCase("openQuickViewBackgroundColorHtml"), TestCase("openQuickViewBackgroundColorHtml"),
TestCase("openQuickViewDrive"), TestCase("openQuickViewDrive"),
TestCase("openQuickViewSmbfs").EnableSmbfs(),
TestCase("openQuickViewAndroid"), TestCase("openQuickViewAndroid"),
TestCase("openQuickViewDocumentsProvider").EnableDocumentsProvider(), TestCase("openQuickViewDocumentsProvider").EnableDocumentsProvider(),
TestCase("openQuickViewCrostini"), TestCase("openQuickViewCrostini"),
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
...@@ -42,6 +43,8 @@ ...@@ -42,6 +43,8 @@
#include "chrome/browser/chromeos/file_manager/path_util.h" #include "chrome/browser/chromeos/file_manager/path_util.h"
#include "chrome/browser/chromeos/file_manager/volume_manager.h" #include "chrome/browser/chromeos/file_manager/volume_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/smb_client/smb_service.h"
#include "chrome/browser/chromeos/smb_client/smb_service_factory.h"
#include "chrome/browser/notifications/notification_display_service_tester.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/platform_util.h" #include "chrome/browser/platform_util.h"
#include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h"
...@@ -56,11 +59,14 @@ ...@@ -56,11 +59,14 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/components/drivefs/drivefs_host.h" #include "chromeos/components/drivefs/drivefs_host.h"
#include "chromeos/components/drivefs/fake_drivefs.h" #include "chromeos/components/drivefs/fake_drivefs.h"
#include "chromeos/components/smbfs/smbfs_host.h"
#include "chromeos/components/smbfs/smbfs_mounter.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "chromeos/dbus/concierge/concierge_service.pb.h" #include "chromeos/dbus/concierge/concierge_service.pb.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cros_disks_client.h" #include "chromeos/dbus/fake_cros_disks_client.h"
#include "chromeos/disks/mount_point.h"
#include "components/arc/arc_features.h" #include "components/arc/arc_features.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
...@@ -101,6 +107,8 @@ ...@@ -101,6 +107,8 @@
#include "ui/shell_dialogs/select_file_dialog_factory.h" #include "ui/shell_dialogs/select_file_dialog_factory.h"
#include "ui/shell_dialogs/select_file_policy.h" #include "ui/shell_dialogs/select_file_policy.h"
using ::testing::_;
class SelectFileDialogExtensionTestFactory class SelectFileDialogExtensionTestFactory
: public ui::SelectFileDialogFactory { : public ui::SelectFileDialogFactory {
public: public:
...@@ -171,7 +179,8 @@ struct AddEntriesMessage { ...@@ -171,7 +179,8 @@ struct AddEntriesMessage {
DOCUMENTS_PROVIDER_VOLUME, DOCUMENTS_PROVIDER_VOLUME,
MEDIA_VIEW_AUDIO, MEDIA_VIEW_AUDIO,
MEDIA_VIEW_IMAGES, MEDIA_VIEW_IMAGES,
MEDIA_VIEW_VIDEOS MEDIA_VIEW_VIDEOS,
SMBFS_VOLUME,
}; };
// Represents the different types of entries (e.g. file, folder). // Represents the different types of entries (e.g. file, folder).
...@@ -225,6 +234,8 @@ struct AddEntriesMessage { ...@@ -225,6 +234,8 @@ struct AddEntriesMessage {
*volume = MEDIA_VIEW_IMAGES; *volume = MEDIA_VIEW_IMAGES;
else if (value == "media_view_videos") else if (value == "media_view_videos")
*volume = MEDIA_VIEW_VIDEOS; *volume = MEDIA_VIEW_VIDEOS;
else if (value == "smbfs")
*volume = SMBFS_VOLUME;
else else
return false; return false;
return true; return true;
...@@ -1292,6 +1303,122 @@ class MediaViewTestVolume : public DocumentsProviderTestVolume { ...@@ -1292,6 +1303,122 @@ class MediaViewTestVolume : public DocumentsProviderTestVolume {
DISALLOW_COPY_AND_ASSIGN(MediaViewTestVolume); DISALLOW_COPY_AND_ASSIGN(MediaViewTestVolume);
}; };
class MockSmbFsMounter : public smbfs::SmbFsMounter {
public:
MOCK_METHOD(void,
Mount,
(smbfs::SmbFsMounter::DoneCallback callback),
(override));
};
class MockSmbFsImpl : public smbfs::mojom::SmbFs {
public:
explicit MockSmbFsImpl(mojo::PendingReceiver<smbfs::mojom::SmbFs> pending)
: receiver_(this, std::move(pending)) {}
private:
mojo::Receiver<smbfs::mojom::SmbFs> receiver_;
};
// SmbfsTestVolume: Test volume for FUSE-based SMB file shares.
class SmbfsTestVolume : public LocalTestVolume {
public:
SmbfsTestVolume() : LocalTestVolume("smbfs") {}
~SmbfsTestVolume() override = default;
// Create root dir so entries can be created, but volume is not mounted.
bool Initialize(Profile* profile) { return CreateRootDirectory(profile); }
bool Mount(Profile* profile) override {
// Only support mounting this volume once.
CHECK(!mock_smbfs_);
if (!CreateRootDirectory(profile)) {
return false;
}
chromeos::smb_client::SmbService* smb_service =
chromeos::smb_client::SmbServiceFactory::Get(profile);
{
base::RunLoop run_loop;
smb_service->OnSetupCompleteForTesting(run_loop.QuitClosure());
run_loop.Run();
}
{
// Share gathering needs to complete at least once before a share can be
// mounted.
base::RunLoop run_loop;
smb_service->GatherSharesInNetwork(
base::DoNothing(),
base::BindLambdaForTesting(
[&run_loop](const std::vector<chromeos::smb_client::SmbUrl>&
shares_gathered,
bool done) {
if (done) {
run_loop.Quit();
}
}));
run_loop.Run();
}
// Inject a mounter creation callback so that smbfs startup can be faked
// out.
smb_service->SetSmbFsMounterCreationCallbackForTesting(base::BindRepeating(
&SmbfsTestVolume::CreateMounter, base::Unretained(this)));
bool success = false;
chromeos::file_system_provider::MountOptions mount_options;
mount_options.display_name = "SMB Share";
base::RunLoop run_loop;
smb_service->Mount(
mount_options, base::FilePath("smb://server/share"), "" /* username */,
"" /* password */, false /* use_chromad_kerberos */,
false /* should_open_file_manager_after_mount */,
false /* save_credentials */,
base::BindLambdaForTesting(
[&](chromeos::smb_client::SmbMountResult result) {
success =
(result == chromeos::smb_client::SmbMountResult::kSuccess);
run_loop.Quit();
}));
run_loop.Run();
return success;
}
const base::FilePath& mount_path() const { return root_path(); }
private:
std::unique_ptr<smbfs::SmbFsMounter> CreateMounter(
const std::string& share_path,
const std::string& mount_dir_name,
const chromeos::smb_client::SmbFsShare::MountOptions& options,
smbfs::SmbFsHost::Delegate* delegate) {
std::unique_ptr<MockSmbFsMounter> mock_mounter =
std::make_unique<MockSmbFsMounter>();
EXPECT_CALL(*mock_mounter, Mount(_))
.WillOnce([this,
delegate](smbfs::SmbFsMounter::DoneCallback mount_callback) {
mojo::Remote<smbfs::mojom::SmbFs> smbfs_remote;
mock_smbfs_ = std::make_unique<MockSmbFsImpl>(
smbfs_remote.BindNewPipeAndPassReceiver());
std::move(mount_callback)
.Run(smbfs::mojom::MountError::kOk,
std::make_unique<smbfs::SmbFsHost>(
std::make_unique<chromeos::disks::MountPoint>(
mount_path(),
chromeos::disks::DiskMountManager::GetInstance()),
delegate, std::move(smbfs_remote),
delegate_.BindNewPipeAndPassReceiver()));
});
return std::move(mock_mounter);
}
std::unique_ptr<MockSmbFsImpl> mock_smbfs_;
mojo::Remote<smbfs::mojom::SmbFsDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(SmbfsTestVolume);
};
FileManagerBrowserTestBase::FileManagerBrowserTestBase() = default; FileManagerBrowserTestBase::FileManagerBrowserTestBase() = default;
FileManagerBrowserTestBase::~FileManagerBrowserTestBase() = default; FileManagerBrowserTestBase::~FileManagerBrowserTestBase() = default;
...@@ -1368,6 +1495,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine( ...@@ -1368,6 +1495,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine(
disabled_features.emplace_back(chromeos::features::kUnifiedMediaView); disabled_features.emplace_back(chromeos::features::kUnifiedMediaView);
} }
if (IsSmbfsTest()) {
enabled_features.emplace_back(features::kSmbFs);
}
// This is destroyed in |TearDown()|. We cannot initialize this in the // This is destroyed in |TearDown()|. We cannot initialize this in the
// constructor due to this feature values' above dependence on virtual // constructor due to this feature values' above dependence on virtual
// method calls, but by convention subclasses of this fixture may initialize // method calls, but by convention subclasses of this fixture may initialize
...@@ -1502,6 +1633,10 @@ void FileManagerBrowserTestBase::SetUpOnMainThread() { ...@@ -1502,6 +1633,10 @@ void FileManagerBrowserTestBase::SetUpOnMainThread() {
} }
} }
if (IsSmbfsTest()) {
smbfs_volume_ = std::make_unique<SmbfsTestVolume>();
}
display_service_ = display_service_ =
std::make_unique<NotificationDisplayServiceTester>(profile()); std::make_unique<NotificationDisplayServiceTester>(profile());
...@@ -1566,6 +1701,10 @@ bool FileManagerBrowserTestBase::GetEnableNativeSmb() const { ...@@ -1566,6 +1701,10 @@ bool FileManagerBrowserTestBase::GetEnableNativeSmb() const {
return true; return true;
} }
bool FileManagerBrowserTestBase::GetEnableSmbfs() const {
return false;
}
bool FileManagerBrowserTestBase::GetEnableUnifiedMediaView() const { bool FileManagerBrowserTestBase::GetEnableUnifiedMediaView() const {
return false; return false;
} }
...@@ -1811,6 +1950,11 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name, ...@@ -1811,6 +1950,11 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name,
LOG(FATAL) << "Add entry: but no MediaView Videos volume."; LOG(FATAL) << "Add entry: but no MediaView Videos volume.";
} }
break; break;
case AddEntriesMessage::SMBFS_VOLUME:
CHECK(smbfs_volume_);
ASSERT_TRUE(smbfs_volume_->Initialize(profile()));
smbfs_volume_->CreateEntry(*message.entries[i]);
break;
} }
} }
...@@ -1967,6 +2111,12 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name, ...@@ -1967,6 +2111,12 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name,
return; return;
} }
if (name == "mountSmbfs") {
CHECK(smbfs_volume_);
ASSERT_TRUE(smbfs_volume_->Mount(profile()));
return;
}
if (name == "setDriveEnabled") { if (name == "setDriveEnabled") {
bool enabled; bool enabled;
ASSERT_TRUE(value.GetBoolean("enabled", &enabled)); ASSERT_TRUE(value.GetBoolean("enabled", &enabled));
......
...@@ -38,6 +38,7 @@ class AndroidFilesTestVolume; ...@@ -38,6 +38,7 @@ class AndroidFilesTestVolume;
class RemovableTestVolume; class RemovableTestVolume;
class DocumentsProviderTestVolume; class DocumentsProviderTestVolume;
class MediaViewTestVolume; class MediaViewTestVolume;
class SmbfsTestVolume;
class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
protected: protected:
...@@ -68,6 +69,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -68,6 +69,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
virtual bool GetIsOffline() const; virtual bool GetIsOffline() const;
virtual bool GetEnableFilesNg() const; virtual bool GetEnableFilesNg() const;
virtual bool GetEnableNativeSmb() const; virtual bool GetEnableNativeSmb() const;
virtual bool GetEnableSmbfs() const;
virtual bool GetEnableUnifiedMediaView() const; virtual bool GetEnableUnifiedMediaView() const;
virtual bool GetStartWithNoVolumesMounted() const; virtual bool GetStartWithNoVolumesMounted() const;
virtual bool GetStartWithFileTasksObserver() const; virtual bool GetStartWithFileTasksObserver() const;
...@@ -107,6 +109,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -107,6 +109,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Returns true if the test needs a native SMB file system provider. // Returns true if the test needs a native SMB file system provider.
bool IsNativeSmbTest() const { return GetEnableNativeSmb(); } bool IsNativeSmbTest() const { return GetEnableNativeSmb(); }
// Returns true if the test needs smbfs for native SMB integration.
bool IsSmbfsTest() const { return GetEnableSmbfs(); }
// Returns true if the test needs the unified media view feature. // Returns true if the test needs the unified media view feature.
bool IsUnifiedMediaViewTest() const { return GetEnableUnifiedMediaView(); } bool IsUnifiedMediaViewTest() const { return GetEnableUnifiedMediaView(); }
...@@ -165,6 +170,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -165,6 +170,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
std::unique_ptr<MediaViewTestVolume> media_view_images_; std::unique_ptr<MediaViewTestVolume> media_view_images_;
std::unique_ptr<MediaViewTestVolume> media_view_videos_; std::unique_ptr<MediaViewTestVolume> media_view_videos_;
std::unique_ptr<MediaViewTestVolume> media_view_audio_; std::unique_ptr<MediaViewTestVolume> media_view_audio_;
std::unique_ptr<SmbfsTestVolume> smbfs_volume_;
drive::DriveIntegrationServiceFactory::FactoryCallback drive::DriveIntegrationServiceFactory::FactoryCallback
create_drive_integration_service_; create_drive_integration_service_;
......
...@@ -310,6 +310,38 @@ ...@@ -310,6 +310,38 @@
chrome.test.assertEq('text/plain', mimeType); chrome.test.assertEq('text/plain', mimeType);
}; };
/**
* Tests opening Quick View on a Smbfs file.
*/
testcase.openQuickViewSmbfs = async () => {
const SMBFS_VOLUME_QUERY = '#directory-tree [volume-type-icon="smb"]';
// Open Files app on Downloads containing ENTRIES.photos.
const appId =
await setupAndWaitUntilReady(RootPath.DOWNLOADS, [ENTRIES.photos], []);
// Populate Smbfs with some files.
await addEntries(['smbfs'], BASIC_LOCAL_ENTRY_SET);
// Mount Smbfs volume.
await sendTestMessage({name: 'mountSmbfs'});
// Wait for the Smbfs volume to mount.
await remoteCall.waitForElement(appId, SMBFS_VOLUME_QUERY);
// Click to open the Smbfs volume.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [SMBFS_VOLUME_QUERY]),
'fakeMouseClick failed');
const files = TestEntryInfo.getExpectedRows(BASIC_LOCAL_ENTRY_SET);
await remoteCall.waitForFiles(appId, files, {ignoreLastModifiedTime: true});
// Open the file in Quick View.
await openQuickView(appId, ENTRIES.hello.nameText);
};
/** /**
* Tests opening Quick View on a USB file. * Tests opening Quick View on a USB file.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment