Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/FilterEngine.cpp

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Rebase on master. Last changes. Created July 7, 2017, 1:36 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/FileSystemJsObject.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/FilterEngine.cpp
===================================================================
--- a/test/FilterEngine.cpp
+++ b/test/FilterEngine.cpp
@@ -72,17 +72,17 @@
class FilterEngineWithFreshFolder : public ::testing::Test
{
protected:
FileSystemPtr fileSystem;
std::weak_ptr<JsEngine> weakJsEngine;
void SetUp() override
{
- fileSystem.reset(new DefaultFileSystem());
+ fileSystem = CreateDefaultFileSystem();
// Since there is neither in memory FS nor functionality to work with
// directories use the hack: manually clean the directory.
removeFileIfExists("patterns.ini");
removeFileIfExists("prefs.json");
}
JsEnginePtr createJsEngine(const AppInfo& appInfo = AppInfo())
{
JsEngineCreationParameters jsEngineParams;
@@ -104,19 +104,33 @@
void removeFileIfExists(const std::string& path)
{
// Hack: allow IO to finish currently running operations, in particular
// writing into files. Otherwise we get "Permission denied".
auto safeRemove = [this, &path]()->bool
{
try
{
- if (fileSystem->Stat(path).exists)
- fileSystem->Remove(path);
- return true;
+ Sync sync;
+ auto fs = fileSystem;
+ fileSystem->Stat(path,
+ [fs, &path, &sync](const IFileSystem::StatResult& stats, const std::string& error)
+ {
+ if (error.empty() && stats.exists)
+ {
+ fs->Remove(path, [&sync](const std::string& error)
+ {
+ sync.Set(error);
+ });
+ }
+ else
+ sync.Set(error);
+ });
+ sync.WaitFor();
+ return sync.GetError().empty();
}
catch (...)
{
return false;
}
};
int i = 5;
while ((i-- > 0 && weakJsEngine.lock()) || !safeRemove())
@@ -580,16 +594,17 @@
std::this_thread::sleep_for(std::chrono::milliseconds(200));
filterEngine->SetFilterChangeCallback([&timesCalled](const std::string&, AdblockPlus::JsValue&&)
{
timesCalled++;
});
filterEngine->GetFilter("foo").AddToList();
EXPECT_EQ(1, timesCalled);
+ // we want to actually check the call count didn't change.
filterEngine->RemoveFilterChangeCallback();
filterEngine->GetFilter("foo").RemoveFromList();
EXPECT_EQ(1, timesCalled);
}
TEST_F(FilterEngineTest, DocumentWhitelisting)
{
filterEngine->GetFilter("@@||example.org^$document").AddToList();
« no previous file with comments | « test/FileSystemJsObject.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld