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

Unified Diff: test/JsEngine.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/FilterEngine.cpp ('k') | test/Notification.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/JsEngine.cpp
===================================================================
--- a/test/JsEngine.cpp
+++ b/test/JsEngine.cpp
@@ -104,33 +104,44 @@
TEST(NewJsEngineTest, CallbackGetSet)
{
- AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ auto jsEngine = AdblockPlus::JsEngine::New();
ASSERT_TRUE(jsEngine->GetLogSystem());
ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr()));
- AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem());
+ auto logSystem(std::make_shared<AdblockPlus::DefaultLogSystem>());
jsEngine->SetLogSystem(logSystem);
ASSERT_EQ(logSystem, jsEngine->GetLogSystem());
ASSERT_TRUE(jsEngine->GetFileSystem());
ASSERT_ANY_THROW(jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr()));
- AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem());
+ auto fileSystem(std::make_shared<AdblockPlus::DefaultFileSystem>());
jsEngine->SetFileSystem(fileSystem);
ASSERT_EQ(fileSystem, jsEngine->GetFileSystem());
ASSERT_TRUE(jsEngine->GetWebRequest());
ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr()));
- AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
+ auto webRequest(std::make_shared<AdblockPlus::DefaultWebRequest>());
jsEngine->SetWebRequest(webRequest);
ASSERT_EQ(webRequest, jsEngine->GetWebRequest());
+
+ ASSERT_EQ(1, jsEngine.use_count());
+ jsEngine.reset();
}
TEST(NewJsEngineTest, GlobalPropertyTest)
{
- AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ auto jsEngine = AdblockPlus::JsEngine::New();
jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar"));
- AdblockPlus::JsValuePtr foo = jsEngine->Evaluate("foo");
- ASSERT_TRUE(foo->IsString());
- ASSERT_EQ(foo->AsString(), "bar");
+ /*
+ * Use a separate scope for JsValue variable to ensure its destruction
+ * before we check the use count of the engine.
+ */
+ {
+ auto foo = jsEngine->Evaluate("foo");
+ ASSERT_TRUE(foo->IsString());
+ ASSERT_EQ(foo->AsString(), "bar");
+ }
+ ASSERT_EQ(1, jsEngine.use_count());
+ jsEngine.reset();
}
« no previous file with comments | « test/FilterEngine.cpp ('k') | test/Notification.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld