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

Unified Diff: test/FilterEngineStubs.cpp

Issue 10173031: Don`t use references to JsEngine to avoid use-after-free errors,switch to shared_ptr instead (Closed)
Patch Set: Created April 18, 2013, 4:15 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
Index: test/FilterEngineStubs.cpp
===================================================================
--- a/test/FilterEngineStubs.cpp
+++ b/test/FilterEngineStubs.cpp
@@ -28,36 +28,36 @@ class DummyFileSystem : public AdblockPl
StatResult Stat(const std::string& path) const
{
throw std::runtime_error("Not implemented");
}
};
TEST(FilterEngineStubsTest, FilterCreation)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
AdblockPlus::FilterEngine filterEngine(jsEngine);
AdblockPlus::FilterPtr filter1 = filterEngine.GetFilter("foo");
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetProperty("type", -1));
AdblockPlus::FilterPtr filter2 = filterEngine.GetFilter("@@foo");
ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetProperty("type", -1));
AdblockPlus::FilterPtr filter3 = filterEngine.GetFilter("example.com##foo");
ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetProperty("type", -1));
AdblockPlus::FilterPtr filter4 = filterEngine.GetFilter("example.com#@#foo");
ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetProperty("type", -1));
AdblockPlus::FilterPtr filter5 = filterEngine.GetFilter(" foo ");
ASSERT_EQ(*filter1, *filter5);
}
TEST(FilterEngineStubsTest, FilterProperties)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
AdblockPlus::FilterEngine filterEngine(jsEngine);
AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo");
ASSERT_EQ("x", filter->GetProperty("stringFoo", "x"));
ASSERT_EQ(42, filter->GetProperty("intFoo", 42));
ASSERT_FALSE(filter->GetProperty("boolFoo", false));
filter->SetProperty("stringFoo", "y");
@@ -65,18 +65,18 @@ TEST(FilterEngineStubsTest, FilterProper
filter->SetProperty("boolFoo", true);
ASSERT_EQ("y", filter->GetProperty("stringFoo", "x"));
ASSERT_EQ(24, filter->GetProperty("intFoo", 42));
ASSERT_TRUE(filter->GetProperty("boolFoo", false));
}
TEST(FilterEngineStubsTest, AddRemoveFilters)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
AdblockPlus::FilterEngine filterEngine(jsEngine);
ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo");
ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
filter->AddToList();
ASSERT_EQ(1u, filterEngine.GetListedFilters().size());
ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]);
filter->AddToList();
@@ -85,18 +85,18 @@ TEST(FilterEngineStubsTest, AddRemoveFil
filter->RemoveFromList();
ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
filter->RemoveFromList();
ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
}
TEST(FilterEngineStubsTest, SubscriptionProperties)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
AdblockPlus::FilterEngine filterEngine(jsEngine);
AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo");
ASSERT_EQ("x", subscription->GetProperty("stringFoo", "x"));
ASSERT_EQ(42, subscription->GetProperty("intFoo", 42));
ASSERT_FALSE(subscription->GetProperty("boolFoo", false));
subscription->SetProperty("stringFoo", "y");
@@ -104,18 +104,18 @@ TEST(FilterEngineStubsTest, Subscription
subscription->SetProperty("boolFoo", true);
ASSERT_EQ("y", subscription->GetProperty("stringFoo", "x"));
ASSERT_EQ(24, subscription->GetProperty("intFoo", 42));
ASSERT_TRUE(subscription->GetProperty("boolFoo", false));
}
TEST(FilterEngineStubsTest, AddRemoveSubscriptions)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
AdblockPlus::FilterEngine filterEngine(jsEngine);
ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo");
ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
subscription->AddToList();
ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size());
ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]);
subscription->AddToList();
@@ -124,30 +124,30 @@ TEST(FilterEngineStubsTest, AddRemoveSub
subscription->RemoveFromList();
ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
subscription->RemoveFromList();
ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
}
TEST(FilterEngineStubsTest, SubscriptionUpdates)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
AdblockPlus::FilterEngine filterEngine(jsEngine);
AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo");
ASSERT_FALSE(subscription->IsUpdating());
//TODO: This currently crashes due to errors reported on a different thread
//subscription->UpdateFilters();
}
TEST(FilterEngineStubsTest, Matches)
{
- AdblockPlus::JsEngine jsEngine;
- jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
+ AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new DummyFileSystem()));
AdblockPlus::FilterEngine filterEngine(jsEngine);
filterEngine.GetFilter("adbanner.gif")->AddToList();
filterEngine.GetFilter("@@notbanner.gif")->AddToList();
AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org/foobar.gif", "IMAGE", "");
ASSERT_FALSE(match1);
« src/JsEngine.cpp ('K') | « test/FileSystemJsObject.cpp ('k') | test/GlobalJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld