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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem())); 221 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem()));
222 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(webRequest = new MockWe bRequest())); 222 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(webRequest = new MockWe bRequest()));
223 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem())); 223 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem()));
224 224
225 subscriptionUrlPrefix = "http://example"; 225 subscriptionUrlPrefix = "http://example";
226 ServerResponse exampleSubscriptionResponse; 226 ServerResponse exampleSubscriptionResponse;
227 exampleSubscriptionResponse.responseStatus = 200; 227 exampleSubscriptionResponse.responseStatus = 200;
228 exampleSubscriptionResponse.status = WebRequest::NS_OK; 228 exampleSubscriptionResponse.status = WebRequest::NS_OK;
229 exampleSubscriptionResponse.responseText = "[Adblock Plus 2.0]\n||example. com"; 229 exampleSubscriptionResponse.responseText = "[Adblock Plus 2.0]\n||example. com";
230 webRequest->responses.emplace(subscriptionUrlPrefix, exampleSubscriptionRe sponse); 230 webRequest->responses.emplace(subscriptionUrlPrefix, exampleSubscriptionRe sponse);
231 createParams.preconfiguredPrefs["first_run_subscription_auto_select"] = js Engine->NewValue(false); 231 createParams.preconfiguredPrefs.insert(
232 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.
232 isConnectionAllowed = true; 233 isConnectionAllowed = true;
233 createParams.isConnectionAllowedCallback = [this](const std::string* allow edConnectionType)->bool{ 234 createParams.isConnectionAllowedCallback = [this](const std::string* allow edConnectionType)->bool{
234 capturedConnectionTypes.Add(allowedConnectionType); 235 capturedConnectionTypes.Add(allowedConnectionType);
235 return isConnectionAllowed; 236 return isConnectionAllowed;
236 }; 237 };
237 jsEngine->SetEventCallback("filterChange", [this](const JsConstValueList& params/*action, item*/) 238 jsEngine->SetEventCallback("filterChange", [this](const JsValueList& param s/*action, item*/)
238 { 239 {
239 ASSERT_EQ(2u, params.size()); 240 ASSERT_EQ(2u, params.size());
240 if (params[0]->AsString() == "subscription.downloadStatus") 241 if (params[0].AsString() == "subscription.downloadStatus")
241 { 242 {
242 { 243 {
243 std::lock_guard<std::mutex> lock(downloadStatusChanged.mutex); 244 std::lock_guard<std::mutex> lock(downloadStatusChanged.mutex);
244 downloadStatusChanged.url = params[1]->GetProperty("url").AsString() ; 245 downloadStatusChanged.url = params[1].GetProperty("url").AsString();
245 } 246 }
246 downloadStatusChanged.cv.notify_one(); 247 downloadStatusChanged.cv.notify_one();
247 } 248 }
248 }); 249 });
249 } 250 }
250 251
251 SubscriptionPtr EnsureExampleSubscriptionAndForceUpdate(const std::string& a pppendToUrl = std::string()) 252 SubscriptionPtr EnsureExampleSubscriptionAndForceUpdate(const std::string& a pppendToUrl = std::string())
252 { 253 {
253 if (!filterEngine) 254 if (!filterEngine)
254 filterEngine = FilterEngine::Create(jsEngine, createParams); 255 filterEngine = FilterEngine::Create(jsEngine, createParams);
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 ASSERT_NE(nullptr, aaSubscription); 744 ASSERT_NE(nullptr, aaSubscription);
744 ASSERT_NE(nullptr, langSubscription); 745 ASSERT_NE(nullptr, langSubscription);
745 EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url").AsString() ); 746 EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url").AsString() );
746 EXPECT_TRUE(filterEngine->IsAAEnabled()); 747 EXPECT_TRUE(filterEngine->IsAAEnabled());
747 } 748 }
748 749
749 TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun) 750 TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun)
750 { 751 {
751 auto jsEngine = createJsEngine(); 752 auto jsEngine = createJsEngine();
752 FilterEngine::CreationParameters createParams; 753 FilterEngine::CreationParameters createParams;
753 createParams.preconfiguredPrefs["first_run_subscription_auto_select"] = jsEngi ne->NewValue(false); 754 createParams.preconfiguredPrefs.insert(
755 std::make_pair("first_run_subscription_auto_select", jsEngine->NewValue(fals e)));
754 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParams); 756 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParams);
755 const auto subscriptions = filterEngine->GetListedSubscriptions(); 757 const auto subscriptions = filterEngine->GetListedSubscriptions();
756 EXPECT_EQ(0u, subscriptions.size()); 758 EXPECT_EQ(0u, subscriptions.size());
757 EXPECT_FALSE(filterEngine->IsAAEnabled()); 759 EXPECT_FALSE(filterEngine->IsAAEnabled());
758 } 760 }
759 761
760 namespace AA_ApiTest 762 namespace AA_ApiTest
761 { 763 {
762 const std::string kOtherSubscriptionUrl = "https://non-existing-subscription.t xt"; 764 const std::string kOtherSubscriptionUrl = "https://non-existing-subscription.t xt";
763 enum class AAStatus 765 enum class AAStatus
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); 1035 auto subscription = EnsureExampleSubscriptionAndForceUpdate();
1034 EXPECT_EQ("synchronize_connection_error", subscription->GetProperty("downloadS tatus").AsString()); 1036 EXPECT_EQ("synchronize_connection_error", subscription->GetProperty("downloadS tatus").AsString());
1035 EXPECT_EQ(0u, subscription->GetProperty("filters").AsList().size()); 1037 EXPECT_EQ(0u, subscription->GetProperty("filters").AsList().size());
1036 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1038 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1037 EXPECT_EQ(1u, capturedConnectionTypes.size()); 1039 EXPECT_EQ(1u, capturedConnectionTypes.size());
1038 } 1040 }
1039 1041
1040 TEST_F(FilterEngineIsAllowedConnectionTest, PredefinedAllowedConnectionTypeIsPas sedToCallback) 1042 TEST_F(FilterEngineIsAllowedConnectionTest, PredefinedAllowedConnectionTypeIsPas sedToCallback)
1041 { 1043 {
1042 std::string predefinedAllowedConnectionType = "non-metered"; 1044 std::string predefinedAllowedConnectionType = "non-metered";
1043 createParams.preconfiguredPrefs["allowed_connection_type"] = jsEngine->NewValu e(predefinedAllowedConnectionType); 1045 createParams.preconfiguredPrefs.insert(std::make_pair("allowed_connection_type ",
1046 jsEngine->NewValue(predefinedAllowedConnectionType)));
1044 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); 1047 auto subscription = EnsureExampleSubscriptionAndForceUpdate();
1045 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsStri ng()); 1048 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsStri ng());
1046 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); 1049 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
1047 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1050 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1048 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1051 ASSERT_EQ(1u, capturedConnectionTypes.size());
1049 EXPECT_TRUE(capturedConnectionTypes[0].first); 1052 EXPECT_TRUE(capturedConnectionTypes[0].first);
1050 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second); 1053 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second);
1051 } 1054 }
1052 1055
1053 TEST_F(FilterEngineIsAllowedConnectionTest, ConfiguredConnectionTypeIsPassedToCa llback) 1056 TEST_F(FilterEngineIsAllowedConnectionTest, ConfiguredConnectionTypeIsPassedToCa llback)
1054 { 1057 {
1055 // FilterEngine->RemoveSubscription is not usable here because subscriptions 1058 // FilterEngine->RemoveSubscription is not usable here because subscriptions
1056 // are cached internally by URL. So, different URLs are used in diffirent 1059 // are cached internally by URL. So, different URLs are used in diffirent
1057 // checks. 1060 // checks.
1058 { 1061 {
1059 std::string predefinedAllowedConnectionType = "non-metered"; 1062 std::string predefinedAllowedConnectionType = "non-metered";
1060 createParams.preconfiguredPrefs["allowed_connection_type"] = jsEngine->NewVa lue(predefinedAllowedConnectionType); 1063 createParams.preconfiguredPrefs.insert(std::make_pair(
1064 "allowed_connection_type", jsEngine->NewValue(predefinedAllowedConnectionT ype)));
1061 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); 1065 auto subscription = EnsureExampleSubscriptionAndForceUpdate();
1062 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring()); 1066 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring());
1063 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); 1067 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
1064 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1068 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1065 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1069 ASSERT_EQ(1u, capturedConnectionTypes.size());
1066 EXPECT_TRUE(capturedConnectionTypes[0].first); 1070 EXPECT_TRUE(capturedConnectionTypes[0].first);
1067 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second ); 1071 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second );
1068 } 1072 }
1069 capturedConnectionTypes.Clear(); 1073 capturedConnectionTypes.Clear();
1070 { 1074 {
(...skipping 15 matching lines...) Expand all
1086 filterEngine->SetAllowedConnectionType(&testConnection); 1090 filterEngine->SetAllowedConnectionType(&testConnection);
1087 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); 1091 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB");
1088 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring()); 1092 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring());
1089 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); 1093 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
1090 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1094 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1091 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1095 ASSERT_EQ(1u, capturedConnectionTypes.size());
1092 EXPECT_TRUE(capturedConnectionTypes[0].first); 1096 EXPECT_TRUE(capturedConnectionTypes[0].first);
1093 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); 1097 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second);
1094 } 1098 }
1095 } 1099 }
OLDNEW

Powered by Google App Engine
This is Rietveld