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

smbprovider: Add a unit test for mounting SMB shares

BUG=None

Change-Id: I283883c95246997c93d6f0b419a3c8662ad3af0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659550
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarFrançois Degros <fdegros@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669141}
parent 57e16cde
...@@ -592,6 +592,19 @@ void SmbService::CompleteSetup( ...@@ -592,6 +592,19 @@ void SmbService::CompleteSetup(
base::Unretained(this)))); base::Unretained(this))));
RestoreMounts(); RestoreMounts();
net::NetworkChangeNotifier::AddNetworkChangeObserver(this); net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
if (setup_complete_callback_) {
std::move(setup_complete_callback_).Run();
}
}
void SmbService::OnSetupCompleteForTesting(base::OnceClosure callback) {
DCHECK(!setup_complete_callback_);
if (temp_file_manager_) {
std::move(callback).Run();
return;
}
setup_complete_callback_ = std::move(callback);
} }
void SmbService::FireMountCallback(MountResponse callback, void SmbService::FireMountCallback(MountResponse callback,
......
...@@ -116,6 +116,10 @@ class SmbService : public KeyedService, ...@@ -116,6 +116,10 @@ class SmbService : public KeyedService,
disable_share_discovery_for_testing_ = true; disable_share_discovery_for_testing_ = true;
} }
// Run |callback| when setup had completed. If setup has already completed,
// |callback| will be run inline.
void OnSetupCompleteForTesting(base::OnceClosure callback);
private: private:
friend class SmbServiceTest; friend class SmbServiceTest;
...@@ -290,6 +294,8 @@ class SmbService : public KeyedService, ...@@ -290,6 +294,8 @@ class SmbService : public KeyedService,
// |file_system_id| -> |mount_id| // |file_system_id| -> |mount_id|
std::unordered_map<std::string, int32_t> mount_id_map_; std::unordered_map<std::string, int32_t> mount_id_map_;
base::OnceClosure setup_complete_callback_;
DISALLOW_COPY_AND_ASSIGN(SmbService); DISALLOW_COPY_AND_ASSIGN(SmbService);
}; };
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/test/bind_test_util.h"
#include "base/test/simple_test_tick_clock.h" #include "base/test/simple_test_tick_clock.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h" #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h"
...@@ -183,6 +185,58 @@ TEST_F(SmbServiceTest, InvalidSsoUrls) { ...@@ -183,6 +185,58 @@ TEST_F(SmbServiceTest, InvalidSsoUrls) {
ExpectInvalidSsoUrl("smb://[::1]/foo"); ExpectInvalidSsoUrl("smb://[::1]/foo");
} }
TEST_F(SmbServiceTest, Mount) {
CreateFspRegistry(profile_);
{
CreateService(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<SmbUrl>& shares_gathered, bool done) {
if (done) {
run_loop.Quit();
}
}));
run_loop.Run();
}
base::RunLoop run_loop;
EXPECT_CALL(
*mock_client_,
Mount(base::FilePath(kMountPath),
AllOf(Field(&SmbProviderClient::MountOptions::username, kTestUser),
Field(&SmbProviderClient::MountOptions::workgroup, ""),
Field(&SmbProviderClient::MountOptions::ntlm_enabled, true),
Field(&SmbProviderClient::MountOptions::skip_connect, false)),
_, _))
.WillOnce(
WithArg<3>(Invoke([](SmbProviderClient::MountCallback callback) {
std::move(callback).Run(smbprovider::ErrorType::ERROR_OK, 7);
})));
smb_service_->Mount(
{}, base::FilePath(kSharePath), kTestUser, "password",
false /* use_chromad_kerberos */,
false /* should_open_file_manager_after_mount */,
base::BindLambdaForTesting([&run_loop](SmbMountResult result) {
EXPECT_EQ(SmbMountResult::SUCCESS, result);
run_loop.Quit();
}));
run_loop.Run();
// Because the mock is potentially leaked, expectations needs to be manually
// verified.
EXPECT_TRUE(testing::Mock::VerifyAndClearExpectations(mock_client_));
}
TEST_F(SmbServiceTest, Remount) { TEST_F(SmbServiceTest, Remount) {
file_system_provider::MountOptions mount_options( file_system_provider::MountOptions mount_options(
CreateFileSystemId(base::FilePath(kSharePath), CreateFileSystemId(base::FilePath(kSharePath),
......
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