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

Unified Diff: test/FilterEngine.cpp

Issue 29416579: Issue 5034 - Part 1: Pass a JsValue directly to SetProperty() and return from GetProperty() (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Remove JsValue test Created April 19, 2017, 2:46 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 | « src/WebRequestJsObject.cpp ('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
@@ -236,31 +236,31 @@
};
jsEngine->SetEventCallback("filterChange", [this](const JsConstValueList& params/*action, item*/)
{
ASSERT_EQ(2u, params.size());
if (params[0]->AsString() == "subscription.downloadStatus")
{
{
std::lock_guard<std::mutex> lock(downloadStatusChanged.mutex);
- downloadStatusChanged.url = params[1]->GetProperty("url")->AsString();
+ downloadStatusChanged.url = params[1]->GetProperty("url").AsString();
}
downloadStatusChanged.cv.notify_one();
}
});
}
SubscriptionPtr EnsureExampleSubscriptionAndForceUpdate(const std::string& apppendToUrl = std::string())
{
if (!filterEngine)
filterEngine = FilterEngine::Create(jsEngine, createParams);
auto subscriptionUrl = subscriptionUrlPrefix + apppendToUrl;
auto subscription = filterEngine->GetSubscription(subscriptionUrl);
- EXPECT_EQ(0u, subscription->GetProperty("filters")->AsList().size()) << subscriptionUrl;
- EXPECT_TRUE(subscription->GetProperty("downloadStatus")->IsNull()) << subscriptionUrl;
+ EXPECT_EQ(0u, subscription->GetProperty("filters").AsList().size()) << subscriptionUrl;
+ EXPECT_TRUE(subscription->GetProperty("downloadStatus").IsNull()) << subscriptionUrl;
subscription->UpdateFilters();
{
std::unique_lock<std::mutex> lock(downloadStatusChanged.mutex);
downloadStatusChanged.cv.wait_for(lock,
/*don't block tests forever*/std::chrono::seconds(5),
[this, subscriptionUrl]()->bool
{
return subscriptionUrl == downloadStatusChanged.url;
@@ -288,26 +288,26 @@
AdblockPlus::FilterPtr filter5 = filterEngine->GetFilter(" foo ");
ASSERT_EQ(*filter1, *filter5);
}
TEST_F(FilterEngineTest, FilterProperties)
{
AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo");
- ASSERT_TRUE(filter->GetProperty("stringFoo")->IsUndefined());
- ASSERT_TRUE(filter->GetProperty("intFoo")->IsUndefined());
- ASSERT_TRUE(filter->GetProperty("boolFoo")->IsUndefined());
+ ASSERT_TRUE(filter->GetProperty("stringFoo").IsUndefined());
+ ASSERT_TRUE(filter->GetProperty("intFoo").IsUndefined());
+ ASSERT_TRUE(filter->GetProperty("boolFoo").IsUndefined());
filter->SetProperty("stringFoo", "y");
filter->SetProperty("intFoo", 24);
filter->SetProperty("boolFoo", true);
- ASSERT_EQ("y", filter->GetProperty("stringFoo")->AsString());
- ASSERT_EQ(24, filter->GetProperty("intFoo")->AsInt());
- ASSERT_TRUE(filter->GetProperty("boolFoo")->AsBool());
+ ASSERT_EQ("y", filter->GetProperty("stringFoo").AsString());
+ ASSERT_EQ(24, filter->GetProperty("intFoo").AsInt());
+ ASSERT_TRUE(filter->GetProperty("boolFoo").AsBool());
}
TEST_F(FilterEngineTest, AddRemoveFilters)
{
ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo");
ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
ASSERT_FALSE(filter->IsListed());
@@ -326,26 +326,26 @@
ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
ASSERT_FALSE(filter->IsListed());
}
TEST_F(FilterEngineTest, SubscriptionProperties)
{
AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
- ASSERT_TRUE(subscription->GetProperty("stringFoo")->IsUndefined());
- ASSERT_TRUE(subscription->GetProperty("intFoo")->IsUndefined());
- ASSERT_TRUE(subscription->GetProperty("boolFoo")->IsUndefined());
+ ASSERT_TRUE(subscription->GetProperty("stringFoo").IsUndefined());
+ ASSERT_TRUE(subscription->GetProperty("intFoo").IsUndefined());
+ ASSERT_TRUE(subscription->GetProperty("boolFoo").IsUndefined());
subscription->SetProperty("stringFoo", "y");
subscription->SetProperty("intFoo", 24);
subscription->SetProperty("boolFoo", true);
- ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString());
- ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt());
- ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool());
+ 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());
AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
ASSERT_FALSE(subscription->IsListed());
@@ -737,17 +737,17 @@
}
else if (subscriptions[1]->IsAA())
{
aaSubscription = subscriptions[1];
langSubscription = subscriptions[0];
}
ASSERT_NE(nullptr, aaSubscription);
ASSERT_NE(nullptr, langSubscription);
- EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url")->AsString());
+ EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url").AsString());
EXPECT_TRUE(filterEngine->IsAAEnabled());
}
TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun)
{
auto jsEngine = createJsEngine();
FilterEngine::CreationParameters createParams;
createParams.preconfiguredPrefs["first_run_subscription_auto_select"] = jsEngine->NewValue(false);
@@ -910,17 +910,17 @@
if (otherSubscriptionsNumber == 1u)
{
auto subscription = filterEngine->GetSubscription(kOtherSubscriptionUrl);
ASSERT_TRUE(subscription);
subscription->AddToList();
const auto subscriptions = filterEngine->GetListedSubscriptions();
ASSERT_EQ(1u, subscriptions.size());
EXPECT_FALSE(subscriptions[0]->IsAA());
- EXPECT_EQ(kOtherSubscriptionUrl, subscriptions[0]->GetProperty("url")->AsString());
+ EXPECT_EQ(kOtherSubscriptionUrl, subscriptions[0]->GetProperty("url").AsString());
}
if (isAASatusPresent(aaStatus))
{
filterEngine->SetAAEnabled(true); // add AA by enabling it
if (aaStatus == AAStatus::disabled_present)
{
filterEngine->SetAAEnabled(false);
}
@@ -1006,90 +1006,90 @@
testSubscriptionState(parameter.expectedAAStatus, otherSubscriptionsNumber);
}
}
TEST_F(FilterEngineIsAllowedConnectionTest, AbsentCallbackAllowsUpdating)
{
createParams.isConnectionAllowedCallback = FilterEngine::IsConnectionAllowedCallback();
auto subscription = EnsureExampleSubscriptionAndForceUpdate();
- EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus")->AsString());
- EXPECT_EQ(1u, subscription->GetProperty("filters")->AsList().size());
+ EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsString());
+ EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
}
TEST_F(FilterEngineIsAllowedConnectionTest, AllowingCallbackAllowsUpdating)
{
// no stored allowed_connection_type preference
auto subscription = EnsureExampleSubscriptionAndForceUpdate();
- EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus")->AsString());
- EXPECT_EQ(1u, subscription->GetProperty("filters")->AsList().size());
+ EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsString());
+ EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
ASSERT_EQ(1u, capturedConnectionTypes.size());
EXPECT_FALSE(capturedConnectionTypes[0].first);
}
TEST_F(FilterEngineIsAllowedConnectionTest, NotAllowingCallbackDoesNotAllowUpdating)
{
isConnectionAllowed = false;
// no stored allowed_connection_type preference
auto subscription = EnsureExampleSubscriptionAndForceUpdate();
- EXPECT_EQ("synchronize_connection_error", subscription->GetProperty("downloadStatus")->AsString());
- EXPECT_EQ(0u, subscription->GetProperty("filters")->AsList().size());
+ EXPECT_EQ("synchronize_connection_error", subscription->GetProperty("downloadStatus").AsString());
+ EXPECT_EQ(0u, subscription->GetProperty("filters").AsList().size());
auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
EXPECT_EQ(1u, capturedConnectionTypes.size());
}
TEST_F(FilterEngineIsAllowedConnectionTest, PredefinedAllowedConnectionTypeIsPassedToCallback)
{
std::string predefinedAllowedConnectionType = "non-metered";
createParams.preconfiguredPrefs["allowed_connection_type"] = jsEngine->NewValue(predefinedAllowedConnectionType);
auto subscription = EnsureExampleSubscriptionAndForceUpdate();
- EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus")->AsString());
- EXPECT_EQ(1u, subscription->GetProperty("filters")->AsList().size());
+ EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsString());
+ EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
ASSERT_EQ(1u, capturedConnectionTypes.size());
EXPECT_TRUE(capturedConnectionTypes[0].first);
EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second);
}
TEST_F(FilterEngineIsAllowedConnectionTest, ConfiguredConnectionTypeIsPassedToCallback)
{
// FilterEngine->RemoveSubscription is not usable here because subscriptions
// are cached internally by URL. So, different URLs are used in diffirent
// checks.
{
std::string predefinedAllowedConnectionType = "non-metered";
createParams.preconfiguredPrefs["allowed_connection_type"] = jsEngine->NewValue(predefinedAllowedConnectionType);
auto subscription = EnsureExampleSubscriptionAndForceUpdate();
- EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus")->AsString());
- EXPECT_EQ(1u, subscription->GetProperty("filters")->AsList().size());
+ EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsString());
+ EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
ASSERT_EQ(1u, capturedConnectionTypes.size());
EXPECT_TRUE(capturedConnectionTypes[0].first);
EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second);
}
capturedConnectionTypes.Clear();
{
// set no value
filterEngine->SetAllowedConnectionType(nullptr);
auto subscription = EnsureExampleSubscriptionAndForceUpdate("subA");
- EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus")->AsString());
- EXPECT_EQ(1u, subscription->GetProperty("filters")->AsList().size());
+ EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsString());
+ EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
ASSERT_EQ(1u, capturedConnectionTypes.size());
EXPECT_FALSE(capturedConnectionTypes[0].first);
subscription->RemoveFromList();
this->capturedConnectionTypes.Clear();
}
capturedConnectionTypes.Clear();
{
// set some value
std::string testConnection = "test connection";
filterEngine->SetAllowedConnectionType(&testConnection);
auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB");
- EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus")->AsString());
- EXPECT_EQ(1u, subscription->GetProperty("filters")->AsList().size());
+ EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsString());
+ EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
ASSERT_EQ(1u, capturedConnectionTypes.size());
EXPECT_TRUE(capturedConnectionTypes[0].first);
EXPECT_EQ(testConnection, capturedConnectionTypes[0].second);
}
}
« no previous file with comments | « src/WebRequestJsObject.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld