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

Unified Diff: test/Prefs.cpp

Issue 29409558: Issue 5125 - Fix prefs tests to comply with new v8 (Closed)
Patch Set: Created April 11, 2017, 8:11 a.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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/Prefs.cpp
diff --git a/test/Prefs.cpp b/test/Prefs.cpp
index 3ef61e83c61a91001813129dafc93f95c7314730..bc20c13ac60c06590d1af2ce40104b1b0b6f0356 100644
--- a/test/Prefs.cpp
+++ b/test/Prefs.cpp
@@ -68,34 +68,36 @@ namespace
TestFileSystem* fileSystem;
AdblockPlus::FileSystemPtr fileSystemPtr;
AdblockPlus::JsEnginePtr jsEngine;
- FilterEnginePtr filterEngine;
void SetUp()
{
fileSystem = new TestFileSystem();
fileSystemPtr.reset(fileSystem);
- jsEngine = CreateJsEngine();
- Reset();
+ ResetJsEngine();
}
- void Reset(const AdblockPlus::FilterEngine::Prefs& preconfiguredPrefs =
- AdblockPlus::FilterEngine::Prefs())
+ void ResetJsEngine()
{
- if (!jsEngine)
- jsEngine = CreateJsEngine();
+ jsEngine = CreateJsEngine();
jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem));
jsEngine->SetFileSystem(fileSystemPtr);
jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
+ }
+
+ FilterEnginePtr CreateFilterEngine(const AdblockPlus::FilterEngine::Prefs& preconfiguredPrefs =
+ AdblockPlus::FilterEngine::Prefs())
+ {
AdblockPlus::FilterEngine::CreationParameters createParams;
createParams.preconfiguredPrefs = preconfiguredPrefs;
- filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParams);
+ return AdblockPlus::FilterEngine::Create(jsEngine, createParams);
}
};
}
TEST_F(PrefsTest, PrefsGetSet)
{
+ auto filterEngine = CreateFilterEngine();
ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString());
ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
@@ -116,30 +118,33 @@ TEST_F(PrefsTest, PrefsGetSet)
TEST_F(PrefsTest, PrefsPersist)
{
- ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString());
- ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
- ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
-
- filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini"));
- filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48));
- filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false));
+ {
+ auto filterEngine = CreateFilterEngine();
+ ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString());
+ ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
+ ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
- AdblockPlus::Sleep(100);
+ filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini"));
+ filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48));
+ filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false));
+ AdblockPlus::Sleep(100);
+ }
ASSERT_FALSE(fileSystem->prefsContents.empty());
- Reset();
-
- ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString());
- ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt());
- ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
+ {
+ ResetJsEngine();
+ auto filterEngine = CreateFilterEngine();
+ ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString());
+ ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt());
+ ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
+ }
}
TEST_F(PrefsTest, UnknownPrefs)
{
fileSystem->prefsContents = "{\"foobar\":2, \"patternsbackupinterval\": 12}";
- Reset();
-
+ auto filterEngine = CreateFilterEngine();
ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined());
ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval")->AsInt());
}
@@ -147,7 +152,7 @@ TEST_F(PrefsTest, UnknownPrefs)
TEST_F(PrefsTest, SyntaxFailure)
{
fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}";
- Reset();
+ auto filterEngine = CreateFilterEngine();
ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
}
@@ -157,7 +162,7 @@ TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured)
AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false);
preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
- Reset(preconfiguredPrefs);
+ auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates")->IsBool());
ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates")->AsBool());
@@ -169,7 +174,7 @@ TEST_F(PrefsTest, PreconfiguredPrefsUnsupported)
{
AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true);
- Reset(preconfiguredPrefs);
+ auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig")->IsUndefined());
}
@@ -178,7 +183,7 @@ TEST_F(PrefsTest, PreconfiguredPrefsOverride)
{
AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
- Reset(preconfiguredPrefs);
+ auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
@@ -187,21 +192,26 @@ TEST_F(PrefsTest, PreconfiguredPrefsOverride)
TEST_F(PrefsTest, PrefsPersistWhenPreconfigured)
{
- AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
- preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
- Reset(preconfiguredPrefs);
-
- ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
- ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
- filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
+ {
+ AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
+ preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
+ auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
- AdblockPlus::Sleep(100);
+ ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
+ ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
+ filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
+ AdblockPlus::Sleep(100);
+ }
ASSERT_FALSE(fileSystem->prefsContents.empty());
- jsEngine.reset();
- Reset(preconfiguredPrefs);
-
- ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
- ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
+ {
+ ResetJsEngine();
+ AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
+ preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
+ auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
+
+ ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
+ ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld