From 71629cd4dadbbeb8fc82454bdaa5661471e6b3a6 Mon Sep 17 00:00:00 2001 From: Sergey P Date: Wed, 26 May 2021 19:17:00 +0300 Subject: [PATCH] Added updater registration test --- browser/ipfs/test/ipfs_service_browsertest.cc | 24 +++++++++++++++++++ components/ipfs/brave_ipfs_client_updater.h | 2 ++ components/ipfs/ipfs_service.cc | 3 +++ components/ipfs/ipfs_service.h | 1 + 4 files changed, 30 insertions(+) diff --git a/browser/ipfs/test/ipfs_service_browsertest.cc b/browser/ipfs/test/ipfs_service_browsertest.cc index f4c67dc82f82..68ec560cfa1e 100644 --- a/browser/ipfs/test/ipfs_service_browsertest.cc +++ b/browser/ipfs/test/ipfs_service_browsertest.cc @@ -9,8 +9,10 @@ #include "base/strings/strcat.h" #include "base/test/mock_callback.h" #include "base/test/scoped_feature_list.h" +#include "brave/browser/brave_browser_process.h" #include "brave/browser/ipfs/ipfs_service_factory.h" #include "brave/common/brave_paths.h" +#include "brave/components/ipfs/brave_ipfs_client_updater.h" #include "brave/components/ipfs/features.h" #include "brave/components/ipfs/import/imported_data.h" #include "brave/components/ipfs/ipfs_constants.h" @@ -1077,4 +1079,26 @@ IN_PROC_BROWSER_TEST_F(IpfsServiceBrowserTest, ImportFileAndPinToIpfsSuccess) { WaitForRequest(); } +IN_PROC_BROWSER_TEST_F(IpfsServiceBrowserTest, UpdaterRegistration) { + base::FilePath user_dir = base::FilePath(FILE_PATH_LITERAL("test")); + auto* context = browser()->profile(); + BraveIpfsClientUpdater* updater = + g_brave_browser_process->ipfs_client_updater(); + { + std::unique_ptr fake_service( + new FakeIpfsService(context, updater, user_dir, chrome::GetChannel())); + } + { + std::unique_ptr fake_service( + new FakeIpfsService(context, updater, user_dir, chrome::GetChannel())); + + ASSERT_FALSE(fake_service->IsDaemonLaunched()); + ASSERT_FALSE(updater->IsRegistered()); + fake_service->OnIpfsLaunched(false, 0); + ASSERT_FALSE(updater->IsRegistered()); + fake_service->OnIpfsLaunched(true, 0); + ASSERT_TRUE(updater->IsRegistered()); + } +} + } // namespace ipfs diff --git a/components/ipfs/brave_ipfs_client_updater.h b/components/ipfs/brave_ipfs_client_updater.h index 5e43ae6f82b8..13dcb58af328 100644 --- a/components/ipfs/brave_ipfs_client_updater.h +++ b/components/ipfs/brave_ipfs_client_updater.h @@ -89,6 +89,8 @@ class BraveIpfsClientUpdater : public BraveComponent, return task_runner_; } + bool IsRegistered() const { return registered_; } + void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); void Cleanup(); diff --git a/components/ipfs/ipfs_service.cc b/components/ipfs/ipfs_service.cc index e88e30f2803c..cd0b417bf76a 100644 --- a/components/ipfs/ipfs_service.cc +++ b/components/ipfs/ipfs_service.cc @@ -116,6 +116,9 @@ IpfsService::IpfsService(content::BrowserContext* context, } IpfsService::~IpfsService() { + if (ipfs_client_updater_) { + ipfs_client_updater_->RemoveObserver(this); + } RemoveObserver(ipns_keys_manager_.get()); Shutdown(); } diff --git a/components/ipfs/ipfs_service.h b/components/ipfs/ipfs_service.h index e133634a00b6..17a4231b5f7b 100644 --- a/components/ipfs/ipfs_service.h +++ b/components/ipfs/ipfs_service.h @@ -147,6 +147,7 @@ class IpfsService : public KeyedService, using SimpleURLLoaderList = std::list>; + FRIEND_TEST_ALL_PREFIXES(IpfsServiceBrowserTest, UpdaterRegistration); // BraveIpfsClientUpdater::Observer void OnExecutableReady(const base::FilePath& path) override; void OnInstallationEvent(ComponentUpdaterEvents event) override;