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

Unified Diff: test/FilterEngine.cpp

Issue 29417605: Issue 5034 - Part 3: Create plain JsValue instead of JsValuePtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 19, 2017, 5:54 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/FilterEngine.cpp
===================================================================
--- a/test/FilterEngine.cpp
+++ b/test/FilterEngine.cpp
@@ -223,30 +223,31 @@
jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem()));
subscriptionUrlPrefix = "http://example";
ServerResponse exampleSubscriptionResponse;
exampleSubscriptionResponse.responseStatus = 200;
exampleSubscriptionResponse.status = WebRequest::NS_OK;
exampleSubscriptionResponse.responseText = "[Adblock Plus 2.0]\n||example.com";
webRequest->responses.emplace(subscriptionUrlPrefix, exampleSubscriptionResponse);
- createParams.preconfiguredPrefs["first_run_subscription_auto_select"] = jsEngine->NewValue(false);
+ createParams.preconfiguredPrefs.insert(
+ std::make_pair("first_run_subscription_auto_select", jsEngine->NewValue(false)));
sergei 2017/04/19 18:56:52 here and below what about using of emplace method
hub 2017/04/19 21:56:49 good idea.
isConnectionAllowed = true;
createParams.isConnectionAllowedCallback = [this](const std::string* allowedConnectionType)->bool{
capturedConnectionTypes.Add(allowedConnectionType);
return isConnectionAllowed;
};
- jsEngine->SetEventCallback("filterChange", [this](const JsConstValueList& params/*action, item*/)
+ jsEngine->SetEventCallback("filterChange", [this](const JsValueList& params/*action, item*/)
{
ASSERT_EQ(2u, params.size());
- if (params[0]->AsString() == "subscription.downloadStatus")
+ 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())
{
@@ -745,17 +746,18 @@
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);
+ createParams.preconfiguredPrefs.insert(
+ std::make_pair("first_run_subscription_auto_select", jsEngine->NewValue(false)));
auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParams);
const auto subscriptions = filterEngine->GetListedSubscriptions();
EXPECT_EQ(0u, subscriptions.size());
EXPECT_FALSE(filterEngine->IsAAEnabled());
}
namespace AA_ApiTest
{
@@ -1035,34 +1037,36 @@
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);
+ createParams.preconfiguredPrefs.insert(std::make_pair("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());
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);
+ createParams.preconfiguredPrefs.insert(std::make_pair(
+ "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());
auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
ASSERT_EQ(1u, capturedConnectionTypes.size());
EXPECT_TRUE(capturedConnectionTypes[0].first);
EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second);
}

Powered by Google App Engine
This is Rietveld