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

Unified Diff: test/Prefs.cpp

Issue 29370977: Issue #3593 - Stop sharing a single isolate amongst all unit tests
Patch Set: Created Jan. 10, 2017, 6:52 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/FilterEngine.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/Prefs.cpp
===================================================================
--- a/test/Prefs.cpp
+++ b/test/Prefs.cpp
@@ -18,6 +18,7 @@
#include <sstream>
#include "BaseJsTest.h"
+#include "../src/JsEngineTransition.h"
namespace
{
@@ -71,19 +72,51 @@
void SetUp()
{
fileSystem = std::make_shared<TestFileSystem>();
- Reset();
+ Construct(boolPrefsInitializer());
}
- void Reset(const AdblockPlus::FilterEngine::Prefs& preconfiguredPrefs =
- AdblockPlus::FilterEngine::Prefs())
+ void TearDown()
{
+ Destroy();
+ fileSystem.reset();
+ }
+
+ // Type of initializer values for C++ boolean preferences
+ typedef std::map<std::string, bool> boolPrefsInitializer;
+
+ void Reset(const boolPrefsInitializer& boolPrefs = boolPrefsInitializer())
+ {
+ Destroy();
+ Construct(boolPrefs);
+ }
+
+ private:
+ void Construct(const boolPrefsInitializer& boolPrefs)
+ {
+ // New JS engine and its resources
jsEngine = CreateJsEngine();
- jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem));
+ jsEngine->SetLogSystem(std::make_shared<LazyLogSystem>());
jsEngine->SetFileSystem(fileSystem);
- jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
+ jsEngine->SetWebRequest(std::make_shared<LazyWebRequest>());
+ /*
+ * Create preference values under the new JS engine.
+ */
+ AdblockPlus::FilterEngine::Prefs jsValuePrefs;
+ for (boolPrefsInitializer::const_iterator entry = boolPrefs.begin();
+ entry != boolPrefs.end(); ++entry)
+ {
+ jsValuePrefs[entry->first] = jsEngine->NewValue(entry->second);
+ }
+ // Use a new filter engine
+ filterEngine = std::make_shared<AdblockPlus::FilterEngine>(jsEngine, jsValuePrefs);
+ }
- filterEngine.reset(
- new AdblockPlus::FilterEngine(jsEngine, preconfiguredPrefs));
+ void Destroy()
+ {
+ filterEngine.reset();
+ ToInternal(jsEngine)->WaitForQuietScheduler();
+ jsEngine.reset();
+ EXPECT_EQ(0, jsEngine.use_count());
}
};
}
@@ -148,9 +181,9 @@
TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured)
{
- AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
- preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false);
- preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
+ boolPrefsInitializer preconfiguredPrefs;
+ preconfiguredPrefs["disable_auto_updates"] = false;
+ preconfiguredPrefs["suppress_first_run_page"] = true;
Reset(preconfiguredPrefs);
ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates")->IsBool());
@@ -161,8 +194,8 @@
TEST_F(PrefsTest, PreconfiguredPrefsUnsupported)
{
- AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
- preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true);
+ boolPrefsInitializer preconfiguredPrefs;
+ preconfiguredPrefs["unsupported_preconfig"] = true;
Reset(preconfiguredPrefs);
ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig")->IsUndefined());
@@ -170,8 +203,8 @@
TEST_F(PrefsTest, PreconfiguredPrefsOverride)
{
- AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
- preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
+ boolPrefsInitializer preconfiguredPrefs;
+ preconfiguredPrefs["suppress_first_run_page"] = true;
Reset(preconfiguredPrefs);
filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
@@ -181,8 +214,8 @@
TEST_F(PrefsTest, PrefsPersistWhenPreconfigured)
{
- AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
- preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
+ boolPrefsInitializer preconfiguredPrefs;
+ preconfiguredPrefs["suppress_first_run_page"] = true;
Reset(preconfiguredPrefs);
ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
« no previous file with comments | « test/FilterEngine.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld