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

Unified Diff: test/FilterEngine.cpp

Issue 10862008: Automatically add default filter subscription when necessary. (Closed)
Patch Set: Created May 27, 2013, 2:12 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/BaseJsTest.h ('k') | test/JsEngine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/FilterEngine.cpp
===================================================================
--- a/test/FilterEngine.cpp
+++ b/test/FilterEngine.cpp
@@ -16,30 +16,43 @@
*/
#include "BaseJsTest.h"
namespace
{
typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
- class FilterEngineTest : public BaseJsTest
+ class VeryLazyFileSystem : public LazyFileSystem
+ {
+ std::tr1::shared_ptr<std::istream> Read(const std::string& path) const
+ {
+ std::string dummyData("# Adblock Plus preferences");
+ return std::tr1::shared_ptr<std::istream>(new std::istringstream(dummyData));
+ }
+ };
+
+ template<class FileSystem, class LogSystem>
+ class FilterEngineTestGeneric : public BaseJsTest
{
protected:
FilterEnginePtr filterEngine;
void SetUp()
{
BaseJsTest::SetUp();
- jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem));
jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
- jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new AdblockPlus::DefaultLogSystem));
+ jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem));
filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
}
};
+
+ typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest;
+ typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngineTestNoData;
}
TEST_F(FilterEngineTest, FilterCreation)
{
AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo");
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType());
AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo");
ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType());
@@ -97,29 +110,30 @@ TEST_F(FilterEngineTest, SubscriptionPro
subscription->SetProperty("boolFoo", true);
ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString());
ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt());
ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool());
}
TEST_F(FilterEngineTest, AddRemoveSubscriptions)
{
- ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
+ // There should be only the default subscription initially
+ ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
- ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
+ ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
subscription->AddToList();
+ ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
+ ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
+ subscription->AddToList();
+ ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
+ ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
+ subscription->RemoveFromList();
ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
- ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
- subscription->AddToList();
+ subscription->RemoveFromList();
ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
- ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
- subscription->RemoveFromList();
- ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
- subscription->RemoveFromList();
- ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
}
TEST_F(FilterEngineTest, SubscriptionUpdates)
{
AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
ASSERT_FALSE(subscription->IsUpdating());
subscription->UpdateFilters();
}
@@ -155,8 +169,18 @@ TEST_F(FilterEngineTest, Matches)
AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpbanner.gif", "IMAGE", "http://example.com/");
ASSERT_TRUE(match7);
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpbanner.gif", "IMAGE", "http://example.com/");
ASSERT_FALSE(match8);
}
+
+TEST_F(FilterEngineTest, FirstRunFlag)
+{
+ ASSERT_FALSE(filterEngine->IsFirstRun());
+}
+
+TEST_F(FilterEngineTestNoData, FirstRunFlag)
+{
+ ASSERT_FALSE(filterEngine->IsFirstRun());
+}
« no previous file with comments | « test/BaseJsTest.h ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld