JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_setAcceptableAdsEnabled(JNIEnv *pEnv, jobject, jboolean enabled) { D(D_WARN, "setAcceptableAdsEnabled()"); try { const std::string surl = filterEngine->GetPref("subscriptions_exceptionsurl")->AsString(); AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(surl); if (enabled == JNI_TRUE) { subscription->AddToList(); } else if (subscription->IsListed()) { subscription->RemoveFromList(); } } catch (const std::exception& e) { ThrowJavaException(pEnv, e); } catch (...) { ThrowJavaException(pEnv); } }
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()); subscription->AddToList(); ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); ASSERT_TRUE(subscription->IsListed()); subscription->AddToList(); ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); ASSERT_TRUE(subscription->IsListed()); subscription->RemoveFromList(); ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); ASSERT_FALSE(subscription->IsListed()); subscription->RemoveFromList(); ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); ASSERT_FALSE(subscription->IsListed()); }
TEST_F(FilterEngineTest, AddRemoveSubscriptions) { // There should be only the default subscription initially ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo"); ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); ASSERT_FALSE(subscription->IsListed()); subscription->AddToList(); ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size()); ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]); ASSERT_TRUE(subscription->IsListed()); subscription->AddToList(); ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size()); ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]); ASSERT_TRUE(subscription->IsListed()); subscription->RemoveFromList(); ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); ASSERT_FALSE(subscription->IsListed()); subscription->RemoveFromList(); ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); ASSERT_FALSE(subscription->IsListed()); }
JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_addSubscription(JNIEnv *pEnv, jobject, jstring url) { D(D_WARN, "addSubscription()"); try { const std::string surl = GetString(pEnv, url); AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(surl); subscription->AddToList(); } catch (const std::exception& e) { ThrowJavaException(pEnv, e); } catch (...) { ThrowJavaException(pEnv); } }