| OLD | NEW | 
|     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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   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     Subscription EnsureExampleSubscriptionAndForceUpdate(const std::string& appp
      endToUrl = std::string()) | 
|   252     { |   252     { | 
|   253       if (!filterEngine) |   253       if (!filterEngine) | 
|   254         filterEngine = FilterEngine::Create(jsEngine, createParams); |   254         filterEngine = FilterEngine::Create(jsEngine, createParams); | 
|   255       auto subscriptionUrl = subscriptionUrlPrefix + apppendToUrl; |   255       auto subscriptionUrl = subscriptionUrlPrefix + apppendToUrl; | 
|   256       auto subscription = filterEngine->GetSubscription(subscriptionUrl); |   256       auto subscription = filterEngine->GetSubscription(subscriptionUrl); | 
|   257       EXPECT_EQ(0u, subscription->GetProperty("filters").AsList().size()) << sub
      scriptionUrl; |   257       EXPECT_EQ(0u, subscription.GetProperty("filters").AsList().size()) << subs
      criptionUrl; | 
|   258       EXPECT_TRUE(subscription->GetProperty("downloadStatus").IsNull()) << subsc
      riptionUrl; |   258       EXPECT_TRUE(subscription.GetProperty("downloadStatus").IsNull()) << subscr
      iptionUrl; | 
|   259       subscription->UpdateFilters(); |   259       subscription.UpdateFilters(); | 
|   260       { |   260       { | 
|   261         std::unique_lock<std::mutex> lock(downloadStatusChanged.mutex); |   261         std::unique_lock<std::mutex> lock(downloadStatusChanged.mutex); | 
|   262         downloadStatusChanged.cv.wait_for(lock, |   262         downloadStatusChanged.cv.wait_for(lock, | 
|   263           /*don't block tests forever*/std::chrono::seconds(5), |   263           /*don't block tests forever*/std::chrono::seconds(5), | 
|   264           [this, subscriptionUrl]()->bool |   264           [this, subscriptionUrl]()->bool | 
|   265         { |   265         { | 
|   266           return subscriptionUrl == downloadStatusChanged.url; |   266           return subscriptionUrl == downloadStatusChanged.url; | 
|   267         }); |   267         }); | 
|   268         // Basically it's enough to wait only for downloadStatus although there |   268         // Basically it's enough to wait only for downloadStatus although there | 
|   269         // is still some JS code being executed. Any following attempt to work |   269         // is still some JS code being executed. Any following attempt to work | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   322   filter.RemoveFromList(); |   322   filter.RemoveFromList(); | 
|   323   ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); |   323   ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); | 
|   324   ASSERT_FALSE(filter.IsListed()); |   324   ASSERT_FALSE(filter.IsListed()); | 
|   325   filter.RemoveFromList(); |   325   filter.RemoveFromList(); | 
|   326   ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); |   326   ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); | 
|   327   ASSERT_FALSE(filter.IsListed()); |   327   ASSERT_FALSE(filter.IsListed()); | 
|   328 } |   328 } | 
|   329  |   329  | 
|   330 TEST_F(FilterEngineTest, SubscriptionProperties) |   330 TEST_F(FilterEngineTest, SubscriptionProperties) | 
|   331 { |   331 { | 
|   332   AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo
      "); |   332   AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 
|   333  |   333  | 
|   334   ASSERT_TRUE(subscription->GetProperty("stringFoo").IsUndefined()); |   334   ASSERT_TRUE(subscription.GetProperty("stringFoo").IsUndefined()); | 
|   335   ASSERT_TRUE(subscription->GetProperty("intFoo").IsUndefined()); |   335   ASSERT_TRUE(subscription.GetProperty("intFoo").IsUndefined()); | 
|   336   ASSERT_TRUE(subscription->GetProperty("boolFoo").IsUndefined()); |   336   ASSERT_TRUE(subscription.GetProperty("boolFoo").IsUndefined()); | 
|   337  |   337  | 
|   338   subscription->SetProperty("stringFoo", "y"); |   338   subscription.SetProperty("stringFoo", "y"); | 
|   339   subscription->SetProperty("intFoo", 24); |   339   subscription.SetProperty("intFoo", 24); | 
|   340   subscription->SetProperty("boolFoo", true); |   340   subscription.SetProperty("boolFoo", true); | 
|   341   ASSERT_EQ("y", subscription->GetProperty("stringFoo").AsString()); |   341   ASSERT_EQ("y", subscription.GetProperty("stringFoo").AsString()); | 
|   342   ASSERT_EQ(24, subscription->GetProperty("intFoo").AsInt()); |   342   ASSERT_EQ(24, subscription.GetProperty("intFoo").AsInt()); | 
|   343   ASSERT_TRUE(subscription->GetProperty("boolFoo").AsBool()); |   343   ASSERT_TRUE(subscription.GetProperty("boolFoo").AsBool()); | 
|   344 } |   344 } | 
|   345  |   345  | 
|   346 TEST_F(FilterEngineTest, AddRemoveSubscriptions) |   346 TEST_F(FilterEngineTest, AddRemoveSubscriptions) | 
|   347 { |   347 { | 
|   348   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |   348   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 
|   349   AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo
      "); |   349   AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 
|   350   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |   350   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 
|   351   ASSERT_FALSE(subscription->IsListed()); |   351   ASSERT_FALSE(subscription.IsListed()); | 
|   352   subscription->AddToList(); |   352   subscription.AddToList(); | 
|   353   ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); |   353   ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | 
|   354   ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); |   354   ASSERT_EQ(subscription, filterEngine->GetListedSubscriptions()[0]); | 
|   355   ASSERT_TRUE(subscription->IsListed()); |   355   ASSERT_TRUE(subscription.IsListed()); | 
|   356   subscription->AddToList(); |   356   subscription.AddToList(); | 
|   357   ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); |   357   ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | 
|   358   ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); |   358   ASSERT_EQ(subscription, filterEngine->GetListedSubscriptions()[0]); | 
|   359   ASSERT_TRUE(subscription->IsListed()); |   359   ASSERT_TRUE(subscription.IsListed()); | 
|   360   subscription->RemoveFromList(); |   360   subscription.RemoveFromList(); | 
|   361   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |   361   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 
|   362   ASSERT_FALSE(subscription->IsListed()); |   362   ASSERT_FALSE(subscription.IsListed()); | 
|   363   subscription->RemoveFromList(); |   363   subscription.RemoveFromList(); | 
|   364   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |   364   ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 
|   365   ASSERT_FALSE(subscription->IsListed()); |   365   ASSERT_FALSE(subscription.IsListed()); | 
|   366 } |   366 } | 
|   367  |   367  | 
|   368 TEST_F(FilterEngineTest, SubscriptionUpdates) |   368 TEST_F(FilterEngineTest, SubscriptionUpdates) | 
|   369 { |   369 { | 
|   370   AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo
      "); |   370   AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 
|   371   ASSERT_FALSE(subscription->IsUpdating()); |   371   ASSERT_FALSE(subscription.IsUpdating()); | 
|   372   subscription->UpdateFilters(); |   372   subscription.UpdateFilters(); | 
|   373 } |   373 } | 
|   374  |   374  | 
|   375 TEST_F(FilterEngineTest, Matches) |   375 TEST_F(FilterEngineTest, Matches) | 
|   376 { |   376 { | 
|   377   filterEngine->GetFilter("adbanner.gif").AddToList(); |   377   filterEngine->GetFilter("adbanner.gif").AddToList(); | 
|   378   filterEngine->GetFilter("@@notbanner.gif").AddToList(); |   378   filterEngine->GetFilter("@@notbanner.gif").AddToList(); | 
|   379   filterEngine->GetFilter("tpbanner.gif$third-party").AddToList(); |   379   filterEngine->GetFilter("tpbanner.gif$third-party").AddToList(); | 
|   380   filterEngine->GetFilter("fpbanner.gif$~third-party").AddToList(); |   380   filterEngine->GetFilter("fpbanner.gif$~third-party").AddToList(); | 
|   381   filterEngine->GetFilter("combanner.gif$domain=example.com").AddToList(); |   381   filterEngine->GetFilter("combanner.gif$domain=example.com").AddToList(); | 
|   382   filterEngine->GetFilter("orgbanner.gif$domain=~example.com").AddToList(); |   382   filterEngine->GetFilter("orgbanner.gif$domain=~example.com").AddToList(); | 
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   721  |   721  | 
|   722 TEST_F(FilterEngineWithFreshFolder, LangAndAASubscriptionsAreChosenOnFirstRun) |   722 TEST_F(FilterEngineWithFreshFolder, LangAndAASubscriptionsAreChosenOnFirstRun) | 
|   723 { |   723 { | 
|   724   AppInfo appInfo; |   724   AppInfo appInfo; | 
|   725   appInfo.locale = "zh"; |   725   appInfo.locale = "zh"; | 
|   726   const std::string langSubscriptionUrl = "https://easylist-downloads.adblockplu
      s.org/easylistchina+easylist.txt"; |   726   const std::string langSubscriptionUrl = "https://easylist-downloads.adblockplu
      s.org/easylistchina+easylist.txt"; | 
|   727   auto jsEngine = createJsEngine(appInfo); |   727   auto jsEngine = createJsEngine(appInfo); | 
|   728   auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); |   728   auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); | 
|   729   const auto subscriptions = filterEngine->GetListedSubscriptions(); |   729   const auto subscriptions = filterEngine->GetListedSubscriptions(); | 
|   730   ASSERT_EQ(2u, subscriptions.size()); |   730   ASSERT_EQ(2u, subscriptions.size()); | 
|   731   SubscriptionPtr aaSubscription; |   731   std::unique_ptr<Subscription> aaSubscription; | 
|   732   SubscriptionPtr langSubscription; |   732   std::unique_ptr<Subscription> langSubscription; | 
|   733   if (subscriptions[0]->IsAA()) |   733   if (subscriptions[0].IsAA()) | 
|   734   { |   734   { | 
|   735     aaSubscription = subscriptions[0]; |   735     aaSubscription.reset(new Subscription(subscriptions[0])); | 
|   736     langSubscription = subscriptions[1]; |   736     langSubscription.reset(new Subscription(subscriptions[1])); | 
|   737   } |   737   } | 
|   738   else if (subscriptions[1]->IsAA()) |   738   else if (subscriptions[1].IsAA()) | 
|   739   { |   739   { | 
|   740     aaSubscription = subscriptions[1]; |   740     aaSubscription.reset(new Subscription(subscriptions[1])); | 
|   741     langSubscription = subscriptions[0]; |   741     langSubscription.reset(new Subscription(subscriptions[0])); | 
|   742   } |   742   } | 
|   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(); | 
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   903         // no subscription (because of preconfigured prefs.json and patterns.ini
      ), |   903         // no subscription (because of preconfigured prefs.json and patterns.ini
      ), | 
|   904         // though it should be enabled by default in a non-test environment, it'
      s tested in |   904         // though it should be enabled by default in a non-test environment, it'
      s tested in | 
|   905         // corresponding tests. |   905         // corresponding tests. | 
|   906         const auto subscriptions = filterEngine->GetListedSubscriptions(); |   906         const auto subscriptions = filterEngine->GetListedSubscriptions(); | 
|   907         EXPECT_EQ(0u, subscriptions.size()); // no any subscription including AA |   907         EXPECT_EQ(0u, subscriptions.size()); // no any subscription including AA | 
|   908         EXPECT_FALSE(filterEngine->IsAAEnabled()); |   908         EXPECT_FALSE(filterEngine->IsAAEnabled()); | 
|   909       } |   909       } | 
|   910       if (otherSubscriptionsNumber == 1u) |   910       if (otherSubscriptionsNumber == 1u) | 
|   911       { |   911       { | 
|   912         auto subscription = filterEngine->GetSubscription(kOtherSubscriptionUrl)
      ; |   912         auto subscription = filterEngine->GetSubscription(kOtherSubscriptionUrl)
      ; | 
|   913         ASSERT_TRUE(subscription); |   913         subscription.AddToList(); | 
|   914         subscription->AddToList(); |  | 
|   915         const auto subscriptions = filterEngine->GetListedSubscriptions(); |   914         const auto subscriptions = filterEngine->GetListedSubscriptions(); | 
|   916         ASSERT_EQ(1u, subscriptions.size()); |   915         ASSERT_EQ(1u, subscriptions.size()); | 
|   917         EXPECT_FALSE(subscriptions[0]->IsAA()); |   916         EXPECT_FALSE(subscriptions[0].IsAA()); | 
|   918         EXPECT_EQ(kOtherSubscriptionUrl, subscriptions[0]->GetProperty("url").As
      String()); |   917         EXPECT_EQ(kOtherSubscriptionUrl, subscriptions[0].GetProperty("url").AsS
      tring()); | 
|   919       } |   918       } | 
|   920       if (isAASatusPresent(aaStatus)) |   919       if (isAASatusPresent(aaStatus)) | 
|   921       { |   920       { | 
|   922         filterEngine->SetAAEnabled(true); // add AA by enabling it |   921         filterEngine->SetAAEnabled(true); // add AA by enabling it | 
|   923         if (aaStatus == AAStatus::disabled_present) |   922         if (aaStatus == AAStatus::disabled_present) | 
|   924         { |   923         { | 
|   925           filterEngine->SetAAEnabled(false); |   924           filterEngine->SetAAEnabled(false); | 
|   926         } |   925         } | 
|   927         testSubscriptionState(aaStatus, otherSubscriptionsNumber); |   926         testSubscriptionState(aaStatus, otherSubscriptionsNumber); | 
|   928       } |   927       } | 
|   929     } |   928     } | 
|   930     bool isAASatusPresent(AAStatus aaStatus) |   929     bool isAASatusPresent(AAStatus aaStatus) | 
|   931     { |   930     { | 
|   932       return aaStatus != AAStatus::absent; |   931       return aaStatus != AAStatus::absent; | 
|   933     } |   932     } | 
|   934     void testSubscriptionState(AAStatus aaStatus, int otherSubscriptionsNumber) |   933     void testSubscriptionState(AAStatus aaStatus, int otherSubscriptionsNumber) | 
|   935     { |   934     { | 
|   936       if (aaStatus == AAStatus::enabled) |   935       if (aaStatus == AAStatus::enabled) | 
|   937         EXPECT_TRUE(filterEngine->IsAAEnabled()); |   936         EXPECT_TRUE(filterEngine->IsAAEnabled()); | 
|   938       else |   937       else | 
|   939         EXPECT_FALSE(filterEngine->IsAAEnabled()); |   938         EXPECT_FALSE(filterEngine->IsAAEnabled()); | 
|   940  |   939  | 
|   941       SubscriptionPtr aaSubscription; |   940       std::unique_ptr<Subscription> aaSubscription; | 
|   942       SubscriptionPtr otherSubscription; |   941       std::unique_ptr<Subscription> otherSubscription; | 
|   943       const auto subscriptions = filterEngine->GetListedSubscriptions(); |   942       auto subscriptions = filterEngine->GetListedSubscriptions(); | 
|   944       for (const auto& subscription : subscriptions) |   943       for (auto& subscription : subscriptions) | 
|   945       { |   944       { | 
|   946         (subscription->IsAA() ? aaSubscription : otherSubscription) = subscripti
      on; |   945         (subscription.IsAA() ? aaSubscription : otherSubscription) = | 
 |   946           std::unique_ptr<Subscription>(new Subscription(std::move(subscription)
      )); | 
|   947       } |   947       } | 
|   948       if (otherSubscriptionsNumber == 1u) |   948       if (otherSubscriptionsNumber == 1u) | 
|   949       { |   949       { | 
|   950         if (isAASatusPresent(aaStatus)) |   950         if (isAASatusPresent(aaStatus)) | 
|   951         { |   951         { | 
|   952           EXPECT_EQ(2u, subscriptions.size()); |   952           EXPECT_EQ(2u, subscriptions.size()); | 
|   953           EXPECT_TRUE(aaSubscription); |   953           EXPECT_TRUE(aaSubscription); | 
|   954           EXPECT_TRUE(otherSubscription); |   954           EXPECT_TRUE(otherSubscription); | 
|   955         } |   955         } | 
|   956         else |   956         else | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|   983     const auto parameter = ::testing::get<0>(GetParam()); |   983     const auto parameter = ::testing::get<0>(GetParam()); | 
|   984     uint8_t otherSubscriptionsNumber = ::testing::get<1>(GetParam()); |   984     uint8_t otherSubscriptionsNumber = ::testing::get<1>(GetParam()); | 
|   985     init(parameter.initialAAStatus, otherSubscriptionsNumber); |   985     init(parameter.initialAAStatus, otherSubscriptionsNumber); | 
|   986  |   986  | 
|   987     if (parameter.action == Action::enable) |   987     if (parameter.action == Action::enable) | 
|   988       filterEngine->SetAAEnabled(true); |   988       filterEngine->SetAAEnabled(true); | 
|   989     else if (parameter.action == Action::disable) |   989     else if (parameter.action == Action::disable) | 
|   990       filterEngine->SetAAEnabled(false); |   990       filterEngine->SetAAEnabled(false); | 
|   991     else if (parameter.action == Action::remove) |   991     else if (parameter.action == Action::remove) | 
|   992     { |   992     { | 
|   993       SubscriptionPtr aaSubscription; |   993       std::unique_ptr<Subscription> aaSubscription; | 
|   994       for (const auto& subscription : filterEngine->GetListedSubscriptions()) |   994       for (auto& subscription : filterEngine->GetListedSubscriptions()) | 
|   995       { |   995       { | 
|   996         if (subscription->IsAA()) |   996         if (subscription.IsAA()) | 
|   997         { |   997         { | 
|   998           aaSubscription = subscription; |   998           aaSubscription.reset(new Subscription(std::move(subscription))); | 
|   999           break; |   999           break; | 
|  1000         } |  1000         } | 
|  1001       } |  1001       } | 
|  1002       ASSERT_TRUE(aaSubscription); |  1002       ASSERT_TRUE(aaSubscription); | 
|  1003       aaSubscription->RemoveFromList(); |  1003       aaSubscription->RemoveFromList(); | 
|  1004     } |  1004     } | 
|  1005  |  1005  | 
|  1006     testSubscriptionState(parameter.expectedAAStatus, otherSubscriptionsNumber); |  1006     testSubscriptionState(parameter.expectedAAStatus, otherSubscriptionsNumber); | 
|  1007   } |  1007   } | 
|  1008 } |  1008 } | 
|  1009  |  1009  | 
|  1010 TEST_F(FilterEngineIsAllowedConnectionTest, AbsentCallbackAllowsUpdating) |  1010 TEST_F(FilterEngineIsAllowedConnectionTest, AbsentCallbackAllowsUpdating) | 
|  1011 { |  1011 { | 
|  1012   createParams.isConnectionAllowedCallback = FilterEngine::IsConnectionAllowedCa
      llback(); |  1012   createParams.isConnectionAllowedCallback = FilterEngine::IsConnectionAllowedCa
      llback(); | 
|  1013   auto subscription = EnsureExampleSubscriptionAndForceUpdate(); |  1013   auto subscription = EnsureExampleSubscriptionAndForceUpdate(); | 
|  1014   EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsStri
      ng()); |  1014   EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStrin
      g()); | 
|  1015   EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); |  1015   EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 
|  1016 } |  1016 } | 
|  1017  |  1017  | 
|  1018 TEST_F(FilterEngineIsAllowedConnectionTest, AllowingCallbackAllowsUpdating) |  1018 TEST_F(FilterEngineIsAllowedConnectionTest, AllowingCallbackAllowsUpdating) | 
|  1019 { |  1019 { | 
|  1020   // no stored allowed_connection_type preference |  1020   // no stored allowed_connection_type preference | 
|  1021   auto subscription = EnsureExampleSubscriptionAndForceUpdate(); |  1021   auto subscription = EnsureExampleSubscriptionAndForceUpdate(); | 
|  1022   EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsStri
      ng()); |  1022   EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStrin
      g()); | 
|  1023   EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); |  1023   EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 
|  1024   auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); |  1024   auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); | 
|  1025   ASSERT_EQ(1u, capturedConnectionTypes.size()); |  1025   ASSERT_EQ(1u, capturedConnectionTypes.size()); | 
|  1026   EXPECT_FALSE(capturedConnectionTypes[0].first); |  1026   EXPECT_FALSE(capturedConnectionTypes[0].first); | 
|  1027 } |  1027 } | 
|  1028  |  1028  | 
|  1029 TEST_F(FilterEngineIsAllowedConnectionTest, NotAllowingCallbackDoesNotAllowUpdat
      ing) |  1029 TEST_F(FilterEngineIsAllowedConnectionTest, NotAllowingCallbackDoesNotAllowUpdat
      ing) | 
|  1030 { |  1030 { | 
|  1031   isConnectionAllowed = false; |  1031   isConnectionAllowed = false; | 
|  1032   // no stored allowed_connection_type preference |  1032   // no stored allowed_connection_type preference | 
|  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("downloadSt
      atus").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.insert(std::make_pair("allowed_connection_type
      ", |  1043   createParams.preconfiguredPrefs.insert(std::make_pair("allowed_connection_type
      ", | 
|  1044     jsEngine->NewValue(predefinedAllowedConnectionType))); |  1044     jsEngine->NewValue(predefinedAllowedConnectionType))); | 
|  1045   auto subscription = EnsureExampleSubscriptionAndForceUpdate(); |  1045   auto subscription = EnsureExampleSubscriptionAndForceUpdate(); | 
|  1046   EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsStri
      ng()); |  1046   EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStrin
      g()); | 
|  1047   EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); |  1047   EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 
|  1048   auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); |  1048   auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); | 
|  1049   ASSERT_EQ(1u, capturedConnectionTypes.size()); |  1049   ASSERT_EQ(1u, capturedConnectionTypes.size()); | 
|  1050   EXPECT_TRUE(capturedConnectionTypes[0].first); |  1050   EXPECT_TRUE(capturedConnectionTypes[0].first); | 
|  1051   EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second); |  1051   EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second); | 
|  1052 } |  1052 } | 
|  1053  |  1053  | 
|  1054 TEST_F(FilterEngineIsAllowedConnectionTest, ConfiguredConnectionTypeIsPassedToCa
      llback) |  1054 TEST_F(FilterEngineIsAllowedConnectionTest, ConfiguredConnectionTypeIsPassedToCa
      llback) | 
|  1055 { |  1055 { | 
|  1056   // FilterEngine->RemoveSubscription is not usable here because subscriptions |  1056   // FilterEngine->RemoveSubscription is not usable here because subscriptions | 
|  1057   // 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 | 
|  1058   // checks. |  1058   // checks. | 
|  1059   { |  1059   { | 
|  1060     std::string predefinedAllowedConnectionType = "non-metered"; |  1060     std::string predefinedAllowedConnectionType = "non-metered"; | 
|  1061     createParams.preconfiguredPrefs.insert(std::make_pair( |  1061     createParams.preconfiguredPrefs.insert(std::make_pair( | 
|  1062       "allowed_connection_type", jsEngine->NewValue(predefinedAllowedConnectionT
      ype))); |  1062       "allowed_connection_type", jsEngine->NewValue(predefinedAllowedConnectionT
      ype))); | 
|  1063     auto subscription = EnsureExampleSubscriptionAndForceUpdate(); |  1063     auto subscription = EnsureExampleSubscriptionAndForceUpdate(); | 
|  1064     EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt
      ring()); |  1064     EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
      ing()); | 
|  1065     EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); |  1065     EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 
|  1066     auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); |  1066     auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); | 
|  1067     ASSERT_EQ(1u, capturedConnectionTypes.size()); |  1067     ASSERT_EQ(1u, capturedConnectionTypes.size()); | 
|  1068     EXPECT_TRUE(capturedConnectionTypes[0].first); |  1068     EXPECT_TRUE(capturedConnectionTypes[0].first); | 
|  1069     EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second
      ); |  1069     EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second
      ); | 
