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

Unified Diff: test/FilterEngineStubs.cpp

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Patch Set: Unbitrotted patch Created April 16, 2013, 3:30 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/FileSystemJsObject.cpp ('k') | test/GlobalJsObject.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/FilterEngineStubs.cpp
===================================================================
--- a/test/FilterEngineStubs.cpp
+++ b/test/FilterEngineStubs.cpp
@@ -2,115 +2,127 @@
#include <gtest/gtest.h>
TEST(FilterEngineStubsTest, FilterCreation)
{
AdblockPlus::JsEngine jsEngine(0, 0, 0);
AdblockPlus::FilterEngine filterEngine(jsEngine);
AdblockPlus::FilterPtr filter1 = filterEngine.GetFilter("foo");
- ASSERT_EQ(filter1->GetProperty("type", -1), AdblockPlus::Filter::TYPE_BLOCKING);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetProperty("type", -1));
AdblockPlus::FilterPtr filter2 = filterEngine.GetFilter("@@foo");
- ASSERT_EQ(filter2->GetProperty("type", -1), AdblockPlus::Filter::TYPE_EXCEPTION);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetProperty("type", -1));
AdblockPlus::FilterPtr filter3 = filterEngine.GetFilter("example.com##foo");
- ASSERT_EQ(filter3->GetProperty("type", -1), AdblockPlus::Filter::TYPE_ELEMHIDE);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetProperty("type", -1));
AdblockPlus::FilterPtr filter4 = filterEngine.GetFilter("example.com#@#foo");
- ASSERT_EQ(filter4->GetProperty("type", -1), AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetProperty("type", -1));
AdblockPlus::FilterPtr filter5 = filterEngine.GetFilter(" foo ");
- ASSERT_EQ(filter5, filter1);
+ ASSERT_EQ(*filter1, *filter5);
}
TEST(FilterEngineStubsTest, FilterProperties)
{
AdblockPlus::JsEngine jsEngine(0, 0, 0);
AdblockPlus::FilterEngine filterEngine(jsEngine);
AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo");
- ASSERT_EQ(filter->GetProperty("stringFoo", "x"), "x");
- ASSERT_EQ(filter->GetProperty("intFoo", 42), 42);
- ASSERT_EQ(filter->GetProperty("boolFoo", false), false);
+ ASSERT_EQ("x", filter->GetProperty("stringFoo", "x"));
+ ASSERT_EQ(42, filter->GetProperty("intFoo", 42));
+ ASSERT_FALSE(filter->GetProperty("boolFoo", false));
filter->SetProperty("stringFoo", "y");
filter->SetProperty("intFoo", 24);
filter->SetProperty("boolFoo", true);
- ASSERT_EQ(filter->GetProperty("stringFoo", "x"), "y");
- ASSERT_EQ(filter->GetProperty("intFoo", 42), 24);
- ASSERT_EQ(filter->GetProperty("boolFoo", false), 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(0, 0, 0);
AdblockPlus::FilterEngine filterEngine(jsEngine);
- ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo");
- ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
filter->AddToList();
- ASSERT_EQ(filterEngine.GetListedFilters().size(), 1u);
- ASSERT_EQ(filterEngine.GetListedFilters()[0], filter);
+ ASSERT_EQ(1u, filterEngine.GetListedFilters().size());
+ ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]);
filter->AddToList();
- ASSERT_EQ(filterEngine.GetListedFilters().size(), 1u);
- ASSERT_EQ(filterEngine.GetListedFilters()[0], filter);
+ ASSERT_EQ(1u, filterEngine.GetListedFilters().size());
+ ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]);
filter->RemoveFromList();
- ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
filter->RemoveFromList();
- ASSERT_EQ(filterEngine.GetListedFilters().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
}
TEST(FilterEngineStubsTest, SubscriptionProperties)
{
AdblockPlus::JsEngine jsEngine(0, 0, 0);
AdblockPlus::FilterEngine filterEngine(jsEngine);
AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo");
- ASSERT_EQ(subscription->GetProperty("stringFoo", "x"), "x");
- ASSERT_EQ(subscription->GetProperty("intFoo", 42), 42);
- ASSERT_EQ(subscription->GetProperty("boolFoo", false), false);
+ ASSERT_EQ("x", subscription->GetProperty("stringFoo", "x"));
+ ASSERT_EQ(42, subscription->GetProperty("intFoo", 42));
+ ASSERT_FALSE(subscription->GetProperty("boolFoo", false));
subscription->SetProperty("stringFoo", "y");
subscription->SetProperty("intFoo", 24);
subscription->SetProperty("boolFoo", true);
- ASSERT_EQ(subscription->GetProperty("stringFoo", "x"), "y");
- ASSERT_EQ(subscription->GetProperty("intFoo", 42), 24);
- ASSERT_EQ(subscription->GetProperty("boolFoo", false), 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(0, 0, 0);
AdblockPlus::FilterEngine filterEngine(jsEngine);
- ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo");
- ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
subscription->AddToList();
- ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 1u);
- ASSERT_EQ(filterEngine.GetListedSubscriptions()[0], subscription);
+ ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size());
+ ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]);
subscription->AddToList();
- ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 1u);
- ASSERT_EQ(filterEngine.GetListedSubscriptions()[0], subscription);
+ ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size());
+ ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]);
subscription->RemoveFromList();
- ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
subscription->RemoveFromList();
- ASSERT_EQ(filterEngine.GetListedSubscriptions().size(), 0u);
+ ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
+}
+
+TEST(FilterEngineStubsTest, SubscriptionUpdates)
+{
+ AdblockPlus::JsEngine jsEngine(0, 0, 0);
+ 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(0, 0, 0);
AdblockPlus::FilterEngine filterEngine(jsEngine);
- AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo");
- subscription->AddToList();
- AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org", "", "");
+ filterEngine.GetFilter("adbanner.gif")->AddToList();
+ filterEngine.GetFilter("@@notbanner.gif")->AddToList();
+
+ AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org/foobar.gif", "IMAGE", "");
ASSERT_FALSE(match1);
- AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adbanner.gif", "", "");
+ AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adbanner.gif", "IMAGE", "");
ASSERT_TRUE(match2);
- ASSERT_EQ(match2->GetProperty("type", -1), AdblockPlus::Filter::TYPE_BLOCKING);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetProperty("type", -1));
- AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notbanner.gif", "", "");
+ AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notbanner.gif", "IMAGE", "");
ASSERT_TRUE(match3);
- ASSERT_EQ(match3->GetProperty("type", -1), AdblockPlus::Filter::TYPE_EXCEPTION);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetProperty("type", -1));
- AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notbanner.gif", "", "");
+ AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notbanner.gif", "IMAGE", "");
ASSERT_TRUE(match4);
- ASSERT_EQ(match4->GetProperty("type", -1), AdblockPlus::Filter::TYPE_EXCEPTION);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetProperty("type", -1));
}
« no previous file with comments | « test/FileSystemJsObject.cpp ('k') | test/GlobalJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld