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

Unified Diff: test/GlobalJsObject.cpp

Issue 29508569: Issue 5450 - don't expose std::shared_ptr<JsEngine> (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Aug. 7, 2017, 8:39 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 | « test/FilterEngine.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/GlobalJsObject.cpp
diff --git a/test/GlobalJsObject.cpp b/test/GlobalJsObject.cpp
index 575f76a2536cc87fcdda929864cdd404e5421e20..0c2e32d2594fa86c05fa5caa82e108ac133bff10 100644
--- a/test/GlobalJsObject.cpp
+++ b/test/GlobalJsObject.cpp
@@ -20,61 +20,45 @@
namespace
{
- class GlobalJsObjectTest : public ::testing::Test
+ class GlobalJsObjectTest : public BaseJsTest
{
protected:
- std::unique_ptr<AdblockPlus::Platform> platform;
- AdblockPlus::JsEnginePtr jsEngine;
-
void SetUp() override
{
ThrowingPlatformCreationParameters params;
params.timer = AdblockPlus::CreateDefaultTimer();
platform.reset(new AdblockPlus::Platform(std::move(params)));
- jsEngine = platform->GetJsEngine();
}
};
}
TEST_F(GlobalJsObjectTest, SetTimeout)
{
- jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
- ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined());
+ GetJsEngine().Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
+ ASSERT_TRUE(GetJsEngine().Evaluate("this.foo").IsUndefined());
AdblockPlus::Sleep(200);
- ASSERT_EQ("bar", jsEngine->Evaluate("this.foo").AsString());
+ ASSERT_EQ("bar", GetJsEngine().Evaluate("this.foo").AsString());
}
TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs)
{
- jsEngine->Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
- ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined());
+ GetJsEngine().Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
+ ASSERT_TRUE(GetJsEngine().Evaluate("this.foo").IsUndefined());
AdblockPlus::Sleep(200);
- ASSERT_EQ("foobar", jsEngine->Evaluate("this.foo").AsString());
+ ASSERT_EQ("foobar", GetJsEngine().Evaluate("this.foo").AsString());
}
TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs)
{
- ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout()"));
- ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout('', 1)"));
+ ASSERT_ANY_THROW(GetJsEngine().Evaluate("setTimeout()"));
+ ASSERT_ANY_THROW(GetJsEngine().Evaluate("setTimeout('', 1)"));
}
TEST_F(GlobalJsObjectTest, SetMultipleTimeouts)
{
- jsEngine->Evaluate("foo = []");
- jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
- jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
- AdblockPlus::Sleep(200);
- ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo").AsString());
-}
-
-TEST_F(GlobalJsObjectTest, TimeoutDoesNotKeepJsEngine)
-{
- jsEngine->Evaluate("setTimeout(function() {}, 50000)");
- // 1 reference is held by platform and yet one by the test fixture class.
- EXPECT_EQ(2u, jsEngine.use_count());
+ GetJsEngine().Evaluate("foo = []");
+ GetJsEngine().Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
+ GetJsEngine().Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
AdblockPlus::Sleep(200);
- std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine = jsEngine;
- jsEngine.reset();
- platform.reset();
- EXPECT_FALSE(weakJsEngine.lock());
-}
+ ASSERT_EQ("1,2", GetJsEngine().Evaluate("this.foo").AsString());
+}
« no previous file with comments | « test/FilterEngine.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld