Skip to content

Commit

Permalink
Merge pull request #8937 from brave/issue-16087
Browse files Browse the repository at this point in the history
Added updater registration test
  • Loading branch information
spylogsster authored May 27, 2021
2 parents 93566bb + 71629cd commit 57aaa58
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions browser/ipfs/test/ipfs_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<FakeIpfsService> fake_service(
new FakeIpfsService(context, updater, user_dir, chrome::GetChannel()));
}
{
std::unique_ptr<FakeIpfsService> 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
2 changes: 2 additions & 0 deletions components/ipfs/brave_ipfs_client_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions components/ipfs/ipfs_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions components/ipfs/ipfs_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class IpfsService : public KeyedService,
using SimpleURLLoaderList =
std::list<std::unique_ptr<network::SimpleURLLoader>>;

FRIEND_TEST_ALL_PREFIXES(IpfsServiceBrowserTest, UpdaterRegistration);
// BraveIpfsClientUpdater::Observer
void OnExecutableReady(const base::FilePath& path) override;
void OnInstallationEvent(ComponentUpdaterEvents event) override;
Expand Down

0 comments on commit 57aaa58

Please sign in to comment.