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

Unified Diff: test/FilterEngine.cpp

Issue 29371607: Issue #3593 - Make isolate a fully internal member of the engine
Patch Set: improve unit tests to go with isolate change Created Jan. 16, 2017, 3:53 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
@@ -17,6 +17,7 @@
#include "BaseJsTest.h"
#include <thread>
+#include "../src/JsEngineTransition.h"
using namespace AdblockPlus;
@@ -44,11 +45,11 @@
void SetUp()
{
BaseJsTest::SetUp();
- jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem));
+ jsEngine->SetFileSystem(std::make_shared<FileSystem>());
webRequest = std::make_shared<LazyWebRequest>();
jsEngine->SetWebRequest(webRequest);
- jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem));
- filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
+ jsEngine->SetLogSystem(std::make_shared<LogSystem>());
+ filterEngine = std::make_shared<AdblockPlus::FilterEngine>(jsEngine);
}
void TearDown()
@@ -94,7 +95,8 @@
}
};
- MockWebRequest* mockWebRequest;
+ AdblockPlus::JsEnginePtr jsEngine;
+ std::shared_ptr<MockWebRequest> mockWebRequest;
FilterEnginePtr filterEngine;
void SetUp()
@@ -102,11 +104,20 @@
AdblockPlus::AppInfo appInfo;
appInfo.name = "test";
appInfo.version = "1.0.1";
- AdblockPlus::JsEnginePtr jsEngine = CreateJsEngine(appInfo);
- jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
- mockWebRequest = new MockWebRequest;
- jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(mockWebRequest));
- filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
+ jsEngine = CreateJsEngine(appInfo);
+ jsEngine->SetFileSystem(std::make_shared<LazyFileSystem>());
+ mockWebRequest = std::make_shared<MockWebRequest>();
+ jsEngine->SetWebRequest(mockWebRequest);
+ filterEngine = std::make_shared<FilterEngine>(jsEngine);
+ }
+
+ void TearDown()
+ {
+ filterEngine.reset();
+ mockWebRequest.reset();
+ ToInternal(jsEngine)->WaitForQuietScheduler();
+ ASSERT_EQ(1, jsEngine.use_count());
+ jsEngine.reset();
}
};
@@ -132,31 +143,41 @@
{
protected:
FileSystemPtr fileSystem;
- std::weak_ptr<JsEngine> weakJsEngine;
+ std::shared_ptr<LazyWebRequest> webRequest;
+ AdblockPlus::JsEnginePtr jsEngine;
void SetUp() override
{
- fileSystem.reset(new DefaultFileSystem());
+ fileSystem = std::make_shared<DefaultFileSystem>();
+ webRequest = std::make_shared<LazyWebRequest>();
// 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())
+
+ void createJsEngine(const AppInfo& appInfo = AppInfo())
{
- auto jsEngine = JsEngine::New(appInfo);
- weakJsEngine = jsEngine;
+ jsEngine = JsEngine::New(appInfo);
jsEngine->SetFileSystem(fileSystem);
- jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest()));
- jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem()));
- return jsEngine;
+ jsEngine->SetWebRequest(webRequest);
+ jsEngine->SetLogSystem(std::make_shared<LazyLogSystem>());
}
+
void TearDown() override
{
+ if (webRequest)
+ {
+ webRequest->Cancel();
+ }
removeFileIfExists("patterns.ini");
removeFileIfExists("prefs.json");
fileSystem.reset();
+ ToInternal(jsEngine)->WaitForQuietScheduler();
+ ASSERT_EQ(1, jsEngine.use_count());
+ jsEngine.reset();
}
+
void removeFileIfExists(const std::string& path)
{
// Hack: allow IO to finish currently running operations, in particular
@@ -175,7 +196,7 @@
}
};
int i = 5;
- while ((i-- > 0 && weakJsEngine.lock()) || !safeRemove())
+ while ((i-- > 0) || !safeRemove())
std::this_thread::sleep_for(std::chrono::seconds(2));
}
};
@@ -608,9 +629,9 @@
AppInfo appInfo;
appInfo.locale = "zh";
const std::string langSubscriptionUrl = "https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt";
- auto jsEngine = createJsEngine(appInfo);
- auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
- const auto subscriptions = filterEngine->GetListedSubscriptions();
+ createJsEngine(appInfo);
+ auto filterEngine = std::make_shared<AdblockPlus::FilterEngine>(jsEngine);
+ auto subscriptions = filterEngine->GetListedSubscriptions();
ASSERT_EQ(2u, subscriptions.size());
const auto aaUrl = filterEngine->GetPref("subscriptions_exceptionsurl")->AsString();
SubscriptionPtr aaSubscription;
@@ -633,10 +654,10 @@
TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun)
{
- auto jsEngine = createJsEngine();
+ createJsEngine();
FilterEngine::Prefs preSettings;
preSettings["first_run_subscription_auto_select"] = jsEngine->NewValue(false);
- auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine, preSettings));
+ auto filterEngine = std::make_shared<AdblockPlus::FilterEngine>(jsEngine, preSettings);
const auto subscriptions = filterEngine->GetListedSubscriptions();
EXPECT_EQ(0u, subscriptions.size());
}
« 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