|  1070   } |  1070   } | 
|  1071   capturedConnectionTypes.Clear(); |  1071   capturedConnectionTypes.Clear(); | 
|  1072   { |  1072   { | 
|  1073     // set no value |  1073     // set no value | 
|  1074     filterEngine->SetAllowedConnectionType(nullptr); |  1074     filterEngine->SetAllowedConnectionType(nullptr); | 
|  1075     auto subscription = EnsureExampleSubscriptionAndForceUpdate("subA"); |  1075     auto subscription = EnsureExampleSubscriptionAndForceUpdate("subA"); | 
|  1076     EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt
      ring()); |  1076     EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
      ing()); | 
|  1077     EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); |  1077     EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 
|  1078     auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); |  1078     auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); | 
|  1079     ASSERT_EQ(1u, capturedConnectionTypes.size()); |  1079     ASSERT_EQ(1u, capturedConnectionTypes.size()); | 
|  1080     EXPECT_FALSE(capturedConnectionTypes[0].first); |  1080     EXPECT_FALSE(capturedConnectionTypes[0].first); | 
|  1081     subscription->RemoveFromList(); |  1081     subscription.RemoveFromList(); | 
|  1082     this->capturedConnectionTypes.Clear(); |  1082     this->capturedConnectionTypes.Clear(); | 
|  1083   } |  1083   } | 
|  1084   capturedConnectionTypes.Clear(); |  1084   capturedConnectionTypes.Clear(); | 
|  1085   { |  1085   { | 
|  1086     // set some value |  1086     // set some value | 
|  1087     std::string testConnection = "test connection"; |  1087     std::string testConnection = "test connection"; | 
|  1088     filterEngine->SetAllowedConnectionType(&testConnection); |  1088     filterEngine->SetAllowedConnectionType(&testConnection); | 
|  1089     auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); |  1089     auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); | 
|  1090     EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt
      ring()); |  1090     EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
      ing()); | 
|  1091     EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); |  1091     EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 
|  1092     auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); |  1092     auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); | 
|  1093     ASSERT_EQ(1u, capturedConnectionTypes.size()); |  1093     ASSERT_EQ(1u, capturedConnectionTypes.size()); | 
|  1094     EXPECT_TRUE(capturedConnectionTypes[0].first); |  1094     EXPECT_TRUE(capturedConnectionTypes[0].first); | 
|  1095     EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); |  1095     EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); | 
|  1096   } |  1096   } | 
|  1097 } |  1097 } | 
| OLD | NEW |