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: Pass JsEngine by ref Created April 20, 2017, 1:01 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
« no previous file with comments | « src/WebRequestJsObject.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.emplace("first_run_subscription_auto_selec t", jsEngine->NewValue(false));
232 isConnectionAllowed = true; 232 isConnectionAllowed = true;
233 createParams.isConnectionAllowedCallback = [this](const std::string* allow edConnectionType)->bool{ 233 createParams.isConnectionAllowedCallback = [this](const std::string* allow edConnectionType)->bool{
234 capturedConnectionTypes.Add(allowedConnectionType); 234 capturedConnectionTypes.Add(allowedConnectionType);
235 return isConnectionAllowed; 235 return isConnectionAllowed;
236 }; 236 };
237 jsEngine->SetEventCallback("filterChange", [this](const JsConstValueList& params/*action, item*/) 237 jsEngine->SetEventCallback("filterChange", [this](const JsValueList& param s/*action, item*/)
238 { 238 {
239 ASSERT_EQ(2u, params.size()); 239 ASSERT_EQ(2u, params.size());
240 if (params[0]->AsString() == "subscription.downloadStatus") 240 if (params[0].AsString() == "subscription.downloadStatus")
241 { 241 {
242 { 242 {
243 std::lock_guard<std::mutex> lock(downloadStatusChanged.mutex); 243 std::lock_guard<std::mutex> lock(downloadStatusChanged.mutex);
244 downloadStatusChanged.url = params[1]->GetProperty("url").AsString() ; 244 downloadStatusChanged.url = params[1].GetProperty("url").AsString();
245 } 245 }
246 downloadStatusChanged.cv.notify_one(); 246 downloadStatusChanged.cv.notify_one();
247 } 247 }
248 }); 248 });
249 } 249 }
250 250
251 SubscriptionPtr EnsureExampleSubscriptionAndForceUpdate(const std::string& a pppendToUrl = std::string()) 251 SubscriptionPtr EnsureExampleSubscriptionAndForceUpdate(const std::string& a pppendToUrl = std::string())
252 { 252 {
253 if (!filterEngine) 253 if (!filterEngine)
254 filterEngine = FilterEngine::Create(jsEngine, createParams); 254 filterEngine = FilterEngine::Create(jsEngine, createParams);
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 ASSERT_NE(nullptr, aaSubscription); 743 ASSERT_NE(nullptr, aaSubscription);
744 ASSERT_NE(nullptr, langSubscription); 744 ASSERT_NE(nullptr, langSubscription);
745 EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url").AsString() ); 745 EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url").AsString() );
746 EXPECT_TRUE(filterEngine->IsAAEnabled()); 746 EXPECT_TRUE(filterEngine->IsAAEnabled());
747 } 747 }
748 748
749 TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun) 749 TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun)
750 { 750 {
751 auto jsEngine = createJsEngine(); 751 auto jsEngine = createJsEngine();
752 FilterEngine::CreationParameters createParams; 752 FilterEngine::CreationParameters createParams;
753 createParams.preconfiguredPrefs["first_run_subscription_auto_select"] = jsEngi ne->NewValue(false); 753 createParams.preconfiguredPrefs.emplace("first_run_subscription_auto_select", jsEngine->NewValue(false));
754 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParams); 754 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParams);
755 const auto subscriptions = filterEngine->GetListedSubscriptions(); 755 const auto subscriptions = filterEngine->GetListedSubscriptions();
756 EXPECT_EQ(0u, subscriptions.size()); 756 EXPECT_EQ(0u, subscriptions.size());
757 EXPECT_FALSE(filterEngine->IsAAEnabled()); 757 EXPECT_FALSE(filterEngine->IsAAEnabled());
758 } 758 }
759 759
760 namespace AA_ApiTest 760 namespace AA_ApiTest
761 { 761 {
762 const std::string kOtherSubscriptionUrl = "https://non-existing-subscription.t xt"; 762 const std::string kOtherSubscriptionUrl = "https://non-existing-subscription.t xt";
763 enum class AAStatus 763 enum class AAStatus
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); 1033 auto subscription = EnsureExampleSubscriptionAndForceUpdate();
1034 EXPECT_EQ("synchronize_connection_error", subscription->GetProperty("downloadS tatus").AsString()); 1034 EXPECT_EQ("synchronize_connection_error", subscription->GetProperty("downloadS tatus").AsString());
1035 EXPECT_EQ(0u, subscription->GetProperty("filters").AsList().size()); 1035 EXPECT_EQ(0u, subscription->GetProperty("filters").AsList().size());
1036 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1036 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1037 EXPECT_EQ(1u, capturedConnectionTypes.size()); 1037 EXPECT_EQ(1u, capturedConnectionTypes.size());
1038 } 1038 }
1039 1039
1040 TEST_F(FilterEngineIsAllowedConnectionTest, PredefinedAllowedConnectionTypeIsPas sedToCallback) 1040 TEST_F(FilterEngineIsAllowedConnectionTest, PredefinedAllowedConnectionTypeIsPas sedToCallback)
1041 { 1041 {
1042 std::string predefinedAllowedConnectionType = "non-metered"; 1042 std::string predefinedAllowedConnectionType = "non-metered";
1043 createParams.preconfiguredPrefs["allowed_connection_type"] = jsEngine->NewValu e(predefinedAllowedConnectionType); 1043 createParams.preconfiguredPrefs.insert(std::make_pair("allowed_connection_type ",
1044 jsEngine->NewValue(predefinedAllowedConnectionType)));
1044 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); 1045 auto subscription = EnsureExampleSubscriptionAndForceUpdate();
1045 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsStri ng()); 1046 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsStri ng());
1046 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); 1047 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
1047 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1048 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1048 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1049 ASSERT_EQ(1u, capturedConnectionTypes.size());
1049 EXPECT_TRUE(capturedConnectionTypes[0].first); 1050 EXPECT_TRUE(capturedConnectionTypes[0].first);
1050 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second); 1051 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second);
1051 } 1052 }
1052 1053
1053 TEST_F(FilterEngineIsAllowedConnectionTest, ConfiguredConnectionTypeIsPassedToCa llback) 1054 TEST_F(FilterEngineIsAllowedConnectionTest, ConfiguredConnectionTypeIsPassedToCa llback)
1054 { 1055 {
1055 // FilterEngine->RemoveSubscription is not usable here because subscriptions 1056 // FilterEngine->RemoveSubscription is not usable here because subscriptions
1056 // are cached internally by URL. So, different URLs are used in diffirent 1057 // are cached internally by URL. So, different URLs are used in diffirent
1057 // checks. 1058 // checks.
1058 { 1059 {
1059 std::string predefinedAllowedConnectionType = "non-metered"; 1060 std::string predefinedAllowedConnectionType = "non-metered";
1060 createParams.preconfiguredPrefs["allowed_connection_type"] = jsEngine->NewVa lue(predefinedAllowedConnectionType); 1061 createParams.preconfiguredPrefs.insert(std::make_pair(
1062 "allowed_connection_type", jsEngine->NewValue(predefinedAllowedConnectionT ype)));
1061 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); 1063 auto subscription = EnsureExampleSubscriptionAndForceUpdate();
1062 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring()); 1064 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring());
1063 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); 1065 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
1064 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1066 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1065 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1067 ASSERT_EQ(1u, capturedConnectionTypes.size());
1066 EXPECT_TRUE(capturedConnectionTypes[0].first); 1068 EXPECT_TRUE(capturedConnectionTypes[0].first);
1067 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second ); 1069 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second );
1068 } 1070 }
1069 capturedConnectionTypes.Clear(); 1071 capturedConnectionTypes.Clear();
1070 { 1072 {
(...skipping 15 matching lines...) Expand all
1086 filterEngine->SetAllowedConnectionType(&testConnection); 1088 filterEngine->SetAllowedConnectionType(&testConnection);
1087 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); 1089 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB");
1088 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring()); 1090 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring());
1089 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); 1091 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
1090 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1092 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1091 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1093 ASSERT_EQ(1u, capturedConnectionTypes.size());
1092 EXPECT_TRUE(capturedConnectionTypes[0].first); 1094 EXPECT_TRUE(capturedConnectionTypes[0].first);
1093 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); 1095 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second);
1094 } 1096 }
1095 } 1097 }
OLDNEW
« 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